mod_export int optlookup(char const *name) { char *s, *t; Optname n; s = t = dupstring(name); /* exorcise underscores, and change to lowercase */ while (*t) if (*t == '_') chuck(t); else { /* * Some locales (in particular tr_TR.UTF-8) may * have non-standard mappings of ASCII characters, * so be careful. Option names must be ASCII so * we don't need to be too clever. */ if (*t >= 'A' && *t <= 'Z') *t = (*t - 'A') + 'a'; t++; } /* look up name in the table */ if (s[0] == 'n' && s[1] == 'o' && (n = (Optname) optiontab->getnode(optiontab, s + 2))) { return -n->optno; } else if ((n = (Optname) optiontab->getnode(optiontab, s))) return n->optno; else return OPT_INVALID; }
mod_export int optlookup(char const *name) { char *s, *t; Optname n; s = t = dupstring(name); /* exorcise underscores, and change to lowercase */ while (*t) if (*t == '_') chuck(t); else { *t = tulower(*t); t++; } /* look up name in the table */ if (s[0] == 'n' && s[1] == 'o' && (n = (Optname) optiontab->getnode(optiontab, s + 2))) { return -n->optno; } else if ((n = (Optname) optiontab->getnode(optiontab, s))) return n->optno; else return OPT_INVALID; }
int bin_setopt(char *nam, char **args, UNUSED(Options ops), int isun) { int action, optno, match = 0; /* With no arguments or options, display options. */ if (!*args) { scanhashtable(optiontab, 1, 0, OPT_ALIAS, optiontab->printnode, !isun); return 0; } /* loop through command line options (begins with "-" or "+") */ while (*args && (**args == '-' || **args == '+')) { action = (**args == '-') ^ isun; if(!args[0][1]) *args = "--"; while (*++*args) { if(**args == Meta) *++*args ^= 32; /* The pseudo-option `--' signifies the end of options. */ if (**args == '-') { args++; goto doneoptions; } else if (**args == 'o') { if (!*++*args) args++; if (!*args) { zwarnnam(nam, "string expected after -o"); inittyptab(); return 1; } if(!(optno = optlookup(*args))) zwarnnam(nam, "no such option: %s", *args); else if(dosetopt(optno, action, 0, opts)) zwarnnam(nam, "can't change option: %s", *args); break; } else if(**args == 'm') { match = 1; } else { if (!(optno = optlookupc(**args))) zwarnnam(nam, "bad option: -%c", **args); else if(dosetopt(optno, action, 0, opts)) zwarnnam(nam, "can't change option: -%c", **args); } } args++; } doneoptions: if (!match) { /* Not globbing the arguments -- arguments are simply option names. */ while (*args) { if(!(optno = optlookup(*args++))) zwarnnam(nam, "no such option: %s", args[-1]); else if(dosetopt(optno, !isun, 0, opts)) zwarnnam(nam, "can't change option: %s", args[-1]); } } else { /* Globbing option (-m) set. */ while (*args) { Patprog pprog; char *s, *t; t = s = dupstring(*args); while (*t) if (*t == '_') chuck(t); else { /* See comment in optlookup() */ if (*t >= 'A' && *t <= 'Z') *t = (*t - 'A') + 'a'; t++; } /* Expand the current arg. */ tokenize(s); if (!(pprog = patcompile(s, PAT_STATIC, NULL))) { zwarnnam(nam, "bad pattern: %s", *args); continue; } /* Loop over expansions. */ scanmatchtable(optiontab, pprog, 0, 0, OPT_ALIAS, setoption, !isun); args++; } } inittyptab(); return 0; }
static int lexconstant(void) { #ifdef USE_LOCALE char *prev_locale; #endif char *nptr; nptr = ptr; if (*nptr == '-') nptr++; if (*nptr == '0') { int lowchar; nptr++; lowchar = tolower(*nptr); if (lowchar == 'x' || lowchar == 'b') { /* Let zstrtol parse number with base */ yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1); /* Should we set lastbase here? */ lastbase = (lowchar == 'b') ? 2 : 16; if (isset(FORCEFLOAT)) { yyval.type = MN_FLOAT; yyval.u.d = (double)yyval.u.l; } return NUM; } else if (isset(OCTALZEROES)) { char *ptr2; /* * Make sure this is a real octal constant; * it can't be a base indication (always decimal) * or a floating point number. */ for (ptr2 = nptr; idigit(*ptr2) || *ptr2 == '_'; ptr2++) ; if (ptr2 > nptr && *ptr2 != '.' && *ptr2 != 'e' && *ptr2 != 'E' && *ptr2 != '#') { yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1); lastbase = 8; if (isset(FORCEFLOAT)) { yyval.type = MN_FLOAT; yyval.u.d = (double)yyval.u.l; } return NUM; } nptr = ptr2; } } while (idigit(*nptr) || *nptr == '_') nptr++; if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') { char *ptr2; /* it's a float */ yyval.type = MN_FLOAT; #ifdef USE_LOCALE prev_locale = dupstring(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "POSIX"); #endif if (*nptr == '.') { nptr++; while (idigit(*nptr) || *nptr == '_') nptr++; } if (*nptr == 'e' || *nptr == 'E') { nptr++; if (*nptr == '+' || *nptr == '-') nptr++; while (idigit(*nptr) || *nptr == '_') nptr++; } for (ptr2 = ptr; ptr2 < nptr; ptr2++) { if (*ptr2 == '_') { int len = nptr - ptr; ptr = strdup(ptr); for (ptr2 = ptr; len; len--) { if (*ptr2 == '_') chuck(ptr2); else ptr2++; } break; } } yyval.u.d = strtod(ptr, &nptr); #ifdef USE_LOCALE if (prev_locale) setlocale(LC_NUMERIC, prev_locale); #endif if (ptr == nptr || *nptr == '.') { zerr("bad floating point constant"); return EOI; } ptr = nptr; } else { /* it's an integer */ yyval.u.l = zstrtol_underscore(ptr, &ptr, 10, 1); if (*ptr == '#') { ptr++; lastbase = yyval.u.l; yyval.u.l = zstrtol_underscore(ptr, &ptr, lastbase, 1); } if (isset(FORCEFLOAT)) { yyval.type = MN_FLOAT; yyval.u.d = (double)yyval.u.l; } } return NUM; }
mod_export char * promptexpand(char *s, int ns, char *rs, char *Rs, unsigned int *txtchangep) { struct buf_vars new_vars; if(!s) return ztrdup(""); if ((termflags & TERM_UNKNOWN) && (unset(INTERACTIVE))) init_term(); if (isset(PROMPTSUBST)) { int olderr = errflag; int oldval = lastval; s = dupstring(s); if (!parsestr(s)) singsub(&s); /* * We don't need the special Nularg hack here and we're * going to be using Nularg for other things. */ if (*s == Nularg && s[1] == '\0') *s = '\0'; /* Ignore errors and status change in prompt substitution */ errflag = olderr; lastval = oldval; } memset(&new_vars, 0, sizeof(new_vars)); new_vars.last = bv; bv = &new_vars; new_vars.rstring = rs; new_vars.Rstring = Rs; new_vars.fm = s; new_vars.bufspc = 256; new_vars.bp = new_vars.bufline = new_vars.buf = zshcalloc(new_vars.bufspc); new_vars.bp1 = NULL; new_vars.truncwidth = 0; putpromptchar(1, '\0', txtchangep); addbufspc(2); if (new_vars.dontcount) *new_vars.bp++ = Outpar; *new_vars.bp = '\0'; if (!ns) { /* If zero, Inpar, Outpar and Nularg should be removed. */ for (new_vars.bp = new_vars.buf; *new_vars.bp; ) { if (*new_vars.bp == Meta) new_vars.bp += 2; else if (*new_vars.bp == Inpar || *new_vars.bp == Outpar || *new_vars.bp == Nularg) chuck(new_vars.bp); else new_vars.bp++; } } bv = new_vars.last; return new_vars.buf; }