1 // Adapted from: XGetopt.cpp Version 1.2 by Hans Dietrich
3 #include "XGetopt.win32.h"
6 char *optarg
; // global argument pointer
7 int optind
= 0; // global argv index
9 int getopt(int argc
, char *argv
[], char *optstring
)
11 static char *next
= NULL
;
17 if (next
== NULL
|| *next
== '\0')
22 if (optind
>= argc
|| argv
[optind
][0] != '-' || argv
[optind
][1] == '\0')
26 optarg
= argv
[optind
];
30 if (strcmp(argv
[optind
], "--") == 0)
35 optarg
= argv
[optind
];
40 next
++; // skip past -
45 char *cp
= strchr(optstring
, c
);
47 if (cp
== NULL
|| c
== ':')
58 else if (optind
< argc
)
60 optarg
= argv
[optind
];