static void do_next_command(char *input) { char *ptr, *arg; ptr = next_token(&input, " \t\r\n"); if (ptr == NULL) return; arg = next_token(&input, " \t\r\n"); if ((strcasecmp(ptr, "set") == 0) && (arg != NULL)) setoption(arg); else if ((strcasecmp(ptr, "server") == 0) || (strcasecmp(ptr, "lserver") == 0)) { isc_app_block(); set_nameserver(arg); check_ra = ISC_FALSE; isc_app_unblock(); show_settings(ISC_TRUE, ISC_TRUE); } else if (strcasecmp(ptr, "exit") == 0) { in_use = ISC_FALSE; } else if (strcasecmp(ptr, "help") == 0 || strcasecmp(ptr, "?") == 0) { printf("The '%s' command is not yet implemented.\n", ptr); } else if (strcasecmp(ptr, "finger") == 0 || strcasecmp(ptr, "root") == 0 || strcasecmp(ptr, "ls") == 0 || strcasecmp(ptr, "view") == 0) { printf("The '%s' command is not implemented.\n", ptr); } else addlookup(ptr); }
int term_optionhandler(int k, const struct termopt *o) { int flag = o->flag; union val v; switch (k) { case 0: break; case MVLEFT: textgfx_flags &= ~flag; break; case MVRIGHT: textgfx_flags |= flag; break; case A_BTN: textgfx_flags ^= flag; break; default: return 0; } printmenuitem_options(o->s, (textgfx_flags & flag)!=0); if (!k) return 1; v.integ = flag==MONOCHROME ? 2-k : k-1; setoption("term", o->key, v, 0); #if !NO_BLOCKSTYLES if ((textgfx_flags & (WHITE_BG | TT_MONO))==(WHITE_BG | TT_BLOCKS) || _TT_BLOCKS_BG && (!_WHITE_BG || _MONOCHROME) && getopt_int("term", "block") == -1) textgfx_flags ^= TT_BLOCKS | TT_BLOCKS_BG; #endif reset_block_chars(); return 3; }
static void parse_args(int argc, char **argv) { isc_boolean_t have_lookup = ISC_FALSE; usesearch = ISC_TRUE; for (argc--, argv++; argc > 0; argc--, argv++) { debug("main parsing %s", argv[0]); if (argv[0][0] == '-') { if (strncasecmp(argv[0], "-ver", 4) == 0) { version(); exit(0); } else if (argv[0][1] != 0) { setoption(&argv[0][1]); } else have_lookup = ISC_TRUE; } else { if (!have_lookup) { have_lookup = ISC_TRUE; in_use = ISC_TRUE; addlookup(argv[0]); } else { set_nameserver(argv[0]); check_ra = ISC_FALSE; } } } }
static void save_bgdot() { union val v; v.str[0] = bgdot; v.str[1] = '\0'; setoption("term", "bgdot", v, 1); }
/* we have -o option=value -- parse, and process */ static int parse_option(netpgp_t *netpgp, prog_t *p, const char *s, int *homeset) { static regex_t opt; struct option *op; static int compiled; regmatch_t matches[10]; char option[128]; char value[128]; if (!compiled) { compiled = 1; (void) regcomp(&opt, "([^=]{1,128})(=(.*))?", REG_EXTENDED); } if (regexec(&opt, s, 10, matches, 0) == 0) { (void) snprintf(option, sizeof(option), "%.*s", (int)(matches[1].rm_eo - matches[1].rm_so), &s[matches[1].rm_so]); if (matches[2].rm_so > 0) { (void) snprintf(value, sizeof(value), "%.*s", (int)(matches[3].rm_eo - matches[3].rm_so), &s[matches[3].rm_so]); } else { value[0] = 0x0; } for (op = options ; op->name ; op++) { if (strcmp(op->name, option) == 0) { return setoption(netpgp, p, op->val, value, homeset); } } } return 0; }
static void minus_o(char *name, int val) { int i; if (name == NULL) { if (val) { /* "Pretty" output. */ out1str("Current option settings\n"); for (i = 0; i < NOPTS; i++) out1fmt("%-16s%s\n", optlist[i].name, optlist[i].val ? "on" : "off"); } else { /* Output suitable for re-input to shell. */ for (i = 0; i < NOPTS; i++) out1fmt("%s %co %s%s", i % 6 == 0 ? "set" : "", optlist[i].val ? '-' : '+', optlist[i].name, i % 6 == 5 || i == NOPTS - 1 ? "\n" : ""); } } else { for (i = 0; i < NOPTS; i++) if (equal(name, optlist[i].name)) { setoption(optlist[i].letter, val); return; } error("Illegal option -o %s", name); } }
static void get_next_command (void) { char *buf; char *ptr, *arg; char *input; fflush (stdout); buf = isc_mem_allocate (mctx, COMMSIZE); if (buf == NULL) fatal ("memory allocation failure"); fputs ("> ", stderr); fflush (stderr); isc_app_block (); ptr = fgets (buf, COMMSIZE, stdin); isc_app_unblock (); if (ptr == NULL) { in_use = ISC_FALSE; goto cleanup; } input = buf; ptr = next_token (&input, " \t\r\n"); if (ptr == NULL) goto cleanup; arg = next_token (&input, " \t\r\n"); if ((strcasecmp (ptr, "set") == 0) && (arg != NULL)) setoption (arg); else if ((strcasecmp (ptr, "server") == 0) || (strcasecmp (ptr, "lserver") == 0)) { isc_app_block (); set_nameserver (arg); check_ra = ISC_FALSE; isc_app_unblock (); show_settings (ISC_TRUE, ISC_TRUE); } else if (strcasecmp (ptr, "exit") == 0) { in_use = ISC_FALSE; goto cleanup; } else if (strcasecmp (ptr, "help") == 0 || strcasecmp (ptr, "?") == 0) { printf ("The '%s' command is not yet implemented.\n", ptr); goto cleanup; } else if (strcasecmp (ptr, "finger") == 0 || strcasecmp (ptr, "root") == 0 || strcasecmp (ptr, "ls") == 0 || strcasecmp (ptr, "view") == 0) { printf ("The '%s' command is not implemented.\n", ptr); goto cleanup; } else addlookup (ptr); cleanup: isc_mem_free (mctx, buf); }
void setopt(char *lpsCmd){ char *lpsOpt=dlp_strsep(&lpsCmd," \t",NULL); if(lpsCmd){ while(lpsCmd[0]==' ' || lpsCmd[0]=='\t' || lpsCmd[0]=='=') lpsCmd++; lpsCmd=dlp_strsep(&lpsCmd," \t\n\r",NULL); } setoption(lpsOpt,lpsCmd,TRUE); if (rCfg.eOut==O_gui) optdump(); }
STATIC void options(int cmdline) { char *p; int val; int c; if (cmdline) minusc = NULL; while ((p = *argptr) != NULL) { argptr++; if ((c = *p++) == '-') { val = 1; if (p[0] == '\0' || (p[0] == '-' && p[1] == '\0')) { if (!cmdline) { /* "-" means turn off -x and -v */ if (p[0] == '\0') xflag = vflag = 0; /* "--" means reset params */ else if (*argptr == NULL) setparam(argptr); } break; /* "-" or "--" terminates options */ } } else if (c == '+') { val = 0; } else { argptr--; break; } while ((c = *p++) != '\0') { if (c == 'c' && cmdline) { char *q; #ifdef NOHACK /* removing this code allows sh -ce 'foo' for compat */ if (*p == '\0') #endif q = *argptr++; if (q == NULL || minusc != NULL) error("Bad -c option"); minusc = q; #ifdef NOHACK break; #endif } else if (c == 'o') { minus_o(*argptr, val); if (*argptr) argptr++; } else { if (c == 'p' && !val && privileged) { (void) setuid(getuid()); (void) setgid(getgid()); } setoption(c, val); } } } }
static int op_handler(int k, int *pos) { const struct termopt opt = {ASCII, "CP437 ASCII", "drawing"}; int i = *pos-2; if (i < 0) { if (k) { clearbox(0, 16, 0, 4); inputsetup_box(k-1, 1, 7); } draw_options_box(); return 1; } if (!i) { if (k == MVLEFT) i = 0; else if (k == MVRIGHT) i = 1; else { i = !getopt_int("", "fullscreen"); if (k == A_BTN) i = !i; else if (k) return 0; } printmenuitem_options("yes no", i); if (k) { union val v; v.integ = !i; setoption("", "fullscreen", v, 0); } i = 1; } else if (i == 1) { if (!k) { get_xy(&k, &i); setcurs(2, i+5); putnchars(HLINE, 28); help_alt_enter(); setcurs(k, i); k = 0; } i = term_optionhandler(k, &opt); } #ifndef NO_BLOCKSTYLES else i = select_blockstyle(k); #endif if (i == 3) { draw_tetris_logo(0, 0); draw_options_box(); } return i; }
static void setupoption(char *name, char *value, char *defaultvalue) { char *nargv[3]; int overbose; nargv[0] = "setupoption()"; nargv[1] = name; nargv[2] = (value ? value : defaultvalue); overbose = verbose; verbose = 0; setoption(3, nargv); verbose = overbose; }
STATIC int options(int cmdline) { char *p; int val; int c; int login = 0; if (cmdline) minusc = NULL; while ((p = *argptr) != NULL) { argptr++; if ((c = *p++) == '-') { val = 1; if (p[0] == '\0' || (p[0] == '-' && p[1] == '\0')) { if (!cmdline) { /* "-" means turn off -x and -v */ if (p[0] == '\0') xflag = vflag = 0; /* "--" means reset params */ else if (*argptr == NULL) setparam(argptr); } break; /* "-" or "--" terminates options */ } } else if (c == '+') { val = 0; } else { argptr--; break; } while ((c = *p++) != '\0') { if (c == 'c' && cmdline) { minusc = p; /* command is after shell args*/ } else if (c == 'l' && cmdline) { login = 1; } else if (c == 'o') { minus_o(*argptr, val); if (*argptr) argptr++; } else { setoption(c, val); } } } return login; }
int init(int argc, char **argv, global_options *options, list_node *test_list) { int i, ret = 0; #ifdef WIN32 DWORD attrs; #else struct stat buf; #endif srand((unsigned int) time(NULL)); /* Check the specified root directory */ #ifdef WIN32 attrs = GetFileAttributes(options->root_dir); /* root directory must be found */ if ((attrs == INVALID_FILE_ATTRIBUTES) || !(attrs & FILE_ATTRIBUTE_DIRECTORY)) return FALSE; #else ret = stat(options->root_dir, &buf); if (ret != 0 || !(S_ISDIR(buf.st_mode))) return FALSE; #endif /* option default */ options->report_flags = REPORT_CONSOLE; /* get options */ i = 2; while (i < argc) { if (argv[i][0] == '-') ret = setoption(argc, argv, options, &i); else add_list_node(test_list, argv[i], strlen(argv[i])+1); if (ret != 0) return FALSE; i++; } return TRUE; }
static int gm_mode(int k, int *pos) { const char *items[2] = {"A-type", "B-type"}; union val v; int i; int ret; v.integ = getopt_int("", "mode"); i = 1-!(v.integ & MODE_BTYPE); ret = selectitem(items, 2, &i, k); if (ret && k) { if (i) v.integ |= MODE_BTYPE; else v.integ &= ~MODE_BTYPE; setoption("", "mode", v, 0); } return ret; }
STATIC void minus_o(char *name, int val) { int doneset, i; if (name == NULL) { if (val) { /* "Pretty" output. */ out1str("Current option settings\n"); for (i = 0; i < NOPTS; i++) out1fmt("%-16s%s\n", optlist[i].name, optlist[i].val ? "on" : "off"); } else { /* Output suitable for re-input to shell. */ for (doneset = i = 0; i < NOPTS; i++) if (optlist[i].val) { if (!doneset) { out1str("set"); doneset = 1; } out1fmt(" -o %s", optlist[i].name); } if (doneset) out1c('\n'); } } else { for (i = 0; i < NOPTS; i++) if (equal(name, optlist[i].name)) { if (!val && privileged && equal(name, "privileged")) { (void) setuid(getuid()); (void) setgid(getgid()); } setoption(optlist[i].letter, val); return; } error("Illegal option -o %s", name); } }
static void parse_args(int argc, char **argv) { isc_boolean_t have_lookup = ISC_FALSE; usesearch = ISC_TRUE; for (argc--, argv++; argc > 0; argc--, argv++) { debug("main parsing %s", argv[0]); if (argv[0][0] == '-') { if (argv[0][1] != 0) setoption(&argv[0][1]); else have_lookup = ISC_TRUE; } else { if (!have_lookup) { have_lookup = ISC_TRUE; in_use = ISC_TRUE; addlookup(argv[0]); } else set_nameserver(argv[0]); } } }
int startup_menu(int i, int x, int y) { union val v; const char *menu[7] = { "1-Player Game", "2-Player Game", #ifdef INET "Netplay", #endif "Mode", "-------------", "Options", "Highscores" }; menuhandler handlers[7] = {0, 0, #ifdef INET 0, #endif gm_mode}; i = openmenu(menu, #ifdef INET 1 + #endif 6, i, x, y, handlers); if (i && i <= 3) { #ifdef INET if (i==3) v.integ = MODE_2PLAYER | MODE_NETWORK; else #endif v.integ = i; v.integ |= getopt_int("", "mode") & MODE_BTYPE; setoption("", "mode", v, 0); } return i; }
static int dofmt(Fmt_t* fp) { register int c; int b; int x; int splice; char* cp; char* dp; char* ep; char* lp; char* tp; char buf[8192]; cp = 0; while (cp || (cp = sfgetr(fp->in, '\n', 0)) && !(splice = 0) && (lp = cp + sfvalue(fp->in) - 1) || (cp = sfgetr(fp->in, '\n', SF_LASTR)) && (splice = 1) && (lp = cp + sfvalue(fp->in))) { if (isoption(fp, 'o')) { if (!isoption(fp, 'i')) { setoption(fp, 'i'); b = 0; while (cp < lp) { if (*cp == ' ') b += 1; else if (*cp == '\t') b += INDENT; else break; cp++; } fp->indent = roundof(b, INDENT); } else while (cp < lp && (*cp == ' ' || *cp == '\t')) cp++; if (!isoption(fp, 'q') && cp < lp) { setoption(fp, 'q'); if (*cp == '"') { ep = lp; while (--ep > cp) if (*ep == '"') { fp->quote = 1; break; } else if (*ep != ' ' && *ep != '\t') break; } } } again: dp = buf; ep = 0; for (b = 1;; b = 0) { if (cp >= lp) { cp = 0; break; } c = *cp++; if (isoption(fp, 'o')) { if (c == '\\') { x = 0; c = ' '; cp--; while (cp < lp) { if (*cp == '\\') { cp++; if ((lp - cp) < 1) { c = '\\'; break; } if (*cp == 'n') { cp++; c = '\n'; if ((lp - cp) > 2) { if (*cp == ']' || *cp == '@' && *(cp + 1) == '(') { *dp++ = '\\'; *dp++ = 'n'; c = *cp++; break; } if (*cp == '\\' && *(cp + 1) == 'n') { cp += 2; *dp++ = '\n'; break; } } } else if (*cp == 't' || *cp == ' ') { cp++; x = 1; c = ' '; } else { if (x && dp != buf && *(dp - 1) != ' ') *dp++ = ' '; *dp++ = '\\'; c = *cp++; break; } } else if (*cp == ' ' || *cp == '\t') { cp++; c = ' '; x = 1; } else { if (x && c != '\n' && dp != buf && *(dp - 1) != ' ') *dp++ = ' '; break; } } if (c == '\n') { c = 0; goto flush; } if (c == ' ' && (dp == buf || *(dp - 1) == ' ')) continue; } else if (c == '"') { if (b || cp >= lp) { if (fp->quote) continue; fp->section = 0; } } else if (c == '\a') { *dp++ = '\\'; c = 'a'; } else if (c == '\b') { *dp++ = '\\'; c = 'b'; } else if (c == '\f') { *dp++ = '\\'; c = 'f'; } else if (c == '\v') { *dp++ = '\\'; c = 'v'; } else if (c == ']' && (cp >= lp || *cp != ':' && *cp != '#' && *cp != '!')) { if (cp < lp && *cp == ']') { cp++; *dp++ = c; } else { fp->section = 1; fp->retain = 0; flush: *dp++ = c; *dp = 0; split(fp, buf, 0); outline(fp); goto again; } } else if (fp->section) { if (c == '[') { if (b) fp->retain = 1; else { cp--; c = 0; goto flush; } fp->section = 0; } else if (c == '{') { x = 1; for (tp = cp; tp < lp; tp++) { if (*tp == '[' || *tp == '\n') break; if (*tp == ' ' || *tp == '\t' || *tp == '"') continue; if (*tp == '\\' && (lp - tp) > 1) { if (*++tp == 'n') break; if (*tp == 't' || *tp == '\n') continue; } x = 0; break; } if (x) { if (fp->endbuf > (fp->outbuf + fp->indent + 2*INDENT)) fp->nextdent = 2*INDENT; goto flush; } else fp->section = 0; } else if (c == '}') { if (fp->indent && (b || *(cp - 2) != 'f')) { if (b) { fp->indent -= 2*INDENT; fp->endbuf += 2*INDENT; } else { cp--; c = 0; } goto flush; } else fp->section = 0; } else if (c == ' ' || c == '\t') continue; else fp->section = 0; } else if (c == '?' && (cp >= lp || *cp != '?')) { if (fp->retain) { cp--; while (cp < lp && *cp != ' ' && *cp != '\t' && *cp != ']' && dp < &buf[sizeof(buf)-3]) *dp++ = *cp++; if (cp < lp && (*cp == ' ' || *cp == '\t')) *dp++ = *cp++; *dp = 0; split(fp, buf, 0); dp = buf; ep = 0; fp->retain = 0; if (fp->outp >= fp->endbuf) outline(fp); continue; } } else if (c == ' ' || c == '\t') for (c = ' '; *cp == ' ' || *cp == '\t'; cp++); } else if (c == '\b') { if (dp > buf) { dp--; if (ep) ep--; } continue; } else if (c == '\t') { /* * expand tabs */ if (!ep) ep = dp; c = isoption(fp, 'o') ? 1 : TABSZ - (dp - buf) % TABSZ; if (dp >= &buf[sizeof(buf) - c - 3]) { cp--; break; } while (c-- > 0) *dp++ = ' '; continue; } else if (!isprint(c)) continue; if (dp >= &buf[sizeof(buf) - 3]) { tp = dp; while (--tp > buf) if (isspace(*tp)) { cp -= dp - tp; dp = tp; break; } ep = 0; break; } if (c != ' ') ep = 0; else if (!ep) ep = dp; *dp++ = c; } if (ep) *ep = 0; else *dp = 0; split(fp, buf, splice); } return 0; }
int main(int argc, char **argv) { struct stat st; netpgp_t netpgp; prog_t p; int homeset; int optindex; int ret; int ch; int i; (void) memset(&p, 0x0, sizeof(p)); (void) memset(&netpgp, 0x0, sizeof(netpgp)); homeset = 0; p.progname = argv[0]; p.numbits = DEFAULT_NUMBITS; if (argc < 2) { print_usage(usage, p.progname); exit(EXIT_ERROR); } /* set some defaults */ netpgp_setvar(&netpgp, "sshkeydir", "/etc/ssh"); netpgp_setvar(&netpgp, "res", "<stdout>"); netpgp_setvar(&netpgp, "hash", DEFAULT_HASH_ALG); netpgp_setvar(&netpgp, "format", "human"); optindex = 0; while ((ch = getopt_long(argc, argv, "S:Vglo:s", options, &optindex)) != -1) { if (ch >= LIST_KEYS) { /* getopt_long returns 0 for long options */ if (!setoption(&netpgp, &p, options[optindex].val, optarg, &homeset)) { (void) fprintf(stderr, "Bad setoption result %d\n", ch); } } else { switch (ch) { case 'S': netpgp_setvar(&netpgp, "ssh keys", "1"); netpgp_setvar(&netpgp, "sshkeyfile", optarg); break; case 'V': printf( "%s\nAll bug reports, praise and chocolate, please, to:\n%s\n", netpgp_get_info("version"), netpgp_get_info("maintainer")); exit(EXIT_SUCCESS); case 'g': p.cmd = GENERATE_KEY; break; case 'l': p.cmd = LIST_KEYS; break; case 'o': if (!parse_option(&netpgp, &p, optarg, &homeset)) { (void) fprintf(stderr, "Bad parse_option\n"); } break; case 's': p.cmd = LIST_SIGS; break; default: p.cmd = HELP_CMD; break; } } } if (!homeset) { netpgp_set_homedir(&netpgp, getenv("HOME"), netpgp_getvar(&netpgp, "ssh keys") ? "/.ssh" : "/.gnupg", 1); } /* initialise, and read keys from file */ if (!netpgp_init(&netpgp)) { if (stat(netpgp_getvar(&netpgp, "homedir"), &st) < 0) { (void) mkdir(netpgp_getvar(&netpgp, "homedir"), 0700); } if (stat(netpgp_getvar(&netpgp, "homedir"), &st) < 0) { (void) fprintf(stderr, "can't create home directory '%s'\n", netpgp_getvar(&netpgp, "homedir")); exit(EXIT_ERROR); } } /* now do the required action for each of the command line args */ ret = EXIT_SUCCESS; if (optind == argc) { if (!netpgp_cmd(&netpgp, &p, NULL)) { ret = EXIT_FAILURE; } } else { for (i = optind; i < argc; i++) { if (!netpgp_cmd(&netpgp, &p, argv[i])) { ret = EXIT_FAILURE; } } } netpgp_end(&netpgp); exit(ret); }
void getargs(void) { const char *str; char *envp; bool DVIfound; /* if a dvi filename found */ #if !defined(THINK_C) if (Argc <= 1) usage(ign); #endif pageswitchon = FALSE; /* show all pages */ sequenceon = FALSE; /* selected pages are TeX-numbered */ outputtofile = FALSE; /* write to stdout */ #if defined(THINK_C) inputfromfile = FALSE; /* read from stdin */ #endif #if !defined(MSDOS) && !defined(VMS) && !defined (THINK_C) && !defined(AMIGA) pager = WANTPAGER; /* want paging, compile time option */ #endif accent = TRUE; /* show all accent etc. as extra char */ ttfont = FALSE; /* assume tt font (verbatim mode) */ noffd = FALSE; /* print formfeed between pages */ scascii = DEFSCAND; /* scandinavian, compile time option */ latin1 = DEFLATIN1; /* latin1 support, compile time option */ ttywidth = 80; /* default terminal width */ espace = 0; /* to fake ttywith calcs */ DVIfound = FALSE; printfont = FALSE; /* do not print font switches */ allchar = FALSE; /* do not put out all characters */ #if !defined(MSDOS) && !defined(VMS) && !defined(THINK_C) && !defined(AMIGA) if ((path = getenv("PAGER")) == NULL) /* find default pathname of page */ path = DEFPAGER; /* program in case paging is wanted */ #endif /* * * With VAX-C under VMS getenv normally searches the environment array * looking for the variables HOME, TERM, PATH, and USER. In certain * situations getenv attempts to first perform a logical name translation * if none of the environment array strings are matched and then trying * to translate a CLI symbol. Unfortunately we need a CLI symbol defined * as; * * dvi2tty :== $path:dvi2tty.exe * * to invoke dvi2tty with command line arguments as it would be invoked * under Unix. So we use the logical DVI$DVI2TYY as the environment * variable from which options may be set. * */ /* * First process environment variable. */ #if defined(VMS) if ((envp = getenv("DVI$DVI2TTY")) != NULL) { #else if ((envp = getenv("DVI2TTY")) != NULL) { /* } keep vi happy */ #endif while (*envp == ' ') envp++; while (*envp) { /* environment var args */ if (strchr(OPTSET, optch = *envp++) != NULL) { /* * we always pass one option, and arrange for optarg ourselfes, * so setoption does not mesh up Argv */ if (strchr(OPTWARG, optch) != NULL) { while (*envp == ' ') envp++; if (*envp == '\0') usage(noarg); str = envp; /* str points to optarg */ while ((*envp != ' ') && (*envp != '\0')) envp++; /* set envp just after optarg */ if (*envp != '\0') *envp++ = '\0'; /* end optarg string */ } else str = ""; setoption(str); } else usage(bdopt); while (*envp == ' ') envp++; } } /* * Now process command line options. */ while (--Argc > 0) { /* command line args */ str = *++Argv; if (*str != '-') { /* argument is not an option */ if (DVIfound) /* only one dvi file allowed */ usage(onef); getfname(str); #if defined(THINK_C) inputfromfile = #endif DVIfound = TRUE; } else if (strchr(OPTSET, optch = *++str) != NULL) { str++; /* point to rest of argument if any */ if ((strchr(OPTWARG, optch) != NULL) && (*str == '\0')) { if (--Argc <= 0) usage(noarg); str = *++Argv; } setoption(str); } else usage(bdopt); } if (!DVIfound) #if defined(THINK_C) /* Allow use of stdin for */ if (isatty(fileno(stdin))) usage(nored); /* Mac, if redirected */ #else usage(ign); #endif return; } /* getargs */ /* * SETOPTION -- Process an option. */ void setoption(const char *optarg) { int j = 0; while (strchr(OPTSET, optch) != NULL) { switch (optch) { case 'h' : usage(ign); break; #if !defined(MSDOS) && !defined(VMS) && !defined(THINK_C) && !defined(AMIGA) case 'q' : pager = FALSE; break; case 'f' : pager = TRUE; break; case 'F' : pager = TRUE; path = optarg; j = strlen(optarg); break; #endif /* case 'J' : japan = TRUE; break; */ case 'J' : jautodetect = TRUE; break; case 'A' : asciip = TRUE; break; /* ASCII pTeX */ case 'N' : japan = TRUE; break; /* NTT jTeX */ case 't' : ttfont = TRUE; break; case 'l' : noffd = TRUE; break; case 's' : scascii ^= 1; break; case 'u' : latin1 ^= 1; break; case 'a' : accent = FALSE; break; case 'c' : allchar = TRUE; break; case 'P' : sequenceon = TRUE; /* fall through */ case 'p' : if (pageswitchon) usage(onepp); getpages(j, optarg); break; case 'w' : if (getinteger(&ttywidth, &j, optarg)) usage(nan); if (optarg[j] != '\0') usage(gae); if ((ttywidth < 16) || (ttywidth > MAXTERMWIDTH)) usage(wrnge); break; case 'e' : if (getinteger(&espace, &j, optarg)) usage(nan); if (optarg[j] != '\0') usage(gae); break; case 'v' : if (getlong(&lineheight, &j, optarg)) usage(nan); if (optarg[j] != '\0') usage(gae); /* lineheight *= 65536L; */ /* want to specify in pt, but have no getfloat */ break; case 'o' : OUTfilename = optarg; outputtofile = TRUE; j = strlen(optarg); break; case 'b' : printfont = TRUE; delim = optarg; if (!strlen(optarg)) printfont = FALSE; break; default : usage(bdopt); } if ((optch = optarg[j++]) == '\0') break; if ( (optarg[j] == '\0') && (strchr(OPTWARG, optch) != NULL) ) { if (--Argc <= 0) usage(noarg); optarg = *++Argv; j = 0; } } /* Option conflict */ if (japan && asciip) { usage(confl); } if (jautodetect && (japan || asciip)) { usage(confj); } return; } /* setoption */
int main(int argc, char **argv) { netpgp_t netpgp; prog_t p; int homeset; int optindex; int ret; int ch; int i; (void) memset(&p, 0x0, sizeof(p)); (void) memset(&netpgp, 0x0, sizeof(netpgp)); p.progname = argv[0]; p.overwrite = 1; p.output = NULL; if (argc < 2) { print_usage(usage, p.progname); exit(EXIT_ERROR); } /* set some defaults */ netpgp_setvar(&netpgp, "hash", DEFAULT_HASH_ALG); /* 4 MiB for a memory file */ netpgp_setvar(&netpgp, "max mem alloc", "4194304"); homeset = 0; optindex = 0; while ((ch = getopt_long(argc, argv, "S:Vdeo:sv", options, &optindex)) != -1) { if (ch >= ENCRYPT) { /* getopt_long returns 0 for long options */ if (!setoption(&netpgp, &p, options[optindex].val, optarg, &homeset)) { (void) fprintf(stderr, "Bad option\n"); } } else { switch (ch) { case 'S': netpgp_setvar(&netpgp, "ssh keys", "1"); netpgp_setvar(&netpgp, "sshkeyfile", optarg); break; case 'V': printf( "%s\nAll bug reports, praise and chocolate, please, to:\n%s\n", netpgp_get_info("version"), netpgp_get_info("maintainer")); exit(EXIT_SUCCESS); case 'd': /* for decryption, we need the seckey */ netpgp_setvar(&netpgp, "need seckey", "1"); p.cmd = DECRYPT; break; case 'e': /* for encryption, we need a userid */ netpgp_setvar(&netpgp, "need userid", "1"); p.cmd = ENCRYPT; break; case 'o': if (!parse_option(&netpgp, &p, optarg, &homeset)) { (void) fprintf(stderr, "Bad option\n"); } break; case 's': /* for signing, we need a userid and a seckey */ netpgp_setvar(&netpgp, "need seckey", "1"); netpgp_setvar(&netpgp, "need userid", "1"); p.cmd = SIGN; break; case 'v': p.cmd = VERIFY; break; default: p.cmd = HELP_CMD; break; } } } if (!homeset) { netpgp_set_homedir(&netpgp, getenv("HOME"), netpgp_getvar(&netpgp, "ssh keys") ? "/.ssh" : "/.gnupg", 1); } /* initialise, and read keys from file */ if (!netpgp_init(&netpgp)) { printf("can't initialise\n"); exit(EXIT_ERROR); } /* now do the required action for each of the command line args */ ret = EXIT_SUCCESS; if (optind == argc) { if (!netpgp_cmd(&netpgp, &p, NULL)) { ret = EXIT_FAILURE; } } else { for (i = optind; i < argc; i++) { if (!netpgp_cmd(&netpgp, &p, argv[i])) { ret = EXIT_FAILURE; } } } netpgp_end(&netpgp); exit(ret); }
int b_fmt(int argc, char** argv, void *context) { register int n; char* cp; Fmt_t fmt; char outbuf[8 * 1024]; fmt.flags = 0; fmt.out = sfstdout; fmt.outbuf = outbuf; fmt.outp = 0; fmt.endbuf = &outbuf[72]; fmt.indent = 0; fmt.nextdent = 0; fmt.nwords = 0; fmt.prefix = 0; fmt.quote = 0; fmt.retain = 0; fmt.section = 1; cmdinit(argc, argv, context, ERROR_CATALOG, 0); for (;;) { switch (n = optget(argv, usage)) { case 'c': case 'o': case 's': case 'u': setoption(&fmt, n); continue; case 'w': if (opt_info.num < TABSZ || opt_info.num>= sizeof(outbuf)) error(2, "width out of range"); fmt.endbuf = &outbuf[opt_info.num]; continue; case ':': error(2, "%s", opt_info.arg); break; case '?': error(ERROR_usage(2), "%s", opt_info.arg); break; } break; } argv += opt_info.index; if (error_info.errors) error(ERROR_usage(2), "%s", optusage(NiL)); if (isoption(&fmt, 'o')) setoption(&fmt, 'c'); if (isoption(&fmt, 's')) clroption(&fmt, 'u'); if (cp = *argv) argv++; do { if (!cp || streq(cp, "-")) fmt.in = sfstdin; else if (!(fmt.in = sfopen(NiL, cp, "r"))) { error(ERROR_system(0), "%s: cannot open", cp); error_info.errors = 1; continue; } dofmt(&fmt); if (fmt.in != sfstdin) sfclose(fmt.in); } while (cp = *argv++); outline(&fmt); if (sfsync(sfstdout)) error(ERROR_system(0), "write error"); return error_info.errors != 0; }
static void options(int cmdline) { char *kp, *p; int val; int c; if (cmdline) minusc = NULL; while ((p = *argptr) != NULL) { argptr++; if ((c = *p++) == '-') { val = 1; /* A "-" or "--" terminates options */ if (p[0] == '\0') goto end_options1; if (p[0] == '-' && p[1] == '\0') goto end_options2; /** * For the benefit of `#!' lines in shell scripts, * treat a string of '-- *#.*' the same as '--'. * This is needed so that a script starting with: * #!/bin/sh -- # -*- perl -*- * will continue to work after a change is made to * kern/imgact_shell.c to NOT token-ize the options * specified on a '#!' line. A bit of a kludge, * but that trick is recommended in documentation * for some scripting languages, and we might as * well continue to support it. */ if (p[0] == '-') { kp = p + 1; while (*kp == ' ' || *kp == '\t') kp++; if (*kp == '#' || *kp == '\0') goto end_options2; } } else if (c == '+') { val = 0; } else { argptr--; break; } while ((c = *p++) != '\0') { if (c == 'c' && cmdline) { char *q; #ifdef NOHACK /* removing this code allows sh -ce 'foo' for compat */ if (*p == '\0') #endif q = *argptr++; if (q == NULL || minusc != NULL) error("Bad -c option"); minusc = q; #ifdef NOHACK break; #endif } else if (c == 'o') { minus_o(*argptr, val); if (*argptr) argptr++; } else setoption(c, val); } } return; /* When processing `set', a single "-" means turn off -x and -v */ end_options1: if (!cmdline) { xflag = vflag = 0; return; } /* * When processing `set', a "--" means the remaining arguments * replace the positional parameters in the active shell. If * there are no remaining options, then all the positional * parameters are cleared (equivalent to doing ``shift $#''). */ end_options2: if (!cmdline) { if (*argptr == NULL) setparam(argptr); return; } /* * At this point we are processing options given to 'sh' on a command * line. If an end-of-options marker ("-" or "--") is followed by an * arg of "#", then skip over all remaining arguments. Some scripting * languages (e.g.: perl) document that /bin/sh will implement this * behavior, and they recommend that users take advantage of it to * solve certain issues that can come up when writing a perl script. * Yes, this feature is in /bin/sh to help users write perl scripts. */ p = *argptr; if (p != NULL && p[0] == '#' && p[1] == '\0') { while (*argptr != NULL) argptr++; /* We need to keep the final argument */ argptr--; } }