HuntnGather – Diff between revs 1 and 31
?pathlinks?
Rev 1 | Rev 31 | |||
---|---|---|---|---|
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 62... | Line 62... | |||
62 | * Date: April 12, 1990. |
62 | * Date: April 12, 1990. |
|
63 | * Comments: First released version. |
63 | * Comments: First released version. |
|
64 | * |
64 | * |
|
65 | ****************************************************************************/ |
65 | ****************************************************************************/ |
|
Line -... | Line 66... | |||
- | 66 | |
||
- | 67 | #if defined MWDEBUG |
||
- | 68 | #include "memwatch.h" |
||
- | 69 | #endif |
||
66 | |
70 | |
|
67 | #ifndef __STDIO_H /* If we haven't already included stdio.h, do it. */ |
71 | #ifndef __STDIO_H /* If we haven't already included stdio.h, do it. */ |
|
68 | # include <stdio.h> /* Maybe someday I'll eliminate this. */ |
72 | # include <stdio.h> /* Maybe someday I'll eliminate this. */ |
|
Line 69... | Line 73... | |||
69 | #endif |
73 | #endif |
|
Line 102... | Line 106... | |||
102 | |
106 | |
|
103 | /************************************************************************ |
107 | /************************************************************************ |
|
104 | * Global variables. You must declare these externs in your program |
108 | * Global variables. You must declare these externs in your program |
|
105 | * if you want to see their values! |
109 | * if you want to see their values! |
|
106 | ************************************************************************/ |
110 | ************************************************************************/ |
|
107 | |
111 | |
|
108 | char *optarg = NULL; /* This will point to a required argument, if any. */ |
112 | char *optarg = NULL; /* This will point to a required argument, if any. */ |
|
109 | int optind = 1; /* The index of the next argument in argv. */ |
113 | int optind = 1; /* The index of the next argument in argv. */ |
|
110 | int opterr = 1; /* 1 == print internal error messages. 0 else. */ |
114 | int opterr = 1; /* 1 == print internal error messages. 0 else. */ |
|
Line 125... | Line 129... | |||
125 | * Return EOF. |
129 | * Return EOF. |
|
126 | * If we have ONLY a DASH, and nothing after it... return EOF as well. |
130 | * 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 |
131 | * If we have a DASH followed immediately by another DASH, this is the |
|
128 | * special "--" option that means "no more options follow." Return EOF. |
132 | * special "--" option that means "no more options follow." Return EOF. |
|
129 | * Otherwise, we have an actual option or list of options. Process it. */ |
133 | * Otherwise, we have an actual option or list of options. Process it. */ |
|
130 | |
134 | |
|
131 | static int NextOption(char *argv[], char *optString) |
135 | static int NextOption(char *argv[], char *optString) |
|
132 | { |
136 | { |
|
133 | static int optsSkipped = 0; /* In a single argv[i]. */ |
137 | static int optsSkipped = 0; /* In a single argv[i]. */ |
|
134 | |
138 | |
|
135 | if ((argv[optind][0] == DASH) |
139 | if ((argv[optind][0] == DASH) |
|
136 | && ((optopt = argv[optind][1+optsSkipped]) != '\0')) |
140 | && ((optopt = argv[optind][1+optsSkipped]) != '\0')) |
|
137 | { |
141 | { |
|
138 | if (optopt == DASH) |
142 | if (optopt == DASH) |
|
139 | { |
143 | { |
|
Line 156... | Line 160... | |||
156 | * If the option is not legal (not in optString), complain and return |
160 | * If the option is not legal (not in optString), complain and return |
|
157 | * UNKNOWN_OPT. |
161 | * UNKNOWN_OPT. |
|
158 | * If the option requires no argument, just return the option letter. |
162 | * If the option requires no argument, just return the option letter. |
|
159 | * If the option requires an argument, call HandleArgument and return |
163 | * If the option requires an argument, call HandleArgument and return |
|
160 | * the option letter. */ |
164 | * the option letter. */ |
|
161 | |
165 | |
|
162 | static int RealOption(char *argv[], char *optString, int *optsSkipped, |
166 | static int RealOption(char *argv[], char *optString, int *optsSkipped, |
|
163 | int *optind, int optopt) |
167 | int *optind, int optopt) |
|
164 | { |
168 | { |
|
165 | char *where; /* Pointer to the letter in optString. */ |
169 | char *where; /* Pointer to the letter in optString. */ |
|
166 | int argWasOK; /* An indication that a required arg was found. */ |
170 | int argWasOK; /* An indication that a required arg was found. */ |