Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygengetopt.c
Go to the documentation of this file.
00001 00002 /* jgaa oct 9th 2000: Found this on www. 00003 * No copyright information given. 00004 * Slightly modidied. 00005 * 00006 * Origin: http://www.winsite.com/info/pc/win3/winsock/sossntr4.zip/SOSSNT/SRC/GETOPT.C.html 00007 */ 00008 00009 /* got this off net.sources */ 00010 00011 #include <stdio.h> 00012 #include <stdlib.h> 00013 #include <string.h> 00014 00015 #include "getopt.h" 00016 00017 00018 /* 00019 * get option letter from argument vector 00020 */ 00021 int opterr = 1, /* useless, never set or used */ 00022 optind = 1, /* index into parent argv vector */ 00023 optopt; /* character checked for validity */ 00024 char* optarg; /* argument associated with option */ 00025 00026 #define BADCH (int)'?' 00027 #define EMSG "" 00028 #define tell(s) fputs(*argv,stderr);fputs(s,stderr); \ 00029 fputc(optopt,stderr);fputc('\n',stderr);return(BADCH); 00030 00031 int getopt(int argc, char * const *argv, const char *optstring) 00032 { 00033 static char *place = EMSG; /* option letter processing */ 00034 register char *oli; /* option letter list index */ 00035 00036 if(!*place) { /* update scanning pointer */ 00037 if(optind >= argc || *(place = argv[optind]) != '-' || !*++place) 00038 return(EOF); 00039 if (*place == '-') { /* found "--" */ 00040 ++optind; 00041 return(EOF); 00042 } 00043 } /* option letter okay? */ 00044 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(optstring,optopt))) 00045 { 00046 if(!*place) ++optind; 00047 tell(": illegal option -- "); 00048 } 00049 if (*++oli != ':') { /* don't need argument */ 00050 optarg = NULL; 00051 if (!*place) ++optind; 00052 } 00053 else { /* need an argument */ 00054 if (*place) optarg = place; /* no white space */ 00055 else if (argc <= ++optind) { /* no arg */ 00056 place = EMSG; 00057 tell(": option requires an argument -- "); 00058 } 00059 else optarg = argv[optind]; /* white space */ 00060 place = EMSG; 00061 ++optind; 00062 } 00063 return(optopt); /* dump back option letter */ 00064 } Generated on Sat May 26 2012 04:16:07 for ReactOS by
1.7.6.1
|