home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 9
/
FreshFishVol9-CD2.bin
/
bbs
/
disk
/
mkisofs-1.00.7.lha
/
mkisofs
/
unix
/
getopt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-29
|
848b
|
47 lines
/* getopt.c: */
#include <stdio.h>
#include <string.h>
char *optarg;
int optind = 0;
int getopt (int argc, char *argv[], char *p_format)
{
static char *cp = 0;
char c, *pos;
while (1) {
if (cp && *cp) {
if (*cp != ':' && (pos = strchr (p_format, *cp))) {
if (pos[1] != ':')
return *cp++;
if (cp[1])
optarg = cp+1;
else
optarg = argv[++optind];
if (optind == argc) {
fprintf (stderr, "missing argument for option '-%c'", *cp);
return -1;
}
c = *cp;
cp = 0;
return c;
}
fprintf (stderr, "-- unknown option character '%c'\n", *cp++);
return '?';
}
if (++optind == argc)
return -1;
cp = argv[optind];
if (cp[0] == '-') {
if (cp[1] == '-' && cp[2] == 0) {
optind++;
return -1;
}
cp++;
} else
return -1;
}
}