HuntnGather – Diff between revs 1 and 32

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 1 Rev 32
Line 1... Line 1...
1 /**************************************************************************** 1 /****************************************************************************
2 * getopt(): Return the next user option on each iteration. 2 * getopt(): Return the next user option on each iteration.
3 * This is a clone of the usual UNIX getopt() function. 3 * This is a clone of the usual UNIX getopt() function.
4 * If you have never used a getopt() before, you'll have to 4 * If you have never used a getopt() before, you'll have to
5 * read about it on any UNIX machine or other C system that 5 * read about it on any UNIX machine or other C system that
6 * documents it. 6 * documents it.
7 * 7 *
Line 102... Line 102...
102   102  
103 /************************************************************************ 103 /************************************************************************
104 * Global variables. You must declare these externs in your program 104 * Global variables. You must declare these externs in your program
105 * if you want to see their values! 105 * if you want to see their values!
106 ************************************************************************/ 106 ************************************************************************/
107 107  
108 char *optarg = NULL; /* This will point to a required argument, if any. */ 108 char *optarg = NULL; /* This will point to a required argument, if any. */
109 int optind = 1; /* The index of the next argument in argv. */ 109 int optind = 1; /* The index of the next argument in argv. */
110 int opterr = 1; /* 1 == print internal error messages. 0 else. */ 110 int opterr = 1; /* 1 == print internal error messages. 0 else. */
Line 125... Line 125...
125 * Return EOF. 125 * Return EOF.
126 * If we have ONLY a DASH, and nothing after it... return EOF as well. 126 * If we have ONLY a DASH, and nothing after it... return EOF as well.
127 * If we have a DASH followed immediately by another DASH, this is the 127 * If we have a DASH followed immediately by another DASH, this is the
128 * special "--" option that means "no more options follow." Return EOF. 128 * special "--" option that means "no more options follow." Return EOF.
129 * Otherwise, we have an actual option or list of options. Process it. */ 129 * Otherwise, we have an actual option or list of options. Process it. */
130 130  
131 static int NextOption(char *argv[], char *optString) 131 static int NextOption(char *argv[], char *optString)
132 { 132 {
133 static int optsSkipped = 0; /* In a single argv[i]. */ 133 static int optsSkipped = 0; /* In a single argv[i]. */
134 134  
135 if ((argv[optind][0] == DASH) 135 if ((argv[optind][0] == DASH)
136 && ((optopt = argv[optind][1+optsSkipped]) != '\0')) 136 && ((optopt = argv[optind][1+optsSkipped]) != '\0'))
137 { 137 {
138 if (optopt == DASH) 138 if (optopt == DASH)
139 { 139 {
Line 156... Line 156...
156 * If the option is not legal (not in optString), complain and return 156 * If the option is not legal (not in optString), complain and return
157 * UNKNOWN_OPT. 157 * UNKNOWN_OPT.
158 * If the option requires no argument, just return the option letter. 158 * If the option requires no argument, just return the option letter.
159 * If the option requires an argument, call HandleArgument and return 159 * If the option requires an argument, call HandleArgument and return
160 * the option letter. */ 160 * the option letter. */
161 161  
162 static int RealOption(char *argv[], char *optString, int *optsSkipped, 162 static int RealOption(char *argv[], char *optString, int *optsSkipped,
163 int *optind, int optopt) 163 int *optind, int optopt)
164 { 164 {
165 char *where; /* Pointer to the letter in optString. */ 165 char *where; /* Pointer to the letter in optString. */
166 int argWasOK; /* An indication that a required arg was found. */ 166 int argWasOK; /* An indication that a required arg was found. */