home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 December
/
VPR9712A.ISO
/
OLS
/
OS2
/
LHA2P205
/
LHA2P205.LZH
/
lha2-2.05pre
/
source.lzh
/
src
/
getopt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-15
|
3KB
|
125 lines
/*
* getopt.c --- get options
* Copyright (C) 1988-1992, Haruyasu YOSHIZAKI
* Copyright (C) 1991-1995, Satoshi HIRAMATSU (OS/2 HPFS version)
*
* $Log$
*/
#include <stdio.h>
#include <ctype.h>
#include <stddef.h>
#include <string.h>
#include <time.h>
#include "port2.h"
#include "typedef.h"
#include "lh.h"
char flg_r = 0, flg_p = 0, flg_x = 0, flg_m = 0, flg_a = 1,
flg_c = 0, flg_n = 0, flg_t = 0, flg_u = 0, flg_v = 0,
flg_w = 0, flg_i = 1, flg_h = 1, flg_o = 0, flg_z = 0,
#ifdef __SUPPORT_EA__
flg_e = 0,
#endif /* __SUPPORT_EA__ */
flg_l = 0, flg_s = 0, flg_at = 0, flg_d = 0, flg_f = 0;
/* get options */
int
getopt(char *p)
{
#ifdef __SUPPORT_EA__
static char flg[] = "rpxmacntuvwihozls-dfe";
static char *flgpos[] = {
&flg_r, &flg_p, &flg_x, &flg_m, &flg_a,
&flg_c, &flg_n, &flg_t, &flg_u, &flg_v,
&flg_w, &flg_i, &flg_h, &flg_o, &flg_z,
&flg_l, &flg_s, &flg_at, &flg_d, &flg_f,
&flg_e};
#else
static char flg[] = "rpxmacntuvwihozls-df";
static char *flgpos[] = {
&flg_r, &flg_p, &flg_x, &flg_m, &flg_a,
&flg_c, &flg_n, &flg_t, &flg_u, &flg_v,
&flg_w, &flg_i, &flg_h, &flg_o, &flg_z,
&flg_l, &flg_s, &flg_at, &flg_d, &flg_f};
#endif /* __SUPPORT_EA__ */
static char val[] = "0-1+2";
int i;
char s;
char *q;
while((s = tolower(*p)) != 0)
{
p++;
q = strchr(flg, s); /* search switch */
if(q)
{
i = q - flg;
if(*p && (q = strchr(val, *p)) != NULL)
{
*flgpos[i] = (q - val) / 2;
p++;
}
#ifdef __SUPPORT_EA__
else if(s == 'h' && *p == '3')
{
flg_h = 3;
p++;
}
#endif
#if 0
else if(s == 'v' && *p)
{
if(flg_v == 0) /* process of '/vSTRING' */
flg_v = 1;
pager = p;
p = "";
}
#endif
else if(s == 'z' && *p)
{
flg_z = 2; /* process of '/zSTRING' */
regext(p);
p = "";
}
else if(s == 'w' && *p)
{
flg_w = 1; /* process of '/wSTRING' */
strcpy(workdir, p);
p = "";
}
else
{
/* flip-flop */
*flgpos[i] = !*flgpos[i];
}
}
#if 0
else if(s == 'k')
{
keyword = p;
p = "";
}
#endif
else
{
if(s == '?')
usage();
return 1;
}
}
#ifdef __SUPPORT_EA__
if(flg_e)
{
flg_h = 3; /* use level-3 header */
if(flg_x)
flg_d = 1; /* for directory's EA */
}
#endif
return 0;
}