home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ctcoll95.zip
/
BASTELST
/
PAPI020.ZIP
/
GETOPT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-06
|
1KB
|
60 lines
/*
getopt.c -- Turbo C
Copyright (c) 1986,87,88 by Borland International Inc.
All Rights Reserved.
*/
#include <string.h>
#include <dos.h>
int optind = 1; /* index of which argument is next */
char *optarg; /* pointer to argument of current option */
static char *letP = NULL; /* remember next option char's location */
#define SW '-' /* DOS switch character, either '-' or '/' */
int getopt(int argc, char *argv[], char *optionS)
{
unsigned char ch;
char *optP;
if (argc > optind) {
if (letP == NULL) {
if ((letP = argv[optind]) == NULL ||
*(letP++) != SW) goto gopEOF;
if (*letP == SW) {
optind++; goto gopEOF;
}
}
if (0 == (ch = *(letP++))) {
optind++; goto gopEOF;
}
if (':' == ch || (optP = strchr(optionS, ch)) == NULL)
goto gopError;
if (':' == *(++optP)) {
optind++;
if (0 == *letP) {
if (argc <= optind) goto gopError;
letP = argv[optind++];
}
optarg = letP;
letP = NULL;
} else {
if (0 == *letP) {
optind++;
letP = NULL;
}
optarg = NULL;
}
return ch;
}
gopEOF:
optarg = letP = NULL;
return -1;
gopError:
optarg = NULL;
return ('?');
}