00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __GNUC__
00010
00011 #include "getopt.hh"
00012 #include <stdio.h>
00013 #include <string.h>
00014
00015 #define NULL 0
00016 #define EOF (-1)
00017 #define ERR(s, c) if(opterr){\
00018 char errbuf[2];\
00019 errbuf[0] = c; errbuf[1] = '\n';\
00020 fputs(argv[0], stderr);\
00021 fputs(s, stderr);\
00022 fputc(c, stderr);}
00023
00024
00025
00026
00027 int opterr = 1;
00028 int optind = 1;
00029 int optopt;
00030 char *optarg;
00031
00032 int
00033 getopt(argc, argv, opts)
00034 int argc;
00035 char **argv, *opts;
00036 {
00037 static int sp = 1;
00038 register int c;
00039 register char *cp;
00040
00041 if(sp == 1)
00042 if(optind >= argc ||
00043 argv[optind][0] != '-' || argv[optind][1] == '\0')
00044 return(EOF);
00045 else if(strcmp(argv[optind], "--") == NULL) {
00046 optind++;
00047 return(EOF);
00048 }
00049 optopt = c = argv[optind][sp];
00050 if(c == ':' || (cp=strchr(opts, c)) == NULL) {
00051 ERR(": illegal option -- ", c);
00052 if(argv[optind][++sp] == '\0') {
00053 optind++;
00054 sp = 1;
00055 }
00056 return('?');
00057 }
00058 if(*++cp == ':') {
00059 if(argv[optind][sp+1] != '\0')
00060 optarg = &argv[optind++][sp+1];
00061 else if(++optind >= argc) {
00062 ERR(": option requires an argument -- ", c);
00063 sp = 1;
00064 return('?');
00065 } else
00066 optarg = argv[optind++];
00067 sp = 1;
00068 } else {
00069 if(argv[optind][++sp] == '\0') {
00070 sp = 1;
00071 optind++;
00072 }
00073 optarg = NULL;
00074 }
00075 return(c);
00076 }
00077
00078 #endif