MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / collectargs

Function collectargs

extlibs/lua/src/lua.c:247–293  ·  view source on GitHub ↗

** Traverses all arguments from 'argv', returning a mask with those ** needed before running any Lua code (or an error code if it finds ** any invalid argument). 'first' returns the first not-handled argument ** (either the script name or a bad argument in case of error). */

Source from the content-addressed store, hash-verified

245** (either the script name or a bad argument in case of error).
246*/
247static int collectargs (char **argv, int *first) {
248 int args = 0;
249 int i;
250 for (i = 1; argv[i] != NULL; i++) {
251 *first = i;
252 if (argv[i][0] != '-') /* not an option? */
253 return args; /* stop handling options */
254 switch (argv[i][1]) { /* else check option */
255 case '-': /* '--' */
256 if (argv[i][2] != '\0') /* extra characters after '--'? */
257 return has_error; /* invalid option */
258 *first = i + 1;
259 return args;
260 case '\0': /* '-' */
261 return args; /* script "name" is '-' */
262 case 'E':
263 if (argv[i][2] != '\0') /* extra characters? */
264 return has_error; /* invalid option */
265 args |= has_E;
266 break;
267 case 'W':
268 if (argv[i][2] != '\0') /* extra characters? */
269 return has_error; /* invalid option */
270 break;
271 case 'i':
272 args |= has_i; /* (-i implies -v) *//* FALLTHROUGH */
273 case 'v':
274 if (argv[i][2] != '\0') /* extra characters? */
275 return has_error; /* invalid option */
276 args |= has_v;
277 break;
278 case 'e':
279 args |= has_e; /* FALLTHROUGH */
280 case 'l': /* both options need an argument */
281 if (argv[i][2] == '\0') { /* no concatenated argument? */
282 i++; /* try next 'argv' */
283 if (argv[i] == NULL || argv[i][0] == '-')
284 return has_error; /* no next argument or it is another option */
285 }
286 break;
287 default: /* invalid option */
288 return has_error;
289 }
290 }
291 *first = i; /* no script name */
292 return args;
293}
294
295
296/*

Callers 1

pmainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected