rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit 47151e4647b8decd77bb65c4fbe0dadb16ae79a8
parent 79fcb6da5a44da33459122881085297c35e781f1
Author: Toby Goodwin <toby@paccrat.org>
Date:   Tue, 20 Mar 2018 21:58:03 +0000

whitespace cleanup

Diffstat:
A.vimrc | 1+
MChangeLog | 21+++++++++++++--------
MEXAMPLES | 130++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mbuiltins.c | 140++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mconfigure.ac | 12++++++------
Mconfigure.scan | 6+++---
Mdevelop.c | 516++++++++++++++++++++++++++++++++++++++++----------------------------------------
Medit-editline.c | 8++++----
Medit-vrl.c | 4++--
Mfootobar.c | 2+-
Mgetopt.c | 4++--
Mglob.c | 2+-
Mhistory.c | 4++--
Minput.c | 2+-
Mmain.c | 10+++++-----
Mmkinstalldirs | 2+-
Mmksignal.c | 2+-
Mnalloc.c | 4++--
Mparse.y | 2+-
Mrc.1 | 2+-
Msignal.c | 4++--
Mstatus.c | 2+-
Mtree.c | 2+-
Mtrip.rc | 4++--
Mwhich.c | 2+-
25 files changed, 447 insertions(+), 441 deletions(-)

diff --git a/.vimrc b/.vimrc @@ -0,0 +1 @@ +set noet sw=8 diff --git a/ChangeLog b/ChangeLog @@ -174,19 +174,19 @@ Changes since rc-1.4: General changes: - Some small memory leaks/uninit references revealed by Purify. + Some small memory leaks/uninit references revealed by Purify. - $bqstatus for querying the exit status of a backquote. + $bqstatus for querying the exit status of a backquote. - Globbing through unreadable directories. + Globbing through unreadable directories. - More options to whatis. + More options to whatis. - History append which always re-opens the file (avoids - inconsistencies over multiple NFS-mounted accesses to - $history). + History append which always re-opens the file (avoids + inconsistencies over multiple NFS-mounted accesses to + $history). - Support "rc -s". + Support "rc -s". --------- @@ -915,3 +915,8 @@ Changes since rc-1.5b2 2018-03-19 Feature: default values for $nl and $tab (github #43). + +2018-03-20 + + Tidiness: be consistent about using tabs everywhere, and add a .vimrc to + keep it so in the future. diff --git a/EXAMPLES b/EXAMPLES @@ -110,19 +110,19 @@ in your path.) #!/bin/rc if (~ $#* 0) - exec openfile + exec openfile create = () files = () for (i in $*) - if (test -f $i) { - files = ($files $i) - } else { - create = ($create $i) + if (test -f $i) { + files = ($files $i) + } else { + create = ($create $i) } create = `{ pick $create } files = ($files $create) for (i in $create) - > $i + > $i if (! ~ $#files 0) openfile $files @@ -139,12 +139,12 @@ to set $foo to a single line from the terminal. (due to John Mackin <john@syd.dit.csiro.au>) fn read { - x=() { - x = `` ($nl) { awk '{print; print 0; exit}' ^ $nl ^ \ - 'END {print 1; print 1}' } - $1 = $x(1) - return $x(2) - } + x=() { + x = `` ($nl) { awk '{print; print 0; exit}' ^ $nl ^ \ + 'END {print 1; print 1}' } + $1 = $x(1) + return $x(2) + } } From cs.wisc.edu!dws Fri Aug 2 18:16:14 1991 @@ -280,62 +280,62 @@ static void b_kill(char **av) boolean res; if (!av[1]) { - set(TRUE); - return; + set(TRUE); + return; } #undef STRCMP #define STRCMP strcmp if ( '-' == av[1][0]) { - char *p = 1+av[1]; - if (0 == strcmp(av[1], "-l")){ - int r; const int nsig = NUMOFSIGNALS; - const int C = 4, R = 1 + (int)((nsig-2)/C); - for (r=1; r<=R; r++){ - int j; - for (j=r; j<nsig; j+=R){ - fprint(1, "%s%d. %s\t", j<10?" ":"", j, signals[j][0]); - } - fprint(1,"\n"); - } - set(TRUE); - return; - } - n++; - if ( (signal=a2u(p)) < 0){ - int i; - for (i = 1; i < NUMOFSIGNALS; i++){ - char UPPER[31], *u=UPPER, *q; - for (q=signals[i][0]; *q; q++, u++) *u = toupper(*q); - *u = '\0'; - - if (*signals[i][0] && - (!STRCMP(signals[i][0], p) || !STRCMP(3+signals[i][0],p) - || !STRCMP(UPPER, p) || !STRCMP(3+UPPER, p) ) ) - { - signal = i; - break; - } - } - if (signal < 0){ - fprint(2,"kill: bad signal %s\n", av[1]); - set(FALSE); - return; - } - } + char *p = 1+av[1]; + if (0 == strcmp(av[1], "-l")){ + int r; const int nsig = NUMOFSIGNALS; + const int C = 4, R = 1 + (int)((nsig-2)/C); + for (r=1; r<=R; r++){ + int j; + for (j=r; j<nsig; j+=R){ + fprint(1, "%s%d. %s\t", j<10?" ":"", j, signals[j][0]); + } + fprint(1,"\n"); + } + set(TRUE); + return; + } + n++; + if ( (signal=a2u(p)) < 0){ + int i; + for (i = 1; i < NUMOFSIGNALS; i++){ + char UPPER[31], *u=UPPER, *q; + for (q=signals[i][0]; *q; q++, u++) *u = toupper(*q); + *u = '\0'; + + if (*signals[i][0] && + (!STRCMP(signals[i][0], p) || !STRCMP(3+signals[i][0],p) + || !STRCMP(UPPER, p) || !STRCMP(3+UPPER, p) ) ) + { + signal = i; + break; + } + } + if (signal < 0){ + fprint(2,"kill: bad signal %s\n", av[1]); + set(FALSE); + return; + } + } } #undef STRCMP for (res=TRUE; av[n]; n++){ - if( (pid = (pid_t) a2u(av[n])) < 0){ - fprint(2, "kill: bad process number %s\n", av[n]); - res = FALSE; - continue; - } - if (kill(pid,signal)){ - uerror("kill"); - res = FALSE; - continue; - } + if( (pid = (pid_t) a2u(av[n])) < 0){ + fprint(2, "kill: bad process number %s\n", av[n]); + res = FALSE; + continue; + } + if (kill(pid,signal)){ + uerror("kill"); + res = FALSE; + continue; + } } set(res); } @@ -513,13 +513,13 @@ while (~ $1 -*) macros=$1; case -k fflag=(); kflag=1; - shift; - break; + shift; + break; case -f # locate related too filenames kflag=(); fflag=1; - shift; - break; + shift; + break; case -* echo bad flag '`'^$1^'''' >[1=2]; usage; @@ -585,7 +585,7 @@ while (!~ $1 ()) { dont=() for (x in $Cat) { if (~ `{echo $x | sed 's/\/[mc]a[nt][1-8l]//'} \ - `{echo $file | sed 's/\/[mc]a[nt][1-8l]//'}) { + `{echo $file | sed 's/\/[mc]a[nt][1-8l]//'}) { dont=1; break; } diff --git a/builtins.c b/builtins.c @@ -46,27 +46,27 @@ static struct { { b_eval, "eval" }, { b_exec, "exec" }, { b_exit, "exit" }, - { b_flag, "flag" }, + { b_flag, "flag" }, #if HAVE_SETRLIMIT - { b_limit, "limit" }, + { b_limit, "limit" }, #endif - { b_newpgrp, "newpgrp" }, - { b_return, "return" }, - { b_shift, "shift" }, - { b_umask, "umask" }, - { b_wait, "wait" }, - { b_whatis, "whatis" }, - { b_dot, "." }, + { b_newpgrp, "newpgrp" }, + { b_return, "return" }, + { b_shift, "shift" }, + { b_umask, "umask" }, + { b_wait, "wait" }, + { b_whatis, "whatis" }, + { b_dot, "." }, #ifdef ADDONS - ADDONS + ADDONS #endif }; extern builtin_t *isbuiltin(char *s) { int i; for (i = 0; i < arraysize(builtins); i++) - if (streq(builtins[i].name, s)) - return builtins[i].p; + if (streq(builtins[i].name, s)) + return builtins[i].p; return NULL; } @@ -110,10 +110,10 @@ extern void b_exec(char **ignore) { static void b_echo(char **av) { char *format = "%A\n"; if (*++av != NULL) { - if (streq(*av, "-n")) - format = "%A", av++; - else if (streq(*av, "--")) - av++; + if (streq(*av, "-n")) + format = "%A", av++; + else if (streq(*av, "--")) + av++; } fprint(1, format, av); set(TRUE); @@ -127,70 +127,70 @@ static void b_cd(char **av) { char *path = NULL; size_t t, pathlen = 0; if (*++av == NULL) { - s = varlookup("home"); - *av = (s == NULL) ? "/" : s->w; + s = varlookup("home"); + *av = (s == NULL) ? "/" : s->w; } else if (av[1] != NULL) { - arg_count("cd"); - return; + arg_count("cd"); + return; } if (isabsolute(*av) || streq(*av, ".") || streq(*av, "..")) { /* absolute pathname? */ - if (chdir(*av) < 0) { - set(FALSE); - uerror(*av); - } else - set(TRUE); + if (chdir(*av) < 0) { + set(FALSE); + uerror(*av); + } else + set(TRUE); } else { - s = varlookup("cdpath"); - if (s == NULL) { - s = &nil; - nil.w = ""; - nil.n = NULL; - } - do { - if (s != &nil && *s->w != '\0') { - t = strlen(*av) + strlen(s->w) + 2; - if (t > pathlen) - path = nalloc(pathlen = t); - strcpy(path, s->w); - if (!streq(s->w, "/")) /* "//" is special to POSIX */ - strcat(path, "/"); - strcat(path, *av); - } else { - pathlen = 0; - path = *av; - } - if (chdir(path) >= 0) { - set(TRUE); - if (interactive && *s->w != '\0' && !streq(s->w, ".")) - fprint(1, "%s\n", path); - return; - } - s = s->n; - } while (s != NULL); - fprint(2, "couldn't cd to %s\n", *av); - set(FALSE); + s = varlookup("cdpath"); + if (s == NULL) { + s = &nil; + nil.w = ""; + nil.n = NULL; + } + do { + if (s != &nil && *s->w != '\0') { + t = strlen(*av) + strlen(s->w) + 2; + if (t > pathlen) + path = nalloc(pathlen = t); + strcpy(path, s->w); + if (!streq(s->w, "/")) /* "//" is special to POSIX */ + strcat(path, "/"); + strcat(path, *av); + } else { + pathlen = 0; + path = *av; + } + if (chdir(path) >= 0) { + set(TRUE); + if (interactive && *s->w != '\0' && !streq(s->w, ".")) + fprint(1, "%s\n", path); + return; + } + s = s->n; + } while (s != NULL); + fprint(2, "couldn't cd to %s\n", *av); + set(FALSE); } } static void b_umask(char **av) { int i; if (*++av == NULL) { - set(TRUE); - i = umask(0); - umask(i); - fprint(1, "0%o\n", i); + set(TRUE); + i = umask(0); + umask(i); + fprint(1, "0%o\n", i); } else if (av[1] == NULL) { - i = o2u(*av); - if ((unsigned int) i > 0777) { - fprint(2, "bad umask\n"); - set(FALSE); - } else { - umask(i); - set(TRUE); - } + i = o2u(*av); + if ((unsigned int) i > 0777) { + fprint(2, "bad umask\n"); + set(FALSE); + } else { + umask(i); + set(TRUE); + } } else { - arg_count("umask"); - return; + arg_count("umask"); + return; } } @@ -203,7 +203,7 @@ static void b_exit(char **av) { static void b_flag(char **av) { bool *flagp = NULL; char f; - int mode = 3; /* 0 = reset (-), 1 = set (+), 2 = test */ + int mode = 3; /* 0 = reset (-), 1 = set (+), 2 = test */ const char *usage = "usage: flag f [ + | - ]\n"; if (*++av == NULL) { @@ -246,7 +246,7 @@ static void b_flag(char **av) { flagp = &dashess; break; case 'v': flagp = &dashvee; break; case 'x': flagp = &dashex; break; - } + } if (flagp != NULL) { if (mode == 2) set(*flagp); diff --git a/configure.ac b/configure.ac @@ -101,7 +101,7 @@ AC_ARG_ENABLE(protect-env, [ --disable-protect-env Don't protect environment AC_ARG_ENABLE(def-interp, [ --enable-def-interp=/bin/foo - Use /bin/foo as default interpreter [[/bin/sh]]], + Use /bin/foo as default interpreter [[/bin/sh]]], [ case "$enableval" in no) @@ -117,8 +117,8 @@ AC_ARG_ENABLE(def-interp, AC_ARG_ENABLE(def-path, [ --enable-def-path=\"/usr/local/bin/\",\"/usr/bin\" - Default path [[All of these that exist - (/usr/local/bin /usr/bin /usr/bsd /usr/ucb /bin .)]]], + Default path [[All of these that exist + (/usr/local/bin /usr/bin /usr/bsd /usr/ucb /bin .)]]], [ case "$enableval" in no|yes) ;; @@ -159,9 +159,9 @@ AM_CONDITIONAL(AMC_DEVELOP, test "$rc_develop" = true) AC_ARG_WITH(history, [ --with-history Build history subprograms],[ case "$withval" in - yes) rc_history=yes ;; - *) rc_history=no ;; - esac + yes) rc_history=yes ;; + *) rc_history=no ;; + esac ], rc_history=no) AM_CONDITIONAL(AMC_HISTORY, test "$rc_history" = yes) diff --git a/configure.scan b/configure.scan @@ -43,7 +43,7 @@ AC_FUNC_STAT AC_CHECK_FUNCS([dup2 memset mkfifo strchr strerror strrchr strspn]) AC_CONFIG_FILES([Makefile - rc-1.7s20020820/Makefile - rc-1.7s20021127/=build/Makefile - rc-1.7s20021127/Makefile]) + rc-1.7s20020820/Makefile + rc-1.7s20021127/=build/Makefile + rc-1.7s20021127/Makefile]) AC_OUTPUT diff --git a/develop.c b/develop.c @@ -7,297 +7,297 @@ void dump(Node *, int); /* dump a Node * as a tree */ static void dump_1(char *p, Node *n, int indent) { - fprint(2, "%s:\n", p); - dump(n->u[0].p, indent + 1); + fprint(2, "%s:\n", p); + dump(n->u[0].p, indent + 1); } static void dump_2(char *p, Node *n, int indent) { - fprint(2, "%s:\n", p); - dump(n->u[0].p, indent + 1); - if (n->u[1].p != NULL) - dump(n->u[1].p, indent + 1); + fprint(2, "%s:\n", p); + dump(n->u[0].p, indent + 1); + if (n->u[1].p != NULL) + dump(n->u[1].p, indent + 1); } static void dump_3(char *p, Node *n, int indent) { - fprint(2, "%s:\n", p); - dump(n->u[0].p, indent + 1); - if (n->u[1].p != NULL) - dump(n->u[1].p, indent + 1); - if (n->u[2].p != NULL) - dump(n->u[2].p, indent + 1); + fprint(2, "%s:\n", p); + dump(n->u[0].p, indent + 1); + if (n->u[1].p != NULL) + dump(n->u[1].p, indent + 1); + if (n->u[2].p != NULL) + dump(n->u[2].p, indent + 1); } static void dump_s(char *p, Node *n, int indent) { - fprint(2, "%s: %S\n", p, n->u[0].s); + fprint(2, "%s: %S\n", p, n->u[0].s); } static void dump_pipe(char *p, Node *n, int indent) { - int ifd = n->u[0].i, ofd = n->u[1].i; - fprint(2, "%s %d %d:\n", p, ifd, ofd); - dump(n->u[2].p, indent + 1); - dump(n->u[3].p, indent + 1); + int ifd = n->u[0].i, ofd = n->u[1].i; + fprint(2, "%s %d %d:\n", p, ifd, ofd); + dump(n->u[2].p, indent + 1); + dump(n->u[3].p, indent + 1); } static char *redir(int op) { - switch (op) { - case rCreate: return ">"; - case rAppend: return ">>"; - case rFrom: return "<"; - case rHeredoc: return "<<"; - case rHerestring: return "<<<"; - default: return "?"; - } + switch (op) { + case rCreate: return ">"; + case rAppend: return ">>"; + case rFrom: return "<"; + case rHeredoc: return "<<"; + case rHerestring: return "<<<"; + default: return "?"; + } } static void dump_dup(char *p, Node *n, int indent) { - fprint(2, "%s %s %d %d:\n", p, redir(n->u[0].i), n->u[1].i, n->u[2].i); + fprint(2, "%s %s %d %d:\n", p, redir(n->u[0].i), n->u[1].i, n->u[2].i); } static void dump_redir(char *p, Node *n, int indent) { - fprint(2, "%s %s %d:\n", p, redir(n->u[0].i), n->u[1].i); - dump(n->u[2].p, indent + 1); + fprint(2, "%s %s %d:\n", p, redir(n->u[0].i), n->u[1].i); + dump(n->u[2].p, indent + 1); } void dump(Node *n, int indent) { - int i; + int i; - if (n == NULL) - return; + if (n == NULL) + return; - for (i = 0; i < indent; ++i) - fprint(2, " "); + for (i = 0; i < indent; ++i) + fprint(2, " "); - switch (n->type) { - case nAndalso: - dump_2("nAndalso", n, indent); - break; - case nArgs: - dump_2("nArgs", n, indent); - break; - case nAssign: - dump_2("nAassign", n, indent); - break; - case nBackq: - dump_1("nBackq", n, indent); - break; - case nBang: - dump_1("nBang", n, indent); - break; - case nBody: - dump_2("nBody", n, indent); - break; - case nBrace: - dump_1("nBrace", n, indent); - break; - case nCase: - dump_1("nCase", n, indent); - break; - case nCbody: - dump_2("nCbody", n, indent); - break; - case nConcat: - dump_2("nConcat", n, indent); - break; - case nCount: - dump_1("nCount", n, indent); - break; - case nDup: - dump_dup("nDup", n, indent); - break; - case nElse: - dump_2("nElse", n, indent); - break; - case nEpilog: - dump_2("nEpilog", n, indent); - break; - case nFlat: - dump_1("nFlat", n, indent); - break; - case nForin: - dump_3("nForin", n, indent); - break; - case nIf: - dump_2("nIf", n, indent); - break; - case nLappend: - dump_2("nLappend", n, indent); - break; - case nMatch: - dump_2("nMatch", n, indent); - break; - case nNewfn: - dump_2("nNewfn", n, indent); - break; - case nNmpipe: - dump_redir("nNowait", n, indent); - break; - case nNowait: - dump_1("nNowait", n, indent); - break; - case nOrelse: - dump_2("nNowait", n, indent); - break; - case nPipe: - dump_pipe("nPipe", n, indent); - break; - case nPre: - dump_2("nPre", n, indent); - break; - case nRedir: - dump_redir("nRedir", n, indent); - break; - case nRmfn: - dump_1("nRmfn", n, indent); - break; - case nSubshell: - dump_1("nSubshell", n, indent); - break; - case nSwitch: - dump_2("nSwitch", n, indent); - break; - case nVar: - dump_1("nVar", n, indent); - break; - case nVarsub: - dump_2("nVarsub", n, indent); - break; - case nWhile: - dump_2("nWhile", n, indent); - break; - case nWord: - dump_s("nWord", n, indent); - break; - default: - fprint(2, "unknown\n"); - break; - } + switch (n->type) { + case nAndalso: + dump_2("nAndalso", n, indent); + break; + case nArgs: + dump_2("nArgs", n, indent); + break; + case nAssign: + dump_2("nAassign", n, indent); + break; + case nBackq: + dump_1("nBackq", n, indent); + break; + case nBang: + dump_1("nBang", n, indent); + break; + case nBody: + dump_2("nBody", n, indent); + break; + case nBrace: + dump_1("nBrace", n, indent); + break; + case nCase: + dump_1("nCase", n, indent); + break; + case nCbody: + dump_2("nCbody", n, indent); + break; + case nConcat: + dump_2("nConcat", n, indent); + break; + case nCount: + dump_1("nCount", n, indent); + break; + case nDup: + dump_dup("nDup", n, indent); + break; + case nElse: + dump_2("nElse", n, indent); + break; + case nEpilog: + dump_2("nEpilog", n, indent); + break; + case nFlat: + dump_1("nFlat", n, indent); + break; + case nForin: + dump_3("nForin", n, indent); + break; + case nIf: + dump_2("nIf", n, indent); + break; + case nLappend: + dump_2("nLappend", n, indent); + break; + case nMatch: + dump_2("nMatch", n, indent); + break; + case nNewfn: + dump_2("nNewfn", n, indent); + break; + case nNmpipe: + dump_redir("nNowait", n, indent); + break; + case nNowait: + dump_1("nNowait", n, indent); + break; + case nOrelse: + dump_2("nNowait", n, indent); + break; + case nPipe: + dump_pipe("nPipe", n, indent); + break; + case nPre: + dump_2("nPre", n, indent); + break; + case nRedir: + dump_redir("nRedir", n, indent); + break; + case nRmfn: + dump_1("nRmfn", n, indent); + break; + case nSubshell: + dump_1("nSubshell", n, indent); + break; + case nSwitch: + dump_2("nSwitch", n, indent); + break; + case nVar: + dump_1("nVar", n, indent); + break; + case nVarsub: + dump_2("nVarsub", n, indent); + break; + case nWhile: + dump_2("nWhile", n, indent); + break; + case nWord: + dump_s("nWord", n, indent); + break; + default: + fprint(2, "unknown\n"); + break; + } } void tree_dump(Node *f) { - dump(f, 0); + dump(f, 0); } #if 0 - bool dollar = f->flags & FMT_altform; - Node *n = va_arg(f->args, Node *); + bool dollar = f->flags & FMT_altform; + Node *n = va_arg(f->args, Node *); - if (n == NULL) { - fmtprint(f, "()"); - return FALSE; - } - switch (n->type) { - case nBang: fmtprint(f, "!%X", n->u[0].p); break; - case nCase: fmtprint(f, "case %X", n->u[0].p); break; - case nNowait: fmtprint(f, "%X&", n->u[0].p); break; - case nRmfn: fmtprint(f, "fn %X", n->u[0].p); break; - case nSubshell: fmtprint(f, "@ %X", n->u[0].p); break; - case nAndalso: fmtprint(f, "%X&&%X", n->u[0].p, n->u[1].p); break; - case nAssign: fmtprint(f, "%X=%X", n->u[0].p, n->u[1].p); break; - case nConcat: fmtprint(f, "%X^%X", n->u[0].p, n->u[1].p); break; - case nElse: fmtprint(f, "{%X}else %X", n->u[0].p, n->u[1].p); break; - case nNewfn: fmtprint(f, "fn %X {%X}", n->u[0].p, n->u[1].p); break; - case nIf: fmtprint(f, "if(%X)%X", n->u[0].p, n->u[1].p); break; - case nOrelse: fmtprint(f, "%X||%X", n->u[0].p, n->u[1].p); break; - case nArgs: fmtprint(f, "nArgs: "); - Xconv(n->u[0].p, 4); - Xconv(n->u[1].p, 4); break; - case nSwitch: fmtprint(f, "switch(%X){%X}", n->u[0].p, n->u[1].p); break; - case nMatch: fmtprint(f, "~ %X %X", n->u[0].p, n->u[1].p); break; - case nWhile: fmtprint(f, "while(%X)%X", n->u[0].p, n->u[1].p); break; - case nForin: fmtprint(f, "for(%X in %X)%X", n->u[0].p, n->u[1].p, n->u[2].p); break; - case nVarsub: fmtprint(f, "$%X(%X)", n->u[0].p, n->u[1].p); break; - case nWord: - fmtprint(f, n->u[2].i && quotep(n->u[0].s, dollar) ? - "%#S" : "%S", n->u[0].s); - break; - case nLappend: { - static bool inlist; - if (!inlist) { - inlist = TRUE; - fmtprint(f, "(%X %X)", n->u[0].p, n->u[1].p); - inlist = FALSE; - } else { - fmtprint(f, "%X %X", n->u[0].p, n->u[1].p); - } - break; - } - case nCount: case nFlat: case nVar: { - char *lp = "", *rp = ""; - Node *n0 = n->u[0].p; + if (n == NULL) { + fmtprint(f, "()"); + return FALSE; + } + switch (n->type) { + case nBang: fmtprint(f, "!%X", n->u[0].p); break; + case nCase: fmtprint(f, "case %X", n->u[0].p); break; + case nNowait: fmtprint(f, "%X&", n->u[0].p); break; + case nRmfn: fmtprint(f, "fn %X", n->u[0].p); break; + case nSubshell: fmtprint(f, "@ %X", n->u[0].p); break; + case nAndalso: fmtprint(f, "%X&&%X", n->u[0].p, n->u[1].p); break; + case nAssign: fmtprint(f, "%X=%X", n->u[0].p, n->u[1].p); break; + case nConcat: fmtprint(f, "%X^%X", n->u[0].p, n->u[1].p); break; + case nElse: fmtprint(f, "{%X}else %X", n->u[0].p, n->u[1].p); break; + case nNewfn: fmtprint(f, "fn %X {%X}", n->u[0].p, n->u[1].p); break; + case nIf: fmtprint(f, "if(%X)%X", n->u[0].p, n->u[1].p); break; + case nOrelse: fmtprint(f, "%X||%X", n->u[0].p, n->u[1].p); break; + case nArgs: fmtprint(f, "nArgs: "); + Xconv(n->u[0].p, 4); + Xconv(n->u[1].p, 4); break; + case nSwitch: fmtprint(f, "switch(%X){%X}", n->u[0].p, n->u[1].p); break; + case nMatch: fmtprint(f, "~ %X %X", n->u[0].p, n->u[1].p); break; + case nWhile: fmtprint(f, "while(%X)%X", n->u[0].p, n->u[1].p); break; + case nForin: fmtprint(f, "for(%X in %X)%X", n->u[0].p, n->u[1].p, n->u[2].p); break; + case nVarsub: fmtprint(f, "$%X(%X)", n->u[0].p, n->u[1].p); break; + case nWord: + fmtprint(f, n->u[2].i && quotep(n->u[0].s, dollar) ? + "%#S" : "%S", n->u[0].s); + break; + case nLappend: { + static bool inlist; + if (!inlist) { + inlist = TRUE; + fmtprint(f, "(%X %X)", n->u[0].p, n->u[1].p); + inlist = FALSE; + } else { + fmtprint(f, "%X %X", n->u[0].p, n->u[1].p); + } + break; + } + case nCount: case nFlat: case nVar: { + char *lp = "", *rp = ""; + Node *n0 = n->u[0].p; - if (n0->type != nWord) - lp = "(", rp = ")"; + if (n0->type != nWord) + lp = "(", rp = ")"; - switch (n->type) { - default: panic("this can't happen"); break; - case nCount: fmtprint(f, "$#%s%#T%s", lp, n0, rp); break; - case nFlat: fmtprint(f, "$^%s%#T%s", lp, n0, rp); break; - case nVar: fmtprint(f, "$%s%#T%s", lp, n0, rp); break; - } - break; - } - case nDup: - if (n->u[2].i != -1) - fmtprint(f, "%D[%d=%d]", n->u[0].i, n->u[1].i, n->u[2].i); - else - fmtprint(f, "%D[%d=]", n->u[0].i, n->u[1].i); - break; - case nBackq: { - Node *n0 = n->u[0].p, *n00; - if (n0 != NULL && n0->type == nVar - && (n00 = n0->u[0].p) != NULL && n00->type == nWord && streq(n00->u[0].s, "ifs")) - fmtprint(f, "`"); - else - fmtprint(f, "``%X", n0); - fmtprint(f, "{%X}", n->u[1].p); - break; - } - case nCbody: - case nBody: { - Node *n0 = n->u[0].p; - if (n0 != NULL) - fmtprint(f, "%X", n->u[0].p); - if (n->u[1].p != NULL) { - if (n0 != NULL && n0->type != nNowait) - fmtprint(f, ";"); - fmtprint(f, "%X", n->u[1].p); - } - break; - } - case nBrace: - fmtprint(f, "{%X}", n->u[0].p); - if (n->u[1].p != NULL) - fmtprint(f, "%X", n->u[1].p); - break; - case nEpilog: - case nPre: - fmtprint(f, "%X", n->u[0].p); - if (n->u[1].p != NULL) - fmtprint(f, " %X", n->u[1].p); - break; - case nPipe: { - int ofd = n->u[0].i, ifd = n->u[1].i; - fmtprint(f, "%X|", n->u[2].p); - if (ifd != 0) - fmtprint(f, "[%d=%d]", ofd, ifd); - else if (ofd != 1) - fmtprint(f, "[%d]", ofd); - fmtprint(f, "%X", n->u[3].p); - break; - } - case nRedir: { - int op = n->u[0].i; - fmtprint(f, "%D", op); - fmtprint(f, "[%d]", n->u[1].i); - fmtprint(f, "%X", n->u[2].p); - break; - } - case nNmpipe: { - int op = n->u[0].i; - fmtprint(f, "%D", op); - fmtprint(f, "[%d]", n->u[1].i); - fmtprint(f, "{%X}", n->u[2].p); - break; - } - } - return FALSE; + switch (n->type) { + default: panic("this can't happen"); break; + case nCount: fmtprint(f, "$#%s%#T%s", lp, n0, rp); break; + case nFlat: fmtprint(f, "$^%s%#T%s", lp, n0, rp); break; + case nVar: fmtprint(f, "$%s%#T%s", lp, n0, rp); break; + } + break; + } + case nDup: + if (n->u[2].i != -1) + fmtprint(f, "%D[%d=%d]", n->u[0].i, n->u[1].i, n->u[2].i); + else + fmtprint(f, "%D[%d=]", n->u[0].i, n->u[1].i); + break; + case nBackq: { + Node *n0 = n->u[0].p, *n00; + if (n0 != NULL && n0->type == nVar + && (n00 = n0->u[0].p) != NULL && n00->type == nWord && streq(n00->u[0].s, "ifs")) + fmtprint(f, "`"); + else + fmtprint(f, "``%X", n0); + fmtprint(f, "{%X}", n->u[1].p); + break; + } + case nCbody: + case nBody: { + Node *n0 = n->u[0].p; + if (n0 != NULL) + fmtprint(f, "%X", n->u[0].p); + if (n->u[1].p != NULL) { + if (n0 != NULL && n0->type != nNowait) + fmtprint(f, ";"); + fmtprint(f, "%X", n->u[1].p); + } + break; + } + case nBrace: + fmtprint(f, "{%X}", n->u[0].p); + if (n->u[1].p != NULL) + fmtprint(f, "%X", n->u[1].p); + break; + case nEpilog: + case nPre: + fmtprint(f, "%X", n->u[0].p); + if (n->u[1].p != NULL) + fmtprint(f, " %X", n->u[1].p); + break; + case nPipe: { + int ofd = n->u[0].i, ifd = n->u[1].i; + fmtprint(f, "%X|", n->u[2].p); + if (ifd != 0) + fmtprint(f, "[%d=%d]", ofd, ifd); + else if (ofd != 1) + fmtprint(f, "[%d]", ofd); + fmtprint(f, "%X", n->u[3].p); + break; + } + case nRedir: { + int op = n->u[0].i; + fmtprint(f, "%D", op); + fmtprint(f, "[%d]", n->u[1].i); + fmtprint(f, "%X", n->u[2].p); + break; + } + case nNmpipe: { + int op = n->u[0].i; + fmtprint(f, "%D", op); + fmtprint(f, "[%d]", n->u[1].i); + fmtprint(f, "{%X}", n->u[2].p); + break; + } + } + return FALSE; } #endif diff --git a/edit-editline.c b/edit-editline.c @@ -17,11 +17,11 @@ void *edit_begin(int fd) { List *hist; struct cookie *c; - hist = varlookup("history"); - if (hist != NULL) - if (read_history(hist->w) != 0 && + hist = varlookup("history"); + if (hist != NULL) + if (read_history(hist->w) != 0 && errno != ENOENT) /* ignore if missing */ - uerror(hist->w); + uerror(hist->w); c = ealloc(sizeof *c); c->buffer = NULL; diff --git a/edit-vrl.c b/edit-vrl.c @@ -21,8 +21,8 @@ void *edit_begin(int fd) { struct cookie *c; - hist = varlookup("history"); - if (hist != NULL) + hist = varlookup("history"); + if (hist != NULL) ; /* XXX will need to loop calling add_history() */ diff --git a/footobar.c b/footobar.c @@ -169,7 +169,7 @@ static bool Tconv(Format *f, int ignore) { fmtprint(f, "{%T}", n->u[2].p); break; } - } + } return FALSE; } diff --git a/getopt.c b/getopt.c @@ -6,9 +6,9 @@ int rc_optopt; char *rc_optarg; /* getopt routine courtesy of David Sanderson */ - + extern int rc_getopt(int argc, char **argv, char *opts) { - static int sp = 1; + static int sp = 1; int c; char *cp; if (rc_optind == 0) /* reset rc_getopt() */ diff --git a/glob.c b/glob.c @@ -94,7 +94,7 @@ static List *dmatch(char *d, char *p, char *m) { int i; /* - return a match if there are no metacharacters; allows globbing through + return a match if there are no metacharacters; allows globbing through directories with no read permission. make sure the file exists, though. */ matched = TRUE; diff --git a/history.c b/history.c @@ -13,7 +13,7 @@ BUGS: There is an implicit assumption that commands are no - more than 1k characters long. + more than 1k characters long. */ #include "rc.h" @@ -318,7 +318,7 @@ next: s = getcommand(); if (!isin(s, replace[i].old)) goto next; else { - int j; + int j; for (j = 0; j <= replace[i].reps; j++) s = sub(s, replace[i].old, replace[i].new); } diff --git a/input.c b/input.c @@ -308,7 +308,7 @@ extern Node *doit(bool clobberexecit) { eof = (lastchar == EOF); /* "lastchar" can be clobbered during a walk() */ if (parsetree != NULL) { if (RC_DEVELOP) - tree_dump(parsetree); + tree_dump(parsetree); if (execit) walk(parsetree, TRUE); else if (dashex && dashen) diff --git a/main.c b/main.c @@ -83,17 +83,17 @@ quitopts: inithash(); initparse(); assigndefault("ifs", " ", "\t", "\n", (void *)0); - assigndefault("nl", "\n", (void *)0); + assigndefault("nl", "\n", (void *)0); #ifdef DEFAULTPATH assigndefault("path", DEFAULTPATH, (void *)0); #endif assigndefault("pid", nprint("%d", rc_pid), (void *)0); assigndefault("prompt", "; ", "", (void *)0); - assigndefault("tab", "\t", (void *)0); + assigndefault("tab", "\t", (void *)0); assigndefault("version", - VERSION, - "$Release: @(#)" PACKAGE " " VERSION " " DESCRIPTION " $", - (void *)0 ); + VERSION, + "$Release: @(#)" PACKAGE " " VERSION " " DESCRIPTION " $", + (void *)0 ); initenv(envp); initinput(); null[0] = NULL; diff --git a/mkinstalldirs b/mkinstalldirs @@ -98,7 +98,7 @@ case $dirmode in # Clean up after NextStep and OpenStep mkdir. for d in ./-m ./-p ./--version "./$dirmode"; do - test -d $d && rmdir $d + test -d $d && rmdir $d done fi ;; diff --git a/mksignal.c b/mksignal.c @@ -224,7 +224,7 @@ int main(void) { /* yes, we could avoid the quadratic searching with an aux array. fap. */ for (s = 1; s <= maxsig; ++s) { - for (snp = signamings; snp->signo && snp->signo != s; ++snp) + for (snp = signamings; snp->signo && snp->signo != s; ++snp) /* */; if (snp->signo) fprintf(outf, "\t{\"%s\",\t\"%s\"},\n", diff --git a/nalloc.c b/nalloc.c @@ -44,13 +44,13 @@ static void getblock(size_t n) { extern void *nalloc(size_t n) { size_t base; Block *ulp; - n = alignto(n, sizeof(align_t)); + n = alignto(n, sizeof(align_t)); ulp = ul; if (ulp != NULL && n + (base = ulp->used) < ulp->size) { ulp->used = base + n; return &ulp->mem[base]; } else { - getblock(n); + getblock(n); assert(ul->used == 0); (ulp = ul)->used = n; return &ulp->mem[0]; diff --git a/parse.y b/parse.y @@ -113,7 +113,7 @@ cmd : /* empty */ %prec WHILE { $$ = NULL; } | TWIDDLE optcaret word words { $$ = mk(nMatch,$3,$4); } | cmd ANDAND optnl cmd { $$ = mk(nAndalso,$1,$4); } | cmd OROR optnl cmd { $$ = mk(nOrelse,$1,$4); } - | cmd PIPE optnl cmd { $$ = mk(nPipe,$2.left,$2.right,$1,$4); } + | cmd PIPE optnl cmd { $$ = mk(nPipe,$2.left,$2.right,$1,$4); } | redir cmd %prec PREDIR { $$ = ($2 != NULL ? mk(nPre,$1,$2) : $1); } | assign cmd %prec BANG { $$ = ($2 != NULL ? mk(nPre,$1,$2) : $1); } | BANG optcaret cmd { $$ = mk(nBang,$3); } diff --git a/rc.1 b/rc.1 @@ -2105,7 +2105,7 @@ cmd : /* empty */ %prec WHILE | TWIDDLE optcaret word words | cmd ANDAND optnl cmd | cmd OROR optnl cmd - | cmd PIPE optnl cmd + | cmd PIPE optnl cmd | redir cmd %prec BANG | assign cmd %prec BANG | BANG optcaret cmd diff --git a/signal.c b/signal.c @@ -16,8 +16,8 @@ void (*sys_signal(int signum, void (*handler)(int)))(int) { new.sa_flags = 0; /* clear SA_RESTART */ sigfillset(&new.sa_mask); if (sigaction(signum, &new, &old) == 0) - return old.sa_handler; - return SIG_DFL; + return old.sa_handler; + return SIG_DFL; } #else void (*sys_signal(int signum, void (*handler)(int)))(int) { diff --git a/status.c b/status.c @@ -133,7 +133,7 @@ extern void ssetstatus(char **av) { statuses[l - i] = k; found = TRUE; break; - } + } else { size_t len = strlen(signals[k].name); if (strncmp(signals[k].name, av[i], len) == 0 && streq(av[i] + len, "+core")) { diff --git a/tree.c b/tree.c @@ -58,7 +58,7 @@ extern Node *mk(int /*nodetype*/ t,...) { n->u[1].i = va_arg(ap, int); n->u[2].p = va_arg(ap, Node *); break; - } + } n->type = t; va_end(ap); return n; diff --git a/trip.rc b/trip.rc @@ -125,11 +125,11 @@ $abc^n $x^here$x^doc EOF {if (!~ `` $nl cat ' ') fail quoted heredoc} << ' ' - + <<<[9] ``''{cat $bigfile} \ { - if(!~ ``''{cat <[0=9]}``'' cat)fail large herestrings + if(!~ ``''{cat <[0=9]}``'' cat)fail large herestrings } < \ $bigfile diff --git a/which.c b/which.c @@ -83,7 +83,7 @@ static char *protect(char *in) { out[i] = '\0'; return out; } - + /* return a full pathname by searching $path, and by checking the status of the file */ extern char *which(char *name, bool verbose) {