00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 #include <stdio.h>
00041 #ifdef VMS
00042 #define index  strchr
00043 #endif
00044 #ifdef WIN32
00045 #define index  strchr
00046 #endif
00047 #ifdef __MACOS__
00048 #define index  strchr
00049 #endif
00050 
00051 
00052 char getoptt(int argc, 
00053             char **argv,
00054             char *optstring,
00055             char **optarg,
00056             int *poptind
00057   ){
00058 #define optind (*poptind)
00059         register int c;
00060         register char *place;
00061         extern char *index();
00062         static char *scan = NULL;
00063 
00064         *optarg = NULL;
00065 
00066         if (scan == NULL || *scan == '\0') {
00067 
00068                 if (optind == 0)
00069                         optind++;
00070                 if (optind >= argc)
00071                         return ':';
00072 
00073                 *optarg = place = argv[optind++];
00074                 if (place[0] != '-' || place[1] == '\0')
00075                         return '?';
00076                 if (place[1] == '-' && place[2] == '\0')
00077                         return '?';
00078                 scan = place + 1;
00079         }
00080 
00081         c = *scan++;
00082         place = index(optstring, c);
00083         if (place == NULL || c == ':' || c == ';') {
00084                 scan = NULL;
00085                 return '!';
00086         }
00087         if (*++place == ':') {
00088 
00089                 if (*scan != '\0') {
00090 
00091                         *optarg = scan;
00092                         scan = NULL;
00093 
00094                 }
00095                 else {
00096 
00097                         if (optind >= argc) {
00098                                 return '!';
00099                         }
00100                         *optarg = argv[optind];
00101                         optind++;
00102                 }
00103         }
00104         else if (*place == ';') {
00105 
00106                 if (*scan != '\0') {
00107 
00108                         *optarg = scan;
00109                         scan = NULL;
00110 
00111                 }
00112                 else {
00113 
00114                         if (optind >= argc || *argv[optind] == '-')
00115                                 *optarg = NULL;
00116                         else {
00117                                 *optarg = argv[optind];
00118                                 optind++;
00119                         }
00120                 }
00121         }
00122         return c;
00123 }