static int collectargs (char **argv, int *pi, int *pv, int *pe) { int i; for (i = 1; argv[i] != NULL; i++) { if (argv[i][0] != '-') /* not an option? */ return i; switch (argv[i][1]) { /* option */ case '-': notail(argv[i]); return (argv[i+1] != NULL ? i+1 : 0); case '\0': return i; case 'i': notail(argv[i]); *pi = 1; /* go through */ case 'v': notail(argv[i]); *pv = 1; break; case 'e': *pe = 1; /* go through */ case 'l': if (argv[i][2] == '\0') { i++; if (argv[i] == NULL) return -1; } break; default: return -1; /* invalid option */ } } return 0; }
static int collectargs (char **argv, int *pi, int *pv, int *pe) { int i; for (i = 1; argv[i] != NULL; i++) { if (argv[i][0] != '-') return i; switch (argv[i][1]) { case '-': notail(argv[i]); return (argv[i+1] != NULL ? i+1 : 0); case '\0': return i; case 'i': notail(argv[i]); *pi = 1; case 'v': notail(argv[i]); *pv = 1; break; case 'e': *pe = 1; case 'l': if (argv[i][2] == '\0') { i++; if (argv[i] == NULL) return -1; } break; default: return -1; } } return 0; }
static int collectargs(char **argv, int *flags) { int i; for(i = 1; argv[i] != NULL; i++) { if(argv[i][0] != '-') /* Not an option? */ { return i; } switch(argv[i][1]) /* Check option. */ { case '-': notail(argv[i]); return (argv[i + 1] != NULL ? i + 1 : 0); case '\0': return i; case 'i': notail(argv[i]); *flags |= FLAGS_INTERACTIVE; /* fallthrough */ case 'v': notail(argv[i]); *flags |= FLAGS_VERSION; break; case 'e': *flags |= FLAGS_EXEC; case 'j': /* LuaJIT extension */ case 'l': *flags |= FLAGS_OPTION; if(argv[i][2] == '\0') { i++; if(argv[i] == NULL) { return -1; } } break; case 'O': break; /* LuaJIT extension */ case 'b': /* LuaJIT extension */ if(*flags) { return -1; } *flags |= FLAGS_EXEC; return 0; case 'E': *flags |= FLAGS_NOENV; break; default: return -1; /* invalid option */ } } return 0; }
static int collectargs(char **argv, int *flags) { int i; *flags |= FLAGS_VERSION|FLAGS_MADENV; for (i = 1; argv[i] != NULL; i++) { if (argv[i][0] != '-') /* Not an option? */ return i; switch (argv[i][1]) { /* Check option. */ case '-': notail(argv[i]); return i+1; case '\0': return i; case 'i': notail(argv[i]); *flags |= FLAGS_INTERACTIVE; break; case 'q': notail(argv[i]); *flags &= ~FLAGS_VERSION; break; case 'e': *flags |= FLAGS_EXEC; case 'j': /* LuaJIT extension */ case 'l': *flags |= FLAGS_OPTION; if (argv[i][2] == '\0') { i++; if (argv[i] == NULL) return -1; } break; case 'O': break; /* LuaJIT extension */ case 'b': /* LuaJIT extension */ *flags &= ~(FLAGS_VERSION|FLAGS_MADENV); if (*flags) return -1; *flags |= FLAGS_EXEC; return i+1; case 'E': notail(argv[i]); *flags |= FLAGS_NOENV; break; case 'M': /* no MAD environment */ notail(argv[i]); *flags &= ~FLAGS_MADENV; break; case 'T': /* MAD initial trace level */ mad_trace_location = 1; case 't': /* MAD initial trace level */ mad_trace_level = argv[i][2] ? strtol(argv[i]+2, NULL, 0) : 1; break; default: return -1; /* invalid option */ } } return i; }