Main Page   Modules   Compound List   File List   Compound Members   File Members   Related Pages  

attgetopt.c

Go to the documentation of this file.
00001 
00014 #include <stdio.h>
00015 #include <string.h>
00016 
00017 
00018 #define ERR(s, c)     if (opterr) (void) fprintf(stderr, "%s: %s\n", argv[0], s) 
00019 
00020 int     opterr = 1;
00021 int     optind = 1;
00022 int     optopt;
00023 char    *optarg;
00024 
00025 int getopt(int argc, char **argv, char *opts)
00026 {
00027     static int sp = 1;
00028     register int c;
00029     register char *cp;
00030 
00031     if(sp == 1) {
00032         if(optind >= argc ||
00033            argv[optind][0] != '-' || argv[optind][1] == '\0')
00034                 return(EOF);
00035         else if(strcmp(argv[optind], "--") == 0) {
00036             optind++;
00037             return(EOF);
00038         }
00039     }
00040     optopt = c = argv[optind][sp];
00041     if(c == ':' || (cp=strchr(opts, c)) == NULL) {
00042         ERR(": illegal option -- ", c);
00043         if(argv[optind][++sp] == '\0') {
00044             optind++;
00045             sp = 1;
00046         }
00047         return('?');
00048     }
00049     if(*++cp == ':') {
00050         if(argv[optind][sp+1] != '\0')
00051             optarg = &argv[optind++][sp+1];
00052         else if(++optind >= argc) {
00053             ERR(": option requires an argument -- ", c);
00054             sp = 1;
00055             return('?');
00056         } else
00057             optarg = argv[optind++];
00058         sp = 1;
00059     } else {
00060         if(argv[optind][++sp] == '\0') {
00061             sp = 1;
00062             optind++;
00063         }
00064         optarg = NULL;
00065     }
00066     return(c);
00067 }

Generated on Mon Nov 24 20:09:42 2003 for WBXML Library by doxygen1.3-rc1