home *** CD-ROM | disk | FTP | other *** search
- /*
- 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 ('?');
- }
-