diff --git a/check.t b/check.t index 2a0df55..afe2179 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.389 2010/08/28 17:21:41 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.390 2010/08/28 20:22:13 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -2268,7 +2268,7 @@ expected-stdout: hi 1 echo hi expected-stderr-pattern: - /(.*cannot unlink HISTFILE.*\n)?X*$/ + /(.*can't unlink HISTFILE.*\n)?X*$/ --- name: history-e-minus-1 description: @@ -6558,7 +6558,7 @@ stdin: expected-stdout: === mir -expected-stderr-pattern: /.*: cannot (create|overwrite) .*/ +expected-stderr-pattern: /.*: can't (create|overwrite) .*/ --- name: bashiop-3b description: diff --git a/edit.c b/edit.c index a43104f..80bedbb 100644 --- a/edit.c +++ b/edit.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.198 2010/08/28 18:50:47 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.199 2010/08/28 20:22:15 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("%s: %s", "fileglob", "substitute error"); + internal_warningf("%s: %s", "fileglob", "bad substitution"); return (0); } source = sold; @@ -2245,7 +2245,7 @@ x_vt_hack(int c) /*- * At this point, we have read the following octets so far: - * - ESC+[ or ESC+O or Ctrl-X (Præfix 2) + * - ESC+[ or ESC+O or Ctrl-X (Prefix 2) * - 1 (vt_hack) * - ; * - 5 (Ctrl key combiner) or 3 (Alt key combiner) @@ -2356,7 +2356,7 @@ x_bind(const char *a1, const char *a2, #endif if (x_tab == NULL) { - bi_errorf("cannot bind, not a tty"); + bi_errorf("can't bind, not a tty"); return (1); } /* List function names */ @@ -2398,12 +2398,12 @@ x_bind(const char *a1, const char *a2, && ((*m1 != '~') || *(m1 + 1)) #endif ) { - char msg[256] = "key sequence '"; + char msg[256]; const char *c = a1; - m1 = msg + strlen(msg); + m1 = msg; while (*c && m1 < (msg + sizeof(msg) - 3)) x_mapout2(*c++, &m1); - bi_errorf("'%s' too long", msg); + bi_errorf("%s: %s '%s'", "bind", "too long key sequence", 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: %s", a2, "no such function"); + bi_errorf("%s: %s %s", a2, "no such", T_function); return (1); } } diff --git a/eval.c b/eval.c index 52935b4..7063720 100644 --- a/eval.c +++ b/eval.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.91 2010/08/28 18:50:49 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.92 2010/08/28 20:22:16 tg Exp $"); /* * string expansion @@ -108,7 +108,7 @@ substitute(const char *cp, int f) s->start = s->str = cp; source = s; if (yylex(ONEWORD) != LWORD) - internal_errorf("substitute"); + internal_errorf("bad substitution"); source = sold; afree(s, ATEMP); return (evalstr(yylval.cp, f)); @@ -1134,13 +1134,13 @@ comsub(Expand *xp, const char *cp) struct ioword *io = *t->ioact; char *name; - if ((io->flag&IOTYPE) != IOREAD) + if ((io->flag & IOTYPE) != IOREAD) 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: %s", name, "cannot open $() input"); + errorf("%s: %s %s", name, "can't open", "$() input"); xp->split = 0; /* no waitlast() */ } else { int ofd1, pv[2]; diff --git a/exec.c b/exec.c index 1386e09..41e48d0 100644 --- a/exec.c +++ b/exec.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.79 2010/08/28 18:50:49 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.80 2010/08/28 20:22:17 tg Exp $"); #ifndef MKSH_DEFAULT_EXECSHELL #define MKSH_DEFAULT_EXECSHELL "/bin/sh" @@ -88,8 +88,8 @@ execute(struct op *volatile t, timex_hook(t, &up); ap = (const char **)up; if (Flag(FXTRACE) && ap[0]) { - shf_fprintf(shl_out, "%s", - substitute(str_val(global("PS4")), 0)); + shf_puts(substitute(str_val(global("PS4")), 0), + shl_out); for (i = 0; ap[i]; i++) shf_fprintf(shl_out, "%s%c", ap[i], ap[i + 1] ? ' ' : '\n'); @@ -534,8 +534,8 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, if (Flag(FXTRACE)) { if (i == 0) - shf_fprintf(shl_out, "%s", - substitute(str_val(global("PS4")), 0)); + shf_puts(substitute(str_val(global("PS4")), 0), + shl_out); shf_fprintf(shl_out, "%s%c", cp, t->vars[i + 1] ? ' ' : '\n'); if (!t->vars[i + 1]) @@ -573,22 +573,24 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, if (!tp->u.fpath) { if (tp->u2.errno_) { - warningf(true, "%s: %s: %s", cp, - "can't find function definition file", + warningf(true, "%s: %s %s: %s", cp, + "can't find", + "function definition file", strerror(tp->u2.errno_)); rv = 126; } else { - warningf(true, "%s: %s", cp, - "can't find function definition file"); + warningf(true, "%s: %s %s", cp, + "can't find", + "function definition file"); rv = 127; } break; } if (include(tp->u.fpath, 0, NULL, 0) < 0) { rv = errno; - warningf(true, - "%s: can't open function definition file %s: %s", - cp, tp->u.fpath, strerror(rv)); + warningf(true, "%s: %s %s %s: %s", cp, + "can't open", "function definition file", + tp->u.fpath, strerror(rv)); rv = 127; break; } @@ -664,7 +666,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, /* NOTREACHED */ default: quitenv(NULL); - internal_errorf("CFUNC %d", i); + internal_errorf("%s %d", "CFUNC", i); } break; } @@ -679,7 +681,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, */ if (tp->u2.errno_) { warningf(true, "%s: %s: %s", cp, - "cannot execute", strerror(tp->u2.errno_)); + "can't execute", strerror(tp->u2.errno_)); rv = 126; /* POSIX */ } else { warningf(true, "%s: %s", cp, "not found"); @@ -1204,7 +1206,7 @@ iosetup(struct ioword *iop, struct tbl *tp) /* herein() may already have printed message */ if (u == -1) { u = errno; - warningf(true, "cannot %s %s: %s", + warningf(true, "can't %s %s: %s", iotype == IODUP ? "dup" : (iotype == IOREAD || iotype == IOHERE) ? "open" : "create", cp, strerror(u)); @@ -1233,8 +1235,8 @@ iosetup(struct ioword *iop, struct tbl *tp) int ev; ev = errno; - warningf(true, - "%s %s %s", "could not finish (dup) redirection", + warningf(true, "%s %s %s", + "can't finish (dup) redirection", snptreef(NULL, 32, "%R", &iotmp), strerror(ev)); if (iotype != IODUP) @@ -1273,7 +1275,7 @@ herein(const char *content, int sub) /* ksh -c 'cat << EOF' can cause this... */ if (content == NULL) { - warningf(true, "here document missing"); + warningf(true, "%s missing", "here document"); return (-2); /* special to iosetup(): don't print error */ } @@ -1317,9 +1319,7 @@ herein(const char *content, int sub) if (shf_close(shf) == EOF) { i = errno; close(fd); - fd = errno; - warningf(true, "error writing %s: %s, %s", h->name, - strerror(i), strerror(fd)); + warningf(true, "%s: %s: %s", "write", h->name, strerror(i)); return (-2); /* special to iosetup(): don't print error */ } @@ -1349,7 +1349,7 @@ do_selectargs(const char **ap, bool print_menu) */ if (print_menu || !*str_val(global("REPLY"))) pr_menu(ap); - shellf("%s", str_val(global("PS3"))); + shf_puts(str_val(global("PS3")), shl_out); if (call_builtin(findcom("read", FC_BI), read_args)) return (NULL); s = str_val(global("REPLY")); @@ -1430,7 +1430,7 @@ static char *plain_fmt_entry(char *, int, int, const void *); static char * plain_fmt_entry(char *buf, int buflen, int i, const void *arg) { - shf_snprintf(buf, buflen, "%s", ((const char * const *)arg)[i]); + strlcpy(buf, ((const char * const *)arg)[i], buflen); return (buf); } diff --git a/funcs.c b/funcs.c index 68e8a37..72997db 100644 --- a/funcs.c +++ b/funcs.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.159 2010/08/28 18:50:51 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.160 2010/08/28 20:22:17 tg Exp $"); #if HAVE_KILLPG /* @@ -204,7 +204,7 @@ do_realpath(const char *upath) /* upath is a relative pathname, prepend cwd */ if ((tp = ksh_get_wd(NULL)) == NULL || tp[0] != '/') return (NULL); - ipath = shf_smprintf("%s/%s", tp, upath); + ipath = shf_smprintf("%s%s%s", tp, "/", upath); afree(tp, ATEMP); } @@ -401,7 +401,7 @@ c_cd(const char **wp) char *cp; if (!current_wd[0]) { - bi_errorf("don't know current directory"); + bi_errorf("can't determine current directory"); return (1); } /* substitute arg1 for arg2 in current path. @@ -521,7 +521,8 @@ c_pwd(const char **wp) if (p && access(p, R_OK) < 0) p = NULL; if (!p && !(p = allocd = ksh_get_wd(NULL))) { - bi_errorf("%s: %s", "can't get current directory", strerror(errno)); + bi_errorf("%s: %s", "can't determine current directory", + strerror(errno)); return (1); } shprintf("%s\n", p); @@ -832,7 +833,7 @@ c_whence(const char **wp) shprintf(" (autoload from %s)", tp->u.fpath); } - shf_puts(" function", shl_stdout); + shf_puts(T__function, shl_stdout); } break; case CSHELL: @@ -1057,11 +1058,11 @@ c_typeset(const char **wp) if (fset | fclr) { f->flag |= fset; f->flag &= ~fclr; - } else - fptreef(shl_stdout, 0, - f->flag & FKSH ? - "function %s %T\n" : - "%s() %T\n", wp[i], f->val.t); + } else { + fpFUNCTf(shl_stdout, 0, f->flag & FKSH, + wp[i], f->val.t); + shf_putc('\n', shl_stdout); + } } else if (!typeset(wp[i], fset, fclr, field, base)) { bi_errorf("%s: %s", wp[i], "not identifier"); set_refflag = 0; @@ -1080,11 +1081,12 @@ c_typeset(const char **wp) if (flag && (vp->flag & flag) == 0) continue; if (thing == '-') - fptreef(shl_stdout, 0, vp->flag & FKSH ? - "function %s %T\n" : "%s() %T\n", + fpFUNCTf(shl_stdout, 0, + vp->flag & FKSH, vp->name, vp->val.t); else - shprintf("%s\n", vp->name); + shf_puts(vp->name, shl_stdout); + shf_putc('\n', shl_stdout); } } } else { @@ -2049,7 +2051,7 @@ c_read(const char **wp) * (it also doesn't check the interactive flag, * as is indicated in the Kornshell book). */ - shellf("%s", cp+1); + shf_puts(cp + 1, shl_out); } } @@ -2136,7 +2138,7 @@ c_read(const char **wp) /* Must be done before setting export. */ if (vp->flag & RDONLY) { shf_flush(shf); - bi_errorf("%s is read only", *wp); + bi_errorf("%s: %s", *wp, "is read only"); afree(wpalloc, ATEMP); return (1); } @@ -2338,7 +2340,7 @@ c_brkcont(const char **wp) * scripts, but don't generate an error (ie, keep going). */ if (n == quit) { - warningf(true, "%s: %s %s", wp[0], "cannot", wp[0]); + warningf(true, "%s: %s %s", wp[0], "can't", wp[0]); return (0); } /* POSIX says if n is too big, the last enclosing loop @@ -2433,7 +2435,7 @@ c_unset(const char **wp) afree(cp, ATEMP); if ((vp->flag&RDONLY)) { - bi_errorf("%s is read only", vp->name); + bi_errorf("%s: %s", vp->name, "is read only"); return (1); } unset(vp, optc); @@ -3352,7 +3354,7 @@ set_ulimit(const struct limits *l, const char *v, int how) } if (getrlimit(l->resource, &limit) < 0) { - /* some cannot be read, e.g. Linux RLIMIT_LOCKS */ + /* some can't be read, e.g. Linux RLIMIT_LOCKS */ limit.rlim_cur = RLIM_INFINITY; limit.rlim_max = RLIM_INFINITY; } @@ -3455,7 +3457,7 @@ c_cat(const char **wp) /* XXX uses malloc instead of lalloc (for alignment/speed) */ if ((buf = malloc(MKSH_CAT_BUFSIZ)) == NULL) { - bi_errorf("cannot allocate %lu data bytes", + bi_errorf("can't allocate %lu data bytes", (unsigned long)MKSH_CAT_BUFSIZ); return (1); } diff --git a/histrap.c b/histrap.c index a1adc6c..62198ae 100644 --- a/histrap.c +++ b/histrap.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.100 2010/08/28 18:50:52 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.101 2010/08/28 20:22:18 tg Exp $"); /*- * MirOS: This is the default mapping type, and need not be specified. @@ -79,7 +79,7 @@ c_fc(const char **wp) char **hfirst, **hlast, **hp; if (!Flag(FTALKING_I)) { - bi_errorf("history functions not available"); + bi_errorf("history %ss not available", T_function); return (1); } @@ -307,8 +307,10 @@ hist_execute(char *cmd) } histsave(&hist_source->line, p, true, true); - shellf("%s\n", p); /* POSIX doesn't say this is done... */ - if (q) /* restore \n (trailing \n not restored) */ + /* POSIX doesn't say this is done... */ + shellf("%s\n", p); + if (q) + /* restore \n (trailing \n not restored) */ q[-1] = '\n'; } @@ -354,7 +356,7 @@ hist_replace(char **hp, const char *pat, const char *rep, bool globr) xp += rep_len; } if (!any_subst) { - bi_errorf("substitution failed"); + bi_errorf("bad substitution"); return (1); } len = strlen(s) + 1; @@ -748,8 +750,9 @@ hist_init(Source *s) hist_finish(); if (rv) { hiniterr: - bi_errorf("cannot unlink HISTFILE %s" - " - %s", hname, strerror(errno)); + bi_errorf("can't %s %s: %s", + "unlink HISTFILE", hname, + strerror(errno)); hsize = 0; return; } @@ -1087,7 +1090,8 @@ inittraps(void) #endif if ((sigtraps[i].mess == NULL) || (sigtraps[i].mess[0] == '\0')) - sigtraps[i].mess = shf_smprintf("Signal %d", i); + sigtraps[i].mess = shf_smprintf("%s %d", + "Signal", i); } } sigtraps[SIGEXIT_].name = "EXIT"; /* our name for signal 0 */ diff --git a/jobs.c b/jobs.c index 128541d..6fd68f9 100644 --- a/jobs.c +++ b/jobs.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.71 2010/08/28 18:50:53 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.72 2010/08/28 20:22:19 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, "%s: %s: %s", "j_init", - "tcgetpgrp() failed", + warningf(false, "%s: %s %s: %s", + "j_init", "tcgetpgrp", "failed", strerror(errno)); ttypgrp_ok = false; break; @@ -292,14 +292,13 @@ j_change(void) SS_RESTORE_DFL|SS_FORCE); if (ttypgrp_ok && kshpgrp != kshpid) { if (setpgid(0, kshpid) < 0) { - warningf(false, "%s: %s: %s", "j_init", - "setpgid() failed", - strerror(errno)); + warningf(false, "%s: %s %s: %s", "j_init", + "setpgid", "failed", strerror(errno)); ttypgrp_ok = false; } else { if (tcsetpgrp(tty_fd, kshpid) < 0) { - warningf(false, "%s: %s: %s", "j_init", - "tcsetpgrp() failed", + warningf(false, "%s: %s %s: %s", + "j_init", "tcsetpgrp", "failed", strerror(errno)); ttypgrp_ok = false; } else @@ -369,8 +368,8 @@ exchild(struct op *t, int flags, if (flags & XPIPEI) { /* continuing with a pipe */ if (!last_job) - internal_errorf( - "exchild: XPIPEI and no last_job - pid %d", + internal_errorf("%s %d", + "exchild: XPIPEI and no last_job - pid", (int)procpid); pi.j = last_job; if (last_proc) @@ -411,7 +410,7 @@ exchild(struct op *t, int flags, kill_job(pi.j, SIGKILL); remove_job(pi.j, "fork failed"); sigprocmask(SIG_SETMASK, &omask, NULL); - errorf("cannot fork - try again"); + errorf("can't fork - try again"); } pi.p->pid = pi.cldpid ? pi.cldpid : (procpid = getpid()); @@ -570,7 +569,7 @@ waitlast(void) return (125); /* not so arbitrary, non-zero value */ } - rv = j_waitj(j, JW_NONE, "jw:waitlast"); + rv = j_waitj(j, JW_NONE, "waitlast"); sigprocmask(SIG_SETMASK, &omask, NULL); @@ -729,10 +728,10 @@ j_resume(const char *cp, int bg) tcsetattr(tty_fd, TCSADRAIN, &tty_state); sigprocmask(SIG_SETMASK, &omask, NULL); - bi_errorf("1st tcsetpgrp(%d, %d) failed: %s", - tty_fd, - (int)((j->flags & JF_SAVEDTTYPGRP) ? - j->saved_ttypgrp : j->pgrp), + bi_errorf("%s %s(%d, %ld) %s: %s", + "1st", "tcsetpgrp", tty_fd, + (long)((j->flags & JF_SAVEDTTYPGRP) ? + j->saved_ttypgrp : j->pgrp), "failed", strerror(rv)); return (1); } @@ -751,12 +750,12 @@ j_resume(const char *cp, int bg) if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) tcsetattr(tty_fd, TCSADRAIN, &tty_state); if (ttypgrp_ok && tcsetpgrp(tty_fd, kshpgrp) < 0) - warningf(true, - "fg: 2nd tcsetpgrp(%d, %ld) failed: %s", - tty_fd, (long)kshpgrp, strerror(errno)); + warningf(true, "%s %s(%d, %ld) %s: %s", + "fg: 2nd", "tcsetpgrp", tty_fd, + (long)kshpgrp, "failed", strerror(errno)); } sigprocmask(SIG_SETMASK, &omask, NULL); - bi_errorf("%s %s %s", "cannot continue job", + bi_errorf("%s %s %s", "can't continue job", cp, strerror(err)); return (1); } @@ -1023,9 +1022,9 @@ j_waitj(Job *j, (j->saved_ttypgrp = tcgetpgrp(tty_fd)) >= 0) j->flags |= JF_SAVEDTTYPGRP; if (tcsetpgrp(tty_fd, kshpgrp) < 0) - warningf(true, - "j_waitj: tcsetpgrp(%d, %ld) failed: %s", - tty_fd, (long)kshpgrp, strerror(errno)); + warningf(true, "%s %s(%d, %ld) %s: %s", + "j_waitj:", "tcsetpgrp", tty_fd, + (long)kshpgrp, "failed", strerror(errno)); if (j->state == PSTOPPED) { j->flags |= JF_SAVEDTTY; tcgetattr(tty_fd, &j->ttystat); @@ -1373,7 +1372,7 @@ j_print(Job *j, int how, struct shf *shf) if (p == j->proc_list) shf_fprintf(shf, "[%d] %c ", j->job, jobchar); else - shf_fprintf(shf, "%s", filler); + shf_puts(filler, shf); } if (how == JP_LONG) @@ -1570,7 +1569,7 @@ remove_job(Job *j, const char *where) for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev) ; if (curr != j) { - internal_warningf("remove_job: job not found (%s)", where); + internal_warningf("remove_job: job %s (%s)", "not found", where); return; } *prev = curr->next; diff --git a/lalloc.c b/lalloc.c index 79627d1..a4d160e 100644 --- a/lalloc.c +++ b/lalloc.c @@ -1,26 +1,26 @@ /*- - * Copyright © 2009 + * Copyright (c) 2009, 2010 * Thorsten Glaser * * Provided that these terms and disclaimer and all copyright notices * are retained or reproduced in an accompanying document, permission - * is granted to deal in this work without restriction, including un‐ + * is granted to deal in this work without restriction, including un- * limited rights to use, publicly perform, distribute, sell, modify, * merge, give away, or sublicence. * - * This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to + * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to * the utmost extent permitted by applicable law, neither express nor * implied; without malicious intent or gross negligence. In no event * may a licensor, author or contributor be held liable for indirect, * direct, other damage, loss, or other issues arising in any way out * of dealing in the work, even if advised of the possibility of such * damage or existence of a defect, except proven that it results out - * of said person’s immediate fault when using the work as intended. + * of said person's immediate fault when using the work as intended. */ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.11 2009/08/08 13:08:51 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.12 2010/08/28 20:22:19 tg Exp $"); /* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */ #if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0) @@ -61,7 +61,8 @@ findptr(ALLOC_ITEM **lpp, char *ptr, Area *ap) #ifndef MKSH_SMALL fail: #endif - internal_errorf("rogue pointer %p", ptr); + internal_errorf("rogue pointer %lX", + (long)(ptrdiff_t)ptr); } return (ap); } @@ -85,7 +86,7 @@ aresize(void *ptr, size_t numb, Area *ap) || ALLOC_ISUNALIGNED(lp) #endif ) - internal_errorf("cannot allocate %lu data bytes", + internal_errorf("can't allocate %lu data bytes", (unsigned long)numb); /* this only works because Area is an ALLOC_ITEM */ lp->next = ap->next; diff --git a/lex.c b/lex.c index ac72394..359bc41 100644 --- a/lex.c +++ b/lex.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.119 2010/08/28 18:50:53 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.120 2010/08/28 20:22:20 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: '%s' %s\n", T_synerr, ")", "missing"); + yyerror("%s: %s\n", T_synerr, "missing )"); #endif /* This done to avoid tests for SHEREDELIM wherever SBASE tested */ @@ -1207,7 +1207,8 @@ readhere(struct ioword *iop) ungetsc(c); while ((c = getsc()) != '\n') { if (c == 0) - yyerror("here document '%s' unclosed\n", eof); + yyerror("%s '%s' unclosed\n", "here document", + eof); Xcheck(xs, xp); Xput(xs, xp, c); } diff --git a/main.c b/main.c index ed5e1ab..23c89c1 100644 --- a/main.c +++ b/main.c @@ -33,7 +33,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.169 2010/08/28 18:50:54 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.170 2010/08/28 20:22:20 tg Exp $"); extern char **environ; @@ -424,7 +424,7 @@ mksh_init(int argc, const char *argv[]) * user will know why things broke. */ if (!current_wd[0] && Flag(FTALKING)) - warningf(false, "Cannot determine current working directory"); + warningf(false, "can't determine current directory"); if (Flag(FLOGIN)) { include(KSH_SYSTEM_PROFILE, 0, NULL, 1); @@ -475,7 +475,7 @@ main(int argc, const char *argv[]) if ((s = mksh_init(argc, argv))) { /* put more entropy into the LCG */ change_random(s, sizeof(*s)); - /* doesn’t return */ + /* doesn't return */ shell(s, true); } return (1); @@ -526,7 +526,7 @@ include(const char *name, int argc, const char **argv, int intr_ok) unwind(i); /* NOTREACHED */ default: - internal_errorf("include: %d", i); + internal_errorf("%s %d", "include", i); /* NOTREACHED */ } } @@ -612,7 +612,7 @@ shell(Source * volatile s, volatile int toplevel) default: source = old_source; quitenv(NULL); - internal_errorf("shell: %d", i); + internal_errorf("%s %d", "shell", i); /* NOTREACHED */ } } @@ -857,8 +857,8 @@ tty_init(bool init_ttystate, bool need_tty) if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) { tty_devtty = 0; if (need_tty) - warningf(false, - "No controlling tty (open /dev/tty: %s)", + warningf(false, "%s: %s %s: %s", + "No controlling tty", "open", "/dev/tty", strerror(errno)); } if (tfd < 0) { @@ -869,15 +869,14 @@ tty_init(bool init_ttystate, bool need_tty) tfd = 2; else { if (need_tty) - warningf(false, - "Can't find tty file descriptor"); + warningf(false, "can't find tty fd"); return; } } if ((tty_fd = fcntl(tfd, F_DUPFD, FDBASE)) < 0) { if (need_tty) - warningf(false, "%s: %s: %s", "j_ttyinit", - "dup of tty fd failed", strerror(errno)); + warningf(false, "%s: %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, "%s: %s: %s", "j_ttyinit", @@ -1279,7 +1278,7 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist) tp->shf = NULL; tp->type = type; #if HAVE_MKSTEMP - shf_snprintf(pathname, len, "%s/%s", dir, "mksh.XXXXXXXXXX"); + 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 19c7126..17f3aff 100644 --- a/misc.c +++ b/misc.c @@ -29,7 +29,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.144 2010/08/28 18:50:55 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.145 2010/08/28 20:22:21 tg Exp $"); unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */ @@ -167,7 +167,7 @@ printoptions(bool verbose) print_columns(shl_stdout, n, options_fmt_entry, &oi, octs + 4, oi.opt_width + 4, true); } else { - /* short version á la AT&T ksh93 */ + /* short version like AT&T ksh93 */ shf_puts(T_set, shl_stdout); while (i < (int)NELEM(options)) { if (Flag(i) && options[i].name) @@ -833,9 +833,10 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp) go->buf[0] = c; go->optarg = go->buf; } else { - warningf(true, "%s%s-%c: unknown option", + warningf(true, "%s%s-%c: %s", (go->flags & GF_NONAME) ? "" : argv[0], - (go->flags & GF_NONAME) ? "" : ": ", c); + (go->flags & GF_NONAME) ? "" : ": ", c, + "unknown option"); if (go->flags & GF_ERROR) bi_errorfz(); } @@ -859,7 +860,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp) go->optarg = go->buf; return (':'); } - warningf(true, "%s%s-'%c' %s", + warningf(true, "%s%s-%c: %s", (go->flags & GF_NONAME) ? "" : argv[0], (go->flags & GF_NONAME) ? "" : ": ", c, "requires an argument"); @@ -1299,19 +1300,20 @@ chvt(const char *fn) if (!(sb.st_mode & S_IFCHR)) errorf("%s %s %s", "chvt: not a char", "device", fn); if ((sb.st_uid != 0) && chown(fn, 0, 0)) - warningf(false, "%s: %s %s", "chvt", "cannot chown root", fn); + warningf(false, "%s: %s %s", "chvt", "can't chown root", fn); if (((sb.st_mode & 07777) != 0600) && chmod(fn, (mode_t)0600)) - warningf(false, "%s: %s %s", "chvt", "cannot chmod 0600", fn); + warningf(false, "%s: %s %s", "chvt", "can't chmod 0600", fn); #if HAVE_REVOKE if (revoke(fn)) #endif - warningf(false, "%s: cannot revoke %s, new shell is" - " potentially insecure", "chvt", fn); + warningf(false, "%s: %s %s", "chvt", + "new shell is potentially insecure, can't revoke", + fn); } if ((fd = open(fn, O_RDWR)) == -1) { sleep(1); if ((fd = open(fn, O_RDWR)) == -1) - errorf("%s: %s %s", "chvt", "cannot open", fn); + errorf("%s: %s %s", "chvt", "can't open", fn); } switch (fork()) { case -1: diff --git a/sh.h b/sh.h index a7ff2ce..309a00f 100644 --- a/sh.h +++ b/sh.h @@ -150,7 +150,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.410 2010/08/28 18:50:55 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.411 2010/08/28 20:22:22 tg Exp $"); #endif #define MKSH_VERSION "R39 2010/08/28" @@ -641,6 +641,8 @@ 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" */ +EXTERN const char T__function[] I__(" function"); +#define T_function (T__function + 1) /* "function" */ enum temp_type { TT_HEREDOC_EXP, /* expanded heredoc */ @@ -1668,6 +1670,7 @@ char *wdcopy(const char *, Area *); const char *wdscan(const char *, int); char *wdstrip(const char *, bool, bool); void tfree(struct op *, Area *); +int fpFUNCTf(struct shf *, int, bool, const char *, struct op *); /* var.c */ void newblock(void); void popblock(void); diff --git a/shf.c b/shf.c index de2ffd3..8a5e45e 100644 --- a/shf.c +++ b/shf.c @@ -18,11 +18,13 @@ * of dealing in the work, even if advised of the possibility of such * damage or existence of a defect, except proven that it results out * of said person's immediate fault when using the work as intended. + *- + * Use %lX instead of %p and floating point isn't supported at all. */ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.38 2010/08/28 18:50:57 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.39 2010/08/28 20:22:23 tg Exp $"); /* flags to shf_emptybuf() */ #define EB_READSW 0x01 /* about to switch to reading */ @@ -704,7 +706,8 @@ shf_snprintf(char *buf, int bsize, const char *fmt, ...) int n; if (!buf || bsize <= 0) - internal_errorf("shf_snprintf: buf %p, bsize %d", buf, bsize); + internal_errorf("shf_snprintf: buf %lX, bsize %d", + (long)(ptrdiff_t)buf, bsize); shf_sopen(buf, bsize, SHF_WR, &shf); va_start(args, fmt); @@ -854,11 +857,6 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) } switch (c) { - case 'p': /* pointer */ - flags &= ~(FL_LONG | FL_SHORT); - flags |= (sizeof(char *) > sizeof(int)) ? - /* hope it fits.. */ FL_LONG : 0; - /* aaahhh... */ case 'd': case 'i': case 'o': @@ -916,7 +914,6 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) *--cp = '0'; break; - case 'p': case 'x': { const char *digits = (flags & FL_UPPER) ? digits_uc : digits_lc; diff --git a/syn.c b/syn.c index 64d063c..4daa04e 100644 --- a/syn.c +++ b/syn.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.50 2010/08/28 18:50:58 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.51 2010/08/28 20:22:23 tg Exp $"); struct nesting_state { int start_token; /* token than began nesting (eg, FOR) */ @@ -740,7 +740,7 @@ const struct tokeninfo { { "do", DO, true }, { "done", DONE, true }, { "in", IN, true }, - { "function", FUNCTION, true }, + { T_function, FUNCTION, true }, { "time", TIME, true }, { "{", '{', true }, { "}", '}', true }, @@ -797,7 +797,7 @@ syntaxerr(const char *what) goto Again; } /* don't quote the EOF */ - yyerror("%s: %s\n", T_synerr, "unexpected EOF"); + yyerror("%s: %s %s\n", T_synerr, "unexpected", "EOF"); /* NOTREACHED */ case LWORD: diff --git a/tree.c b/tree.c index aa861db..88b03e8 100644 --- a/tree.c +++ b/tree.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.30 2010/02/25 20:18:19 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.31 2010/08/28 20:22:24 tg Exp $"); #define INDENT 4 @@ -164,12 +164,10 @@ ptree(struct op *t, int indent, struct shf *shf) fptreef(shf, indent, "%T& ", t->left); break; case TFUNCT: - fptreef(shf, indent, - t->u.ksh_func ? "function %s %T" : "%s() %T", - t->str, t->left); + fpFUNCTf(shf, indent, t->u.ksh_func, t->str, t->left); break; case TTIME: - fptreef(shf, indent, "time %T", t->left); + fptreef(shf, indent, "%s %T", "time", t->left); break; default: shf_puts("", shf); @@ -714,3 +712,12 @@ iofree(struct ioword **iow, Area *ap) } afree(iow, ap); } + +int +fpFUNCTf(struct shf *shf, int i, bool isksh, const char *k, struct op *v) +{ + if (isksh) + return (fptreef(shf, i, "%s %s %T", T_function, k, v)); + else + return (fptreef(shf, i, "%s() %T", k, v)); +} diff --git a/var.c b/var.c index 5252953..383d57f 100644 --- a/var.c +++ b/var.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.111 2010/08/28 18:50:58 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.112 2010/08/28 20:22:24 tg Exp $"); /* * Variables @@ -686,7 +686,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) if (*val == '[') { if (set_refflag) errorf("%s: %s", var, - "reference variable cannot be an array"); + "reference variable can't be an array"); len = array_ref_len(val); if (len == 0) return (NULL); @@ -712,7 +712,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) return (NULL); strdupx(tvar, var, ATEMP); val = NULL; - /* handle foo[*] ⇒ foo (whole array) mapping for R39b */ + /* handle foo[*] => foo (whole array) mapping for R39b */ len = strlen(tvar); if (len > 3 && tvar[len-3] == '[' && tvar[len-2] == '*' && tvar[len-1] == ']') @@ -1051,7 +1051,7 @@ change_random(const void *vp, size_t n) h = oaathash_update(h, k, sizeof(k)); kshstate_v.lcg_state_ = oaathash_finalise(h); #elif defined(MKSH_A4PB) - /* forced by the user to use arc4random_pushb(3) • Cygwin? */ + /* forced by the user to use arc4random_pushb(3) - Cygwin? */ { uint32_t prv;