diff --git a/edit.c b/edit.c index 45f6342..a43104f 100644 --- a/edit.c +++ b/edit.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.197 2010/08/28 16:47:08 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.198 2010/08/28 18:50:47 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -324,7 +324,7 @@ x_file_glob(int flags MKSH_A_UNUSED, const char *str, int slen, char ***wordsp) source = s; if (yylex(ONEWORD | LQCHAR) != LWORD) { source = sold; - internal_warningf("fileglob: substitute error"); + internal_warningf("%s: %s", "fileglob", "substitute error"); return (0); } source = sold; @@ -2403,7 +2403,7 @@ x_bind(const char *a1, const char *a2, m1 = msg + strlen(msg); while (*c && m1 < (msg + sizeof(msg) - 3)) x_mapout2(*c++, &m1); - bi_errorf("%s' too long", msg); + bi_errorf("'%s' too long", msg); return (1); } #ifndef MKSH_SMALL @@ -2428,7 +2428,7 @@ x_bind(const char *a1, const char *a2, strcmp(x_ftab[f].xf_name, a2) == 0) break; if (f == NELEM(x_ftab) || x_ftab[f].xf_flags & XF_NOBIND) { - bi_errorf("%s: no such function", a2); + bi_errorf("%s: %s", a2, "no such function"); return (1); } } @@ -4811,7 +4811,7 @@ grabhist(int save, int n) } (void)histnum(n); if ((hptr = *histpos()) == NULL) { - internal_warningf("grabhist: bad history array"); + internal_warningf("%s: %s", "grabhist", "bad history array"); return (-1); } if (save) diff --git a/eval.c b/eval.c index c22e346..52935b4 100644 --- a/eval.c +++ b/eval.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.90 2010/07/17 22:09:33 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.91 2010/08/28 18:50:49 tg Exp $"); /* * string expansion @@ -334,7 +334,7 @@ expand(const char *cp, /* input word */ *end = EOS; str = snptreef(NULL, 64, "%S", beg); afree(beg, ATEMP); - errorf("%s: bad substitution", str); + errorf("%s: %s", str, "bad substitution"); } if (f & DOBLANK) doblank++; @@ -974,7 +974,7 @@ varsub(Expand *xp, const char *sp, const char *word, } } if (Flag(FNOUNSET) && c == 0 && !zero_ok) - errorf("%s: parameter not set", sp); + errorf("%s: %s", sp, "parameter not set"); *stypep = 0; /* unqualified variable/string substitution */ xp->str = shf_smprintf("%d", c); return (XSUB); @@ -1105,7 +1105,7 @@ varsub(Expand *xp, const char *sp, const char *word, state = XBASE; /* expand word instead of variable value */ if (Flag(FNOUNSET) && xp->str == null && !zero_ok && (ctype(c, C_SUBOP2) || (state != XBASE && c != '+'))) - errorf("%s: parameter not set", sp); + errorf("%s: %s", sp, "parameter not set"); return (state); } @@ -1135,12 +1135,12 @@ comsub(Expand *xp, const char *cp) char *name; if ((io->flag&IOTYPE) != IOREAD) - errorf("funny $() command: %s", + errorf("%s: %s", "funny $() command", snptreef(NULL, 32, "%R", io)); shf = shf_open(name = evalstr(io->name, DOTILDE), O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC); if (shf == NULL) - errorf("%s: cannot open $() input", name); + errorf("%s: %s", name, "cannot open $() input"); xp->split = 0; /* no waitlast() */ } else { int ofd1, pv[2]; diff --git a/exec.c b/exec.c index fd12eeb..1386e09 100644 --- a/exec.c +++ b/exec.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.78 2010/08/28 17:21:43 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.79 2010/08/28 18:50:49 tg Exp $"); #ifndef MKSH_DEFAULT_EXECSHELL #define MKSH_DEFAULT_EXECSHELL "/bin/sh" @@ -450,7 +450,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, } tp = findcom(cp, FC_BI); if (tp == NULL) - errorf("builtin: %s: not a builtin", cp); + errorf("%s: %s: %s", T_builtin, cp, "not a builtin"); continue; } else if (tp->val.f == c_exec) { if (ap[1] == NULL) @@ -472,8 +472,8 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, fcflags = FC_BI|FC_PATH; if (saw_p) { if (Flag(FRESTRICTED)) { - warningf(true, - "command -p: restricted"); + warningf(true, "%s: %s", + "command -p", "restricted"); rv = 1; goto Leave; } @@ -551,7 +551,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, goto Leave; } else if (!tp) { if (Flag(FRESTRICTED) && vstrchr(cp, '/')) { - warningf(true, "%s: restricted", cp); + warningf(true, "%s: %s", cp, "restricted"); rv = 1; goto Leave; } @@ -573,15 +573,13 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, if (!tp->u.fpath) { if (tp->u2.errno_) { - warningf(true, - "%s: can't find function " - "definition file - %s", - cp, strerror(tp->u2.errno_)); + warningf(true, "%s: %s: %s", cp, + "can't find function definition file", + strerror(tp->u2.errno_)); rv = 126; } else { - warningf(true, - "%s: can't find function " - "definition file", cp); + warningf(true, "%s: %s", cp, + "can't find function definition file"); rv = 127; } break; @@ -589,16 +587,15 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, if (include(tp->u.fpath, 0, NULL, 0) < 0) { rv = errno; warningf(true, - "%s: can't open function definition file %s - %s", + "%s: can't open function definition file %s: %s", cp, tp->u.fpath, strerror(rv)); rv = 127; break; } if (!(ftp = findfunc(cp, hash(cp), false)) || !(ftp->flag & ISSET)) { - warningf(true, - "%s: function not defined by %s", - cp, tp->u.fpath); + warningf(true, "%s: %s %s", cp, + "function not defined by", tp->u.fpath); rv = 127; break; } @@ -681,11 +678,11 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, * useful error message and set the exit status to 126. */ if (tp->u2.errno_) { - warningf(true, "%s: cannot execute - %s", cp, - strerror(tp->u2.errno_)); + warningf(true, "%s: %s: %s", cp, + "cannot execute", strerror(tp->u2.errno_)); rv = 126; /* POSIX */ } else { - warningf(true, "%s: not found", cp); + warningf(true, "%s: %s", cp, "not found"); rv = 127; } break; @@ -822,7 +819,7 @@ shcomexec(const char **wp) tp = ktsearch(&builtins, *wp, hash(*wp)); if (tp == NULL) - internal_errorf("shcomexec: %s", *wp); + internal_errorf("%s: %s", "shcomexec", *wp); return (call_builtin(tp, wp)); } @@ -1198,7 +1195,7 @@ iosetup(struct ioword *iop, struct tbl *tp) if (do_open) { if (Flag(FRESTRICTED) && (flags & O_CREAT)) { - warningf(true, "%s: restricted", cp); + warningf(true, "%s: %s", cp, "restricted"); return (-1); } u = open(cp, flags, 0666); @@ -1237,7 +1234,7 @@ iosetup(struct ioword *iop, struct tbl *tp) ev = errno; warningf(true, - "could not finish (dup) redirection %s: %s", + "%s %s %s", "could not finish (dup) redirection", snptreef(NULL, 32, "%R", &iotmp), strerror(ev)); if (iotype != IODUP) @@ -1309,7 +1306,7 @@ herein(const char *content, int sub) s->start = s->str = content; source = s; if (yylex(ONEWORD|HEREDOC) != LWORD) - internal_errorf("herein: yylex"); + internal_errorf("%s: %s", "herein", "yylex"); source = osource; shf_puts(evalstr(yylval.cp, 0), shf); } else diff --git a/expr.c b/expr.c index 6c5710c..7acc177 100644 --- a/expr.c +++ b/expr.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.44 2010/08/14 21:35:13 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.45 2010/08/28 18:50:50 tg Exp $"); /* The order of these enums is constrained by the order of opinfo[] */ enum token { @@ -269,26 +269,28 @@ evalerr(Expr_state *es, enum error_type type, const char *str) default: s = opinfo[(int)es->tok].name; } - warningf(true, "%s: unexpected '%s'", es->expression, s); + warningf(true, "%s: %s '%s'", es->expression, + "unexpected", s); break; case ET_BADLIT: - warningf(true, "%s: bad number '%s'", es->expression, str); + warningf(true, "%s: %s '%s'", es->expression, + "bad number", str); break; case ET_RECURSIVE: - warningf(true, "%s: expression recurses on parameter '%s'", - es->expression, str); + warningf(true, "%s: %s '%s'", es->expression, + "expression recurses on parameter", str); break; case ET_LVALUE: - warningf(true, "%s: %s requires lvalue", - es->expression, str); + warningf(true, "%s: %s %s", + es->expression, str, "requires lvalue"); break; case ET_RDONLY: - warningf(true, "%s: %s applied to read only variable", - es->expression, str); + warningf(true, "%s: %s %s", + es->expression, str, "applied to read only variable"); break; default: /* keep gcc happy */ diff --git a/funcs.c b/funcs.c index 606aa51..68e8a37 100644 --- a/funcs.c +++ b/funcs.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.158 2010/08/28 17:21:44 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.159 2010/08/28 18:50:51 tg Exp $"); #if HAVE_KILLPG /* @@ -59,14 +59,14 @@ const struct builtin mkshbuiltins[] = { {"*=:", c_label}, {"[", c_test}, {"*=break", c_brkcont}, - {"=builtin", c_builtin}, + {T_gbuiltin, c_builtin}, {"*=continue", c_brkcont}, {"*=eval", c_eval}, {"*=exec", c_exec}, {"*=exit", c_exitreturn}, {"+false", c_label}, {"*=return", c_exitreturn}, - {"*=set", c_set}, + {T_sgset, c_set}, {"*=shift", c_shift}, {"=times", c_times}, {"*=trap", c_trap}, @@ -77,7 +77,7 @@ const struct builtin mkshbuiltins[] = { {"ulimit", c_ulimit}, {"+umask", c_umask}, {"*=unset", c_unset}, - {"+alias", c_alias}, /* no =: AT&T manual wrong */ + {T_palias, c_alias}, /* no =: AT&T manual wrong */ {"+cd", c_cd}, {"chdir", c_cd}, /* dash compatibility hack */ {"+command", c_command}, @@ -95,7 +95,7 @@ const struct builtin mkshbuiltins[] = { {"pwd", c_pwd}, {"*=readonly", c_typeset}, {T__typeset, c_typeset}, - {"+unalias", c_unalias}, + {T_punalias, c_unalias}, {"whence", c_whence}, #ifndef MKSH_UNEMPLOYED {"+bg", c_fgbg}, @@ -447,9 +447,9 @@ c_cd(const char **wp) if (rv < 0) { if (cdnode) - bi_errorf("%s: bad directory", dir); + bi_errorf("%s: %s", dir, "bad directory"); else - bi_errorf("%s - %s", tryp, strerror(errno)); + bi_errorf("%s: %s", tryp, strerror(errno)); afree(allocd, ATEMP); return (1); } @@ -521,7 +521,7 @@ c_pwd(const char **wp) if (p && access(p, R_OK) < 0) p = NULL; if (!p && !(p = allocd = ksh_get_wd(NULL))) { - bi_errorf("can't get current directory - %s", strerror(errno)); + bi_errorf("%s: %s", "can't get current directory", strerror(errno)); return (1); } shprintf("%s\n", p); @@ -613,7 +613,7 @@ c_print(const char **wp) break; case 'p': if ((fd = coproc_getfd(W_OK, &emsg)) < 0) { - bi_errorf("-p: %s", emsg); + bi_errorf("%s: %s", "-p", emsg); return (1); } break; @@ -627,7 +627,7 @@ c_print(const char **wp) if (!*(s = builtin_opt.optarg)) fd = 0; else if ((fd = check_fd(s, W_OK, &emsg)) < 0) { - bi_errorf("-u: %s: %s", s, emsg); + bi_errorf("%s: %s: %s", "-u", s, emsg); return (1); } break; @@ -796,22 +796,32 @@ c_whence(const char **wp) if (vflag || (tp->type != CALIAS && tp->type != CEXEC && tp->type != CTALIAS)) shf_puts(id, shl_stdout); + if (vflag) + switch (tp->type) { + case CKEYWD: + case CALIAS: + case CFUNC: + case CSHELL: + shf_puts(" is a", shl_stdout); + break; + } + switch (tp->type) { case CKEYWD: if (vflag) - shf_puts(" is a reserved word", shl_stdout); + shf_puts(" reserved word", shl_stdout); break; case CALIAS: if (vflag) - shprintf(" is an %salias for ", - (tp->flag & EXPORT) ? "exported " : null); + shprintf("n %s%s for ", + (tp->flag & EXPORT) ? "exported " : null, + T_alias); if (!iam_whence && !vflag) - shprintf("alias %s=", id); + shprintf("%s %s=", T_alias, id); print_value_quoted(tp->val.s); break; case CFUNC: if (vflag) { - shf_puts(" is a", shl_stdout); if (tp->flag & EXPORT) shf_puts("n exported", shl_stdout); if (tp->flag & TRACE) @@ -827,8 +837,9 @@ c_whence(const char **wp) break; case CSHELL: if (vflag) - shprintf(" is a%s shell builtin", - (tp->flag & SPEC_BI) ? " special" : null); + shprintf("%s %s %s", + (tp->flag & SPEC_BI) ? " special" : null, + "shell", T_builtin); break; case CTALIAS: case CEXEC: @@ -836,14 +847,15 @@ c_whence(const char **wp) if (vflag) { shf_puts(" is ", shl_stdout); if (tp->type == CTALIAS) - shprintf("a tracked %salias for ", + shprintf("a tracked %s%s for ", (tp->flag & EXPORT) ? - "exported " : null); + "exported " : null, + T_alias); } shf_puts(tp->val.s, shl_stdout); } else { if (vflag) - shf_puts(" not found", shl_stdout); + shprintf(" %s\n", "not found"); rv = 1; } break; @@ -1051,7 +1063,7 @@ c_typeset(const char **wp) "function %s %T\n" : "%s() %T\n", wp[i], f->val.t); } else if (!typeset(wp[i], fset, fclr, field, base)) { - bi_errorf("%s: not identifier", wp[i]); + bi_errorf("%s: %s", wp[i], "not identifier"); set_refflag = 0; return (1); } @@ -1120,27 +1132,27 @@ c_typeset(const char **wp) */ shf_puts("typeset ", shl_stdout); if (((vp->flag&(ARRAY|ASSOC))==ASSOC)) - shf_puts("-n ", shl_stdout); + shprintf("%s ", "-n"); if ((vp->flag&INTEGER)) - shf_puts("-i ", shl_stdout); + shprintf("%s ", "-i"); if ((vp->flag&EXPORT)) - shf_puts("-x ", shl_stdout); + shprintf("%s ", "-x"); if ((vp->flag&RDONLY)) - shf_puts("-r ", shl_stdout); + shprintf("%s ", "-r"); if ((vp->flag&TRACE)) - shf_puts("-t ", shl_stdout); + shprintf("%s ", "-t"); if ((vp->flag&LJUST)) shprintf("-L%d ", vp->u2.field); if ((vp->flag&RJUST)) shprintf("-R%d ", vp->u2.field); if ((vp->flag&ZEROFIL)) - shf_puts("-Z ", shl_stdout); + shprintf("%s ", "-Z"); if ((vp->flag&LCASEV)) - shf_puts("-l ", shl_stdout); + shprintf("%s ", "-l"); if ((vp->flag&UCASEV_AL)) - shf_puts("-u ", shl_stdout); + shprintf("%s ", "-u"); if ((vp->flag&INT_U)) - shf_puts("-U ", shl_stdout); + shprintf("%s ", "-U"); shf_puts(vp->name, shl_stdout); if (pflag) { char *s = str_val(vp); @@ -1259,12 +1271,12 @@ c_alias(const char **wp) /* "hash -r" means reset all the tracked aliases.. */ if (rflag) { static const char *args[] = { - "unalias", "-ta", NULL + T_unalias, "-ta", NULL }; if (!tflag || *wp) { - shf_puts("alias: -r flag can only be used with -t" - " and without arguments\n", shl_stdout); + shprintf("%s: -r flag can only be used with -t" + " and without arguments\n", T_alias); return (1); } ksh_getopt_reset(&builtin_opt, GF_ERROR); @@ -1277,7 +1289,7 @@ c_alias(const char **wp) for (p = ktsort(t); (ap = *p++) != NULL; ) if ((ap->flag & (ISSET|xflag)) == (ISSET|xflag)) { if (pflag) - shf_puts("alias ", shl_stdout); + shprintf("%s ", T_alias); shf_puts(ap->name, shl_stdout); if (prefix != '+') { shf_putc('=', shl_stdout); @@ -1302,7 +1314,7 @@ c_alias(const char **wp) ap = ktsearch(t, alias, h); if (ap != NULL && (ap->flag&ISSET)) { if (pflag) - shf_puts("alias ", shl_stdout); + shprintf("%s ", T_alias); shf_puts(ap->name, shl_stdout); if (prefix != '+') { shf_putc('=', shl_stdout); @@ -1310,7 +1322,8 @@ c_alias(const char **wp) } shf_putc('\n', shl_stdout); } else { - shprintf("%s alias not found\n", alias); + shprintf("%s %s %s\n", alias, T_alias, + "not found"); rv = 1; } continue; @@ -1583,8 +1596,8 @@ c_kill(const char **wp) if (j_kill(p, sig)) rv = 1; } else if (!getn(p, &n)) { - bi_errorf("%s: arguments must be jobs or process IDs", - p); + bi_errorf("%s: %s", p, + "arguments must be jobs or process IDs"); rv = 1; } else { if (mksh_kill(n, sig) < 0) { @@ -1619,22 +1632,22 @@ c_getopts(const char **wp) opts = *wp++; if (!opts) { - bi_errorf("missing options argument"); + bi_errorf("missing %s argument", "options"); return (1); } var = *wp++; if (!var) { - bi_errorf("missing name argument"); + bi_errorf("missing %s argument", "name"); return (1); } if (!*var || *skip_varname(var, true)) { - bi_errorf("%s: is not an identifier", var); + bi_errorf("%s: %s", var, "is not an identifier"); return (1); } if (e->loc->next == NULL) { - internal_warningf("c_getopts: no argv"); + internal_warningf("%s: %s", "c_getopts", "no argv"); return (1); } /* Which arguments are we parsing... */ @@ -1777,7 +1790,7 @@ c_shift(const char **wp) } else n = 1; if (n < 0) { - bi_errorf("%s: bad number", arg); + bi_errorf("%s: %s", arg, "bad number"); return (1); } if (l->argc < n) { @@ -1995,7 +2008,7 @@ c_read(const char **wp) switch (optc) { case 'p': if ((fd = coproc_getfd(R_OK, &emsg)) < 0) { - bi_errorf("-p: %s", emsg); + bi_errorf("%s: %s", "-p", emsg); return (1); } break; @@ -2009,7 +2022,7 @@ c_read(const char **wp) if (!*(cp = builtin_opt.optarg)) fd = 0; else if ((fd = check_fd(cp, R_OK, &emsg)) < 0) { - bi_errorf("-u: %s: %s", cp, emsg); + bi_errorf("%s: %s: %s", "-u", cp, emsg); return (1); } break; @@ -2240,7 +2253,7 @@ c_trap(const char **wp) while (*wp != NULL) { p = gettrap(*wp++, true); if (p == NULL) { - bi_errorf("bad signal %s", wp[-1]); + bi_errorf("bad signal '%s'", wp[-1]); return (1); } settrap(p, s); @@ -2261,7 +2274,7 @@ c_exitreturn(const char **wp) if (arg) { if (!getn(arg, &n)) { exstat = 1; - warningf(true, "%s: bad number", arg); + warningf(true, "%s: %s", arg, "bad number"); } else exstat = n; } @@ -2306,7 +2319,7 @@ c_brkcont(const char **wp) quit = n; if (quit <= 0) { /* AT&T ksh does this for non-interactive shells only - weird */ - bi_errorf("%s: bad value", arg); + bi_errorf("%s: %s", arg, "bad value"); return (1); } @@ -2325,7 +2338,7 @@ c_brkcont(const char **wp) * scripts, but don't generate an error (ie, keep going). */ if (n == quit) { - warningf(true, "%s: cannot %s", wp[0], wp[0]); + warningf(true, "%s: %s %s", wp[0], "cannot", wp[0]); return (0); } /* POSIX says if n is too big, the last enclosing loop @@ -2351,7 +2364,7 @@ c_set(const char **wp) const char **owp; if (wp[1] == NULL) { - static const char *args[] = { "set", "-", NULL }; + static const char *args[] = { T_set, "-", NULL }; return (c_typeset(args)); } @@ -2550,10 +2563,11 @@ timex_hook(struct op *t, char **volatile *app) t->str[0] |= TF_POSIX; break; case '?': - errorf("time: -%s unknown option", opt.optarg); + errorf("time: -%s %s", opt.optarg, + "unknown option"); case ':': - errorf("time: -%s requires an argument", - opt.optarg); + errorf("time: -%s %s", opt.optarg, + "requires an argument"); } /* Copy command words down over options. */ if (opt.optind != 0) { @@ -2641,21 +2655,21 @@ c_mknod(const char **wp) majnum = strtoul(argv[2], &c, 0); if ((c == argv[2]) || (*c != '\0')) { - bi_errorf("non-numeric device major '%s'", argv[2]); + bi_errorf("non-numeric %s %s '%s'", "device", "major", argv[2]); goto c_mknod_err; } minnum = strtoul(argv[3], &c, 0); if ((c == argv[3]) || (*c != '\0')) { - bi_errorf("non-numeric device minor '%s'", argv[3]); + bi_errorf("non-numeric %s %s '%s'", "device", "minor", argv[3]); goto c_mknod_err; } dv = makedev(majnum, minnum); if ((unsigned long)(major(dv)) != majnum) { - bi_errorf("device major too large: %lu", majnum); + bi_errorf("%s %s too large: %lu", "device", "major", majnum); goto c_mknod_err; } if ((unsigned long)(minor(dv)) != minnum) { - bi_errorf("device minor too large: %lu", minnum); + bi_errorf("%s %s too large: %lu", "device", "minor", minnum); goto c_mknod_err; } if (mknod(argv[0], mode, dv)) @@ -2671,8 +2685,8 @@ c_mknod(const char **wp) umask(oldmode); return (rv); c_mknod_usage: - bi_errorf("usage: mknod [-m mode] name b|c major minor"); - bi_errorf("usage: mknod [-m mode] name p"); + bi_errorf("%s: %s", "usage", "mknod [-m mode] name b|c major minor"); + bi_errorf("%s: %s", "usage", "mknod [-m mode] name p"); return (1); } #endif @@ -3021,7 +3035,7 @@ test_primary(Test_env *te, bool do_eval) if (te->flags & TEF_ERROR) return (0); if (!(*te->isa)(te, TM_CPAREN)) { - (*te->error)(te, 0, "missing closing paren"); + (*te->error)(te, 0, "missing )"); return (0); } return (rv); @@ -3281,7 +3295,8 @@ c_ulimit(const char **wp) all = true; break; case '?': - bi_errorf("usage: ulimit [-acdfHLlmnpSsTtvw] [value]"); + bi_errorf("%s: %s", "usage", + "ulimit [-acdfHLlmnpSsTtvw] [value]"); return (1); default: what = optc; @@ -3388,7 +3403,7 @@ c_rename(const char **wp) bi_errorf(T_synerr); else if ((rv = rename(wp[1], wp[2])) != 0) { rv = errno; - bi_errorf("failed: %s", strerror(rv)); + bi_errorf("%s: %s", "failed", strerror(rv)); } return (rv); diff --git a/histrap.c b/histrap.c index 3a88f9b..a1adc6c 100644 --- a/histrap.c +++ b/histrap.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.99 2010/08/28 15:48:18 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.100 2010/08/28 18:50:52 tg Exp $"); /*- * MirOS: This is the default mapping type, and need not be specified. @@ -230,15 +230,16 @@ c_fc(const char **wp) tf = maketemp(ATEMP, TT_HIST_EDIT, &e->temps); if (!(shf = tf->shf)) { - bi_errorf("cannot create temp file %s - %s", - tf->name, strerror(errno)); + bi_errorf("can't %s temporary file %s: %s", + "create", tf->name, strerror(errno)); return (1); } for (hp = rflag ? hlast : hfirst; hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1) shf_fprintf(shf, "%s\n", *hp); if (shf_close(shf) == EOF) { - bi_errorf("error writing temporary file - %s", strerror(errno)); + bi_errorf("can't %s temporary file %s: %s", + "write", tf->name, strerror(errno)); return (1); } @@ -263,7 +264,8 @@ c_fc(const char **wp) int n; if (!(shf = shf_open(tf->name, O_RDONLY, 0, 0))) { - bi_errorf("cannot open temp file %s", tf->name); + bi_errorf("can't %s temporary file %s: %s", + "open", tf->name, strerror(errno)); return (1); } @@ -275,8 +277,8 @@ c_fc(const char **wp) XcheckN(xs, xp, Xlength(xs, xp)); } if (n < 0) { - bi_errorf("error reading temp file %s - %s", - tf->name, strerror(shf_errno(shf))); + bi_errorf("can't %s temporary file %s: %s", + "read", tf->name, strerror(shf_errno(shf))); shf_close(shf); return (1); } @@ -380,18 +382,18 @@ hist_get(const char *str, bool approx, bool allow_cur) if (approx) hp = hist_get_oldest(); else { - bi_errorf("%s: not in history", str); + bi_errorf("%s: %s", str, "not in history"); hp = NULL; } } else if ((ptrdiff_t)hp > (ptrdiff_t)histptr) { if (approx) hp = hist_get_newest(allow_cur); else { - bi_errorf("%s: not in history", str); + bi_errorf("%s: %s", str, "not in history"); hp = NULL; } } else if (!allow_cur && hp == histptr) { - bi_errorf("%s: invalid range", str); + bi_errorf("%s: %s", str, "invalid range"); hp = NULL; } } else { @@ -399,7 +401,7 @@ hist_get(const char *str, bool approx, bool allow_cur) /* the -1 is to avoid the current fc command */ if ((n = findhist(histptr - history - 1, 0, str, anchored)) < 0) - bi_errorf("%s: not in history", str); + bi_errorf("%s: %s", str, "not in history"); else hp = &history[n]; } diff --git a/jobs.c b/jobs.c index 3e13cf3..128541d 100644 --- a/jobs.c +++ b/jobs.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.70 2010/08/28 15:48:19 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.71 2010/08/28 18:50:53 tg Exp $"); #if HAVE_KILLPG #define mksh_killpg killpg @@ -276,8 +276,8 @@ j_change(void) pid_t ttypgrp; if ((ttypgrp = tcgetpgrp(tty_fd)) < 0) { - warningf(false, - "j_init: tcgetpgrp() failed: %s", + warningf(false, "%s: %s: %s", "j_init", + "tcgetpgrp() failed", strerror(errno)); ttypgrp_ok = false; break; @@ -292,14 +292,14 @@ j_change(void) SS_RESTORE_DFL|SS_FORCE); if (ttypgrp_ok && kshpgrp != kshpid) { if (setpgid(0, kshpid) < 0) { - warningf(false, - "j_init: setpgid() failed: %s", + warningf(false, "%s: %s: %s", "j_init", + "setpgid() failed", strerror(errno)); ttypgrp_ok = false; } else { if (tcsetpgrp(tty_fd, kshpid) < 0) { - warningf(false, - "j_init: tcsetpgrp() failed: %s", + warningf(false, "%s: %s: %s", "j_init", + "tcsetpgrp() failed", strerror(errno)); ttypgrp_ok = false; } else @@ -308,7 +308,8 @@ j_change(void) } } if (use_tty && !ttypgrp_ok) - warningf(false, "warning: won't have full job control"); + warningf(false, "%s: %s", "warning", + "won't have full job control"); if (tty_fd >= 0) tcgetattr(tty_fd, &tty_state); } else { @@ -494,8 +495,9 @@ exchild(struct op *t, int flags, #ifndef MKSH_SMALL if (t->type == TPIPE) unwind(LLEAVE); - internal_warningf("exchild: execute() returned"); - fptreef(shl_out, 2, "exchild: tried to execute {\n%T\n}\n", t); + internal_warningf("%s: %s", "exchild", "execute() returned"); + fptreef(shl_out, 2, "%s: tried to execute {\n%T\n}\n", + "exchild", t); shf_flush(shl_out); #endif unwind(LLEAVE); @@ -561,9 +563,9 @@ waitlast(void) j = last_job; if (!j || !(j->flags & JF_STARTED)) { if (!j) - warningf(true, "waitlast: no last job"); + warningf(true, "%s: %s", "waitlast", "no last job"); else - internal_warningf("waitlast: not started"); + internal_warningf("%s: %s", "waitlast", "not started"); sigprocmask(SIG_SETMASK, &omask, NULL); return (125); /* not so arbitrary, non-zero value */ } @@ -754,7 +756,7 @@ j_resume(const char *cp, int bg) tty_fd, (long)kshpgrp, strerror(errno)); } sigprocmask(SIG_SETMASK, &omask, NULL); - bi_errorf("cannot continue job %s: %s", + bi_errorf("%s %s %s", "cannot continue job", cp, strerror(err)); return (1); } @@ -916,7 +918,7 @@ j_set_async(Job *j) if (async_job && (async_job->flags & (JF_KNOWN|JF_ZOMBIE)) == JF_ZOMBIE) remove_job(async_job, "async"); if (!(j->flags & JF_STARTED)) { - internal_warningf("j_async: job not started"); + internal_warningf("%s: %s", "j_async", "job not started"); return; } async_job = j; @@ -930,8 +932,8 @@ j_set_async(Job *j) if (!oldest) { /* XXX debugging */ if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) { - internal_warningf("j_async: bad nzombie (%d)", - nzombie); + internal_warningf("%s: bad nzombie (%d)", + "j_async", nzombie); nzombie = 0; } break; diff --git a/lex.c b/lex.c index d0219e7..ac72394 100644 --- a/lex.c +++ b/lex.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.118 2010/07/25 11:35:41 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.119 2010/08/28 18:50:53 tg Exp $"); /* * states while lexing word @@ -944,7 +944,7 @@ yylex(int cf) #ifndef MKSH_SMALL if (state == SLETARRAY && statep->ls_sletarray.nparen != -1) - yyerror("%s: ')' missing\n", T_synerr); + yyerror("%s: '%s' %s\n", T_synerr, ")", "missing"); #endif /* This done to avoid tests for SHEREDELIM wherever SBASE tested */ diff --git a/main.c b/main.c index 45c06ab..ed5e1ab 100644 --- a/main.c +++ b/main.c @@ -33,7 +33,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.168 2010/08/28 15:39:19 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.169 2010/08/28 18:50:54 tg Exp $"); extern char **environ; @@ -68,7 +68,7 @@ static const char *initcoms[] = { T_typeset, "-x", "HOME", "PATH", "RANDOM", "SHELL", NULL, T_typeset, "-i10", "COLUMNS", "LINES", "OPTIND", "PGRP", "PPID", "RANDOM", "SECONDS", "TMOUT", "USER_ID", NULL, - "alias", + T_alias, "integer=typeset -i", T_local_typeset, "hash=alias -t", /* not "alias -t --": hash -r needs to work */ @@ -87,7 +87,7 @@ static const char *initcoms[] = { "login=exec login", NULL, /* this is what AT&T ksh seems to track, with the addition of emacs */ - "alias", "-tU", + T_alias, "-tU", "cat", "cc", "chmod", "cp", "date", "ed", "emacs", "grep", "ls", "make", "mv", "pr", "rm", "sed", "sh", "vi", "who", NULL, NULL @@ -323,7 +323,7 @@ mksh_init(int argc, const char *argv[]) if (Flag(FCOMMAND)) { s = pushs(SSTRING, ATEMP); if (!(s->start = s->str = argv[argi++])) - errorf("-c requires an argument"); + errorf("%s %s", "-c", "requires an argument"); #ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT /* compatibility to MidnightBSD 0.1 /bin/sh (kludge) */ if (Flag(FSH) && argv[argi] && !strcmp(argv[argi], "--")) @@ -633,7 +633,7 @@ shell(Source * volatile s, volatile int toplevel) t = compile(s); if (t != NULL && t->type == TEOF) { if (wastty && Flag(FIGNOREEOF) && --attempts > 0) { - shellf("Use 'exit' to leave ksh\n"); + shellf("Use 'exit' to leave mksh\n"); s->type = SSTDIN; } else if (wastty && !really_exit && j_stopped_running()) { @@ -876,13 +876,12 @@ tty_init(bool init_ttystate, bool need_tty) } if ((tty_fd = fcntl(tfd, F_DUPFD, FDBASE)) < 0) { if (need_tty) - warningf(false, "j_ttyinit: dup of tty fd failed: %s", - strerror(errno)); + warningf(false, "%s: %s: %s", "j_ttyinit", + "dup of tty fd failed", strerror(errno)); } else if (fcntl(tty_fd, F_SETFD, FD_CLOEXEC) < 0) { if (need_tty) - warningf(false, - "j_ttyinit: can't set close-on-exec flag: %s", - strerror(errno)); + warningf(false, "%s: %s: %s", "j_ttyinit", + "can't set close-on-exec flag", strerror(errno)); close(tty_fd); tty_fd = -1; } else if (init_ttystate) @@ -1280,7 +1279,7 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist) tp->shf = NULL; tp->type = type; #if HAVE_MKSTEMP - shf_snprintf(pathname, len, "%s/mksh.XXXXXXXXXX", dir); + shf_snprintf(pathname, len, "%s/%s", dir, "mksh.XXXXXXXXXX"); if ((fd = mkstemp(pathname)) >= 0) #else if (tp->name[0] && (fd = open(tp->name, O_CREAT | O_RDWR, 0600)) >= 0) diff --git a/misc.c b/misc.c index 9002167..19c7126 100644 --- a/misc.c +++ b/misc.c @@ -29,7 +29,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.143 2010/08/28 16:47:09 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.144 2010/08/28 18:50:55 tg Exp $"); unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */ @@ -168,10 +168,11 @@ printoptions(bool verbose) octs + 4, oi.opt_width + 4, true); } else { /* short version รก la AT&T ksh93 */ - shf_puts("set", shl_stdout); + shf_puts(T_set, shl_stdout); while (i < (int)NELEM(options)) { if (Flag(i) && options[i].name) - shprintf(" -o %s", options[i].name); + shprintf("%s %s %s", null, "-o", + options[i].name); ++i; } shf_putc('\n', shl_stdout); @@ -345,7 +346,7 @@ parse_args(const char **argv, else if ((i != (size_t)-1) && (options[i].flags & what)) change_flag((enum sh_flag)i, what, set); else { - bi_errorf("%s: bad option", go.optarg); + bi_errorf("%s: %s", go.optarg, "bad option"); return (-1); } break; @@ -399,7 +400,7 @@ parse_args(const char **argv, argv[go.optind]); if (arrayset && (!*array || *skip_varname(array, false))) { - bi_errorf("%s: is not an identifier", array); + bi_errorf("%s: %s", array, "is not an identifier"); return (-1); } if (sortargs) { @@ -456,7 +457,7 @@ bi_getn(const char *as, int *ai) int rv; if (!(rv = getn(as, ai))) - bi_errorf("%s: bad number", as); + bi_errorf("%s: %s", as, "bad number"); return (rv); } @@ -858,9 +859,10 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp) go->optarg = go->buf; return (':'); } - warningf(true, "%s%s-'%c' requires argument", + warningf(true, "%s%s-'%c' %s", (go->flags & GF_NONAME) ? "" : argv[0], - (go->flags & GF_NONAME) ? "" : ": ", c); + (go->flags & GF_NONAME) ? "" : ": ", c, + "requires an argument"); if (go->flags & GF_ERROR) bi_errorfz(); return ('?'); @@ -1289,42 +1291,43 @@ chvt(const char *fn) if (stat(dv, &sb)) { strlcpy(dv + 8, fn, sizeof(dv) - 8); if (stat(dv, &sb)) - errorf("chvt: can't find tty %s", fn); + errorf("%s: %s %s", "chvt", + "can't find tty", fn); } fn = dv; } if (!(sb.st_mode & S_IFCHR)) - errorf("chvt: not a char device: %s", fn); + errorf("%s %s %s", "chvt: not a char", "device", fn); if ((sb.st_uid != 0) && chown(fn, 0, 0)) - warningf(false, "chvt: cannot chown root %s", fn); + warningf(false, "%s: %s %s", "chvt", "cannot chown root", fn); if (((sb.st_mode & 07777) != 0600) && chmod(fn, (mode_t)0600)) - warningf(false, "chvt: cannot chmod 0600 %s", fn); + warningf(false, "%s: %s %s", "chvt", "cannot chmod 0600", fn); #if HAVE_REVOKE if (revoke(fn)) #endif - warningf(false, "chvt: cannot revoke %s, new shell is" - " potentially insecure", fn); + warningf(false, "%s: cannot revoke %s, new shell is" + " potentially insecure", "chvt", fn); } if ((fd = open(fn, O_RDWR)) == -1) { sleep(1); if ((fd = open(fn, O_RDWR)) == -1) - errorf("chvt: cannot open %s", fn); + errorf("%s: %s %s", "chvt", "cannot open", fn); } switch (fork()) { case -1: - errorf("chvt: %s failed", "fork"); + errorf("%s: %s %s", "chvt", "fork", "failed"); case 0: break; default: exit(0); } if (setsid() == -1) - errorf("chvt: %s failed", "setsid"); + errorf("%s: %s %s", "chvt", "setsid", "failed"); if (fn != dv + 1) { if (ioctl(fd, TIOCSCTTY, NULL) == -1) - errorf("chvt: %s failed", "TIOCSCTTY"); + errorf("%s: %s %s", "chvt", "TIOCSCTTY", "failed"); if (tcflush(fd, TCIOFLUSH)) - errorf("chvt: %s failed", "TCIOFLUSH"); + errorf("%s: %s %s", "chvt", "TCIOFLUSH", "failed"); } ksh_dup2(fd, 0, false); ksh_dup2(fd, 1, false); diff --git a/sh.h b/sh.h index e00f17c..a7ff2ce 100644 --- a/sh.h +++ b/sh.h @@ -150,7 +150,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.409 2010/08/28 17:21:46 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.410 2010/08/28 18:50:55 tg Exp $"); #endif #define MKSH_VERSION "R39 2010/08/28" @@ -633,6 +633,14 @@ EXTERN const char r_fc_e_[] I__("r=fc -e -"); EXTERN const char T_local_typeset[] I__("local=typeset"); #define T__typeset (T_local_typeset + 5) /* "=typeset" */ #define T_typeset (T_local_typeset + 6) /* "typeset" */ +EXTERN const char T_palias[] I__("+alias"); +#define T_alias (T_palias + 1) /* "alias" */ +EXTERN const char T_punalias[] I__("+unalias"); +#define T_unalias (T_punalias + 1) /* "unalias" */ +EXTERN const char T_sgset[] I__("*=set"); +#define T_set (T_sgset + 2) /* "set" */ +EXTERN const char T_gbuiltin[] I__("=builtin"); +#define T_builtin (T_gbuiltin + 1) /* "builtin" */ enum temp_type { TT_HEREDOC_EXP, /* expanded heredoc */ diff --git a/shf.c b/shf.c index 5274107..de2ffd3 100644 --- a/shf.c +++ b/shf.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.37 2010/08/28 16:47:11 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.38 2010/08/28 18:50:57 tg Exp $"); /* flags to shf_emptybuf() */ #define EB_READSW 0x01 /* about to switch to reading */ @@ -108,7 +108,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf) } if (!(sflags & (SHF_RD | SHF_WR))) - internal_errorf("shf_fdopen: missing read/write"); + internal_errorf("%s: %s", "shf_fdopen", "missing read/write"); if (shf) { if (bsize) { @@ -165,9 +165,9 @@ shf_reopen(int fd, int sflags, struct shf *shf) } if (!(sflags & (SHF_RD | SHF_WR))) - internal_errorf("shf_reopen: missing read/write"); + internal_errorf("%s: %s", "shf_reopen", "missing read/write"); if (!shf || !shf->buf || shf->bsize < bsize) - internal_errorf("shf_reopen: bad shf/buf/bsize"); + internal_errorf("%s: %s", "shf_reopen", "bad shf/buf/bsize"); /* assumes shf->buf and shf->bsize already set up */ shf->fd = fd; @@ -196,7 +196,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf) { /* can't have a read+write string */ if (!(!(sflags & SHF_RD) ^ !(sflags & SHF_WR))) - internal_errorf("shf_sopen: flags 0x%x", sflags); + internal_errorf("%s: flags 0x%X", "shf_sopen", sflags); if (!shf) { shf = alloc(sizeof(struct shf), ATEMP); @@ -289,7 +289,7 @@ shf_flush(struct shf *shf) return ((shf->flags & SHF_WR) ? EOF : 0); if (shf->fd < 0) - internal_errorf("shf_flush: no fd"); + internal_errorf("%s: %s", "shf_flush", "no fd"); if (shf->flags & SHF_ERROR) { errno = shf->errno_; @@ -319,7 +319,7 @@ shf_emptybuf(struct shf *shf, int flags) int ret = 0; if (!(shf->flags & SHF_STRING) && shf->fd < 0) - internal_errorf("shf_emptybuf: no fd"); + internal_errorf("%s: %s", "shf_emptybuf", "no fd"); if (shf->flags & SHF_ERROR) { errno = shf->errno_; @@ -401,7 +401,7 @@ shf_fillbuf(struct shf *shf) return (0); if (shf->fd < 0) - internal_errorf("shf_fillbuf: no fd"); + internal_errorf("%s: %s", "shf_fillbuf", "no fd"); if (shf->flags & (SHF_EOF | SHF_ERROR)) { if (shf->flags & SHF_ERROR) @@ -444,10 +444,10 @@ shf_read(char *buf, int bsize, struct shf *shf) int ncopy; if (!(shf->flags & SHF_RD)) - internal_errorf("shf_read: flags %x", shf->flags); + internal_errorf("%s: flags 0x%X", "shf_read", shf->flags); if (bsize <= 0) - internal_errorf("shf_read: bsize %d", bsize); + internal_errorf("%s: %s %d", "shf_write", "bsize", bsize); while (bsize > 0) { if (shf->rnleft == 0 && @@ -479,7 +479,7 @@ shf_getse(char *buf, int bsize, struct shf *shf) char *orig_buf = buf; if (!(shf->flags & SHF_RD)) - internal_errorf("shf_getse: flags %x", shf->flags); + internal_errorf("%s: flags 0x%X", "shf_getse", shf->flags); if (bsize <= 0) return (NULL); @@ -514,7 +514,7 @@ int shf_getchar(struct shf *shf) { if (!(shf->flags & SHF_RD)) - internal_errorf("shf_getchar: flags %x", shf->flags); + internal_errorf("%s: flags 0x%X", "shf_getchar", shf->flags); if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0)) return (EOF); @@ -529,7 +529,7 @@ int shf_ungetc(int c, struct shf *shf) { if (!(shf->flags & SHF_RD)) - internal_errorf("shf_ungetc: flags %x", shf->flags); + internal_errorf("%s: flags 0x%X", "shf_ungetc", shf->flags); if ((shf->flags & SHF_ERROR) || c == EOF || (shf->rp == shf->buf && shf->rnleft)) @@ -564,7 +564,7 @@ int shf_putchar(int c, struct shf *shf) { if (!(shf->flags & SHF_WR)) - internal_errorf("shf_putchar: flags %x", shf->flags); + internal_errorf("%s: flags 0x%X", "shf_putchar", shf->flags); if (c == EOF) return (EOF); @@ -574,7 +574,7 @@ shf_putchar(int c, struct shf *shf) int n; if (shf->fd < 0) - internal_errorf("shf_putchar: no fd"); + internal_errorf("%s: %s", "shf_putchar", "no fd"); if (shf->flags & SHF_ERROR) { errno = shf->errno_; return (EOF); @@ -618,10 +618,10 @@ shf_write(const char *buf, int nbytes, struct shf *shf) int n, ncopy, orig_nbytes = nbytes; if (!(shf->flags & SHF_WR)) - internal_errorf("shf_write: flags %x", shf->flags); + internal_errorf("%s: flags 0x%X", "shf_write", shf->flags); if (nbytes < 0) - internal_errorf("shf_write: nbytes %d", nbytes); + internal_errorf("%s: %s %d", "shf_write", "nbytes", nbytes); /* Don't buffer if buffer is empty and we're writting a large amount. */ if ((ncopy = shf->wnleft) && diff --git a/syn.c b/syn.c index 64b2867..64d063c 100644 --- a/syn.c +++ b/syn.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.49 2010/07/17 22:09:39 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.50 2010/08/28 18:50:58 tg Exp $"); struct nesting_state { int start_token; /* token than began nesting (eg, FOR) */ @@ -181,7 +181,7 @@ synio(int cf) if (*ident != 0) /* unquoted */ iop->flag |= IOEVAL; if (herep > &heres[HERES - 1]) - yyerror("too many <name = yylval.cp; @@ -257,7 +257,8 @@ get_command(int cf) case REDIR: while ((iop = synio(cf)) != NULL) { if (iopn >= NUFILE) - yyerror("too many redirections\n"); + yyerror("too many %ss\n", + "redirection"); iops[iopn++] = iop; } break; @@ -403,8 +404,8 @@ get_command(int cf) t = newtp((c == FOR) ? TFOR : TSELECT); musthave(LWORD, ARRAYVAR); if (!is_wdvarname(yylval.cp, true)) - yyerror("%s: bad identifier\n", - c == FOR ? "for" : "select"); + yyerror("%s: %s\n", c == FOR ? "for" : "select", + "bad identifier"); strdupx(t->str, ident, ATEMP); nesting_push(&old_nesting, c); t->vars = wordlist(); @@ -466,7 +467,7 @@ get_command(int cf) while ((iop = synio(syniocf)) != NULL) { if (iopn >= NUFILE) - yyerror("too many redirections\n"); + yyerror("too many %ss\n", "redirection"); iops[iopn++] = iop; } @@ -622,7 +623,7 @@ function_body(char *name, */ for (p = sname; *p; p++) if (ctype(*p, C_QUOTE)) - yyerror("%s: invalid function name\n", sname); + yyerror("%s: %s\n", sname, "invalid function name"); /* Note that POSIX allows only compound statements after foo(), sh and * AT&T ksh allow any command, go with the later since it shouldn't @@ -796,7 +797,7 @@ syntaxerr(const char *what) goto Again; } /* don't quote the EOF */ - yyerror("%s: unexpected EOF\n", T_synerr); + yyerror("%s: %s\n", T_synerr, "unexpected EOF"); /* NOTREACHED */ case LWORD: @@ -882,7 +883,7 @@ assign_command(char *s) { if (!*s) return (0); - return ((strcmp(s, "alias") == 0) || + return ((strcmp(s, T_alias) == 0) || (strcmp(s, "export") == 0) || (strcmp(s, "readonly") == 0) || (strcmp(s, T_typeset) == 0)); diff --git a/var.c b/var.c index 4e9729e..5252953 100644 --- a/var.c +++ b/var.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.110 2010/07/25 11:35:43 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.111 2010/08/28 18:50:58 tg Exp $"); /* * Variables @@ -393,7 +393,7 @@ intval(struct tbl *vp) base = getint(vp, &num, false); if (base == -1) /* XXX check calls - is error here ok by POSIX? */ - errorf("%s: bad number", str_val(vp)); + errorf("%s: %s", str_val(vp), "bad number"); return (num); } @@ -406,7 +406,7 @@ setstr(struct tbl *vq, const char *s, int error_ok) error_ok &= ~0x4; if ((vq->flag & RDONLY) && !no_ro_check) { - warningf(true, "%s: is read only", vq->name); + warningf(true, "%s: %s", vq->name, "is read only"); if (!error_ok) errorfz(); return (0); @@ -685,8 +685,8 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) mkssert(*var != 0); if (*val == '[') { if (set_refflag) - errorf("%s: reference variable cannot be an array", - var); + errorf("%s: %s", var, + "reference variable cannot be an array"); len = array_ref_len(val); if (len == 0) return (NULL); @@ -722,7 +722,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) /* Prevent typeset from creating a local PATH/ENV/SHELL */ if (Flag(FRESTRICTED) && (strcmp(tvar, "PATH") == 0 || strcmp(tvar, "ENV") == 0 || strcmp(tvar, "SHELL") == 0)) - errorf("%s: restricted", tvar); + errorf("%s: %s", tvar, "restricted"); vp = (set&LOCAL) ? local(tvar, (set & LOCAL_COPY) ? true : false) : global(tvar); @@ -756,7 +756,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) if ((vpbase->flag&RDONLY) && (val || clr || (set & ~EXPORT))) /* XXX check calls - is error here ok by POSIX? */ - errorf("%s: is read only", tvar); + errorf("%s: %s", tvar, "is read only"); afree(tvar, ATEMP); /* most calls are with set/clr == 0 */ @@ -1389,7 +1389,7 @@ set_array(const char *var, bool reset, const char **vals) /* Note: AT&T ksh allows set -A but not set +A of a read-only var */ if ((vp->flag&RDONLY)) - errorf("%s: is read only", var); + errorf("%s: %s", var, "is read only"); /* This code is quite non-optimal */ if (reset) /* trash existing values and attributes */