MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / collectargs

Function collectargs

third-party/lua-5.5.0/src/lua.c:287–342  ·  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. In case of error, 'first' is the index of the bad ** argument. Otherwise, 'first' is -1 if there is no program name, ** 0 if there is no script name, or the index of the script name. */

Source from the content-addressed store, hash-verified

285** 0 if there is no script name, or the index of the script name.
286*/
287static int collectargs (char **argv, int *first) {
288 int args = 0;
289 int i;
290 if (argv[0] != NULL) { /* is there a program name? */
291 if (argv[0][0]) /* not empty? */
292 progname = argv[0]; /* save it */
293 }
294 else { /* no program name */
295 *first = -1;
296 return 0;
297 }
298 for (i = 1; argv[i] != NULL; i++) { /* handle arguments */
299 *first = i;
300 if (argv[i][0] != '-') /* not an option? */
301 return args; /* stop handling options */
302 switch (argv[i][1]) { /* else check option */
303 case '-': /* '--' */
304 if (argv[i][2] != '\0') /* extra characters after '--'? */
305 return has_error; /* invalid option */
306 /* if there is a script name, it comes after '--' */
307 *first = (argv[i + 1] != NULL) ? i + 1 : 0;
308 return args;
309 case '\0': /* '-' */
310 return args; /* script "name" is '-' */
311 case 'E':
312 if (argv[i][2] != '\0') /* extra characters? */
313 return has_error; /* invalid option */
314 args |= has_E;
315 break;
316 case 'W':
317 if (argv[i][2] != '\0') /* extra characters? */
318 return has_error; /* invalid option */
319 break;
320 case 'i':
321 args |= has_i; /* (-i implies -v) *//* FALLTHROUGH */
322 case 'v':
323 if (argv[i][2] != '\0') /* extra characters? */
324 return has_error; /* invalid option */
325 args |= has_v;
326 break;
327 case 'e':
328 args |= has_e; /* FALLTHROUGH */
329 case 'l': /* both options need an argument */
330 if (argv[i][2] == '\0') { /* no concatenated argument? */
331 i++; /* try next 'argv' */
332 if (argv[i] == NULL || argv[i][0] == '-')
333 return has_error; /* no next argument or it is another option */
334 }
335 break;
336 default: /* invalid option */
337 return has_error;
338 }
339 }
340 *first = 0; /* no script name */
341 return args;
342}
343
344

Callers 1

pmainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected