int AllowModes(struct cmdargs const *arg) { /* arg->bundle may be NULL (see system_IsValid()) ! */ int f, mode, allowed; allowed = 0; for (f = arg->argn; f < arg->argc; f++) { mode = Nam2mode(arg->argv[f]); if (mode == PHYS_NONE || mode == PHYS_ALL) log_Printf(LogWARN, "allow modes: %s: Invalid mode\n", arg->argv[f]); else allowed |= mode; } modeok = modereq & allowed ? 1 : 0; return 0; }
static int ProcessArgs(int argc, char **argv, struct switches *sw) { int optc, newmode, arg; char *cp; optc = 0; memset(sw, '\0', sizeof *sw); sw->mode = PHYS_INTERACTIVE; sw->unit = -1; for (arg = 1; arg < argc && *argv[arg] == '-'; arg++, optc++) { cp = argv[arg] + 1; newmode = Nam2mode(cp); switch (newmode) { case PHYS_NONE: if (strcmp(cp, "nat") == 0) { #ifdef NONAT log_Printf(LogWARN, "%s ignored: NAT is compiled out\n", argv[arg]); #else sw->nat = 1; #endif optc--; /* this option isn't exclusive */ } else if (strcmp(cp, "alias") == 0) { #ifdef NONAT log_Printf(LogWARN, "%s ignored: NAT is compiled out\n", argv[arg]); fprintf(stderr, "%s ignored: NAT is compiled out\n", argv[arg]); #else log_Printf(LogWARN, "%s is deprecated\n", argv[arg]); fprintf(stderr, "%s is deprecated\n", argv[arg]); sw->nat = 1; #endif optc--; /* this option isn't exclusive */ } else if (strncmp(cp, "unit", 4) == 0) { optc--; /* this option isn't exclusive */ if (cp[4] == '\0') { optc--; /* nor is the argument */ if (++arg == argc) { fprintf(stderr, "-unit: Expected unit number\n"); Usage(); } else sw->unit = atoi(argv[arg]); } else sw->unit = atoi(cp + 4); } else if (strcmp(cp, "quiet") == 0) { sw->quiet = 1; optc--; /* this option isn't exclusive */ } else Usage(); break; case PHYS_ALL: Usage(); break; default: sw->mode = newmode; if (newmode == PHYS_FOREGROUND) sw->fg = 1; } } if (optc > 1) { fprintf(stderr, "You may specify only one mode.\n"); exit(EX_START); } if (sw->mode == PHYS_AUTO && arg == argc) { fprintf(stderr, "A system must be specified in auto mode.\n"); exit(EX_START); } return arg; /* Don't SetLabel yet ! */ }