summaryrefslogtreecommitdiff
path: root/bin/ksh
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2005-03-30 17:16:38 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2005-03-30 17:16:38 +0000
commit5337e301d74fd022c6b947fa978a12121f5e8f9f (patch)
tree31f24adfb3fb3e4d0e0e7aaca4e7dbd6cc0df942 /bin/ksh
parenta47df1829eb3be603b20e38db0ab7b904b14f545 (diff)
lots of indentation cleanup, now ksh is readable like our other code.
double checked to make sure no binaries change, and eyed by niallo
Diffstat (limited to 'bin/ksh')
-rw-r--r--bin/ksh/Makefile12
-rw-r--r--bin/ksh/c_ksh.c447
-rw-r--r--bin/ksh/c_sh.c71
-rw-r--r--bin/ksh/c_test.c145
-rw-r--r--bin/ksh/c_ulimit.c37
-rw-r--r--bin/ksh/edit.c66
-rw-r--r--bin/ksh/emacs.c446
-rw-r--r--bin/ksh/eval.c211
-rw-r--r--bin/ksh/exec.c240
-rw-r--r--bin/ksh/expand.h4
-rw-r--r--bin/ksh/expr.c139
-rw-r--r--bin/ksh/history.c70
-rw-r--r--bin/ksh/io.c35
-rw-r--r--bin/ksh/jobs.c200
-rw-r--r--bin/ksh/lex.c237
-rw-r--r--bin/ksh/mail.c16
-rw-r--r--bin/ksh/main.c92
-rw-r--r--bin/ksh/misc.c136
-rw-r--r--bin/ksh/path.c11
-rw-r--r--bin/ksh/shf.c138
-rw-r--r--bin/ksh/shf.h6
-rw-r--r--bin/ksh/syn.c98
-rw-r--r--bin/ksh/table.c27
-rw-r--r--bin/ksh/trap.c30
-rw-r--r--bin/ksh/tree.c258
-rw-r--r--bin/ksh/tty.c11
-rw-r--r--bin/ksh/var.c138
-rw-r--r--bin/ksh/vi.c105
28 files changed, 1665 insertions, 1761 deletions
diff --git a/bin/ksh/Makefile b/bin/ksh/Makefile
index 6cf7301376f..c89691b695b 100644
--- a/bin/ksh/Makefile
+++ b/bin/ksh/Makefile
@@ -1,10 +1,9 @@
-# $OpenBSD: Makefile,v 1.23 2004/12/31 16:24:09 millert Exp $
+# $OpenBSD: Makefile,v 1.24 2005/03/30 17:16:37 deraadt Exp $
PROG= ksh
-SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c \
- eval.c exec.c expr.c history.c io.c jobs.c lex.c mail.c \
- main.c misc.c path.c shf.c syn.c table.c trap.c \
- tree.c tty.c var.c version.c vi.c
+SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c eval.c \
+ exec.c expr.c history.c io.c jobs.c lex.c mail.c main.c misc.c path.c \
+ shf.c syn.c table.c trap.c tree.c tty.c var.c version.c vi.c
DEFS= -Wall
CFLAGS+=${DEFS} -I. -I${.CURDIR}
@@ -22,6 +21,7 @@ emacs.out: emacs.c
/bin/sh ${.CURDIR}/emacs-gen.sh ${.CURDIR}/emacs.c > emacs.out
check test:
- /usr/bin/perl ${.CURDIR}/tests/th -s ${.CURDIR}/tests -p ./ksh -C pdksh,sh,ksh,posix,posix-upu
+ /usr/bin/perl ${.CURDIR}/tests/th -s ${.CURDIR}/tests -p ./ksh -C \
+ pdksh,sh,ksh,posix,posix-upu
.include <bsd.prog.mk>
diff --git a/bin/ksh/c_ksh.c b/bin/ksh/c_ksh.c
index 2e822a01cc4..0abd380fd11 100644
--- a/bin/ksh/c_ksh.c
+++ b/bin/ksh/c_ksh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_ksh.c,v 1.26 2005/03/28 21:33:04 deraadt Exp $ */
+/* $OpenBSD: c_ksh.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */
/*
* built-in Korn commands: c_*
@@ -105,8 +105,7 @@ c_cd(char **wp)
cdnode = make_path(current_wd, dir, &cdpath, &xs, &phys_path);
if (physical)
rval = chdir(try = Xstring(xs, xp) + phys_path);
- else
- {
+ else {
simplify_path(Xstring(xs, xp));
rval = chdir(try = Xstring(xs, xp));
}
@@ -177,15 +176,15 @@ c_pwd(char **wp)
bi_errorf("too many arguments");
return 1;
}
- p = current_wd[0] ? (physical ? get_phys_path(current_wd) : current_wd)
- : (char *) 0;
+ p = current_wd[0] ? (physical ? get_phys_path(current_wd) : current_wd) :
+ (char *) 0;
if (p && access(p, R_OK) < 0)
p = (char *) 0;
if (!p) {
p = ksh_get_wd((char *) 0, 0);
if (!p) {
bi_errorf("can't get current directory - %s",
- strerror(errno));
+ strerror(errno));
return 1;
}
}
@@ -244,30 +243,30 @@ c_print(char **wp)
const char *options = "Rnprsu,";
while ((optc = ksh_getopt(wp, &builtin_opt, options)) != EOF)
switch (optc) {
- case 'R': /* fake BSD echo command */
+ case 'R': /* fake BSD echo command */
flags |= PO_PMINUSMINUS;
flags &= ~PO_EXPAND;
options = "ne";
break;
- case 'e':
+ case 'e':
flags |= PO_EXPAND;
break;
- case 'n':
+ case 'n':
flags &= ~PO_NL;
break;
- case 'p':
+ case 'p':
if ((fd = coproc_getfd(W_OK, &emsg)) < 0) {
bi_errorf("-p: %s", emsg);
return 1;
}
break;
- case 'r':
+ case 'r':
flags &= ~PO_EXPAND;
break;
- case 's':
+ case 's':
flags |= PO_HIST;
break;
- case 'u':
+ case 'u':
if (!*(s = builtin_opt.optarg))
fd = 0;
else if ((fd = check_fd(s, W_OK, &emsg)) < 0) {
@@ -275,13 +274,13 @@ c_print(char **wp)
return 1;
}
break;
- case '?':
+ case '?':
return 1;
}
if (!(builtin_opt.info & GI_MINUSMINUS)) {
/* treat a lone - like -- */
- if (wp[builtin_opt.optind]
- && strcmp(wp[builtin_opt.optind], "-") == 0)
+ if (wp[builtin_opt.optind] &&
+ strcmp(wp[builtin_opt.optind], "-") == 0)
builtin_opt.optind++;
} else if (flags & PO_PMINUSMINUS)
builtin_opt.optind--;
@@ -441,24 +440,24 @@ c_whence(char **wp)
}
if (!tp)
tp = findcom(id, fcflags);
- if (vflag || (tp->type != CALIAS && tp->type != CEXEC
- && tp->type != CTALIAS))
+ if (vflag || (tp->type != CALIAS && tp->type != CEXEC &&
+ tp->type != CTALIAS))
shprintf("%s", id);
switch (tp->type) {
- case CKEYWD:
+ case CKEYWD:
if (vflag)
shprintf(" is a reserved word");
break;
- case CALIAS:
+ case CALIAS:
if (vflag)
shprintf(" is an %salias for ",
- (tp->flag & EXPORT) ? "exported "
- : null);
+ (tp->flag & EXPORT) ? "exported " :
+ null);
if (!iam_whence && !vflag)
shprintf("alias %s=", id);
print_value_quoted(tp->val.s);
break;
- case CFUNC:
+ case CFUNC:
if (vflag) {
shprintf(" is a");
if (tp->flag & EXPORT)
@@ -469,27 +468,25 @@ c_whence(char **wp)
shprintf(" undefined");
if (tp->u.fpath)
shprintf(" (autoload from %s)",
- tp->u.fpath);
+ tp->u.fpath);
}
shprintf(" function");
}
break;
- case CSHELL:
+ case CSHELL:
if (vflag)
shprintf(" is a%s shell builtin",
(tp->flag & SPEC_BI) ? " special" : null);
break;
- case CTALIAS:
- case CEXEC:
+ case CTALIAS:
+ case CEXEC:
if (tp->flag & ISSET) {
if (vflag) {
shprintf(" is ");
if (tp->type == CTALIAS)
- shprintf(
- "a tracked %salias for ",
- (tp->flag & EXPORT) ?
- "exported "
- : null);
+ shprintf("a tracked %salias for ",
+ (tp->flag & EXPORT) ?
+ "exported " : null);
}
shprintf("%s", tp->val.s);
} else {
@@ -498,7 +495,7 @@ c_whence(char **wp)
ret = 1;
}
break;
- default:
+ default:
shprintf("%s is *GOK*", id);
break;
}
@@ -534,18 +531,18 @@ c_typeset(char **wp)
int pflag = 0;
switch (**wp) {
- case 'e': /* export */
+ case 'e': /* export */
fset |= EXPORT;
options = "p";
break;
- case 'r': /* readonly */
+ case 'r': /* readonly */
fset |= RDONLY;
options = "p";
break;
- case 's': /* set */
+ case 's': /* set */
/* called with 'typeset -' */
break;
- case 't': /* typeset */
+ case 't': /* typeset */
local = 1;
break;
}
@@ -563,54 +560,55 @@ c_typeset(char **wp)
while ((optc = ksh_getopt(wp, &builtin_opt, options)) != EOF) {
flag = 0;
switch (optc) {
- case 'L':
+ case 'L':
flag = LJUST;
fieldstr = builtin_opt.optarg;
break;
- case 'R':
+ case 'R':
flag = RJUST;
fieldstr = builtin_opt.optarg;
break;
- case 'U':
+ case 'U':
/* at&t ksh uses u, but this conflicts with
* upper/lower case. If this option is changed,
* need to change the -U below as well
*/
flag = INT_U;
break;
- case 'Z':
+ case 'Z':
flag = ZEROFIL;
fieldstr = builtin_opt.optarg;
break;
- case 'f':
+ case 'f':
func = 1;
break;
- case 'i':
+ case 'i':
flag = INTEGER;
basestr = builtin_opt.optarg;
break;
- case 'l':
+ case 'l':
flag = LCASEV;
break;
- case 'p': /* posix export/readonly -p flag.
- * typeset -p is the same as typeset (in pdksh);
- * here for compatibility with ksh93.
- */
+ case 'p':
+ /* posix export/readonly -p flag.
+ * typeset -p is the same as typeset (in pdksh);
+ * here for compatibility with ksh93.
+ */
pflag = 1;
break;
- case 'r':
+ case 'r':
flag = RDONLY;
break;
- case 't':
+ case 't':
flag = TRACE;
break;
- case 'u':
+ case 'u':
flag = UCASEV_AL; /* upper case / autoload */
break;
- case 'x':
+ case 'x':
flag = EXPORT;
break;
- case '?':
+ case '?':
return 1;
}
if (builtin_opt.info & GI_PLUS) {
@@ -631,11 +629,10 @@ c_typeset(char **wp)
if (basestr && !bi_getn(basestr, &base))
return 1;
- if (!(builtin_opt.info & GI_MINUSMINUS) && wp[builtin_opt.optind]
- && (wp[builtin_opt.optind][0] == '-'
- || wp[builtin_opt.optind][0] == '+')
- && wp[builtin_opt.optind][1] == '\0')
- {
+ if (!(builtin_opt.info & GI_MINUSMINUS) && wp[builtin_opt.optind] &&
+ (wp[builtin_opt.optind][0] == '-' ||
+ wp[builtin_opt.optind][0] == '+') &&
+ wp[builtin_opt.optind][1] == '\0') {
thing = wp[builtin_opt.optind][0];
builtin_opt.optind++;
}
@@ -660,11 +657,10 @@ c_typeset(char **wp)
/* Setting these attributes clears the others, unless they
* are also set in this command
*/
- if (fset & (LJUST|RJUST|ZEROFIL|UCASEV_AL|LCASEV|INTEGER
- |INT_U|INT_L))
- fclr |= ~fset &
- (LJUST|RJUST|ZEROFIL|UCASEV_AL|LCASEV|INTEGER
- |INT_U|INT_L);
+ if (fset & (LJUST | RJUST | ZEROFIL | UCASEV_AL | LCASEV |
+ INTEGER | INT_U | INT_L))
+ fclr |= ~fset & (LJUST | RJUST | ZEROFIL | UCASEV_AL |
+ LCASEV | INTEGER | INT_U | INT_L);
}
/* set variables and attributes */
@@ -678,7 +674,7 @@ c_typeset(char **wp)
for (i = builtin_opt.optind; wp[i]; i++) {
if (func) {
f = findfunc(wp[i], hash(wp[i]),
- (fset&UCASEV_AL) ? true : false);
+ (fset&UCASEV_AL) ? true : false);
if (!f) {
/* at&t ksh does ++rval: bogus */
rval = 1;
@@ -689,11 +685,9 @@ c_typeset(char **wp)
f->flag &= ~fclr;
} else
fptreef(shl_stdout, 0,
- f->flag & FKSH ?
- "function %s %T\n"
- : "%s() %T\n"
- ,
- wp[i], f->val.t);
+ f->flag & FKSH ?
+ "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]);
return 1;
@@ -705,112 +699,118 @@ c_typeset(char **wp)
/* list variables and attributes */
flag = fset | fclr; /* no difference at this point.. */
if (func) {
- for (l = e->loc; l; l = l->next) {
- for (p = tsort(&l->funs); (vp = *p++); ) {
- if (flag && (vp->flag & flag) == 0)
- continue;
- if (thing == '-')
- fptreef(shl_stdout, 0, vp->flag & FKSH ?
- "function %s %T\n"
- : "%s() %T\n",
- vp->name, vp->val.t);
- else
- shprintf("%s\n", vp->name);
+ for (l = e->loc; l; l = l->next) {
+ for (p = tsort(&l->funs); (vp = *p++); ) {
+ if (flag && (vp->flag & flag) == 0)
+ continue;
+ if (thing == '-')
+ fptreef(shl_stdout, 0, vp->flag & FKSH ?
+ "function %s %T\n" : "%s() %T\n",
+ vp->name, vp->val.t);
+ else
+ shprintf("%s\n", vp->name);
+ }
}
- }
} else {
- for (l = e->loc; l; l = l->next) {
- for (p = tsort(&l->vars); (vp = *p++); ) {
- struct tbl *tvp;
- int any_set = 0;
- /*
- * See if the parameter is set (for arrays, if any
- * element is set).
- */
- for (tvp = vp; tvp; tvp = tvp->u.array)
- if (tvp->flag & ISSET) {
- any_set = 1;
- break;
- }
- /*
- * Check attributes - note that all array elements
- * have (should have?) the same attributes, so checking
- * the first is sufficient.
- *
- * Report an unset param only if the user has
- * explicitly given it some attribute (like export);
- * otherwise, after "echo $FOO", we would report FOO...
- */
- if (!any_set && !(vp->flag & USERATTRIB))
- continue;
- if (flag && (vp->flag & flag) == 0)
- continue;
- for (; vp; vp = vp->u.array) {
- /* Ignore array elements that aren't set unless there
- * are no set elements, in which case the first is
- * reported on
- */
- if ((vp->flag&ARRAY) && any_set && !(vp->flag & ISSET))
- continue;
- /* no arguments */
- if (thing == 0 && flag == 0) {
- /* at&t ksh prints things like export, integer,
- * leftadj, zerofill, etc., but POSIX says must
- * be suitable for re-entry...
- */
- shprintf("typeset ");
- if ((vp->flag&INTEGER))
- shprintf("-i ");
- if ((vp->flag&EXPORT))
- shprintf("-x ");
- if ((vp->flag&RDONLY))
- shprintf("-r ");
- if ((vp->flag&TRACE))
- shprintf("-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))
- shprintf("-Z ");
- if ((vp->flag&LCASEV))
- shprintf("-l ");
- if ((vp->flag&UCASEV_AL))
- shprintf("-u ");
- if ((vp->flag&INT_U))
- shprintf("-U ");
- shprintf("%s\n", vp->name);
- if (vp->flag&ARRAY)
- break;
- } else {
- if (pflag)
- shprintf("%s ",
- (flag & EXPORT) ? "export" : "readonly");
- if ((vp->flag&ARRAY) && any_set)
- shprintf("%s[%d]", vp->name, vp->index);
- else
- shprintf("%s", vp->name);
- if (thing == '-' && (vp->flag&ISSET)) {
- char *s = str_val(vp);
-
- shprintf("=");
- /* at&t ksh can't have justified integers.. */
- if ((vp->flag & (INTEGER|LJUST|RJUST))
- == INTEGER)
- shprintf("%s", s);
- else
- print_value_quoted(s);
- }
- shprintf(newline);
+ for (l = e->loc; l; l = l->next) {
+ for (p = tsort(&l->vars); (vp = *p++); ) {
+ struct tbl *tvp;
+ int any_set = 0;
+ /*
+ * See if the parameter is set (for arrays, if any
+ * element is set).
+ */
+ for (tvp = vp; tvp; tvp = tvp->u.array)
+ if (tvp->flag & ISSET) {
+ any_set = 1;
+ break;
+ }
+
+ /*
+ * Check attributes - note that all array elements
+ * have (should have?) the same attributes, so checking
+ * the first is sufficient.
+ *
+ * Report an unset param only if the user has
+ * explicitly given it some attribute (like export);
+ * otherwise, after "echo $FOO", we would report FOO...
+ */
+ if (!any_set && !(vp->flag & USERATTRIB))
+ continue;
+ if (flag && (vp->flag & flag) == 0)
+ continue;
+ for (; vp; vp = vp->u.array) {
+ /* Ignore array elements that aren't
+ * set unless there are no set elements,
+ * in which case the first is reported on */
+ if ((vp->flag&ARRAY) && any_set &&
+ !(vp->flag & ISSET))
+ continue;
+ /* no arguments */
+ if (thing == 0 && flag == 0) {
+ /* at&t ksh prints things
+ * like export, integer,
+ * leftadj, zerofill, etc.,
+ * but POSIX says must
+ * be suitable for re-entry...
+ */
+ shprintf("typeset ");
+ if ((vp->flag&INTEGER))
+ shprintf("-i ");
+ if ((vp->flag&EXPORT))
+ shprintf("-x ");
+ if ((vp->flag&RDONLY))
+ shprintf("-r ");
+ if ((vp->flag&TRACE))
+ shprintf("-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))
+ shprintf("-Z ");
+ if ((vp->flag&LCASEV))
+ shprintf("-l ");
+ if ((vp->flag&UCASEV_AL))
+ shprintf("-u ");
+ if ((vp->flag&INT_U))
+ shprintf("-U ");
+ shprintf("%s\n", vp->name);
+ if (vp->flag&ARRAY)
+ break;
+ } else {
+ if (pflag)
+ shprintf("%s ",
+ (flag & EXPORT) ?
+ "export" : "readonly");
+ if ((vp->flag&ARRAY) && any_set)
+ shprintf("%s[%d]",
+ vp->name, vp->index);
+ else
+ shprintf("%s", vp->name);
+ if (thing == '-' && (vp->flag&ISSET)) {
+ char *s = str_val(vp);
+
+ shprintf("=");
+ /* at&t ksh can't have
+ * justified integers.. */
+ if ((vp->flag &
+ (INTEGER|LJUST|RJUST)) ==
+ INTEGER)
+ shprintf("%s", s);
+ else
+ print_value_quoted(s);
+ }
+ shprintf(newline);
+ }
+ /* Only report first `element' of an array with
+ * no set elements.
+ */
+ if (!any_set)
+ break;
+ }
}
- /* Only report first `element' of an array with
- * no set elements.
- */
- if (!any_set)
- break;
- }
}
- }
}
return 0;
}
@@ -828,35 +828,36 @@ c_alias(char **wp)
while ((optc = ksh_getopt(wp, &builtin_opt, "dprtUx")) != EOF) {
prefix = builtin_opt.info & GI_PLUS ? '+' : '-';
switch (optc) {
- case 'd':
+ case 'd':
t = &homedirs;
break;
- case 'p':
+ case 'p':
pflag = 1;
break;
- case 'r':
+ case 'r':
rflag = 1;
break;
- case 't':
+ case 't':
t = &taliases;
break;
- case 'U': /* kludge for tracked alias initialization
- * (don't do a path search, just make an entry)
- */
+ case 'U':
+ /*
+ * kludge for tracked alias initialization
+ * (don't do a path search, just make an entry)
+ */
Uflag = 1;
break;
- case 'x':
+ case 'x':
xflag = EXPORT;
break;
- case '?':
+ case '?':
return 1;
}
}
wp += builtin_opt.optind;
- if (!(builtin_opt.info & GI_MINUSMINUS) && *wp
- && (wp[0][0] == '-' || wp[0][0] == '+') && wp[0][1] == '\0')
- {
+ if (!(builtin_opt.info & GI_MINUSMINUS) && *wp &&
+ (wp[0][0] == '-' || wp[0][0] == '+') && wp[0][1] == '\0') {
prefix = wp[0][0];
wp++;
}
@@ -870,8 +871,8 @@ c_alias(char **wp)
};
if (!tflag || *wp) {
- shprintf(
- "alias: -r flag can only be used with -t and without arguments\n");
+ shprintf("alias: -r flag can only be used with -t"
+ " and without arguments\n");
return 1;
}
ksh_getopt_reset(&builtin_opt, GF_ERROR);
@@ -930,8 +931,8 @@ c_alias(char **wp)
afree((void*)ap->val.s, APERM);
}
/* ignore values for -t (at&t ksh does this) */
- newval = tflag ? search(alias, path, X_OK, (int *) 0)
- : val;
+ newval = tflag ? search(alias, path, X_OK, (int *) 0) :
+ val;
if (newval) {
ap->val.s = str_save(newval, APERM);
ap->flag |= ALLOC|ISSET;
@@ -960,16 +961,16 @@ c_unalias(char **wp)
while ((optc = ksh_getopt(wp, &builtin_opt, "adt")) != EOF)
switch (optc) {
- case 'a':
+ case 'a':
all = 1;
break;
- case 'd':
+ case 'd':
t = &homedirs;
break;
- case 't':
+ case 't':
t = &taliases;
break;
- case '?':
+ case '?':
return 1;
}
wp += builtin_opt.optind;
@@ -1030,19 +1031,19 @@ c_jobs(char **wp)
while ((optc = ksh_getopt(wp, &builtin_opt, "lpnz")) != EOF)
switch (optc) {
- case 'l':
+ case 'l':
flag = 1;
break;
- case 'p':
+ case 'p':
flag = 2;
break;
- case 'n':
+ case 'n':
nflag = 1;
break;
- case 'z': /* debugging: print zombies */
+ case 'z': /* debugging: print zombies */
nflag = -1;
break;
- case '?':
+ case '?':
return 1;
}
wp += builtin_opt.optind;
@@ -1098,14 +1099,14 @@ kill_fmt_entry(void *arg, int i, char *buf, int buflen)
i++;
if (sigtraps[i].name)
shf_snprintf(buf, buflen, "%*d %*s %s",
- ki->num_width, i,
- ki->name_width, sigtraps[i].name,
- sigtraps[i].mess);
+ ki->num_width, i,
+ ki->name_width, sigtraps[i].name,
+ sigtraps[i].mess);
else
shf_snprintf(buf, buflen, "%*d %*d %s",
- ki->num_width, i,
- ki->name_width, sigtraps[i].signal,
- sigtraps[i].mess);
+ ki->num_width, i,
+ ki->name_width, sigtraps[i].signal,
+ sigtraps[i].mess);
return buf;
}
@@ -1130,26 +1131,25 @@ c_kill(char **wp)
while ((optc = ksh_getopt(wp, &builtin_opt, "ls:")) != EOF)
switch (optc) {
- case 'l':
+ case 'l':
lflag = 1;
break;
- case 's':
+ case 's':
if (!(t = gettrap(builtin_opt.optarg, true))) {
bi_errorf("bad signal `%s'",
- builtin_opt.optarg);
+ builtin_opt.optarg);
return 1;
}
break;
- case '?':
+ case '?':
return 1;
}
i = builtin_opt.optind;
}
if ((lflag && t) || (!wp[i] && !lflag)) {
shf_fprintf(shl_out,
-"Usage: kill [ -s signame | -signum | -signame ] {pid|job}...\n\
- kill -l [exit_status]\n"
- );
+ "Usage: kill [ -s signame | -signum | -signame ] {pid|job}...\n"
+ " kill -l [exit_status]\n");
bi_errorf(null);
return 1;
}
@@ -1181,8 +1181,8 @@ c_kill(char **wp)
ki.num_width++;
ki.name_width = mess_width = 0;
for (i = 0; i < NSIG; i++) {
- w = sigtraps[i].name ? strlen(sigtraps[i].name)
- : ki.num_width;
+ w = sigtraps[i].name ? strlen(sigtraps[i].name) :
+ ki.num_width;
if (w > ki.name_width)
ki.name_width = w;
w = strlen(sigtraps[i].mess);
@@ -1191,8 +1191,8 @@ c_kill(char **wp)
}
print_columns(shl_stdout, NSIG - 1,
- kill_fmt_entry, (void *) &ki,
- ki.num_width + ki.name_width + mess_width + 3, 1);
+ kill_fmt_entry, (void *) &ki,
+ ki.num_width + ki.name_width + mess_width + 3, 1);
}
return 0;
}
@@ -1204,7 +1204,7 @@ c_kill(char **wp)
rv = 1;
} else if (!getn(p, &n)) {
bi_errorf("%s: arguments must be jobs or process IDs",
- p);
+ p);
rv = 1;
} else {
/* use killpg if < -1 since -1 does special things for
@@ -1224,7 +1224,7 @@ getopts_reset(int val)
{
if (val >= 1) {
ksh_getopt_reset(&user_opt,
- GF_NONAME | (Flag(FPOSIX) ? 0 : GF_PLUSOPT));
+ GF_NONAME | (Flag(FPOSIX) ? 0 : GF_PLUSOPT));
user_opt.optind = user_opt.uoptind = val;
}
}
@@ -1273,12 +1273,11 @@ c_getopts(char **wp)
/* Check that our saved state won't cause a core dump... */
for (argc = 0; wp[argc]; argc++)
;
- if (user_opt.optind > argc
- || (user_opt.p != 0
- && user_opt.p > strlen(wp[user_opt.optind - 1])))
- {
- bi_errorf("arguments changed since last call");
- return 1;
+ if (user_opt.optind > argc ||
+ (user_opt.p != 0 &&
+ user_opt.p > strlen(wp[user_opt.optind - 1]))) {
+ bi_errorf("arguments changed since last call");
+ return 1;
}
user_opt.optarg = (char *) 0;
@@ -1336,13 +1335,13 @@ c_bind(char **wp)
while ((optc = ksh_getopt(wp, &builtin_opt, "lm")) != EOF)
switch (optc) {
- case 'l':
+ case 'l':
list = 1;
break;
- case 'm':
+ case 'm':
macro = 1;
break;
- case '?':
+ case '?':
return 1;
}
wp += builtin_opt.optind;
diff --git a/bin/ksh/c_sh.c b/bin/ksh/c_sh.c
index 05ec4b9c620..ebea7ef17dd 100644
--- a/bin/ksh/c_sh.c
+++ b/bin/ksh/c_sh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_sh.c,v 1.28 2005/02/02 07:53:01 otto Exp $ */
+/* $OpenBSD: c_sh.c,v 1.29 2005/03/30 17:16:37 deraadt Exp $ */
/*
* built-in Bourne commands
@@ -60,10 +60,10 @@ c_umask(char **wp)
while ((optc = ksh_getopt(wp, &builtin_opt, "S")) != EOF)
switch (optc) {
- case 'S':
+ case 'S':
symbolic = 1;
break;
- case '?':
+ case '?':
return 1;
}
cp = wp[builtin_opt.optind];
@@ -111,10 +111,18 @@ c_umask(char **wp)
while (*cp) {
while (*cp && strchr("augo", *cp))
switch (*cp++) {
- case 'a': positions |= 0111; break;
- case 'u': positions |= 0100; break;
- case 'g': positions |= 0010; break;
- case 'o': positions |= 0001; break;
+ case 'a':
+ positions |= 0111;
+ break;
+ case 'u':
+ positions |= 0100;
+ break;
+ case 'g':
+ positions |= 0010;
+ break;
+ case 'o':
+ positions |= 0001;
+ break;
}
if (!positions)
positions = 0111; /* default is a */
@@ -145,8 +153,8 @@ c_umask(char **wp)
new_umask &= ~new_val;
break;
case '=':
- new_umask = new_val
- | (new_umask & ~(positions * 07));
+ new_umask = new_val |
+ (new_umask & ~(positions * 07));
break;
case '+':
new_umask |= new_val;
@@ -246,19 +254,19 @@ c_read(char **wp)
while ((optc = ksh_getopt(wp, &builtin_opt, "prsu,")) != EOF)
switch (optc) {
- case 'p':
+ case 'p':
if ((fd = coproc_getfd(R_OK, &emsg)) < 0) {
bi_errorf("-p: %s", emsg);
return 1;
}
break;
- case 'r':
+ case 'r':
expand = 0;
break;
- case 's':
+ case 's':
history = 1;
break;
- case 'u':
+ case 'u':
if (!*(cp = builtin_opt.optarg))
fd = 0;
else if ((fd = check_fd(cp, R_OK, &emsg)) < 0) {
@@ -266,7 +274,7 @@ c_read(char **wp)
return 1;
}
break;
- case '?':
+ case '?':
return 1;
}
wp += builtin_opt.optind;
@@ -314,9 +322,8 @@ c_read(char **wp)
c = shf_getc(shf);
if (c == '\0')
continue;
- if (c == EOF && shf_error(shf)
- && shf_errno(shf) == EINTR)
- {
+ if (c == EOF && shf_error(shf) &&
+ shf_errno(shf) == EINTR) {
/* Was the offending signal one that
* would normally kill a process?
* If so, pretend the read was killed.
@@ -367,8 +374,8 @@ c_read(char **wp)
}
/* strip trailing IFS white space from last variable */
if (!wp[1])
- while (Xlength(cs, cp) && ctype(cp[-1], C_IFS)
- && ctype(cp[-1], C_IFSWS))
+ while (Xlength(cs, cp) && ctype(cp[-1], C_IFS) &&
+ ctype(cp[-1], C_IFSWS))
cp--;
Xput(cs, cp, '\0');
vp = global(*wp);
@@ -514,11 +521,11 @@ c_exitreturn(char **wp)
arg = wp[builtin_opt.optind];
if (arg) {
- if (!getn(arg, &n)) {
- exstat = 1;
- warningf(true, "%s: bad number", arg);
- } else
- exstat = n;
+ if (!getn(arg, &n)) {
+ exstat = 1;
+ warningf(true, "%s: bad number", arg);
+ } else
+ exstat = n;
}
if (wp[0][0] == 'r') { /* return */
struct env *ep;
@@ -590,7 +597,7 @@ c_brkcont(char **wp)
*/
last_ep->flags &= ~EF_BRKCONT_PASS;
warningf(true, "%s: can only %s %d level(s)",
- wp[0], wp[0], n - quit);
+ wp[0], wp[0], n - quit);
}
unwind(*wp[0] == 'b' ? LBREAK : LCONTIN);
@@ -641,13 +648,13 @@ c_unset(char **wp)
while ((optc = ksh_getopt(wp, &builtin_opt, "fv")) != EOF)
switch (optc) {
- case 'f':
+ case 'f':
unset_var = 0;
break;
- case 'v':
+ case 'v':
unset_var = 1;
break;
- case '?':
+ case '?':
return 1;
}
wp += builtin_opt.optind;
@@ -782,14 +789,14 @@ timex_hook(struct op *t, char **volatile *app)
opt.optind = 0; /* start at the start */
while ((optc = ksh_getopt(wp, &opt, ":p")) != EOF)
switch (optc) {
- case 'p':
+ case 'p':
t->str[0] |= TF_POSIX;
break;
- case '?':
+ case '?':
errorf("time: -%s unknown option", opt.optarg);
- case ':':
+ case ':':
errorf("time: -%s requires an argument",
- opt.optarg);
+ opt.optarg);
}
/* Copy command words down over options. */
if (opt.optind != 0) {
diff --git a/bin/ksh/c_test.c b/bin/ksh/c_test.c
index 0e6ee7fd259..9e03fb0c3d3 100644
--- a/bin/ksh/c_test.c
+++ b/bin/ksh/c_test.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_test.c,v 1.16 2005/03/28 21:33:04 deraadt Exp $ */
+/* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */
/*
* test(1); version 7-like -- author Erik Baalbergen
@@ -66,7 +66,7 @@ static const struct t_op u_ops [] = {
{"-x", TO_FILEX },
{"-z", TO_STZER },
{"", TO_NONOP }
- };
+};
static const struct t_op b_ops [] = {
{"=", TO_STEQL },
{"==", TO_STEQL },
@@ -83,7 +83,7 @@ static const struct t_op b_ops [] = {
{"-nt", TO_FILNT },
{"-ot", TO_FILOT },
{"", TO_NONOP }
- };
+};
static int test_stat(const char *, struct stat *);
static int test_eaccess(const char *, int);
@@ -141,8 +141,8 @@ c_test(char **wp)
opnd1 = (*te.getopnd)(&te, TO_NONOP, 1);
if ((op = (Test_op) (*te.isa)(&te, TM_BINOP))) {
opnd2 = (*te.getopnd)(&te, op, 1);
- res = (*te.eval)(&te, op, opnd1, opnd2,
- 1);
+ res = (*te.eval)(&te, op, opnd1,
+ opnd2, 1);
if (te.flags & TEF_ERROR)
return T_ERR_EXIT;
if (invert & 1)
@@ -161,7 +161,7 @@ c_test(char **wp)
if (!Flag(FPOSIX) && strcmp(opnd1, "-t") == 0)
break;
res = (*te.eval)(&te, TO_STNZE, opnd1,
- (char *) 0, 1);
+ (char *) 0, 1);
if (invert & 1)
res = !res;
return !res;
@@ -191,11 +191,10 @@ test_isop(Test_env *te, Test_meta meta, const char *s)
if (*s) {
sc1 = s[1];
for (; otab->op_text[0]; otab++)
- if (sc1 == otab->op_text[1]
- && strcmp(s, otab->op_text) == 0
- && ((te->flags & TEF_DBRACKET)
- || (otab->op_num != TO_STLT
- && otab->op_num != TO_STGT)))
+ if (sc1 == otab->op_text[1] &&
+ strcmp(s, otab->op_text) == 0 &&
+ ((te->flags & TEF_DBRACKET) ||
+ (otab->op_num != TO_STLT && otab->op_num != TO_STGT)))
return otab->op_num;
}
return TO_NONOP;
@@ -216,11 +215,11 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
/*
* Unary Operators
*/
- case TO_STNZE: /* -n */
+ case TO_STNZE: /* -n */
return *opnd1 != '\0';
- case TO_STZER: /* -z */
+ case TO_STZER: /* -z */
return *opnd1 == '\0';
- case TO_OPTION: /* -o */
+ case TO_OPTION: /* -o */
if ((not = *opnd1 == '!'))
opnd1++;
if ((res = option(opnd1)) < 0)
@@ -231,47 +230,47 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
res = !res;
}
return res;
- case TO_FILRD: /* -r */
+ case TO_FILRD: /* -r */
return test_eaccess(opnd1, R_OK) == 0;
- case TO_FILWR: /* -w */
+ case TO_FILWR: /* -w */
return test_eaccess(opnd1, W_OK) == 0;
- case TO_FILEX: /* -x */
+ case TO_FILEX: /* -x */
return test_eaccess(opnd1, X_OK) == 0;
- case TO_FILAXST: /* -a */
+ case TO_FILAXST: /* -a */
return test_stat(opnd1, &b1) == 0;
- case TO_FILEXST: /* -e */
+ case TO_FILEXST: /* -e */
/* at&t ksh does not appear to do the /dev/fd/ thing for
* this (unless the os itself handles it)
*/
return stat(opnd1, &b1) == 0;
- case TO_FILREG: /* -r */
+ case TO_FILREG: /* -r */
return test_stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode);
- case TO_FILID: /* -d */
+ case TO_FILID: /* -d */
return test_stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode);
- case TO_FILCDEV: /* -c */
+ case TO_FILCDEV: /* -c */
return test_stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode);
- case TO_FILBDEV: /* -b */
+ case TO_FILBDEV: /* -b */
return test_stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode);
- case TO_FILFIFO: /* -p */
+ case TO_FILFIFO: /* -p */
return test_stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode);
- case TO_FILSYM: /* -h -L */
+ case TO_FILSYM: /* -h -L */
return lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode);
- case TO_FILSOCK: /* -S */
+ case TO_FILSOCK: /* -S */
return test_stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode);
- case TO_FILCDF:/* -H HP context dependent files (directories) */
+ case TO_FILCDF:/* -H HP context dependent files (directories) */
return 0;
- case TO_FILSETU: /* -u */
- return test_stat(opnd1, &b1) == 0
- && (b1.st_mode & S_ISUID) == S_ISUID;
- case TO_FILSETG: /* -g */
- return test_stat(opnd1, &b1) == 0
- && (b1.st_mode & S_ISGID) == S_ISGID;
- case TO_FILSTCK: /* -k */
- return test_stat(opnd1, &b1) == 0
- && (b1.st_mode & S_ISVTX) == S_ISVTX;
- case TO_FILGZ: /* -s */
+ case TO_FILSETU: /* -u */
+ return test_stat(opnd1, &b1) == 0 &&
+ (b1.st_mode & S_ISUID) == S_ISUID;
+ case TO_FILSETG: /* -g */
+ return test_stat(opnd1, &b1) == 0 &&
+ (b1.st_mode & S_ISGID) == S_ISGID;
+ case TO_FILSTCK: /* -k */
+ return test_stat(opnd1, &b1) == 0 &&
+ (b1.st_mode & S_ISVTX) == S_ISVTX;
+ case TO_FILGZ: /* -s */
return test_stat(opnd1, &b1) == 0 && b1.st_size > 0L;
- case TO_FILTT: /* -t */
+ case TO_FILTT: /* -t */
if (opnd1 && !bi_getn(opnd1, &res)) {
te->flags |= TEF_ERROR;
res = 0;
@@ -280,80 +279,78 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
res = isatty(opnd1 ? res : 0);
}
return res;
- case TO_FILUID: /* -O */
+ case TO_FILUID: /* -O */
return test_stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid;
- case TO_FILGID: /* -G */
+ case TO_FILGID: /* -G */
return test_stat(opnd1, &b1) == 0 && b1.st_gid == getegid();
/*
* Binary Operators
*/
- case TO_STEQL: /* = */
+ case TO_STEQL: /* = */
if (te->flags & TEF_DBRACKET)
return gmatch(opnd1, opnd2, false);
return strcmp(opnd1, opnd2) == 0;
- case TO_STNEQ: /* != */
+ case TO_STNEQ: /* != */
if (te->flags & TEF_DBRACKET)
return !gmatch(opnd1, opnd2, false);
return strcmp(opnd1, opnd2) != 0;
- case TO_STLT: /* < */
+ case TO_STLT: /* < */
return strcmp(opnd1, opnd2) < 0;
- case TO_STGT: /* > */
+ case TO_STGT: /* > */
return strcmp(opnd1, opnd2) > 0;
- case TO_INTEQ: /* -eq */
- case TO_INTNE: /* -ne */
- case TO_INTGE: /* -ge */
- case TO_INTGT: /* -gt */
- case TO_INTLE: /* -le */
- case TO_INTLT: /* -lt */
+ case TO_INTEQ: /* -eq */
+ case TO_INTNE: /* -ne */
+ case TO_INTGE: /* -ge */
+ case TO_INTGT: /* -gt */
+ case TO_INTLE: /* -le */
+ case TO_INTLT: /* -lt */
{
long v1, v2;
- if (!evaluate(opnd1, &v1, KSH_RETURN_ERROR, false)
- || !evaluate(opnd2, &v2, KSH_RETURN_ERROR, false))
- {
+ if (!evaluate(opnd1, &v1, KSH_RETURN_ERROR, false) ||
+ !evaluate(opnd2, &v2, KSH_RETURN_ERROR, false)) {
/* error already printed.. */
te->flags |= TEF_ERROR;
return 1;
}
switch ((int) op) {
- case TO_INTEQ:
+ case TO_INTEQ:
return v1 == v2;
- case TO_INTNE:
+ case TO_INTNE:
return v1 != v2;
- case TO_INTGE:
+ case TO_INTGE:
return v1 >= v2;
- case TO_INTGT:
+ case TO_INTGT:
return v1 > v2;
- case TO_INTLE:
+ case TO_INTLE:
return v1 <= v2;
- case TO_INTLT:
+ case TO_INTLT:
return v1 < v2;
}
}
- case TO_FILNT: /* -nt */
+ case TO_FILNT: /* -nt */
{
int s2;
/* ksh88/ksh93 succeed if file2 can't be stated
* (subtly different from `does not exist').
*/
- return stat(opnd1, &b1) == 0
- && (((s2 = stat(opnd2, &b2)) == 0
- && b1.st_mtime > b2.st_mtime) || s2 < 0);
+ return stat(opnd1, &b1) == 0 &&
+ (((s2 = stat(opnd2, &b2)) == 0 &&
+ b1.st_mtime > b2.st_mtime) || s2 < 0);
}
- case TO_FILOT: /* -ot */
+ case TO_FILOT: /* -ot */
{
int s1;
/* ksh88/ksh93 succeed if file1 can't be stated
* (subtly different from `does not exist').
*/
- return stat(opnd2, &b2) == 0
- && (((s1 = stat(opnd1, &b1)) == 0
- && b1.st_mtime < b2.st_mtime) || s1 < 0);
+ return stat(opnd2, &b2) == 0 &&
+ (((s1 = stat(opnd1, &b1)) == 0 &&
+ b1.st_mtime < b2.st_mtime) || s1 < 0);
}
- case TO_FILEQ: /* -ef */
- return stat (opnd1, &b1) == 0 && stat (opnd2, &b2) == 0
- && b1.st_dev == b2.st_dev
- && b1.st_ino == b2.st_ino;
+ case TO_FILEQ: /* -ef */
+ return stat (opnd1, &b1) == 0 && stat (opnd2, &b2) == 0 &&
+ b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino;
}
(*te->error)(te, 0, "internal error: unknown op");
return 1;
@@ -387,8 +384,8 @@ test_eaccess(const char *path, int mode)
else if (S_ISDIR(statb.st_mode))
res = 0;
else
- res = (statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))
- ? 0 : -1;
+ res = (statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) ?
+ 0 : -1;
}
return res;
@@ -545,7 +542,7 @@ static void
ptest_error(Test_env *te, int offset, const char *msg)
{
const char *op = te->pos.wp + offset >= te->wp_end ?
- (const char *) 0 : te->pos.wp[offset];
+ (const char *) 0 : te->pos.wp[offset];
te->flags |= TEF_ERROR;
if (op)
diff --git a/bin/ksh/c_ulimit.c b/bin/ksh/c_ulimit.c
index 5bf0f19b5f6..f4bde13e103 100644
--- a/bin/ksh/c_ulimit.c
+++ b/bin/ksh/c_ulimit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_ulimit.c,v 1.13 2005/02/02 07:53:01 otto Exp $ */
+/* $OpenBSD: c_ulimit.c,v 1.14 2005/03/30 17:16:37 deraadt Exp $ */
/*
ulimit -- handle "ulimit" builtin
@@ -41,15 +41,17 @@ c_ulimit(char **wp)
{ "coredump(blocks)", RLIMIT, RLIMIT_CORE, RLIMIT_CORE, 512, 'c' },
{ "data(kbytes)", RLIMIT, RLIMIT_DATA, RLIMIT_DATA, 1024, 'd' },
{ "stack(kbytes)", RLIMIT, RLIMIT_STACK, RLIMIT_STACK, 1024, 's' },
- { "lockedmem(kbytes)", RLIMIT, RLIMIT_MEMLOCK, RLIMIT_MEMLOCK, 1024, 'l' },
+ { "lockedmem(kbytes)", RLIMIT, RLIMIT_MEMLOCK, RLIMIT_MEMLOCK,
+ 1024, 'l' },
{ "memory(kbytes)", RLIMIT, RLIMIT_RSS, RLIMIT_RSS, 1024, 'm' },
- { "nofiles(descriptors)", RLIMIT, RLIMIT_NOFILE, RLIMIT_NOFILE, 1, 'n' },
+ { "nofiles(descriptors)", RLIMIT, RLIMIT_NOFILE, RLIMIT_NOFILE,
+ 1, 'n' },
{ "processes", RLIMIT, RLIMIT_NPROC, RLIMIT_NPROC, 1, 'p' },
-#ifdef RLIMIT_VMEM
+ #ifdef RLIMIT_VMEM
{ "vmemory(kbytes)", RLIMIT, RLIMIT_VMEM, RLIMIT_VMEM, 1024, 'v' },
-#endif /* RLIMIT_VMEM */
+ #endif /* RLIMIT_VMEM */
{ (char *) 0 }
- };
+ };
static char options[3 + NELEM(limits)];
rlim_t val = 0;
int how = SOFT | HARD;
@@ -57,7 +59,6 @@ c_ulimit(char **wp)
int set, all = 0;
int optc, what;
struct rlimit limit;
-
if (!options[0]) {
/* build options string on first call - yuck */
char *p = options;
@@ -70,18 +71,18 @@ c_ulimit(char **wp)
what = 'f';
while ((optc = ksh_getopt(wp, &builtin_opt, options)) != EOF)
switch (optc) {
- case 'H':
+ case 'H':
how = HARD;
break;
- case 'S':
+ case 'S':
how = SOFT;
break;
- case 'a':
+ case 'a':
all = 1;
break;
- case '?':
+ case '?':
return 1;
- default:
+ default:
what = optc;
}
@@ -114,8 +115,8 @@ c_ulimit(char **wp)
* if unset params are 0 or an error.
*/
if (!rval && !digit(wp[0][0])) {
- bi_errorf("invalid limit: %s", wp[0]);
- return 1;
+ bi_errorf("invalid limit: %s", wp[0]);
+ return 1;
}
val = rval * l->factor;
}
@@ -132,8 +133,7 @@ c_ulimit(char **wp)
shprintf("%-20s ", l->name);
if (val == RLIM_INFINITY)
shprintf("unlimited\n");
- else
- {
+ else {
val /= l->factor;
shprintf("%ld\n", (long) val);
}
@@ -152,7 +152,7 @@ c_ulimit(char **wp)
bi_errorf("exceeds allowable limit");
else
bi_errorf("bad limit: %s",
- strerror(errno));
+ strerror(errno));
return 1;
}
} else {
@@ -165,8 +165,7 @@ c_ulimit(char **wp)
if (!set) {
if (val == RLIM_INFINITY)
shprintf("unlimited\n");
- else
- {
+ else {
val /= l->factor;
shprintf("%ld\n", (long) val);
}
diff --git a/bin/ksh/edit.c b/bin/ksh/edit.c
index 9e721abcaa1..6618e079a83 100644
--- a/bin/ksh/edit.c
+++ b/bin/ksh/edit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: edit.c,v 1.27 2005/02/25 11:21:16 deraadt Exp $ */
+/* $OpenBSD: edit.c,v 1.28 2005/03/30 17:16:37 deraadt Exp $ */
/*
* Command line editing - common code
@@ -33,8 +33,8 @@ void
x_init(void)
{
/* set to -2 to force initial binding */
- edchars.erase = edchars.kill = edchars.intr = edchars.quit
- = edchars.eof = -2;
+ edchars.erase = edchars.kill = edchars.intr = edchars.quit =
+ edchars.eof = -2;
/* default value for deficient systems */
edchars.werase = 027; /* ^W */
@@ -72,14 +72,13 @@ check_sigwinch(void)
* see the change cause the environ doesn't change.
*/
if (ws.ws_col) {
- x_cols = ws.ws_col < MIN_COLS ? MIN_COLS
- : ws.ws_col;
+ x_cols = ws.ws_col < MIN_COLS ? MIN_COLS :
+ ws.ws_col;
if ((vp = typeset("COLUMNS", 0, 0, 0, 0)))
setint(vp, (long) ws.ws_col);
}
- if (ws.ws_row
- && (vp = typeset("LINES", 0, 0, 0, 0)))
+ if (ws.ws_row && (vp = typeset("LINES", 0, 0, 0, 0)))
setint(vp, (long) ws.ws_row);
}
}
@@ -215,12 +214,12 @@ set_editmode(const char *ed)
{
static const enum sh_flag edit_flags[] = {
#ifdef EMACS
- FEMACS, FGMACS,
+ FEMACS, FGMACS,
#endif
#ifdef VI
- FVI,
+ FVI,
#endif
- };
+ };
char *rcp;
int i;
@@ -296,7 +295,7 @@ static void glob_path(int flags, const char *pat, XPtrV *wp,
#if 0 /* not used... */
int x_complete_word(const char *str, int slen, int is_command,
- int *multiple, char **ret);
+ int *multiple, char **ret);
int
x_complete_word(const char *str, int slen, int is_command, int *multiple,
char **ret)
@@ -306,7 +305,7 @@ x_complete_word(const char *str, int slen, int is_command, int *multiple,
char **words;
nwords = (is_command ? x_command_glob : x_file_glob)(XCF_FULLPATH,
- str, slen, &words);
+ str, slen, &words);
*nwordsp = nwords;
if (nwords == 0) {
*ret = (char *) 0;
@@ -330,9 +329,8 @@ x_print_expansions(int nwords, char *const *words, int is_command)
/* Check if all matches are in the same directory (in this
* case, we want to omit the directory name)
*/
- if (!is_command
- && (prefix_len = x_longest_prefix(nwords, words)) > 0)
- {
+ if (!is_command &&
+ (prefix_len = x_longest_prefix(nwords, words)) > 0) {
int i;
/* Special case for 1 match (prefix is whole word) */
@@ -340,13 +338,12 @@ x_print_expansions(int nwords, char *const *words, int is_command)
prefix_len = x_basename(words[0], (char *) 0);
/* Any (non-trailing) slashes in non-common word suffixes? */
for (i = 0; i < nwords; i++)
- if (x_basename(words[i] + prefix_len, (char *) 0)
- > prefix_len)
+ if (x_basename(words[i] + prefix_len, (char *) 0) >
+ prefix_len)
break;
/* All in same directory? */
if (i == nwords) {
- while (prefix_len > 0
- && words[0][prefix_len - 1] != '/')
+ while (prefix_len > 0 && words[0][prefix_len - 1] != '/')
prefix_len--;
use_copy = 1;
XPinit(l, nwords + 1);
@@ -390,7 +387,7 @@ x_file_glob(int flags, const char *str, int slen, char ***wordsp)
/* remove all escaping backward slashes */
escaping = 0;
- for(i = 0, idx = 0; toglob[i]; i++) {
+ for (i = 0, idx = 0; toglob[i]; i++) {
if (toglob[i] == '\\' && !escaping) {
escaping = 1;
continue;
@@ -432,10 +429,9 @@ x_file_glob(int flags, const char *str, int slen, char ***wordsp)
* to glob something which evaluated to an empty
* string (e.g., "$FOO" when there is no FOO, etc).
*/
- if ((strcmp(words[0], toglob) == 0
- && stat(words[0], &statb) < 0)
- || words[0][0] == '\0')
- {
+ if ((strcmp(words[0], toglob) == 0 &&
+ stat(words[0], &statb) < 0) ||
+ words[0][0] == '\0') {
x_free_words(nwords, words);
nwords = 0;
}
@@ -521,10 +517,8 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
for (i = 0; i < nwords; i++) {
info[i].word = words[i];
info[i].base = x_basename(words[i], (char *) 0);
- if (!last_info || info[i].base != last_info->base
- || strncmp(words[i],
- last_info->word, info[i].base) != 0)
- {
+ if (!last_info || info[i].base != last_info->base ||
+ strncmp(words[i], last_info->word, info[i].base) != 0) {
last_info = &info[i];
path_order++;
}
@@ -559,8 +553,8 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
return nwords;
}
-#define IS_WORDC(c) !( ctype(c, C_LEX1) || (c) == '\'' || (c) == '"' \
- || (c) == '`' || (c) == '=' || (c) == ':' )
+#define IS_WORDC(c) !( ctype(c, C_LEX1) || (c) == '\'' || (c) == '"' || \
+ (c) == '`' || (c) == '=' || (c) == ':' )
static int
x_locate_word(const char *buf, int buflen, int pos, int *startp,
@@ -581,8 +575,8 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp,
/* Keep going backwards to start of word (has effect of allowing
* one blank after the end of a word)
*/
- for (; (start > 0 && IS_WORDC(buf[start - 1]))
- || (start > 1 && buf[start-2] == '\\'); start--)
+ for (; (start > 0 && IS_WORDC(buf[start - 1])) ||
+ (start > 1 && buf[start-2] == '\\'); start--)
;
/* Go forwards to end of word */
for (end = start; end < buflen && IS_WORDC(buf[end]); end++) {
@@ -635,7 +629,7 @@ x_cf_glob(int flags, const char *buf, int buflen, int pos, int *startp,
return 0;
nwords = (is_command ? x_command_glob : x_file_glob)(flags,
- buf + *startp, len, &words);
+ buf + *startp, len, &words);
if (nwords == 0) {
*wordsp = (char **) 0;
return 0;
@@ -818,12 +812,12 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *path)
words = (char **) XPptrv(*wp);
for (i = j = oldsize; i < newsize; i++) {
staterr = 0;
- if ((search_access(words[i], X_OK, &staterr) >= 0)
- || (staterr == EISDIR)) {
+ if ((search_access(words[i], X_OK, &staterr) >= 0) ||
+ (staterr == EISDIR)) {
words[j] = words[i];
if (!(flags & XCF_FULLPATH))
memmove(words[j], words[j] + pathlen,
- strlen(words[j] + pathlen) + 1);
+ strlen(words[j] + pathlen) + 1);
j++;
} else
afree(words[i], ATEMP);
diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c
index 100d8b354f4..ebfa3461d64 100644
--- a/bin/ksh/emacs.c
+++ b/bin/ksh/emacs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: emacs.c,v 1.36 2005/03/28 21:28:22 deraadt Exp $ */
+/* $OpenBSD: emacs.c,v 1.37 2005/03/30 17:16:37 deraadt Exp $ */
/*
* Emacs-like command line editing and history
@@ -31,7 +31,7 @@ static Area aedit;
#define KEOL 1 /* ^M, ^J */
#define KINTR 2 /* ^G, ^C */
-struct x_ftab {
+struct x_ftab {
int (*xf_func)(int c);
const char *xf_name;
short xf_flags;
@@ -197,26 +197,26 @@ static const struct x_ftab x_ftab[] = {
{ x_version, "version", 0 },
{ x_xchg_point_mark, "exchange-point-and-mark", 0 },
{ x_yank, "yank", 0 },
- { x_comp_list, "complete-list", 0 },
- { x_expand, "expand-file", 0 },
- { x_fold_capitalize, "capitalize-word", XF_ARG },
- { x_fold_lower, "downcase-word", XF_ARG },
- { x_fold_upper, "upcase-word", XF_ARG },
- { x_set_arg, "set-arg", XF_NOBIND },
- { x_comment, "comment", 0 },
+ { x_comp_list, "complete-list", 0 },
+ { x_expand, "expand-file", 0 },
+ { x_fold_capitalize, "capitalize-word", XF_ARG },
+ { x_fold_lower, "downcase-word", XF_ARG },
+ { x_fold_upper, "upcase-word", XF_ARG },
+ { x_set_arg, "set-arg", XF_NOBIND },
+ { x_comment, "comment", 0 },
#ifdef SILLY
{ x_game_of_life, "play-game-of-life", 0 },
#else
{ 0, 0, 0 },
#endif
#ifdef DEBUG
- { x_debug_info, "debug-info", 0 },
+ { x_debug_info, "debug-info", 0 },
#else
{ 0, 0, 0 },
#endif
{ 0, 0, 0 },
/* @END-FUNC-TAB@ */
- };
+};
static struct x_defbindings const x_defbindings[] = {
{ XFUNC_del_back, 0, CTRL('?') },
@@ -252,7 +252,7 @@ static struct x_defbindings const x_defbindings[] = {
{ XFUNC_yank, 0, CTRL('Y') },
{ XFUNC_meta_yank, 1, 'y' },
{ XFUNC_literal, 0, CTRL('^') },
- { XFUNC_comment, 1, '#' },
+ { XFUNC_comment, 1, '#' },
#if defined(TIOCSTI)
{ XFUNC_stuff, 0, CTRL('T') },
#else
@@ -260,9 +260,9 @@ static struct x_defbindings const x_defbindings[] = {
#endif
{ XFUNC_complete, 1, CTRL('[') },
{ XFUNC_comp_list, 0, CTRL('I') },
- { XFUNC_comp_list, 1, '=' },
+ { XFUNC_comp_list, 1, '=' },
{ XFUNC_enumerate, 1, '?' },
- { XFUNC_expand, 1, '*' },
+ { XFUNC_expand, 1, '*' },
{ XFUNC_comp_file, 1, CTRL('X') },
{ XFUNC_comp_comm, 2, CTRL('[') },
{ XFUNC_list_comm, 2, '?' },
@@ -272,32 +272,32 @@ static struct x_defbindings const x_defbindings[] = {
{ XFUNC_xchg_point_mark, 2, CTRL('X') },
{ XFUNC_version, 0, CTRL('V') },
#ifdef DEBUG
- { XFUNC_debug_info, 1, CTRL('H') },
+ { XFUNC_debug_info, 1, CTRL('H') },
#endif
{ XFUNC_prev_histword, 1, '.' },
{ XFUNC_prev_histword, 1, '_' },
- { XFUNC_set_arg, 1, '0' },
- { XFUNC_set_arg, 1, '1' },
- { XFUNC_set_arg, 1, '2' },
- { XFUNC_set_arg, 1, '3' },
- { XFUNC_set_arg, 1, '4' },
- { XFUNC_set_arg, 1, '5' },
- { XFUNC_set_arg, 1, '6' },
- { XFUNC_set_arg, 1, '7' },
- { XFUNC_set_arg, 1, '8' },
- { XFUNC_set_arg, 1, '9' },
- { XFUNC_fold_upper, 1, 'U' },
- { XFUNC_fold_upper, 1, 'u' },
- { XFUNC_fold_lower, 1, 'L' },
- { XFUNC_fold_lower, 1, 'l' },
- { XFUNC_fold_capitalize, 1, 'C' },
- { XFUNC_fold_capitalize, 1, 'c' },
+ { XFUNC_set_arg, 1, '0' },
+ { XFUNC_set_arg, 1, '1' },
+ { XFUNC_set_arg, 1, '2' },
+ { XFUNC_set_arg, 1, '3' },
+ { XFUNC_set_arg, 1, '4' },
+ { XFUNC_set_arg, 1, '5' },
+ { XFUNC_set_arg, 1, '6' },
+ { XFUNC_set_arg, 1, '7' },
+ { XFUNC_set_arg, 1, '8' },
+ { XFUNC_set_arg, 1, '9' },
+ { XFUNC_fold_upper, 1, 'U' },
+ { XFUNC_fold_upper, 1, 'u' },
+ { XFUNC_fold_lower, 1, 'L' },
+ { XFUNC_fold_lower, 1, 'l' },
+ { XFUNC_fold_capitalize, 1, 'C' },
+ { XFUNC_fold_capitalize, 1, 'c' },
/* These for ansi arrow keys: arguablely shouldn't be here by
* default, but its simpler/faster/smaller than using termcap
* entries.
*/
- { XFUNC_meta2, 1, '[' },
- { XFUNC_meta2, 1, 'O' },
+ { XFUNC_meta2, 1, '[' },
+ { XFUNC_meta2, 1, 'O' },
{ XFUNC_prev_com, 2, 'A' },
{ XFUNC_next_com, 2, 'B' },
{ XFUNC_mv_forw, 2, 'C' },
@@ -348,26 +348,25 @@ x_emacs(char *buf, size_t len)
x_curprefix = 1;
}
- f = x_curprefix == -1 ? XFUNC_insert
- : x_tab[x_curprefix][c&CHARMASK];
+ f = x_curprefix == -1 ? XFUNC_insert :
+ x_tab[x_curprefix][c&CHARMASK];
- if (!(x_ftab[f].xf_flags & XF_PREFIX)
- && x_last_command != XFUNC_set_arg)
- {
+ if (!(x_ftab[f].xf_flags & XF_PREFIX) &&
+ x_last_command != XFUNC_set_arg) {
x_arg = 1;
x_arg_defaulted = 1;
}
i = c | (x_curprefix << 8);
x_curprefix = 0;
- switch (i = (*x_ftab[f].xf_func)(i)) {
- case KSTD:
+ switch (i = (*x_ftab[f].xf_func)(i)) {
+ case KSTD:
if (!(x_ftab[f].xf_flags & XF_PREFIX))
x_last_command = f;
break;
- case KEOL:
+ case KEOL:
i = xep - xbuf;
return i;
- case KINTR: /* special case for interrupt */
+ case KINTR: /* special case for interrupt */
trapsig(SIGINT);
x_mode(false);
unwind(LSHELL);
@@ -383,7 +382,7 @@ x_insert(int c)
/*
* Should allow tab and control chars.
*/
- if (c == 0) {
+ if (c == 0) {
x_e_putc(BEL);
return KSTD;
}
@@ -397,7 +396,7 @@ x_insert(int c)
static int
x_ins_string(int c)
{
- if (macroptr) {
+ if (macroptr) {
x_e_putc(BEL);
return KSTD;
}
@@ -442,11 +441,10 @@ x_ins(char *s)
x_lastcp();
x_adj_ok = (xcp >= xlp);
x_zots(cp);
- if (adj == x_adj_done) /* has x_adjust() been called? */
- {
- /* no */
- for (cp = xlp; cp > xcp; )
- x_bs(*--cp);
+ if (adj == x_adj_done) { /* has x_adjust() been called? */
+ /* no */
+ for (cp = xlp; cp > xcp; )
+ x_bs(*--cp);
}
x_adj_ok = 1;
@@ -471,7 +469,7 @@ x_del_back(int c)
{
int col = xcp - xbuf;
- if (col == 0) {
+ if (col == 0) {
x_e_putc(BEL);
return KSTD;
}
@@ -523,7 +521,7 @@ x_delete(int nc, int push)
cp = xcp;
j = 0;
i = nc;
- while (i--) {
+ while (i--) {
j += x_size(*cp++);
}
memmove(xcp, xcp+nc, xep - xcp + 1); /* Copies the null */
@@ -534,15 +532,14 @@ x_delete(int nc, int push)
* there is no need to ' ','\b'.
* But if we must, make sure we do the minimum.
*/
- if ((i = xx_cols - 2 - x_col) > 0)
- {
- j = (j < i) ? j : i;
- i = j;
- while (i--)
- x_e_putc(' ');
- i = j;
- while (i--)
- x_e_putc('\b');
+ if ((i = xx_cols - 2 - x_col) > 0) {
+ j = (j < i) ? j : i;
+ i = j;
+ while (i--)
+ x_e_putc(' ');
+ i = j;
+ while (i--)
+ x_e_putc('\b');
}
/*x_goto(xcp);*/
x_adj_ok = 1;
@@ -587,22 +584,19 @@ x_bword(void)
int nc = 0;
char *cp = xcp;
- if (cp == xbuf) {
+ if (cp == xbuf) {
x_e_putc(BEL);
return 0;
}
- while (x_arg--)
- {
- while (cp != xbuf && is_mfs(cp[-1]))
- {
- cp--;
- nc++;
- }
- while (cp != xbuf && !is_mfs(cp[-1]))
- {
- cp--;
- nc++;
- }
+ while (x_arg--) {
+ while (cp != xbuf && is_mfs(cp[-1])) {
+ cp--;
+ nc++;
+ }
+ while (cp != xbuf && !is_mfs(cp[-1])) {
+ cp--;
+ nc++;
+ }
}
x_goto(cp);
return nc;
@@ -614,22 +608,19 @@ x_fword(void)
int nc = 0;
char *cp = xcp;
- if (cp == xep) {
+ if (cp == xep) {
x_e_putc(BEL);
return 0;
}
- while (x_arg--)
- {
- while (cp != xep && is_mfs(*cp))
- {
- cp++;
- nc++;
- }
- while (cp != xep && !is_mfs(*cp))
- {
- cp++;
- nc++;
- }
+ while (x_arg--) {
+ while (cp != xep && is_mfs(*cp)) {
+ cp++;
+ nc++;
+ }
+ while (cp != xep && !is_mfs(*cp)) {
+ cp++;
+ nc++;
+ }
}
return nc;
}
@@ -637,34 +628,24 @@ x_fword(void)
static void
x_goto(char *cp)
{
- if (cp < xbp || cp >= (xbp + x_displen))
- {
- /* we are heading off screen */
- xcp = cp;
- x_adjust();
- }
- else
- {
- if (cp < xcp) /* move back */
- {
- while (cp < xcp)
- x_bs(*--xcp);
- }
- else
- {
- if (cp > xcp) /* move forward */
- {
- while (cp > xcp)
- x_zotc(*xcp++);
- }
- }
- }
+ if (cp < xbp || cp >= (xbp + x_displen)) {
+ /* we are heading off screen */
+ xcp = cp;
+ x_adjust();
+ } else if (cp < xcp) { /* move back */
+ while (cp < xcp)
+ x_bs(*--xcp);
+ } else if (cp > xcp) { /* move forward */
+ while (cp > xcp)
+ x_zotc(*xcp++);
+ }
}
static void
x_bs(int c)
{
int i;
+
i = x_size(c);
while (i--)
x_e_putc('\b');
@@ -702,10 +683,10 @@ x_zots(char *str)
static void
x_zotc(int c)
{
- if (c == '\t') {
+ if (c == '\t') {
/* Kludge, tabs are always four spaces. */
x_e_puts(" ");
- } else if (iscntrl(c)) {
+ } else if (iscntrl(c)) {
x_e_putc('^');
x_e_putc(UNCTRL(c));
} else
@@ -717,7 +698,7 @@ x_mv_back(int c)
{
int col = xcp - xbuf;
- if (col == 0) {
+ if (col == 0) {
x_e_putc(BEL);
return KSTD;
}
@@ -750,13 +731,12 @@ x_search_char_forw(int c)
*xep = '\0';
c = x_e_getc();
while (x_arg--) {
- if (c < 0
- || ((cp = (cp == xep) ? NULL : strchr(cp + 1, c)) == NULL
- && (cp = strchr(xbuf, c)) == NULL))
- {
- x_e_putc(BEL);
- return KSTD;
- }
+ if (c < 0 ||
+ ((cp = (cp == xep) ? NULL : strchr(cp + 1, c)) == NULL &&
+ (cp = strchr(xbuf, c)) == NULL)) {
+ x_e_putc(BEL);
+ return KSTD;
+ }
}
x_goto(cp);
return KSTD;
@@ -909,7 +889,8 @@ x_search_hist(int c)
/* already have partial match */
offset = x_match(xbuf, pat);
if (offset >= 0) {
- x_goto(xbuf + offset + (p - pat) - (*pat == '^'));
+ x_goto(xbuf + offset + (p - pat) -
+ (*pat == '^'));
continue;
}
}
@@ -1014,44 +995,39 @@ x_redraw(int limit)
else
x_e_putc('\r');
x_flush();
- if (xbp == xbuf)
- {
- pprompt(prompt + prompt_skip, 0);
- x_col = promptlen(prompt, (const char **) 0);
+ if (xbp == xbuf) {
+ pprompt(prompt + prompt_skip, 0);
+ x_col = promptlen(prompt, (const char **) 0);
}
x_displen = xx_cols - 2 - x_col;
xlp_valid = false;
cp = x_lastcp();
x_zots(xbp);
if (xbp != xbuf || xep > xlp)
- limit = xx_cols;
- if (limit >= 0)
- {
- if (xep > xlp)
- i = 0; /* we fill the line */
- else
- i = limit - (xlp - xbp);
-
- for (j = 0; j < i && x_col < (xx_cols - 2); j++)
- x_e_putc(' ');
- i = ' ';
- if (xep > xlp) /* more off screen */
- {
- if (xbp > xbuf)
- i = '*';
- else
- i = '>';
- }
- else
- if (xbp > xbuf)
- i = '<';
- x_e_putc(i);
- j++;
- while (j--)
- x_e_putc('\b');
+ limit = xx_cols;
+ if (limit >= 0) {
+ if (xep > xlp)
+ i = 0; /* we fill the line */
+ else
+ i = limit - (xlp - xbp);
+
+ for (j = 0; j < i && x_col < (xx_cols - 2); j++)
+ x_e_putc(' ');
+ i = ' ';
+ if (xep > xlp) { /* more off screen */
+ if (xbp > xbuf)
+ i = '*';
+ else
+ i = '>';
+ } else if (xbp > xbuf)
+ i = '<';
+ x_e_putc(i);
+ j++;
+ while (j--)
+ x_e_putc('\b');
}
for (cp = xlp; cp > xcp; )
- x_bs(*--cp);
+ x_bs(*--cp);
x_adj_ok = 1;
D__(x_flush();)
return;
@@ -1168,7 +1144,7 @@ x_yank(int c)
else
killtp = killsp;
killtp --;
- if (killstack[killtp] == 0) {
+ if (killstack[killtp] == 0) {
x_e_puts("\nnothing to yank");
x_redraw(-1);
return KSTD;
@@ -1182,8 +1158,8 @@ static int
x_meta_yank(int c)
{
int len;
- if ((x_last_command != XFUNC_yank && x_last_command != XFUNC_meta_yank)
- || killstack[killtp] == 0) {
+ if ((x_last_command != XFUNC_yank && x_last_command != XFUNC_meta_yank) ||
+ killstack[killtp] == 0) {
killtp = killsp;
x_e_puts("\nyank something first");
x_redraw(-1);
@@ -1255,13 +1231,13 @@ x_mapin(const char *cp)
char *new, *op;
op = new = str_save(cp, ATEMP);
- while (*cp) {
+ while (*cp) {
/* XXX -- should handle \^ escape? */
- if (*cp == '^') {
+ if (*cp == '^') {
cp++;
if (*cp >= '?') /* includes '?'; ASCII */
*op++ = CTRL(*cp);
- else {
+ else {
*op++ = '^';
cp--;
}
@@ -1280,7 +1256,7 @@ x_mapout(int c)
static char buf[8];
char *p = buf;
- if (iscntrl(c)) {
+ if (iscntrl(c)) {
*p++ = '^';
*p++ = UNCTRL(c);
} else
@@ -1321,8 +1297,8 @@ x_bind( const char *a1, const char *a2,
/* List function names */
if (list) {
for (f = 0; f < NELEM(x_ftab); f++)
- if (x_ftab[f].xf_name
- && !(x_ftab[f].xf_flags & XF_NOBIND))
+ if (x_ftab[f].xf_name &&
+ !(x_ftab[f].xf_flags & XF_NOBIND))
shprintf("%s\n", x_ftab[f].xf_name);
return 0;
}
@@ -1331,8 +1307,8 @@ x_bind( const char *a1, const char *a2,
for (prefix = 0; prefix < X_NTABS; prefix++)
for (key = 0; key < X_TABSZ; key++) {
f = x_tab[prefix][key];
- if (f == XFUNC_insert || f == XFUNC_error
- || (macro && f != XFUNC_ins_string))
+ if (f == XFUNC_insert || f == XFUNC_error ||
+ (macro && f != XFUNC_ins_string))
continue;
x_print(prefix, key);
}
@@ -1360,8 +1336,8 @@ x_bind( const char *a1, const char *a2,
f = XFUNC_insert;
else if (!macro) {
for (f = 0; f < NELEM(x_ftab); f++)
- if (x_ftab[f].xf_name
- && strcmp(x_ftab[f].xf_name, a2) == 0)
+ if (x_ftab[f].xf_name &&
+ 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);
@@ -1387,10 +1363,10 @@ x_bind( const char *a1, const char *a2,
/* Track what the user has bound so x_emacs_keys() won't toast things */
if (f == XFUNC_insert)
x_bound[(prefix * X_TABSZ + key) / 8] &=
- ~(1 << ((prefix * X_TABSZ + key) % 8));
+ ~(1 << ((prefix * X_TABSZ + key) % 8));
else
x_bound[(prefix * X_TABSZ + key) / 8] |=
- (1 << ((prefix * X_TABSZ + key) % 8));
+ (1 << ((prefix * X_TABSZ + key) % 8));
return 0;
}
@@ -1412,7 +1388,7 @@ x_init_emacs(void)
x_tab[i][j] = XFUNC_error;
for (i = 0; i < NELEM(x_defbindings); i++)
x_tab[(unsigned char)x_defbindings[i].xdb_tab][x_defbindings[i].xdb_char]
- = x_defbindings[i].xdb_func;
+ = x_defbindings[i].xdb_func;
x_atab = (char *(*)[X_TABSZ]) alloc(sizeofN(*x_atab, X_NTABS), AEDIT);
for (i = 1; i < X_NTABS; i++)
@@ -1434,8 +1410,8 @@ static void
bind_if_not_bound(int p, int k, int func)
{
/* Has user already bound this key? If so, don't override it */
- if (x_bound[((p) * X_TABSZ + (k)) / 8]
- & (1 << (((p) * X_TABSZ + (k)) % 8)))
+ if (x_bound[((p) * X_TABSZ + (k)) / 8] &
+ (1 << (((p) * X_TABSZ + (k)) % 8)))
return;
x_tab[p][k] = func;
@@ -1553,11 +1529,11 @@ x_game_of_life(int c)
memmove(newbuf+1, xbuf, i);
newbuf[0] = 'A';
newbuf[i] = 'A';
- for (ip = newbuf+1, op = xbuf; --i >= 0; ip++, op++) {
+ for (ip = newbuf+1, op = xbuf; --i >= 0; ip++, op++) {
/* Empty space */
- if (*ip < '@' || *ip == '_' || *ip == 0x7F) {
+ if (*ip < '@' || *ip == '_' || *ip == 0x7F) {
/* Two adults, make whoopee */
- if (ip[-1] < '_' && ip[1] < '_') {
+ if (ip[-1] < '_' && ip[1] < '_') {
/* Make kid look like parents. */
*op = '`' + ((ip[-1] + ip[1])/2)%32;
if (*op == 0x7F) /* Birth defect */
@@ -1568,7 +1544,7 @@ x_game_of_life(int c)
continue;
}
/* Child */
- if (*ip > '`') {
+ if (*ip > '`') {
/* All alone, dies */
if (ip[-1] == ' ' && ip[1] == ' ')
*op = ' ';
@@ -1578,7 +1554,7 @@ x_game_of_life(int c)
}
/* Adult */
/* Overcrowded, dies */
- if (ip[-1] >= '@' && ip[1] >= '@') {
+ if (ip[-1] >= '@' && ip[1] >= '@') {
*op = ' ';
continue;
}
@@ -1646,9 +1622,8 @@ x_expand(int c)
int is_command;
int i;
- nwords = x_cf_glob(XCF_FILE,
- xbuf, xep - xbuf, xcp - xbuf,
- &start, &end, &words, &is_command);
+ nwords = x_cf_glob(XCF_FILE, xbuf, xep - xbuf, xcp - xbuf,
+ &start, &end, &words, &is_command);
if (nwords == 0) {
x_e_putc(BEL);
@@ -1659,8 +1634,7 @@ x_expand(int c)
x_delete(end - start, false);
for (i = 0; i < nwords;) {
if (x_escape(words[i], strlen(words[i]), x_emacs_putbuf) < 0 ||
- (++i < nwords && x_ins(space) < 0))
- {
+ (++i < nwords && x_ins(space) < 0)) {
x_e_putc(BEL);
return KSTD;
}
@@ -1682,7 +1656,7 @@ do_complete(int flags, /* XCF_{COMMAND,FILE,COMMAND_FILE} */
int completed = 0;
nwords = x_cf_glob(flags, xbuf, xep - xbuf, xcp - xbuf,
- &start, &end, &words, &is_command);
+ &start, &end, &words, &is_command);
/* no match */
if (nwords == 0) {
x_e_putc(BEL);
@@ -1740,15 +1714,15 @@ do_complete(int flags, /* XCF_{COMMAND,FILE,COMMAND_FILE} */
static void
x_adjust(void)
{
- x_adj_done++; /* flag the fact that we were called. */
- /*
- * we had a problem if the prompt length > xx_cols / 2
- */
- if ((xbp = xcp - (x_displen / 2)) < xbuf)
- xbp = xbuf;
- xlp_valid = false;
- x_redraw(xx_cols);
- x_flush();
+ x_adj_done++; /* flag the fact that we were called. */
+ /*
+ * we had a problem if the prompt length > xx_cols / 2
+ */
+ if ((xbp = xcp - (x_displen / 2)) < xbuf)
+ xbp = xbuf;
+ xlp_valid = false;
+ x_redraw(xx_cols);
+ x_flush();
}
static int unget_char = -1;
@@ -1768,7 +1742,7 @@ x_e_getc(void)
c = unget_char;
unget_char = -1;
} else {
- if (macroptr) {
+ if (macroptr) {
c = *macroptr++;
if (!*macroptr)
macroptr = (char *) 0;
@@ -1782,30 +1756,26 @@ x_e_getc(void)
static void
x_e_putc(int c)
{
- if (c == '\r' || c == '\n')
- x_col = 0;
- if (x_col < xx_cols)
- {
- x_putc(c);
- switch(c)
- {
- case BEL:
- break;
- case '\r':
- case '\n':
- break;
- case '\b':
- x_col--;
- break;
- default:
- x_col++;
- break;
- }
- }
- if (x_adj_ok && (x_col < 0 || x_col >= (xx_cols - 2)))
- {
- x_adjust();
- }
+ if (c == '\r' || c == '\n')
+ x_col = 0;
+ if (x_col < xx_cols) {
+ x_putc(c);
+ switch (c) {
+ case BEL:
+ break;
+ case '\r':
+ case '\n':
+ break;
+ case '\b':
+ x_col--;
+ break;
+ default:
+ x_col++;
+ break;
+ }
+ }
+ if (x_adj_ok && (x_col < 0 || x_col >= (xx_cols - 2)))
+ x_adjust();
}
#ifdef DEBUG
@@ -1815,7 +1785,7 @@ x_debug_info(int c)
x_flush();
shellf("\nksh debug:\n");
shellf("\tx_col == %d,\t\tx_cols == %d,\tx_displen == %d\n",
- x_col, xx_cols, x_displen);
+ x_col, xx_cols, x_displen);
shellf("\txcp == 0x%lx,\txep == 0x%lx\n", (long) xcp, (long) xep);
shellf("\txbp == 0x%lx,\txbuf == 0x%lx\n", (long) xbp, (long) xbuf);
shellf("\txlp == 0x%lx\n", (long) xlp);
@@ -1829,10 +1799,10 @@ x_debug_info(int c)
static void
x_e_puts(const char *s)
{
- int adj = x_adj_done;
+ int adj = x_adj_done;
- while (*s && adj == x_adj_done)
- x_e_putc(*s++);
+ while (*s && adj == x_adj_done)
+ x_e_putc(*s++);
}
/* NAME:
@@ -1914,39 +1884,39 @@ x_prev_histword(int c)
if (!cp)
x_e_putc(BEL);
else if (x_arg_defaulted) {
- rcp = &cp[strlen(cp) - 1];
- /*
- * ignore white-space after the last word
- */
- while (rcp > cp && is_cfs(*rcp))
+ rcp = &cp[strlen(cp) - 1];
+ /*
+ * ignore white-space after the last word
+ */
+ while (rcp > cp && is_cfs(*rcp))
rcp--;
- while (rcp > cp && !is_cfs(*rcp))
+ while (rcp > cp && !is_cfs(*rcp))
rcp--;
- if (is_cfs(*rcp))
+ if (is_cfs(*rcp))
rcp++;
- x_ins(rcp);
+ x_ins(rcp);
} else {
- int c;
+ int c;
- rcp = cp;
- /*
- * ignore white-space at start of line
- */
- while (*rcp && is_cfs(*rcp))
+ rcp = cp;
+ /*
+ * ignore white-space at start of line
+ */
+ while (*rcp && is_cfs(*rcp))
rcp++;
- while (x_arg-- > 1) {
+ while (x_arg-- > 1) {
while (*rcp && !is_cfs(*rcp))
rcp++;
while (*rcp && is_cfs(*rcp))
rcp++;
- }
- cp = rcp;
- while (*rcp && !is_cfs(*rcp))
+ }
+ cp = rcp;
+ while (*rcp && !is_cfs(*rcp))
rcp++;
- c = *rcp;
- *rcp = '\0';
- x_ins(cp);
- *rcp = c;
+ c = *rcp;
+ *rcp = '\0';
+ x_ins(cp);
+ *rcp = c;
}
return KSTD;
}
diff --git a/bin/ksh/eval.c b/bin/ksh/eval.c
index 48466f17c62..e30a5ad9546 100644
--- a/bin/ksh/eval.c
+++ b/bin/ksh/eval.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eval.c,v 1.26 2005/02/25 11:21:16 deraadt Exp $ */
+/* $OpenBSD: eval.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */
/*
* Expansion - quoting, separation, substitution, globbing
@@ -191,28 +191,28 @@ expand(char *cp, /* input word */
Xcheck(ds, dp);
switch (type) {
- case XBASE: /* original prefixed string */
+ case XBASE: /* original prefixed string */
c = *sp++;
switch (c) {
- case EOS:
+ case EOS:
c = 0;
break;
- case CHAR:
+ case CHAR:
c = *sp++;
break;
- case QCHAR:
+ case QCHAR:
quote |= 2; /* temporary quote */
c = *sp++;
break;
- case OQUOTE:
+ case OQUOTE:
word = IFS_WORD;
tilde_ok = 0;
quote = 1;
continue;
- case CQUOTE:
+ case CQUOTE:
quote = 0;
continue;
- case COMSUB:
+ case COMSUB:
tilde_ok = 0;
if (f & DONTRUNCOMMAND) {
word = IFS_WORD;
@@ -230,7 +230,7 @@ expand(char *cp, /* input word */
newlines = 0;
}
continue;
- case EXPRSUB:
+ case EXPRSUB:
word = IFS_WORD;
tilde_ok = 0;
if (f & DONTRUNCOMMAND) {
@@ -248,7 +248,7 @@ expand(char *cp, /* input word */
v.type = 10; /* not default */
v.name[0] = '\0';
v_evaluate(&v, substitute(sp, 0),
- KSH_UNWIND_ERROR, true);
+ KSH_UNWIND_ERROR, true);
sp = strchr(sp, 0) + 1;
for (p = str_val(&v); *p; ) {
Xcheck(ds, dp);
@@ -256,13 +256,13 @@ expand(char *cp, /* input word */
}
}
continue;
- case OSUBST: /* ${{#}var{:}[=+-?#%]word} */
+ case OSUBST: /* ${{#}var{:}[=+-?#%]word} */
/* format is:
* OSUBST [{x] plain-variable-part \0
* compiled-word-part CSUBST [}x]
* This is where all syntax checking gets done...
*/
- {
+ {
char *varname = ++sp; /* skip the { or x (}) */
int stype;
int slen;
@@ -290,7 +290,7 @@ expand(char *cp, /* input word */
SubType *newst;
newst = (SubType *) alloc(
- sizeof(SubType), ATEMP);
+ sizeof(SubType), ATEMP);
newst->next = (SubType *) 0;
newst->prev = st;
st->next = newst;
@@ -305,11 +305,11 @@ expand(char *cp, /* input word */
if (stype)
sp += slen;
switch (stype & 0x7f) {
- case '#':
- case '%':
+ case '#':
+ case '%':
/* ! DOBLANK,DOBRACE_,DOTILDE */
- f = DOPAT | (f&DONTRUNCOMMAND)
- | DOTEMP_;
+ f = DOPAT | (f&DONTRUNCOMMAND) |
+ DOTEMP_;
quote = 0;
/* Prepend open pattern (so |
* in a trim will work as
@@ -318,7 +318,7 @@ expand(char *cp, /* input word */
*dp++ = MAGIC;
*dp++ = '@' + 0x80;
break;
- case '=':
+ case '=':
/* Enabling tilde expansion
* after :'s here is
* non-standard ksh, but is
@@ -341,11 +341,11 @@ expand(char *cp, /* input word */
f &= ~(DOBLANK|DOGLOB|DOBRACE_);
tilde_ok = 1;
break;
- case '?':
+ case '?':
f &= ~DOBLANK;
f |= DOTEMP_;
/* fall through */
- default:
+ default:
/* Enable tilde expansion */
tilde_ok = 1;
f |= DOTILDE;
@@ -354,8 +354,8 @@ expand(char *cp, /* input word */
/* skip word */
sp = (char *) wdscan(sp, CSUBST);
continue;
- }
- case CSUBST: /* only get here if expanding word */
+ }
+ case CSUBST: /* only get here if expanding word */
sp++; /* ({) skip the } or x */
tilde_ok = 0; /* in case of ${unset:-} */
*dp = '\0';
@@ -364,8 +364,8 @@ expand(char *cp, /* input word */
if (f&DOBLANK)
doblank--;
switch (st->stype&0x7f) {
- case '#':
- case '%':
+ case '#':
+ case '%':
/* Append end-pattern */
*dp++ = MAGIC; *dp++ = ')'; *dp = '\0';
dp = Xrestpos(ds, dp, st->base);
@@ -380,7 +380,7 @@ expand(char *cp, /* input word */
doblank++;
st = st->prev;
continue;
- case '=':
+ case '=':
/* Restore our position and substitute
* the value of st->var (may not be
* the assigned value in the presence
@@ -401,47 +401,46 @@ expand(char *cp, /* input word */
len = strlen(dp) + 1;
setstr(st->var,
debunk((char *) alloc(len, ATEMP),
- dp, len),
- KSH_UNWIND_ERROR);
+ dp, len), KSH_UNWIND_ERROR);
x.str = str_val(st->var);
type = XSUB;
if (f&DOBLANK)
doblank++;
st = st->prev;
continue;
- case '?':
+ case '?':
{
char *s = Xrestpos(ds, dp, st->base);
errorf("%s: %s", st->var->name,
dp == s ?
- "parameter null or not set"
- : (debunk(s, s, strlen(s) + 1), s));
+ "parameter null or not set" :
+ (debunk(s, s, strlen(s) + 1), s));
}
}
st = st->prev;
type = XBASE;
continue;
- case OPAT: /* open pattern: *(foo|bar) */
+ case OPAT: /* open pattern: *(foo|bar) */
/* Next char is the type of pattern */
make_magic = 1;
c = *sp++ + 0x80;
break;
- case SPAT: /* pattern separator (|) */
+ case SPAT: /* pattern separator (|) */
make_magic = 1;
c = '|';
break;
- case CPAT: /* close pattern */
+ case CPAT: /* close pattern */
make_magic = 1;
c = /*(*/ ')';
break;
}
break;
- case XNULLSUB:
+ case XNULLSUB:
/* Special case for "$@" (and "${foo[@]}") - no
* word is generated if $# is 0 (unless there is
* other stuff inside the quotes).
@@ -458,8 +457,8 @@ expand(char *cp, /* input word */
}
continue;
- case XSUB:
- case XSUBMID:
+ case XSUB:
+ case XSUBMID:
if ((c = *x.str++) == 0) {
type = XBASE;
if (f&DOBLANK)
@@ -468,10 +467,10 @@ expand(char *cp, /* input word */
}
break;
- case XARGSEP:
+ case XARGSEP:
type = XARG;
quote = 1;
- case XARG:
+ case XARG:
if ((c = *x.str++) == '\0') {
/* force null words to be created so
* set -- '' 2 ''; foo "$@" will do
@@ -499,7 +498,7 @@ expand(char *cp, /* input word */
}
break;
- case XCOM:
+ case XCOM:
if (newlines) { /* Spit out saved nl's */
c = '\n';
--newlines;
@@ -527,9 +526,8 @@ expand(char *cp, /* input word */
}
/* check for end of word or IFS separation */
- if (c == 0 || (!quote && (f & DOBLANK) && doblank && !make_magic
- && ctype(c, C_IFS)))
- {
+ if (c == 0 || (!quote && (f & DOBLANK) && doblank &&
+ !make_magic && ctype(c, C_IFS))) {
/* How words are broken up:
* | value of c
* word | ws nws 0
@@ -541,9 +539,8 @@ expand(char *cp, /* input word */
* Note that IFS_NWS/0 generates a word (at&t ksh
* doesn't do this, but POSIX does).
*/
- if (word == IFS_WORD
- || (!ctype(c, C_IFSWS) && c && word == IFS_NWS))
- {
+ if (word == IFS_WORD ||
+ (!ctype(c, C_IFSWS) && c && word == IFS_NWS)) {
char *p;
*dp++ = '\0';
@@ -552,8 +549,8 @@ expand(char *cp, /* input word */
if (fdo & DOBRACE_)
/* also does globbing */
alt_expand(wp, p, p,
- p + Xlength(ds, (dp - 1)),
- fdo | (f & DOMARKDIRS));
+ p + Xlength(ds, (dp - 1)),
+ fdo | (f & DOMARKDIRS));
else
#endif /* BRACE_EXPAND */
if (fdo & DOGLOB)
@@ -591,10 +588,10 @@ expand(char *cp, /* input word */
/* mark any special second pass chars */
if (!quote)
switch (c) {
- case '[':
- case NOT:
- case '-':
- case ']':
+ case '[':
+ case NOT:
+ case '-':
+ case ']':
/* For character classes - doesn't hurt
* to have magic !,-,]'s outside of
* [...] expressions.
@@ -606,53 +603,51 @@ expand(char *cp, /* input word */
*dp++ = MAGIC;
}
break;
- case '*':
- case '?':
+ case '*':
+ case '?':
if (f & (DOPAT | DOGLOB)) {
fdo |= DOMAGIC_ | (f & DOGLOB);
*dp++ = MAGIC;
}
break;
#ifdef BRACE_EXPAND
- case OBRACE:
- case ',':
- case CBRACE:
- if ((f & DOBRACE_) && (c == OBRACE
- || (fdo & DOBRACE_)))
- {
+ case OBRACE:
+ case ',':
+ case CBRACE:
+ if ((f & DOBRACE_) && (c == OBRACE ||
+ (fdo & DOBRACE_))) {
fdo |= DOBRACE_|DOMAGIC_;
*dp++ = MAGIC;
}
break;
#endif /* BRACE_EXPAND */
- case '=':
+ case '=':
/* Note first unquoted = for ~ */
if (!(f & DOTEMP_) && !saw_eq) {
saw_eq = 1;
tilde_ok = 1;
}
break;
- case ':': /* : */
+ case ':': /* : */
/* Note unquoted : for ~ */
if (!(f & DOTEMP_) && (f & DOASNTILDE))
tilde_ok = 1;
break;
- case '~':
+ case '~':
/* tilde_ok is reset whenever
* any of ' " $( $(( ${ } are seen.
* Note that tilde_ok must be preserved
* through the sequence ${A=a=}~
*/
- if (type == XBASE
- && (f & (DOTILDE|DOASNTILDE))
- && (tilde_ok & 2))
- {
+ if (type == XBASE &&
+ (f & (DOTILDE|DOASNTILDE)) &&
+ (tilde_ok & 2)) {
char *p, *dp_x;
dp_x = dp;
p = maybe_expand_tilde(sp,
- &ds, &dp_x,
- f & DOASNTILDE);
+ &ds, &dp_x,
+ f & DOASNTILDE);
if (p) {
if (dp != dp_x)
word = IFS_WORD;
@@ -764,9 +759,9 @@ varsub(Expand *xp, char *sp, char *word,
c = sp[0];
if (c == '*' || c == '@') {
switch (stype & 0x7f) {
- case '=': /* can't assign to a vector */
- case '%': /* can't trim a vector (yet) */
- case '#':
+ case '=': /* can't assign to a vector */
+ case '%': /* can't trim a vector (yet) */
+ case '#':
return -1;
}
if (e->loc->argc == 0) {
@@ -784,10 +779,10 @@ varsub(Expand *xp, char *sp, char *word,
XPtrV wv;
switch (stype & 0x7f) {
- case '=': /* can't assign to a vector */
- case '%': /* can't trim a vector (yet) */
- case '#':
- case '?':
+ case '=': /* can't assign to a vector */
+ case '%': /* can't trim a vector (yet) */
+ case '#':
+ case '?':
return -1;
}
XPinit(wv, 32);
@@ -810,8 +805,8 @@ varsub(Expand *xp, char *sp, char *word,
}
} else {
/* Can't assign things like $! or $1 */
- if ((stype & 0x7f) == '='
- && (ctype(*sp, C_VAR1) || digit(*sp)))
+ if ((stype & 0x7f) == '=' &&
+ (ctype(*sp, C_VAR1) || digit(*sp)))
return -1;
xp->var = global(sp);
xp->str = str_val(xp->var);
@@ -823,10 +818,10 @@ varsub(Expand *xp, char *sp, char *word,
/* test the compiler's code generator */
if (ctype(c, C_SUBOP2) ||
(((stype&0x80) ? *xp->str=='\0' : xp->str==null) ? /* undef? */
- c == '=' || c == '-' || c == '?' : c == '+'))
+ c == '=' || c == '-' || c == '?' : c == '+'))
state = XBASE; /* expand word instead of variable value */
- if (Flag(FNOUNSET) && xp->str == null
- && (ctype(c, C_SUBOP2) || (state != XBASE && c != '+')))
+ if (Flag(FNOUNSET) && xp->str == null &&
+ (ctype(c, C_SUBOP2) || (state != XBASE && c != '+')))
errorf("%s: parameter not set", sp);
return state;
}
@@ -857,7 +852,7 @@ comsub(Expand *xp, char *cp)
if ((io->flag&IOTYPE) != IOREAD)
errorf("funny $() command: %s",
- snptreef((char *) 0, 32, "%R", io));
+ snptreef((char *) 0, 32, "%R", io));
shf = shf_open(name = evalstr(io->name, DOTILDE), O_RDONLY, 0,
SHF_MAPHI|SHF_CLEXEC);
if (shf == NULL)
@@ -893,7 +888,7 @@ trimsub(char *str, char *pat, int how)
char *p, c;
switch (how&0xff) { /* UCHAR_MAX maybe? */
- case '#': /* shortest at beginning */
+ case '#': /* shortest at beginning */
for (p = str; p <= end; p++) {
c = *p; *p = '\0';
if (gmatch(str, pat, false)) {
@@ -903,7 +898,7 @@ trimsub(char *str, char *pat, int how)
*p = c;
}
break;
- case '#'|0x80: /* longest match at beginning */
+ case '#'|0x80: /* longest match at beginning */
for (p = end; p >= str; p--) {
c = *p; *p = '\0';
if (gmatch(str, pat, false)) {
@@ -913,13 +908,13 @@ trimsub(char *str, char *pat, int how)
*p = c;
}
break;
- case '%': /* shortest match at end */
+ case '%': /* shortest match at end */
for (p = end; p >= str; p--) {
if (gmatch(p, pat, false))
return str_nsave(str, p - str, ATEMP);
}
break;
- case '%'|0x80: /* longest match at end */
+ case '%'|0x80: /* longest match at end */
for (p = str; p <= end; p++) {
if (gmatch(p, pat, false))
return str_nsave(str, p - str, ATEMP);
@@ -992,9 +987,8 @@ globit(XString *xs, /* dest string */
* any patterns were expanded and the markdirs option is set.
* Symlinks make things a bit tricky...
*/
- if ((check & GF_EXCHECK)
- || ((check & GF_MARKDIR) && (check & GF_GLOBBED)))
- {
+ if ((check & GF_EXCHECK) ||
+ ((check & GF_MARKDIR) && (check & GF_GLOBBED))) {
#define stat_check() (stat_done ? stat_done : \
(stat_done = stat(Xstring(*xs, xp), &statb) < 0 \
? -1 : 1))
@@ -1007,25 +1001,20 @@ globit(XString *xs, /* dest string */
* slashes from regular files (eg, /etc/passwd/).
* SunOS 4.1.3 does this...
*/
- if ((check & GF_EXCHECK) && xp > Xstring(*xs, xp)
- && xp[-1] == '/' && !S_ISDIR(lstatb.st_mode)
- && (!S_ISLNK(lstatb.st_mode)
- || stat_check() < 0
- || !S_ISDIR(statb.st_mode))
- )
+ if ((check & GF_EXCHECK) && xp > Xstring(*xs, xp) &&
+ xp[-1] == '/' && !S_ISDIR(lstatb.st_mode) &&
+ (!S_ISLNK(lstatb.st_mode) ||
+ stat_check() < 0 || !S_ISDIR(statb.st_mode)))
return;
/* Possibly tack on a trailing / if there isn't already
* one and if the file is a directory or a symlink to a
* directory
*/
- if (((check & GF_MARKDIR) && (check & GF_GLOBBED))
- && xp > Xstring(*xs, xp) && xp[-1] != '/'
- && (S_ISDIR(lstatb.st_mode)
- || (S_ISLNK(lstatb.st_mode)
- && stat_check() > 0
- && S_ISDIR(statb.st_mode))
- ))
- {
+ if (((check & GF_MARKDIR) && (check & GF_GLOBBED)) &&
+ xp > Xstring(*xs, xp) && xp[-1] != '/' &&
+ (S_ISDIR(lstatb.st_mode) ||
+ (S_ISLNK(lstatb.st_mode) && stat_check() > 0 &&
+ S_ISDIR(statb.st_mode)))) {
*xp++ = '/';
*xp = '\0';
}
@@ -1081,8 +1070,8 @@ globit(XString *xs, /* dest string */
if (name[0] == '.' &&
(name[1] == 0 || (name[1] == '.' && name[2] == 0)))
continue; /* always ignore . and .. */
- if ((*name == '.' && *sp != '.')
- || !gmatch(name, sp, true))
+ if ((*name == '.' && *sp != '.') ||
+ !gmatch(name, sp, true))
continue;
len = strlen(d->d_name) + 1;
@@ -1154,8 +1143,8 @@ debunk(char *dp, const char *sp, size_t dlen)
return dp;
memcpy(dp, sp, s - sp);
for (d = dp + (s - sp); *s && (d - dp < dlen); s++)
- if (!ISMAGIC(*s) || !(*++s & 0x80)
- || !strchr("*+?@! ", *s & 0x7f))
+ if (!ISMAGIC(*s) || !(*++s & 0x80) ||
+ !strchr("*+?@! ", *s & 0x7f))
*d++ = *s;
else {
/* extended pattern operators: *+?@! */
@@ -1190,7 +1179,8 @@ maybe_expand_tilde(char *p, XString *dsp, char **dpp, int isassign)
p += 2;
}
*tp = '\0';
- r = (p[0] == EOS || p[0] == CHAR || p[0] == CSUBST) ? tilde(Xstring(ts, tp)) : (char *) 0;
+ r = (p[0] == EOS || p[0] == CHAR || p[0] == CSUBST) ?
+ tilde(Xstring(ts, tp)) : (char *) 0;
Xfree(ts, tp);
if (r) {
while (*r) {
@@ -1309,9 +1299,8 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
if (ISMAGIC(*p)) {
if (*++p == OBRACE)
count++;
- else if ((*p == CBRACE && --count == 0)
- || (*p == ',' && count == 1))
- {
+ else if ((*p == CBRACE && --count == 0) ||
+ (*p == ',' && count == 1)) {
char *new;
int l1, l2, l3;
@@ -1324,7 +1313,7 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
memcpy(new + l1 + l2, brace_end, l3);
new[l1 + l2 + l3] = '\0';
alt_expand(wp, new, new + l1,
- new + l1 + l2 + l3, fdo);
+ new + l1 + l2 + l3, fdo);
field_start = p + 1;
}
}
diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c
index 27a7cd28a8a..400f7357f80 100644
--- a/bin/ksh/exec.c
+++ b/bin/ksh/exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec.c,v 1.40 2005/03/28 21:28:22 deraadt Exp $ */
+/* $OpenBSD: exec.c,v 1.41 2005/03/30 17:16:37 deraadt Exp $ */
/*
* execute command tree
@@ -79,7 +79,7 @@ execute(struct op *volatile t,
PS4_SUBSTITUTE(str_val(global("PS4"))));
for (i = 0; ap[i]; i++)
shf_fprintf(shl_out, "%s%s", ap[i],
- ap[i + 1] ? space : newline);
+ ap[i + 1] ? space : newline);
shf_flush(shl_out);
}
if (ap[0])
@@ -101,24 +101,24 @@ execute(struct op *volatile t,
/* Redirection failures for special commands
* cause (non-interactive) shell to exit.
*/
- if (tp && tp->type == CSHELL
- && (tp->flag & SPEC_BI))
+ if (tp && tp->type == CSHELL &&
+ (tp->flag & SPEC_BI))
errorf(null);
/* Deal with FERREXIT, quitenv(), etc. */
goto Break;
}
}
- switch(t->type) {
- case TCOM:
+ switch (t->type) {
+ case TCOM:
rv = comexec(t, tp, ap, flags);
break;
- case TPAREN:
+ case TPAREN:
rv = execute(t->left, flags|XFORK);
break;
- case TPIPE:
+ case TPIPE:
flags |= XFORK;
flags &= ~XEXEC;
e->savefd[0] = savefd(0, 0);
@@ -146,7 +146,7 @@ execute(struct op *volatile t,
rv = i;
break;
- case TLIST:
+ case TLIST:
while (t->type == TLIST) {
execute(t->left, flags & XERROK);
t = t->right;
@@ -154,8 +154,8 @@ execute(struct op *volatile t,
rv = execute(t, flags & XERROK);
break;
- case TCOPROC:
- {
+ case TCOPROC:
+ {
sigset_t omask;
/* Block sigchild as we are using things changed in the
@@ -209,11 +209,11 @@ execute(struct op *volatile t,
*/
flags &= ~XEXEC;
exchild(t->left, flags|XBGND|XFORK|XCOPROC|XCCLOSE,
- coproc.readw);
+ coproc.readw);
break;
- }
+ }
- case TASYNC:
+ case TASYNC:
/* XXX non-optimal, I think - "(foo &)", forks for (),
* forks again for async... parent should optimize
* this to "foo &"...
@@ -221,8 +221,8 @@ execute(struct op *volatile t,
rv = execute(t->left, (flags&~XEXEC)|XBGND|XFORK);
break;
- case TOR:
- case TAND:
+ case TOR:
+ case TAND:
rv = execute(t->left, XERROK);
if (t->right != NULL && (rv == 0) == (t->type == TAND))
rv = execute(t->right, flags & XERROK);
@@ -230,11 +230,11 @@ execute(struct op *volatile t,
flags |= XERROK;
break;
- case TBANG:
+ case TBANG:
rv = !execute(t->right, XERROK);
break;
- case TDBRACKET:
+ case TDBRACKET:
{
Test_env te;
@@ -249,21 +249,19 @@ execute(struct op *volatile t,
break;
}
- case TFOR:
- case TSELECT:
+ case TFOR:
+ case TSELECT:
{
volatile bool is_first = true;
- ap = (t->vars != NULL) ?
- eval(t->vars, DOBLANK|DOGLOB|DOTILDE)
- : e->loc->argv + 1;
+ ap = (t->vars != NULL) ? eval(t->vars, DOBLANK|DOGLOB|DOTILDE) :
+ e->loc->argv + 1;
e->type = E_LOOP;
while (1) {
i = sigsetjmp(e->jbuf, 0);
if (!i)
break;
- if ((e->flags&EF_BRKCONT_PASS)
- || (i != LBREAK && i != LCONTIN))
- {
+ if ((e->flags&EF_BRKCONT_PASS) ||
+ (i != LBREAK && i != LCONTIN)) {
quitenv(NULL);
unwind(i);
} else if (i == LBREAK) {
@@ -291,16 +289,15 @@ execute(struct op *volatile t,
}
break;
- case TWHILE:
- case TUNTIL:
+ case TWHILE:
+ case TUNTIL:
e->type = E_LOOP;
while (1) {
i = sigsetjmp(e->jbuf, 0);
if (!i)
break;
- if ((e->flags&EF_BRKCONT_PASS)
- || (i != LBREAK && i != LCONTIN))
- {
+ if ((e->flags&EF_BRKCONT_PASS) ||
+ (i != LBREAK && i != LCONTIN)) {
quitenv(NULL);
unwind(i);
} else if (i == LBREAK) {
@@ -313,43 +310,43 @@ execute(struct op *volatile t,
rv = execute(t->right, flags & XERROK);
break;
- case TIF:
- case TELIF:
+ case TIF:
+ case TELIF:
if (t->right == NULL)
break; /* should be error */
rv = execute(t->left, XERROK) == 0 ?
- execute(t->right->left, flags & XERROK) :
- execute(t->right->right, flags & XERROK);
+ execute(t->right->left, flags & XERROK) :
+ execute(t->right->right, flags & XERROK);
break;
- case TCASE:
+ case TCASE:
cp = evalstr(t->str, DOTILDE);
for (t = t->left; t != NULL && t->type == TPAT; t = t->right)
for (ap = t->vars; *ap; ap++)
- if ((s = evalstr(*ap, DOTILDE|DOPAT))
- && gmatch(cp, s, false))
+ if ((s = evalstr(*ap, DOTILDE|DOPAT)) &&
+ gmatch(cp, s, false))
goto Found;
break;
Found:
rv = execute(t->left, flags & XERROK);
break;
- case TBRACE:
+ case TBRACE:
rv = execute(t->left, flags & XERROK);
break;
- case TFUNCT:
+ case TFUNCT:
rv = define(t->str, t);
break;
- case TTIME:
+ case TTIME:
/* Clear XEXEC so nested execute() call doesn't exit
* (allows "ls -l | time grep foo").
*/
rv = timex(t, flags & ~XEXEC);
break;
- case TEXEC: /* an eval'd TCOM */
+ case TEXEC: /* an eval'd TCOM */
s = t->args[0];
ap = makenv();
restoresigs();
@@ -401,7 +398,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
;
/* setstr() can't fail here */
setstr(typeset("_", LOCAL, 0, INTEGER, 0), *--lastp,
- KSH_RETURN_ERROR);
+ KSH_RETURN_ERROR);
}
/* Deal with the shell builtins builtin, exec and command since
@@ -440,8 +437,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
* in c_command(), but such is life)
*/
ksh_getopt_reset(&builtin_opt, 0);
- while ((optc = ksh_getopt(ap, &builtin_opt, ":p"))
- == 'p')
+ while ((optc = ksh_getopt(ap, &builtin_opt, ":p")) == 'p')
saw_p = 1;
if (optc != EOF)
break; /* command -vV or something */
@@ -450,7 +446,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
if (saw_p) {
if (Flag(FRESTRICTED)) {
warningf(true,
- "command -p: restricted");
+ "command -p: restricted");
rv = 1;
goto Leave;
}
@@ -476,8 +472,8 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
/* create new variable/function block */
newblock();
/* ksh functions don't keep assignments, POSIX functions do. */
- if (keepasn_ok && tp && tp->type == CFUNC
- && !(tp->flag & FKSH)) {
+ if (keepasn_ok && tp && tp->type == CFUNC &&
+ !(tp->flag & FKSH)) {
bourne_function_call = 1;
type_flags = 0;
} else
@@ -490,9 +486,9 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
if (Flag(FXTRACE)) {
if (i == 0)
shf_fprintf(shl_out, "%s",
- PS4_SUBSTITUTE(str_val(global("PS4"))));
+ PS4_SUBSTITUTE(str_val(global("PS4"))));
shf_fprintf(shl_out, "%s%s", cp,
- t->vars[i + 1] ? space : newline);
+ t->vars[i + 1] ? space : newline);
if (!t->vars[i + 1])
shf_flush(shl_out);
}
@@ -514,12 +510,12 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
}
switch (tp->type) {
- case CSHELL: /* shell built-in */
+ case CSHELL: /* shell built-in */
rv = call_builtin(tp, ap);
break;
- case CFUNC: /* function call */
- {
+ case CFUNC: /* function call */
+ {
volatile int old_xflag;
volatile Tflag old_inuse;
const char *volatile old_kshname;
@@ -530,29 +526,30 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
if (!tp->u.fpath) {
if (tp->u2.errno_) {
warningf(true,
- "%s: can't find function definition file - %s",
- cp, strerror(tp->u2.errno_));
+ "%s: can't find function "
+ "definition file - %s",
+ cp, strerror(tp->u2.errno_));
rv = 126;
} else {
warningf(true,
- "%s: can't find function definition file", cp);
+ "%s: can't find function "
+ "definition file", cp);
rv = 127;
}
break;
}
if (include(tp->u.fpath, 0, (char **) 0, 0) < 0) {
warningf(true,
- "%s: can't open function definition file %s - %s",
- cp, tp->u.fpath, strerror(errno));
+ "%s: can't open function definition file %s - %s",
+ cp, tp->u.fpath, strerror(errno));
rv = 127;
break;
}
- if (!(ftp = findfunc(cp, hash(cp), false))
- || !(ftp->flag & ISSET))
- {
+ if (!(ftp = findfunc(cp, hash(cp), false)) ||
+ !(ftp->flag & ISSET)) {
warningf(true,
- "%s: function not defined by %s",
- cp, tp->u.fpath);
+ "%s: function not defined by %s",
+ cp, tp->u.fpath);
rv = 127;
break;
}
@@ -608,26 +605,26 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
tp->flag = 0;
}
switch (i) {
- case LRETURN:
- case LERROR:
+ case LRETURN:
+ case LERROR:
rv = exstat;
break;
- case LINTR:
- case LEXIT:
- case LLEAVE:
- case LSHELL:
+ case LINTR:
+ case LEXIT:
+ case LLEAVE:
+ case LSHELL:
quitenv(NULL);
unwind(i);
/*NOTREACHED*/
- default:
+ default:
quitenv(NULL);
internal_errorf(1, "CFUNC %d", i);
}
break;
- }
+ }
- case CEXEC: /* executable command */
- case CTALIAS: /* tracked alias */
+ case CEXEC: /* executable command */
+ case CTALIAS: /* tracked alias */
if (!(tp->flag&ISSET)) {
/* errno_ will be set if the named command was found
* but could not be executed (permissions, no execute
@@ -636,7 +633,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
*/
if (tp->u2.errno_) {
warningf(true, "%s: cannot execute - %s", cp,
- strerror(tp->u2.errno_));
+ strerror(tp->u2.errno_));
rv = 126; /* POSIX */
} else {
warningf(true, "%s: not found", cp);
@@ -649,7 +646,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
/* set $_ to program's full path */
/* setstr() can't fail here */
setstr(typeset("_", LOCAL|EXPORT, 0, INTEGER, 0),
- tp->val.s, KSH_RETURN_ERROR);
+ tp->val.s, KSH_RETURN_ERROR);
}
if (flags&XEXEC) {
@@ -837,7 +834,7 @@ findcom(const char *name, int flags)
tp->u2.errno_ = 0;
} else
tp->u.fpath = search(name, fpath, R_OK,
- &tp->u2.errno_);
+ &tp->u2.errno_);
}
}
if (!tp && (flags & FC_REGBI) && tbi && (tbi->flag & REG_BI))
@@ -864,9 +861,8 @@ findcom(const char *name, int flags)
}
Search:
- if ((!tp || (tp->type == CTALIAS && !(tp->flag&ISSET)))
- && (flags & FC_PATH))
- {
+ if ((!tp || (tp->type == CTALIAS && !(tp->flag&ISSET))) &&
+ (flags & FC_PATH)) {
if (!tp) {
if (insert && !(flags & FC_DEFPATH)) {
tp = tenter(&taliases, name, h);
@@ -878,15 +874,14 @@ findcom(const char *name, int flags)
tp->flag = DEFINED; /* make ~ISSET */
}
npath = search(name, flags & FC_DEFPATH ? def_path : path,
- X_OK, &tp->u2.errno_);
+ X_OK, &tp->u2.errno_);
if (npath) {
tp->val.s = tp == &temp ? npath : str_save(npath, APERM);
tp->flag |= ISSET|ALLOC;
- } else if ((flags & FC_FUNC)
- && (fpath = str_val(global("FPATH"))) != null
- && (npath = search(name, fpath, R_OK,
- &tp->u2.errno_)) != (char *) 0)
- {
+ } else if ((flags & FC_FUNC) &&
+ (fpath = str_val(global("FPATH"))) != null &&
+ (npath = search(name, fpath, R_OK,
+ &tp->u2.errno_)) != (char *) 0) {
/* An undocumented feature of at&t ksh is that it
* searches FPATH if a command is not found, even
* if the command hasn't been set up as an autoloaded
@@ -933,11 +928,9 @@ search_access(const char *path, int mode,
ret = access(path, mode);
if (ret < 0)
err = errno; /* File exists, but we can't access it */
- else if (mode == X_OK
- && (!S_ISREG(statb.st_mode)
- /* This 'cause access() says root can execute everything */
- || !(statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))))
- {
+ else if (mode == X_OK && (!S_ISREG(statb.st_mode) ||
+ !(statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))) {
+ /* This 'cause access() says root can execute everything */
ret = -1;
err = S_ISDIR(statb.st_mode) ? EISDIR : EACCES;
}
@@ -1034,41 +1027,41 @@ iosetup(struct ioword *iop, struct tbl *tp)
if (Flag(FXTRACE))
shellf("%s%s\n",
- PS4_SUBSTITUTE(str_val(global("PS4"))),
- snptreef((char *) 0, 32, "%R", &iotmp));
+ PS4_SUBSTITUTE(str_val(global("PS4"))),
+ snptreef((char *) 0, 32, "%R", &iotmp));
switch (iotype) {
- case IOREAD:
+ case IOREAD:
flags = O_RDONLY;
break;
- case IOCAT:
+ case IOCAT:
flags = O_WRONLY | O_APPEND | O_CREAT;
break;
- case IOWRITE:
+ case IOWRITE:
flags = O_WRONLY | O_CREAT | O_TRUNC;
/* The stat() is here to allow redirections to
* things like /dev/null without error.
*/
- if (Flag(FNOCLOBBER) && !(iop->flag & IOCLOB)
- && (stat(cp, &statb) < 0 || S_ISREG(statb.st_mode)))
+ if (Flag(FNOCLOBBER) && !(iop->flag & IOCLOB) &&
+ (stat(cp, &statb) < 0 || S_ISREG(statb.st_mode)))
flags |= O_EXCL;
break;
- case IORDWR:
+ case IORDWR:
flags = O_RDWR | O_CREAT;
break;
- case IOHERE:
+ case IOHERE:
do_open = 0;
/* herein() returns -2 if error has been printed */
u = herein(iop->heredoc, iop->flag & IOEVAL);
/* cp may have wrong name */
break;
- case IODUP:
- {
+ case IODUP:
+ {
const char *emsg;
do_open = 0;
@@ -1076,18 +1069,18 @@ iosetup(struct ioword *iop, struct tbl *tp)
u = 1009; /* prevent error return below */
do_close = 1;
} else if ((u = check_fd(cp,
- X_OK | ((iop->flag & IORDUP) ? R_OK : W_OK),
- &emsg)) < 0)
- {
+ X_OK | ((iop->flag & IORDUP) ? R_OK : W_OK),
+ &emsg)) < 0) {
warningf(true, "%s: %s",
- snptreef((char *) 0, 32, "%R", &iotmp), emsg);
+ snptreef((char *) 0, 32, "%R", &iotmp), emsg);
return -1;
}
if (u == iop->unit)
return 0; /* "dup from" == "dup to" */
break;
- }
+ }
}
+
if (do_open) {
if (Flag(FRESTRICTED) && (flags & O_CREAT)) {
warningf(true, "%s: restricted", cp);
@@ -1099,9 +1092,9 @@ iosetup(struct ioword *iop, struct tbl *tp)
/* herein() may already have printed message */
if (u == -1)
warningf(true, "cannot %s %s: %s",
- iotype == IODUP ? "dup"
- : (iotype == IOREAD || iotype == IOHERE) ?
- "open" : "create", cp, strerror(errno));
+ iotype == IODUP ? "dup" :
+ (iotype == IOREAD || iotype == IOHERE) ?
+ "open" : "create", cp, strerror(errno));
return -1;
}
/* Do not save if it has already been redirected (i.e. "cat >x >y"). */
@@ -1124,9 +1117,9 @@ iosetup(struct ioword *iop, struct tbl *tp)
else if (u != iop->unit) {
if (ksh_dup2(u, iop->unit, true) < 0) {
warningf(true,
- "could not finish (dup) redirection %s: %s",
- snptreef((char *) 0, 32, "%R", &iotmp),
- strerror(errno));
+ "could not finish (dup) redirection %s: %s",
+ snptreef((char *) 0, 32, "%R", &iotmp),
+ strerror(errno));
if (iotype != IODUP)
close(u);
return -1;
@@ -1173,8 +1166,8 @@ herein(const char *content, int sub)
h = maketemp(ATEMP, TT_HEREDOC_EXP, &e->temps);
if (!(shf = h->shf) || (fd = open(h->name, O_RDONLY, 0)) < 0) {
warningf(true, "can't %s temporary file %s: %s",
- !shf ? "create" : "open",
- h->name, strerror(errno));
+ !shf ? "create" : "open",
+ h->name, strerror(errno));
if (shf)
shf_close(shf);
return -2 /* special to iosetup(): don't print error */;
@@ -1206,7 +1199,7 @@ herein(const char *content, int sub)
if (shf_close(shf) == EOF) {
close(fd);
warningf(true, "error writing %s: %s", h->name,
- strerror(errno));
+ strerror(errno));
return -2; /* special to iosetup(): don't print error */
}
@@ -1222,8 +1215,8 @@ static char *
do_selectargs(char **ap, bool print_menu)
{
static const char *const read_args[] = {
- "read", "-r", "REPLY", (char *) 0
- };
+ "read", "-r", "REPLY", (char *) 0
+ };
char *s;
int i, argct;
@@ -1264,7 +1257,7 @@ select_fmt_entry(void *arg, int i, char *buf, int buflen)
struct select_menu_info *smi = (struct select_menu_info *) arg;
shf_snprintf(buf, buflen, "%*d) %s",
- smi->num_width, i + 1, smi->args[i]);
+ smi->num_width, i + 1, smi->args[i]);
return buf;
}
@@ -1305,7 +1298,7 @@ pr_menu(char *const *ap)
smi.arg_width = nwidth;
smi.num_width = dwidth;
print_columns(shl_out, n, select_fmt_entry, (void *) &smi,
- dwidth + nwidth + 2, 1);
+ dwidth + nwidth + 2, 1);
return n;
}
@@ -1368,9 +1361,8 @@ dbteste_isa(Test_env *te, Test_meta meta)
if (uqword) {
char buf[8]; /* longer than the longest operator */
char *q = buf;
- for (p = *te->pos.wp; *p == CHAR
- && q < &buf[sizeof(buf) - 1];
- p += 2)
+ for (p = *te->pos.wp;
+ *p == CHAR && q < &buf[sizeof(buf) - 1]; p += 2)
*q++ = p[1];
*q = '\0';
ret = (int) test_isop(te, meta, buf);
@@ -1378,8 +1370,8 @@ dbteste_isa(Test_env *te, Test_meta meta)
} else if (meta == TM_END)
ret = 0;
else
- ret = uqword
- && strcmp(*te->pos.wp, dbtest_tokens[(int) meta]) == 0;
+ ret = uqword &&
+ strcmp(*te->pos.wp, dbtest_tokens[(int) meta]) == 0;
/* Accept the token? */
if (ret)
diff --git a/bin/ksh/expand.h b/bin/ksh/expand.h
index e7f0e23219a..7288d4de1a3 100644
--- a/bin/ksh/expand.h
+++ b/bin/ksh/expand.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: expand.h,v 1.5 2004/12/18 21:25:44 millert Exp $ */
+/* $OpenBSD: expand.h,v 1.6 2005/03/30 17:16:37 deraadt Exp $ */
/*
* Expanding strings
@@ -85,7 +85,7 @@ typedef struct XPtrV {
vp__ = (void**) alloc(sizeofN(void*, n), ATEMP); \
(x).cur = (x).beg = vp__; \
(x).end = vp__ + n; \
- } while (0)
+ } while (0)
#define XPput(x, p) do { \
if ((x).cur >= (x).end) { \
diff --git a/bin/ksh/expr.c b/bin/ksh/expr.c
index 8b0b4e71019..a4e97d3bb16 100644
--- a/bin/ksh/expr.c
+++ b/bin/ksh/expr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: expr.c,v 1.17 2005/02/02 07:53:01 otto Exp $ */
+/* $OpenBSD: expr.c,v 1.18 2005/03/30 17:16:37 deraadt Exp $ */
/*
* Korn expression evaluation
@@ -19,7 +19,7 @@ enum token {
O_EQ, O_NE,
/* assignments are assumed to be in range O_ASN .. O_BORASN */
O_ASN, O_TIMESASN, O_DIVASN, O_MODASN, O_PLUSASN, O_MINUSASN,
- O_LSHIFTASN, O_RSHIFTASN, O_BANDASN, O_BXORASN, O_BORASN,
+ O_LSHIFTASN, O_RSHIFTASN, O_BANDASN, O_BXORASN, O_BORASN,
O_LSHIFT, O_RSHIFT,
O_LE, O_GE, O_LT, O_GT,
O_LAND,
@@ -38,7 +38,7 @@ enum token {
OPEN_PAREN, CLOSE_PAREN, CTERN,
/* things that don't appear in the opinfo[] table */
VAR, LIT, END, BAD
- };
+};
#define IS_BINOP(op) (((int)op) >= (int)O_EQ && ((int)op) <= (int)O_COMMA)
#define IS_ASSIGNOP(op) ((int)(op) >= (int)O_ASN && (int)(op) <= (int)O_BORASN)
@@ -57,7 +57,7 @@ enum prec {
P_TERN, /* ?: */
P_ASSIGN, /* = *= /= %= += -= <<= >>= &= ^= |= */
P_COMMA /* , */
- };
+};
#define MAX_PREC P_COMMA
struct opinfo {
@@ -71,46 +71,46 @@ struct opinfo {
* of enum token too.
*/
static const struct opinfo opinfo[] = {
- { "++", 2, P_PRIMARY }, /* before + */
- { "--", 2, P_PRIMARY }, /* before - */
- { "==", 2, P_EQUALITY }, /* before = */
- { "!=", 2, P_EQUALITY }, /* before ! */
- { "=", 1, P_ASSIGN }, /* keep assigns in a block */
- { "*=", 2, P_ASSIGN },
- { "/=", 2, P_ASSIGN },
- { "%=", 2, P_ASSIGN },
- { "+=", 2, P_ASSIGN },
- { "-=", 2, P_ASSIGN },
- { "<<=", 3, P_ASSIGN },
- { ">>=", 3, P_ASSIGN },
- { "&=", 2, P_ASSIGN },
- { "^=", 2, P_ASSIGN },
- { "|=", 2, P_ASSIGN },
- { "<<", 2, P_SHIFT },
- { ">>", 2, P_SHIFT },
- { "<=", 2, P_RELATION },
- { ">=", 2, P_RELATION },
- { "<", 1, P_RELATION },
- { ">", 1, P_RELATION },
- { "&&", 2, P_LAND },
- { "||", 2, P_LOR },
- { "*", 1, P_MULT },
- { "/", 1, P_MULT },
- { "%", 1, P_MULT },
- { "+", 1, P_ADD },
- { "-", 1, P_ADD },
- { "&", 1, P_BAND },
- { "^", 1, P_BXOR },
- { "|", 1, P_BOR },
- { "?", 1, P_TERN },
- { ",", 1, P_COMMA },
- { "~", 1, P_PRIMARY },
- { "!", 1, P_PRIMARY },
- { "(", 1, P_PRIMARY },
- { ")", 1, P_PRIMARY },
- { ":", 1, P_PRIMARY },
- { "", 0, P_PRIMARY } /* end of table */
- };
+ { "++", 2, P_PRIMARY }, /* before + */
+ { "--", 2, P_PRIMARY }, /* before - */
+ { "==", 2, P_EQUALITY }, /* before = */
+ { "!=", 2, P_EQUALITY }, /* before ! */
+ { "=", 1, P_ASSIGN }, /* keep assigns in a block */
+ { "*=", 2, P_ASSIGN },
+ { "/=", 2, P_ASSIGN },
+ { "%=", 2, P_ASSIGN },
+ { "+=", 2, P_ASSIGN },
+ { "-=", 2, P_ASSIGN },
+ { "<<=", 3, P_ASSIGN },
+ { ">>=", 3, P_ASSIGN },
+ { "&=", 2, P_ASSIGN },
+ { "^=", 2, P_ASSIGN },
+ { "|=", 2, P_ASSIGN },
+ { "<<", 2, P_SHIFT },
+ { ">>", 2, P_SHIFT },
+ { "<=", 2, P_RELATION },
+ { ">=", 2, P_RELATION },
+ { "<", 1, P_RELATION },
+ { ">", 1, P_RELATION },
+ { "&&", 2, P_LAND },
+ { "||", 2, P_LOR },
+ { "*", 1, P_MULT },
+ { "/", 1, P_MULT },
+ { "%", 1, P_MULT },
+ { "+", 1, P_ADD },
+ { "-", 1, P_ADD },
+ { "&", 1, P_BAND },
+ { "^", 1, P_BXOR },
+ { "|", 1, P_BOR },
+ { "?", 1, P_TERN },
+ { ",", 1, P_COMMA },
+ { "~", 1, P_PRIMARY },
+ { "!", 1, P_PRIMARY },
+ { "(", 1, P_PRIMARY },
+ { ")", 1, P_PRIMARY },
+ { ":", 1, P_PRIMARY },
+ { "", 0, P_PRIMARY } /* end of table */
+};
typedef struct expr_state Expr_state;
@@ -128,13 +128,15 @@ struct expr_state {
*/
};
-enum error_type { ET_UNEXPECTED, ET_BADLIT, ET_RECURSIVE,
- ET_LVALUE, ET_RDONLY, ET_STR };
+enum error_type {
+ ET_UNEXPECTED, ET_BADLIT, ET_RECURSIVE,
+ ET_LVALUE, ET_RDONLY, ET_STR
+};
-static void evalerr(Expr_state *, enum error_type, const char *)
- __attribute__((__noreturn__));
+static void evalerr(Expr_state *, enum error_type, const char *)
+ __attribute__((__noreturn__));
static struct tbl *evalexpr(Expr_state *, enum prec);
-static void token(Expr_state *);
+static void token(Expr_state *);
static struct tbl *do_ppmm(Expr_state *, enum token, struct tbl *, bool);
static void assign_check(Expr_state *, enum token, struct tbl *);
static struct tbl *tempvar(void);
@@ -249,17 +251,17 @@ evalerr(Expr_state *es, enum error_type type, const char *str)
case ET_RECURSIVE:
warningf(true, "%s: expression recurses on parameter `%s'",
- es->expression, str);
+ es->expression, str);
break;
case ET_LVALUE:
warningf(true, "%s: %s requires lvalue",
- es->expression, str);
+ es->expression, str);
break;
case ET_RDONLY:
warningf(true, "%s: %s applied to read only variable",
- es->expression, str);
+ es->expression, str);
break;
default: /* keep gcc happy */
@@ -279,9 +281,8 @@ evalexpr(Expr_state *es, enum prec prec)
if (prec == P_PRIMARY) {
op = es->tok;
- if (op == O_BNOT || op == O_LNOT || op == O_MINUS
- || op == O_PLUS)
- {
+ if (op == O_BNOT || op == O_LNOT || op == O_MINUS ||
+ op == O_PLUS) {
token(es);
vl = intvar(es, evalexpr(es, P_PRIMARY));
if (op == O_BNOT)
@@ -316,8 +317,7 @@ evalexpr(Expr_state *es, enum prec prec)
}
vl = evalexpr(es, ((int) prec) - 1);
for (op = es->tok; IS_BINOP(op) && opinfo[(int) op].prec == prec;
- op = es->tok)
- {
+ op = es->tok) {
token(es);
vasn = vl;
if (op != O_ASN) /* vl may not have a value yet */
@@ -327,9 +327,8 @@ evalexpr(Expr_state *es, enum prec prec)
vr = intvar(es, evalexpr(es, P_ASSIGN));
} else if (op != O_TERN && op != O_LAND && op != O_LOR)
vr = intvar(es, evalexpr(es, ((int) prec) - 1));
- if ((op == O_DIV || op == O_MOD || op == O_DIVASN
- || op == O_MODASN) && vr->val.i == 0)
- {
+ if ((op == O_DIV || op == O_MOD || op == O_DIVASN ||
+ op == O_MODASN) && vr->val.i == 0) {
if (es->noassign)
vr->val.i = 1;
else
@@ -413,6 +412,7 @@ evalexpr(Expr_state *es, enum prec prec)
case O_TERN:
{
int e = vl->val.i != 0;
+
if (!e)
es->noassign++;
vl = evalexpr(es, MAX_PREC);
@@ -474,11 +474,11 @@ token(Expr_state *es)
evalerr(es, ET_STR, "missing ]");
cp += len;
} else if (c == '(' /*)*/ ) {
- /* todo: add math functions (all take single argument):
- * abs acos asin atan cos cosh exp int log sin sinh sqrt
- * tan tanh
- */
- ;
+ /* todo: add math functions (all take single argument):
+ * abs acos asin atan cos cosh exp int log sin sinh sqrt
+ * tan tanh
+ */
+ ;
}
if (es->noassign) {
es->val = tempvar();
@@ -505,9 +505,8 @@ token(Expr_state *es)
int i, n0;
for (i = 0; (n0 = opinfo[i].name[0]); i++)
- if (c == n0
- && strncmp(cp, opinfo[i].name, opinfo[i].len) == 0)
- {
+ if (c == n0 &&
+ strncmp(cp, opinfo[i].name, opinfo[i].len) == 0) {
es->tok = (enum token) i;
cp += opinfo[i].len;
break;
@@ -569,8 +568,8 @@ intvar(Expr_state *es, struct tbl *vp)
struct tbl *vq;
/* try to avoid replacing a temp var with another temp var */
- if (vp->name[0] == '\0'
- && (vp->flag & (ISSET|INTEGER|EXPRLVALUE)) == (ISSET|INTEGER))
+ if (vp->name[0] == '\0' &&
+ (vp->flag & (ISSET|INTEGER|EXPRLVALUE)) == (ISSET|INTEGER))
return vp;
vq = tempvar();
diff --git a/bin/ksh/history.c b/bin/ksh/history.c
index 21eaff60dd5..6198e56d027 100644
--- a/bin/ksh/history.c
+++ b/bin/ksh/history.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: history.c,v 1.29 2004/12/22 17:14:34 millert Exp $ */
+/* $OpenBSD: history.c,v 1.30 2005/03/30 17:16:37 deraadt Exp $ */
/*
* command history
@@ -65,9 +65,10 @@ c_fc(char **wp)
return 1;
}
- while ((optc = ksh_getopt(wp, &builtin_opt, "e:glnrs0,1,2,3,4,5,6,7,8,9,")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt,
+ "e:glnrs0,1,2,3,4,5,6,7,8,9,")) != EOF)
switch (optc) {
- case 'e':
+ case 'e':
p = builtin_opt.optarg;
if (strcmp(p, "-") == 0)
sflag++;
@@ -77,24 +78,24 @@ c_fc(char **wp)
strlcat(editor, " $_", len);
}
break;
- case 'g': /* non-at&t ksh */
+ case 'g': /* non-at&t ksh */
gflag++;
break;
- case 'l':
+ case 'l':
lflag++;
break;
- case 'n':
+ case 'n':
nflag++;
break;
- case 'r':
+ case 'r':
rflag++;
break;
- case 's': /* posix version of -e - */
+ case 's': /* posix version of -e - */
sflag++;
break;
/* kludge city - accept -num as -- -num (kind of) */
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
p = shf_smprintf("-%c%s",
optc, builtin_opt.optarg);
if (!first)
@@ -106,7 +107,7 @@ c_fc(char **wp)
return 1;
}
break;
- case '?':
+ case '?':
return 1;
}
wp += builtin_opt.optind;
@@ -136,8 +137,8 @@ c_fc(char **wp)
return 1;
}
- hp = first ? hist_get(first, false, false)
- : hist_get_newest(false);
+ hp = first ? hist_get(first, false, false) :
+ hist_get_newest(false);
if (!hp)
return 1;
return hist_replace(hp, pat, rep, gflag);
@@ -157,8 +158,8 @@ c_fc(char **wp)
return 1;
}
if (!first) {
- hfirst = lflag ? hist_get("-16", true, true)
- : hist_get_newest(false);
+ hfirst = lflag ? hist_get("-16", true, true) :
+ hist_get_newest(false);
if (!hfirst)
return 1;
/* can't fail if hfirst didn't fail */
@@ -169,11 +170,11 @@ c_fc(char **wp)
* bounds for -l as well.
*/
hfirst = hist_get(first, (lflag || last) ? true : false,
- lflag ? true : false);
+ lflag ? true : false);
if (!hfirst)
return 1;
- hlast = last ? hist_get(last, true, lflag ? true : false)
- : (lflag ? hist_get_newest(false) : hfirst);
+ hlast = last ? hist_get(last, true, lflag ? true : false) :
+ (lflag ? hist_get_newest(false) : hfirst);
if (!hlast)
return 1;
}
@@ -190,10 +191,9 @@ c_fc(char **wp)
const char *nfmt = nflag ? "\t" : "%d\t";
for (hp = rflag ? hlast : hfirst;
- hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1)
- {
+ hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1) {
shf_fprintf(shl_stdout, nfmt,
- hist_source->line - (int) (histptr - hp));
+ hist_source->line - (int) (histptr - hp));
/* print multi-line commands correctly */
for (s = *hp; (t = strchr(s, '\n')); s = t)
shf_fprintf(shl_stdout, "%.*s\t", ++t - s, s);
@@ -208,11 +208,11 @@ c_fc(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));
+ tf->name, strerror(errno));
return 1;
}
for (hp = rflag ? hlast : hfirst;
- hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1)
+ 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));
@@ -244,8 +244,8 @@ c_fc(char **wp)
return 1;
}
- n = fstat(shf_fileno(shf), &statb) < 0 ? 128
- : statb.st_size + 1;
+ n = fstat(shf_fileno(shf), &statb) < 0 ? 128 :
+ statb.st_size + 1;
Xinit(xs, xp, n, hist_source->areap);
while ((n = shf_read(xp, Xnleft(xs, xp), shf)) > 0) {
xp += n;
@@ -254,7 +254,7 @@ c_fc(char **wp)
}
if (n < 0) {
bi_errorf("error reading temp file %s - %s",
- tf->name, strerror(shf_errno(shf)));
+ tf->name, strerror(shf_errno(shf)));
shf_close(shf);
return 1;
}
@@ -318,9 +318,8 @@ hist_replace(char **hp, const char *pat, const char *rep, int global)
int any_subst = 0;
Xinit(xs, xp, 128, ATEMP);
- for (s = *hp; (s1 = strstr(s, pat))
- && (!any_subst || global) ; s = s1 + pat_len)
- {
+ for (s = *hp; (s1 = strstr(s, pat)) && (!any_subst || global);
+ s = s1 + pat_len) {
any_subst = 1;
len = s1 - s;
XcheckN(xs, xp, len + rep_len);
@@ -475,8 +474,8 @@ findhist(int start, int fwd, const char *str, int anchored)
hp = &history[start];
for (; hp >= history && hp <= histptr; hp += incr)
- if ((anchored && strncmp(*hp, str, len) == 0)
- || (!anchored && strstr(*hp, str)))
+ if ((anchored && strncmp(*hp, str, len) == 0) ||
+ (!anchored && strstr(*hp, str)))
return hp - history;
return -1;
@@ -673,7 +672,8 @@ hist_init(Source *s)
/*
* we have some data
*/
- base = (unsigned char *)mmap(0, hsize, PROT_READ, MAP_FILE|MAP_PRIVATE, histfd, 0);
+ base = (unsigned char *)mmap(0, hsize, PROT_READ,
+ MAP_FILE|MAP_PRIVATE, histfd, 0);
/*
* check on its validity
*/
@@ -716,8 +716,7 @@ hist_count_lines(unsigned char *base, int bytes)
int lines = 0;
while (bytes--) {
- switch (state)
- {
+ switch (state) {
case shdr:
if (*base == COMMAND)
state = sn1;
@@ -908,7 +907,8 @@ writehistfile(int lno, char *cmd)
if (sizenow > hsize) {
/* someone has added some lines */
bytes = sizenow - hsize;
- base = (unsigned char *)mmap(0, sizenow, PROT_READ, MAP_FILE|MAP_PRIVATE, histfd, 0);
+ base = (unsigned char *)mmap(0, sizenow,
+ PROT_READ, MAP_FILE|MAP_PRIVATE, histfd, 0);
if (base == MAP_FAILED)
goto bad;
new = base + hsize;
diff --git a/bin/ksh/io.c b/bin/ksh/io.c
index 00593a1dffc..7012d78773d 100644
--- a/bin/ksh/io.c
+++ b/bin/ksh/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.20 2004/12/30 21:34:24 otto Exp $ */
+/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
/*
* shell buffered IO and formatted output
@@ -73,9 +73,8 @@ bi_errorf(const char *fmt, ...)
* non-interactive shells to exit.
* XXX odd use of KEEPASN; also may not want LERROR here
*/
- if ((builtin_flag & SPEC_BI)
- || (Flag(FPOSIX) && (builtin_flag & KEEPASN)))
- {
+ if ((builtin_flag & SPEC_BI) ||
+ (Flag(FPOSIX) && (builtin_flag & KEEPASN))) {
builtin_argv0 = (char *) 0;
unwind(LERROR);
}
@@ -103,12 +102,12 @@ void
error_prefix(int fileline)
{
/* Avoid foo: foo[2]: ... */
- if (!fileline || !source || !source->file
- || strcmp(source->file, kshname) != 0)
+ if (!fileline || !source || !source->file ||
+ strcmp(source->file, kshname) != 0)
shf_fprintf(shl_out, "%s: ", kshname + (*kshname == '-'));
if (fileline && source && source->file != NULL) {
shf_fprintf(shl_out, "%s[%d]: ", source->file,
- source->errline > 0 ? source->errline : source->line);
+ source->errline > 0 ? source->errline : source->line);
source->errline = 0;
}
}
@@ -149,8 +148,7 @@ kshdebug_init_(void)
if (kshdebug_shf)
shf_close(kshdebug_shf);
kshdebug_shf = shf_open("/tmp/ksh-debug.log",
- O_WRONLY|O_APPEND|O_CREAT, 0600,
- SHF_WR|SHF_MAPHI);
+ O_WRONLY|O_APPEND|O_CREAT, 0600, SHF_WR|SHF_MAPHI);
if (kshdebug_shf) {
shf_fprintf(kshdebug_shf, "\nNew shell[pid %d]\n", getpid());
shf_flush(kshdebug_shf);
@@ -183,9 +181,10 @@ kshdebug_dump_(const char *str, const void *mem, int nbytes)
shf_fprintf(kshdebug_shf, "[%d] %s:\n", getpid(), str);
for (i = 0; i < nbytes; i += nprow) {
char c = '\t';
+
for (j = 0; j < nprow && i + j < nbytes; j++) {
- shf_fprintf(kshdebug_shf, "%c%02x",
- c, ((const unsigned char *) mem)[i + j]);
+ shf_fprintf(kshdebug_shf, "%c%02x", c,
+ ((const unsigned char *) mem)[i + j]);
c = ' ';
}
shf_fprintf(kshdebug_shf, "\n");
@@ -201,7 +200,7 @@ can_seek(int fd)
struct stat statb;
return fstat(fd, &statb) == 0 && !S_ISREG(statb.st_mode) ?
- SHF_UNBUF : 0;
+ SHF_UNBUF : 0;
}
struct shf shf_iob[3];
@@ -302,14 +301,13 @@ check_fd(char *name, int mode, const char **emsgp)
* historical shells never did this check (XXX don't know what
* posix has to say).
*/
- if (!(mode & X_OK) && fl != O_RDWR
- && (((mode & R_OK) && fl != O_RDONLY)
- || ((mode & W_OK) && fl != O_WRONLY)))
- {
+ if (!(mode & X_OK) && fl != O_RDWR &&
+ (((mode & R_OK) && fl != O_RDONLY) ||
+ ((mode & W_OK) && fl != O_WRONLY))) {
if (emsgp)
*emsgp = (fl == O_WRONLY) ?
- "fd not open for reading"
- : "fd not open for writing";
+ "fd not open for reading" :
+ "fd not open for writing";
return -1;
}
return fd;
@@ -431,6 +429,5 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist)
tp->next = *tlist;
*tlist = tp;
-
return tp;
}
diff --git a/bin/ksh/jobs.c b/bin/ksh/jobs.c
index 0fa88155868..27e60685118 100644
--- a/bin/ksh/jobs.c
+++ b/bin/ksh/jobs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: jobs.c,v 1.33 2005/03/28 21:28:22 deraadt Exp $ */
+/* $OpenBSD: jobs.c,v 1.34 2005/03/30 17:16:37 deraadt Exp $ */
/*
* Process and job control
@@ -96,12 +96,13 @@ struct job {
#define JL_INVALID 3 /* non-pid, non-% job id */
static const char *const lookup_msgs[] = {
- null,
- "no such job",
- "ambiguous",
- "argument must be %job or process id",
- (char *) 0
- };
+ null,
+ "no such job",
+ "ambiguous",
+ "argument must be %job or process id",
+ (char *) 0
+};
+
struct timeval j_systime, j_usrtime; /* user and system time of last j_waitjed job */
static Job *job_list; /* job list */
@@ -151,7 +152,7 @@ j_init(int mflagset)
sigaddset(&sm_sigchld, SIGCHLD);
setsig(&sigtraps[SIGCHLD], j_sigchld,
- SS_RESTORE_ORIG|SS_FORCE|SS_SHTRAP);
+ SS_RESTORE_ORIG|SS_FORCE|SS_SHTRAP);
#ifdef JOBS
if (!mflagset && Flag(FTALKING))
@@ -172,7 +173,7 @@ j_init(int mflagset)
sigtraps[tt_sigs[i]].flags |= TF_SHELL_USES;
/* j_change() sets this to SS_RESTORE_DFL if FMONITOR */
setsig(&sigtraps[tt_sigs[i]], SIG_IGN,
- SS_RESTORE_IGN|SS_FORCE);
+ SS_RESTORE_IGN|SS_FORCE);
}
}
@@ -181,8 +182,8 @@ j_init(int mflagset)
j_change();
else
#endif /* JOBS */
- if (Flag(FTALKING))
- tty_init(true);
+ if (Flag(FTALKING))
+ tty_init(true);
}
/* job cleanup before shell exit */
@@ -194,13 +195,11 @@ j_exit(void)
int killed = 0;
for (j = job_list; j != (Job *) 0; j = j->next) {
- if (j->ppid == procpid
- && (j->state == PSTOPPED
- || (j->state == PRUNNING
- && ((j->flags & JF_FG)
- || (Flag(FLOGIN) && !Flag(FNOHUP)
- && procpid == kshpid)))))
- {
+ if (j->ppid == procpid &&
+ (j->state == PSTOPPED ||
+ (j->state == PRUNNING &&
+ ((j->flags & JF_FG) ||
+ (Flag(FLOGIN) && !Flag(FNOHUP) && procpid == kshpid))))) {
killed = 1;
if (j->pgrp == 0)
kill_job(j, SIGHUP);
@@ -255,20 +254,20 @@ j_change(void)
if (ttypgrp_ok && (our_pgrp = getpgrp()) < 0) {
warningf(false, "j_init: getpgrp() failed: %s",
- strerror(errno));
+ strerror(errno));
ttypgrp_ok = 0;
}
if (ttypgrp_ok) {
setsig(&sigtraps[SIGTTIN], SIG_DFL,
- SS_RESTORE_ORIG|SS_FORCE);
+ SS_RESTORE_ORIG|SS_FORCE);
/* wait to be given tty (POSIX.1, B.2, job control) */
while (1) {
pid_t ttypgrp;
if ((ttypgrp = tcgetpgrp(tty_fd)) < 0) {
warningf(false,
- "j_init: tcgetpgrp() failed: %s",
- strerror(errno));
+ "j_init: tcgetpgrp() failed: %s",
+ strerror(errno));
ttypgrp_ok = 0;
break;
}
@@ -279,18 +278,18 @@ j_change(void)
}
for (i = NELEM(tt_sigs); --i >= 0; )
setsig(&sigtraps[tt_sigs[i]], SIG_IGN,
- SS_RESTORE_DFL|SS_FORCE);
+ SS_RESTORE_DFL|SS_FORCE);
if (ttypgrp_ok && our_pgrp != kshpid) {
if (setpgid(0, kshpid) < 0) {
warningf(false,
- "j_init: setpgid() failed: %s",
- strerror(errno));
+ "j_init: setpgid() failed: %s",
+ strerror(errno));
ttypgrp_ok = 0;
} else {
if (tcsetpgrp(tty_fd, kshpid) < 0) {
warningf(false,
- "j_init: tcsetpgrp() failed: %s",
- strerror(errno));
+ "j_init: tcsetpgrp() failed: %s",
+ strerror(errno));
ttypgrp_ok = 0;
} else
restore_ttypgrp = our_pgrp;
@@ -306,14 +305,15 @@ j_change(void)
if (Flag(FTALKING))
for (i = NELEM(tt_sigs); --i >= 0; )
setsig(&sigtraps[tt_sigs[i]], SIG_IGN,
- SS_RESTORE_IGN|SS_FORCE);
+ SS_RESTORE_IGN|SS_FORCE);
else
for (i = NELEM(tt_sigs); --i >= 0; ) {
- if (sigtraps[tt_sigs[i]].flags & (TF_ORIG_IGN
- |TF_ORIG_DFL))
+ if (sigtraps[tt_sigs[i]].flags &
+ (TF_ORIG_IGN | TF_ORIG_DFL))
setsig(&sigtraps[tt_sigs[i]],
- (sigtraps[tt_sigs[i]].flags & TF_ORIG_IGN) ? SIG_IGN : SIG_DFL,
- SS_RESTORE_ORIG|SS_FORCE);
+ (sigtraps[tt_sigs[i]].flags & TF_ORIG_IGN) ?
+ SIG_IGN : SIG_DFL,
+ SS_RESTORE_ORIG|SS_FORCE);
}
if (!Flag(FTALKING))
tty_close();
@@ -354,7 +354,9 @@ exchild(struct op *t, int flags,
/* link process into jobs list */
if (flags&XPIPEI) { /* continuing with a pipe */
if (!last_job)
- internal_errorf(1, "exchild: XPIPEI and no last_job - pid %d", (int) procpid);
+ internal_errorf(1,
+ "exchild: XPIPEI and no last_job - pid %d",
+ (int) procpid);
j = last_job;
last_proc->next = p;
last_proc = p;
@@ -363,8 +365,8 @@ exchild(struct op *t, int flags,
/* we don't consider XXCOM's foreground since they don't get
* tty process group and we don't save or restore tty modes.
*/
- j->flags = (flags & XXCOM) ? JF_XXCOM
- : ((flags & XBGND) ? 0 : (JF_FG|JF_USETTYMODE));
+ j->flags = (flags & XXCOM) ? JF_XXCOM :
+ ((flags & XBGND) ? 0 : (JF_FG|JF_USETTYMODE));
timerclear(&j->usrtime);
timerclear(&j->systime);
j->state = PRUNNING;
@@ -424,8 +426,8 @@ exchild(struct op *t, int flags,
#endif /* JOBS */
/* used to close pipe input fd */
- if (close_fd >= 0 && (((flags & XPCLOSE) && !ischild)
- || ((flags & XCCLOSE) && ischild)))
+ if (close_fd >= 0 && (((flags & XPCLOSE) && !ischild) ||
+ ((flags & XCCLOSE) && ischild)))
close(close_fd);
if (ischild) { /* child */
/* Do this before restoring signal */
@@ -441,16 +443,16 @@ exchild(struct op *t, int flags,
if (Flag(FMONITOR) && !(flags & XXCOM)) {
for (i = NELEM(tt_sigs); --i >= 0; )
setsig(&sigtraps[tt_sigs[i]], SIG_DFL,
- SS_RESTORE_DFL|SS_FORCE);
+ SS_RESTORE_DFL|SS_FORCE);
}
#endif /* JOBS */
if (Flag(FBGNICE) && (flags & XBGND))
nice(4);
if ((flags & XBGND) && !Flag(FMONITOR)) {
setsig(&sigtraps[SIGINT], SIG_IGN,
- SS_RESTORE_IGN|SS_FORCE);
+ SS_RESTORE_IGN|SS_FORCE);
setsig(&sigtraps[SIGQUIT], SIG_IGN,
- SS_RESTORE_IGN|SS_FORCE);
+ SS_RESTORE_IGN|SS_FORCE);
if (!(flags & (XPIPEI | XCOPROC))) {
int fd = open("/dev/null", 0);
if (fd != 0) {
@@ -693,13 +695,18 @@ j_resume(const char *cp, int bg)
if (ttypgrp_ok && (j->flags & JF_SAVEDTTY))
tcsetattr(tty_fd, TCSADRAIN, &j->ttystate);
/* See comment in j_waitj regarding saved_ttypgrp. */
- if (ttypgrp_ok && tcsetpgrp(tty_fd, (j->flags & JF_SAVEDTTYPGRP) ? j->saved_ttypgrp : j->pgrp) < 0) {
+ if (ttypgrp_ok &&
+ tcsetpgrp(tty_fd, (j->flags & JF_SAVEDTTYPGRP) ?
+ j->saved_ttypgrp : j->pgrp) < 0) {
if (j->flags & JF_SAVEDTTY)
tcsetattr(tty_fd, TCSADRAIN, &tty_state);
sigprocmask(SIG_SETMASK, &omask,
- (sigset_t *) 0);
+ (sigset_t *) 0);
bi_errorf("1st tcsetpgrp(%d, %d) failed: %s",
- tty_fd, (int) ((j->flags & JF_SAVEDTTYPGRP) ? j->saved_ttypgrp : j->pgrp), strerror(errno));
+ tty_fd,
+ (int) ((j->flags & JF_SAVEDTTYPGRP) ?
+ j->saved_ttypgrp : j->pgrp),
+ strerror(errno));
return 1;
}
}
@@ -720,15 +727,15 @@ j_resume(const char *cp, int bg)
tcsetattr(tty_fd, TCSADRAIN, &tty_state);
if (ttypgrp_ok && tcsetpgrp(tty_fd, our_pgrp) < 0) {
warningf(true,
- "fg: 2nd tcsetpgrp(%d, %d) failed: %s",
- tty_fd, (int) our_pgrp,
- strerror(errno));
+ "fg: 2nd tcsetpgrp(%d, %d) failed: %s",
+ tty_fd, (int) our_pgrp,
+ strerror(errno));
}
# endif /* JOBS */
}
sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
bi_errorf("cannot continue job %s: %s",
- cp, strerror(err));
+ cp, strerror(err));
return 1;
}
if (!bg) {
@@ -756,15 +763,15 @@ j_stopped_running(void)
if (j->ppid == procpid && j->state == PSTOPPED)
which |= 1;
#endif /* JOBS */
- if (Flag(FLOGIN) && !Flag(FNOHUP) && procpid == kshpid
- && j->ppid == procpid && j->state == PRUNNING)
+ if (Flag(FLOGIN) && !Flag(FNOHUP) && procpid == kshpid &&
+ j->ppid == procpid && j->state == PRUNNING)
which |= 2;
}
if (which) {
shellf("You have %s%s%s jobs\n",
- which & 1 ? "stopped" : "",
- which == 3 ? " and " : "",
- which & 2 ? "running" : "");
+ which & 1 ? "stopped" : "",
+ which == 3 ? " and " : "",
+ which & 2 ? "running" : "");
return 1;
}
@@ -815,9 +822,8 @@ j_jobs(const char *cp, int slp,
j = job_list;
how = slp == 0 ? JP_MEDIUM : (slp == 1 ? JP_LONG : JP_PGRP);
for (; j; j = j->next) {
- if ((!(j->flags & JF_ZOMBIE) || zflag)
- && (!nflag || (j->flags & JF_CHANGED)))
- {
+ if ((!(j->flags & JF_ZOMBIE) || zflag) &&
+ (!nflag || (j->flags & JF_CHANGED))) {
j_print(j, how, shl_stdout);
if (j->state == PEXITED || j->state == PSIGNALLED)
j->flags |= JF_REMOVE;
@@ -899,13 +905,14 @@ j_set_async(Job *j)
while (nzombie > child_max) {
oldest = (Job *) 0;
for (jl = job_list; jl; jl = jl->next)
- if (jl != async_job && (jl->flags & JF_ZOMBIE)
- && (!oldest || jl->age < oldest->age))
+ if (jl != async_job && (jl->flags & JF_ZOMBIE) &&
+ (!oldest || jl->age < oldest->age))
oldest = jl;
if (!oldest) {
/* XXX debugging */
if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) {
- internal_errorf(0, "j_async: bad nzombie (%d)", nzombie);
+ internal_errorf(0,
+ "j_async: bad nzombie (%d)", nzombie);
nzombie = 0;
}
break;
@@ -957,10 +964,8 @@ j_waitj(Job *j,
if (!Flag(FMONITOR))
flags |= JW_STOPPEDWAIT;
- while ((volatile int) j->state == PRUNNING
- || ((flags & JW_STOPPEDWAIT)
- && (volatile int) j->state == PSTOPPED))
- {
+ while ((volatile int) j->state == PRUNNING ||
+ ((flags & JW_STOPPEDWAIT) && (volatile int) j->state == PSTOPPED)) {
sigsuspend(&sm_default);
if (fatal_trap) {
int oldf = j->flags & (JF_WAITING|JF_W_ASYNCNOTIFY);
@@ -992,13 +997,13 @@ j_waitj(Job *j,
* has restored the tty's pgrp to that of the su
* process).
*/
- if (j->state == PSTOPPED
- && (j->saved_ttypgrp = tcgetpgrp(tty_fd)) >= 0)
+ if (j->state == PSTOPPED &&
+ (j->saved_ttypgrp = tcgetpgrp(tty_fd)) >= 0)
j->flags |= JF_SAVEDTTYPGRP;
if (tcsetpgrp(tty_fd, our_pgrp) < 0) {
warningf(true,
- "j_waitj: tcsetpgrp(%d, %d) failed: %s",
- tty_fd, (int) our_pgrp,
+ "j_waitj: tcsetpgrp(%d, %d) failed: %s",
+ tty_fd, (int) our_pgrp,
strerror(errno));
}
if (j->state == PSTOPPED) {
@@ -1016,9 +1021,8 @@ j_waitj(Job *j,
* when more exits, it restores the `original'
* settings, and things go down hill from there...
*/
- if (j->state == PEXITED && j->status == 0
- && (j->flags & JF_USETTYMODE))
- {
+ if (j->state == PEXITED && j->status == 0 &&
+ (j->flags & JF_USETTYMODE)) {
tcgetattr(tty_fd, &tty_state);
} else {
tcsetattr(tty_fd, TCSADRAIN, &tty_state);
@@ -1044,9 +1048,9 @@ j_waitj(Job *j,
* a tty generated ^C goes to the whole process group)
*/
status = j->last_proc->status;
- if (Flag(FMONITOR) && j->state == PSIGNALLED
- && WIFSIGNALED(status)
- && (sigtraps[WTERMSIG(status)].flags & TF_TTY_INTR))
+ if (Flag(FMONITOR) && j->state == PSIGNALLED &&
+ WIFSIGNALED(status) &&
+ (sigtraps[WTERMSIG(status)].flags & TF_TTY_INTR))
trapsig(WTERMSIG(status));
#endif /* JOBS */
}
@@ -1055,14 +1059,13 @@ j_waitj(Job *j,
j_systime = j->systime;
rv = j->status;
- if (!(flags & JW_ASYNCNOTIFY)
- && (!Flag(FMONITOR) || j->state != PSTOPPED))
- {
+ if (!(flags & JW_ASYNCNOTIFY) &&
+ (!Flag(FMONITOR) || j->state != PSTOPPED)) {
j_print(j, JP_SHORT, shl_out);
shf_flush(shl_out);
}
- if (j->state != PSTOPPED
- && (!Flag(FMONITOR) || !(flags & JW_ASYNCNOTIFY)))
+ if (j->state != PSTOPPED &&
+ (!Flag(FMONITOR) || !(flags & JW_ASYNCNOTIFY)))
remove_job(j, where);
return rv;
@@ -1158,7 +1161,7 @@ check_job(Job *j)
/* XXX debugging (nasty - interrupt routine using shl_out) */
if (!(j->flags & JF_STARTED)) {
internal_errorf(0, "check_job: job started (flags 0x%x)",
- j->flags);
+ j->flags);
return;
}
@@ -1201,8 +1204,8 @@ check_job(Job *j)
coproc_write_close(coproc.write);
}
/* Do we need to keep the output? */
- if (j->coproc_id && j->coproc_id == coproc.id
- && --coproc.njobs == 0)
+ if (j->coproc_id && j->coproc_id == coproc.id &&
+ --coproc.njobs == 0)
coproc_readw_close(coproc.read);
}
@@ -1214,9 +1217,8 @@ check_job(Job *j)
*/
if (j->state == PSTOPPED)
put_job(j, PJ_ON_FRONT);
- if (Flag(FNOTIFY)
- && (j->flags & (JF_WAITING|JF_W_ASYNCNOTIFY)) != JF_WAITING)
- {
+ if (Flag(FNOTIFY) &&
+ (j->flags & (JF_WAITING|JF_W_ASYNCNOTIFY)) != JF_WAITING) {
/* Look for the real file descriptor 2 */
{
struct env *ep;
@@ -1238,9 +1240,8 @@ check_job(Job *j)
}
}
#endif /* JOBS */
- if (!Flag(FMONITOR) && !(j->flags & (JF_WAITING|JF_FG))
- && j->state != PSTOPPED)
- {
+ if (!Flag(FMONITOR) && !(j->flags & (JF_WAITING|JF_FG)) &&
+ j->state != PSTOPPED) {
if (j == async_job || (j->flags & JF_KNOWN)) {
j->flags |= JF_ZOMBIE;
j->job = -1;
@@ -1272,8 +1273,8 @@ j_print(Job *j, int how, struct shf *shf)
* group leader (ie, !FMONITOR). We arbitrarily return
* last pid (which is what $! returns).
*/
- shf_fprintf(shf, "%d\n", j->pgrp ? j->pgrp
- : (j->last_proc ? j->last_proc->pid : 0));
+ shf_fprintf(shf, "%d\n", j->pgrp ? j->pgrp :
+ (j->last_proc ? j->last_proc->pid : 0));
return;
}
j->flags &= ~JF_CHANGED;
@@ -1300,7 +1301,7 @@ j_print(Job *j, int how, struct shf *shf)
strlcpy(buf, "Done", sizeof buf);
else
shf_snprintf(buf, sizeof(buf), "Done (%d)",
- WEXITSTATUS(p->status));
+ WEXITSTATUS(p->status));
break;
case PSIGNALLED:
if (WCOREDUMP(p->status))
@@ -1308,9 +1309,9 @@ j_print(Job *j, int how, struct shf *shf)
/* kludge for not reporting `normal termination signals'
* (ie, SIGINT, SIGPIPE)
*/
- if (how == JP_SHORT && !coredumped
- && (WTERMSIG(p->status) == SIGINT
- || WTERMSIG(p->status) == SIGPIPE)) {
+ if (how == JP_SHORT && !coredumped &&
+ (WTERMSIG(p->status) == SIGINT ||
+ WTERMSIG(p->status) == SIGPIPE)) {
buf[0] = '\0';
} else
strlcpy(buf, sigtraps[WTERMSIG(p->status)].mess,
@@ -1332,26 +1333,25 @@ j_print(Job *j, int how, struct shf *shf)
if (buf[0]) {
output = 1;
shf_fprintf(shf, "%s%s ",
- buf, coredumped ? " (core dumped)" : null);
+ buf, coredumped ? " (core dumped)" : null);
}
} else {
output = 1;
shf_fprintf(shf, "%-20s %s%s%s", buf, p->command,
- p->next ? "|" : null,
- coredumped ? " (core dumped)" : null);
+ p->next ? "|" : null,
+ coredumped ? " (core dumped)" : null);
}
state = p->state;
status = p->status;
p = p->next;
- while (p && p->state == state && p->status == status)
- {
+ while (p && p->state == state && p->status == status) {
if (how == JP_LONG)
shf_fprintf(shf, "%s%5d %-20s %s%s", filler, p->pid,
- space, p->command, p->next ? "|" : null);
+ space, p->command, p->next ? "|" : null);
else if (how == JP_MEDIUM)
shf_fprintf(shf, " %s%s", p->command,
- p->next ? "|" : null);
+ p->next ? "|" : null);
p = p->next;
}
}
@@ -1566,7 +1566,7 @@ put_job(Job *j, int where)
prev = &job_list;
curr = job_list;
for (; curr && curr->state == PSTOPPED; prev = &curr->next,
- curr = *prev)
+ curr = *prev)
;
j->next = curr;
*prev = j;
diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c
index 2441dc14842..b06c590dd1f 100644
--- a/bin/ksh/lex.c
+++ b/bin/ksh/lex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lex.c,v 1.35 2005/02/21 16:01:58 otto Exp $ */
+/* $OpenBSD: lex.c,v 1.36 2005/03/30 17:16:37 deraadt Exp $ */
/*
* lexical analysis and source input
@@ -16,33 +16,33 @@ typedef struct lex_state Lex_state;
struct lex_state {
int ls_state;
union {
- /* $(...) */
- struct scsparen_info {
- int nparen; /* count open parenthesis */
- int csstate; /* XXX remove */
+ /* $(...) */
+ struct scsparen_info {
+ int nparen; /* count open parenthesis */
+ int csstate; /* XXX remove */
#define ls_scsparen ls_info.u_scsparen
- } u_scsparen;
+ } u_scsparen;
- /* $((...)) */
- struct sasparen_info {
- int nparen; /* count open parenthesis */
- int start; /* marks start of $(( in output str */
+ /* $((...)) */
+ struct sasparen_info {
+ int nparen; /* count open parenthesis */
+ int start; /* marks start of $(( in output str */
#define ls_sasparen ls_info.u_sasparen
- } u_sasparen;
+ } u_sasparen;
- /* ((...)) */
- struct sletparen_info {
- int nparen; /* count open parenthesis */
+ /* ((...)) */
+ struct sletparen_info {
+ int nparen; /* count open parenthesis */
#define ls_sletparen ls_info.u_sletparen
- } u_sletparen;
+ } u_sletparen;
- /* `...` */
- struct sbquote_info {
- int indquotes; /* true if in double quotes: "`...`" */
+ /* `...` */
+ struct sbquote_info {
+ int indquotes; /* true if in double quotes: "`...`" */
#define ls_sbquote ls_info.u_sbquote
- } u_sbquote;
+ } u_sbquote;
- Lex_state *base; /* used to point to next state block */
+ Lex_state *base; /* used to point to next state block */
} ls_info;
};
@@ -153,14 +153,13 @@ yylex(int cf)
statep->ls_state = state;
/* collect non-special or quoted characters to form word */
- while (!((c = getsc()) == 0
- || ((state == SBASE || state == SHEREDELIM)
- && ctype(c, C_LEX1))))
- {
+ while (!((c = getsc()) == 0 ||
+ ((state == SBASE || state == SHEREDELIM) && ctype(c, C_LEX1)))) {
Xcheck(ws, wp);
switch (state) {
- case SBASE:
- if (Flag(FCSHHISTORY) && (source->flags & SF_TTY) && c == '!') {
+ case SBASE:
+ if (Flag(FCSHHISTORY) && (source->flags & SF_TTY) &&
+ c == '!') {
char **replace = NULL;
c2 = getsc();
@@ -211,8 +210,7 @@ yylex(int cf)
Source *s;
/* do not strdup replacement via alloc */
- s = pushs(SREREAD,
- source->areap);
+ s = pushs(SREREAD, source->areap);
s->start = s->str = *replace;
s->next = source;
s->u.freeme = NULL;
@@ -223,8 +221,7 @@ yylex(int cf)
}
if (c == '[' && (cf & (VARASN|ARRAYVAR))) {
*wp = EOS; /* temporary */
- if (is_wdvarname(Xstring(ws, wp), false))
- {
+ if (is_wdvarname(Xstring(ws, wp), false)) {
char *p, *tmp;
if (arraysub(&tmp)) {
@@ -254,9 +251,8 @@ yylex(int cf)
}
/* fall through.. */
Sbase1: /* includes *(...|...) pattern (*+?@!) */
- if (c == '*' || c == '@' || c == '+' || c == '?'
- || c == '!')
- {
+ if (c == '*' || c == '@' || c == '+' || c == '?' ||
+ c == '!') {
c2 = getsc();
if (c2 == '(' /*)*/ ) {
*wp++ = OPAT;
@@ -269,35 +265,35 @@ yylex(int cf)
/* fall through.. */
Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */
switch (c) {
- case '\\':
+ case '\\':
c = getsc();
if (c) /* trailing \ is lost */
*wp++ = QCHAR, *wp++ = c;
break;
- case '\'':
+ case '\'':
*wp++ = OQUOTE;
ignore_backslash_newline++;
PUSH_STATE(SSQUOTE);
break;
- case '"':
+ case '"':
*wp++ = OQUOTE;
PUSH_STATE(SDQUOTE);
break;
- default:
+ default:
goto Subst;
}
break;
Subst:
switch (c) {
- case '\\':
+ case '\\':
c = getsc();
switch (c) {
- case '"': case '\\':
- case '$': case '`':
+ case '"': case '\\':
+ case '$': case '`':
*wp++ = QCHAR, *wp++ = c;
break;
- default:
+ default:
Xcheck(ws, wp);
if (c) { /* trailing \ is lost */
*wp++ = CHAR, *wp++ = '\\';
@@ -306,7 +302,7 @@ yylex(int cf)
break;
}
break;
- case '$':
+ case '$':
c = getsc();
if (c == '(') /*)*/ {
c = getsc();
@@ -314,7 +310,7 @@ yylex(int cf)
PUSH_STATE(SASPAREN);
statep->ls_sasparen.nparen = 2;
statep->ls_sasparen.start =
- Xsavepos(ws, wp);
+ Xsavepos(ws, wp);
*wp++ = EXPRSUB;
} else {
ungetsc(c);
@@ -368,7 +364,7 @@ yylex(int cf)
ungetsc(c);
}
break;
- case '`':
+ case '`':
PUSH_STATE(SBQUOTE);
*wp++ = COMSUB;
/* Need to know if we are inside double quotes
@@ -410,12 +406,12 @@ yylex(int cf)
}
}
break;
- default:
+ default:
*wp++ = CHAR, *wp++ = c;
}
break;
- case SSQUOTE:
+ case SSQUOTE:
if (c == '\'') {
POP_STATE();
*wp++ = CQUOTE;
@@ -424,7 +420,7 @@ yylex(int cf)
*wp++ = QCHAR, *wp++ = c;
break;
- case SDQUOTE:
+ case SDQUOTE:
if (c == '"') {
POP_STATE();
*wp++ = CQUOTE;
@@ -432,47 +428,47 @@ yylex(int cf)
goto Subst;
break;
- case SCSPAREN: /* $( .. ) */
+ case SCSPAREN: /* $( .. ) */
/* todo: deal with $(...) quoting properly
* kludge to partly fake quoting inside $(..): doesn't
* really work because nested $(..) or ${..} inside
* double quotes aren't dealt with.
*/
switch (statep->ls_scsparen.csstate) {
- case 0: /* normal */
+ case 0: /* normal */
switch (c) {
- case '(':
+ case '(':
statep->ls_scsparen.nparen++;
break;
- case ')':
+ case ')':
statep->ls_scsparen.nparen--;
break;
- case '\\':
+ case '\\':
statep->ls_scsparen.csstate = 1;
break;
- case '"':
+ case '"':
statep->ls_scsparen.csstate = 2;
break;
- case '\'':
+ case '\'':
statep->ls_scsparen.csstate = 4;
ignore_backslash_newline++;
break;
}
break;
- case 1: /* backslash in normal mode */
- case 3: /* backslash in double quotes */
+ case 1: /* backslash in normal mode */
+ case 3: /* backslash in double quotes */
--statep->ls_scsparen.csstate;
break;
- case 2: /* double quotes */
+ case 2: /* double quotes */
if (c == '"')
statep->ls_scsparen.csstate = 0;
else if (c == '\\')
statep->ls_scsparen.csstate = 3;
break;
- case 4: /* single quotes */
+ case 4: /* single quotes */
if (c == '\'') {
statep->ls_scsparen.csstate = 0;
ignore_backslash_newline--;
@@ -486,10 +482,10 @@ yylex(int cf)
*wp++ = c;
break;
- case SASPAREN: /* $(( .. )) */
+ case SASPAREN: /* $(( .. )) */
/* todo: deal with $((...); (...)) properly */
/* XXX should nest using existing state machine
- * (embed "..", $(...), etc.) */
+ * (embed "..", $(...), etc.) */
if (c == '(')
statep->ls_sasparen.nparen++;
else if (c == ')') {
@@ -509,22 +505,22 @@ yylex(int cf)
* parsing a $(..) expression
*/
s = Xrestpos(ws, wp,
- statep->ls_sasparen.start);
+ statep->ls_sasparen.start);
memmove(s + 1, s, wp - s);
*s++ = COMSUB;
*s = '('; /*)*/
wp++;
statep->ls_scsparen.nparen = 1;
statep->ls_scsparen.csstate = 0;
- state = statep->ls_state
- = SCSPAREN;
+ state = statep->ls_state =
+ SCSPAREN;
}
}
}
*wp++ = c;
break;
- case SBRACE:
+ case SBRACE:
/*{*/
if (c == '}') {
POP_STATE();
@@ -534,7 +530,7 @@ yylex(int cf)
goto Sbase1;
break;
- case STBRACE:
+ case STBRACE:
/* Same as SBRACE, except (,|,) treated specially */
/*{*/
if (c == '}') {
@@ -551,23 +547,23 @@ yylex(int cf)
goto Sbase1;
break;
- case SBQUOTE:
+ case SBQUOTE:
if (c == '`') {
*wp++ = 0;
POP_STATE();
} else if (c == '\\') {
switch (c = getsc()) {
- case '\\':
- case '$': case '`':
+ case '\\':
+ case '$': case '`':
*wp++ = c;
break;
- case '"':
+ case '"':
if (statep->ls_sbquote.indquotes) {
*wp++ = c;
break;
}
/* fall through.. */
- default:
+ default:
if (c) { /* trailing \ is lost */
*wp++ = '\\';
*wp++ = c;
@@ -578,10 +574,10 @@ yylex(int cf)
*wp++ = c;
break;
- case SWORD: /* ONEWORD */
+ case SWORD: /* ONEWORD */
goto Subst;
- case SLETPAREN: /* LETEXPR: (( ... )) */
+ case SLETPAREN: /* LETEXPR: (( ... )) */
/*(*/
if (c == ')') {
if (statep->ls_sletparen.nparen > 0)
@@ -601,7 +597,7 @@ yylex(int cf)
++statep->ls_sletparen.nparen;
goto Sbase2;
- case SHEREDELIM: /* <<,<<- delimiter */
+ case SHEREDELIM: /* <<,<<- delimiter */
/* XXX chuck this state (and the next) - use
* the existing states ($ and \`..` should be
* stripped of their specialness after the
@@ -629,17 +625,17 @@ yylex(int cf)
}
break;
- case SHEREDQUOTE: /* " in <<,<<- delimiter */
+ case SHEREDQUOTE: /* " in <<,<<- delimiter */
if (c == '"') {
*wp++ = CQUOTE;
state = statep->ls_state = SHEREDELIM;
} else {
if (c == '\\') {
switch (c = getsc()) {
- case '\\': case '"':
- case '$': case '`':
+ case '\\': case '"':
+ case '$': case '`':
break;
- default:
+ default:
if (c) { /* trailing \ lost */
*wp++ = CHAR;
*wp++ = '\\';
@@ -652,7 +648,7 @@ yylex(int cf)
}
break;
- case SPATTERN: /* in *(...|...) pattern (*+?@!) */
+ case SPATTERN: /* in *(...|...) pattern (*+?@!) */
if ( /*(*/ c == ')') {
*wp++ = CPAT;
POP_STATE();
@@ -678,12 +674,10 @@ Done:
state = SBASE;
dp = Xstring(ws, wp);
- if ((c == '<' || c == '>') && state == SBASE
- && ((c2 = Xlength(ws, wp)) == 0
- || (c2 == 2 && dp[0] == CHAR && digit(dp[1]))))
- {
- struct ioword *iop =
- (struct ioword *) alloc(sizeof(*iop), ATEMP);
+ if ((c == '<' || c == '>') && state == SBASE &&
+ ((c2 = Xlength(ws, wp)) == 0 ||
+ (c2 == 2 && dp[0] == CHAR && digit(dp[1])))) {
+ struct ioword *iop = (struct ioword *) alloc(sizeof(*iop), ATEMP);
if (c2 == 2)
iop->unit = dp[1] - '0';
@@ -694,7 +688,7 @@ Done:
/* <<, >>, <> are ok, >< is not */
if (c == c2 || (c == '<' && c2 == '>')) {
iop->flag = c == c2 ?
- (c == '>' ? IOCAT : IOHERE) : IORDWR;
+ (c == '>' ? IOCAT : IOHERE) : IORDWR;
if (iop->flag == IOHERE) {
if ((c2 = getsc()) == '-')
iop->flag |= IOSKIP;
@@ -723,12 +717,12 @@ Done:
Xfree(ws, wp); /* free word */
/* no word, process LEX1 character */
switch (c) {
- default:
+ default:
return c;
- case '|':
- case '&':
- case ';':
+ case '|':
+ case '&':
+ case ';':
if ((c2 = getsc()) == c)
c = (c == ';') ? BREAK :
(c == '|') ? LOGOR :
@@ -740,13 +734,13 @@ Done:
ungetsc(c2);
return c;
- case '\n':
+ case '\n':
gethere();
if (cf & CONTIN)
goto Again;
return c;
- case '(': /*)*/
+ case '(': /*)*/
if (!Flag(FSH)) {
if ((c2 = getsc()) == '(') /*)*/
/* XXX need to handle ((...); (...)) */
@@ -756,7 +750,7 @@ Done:
}
return c;
/*(*/
- case ')':
+ case ')':
return c;
}
}
@@ -780,15 +774,13 @@ Done:
int h = hash(ident);
/* { */
- if ((cf & KEYWORD) && (p = tsearch(&keywords, ident, h))
- && (!(cf & ESACONLY) || p->val.i == ESAC || p->val.i == '}'))
- {
+ if ((cf & KEYWORD) && (p = tsearch(&keywords, ident, h)) &&
+ (!(cf & ESACONLY) || p->val.i == ESAC || p->val.i == '}')) {
afree(yylval.cp, ATEMP);
return p->val.i;
}
- if ((cf & ALIAS) && (p = tsearch(&aliases, ident, h))
- && (p->flag & ISSET))
- {
+ if ((cf & ALIAS) && (p = tsearch(&aliases, ident, h)) &&
+ (p->flag & ISSET)) {
Source *s;
for (s = source; s->type == SALIAS; s = s->next)
@@ -933,27 +925,27 @@ getsc__(void)
while ((c = *s->str++) == 0) {
s->str = NULL; /* return 0 for EOF by default */
switch (s->type) {
- case SEOF:
+ case SEOF:
s->str = null;
return 0;
- case SSTDIN:
- case SFILE:
+ case SSTDIN:
+ case SFILE:
getsc_line(s);
break;
- case SWSTR:
+ case SWSTR:
break;
- case SSTRING:
+ case SSTRING:
break;
- case SWORDS:
+ case SWORDS:
s->start = s->str = *s->u.strv++;
s->type = SWORDSEP;
break;
- case SWORDSEP:
+ case SWORDSEP:
if (*s->u.strv == NULL) {
s->start = s->str = newline;
s->type = SEOF;
@@ -963,15 +955,14 @@ getsc__(void)
}
break;
- case SALIAS:
+ case SALIAS:
if (s->flags & SF_ALIASEND) {
/* pass on an unused SF_ALIAS flag */
source = s->next;
source->flags |= s->flags & SF_ALIAS;
s = source;
- } else if (*s->u.tblp->val.s
- && isspace(strchr(s->u.tblp->val.s, 0)[-1]))
- {
+ } else if (*s->u.tblp->val.s &&
+ isspace(strchr(s->u.tblp->val.s, 0)[-1])) {
source = s = s->next; /* pop source stack */
/* Note that this alias ended with a space,
* enabling alias expansion on the following
@@ -1006,7 +997,7 @@ getsc__(void)
}
continue;
- case SREREAD:
+ case SREREAD:
if (s->start != s->ugbuf) /* yuck */
afree(s->u.freeme, ATEMP);
source = s = s->next;
@@ -1044,13 +1035,12 @@ getsc_line(Source *s)
#ifdef EDIT
if (have_tty && (0
# ifdef VI
- || Flag(FVI)
+ || Flag(FVI)
# endif /* VI */
# ifdef EMACS
- || Flag(FEMACS) || Flag(FGMACS)
+ || Flag(FEMACS) || Flag(FGMACS)
# endif /* EMACS */
- ))
- {
+ )) {
int nread;
nread = x_read(xp, LINE);
@@ -1070,9 +1060,8 @@ getsc_line(Source *s)
while (1) {
char *p = shf_getse(xp, Xnleft(s->xs, xp), s->u.shf);
- if (!p && shf_error(s->u.shf)
- && shf_errno(s->u.shf) == EINTR)
- {
+ if (!p && shf_error(s->u.shf) &&
+ shf_errno(s->u.shf) == EINTR) {
shf_clearerr(s->u.shf);
if (trap)
runtraps(0);
@@ -1148,7 +1137,7 @@ set_prompt(int to, Source *s)
*/
} else
prompt = str_save(substitute(ps1, 0),
- saved_atemp);
+ saved_atemp);
quitenv(NULL);
break;
case PS2: /* command continuation */
@@ -1449,13 +1438,13 @@ get_brace_var(XString *wsp, char *wp)
c = getsc();
/* State machine to figure out where the variable part ends. */
switch (state) {
- case PS_INITIAL:
+ case PS_INITIAL:
if (c == '#') {
state = PS_SAW_HASH;
break;
}
/* fall through.. */
- case PS_SAW_HASH:
+ case PS_SAW_HASH:
if (letter(c))
state = PS_IDENT;
else if (digit(c))
@@ -1465,7 +1454,7 @@ get_brace_var(XString *wsp, char *wp)
else
state = PS_END;
break;
- case PS_IDENT:
+ case PS_IDENT:
if (!letnum(c)) {
state = PS_END;
if (c == '[') {
@@ -1483,14 +1472,14 @@ get_brace_var(XString *wsp, char *wp)
}
}
break;
- case PS_NUMBER:
+ case PS_NUMBER:
if (!digit(c))
state = PS_END;
break;
- case PS_VAR1:
+ case PS_VAR1:
state = PS_END;
break;
- case PS_END: /* keep gcc happy */
+ case PS_END: /* keep gcc happy */
break;
}
if (state == PS_END) {
diff --git a/bin/ksh/mail.c b/bin/ksh/mail.c
index a65fe543238..9f6c1eda45c 100644
--- a/bin/ksh/mail.c
+++ b/bin/ksh/mail.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mail.c,v 1.14 2004/12/22 17:14:34 millert Exp $ */
+/* $OpenBSD: mail.c,v 1.15 2005/03/30 17:16:37 deraadt Exp $ */
/*
* Mailbox checking code by Robert J. Gibson, adapted for PD ksh by
@@ -57,12 +57,11 @@ mcheck(void)
mbp = NULL;
while (mbp) {
- if (mbp->mb_path && stat(mbp->mb_path, &stbuf) == 0
- && S_ISREG(stbuf.st_mode))
- {
- if (stbuf.st_size
- && mbp->mb_mtime != stbuf.st_mtime
- && stbuf.st_atime <= stbuf.st_mtime)
+ if (mbp->mb_path && stat(mbp->mb_path, &stbuf) == 0 &&
+ S_ISREG(stbuf.st_mode)) {
+ if (stbuf.st_size &&
+ mbp->mb_mtime != stbuf.st_mtime &&
+ stbuf.st_atime <= stbuf.st_mtime)
mprintit(mbp);
mbp->mb_mtime = stbuf.st_mtime;
} else {
@@ -116,7 +115,8 @@ mpset(char *mptoparse)
while (mval) {
mpath = mval;
if ((mval = strchr(mval, ':')) != NULL) {
- *mval = '\0', mval++;
+ *mval = '\0';
+ mval++;
}
/* POSIX/bourne-shell say file%message */
for (p = mpath; (mmsg = strchr(p, '%')); ) {
diff --git a/bin/ksh/main.c b/bin/ksh/main.c
index f4f97516916..e8ef8228942 100644
--- a/bin/ksh/main.c
+++ b/bin/ksh/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.37 2005/03/28 21:33:01 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
/*
* startup, main loop, environments and error handling
@@ -175,8 +175,8 @@ main(int argc, char *argv[])
#endif /* POSIXLY_CORRECT */
/* Check to see if we're /bin/sh. */
- if (!strcmp(&kshname[strlen(kshname) - 3], "/sh")
- || !strcmp(kshname, "sh") || !strcmp(kshname, "-sh")) {
+ if (!strcmp(&kshname[strlen(kshname) - 3], "/sh") ||
+ !strcmp(kshname, "sh") || !strcmp(kshname, "-sh")) {
Flag(FSH) = 1;
version_param = "SH_VERSION";
}
@@ -210,10 +210,10 @@ main(int argc, char *argv[])
char *pwdx = pwd;
/* Try to use existing $PWD if it is valid */
- if (pwd[0] != '/'
- || stat(pwd, &s_pwd) < 0 || stat(".", &s_dot) < 0
- || s_pwd.st_dev != s_dot.st_dev
- || s_pwd.st_ino != s_dot.st_ino)
+ if (pwd[0] != '/' ||
+ stat(pwd, &s_pwd) < 0 || stat(".", &s_dot) < 0 ||
+ s_pwd.st_dev != s_dot.st_dev ||
+ s_pwd.st_ino != s_dot.st_ino)
pwdx = (char *) 0;
set_current_wd(pwdx);
if (current_wd[0])
@@ -247,8 +247,8 @@ main(int argc, char *argv[])
/* Set PS1 if it isn't set, or we are root and prompt doesn't
* contain a #.
*/
- if (!(vp->flag & ISSET)
- || (!ksheuid && !strchr(str_val(vp), '#')))
+ if (!(vp->flag & ISSET) ||
+ (!ksheuid && !strchr(str_val(vp), '#')))
/* setstr can't fail here */
setstr(vp, safe_prompt, KSH_RETURN_ERROR);
}
@@ -282,7 +282,7 @@ main(int argc, char *argv[])
s = pushs(SSTDIN, ATEMP);
s->file = "<stdin>";
s->u.shf = shf_fdopen(0, SHF_RD | can_seek(0),
- (struct shf *) 0);
+ (struct shf *) 0);
if (isatty(0) && isatty(2)) {
Flag(FTALKING) = Flag(FTALKING_I) = 1;
/* The following only if isatty(0) */
@@ -333,7 +333,7 @@ main(int argc, char *argv[])
include(KSH_SYSTEM_PROFILE, 0, (char **) 0, 1);
if (!Flag(FPRIVILEGED))
include(substitute("$HOME/.profile", 0), 0,
- (char **) 0, 1);
+ (char **) 0, 1);
}
if (Flag(FPRIVILEGED))
@@ -341,8 +341,8 @@ main(int argc, char *argv[])
else {
char *env_file;
- /* include $ENV */
- env_file = str_val(global("ENV"));
+ /* include $ENV */
+ env_file = str_val(global("ENV"));
#ifdef DEFAULT_ENV
/* If env isn't set, include default environment */
@@ -358,10 +358,10 @@ main(int argc, char *argv[])
restricted = 1;
if (restricted) {
static const char *const restr_com[] = {
- "typeset", "-r", "PATH",
- "ENV", "SHELL",
- (char *) 0
- };
+ "typeset", "-r", "PATH",
+ "ENV", "SHELL",
+ (char *) 0
+ };
shcomexec((char **) restr_com);
/* After typeset command... */
Flag(FRESTRICTED) = 1;
@@ -422,22 +422,22 @@ include(const char *name, int argc, char **argv, int intr_ok)
e->loc->argc = old_argc;
}
switch (i) {
- case LRETURN:
- case LERROR:
+ case LRETURN:
+ case LERROR:
return exstat & 0xff; /* see below */
- case LINTR:
+ case LINTR:
/* intr_ok is set if we are including .profile or $ENV.
* If user ^C's out, we don't want to kill the shell...
*/
if (intr_ok && (exstat - 128) != SIGTERM)
return 1;
/* fall through... */
- case LEXIT:
- case LLEAVE:
- case LSHELL:
+ case LEXIT:
+ case LLEAVE:
+ case LSHELL:
unwind(i);
/*NOREACHED*/
- default:
+ default:
internal_errorf(1, "include: %d", i);
/*NOREACHED*/
}
@@ -487,17 +487,17 @@ shell(Source *volatile s, volatile int toplevel)
i = sigsetjmp(e->jbuf, 0);
if (i) {
switch (i) {
- case LINTR: /* we get here if SIGINT not caught or ignored */
- case LERROR:
- case LSHELL:
+ case LINTR: /* we get here if SIGINT not caught or ignored */
+ case LERROR:
+ case LSHELL:
if (interactive) {
if (i == LINTR)
shellf(newline);
/* Reset any eof that was read as part of a
* multiline command.
*/
- if (Flag(FIGNOREEOF) && s->type == SEOF
- && wastty)
+ if (Flag(FIGNOREEOF) && s->type == SEOF &&
+ wastty)
s->type = SSTDIN;
/* Used by exit command to get back to
* top level shell. Kind of strange since
@@ -510,14 +510,14 @@ shell(Source *volatile s, volatile int toplevel)
break;
}
/* fall through... */
- case LEXIT:
- case LLEAVE:
- case LRETURN:
+ case LEXIT:
+ case LLEAVE:
+ case LRETURN:
source = old_source;
quitenv(NULL);
unwind(i); /* keep on going */
/*NOREACHED*/
- default:
+ default:
source = old_source;
quitenv(NULL);
internal_errorf(1, "shell: %d", i);
@@ -547,9 +547,8 @@ shell(Source *volatile s, volatile int toplevel)
if (wastty && Flag(FIGNOREEOF) && --attempts > 0) {
shellf("Use `exit' to leave ksh\n");
s->type = SSTDIN;
- } else if (wastty && !really_exit
- && j_stopped_running())
- {
+ } else if (wastty && !really_exit &&
+ j_stopped_running()) {
really_exit = 1;
s->type = SSTDIN;
} else {
@@ -582,9 +581,8 @@ void
unwind(int i)
{
/* ordering for EXIT vs ERR is a bit odd (this is what at&t ksh does) */
- if (i == LEXIT || (Flag(FERREXIT) && (i == LERROR || i == LINTR)
- && sigtraps[SIGEXIT_].trap))
- {
+ if (i == LEXIT || (Flag(FERREXIT) && (i == LERROR || i == LINTR) &&
+ sigtraps[SIGEXIT_].trap)) {
runtrap(&sigtraps[SIGEXIT_]);
i = LLEAVE;
} else if (Flag(FERREXIT) && (i == LERROR || i == LINTR)) {
@@ -593,20 +591,20 @@ unwind(int i)
}
while (1) {
switch (e->type) {
- case E_PARSE:
- case E_FUNC:
- case E_INCL:
- case E_LOOP:
- case E_ERRH:
+ case E_PARSE:
+ case E_FUNC:
+ case E_INCL:
+ case E_LOOP:
+ case E_ERRH:
siglongjmp(e->jbuf, i);
/*NOTREACHED*/
- case E_NONE:
+ case E_NONE:
if (i == LINTR)
e->flags |= EF_FAKE_SIGDIE;
/* Fall through... */
- default:
+ default:
quitenv(NULL);
}
}
@@ -664,7 +662,7 @@ quitenv(struct shf *shf)
if ((sig == SIGINT || sig == SIGTERM) &&
getpgrp() == kshpid) {
setsig(&sigtraps[sig], SIG_DFL,
- SS_RESTORE_CURR|SS_FORCE);
+ SS_RESTORE_CURR|SS_FORCE);
kill(0, sig);
}
}
diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c
index 5987fcacfd7..c1a36b08572 100644
--- a/bin/ksh/misc.c
+++ b/bin/ksh/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.27 2005/03/28 21:28:22 deraadt Exp $ */
+/* $OpenBSD: misc.c,v 1.28 2005/03/30 17:16:37 deraadt Exp $ */
/*
* Miscellaneous functions
@@ -203,8 +203,8 @@ options_fmt_entry(void *arg, int i, char *buf, int buflen)
struct options_info *oi = (struct options_info *) arg;
shf_snprintf(buf, buflen, "%-*s %s",
- oi->opt_width, oi->opts[i].name,
- Flag(oi->opts[i].flag) ? "on" : "off");
+ oi->opt_width, oi->opts[i].name,
+ Flag(oi->opts[i].flag) ? "on" : "off");
return buf;
}
@@ -229,7 +229,7 @@ printoptions(int verbose)
oi.opt_width = len;
}
print_columns(shl_stdout, n, options_fmt_entry, &oi,
- oi.opt_width + 5, 1);
+ oi.opt_width + 5, 1);
} else {
/* short version ala ksh93 */
shprintf("set");
@@ -352,9 +352,8 @@ parse_args(char **argv,
/* Set FLOGIN before parsing options so user can clear
* flag using +l.
*/
- Flag(FLOGIN) = (argv[0][0] == '-'
- || ((p = strrchr(argv[0], '/'))
- && *++p == '-'));
+ Flag(FLOGIN) = (argv[0][0] == '-' ||
+ ((p = strrchr(argv[0], '/')) && *++p == '-'));
opts = cmd_opts;
} else
opts = set_opts;
@@ -362,12 +361,12 @@ parse_args(char **argv,
while ((optc = ksh_getopt(argv, &go, opts)) != EOF) {
set = (go.info & GI_PLUS) ? 0 : 1;
switch (optc) {
- case 'A':
+ case 'A':
arrayset = set ? 1 : -1;
array = go.optarg;
break;
- case 'o':
+ case 'o':
if (go.optarg == (char *) 0) {
/* lone -o: print options
*
@@ -394,21 +393,20 @@ parse_args(char **argv,
}
break;
- case '?':
+ case '?':
return -1;
- default:
+ default:
/* -s: sort positional params (at&t ksh stupidity) */
if (what == OF_SET && optc == 's') {
sortargs = 1;
break;
}
for (i = 0; i < NELEM(options); i++)
- if (optc == options[i].c
- && (what & options[i].flags))
- {
+ if (optc == options[i].c &&
+ (what & options[i].flags)) {
change_flag((enum sh_flag) i, what,
- set);
+ set);
break;
}
if (i == NELEM(options)) {
@@ -417,10 +415,9 @@ parse_args(char **argv,
}
}
}
- if (!(go.info & GI_MINUSMINUS) && argv[go.optind]
- && (argv[go.optind][0] == '-' || argv[go.optind][0] == '+')
- && argv[go.optind][1] == '\0')
- {
+ if (!(go.info & GI_MINUSMINUS) && argv[go.optind] &&
+ (argv[go.optind][0] == '-' || argv[go.optind][0] == '+') &&
+ argv[go.optind][1] == '\0') {
/* lone - clears -v and -x flags */
if (argv[go.optind][0] == '-' && !Flag(FPOSIX))
Flag(FVERBOSE) = Flag(FXTRACE) = 0;
@@ -429,8 +426,8 @@ parse_args(char **argv,
}
if (setargsp)
/* -- means set $#/$* even if there are no arguments */
- *setargsp = !arrayset && ((go.info & GI_MINUSMINUS)
- || argv[go.optind]);
+ *setargsp = !arrayset && ((go.info & GI_MINUSMINUS) ||
+ argv[go.optind]);
if (arrayset && (!*array || *skip_varname(array, false))) {
bi_errorf("%s: is not an identifier", array);
@@ -440,7 +437,7 @@ parse_args(char **argv,
for (i = go.optind; argv[i]; i++)
;
qsortp((void **) &argv[go.optind], (size_t) (i - go.optind),
- xstrcmp);
+ xstrcmp);
}
if (arrayset) {
set_array(array, arrayset, argv + go.optind);
@@ -503,13 +500,13 @@ gmatch(const char *s, const char *p, int isfile)
if (!isfile && !has_globbing(p, pe)) {
int len = pe - p + 1;
char tbuf[64];
- char *t = len <= sizeof(tbuf) ? tbuf
- : (char *) alloc(len, ATEMP);
+ char *t = len <= sizeof(tbuf) ? tbuf :
+ (char *) alloc(len, ATEMP);
debunk(t, p, len);
return !strcmp(t, s);
}
return do_gmatch((const unsigned char *) s, (const unsigned char *) se,
- (const unsigned char *) p, (const unsigned char *) pe);
+ (const unsigned char *) p, (const unsigned char *) pe);
}
/* Returns if p is a syntacticly correct globbing pattern, false
@@ -602,17 +599,17 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
continue;
}
switch (*p++) {
- case '[':
+ case '[':
if (sc == 0 || (p = cclass(p, sc)) == NULL)
return 0;
break;
- case '?':
+ case '?':
if (sc == 0)
return 0;
break;
- case '*':
+ case '*':
if (p == pe)
return 1;
s--;
@@ -627,25 +624,22 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
*
* Not ifdef'd KSH as this is needed for ${..%..}, etc.
*/
- case 0x80|'+': /* matches one or more times */
- case 0x80|'*': /* matches zero or more times */
+ case 0x80|'+': /* matches one or more times */
+ case 0x80|'*': /* matches zero or more times */
if (!(prest = pat_scan(p, pe, 0)))
return 0;
s--;
/* take care of zero matches */
- if (p[-1] == (0x80 | '*')
- && do_gmatch(s, se, prest, pe))
+ if (p[-1] == (0x80 | '*') &&
+ do_gmatch(s, se, prest, pe))
return 1;
for (psub = p; ; psub = pnext) {
pnext = pat_scan(psub, pe, 1);
for (srest = s; srest <= se; srest++) {
- if (do_gmatch(s, srest,
- psub, pnext - 2)
- && (do_gmatch(srest, se,
- prest, pe)
- || (s != srest
- && do_gmatch(srest, se,
- p - 2, pe))))
+ if (do_gmatch(s, srest, psub, pnext - 2) &&
+ (do_gmatch(srest, se, prest, pe) ||
+ (s != srest && do_gmatch(srest,
+ se, p - 2, pe))))
return 1;
}
if (pnext == prest)
@@ -653,24 +647,22 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
}
return 0;
- case 0x80|'?': /* matches zero or once */
- case 0x80|'@': /* matches one of the patterns */
- case 0x80|' ': /* simile for @ */
+ case 0x80|'?': /* matches zero or once */
+ case 0x80|'@': /* matches one of the patterns */
+ case 0x80|' ': /* simile for @ */
if (!(prest = pat_scan(p, pe, 0)))
return 0;
s--;
/* Take care of zero matches */
- if (p[-1] == (0x80 | '?')
- && do_gmatch(s, se, prest, pe))
+ if (p[-1] == (0x80 | '?') &&
+ do_gmatch(s, se, prest, pe))
return 1;
for (psub = p; ; psub = pnext) {
pnext = pat_scan(psub, pe, 1);
srest = prest == pe ? se : s;
for (; srest <= se; srest++) {
- if (do_gmatch(s, srest,
- psub, pnext - 2)
- && do_gmatch(srest, se,
- prest, pe))
+ if (do_gmatch(s, srest, psub, pnext - 2) &&
+ do_gmatch(srest, se, prest, pe))
return 1;
}
if (pnext == prest)
@@ -678,7 +670,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
}
return 0;
- case 0x80|'!': /* matches none of the patterns */
+ case 0x80|'!': /* matches none of the patterns */
if (!(prest = pat_scan(p, pe, 0)))
return 0;
s--;
@@ -687,22 +679,21 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
for (psub = p; ; psub = pnext) {
pnext = pat_scan(psub, pe, 1);
- if (do_gmatch(s, srest,
- psub, pnext - 2))
- {
+ if (do_gmatch(s, srest, psub,
+ pnext - 2)) {
matched = 1;
break;
}
if (pnext == prest)
break;
}
- if (!matched && do_gmatch(srest, se,
- prest, pe))
+ if (!matched &&
+ do_gmatch(srest, se, prest, pe))
return 1;
}
return 0;
- default:
+ default:
if (sc != p[-1])
return 0;
break;
@@ -733,9 +724,8 @@ cclass(const unsigned char *p, int sub)
if (c == '\0')
/* No closing ] - act as if the opening [ was quoted */
return sub == '[' ? orig_p : NULL;
- if (ISMAGIC(p[0]) && p[1] == '-'
- && (!ISMAGIC(p[2]) || p[3] != ']'))
- {
+ if (ISMAGIC(p[0]) && p[1] == '-' &&
+ (!ISMAGIC(p[2]) || p[3] != ']')) {
p += 2; /* MAGIC- */
d = *p++;
if (ISMAGIC(d)) {
@@ -764,8 +754,8 @@ pat_scan(const unsigned char *p, const unsigned char *pe, int match_sep)
for (; p < pe; p++) {
if (!ISMAGIC(*p))
continue;
- if ((*++p == /*(*/ ')' && nest-- == 0)
- || (*p == '|' && match_sep && nest == 0))
+ if ((*++p == /*(*/ ')' && nest-- == 0) ||
+ (*p == '|' && match_sep && nest == 0))
return ++p;
if ((*p & 0x80) && strchr("*+?@! ", *p & 0x7f))
nest++;
@@ -924,11 +914,10 @@ ksh_getopt(char **argv, Getopt *go, const char *options)
go->info |= GI_MINUSMINUS;
return EOF;
}
- if (arg == (char *) 0
- || ((flag != '-' ) /* neither a - nor a + (if + allowed) */
- && (!(go->flags & GF_PLUSOPT) || flag != '+'))
- || (c = arg[1]) == '\0')
- {
+ if (arg == (char *) 0 ||
+ ((flag != '-' ) && /* neither a - nor a + (if + allowed) */
+ (!(go->flags & GF_PLUSOPT) || flag != '+')) ||
+ (c = arg[1]) == '\0') {
go->p = 0;
return EOF;
}
@@ -937,16 +926,15 @@ ksh_getopt(char **argv, Getopt *go, const char *options)
go->info |= flag == '-' ? GI_MINUS : GI_PLUS;
}
go->p++;
- if (c == '?' || c == ':' || c == ';' || c == ',' || c == '#'
- || !(o = strchr(options, c)))
- {
+ if (c == '?' || c == ':' || c == ';' || c == ',' || c == '#' ||
+ !(o = strchr(options, c))) {
if (options[0] == ':') {
go->buf[0] = c;
go->optarg = go->buf;
} else {
warningf(true, "%s%s-%c: unknown option",
- (go->flags & GF_NONAME) ? "" : argv[0],
- (go->flags & GF_NONAME) ? "" : ": ", c);
+ (go->flags & GF_NONAME) ? "" : argv[0],
+ (go->flags & GF_NONAME) ? "" : ": ", c);
if (go->flags & GF_ERROR)
bi_errorf(null);
}
@@ -971,8 +959,8 @@ ksh_getopt(char **argv, Getopt *go, const char *options)
return ':';
}
warningf(true, "%s%s-`%c' requires argument",
- (go->flags & GF_NONAME) ? "" : argv[0],
- (go->flags & GF_NONAME) ? "" : ": ", c);
+ (go->flags & GF_NONAME) ? "" : argv[0],
+ (go->flags & GF_NONAME) ? "" : ": ", c);
if (go->flags & GF_ERROR)
bi_errorf(null);
return '?';
@@ -1076,8 +1064,8 @@ print_columns(struct shf *shf, int n, char *(*func) (void *, int, char *, int),
i = c * rows + r;
if (i < n) {
shf_fprintf(shf, "%-*s",
- max_width,
- (*func)(arg, i, str, max_width + 1));
+ max_width,
+ (*func)(arg, i, str, max_width + 1));
if (c + 1 < cols)
shf_fprintf(shf, "%*s", nspace, null);
}
diff --git a/bin/ksh/path.c b/bin/ksh/path.c
index 46bfd388749..f20823faab4 100644
--- a/bin/ksh/path.c
+++ b/bin/ksh/path.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: path.c,v 1.11 2004/12/20 11:34:26 otto Exp $ */
+/* $OpenBSD: path.c,v 1.12 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h"
#include <sys/stat.h>
@@ -70,9 +70,8 @@ make_path(const char *cwd, const char *file,
*cdpathp = *pend ? ++pend : (char *) 0;
}
- if ((use_cdpath == 0 || !plen || plist[0] != '/')
- && (cwd && *cwd))
- {
+ if ((use_cdpath == 0 || !plen || plist[0] != '/') &&
+ (cwd && *cwd)) {
len = strlen(cwd);
XcheckN(*xsp, xp, len);
memcpy(xp, cwd, len);
@@ -253,8 +252,8 @@ do_phys_path(XString *xsp, char *xp, const char *path)
lbuf[llen] = '\0';
/* If absolute path, start from scratch.. */
- xp = lbuf[0] == '/' ? Xstring(*xsp, xp)
- : Xrestpos(*xsp, xp, savepos);
+ xp = lbuf[0] == '/' ? Xstring(*xsp, xp) :
+ Xrestpos(*xsp, xp, savepos);
if (!(xp = do_phys_path(xsp, xp, lbuf)))
return (char *) 0;
}
diff --git a/bin/ksh/shf.c b/bin/ksh/shf.c
index 706ede99f05..ef503f1abbb 100644
--- a/bin/ksh/shf.c
+++ b/bin/ksh/shf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: shf.c,v 1.12 2005/03/28 21:28:22 deraadt Exp $ */
+/* $OpenBSD: shf.c,v 1.13 2005/03/30 17:16:37 deraadt Exp $ */
/*
* Shell file I/O routines
@@ -58,9 +58,8 @@ shf_open(const char *name, int oflags, int mode, int sflags)
fd = nfd;
}
sflags &= ~SHF_ACCMODE;
- sflags |= (oflags & O_ACCMODE) == O_RDONLY ? SHF_RD
- : ((oflags & O_ACCMODE) == O_WRONLY ? SHF_WR
- : SHF_RDWR);
+ sflags |= (oflags & O_ACCMODE) == O_RDONLY ? SHF_RD :
+ ((oflags & O_ACCMODE) == O_WRONLY ? SHF_WR : SHF_RDWR);
return shf_reopen(fd, sflags, shf);
}
@@ -78,12 +77,19 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
if (flags < 0)
/* will get an error on first read/write */
sflags |= SHF_RDWR;
- else
+ else {
switch (flags & O_ACCMODE) {
- case O_RDONLY: sflags |= SHF_RD; break;
- case O_WRONLY: sflags |= SHF_WR; break;
- case O_RDWR: sflags |= SHF_RDWR; break;
+ case O_RDONLY:
+ sflags |= SHF_RD;
+ break;
+ case O_WRONLY:
+ sflags |= SHF_WR;
+ break;
+ case O_RDWR:
+ sflags |= SHF_RDWR;
+ break;
}
+ }
}
if (!(sflags & (SHF_RD | SHF_WR)))
@@ -128,12 +134,19 @@ shf_reopen(int fd, int sflags, struct shf *shf)
if (flags < 0)
/* will get an error on first read/write */
sflags |= SHF_RDWR;
- else
+ else {
switch (flags & O_ACCMODE) {
- case O_RDONLY: sflags |= SHF_RD; break;
- case O_WRONLY: sflags |= SHF_WR; break;
- case O_RDWR: sflags |= SHF_RDWR; break;
+ case O_RDONLY:
+ sflags |= SHF_RD;
+ break;
+ case O_WRONLY:
+ sflags |= SHF_WR;
+ break;
+ case O_RDWR:
+ sflags |= SHF_RDWR;
+ break;
}
+ }
}
if (!(sflags & (SHF_RD | SHF_WR)))
@@ -167,8 +180,8 @@ struct shf *
shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
{
/* can't have a read+write string */
- if (!(sflags & (SHF_RD | SHF_WR))
- || (sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR))
+ if (!(sflags & (SHF_RD | SHF_WR)) ||
+ (sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR))
internal_errorf(1, "shf_sopen: flags 0x%x", sflags);
if (!shf) {
@@ -327,12 +340,12 @@ shf_emptybuf(struct shf *shf, int flags)
/* Note that we assume SHF_ALLOCS is not set if SHF_ALLOCB
* is set... (changing the shf pointer could cause problems)
*/
- if (!(flags & EB_GROW) || !(shf->flags & SHF_DYNAMIC)
- || !(shf->flags & SHF_ALLOCB))
+ if (!(flags & EB_GROW) || !(shf->flags & SHF_DYNAMIC) ||
+ !(shf->flags & SHF_ALLOCB))
return EOF;
/* allocate more space for buffer */
nbuf = (unsigned char *) aresize(shf->buf, shf->wbsize * 2,
- shf->areap);
+ shf->areap);
shf->rp = nbuf + (shf->rp - shf->buf);
shf->wp = nbuf + (shf->wp - shf->buf);
shf->rbsize += shf->wbsize;
@@ -348,8 +361,8 @@ shf_emptybuf(struct shf *shf, int flags)
while (ntowrite > 0) {
n = write(shf->fd, buf, ntowrite);
if (n < 0) {
- if (errno == EINTR
- && !(shf->flags & SHF_INTERRUPT))
+ if (errno == EINTR &&
+ !(shf->flags & SHF_INTERRUPT))
continue;
shf->flags |= SHF_ERROR;
shf->errno_ = errno;
@@ -358,7 +371,7 @@ shf_emptybuf(struct shf *shf, int flags)
/* allow a second flush
* to work */
memmove(shf->buf, buf,
- ntowrite);
+ ntowrite);
shf->wp = shf->buf + ntowrite;
}
return EOF;
@@ -405,9 +418,9 @@ shf_fillbuf(struct shf *shf)
shf->rp = shf->buf;
while (1) {
shf->rnleft = blocking_read(shf->fd, (char *) shf->buf,
- shf->rbsize);
- if (shf->rnleft < 0 && errno == EINTR
- && !(shf->flags & SHF_INTERRUPT))
+ shf->rbsize);
+ if (shf->rnleft < 0 && errno == EINTR &&
+ !(shf->flags & SHF_INTERRUPT))
continue;
break;
}
@@ -446,9 +459,8 @@ shf_seek(struct shf *shf, off_t where, int from)
if (shf->flags & SHF_READING) {
if (from == SEEK_CUR &&
- (where < 0 ?
- -where >= shf->rbsize - shf->rnleft :
- where < shf->rnleft)) {
+ (where < 0 ? -where >= shf->rbsize - shf->rnleft :
+ where < shf->rnleft)) {
shf->rnleft -= where;
shf->rp += where;
return 0;
@@ -486,8 +498,8 @@ shf_read(char *buf, int bsize, struct shf *shf)
internal_errorf(1, "shf_read: bsize %d", bsize);
while (bsize > 0) {
- if (shf->rnleft == 0
- && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
+ if (shf->rnleft == 0 &&
+ (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
break;
ncopy = shf->rnleft;
if (ncopy > bsize)
@@ -499,8 +511,8 @@ shf_read(char *buf, int bsize, struct shf *shf)
shf->rnleft -= ncopy;
}
/* Note: fread(3S) returns 0 for errors - this doesn't */
- return orig_bsize == bsize ? (shf_error(shf) ? EOF : 0)
- : orig_bsize - bsize;
+ return orig_bsize == bsize ? (shf_error(shf) ? EOF : 0) :
+ orig_bsize - bsize;
}
/* Read up to a newline or EOF. The newline is put in buf; buf is always
@@ -531,7 +543,7 @@ shf_getse(char *buf, int bsize, struct shf *shf)
}
}
end = (unsigned char *) memchr((char *) shf->rp, '\n',
- shf->rnleft);
+ shf->rnleft);
ncopy = end ? end - shf->rp + 1 : shf->rnleft;
if (ncopy > bsize)
ncopy = bsize;
@@ -567,8 +579,8 @@ shf_ungetc(int c, struct shf *shf)
if (!(shf->flags & SHF_RD))
internal_errorf(1, "shf_ungetc: flags %x", shf->flags);
- if ((shf->flags & SHF_ERROR) || c == EOF
- || (shf->rp == shf->buf && shf->rnleft))
+ if ((shf->flags & SHF_ERROR) || c == EOF ||
+ (shf->rp == shf->buf && shf->rnleft))
return EOF;
if ((shf->flags & SHF_WRITING) && shf_emptybuf(shf, EB_READSW) == EOF)
@@ -617,8 +629,8 @@ shf_putchar(int c, struct shf *shf)
}
while ((n = write(shf->fd, &cc, 1)) != 1)
if (n < 0) {
- if (errno == EINTR
- && !(shf->flags & SHF_INTERRUPT))
+ if (errno == EINTR &&
+ !(shf->flags & SHF_INTERRUPT))
continue;
shf->flags |= SHF_ERROR;
shf->errno_ = errno;
@@ -662,9 +674,8 @@ shf_write(const char *buf, int nbytes, struct shf *shf)
internal_errorf(1, "shf_write: nbytes %d", nbytes);
/* Don't buffer if buffer is empty and we're writting a large amount. */
- if ((ncopy = shf->wnleft)
- && (shf->wp != shf->buf || nbytes < shf->wnleft))
- {
+ if ((ncopy = shf->wnleft) &&
+ (shf->wp != shf->buf || nbytes < shf->wnleft)) {
if (ncopy > nbytes)
ncopy = nbytes;
memcpy(shf->wp, buf, ncopy);
@@ -685,8 +696,8 @@ shf_write(const char *buf, int nbytes, struct shf *shf)
while (ncopy > 0) {
n = write(shf->fd, buf, ncopy);
if (n < 0) {
- if (errno == EINTR
- && !(shf->flags & SHF_INTERRUPT))
+ if (errno == EINTR &&
+ !(shf->flags & SHF_INTERRUPT))
continue;
shf->flags |= SHF_ERROR;
shf->errno_ = errno;
@@ -772,16 +783,11 @@ shf_smprintf(const char *fmt, ...)
* machines it don't matter. Assumes C compiler has converted shorts to
* ints before pushing them.
*/
-#define POP_INT(f, s, a) (((f) & FL_LONG) ? \
- va_arg((a), unsigned long) \
- : \
- (sizeof(int) < sizeof(long) ? \
- ((s) ? \
- (long) va_arg((a), int) \
- : \
- va_arg((a), unsigned)) \
- : \
- va_arg((a), unsigned)))
+#define POP_INT(f, s, a) \
+ (((f) & FL_LONG) ? va_arg((a), unsigned long) : \
+ (sizeof(int) < sizeof(long) ? ((s) ? \
+ (long) va_arg((a), int) : va_arg((a), unsigned)) : \
+ va_arg((a), unsigned)))
#define ABIGNUM 32000 /* big numer that will fit in a short */
#define LOG2_10 3.321928094887362347870319429 /* log base 2 of 10 */
@@ -978,8 +984,8 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
case 'x':
{
const char *digits = (flags & FL_UPPER) ?
- "0123456789ABCDEF"
- : "0123456789abcdef";
+ "0123456789ABCDEF" :
+ "0123456789abcdef";
do {
*--s = digits[lnum & 0xf];
lnum >>= 4;
@@ -1061,12 +1067,8 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
/* Overflow check - should
* never have this problem.
*/
- if (decpt >
- &fpbuf[sizeof(fpbuf)]
- - s - 8)
- decpt =
- &fpbuf[sizeof(fpbuf)]
- - s - 8;
+ if (decpt > &fpbuf[sizeof(fpbuf)] - s - 8)
+ decpt = &fpbuf[sizeof(fpbuf)] - s - 8;
(void) memcpy(s, p, decpt);
s += decpt;
p += decpt;
@@ -1080,11 +1082,8 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
/* Overflow check - should
* never have this problem.
*/
- if (precision > &fpbuf[sizeof(fpbuf)]
- - s - 7)
- precision =
- &fpbuf[sizeof(fpbuf)]
- - s - 7;
+ if (precision > &fpbuf[sizeof(fpbuf)] - s - 7)
+ precision = &fpbuf[sizeof(fpbuf)] - s - 7;
for (tmp = decpt; tmp++ < 0 &&
precision > 0 ; precision--)
*s++ = '0';
@@ -1094,11 +1093,8 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
/* Overflow check - should
* never have this problem.
*/
- if (precision > &fpbuf[sizeof(fpbuf)]
- - s - 7)
- precision =
- &fpbuf[sizeof(fpbuf)]
- - s - 7;
+ if (precision > &fpbuf[sizeof(fpbuf)] - s - 7)
+ precision = &fpbuf[sizeof(fpbuf)] - s - 7;
(void) memcpy(s, p, precision);
s += precision;
/*
@@ -1173,8 +1169,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
field = -field;
/* skip past sign or 0x when padding with 0 */
if ((flags & FL_ZERO) && (flags & FL_NUMBER)) {
- if (*s == '+' || *s == '-' || *s ==' ')
- {
+ if (*s == '+' || *s == '-' || *s ==' ') {
shf_putc(*s, shf);
s++;
precision--;
@@ -1184,8 +1179,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
s++;
nwritten++;
if (--precision > 0 &&
- (*s | 0x20) == 'x')
- {
+ (*s | 0x20) == 'x') {
shf_putc(*s, shf);
s++;
precision--;
diff --git a/bin/ksh/shf.h b/bin/ksh/shf.h
index 5104e02a730..4f1c7203564 100644
--- a/bin/ksh/shf.h
+++ b/bin/ksh/shf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: shf.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
+/* $OpenBSD: shf.h,v 1.5 2005/03/30 17:16:37 deraadt Exp $ */
#ifndef SHF_H
# define SHF_H
@@ -13,8 +13,8 @@
#define shf_setfileno(shf,nfd) ((shf)->fd = (nfd))
#define shf_getc(shf) ((shf)->rnleft > 0 ? (shf)->rnleft--, *(shf)->rp++ : \
shf_getchar(shf))
-#define shf_putc(c, shf) ((shf)->wnleft == 0 ? shf_putchar((c), (shf)) \
- : ((shf)->wnleft--, *(shf)->wp++ = (c)))
+#define shf_putc(c, shf) ((shf)->wnleft == 0 ? shf_putchar((c), (shf)) : \
+ ((shf)->wnleft--, *(shf)->wp++ = (c)))
#define shf_eof(shf) ((shf)->flags & SHF_EOF)
#define shf_error(shf) ((shf)->flags & SHF_ERROR)
#define shf_errno(shf) ((shf)->errno_)
diff --git a/bin/ksh/syn.c b/bin/ksh/syn.c
index ea494ac7c27..9c77331eefd 100644
--- a/bin/ksh/syn.c
+++ b/bin/ksh/syn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: syn.c,v 1.21 2005/03/28 21:33:04 deraadt Exp $ */
+/* $OpenBSD: syn.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */
/*
* shell parser (C version)
@@ -198,52 +198,52 @@ get_command(int cf)
struct nesting_state old_nesting;
iops = (struct ioword **) alloc(sizeofN(struct ioword *, NUFILE+1),
- ATEMP);
+ ATEMP);
XPinit(args, 16);
XPinit(vars, 16);
syniocf = KEYWORD|ALIAS;
switch (c = token(cf|KEYWORD|ALIAS|VARASN)) {
- default:
+ default:
REJECT;
afree((void*) iops, ATEMP);
XPfree(args);
XPfree(vars);
return NULL; /* empty line */
- case LWORD:
- case REDIR:
+ case LWORD:
+ case REDIR:
REJECT;
syniocf &= ~(KEYWORD|ALIAS);
t = newtp(TCOM);
t->lineno = source->line;
while (1) {
- cf = (t->u.evalflags ? ARRAYVAR : 0)
- | (XPsize(args) == 0 ? ALIAS|VARASN : CMDWORD);
+ cf = (t->u.evalflags ? ARRAYVAR : 0) |
+ (XPsize(args) == 0 ? ALIAS|VARASN : CMDWORD);
switch (tpeek(cf)) {
- case REDIR:
+ case REDIR:
if (iopn >= NUFILE)
yyerror("too many redirections\n");
iops[iopn++] = synio(cf);
break;
- case LWORD:
+ case LWORD:
ACCEPT;
/* the iopn == 0 and XPsize(vars) == 0 are
* dubious but at&t ksh acts this way
*/
- if (iopn == 0 && XPsize(vars) == 0
- && XPsize(args) == 0
- && assign_command(ident))
+ if (iopn == 0 && XPsize(vars) == 0 &&
+ XPsize(args) == 0 &&
+ assign_command(ident))
t->u.evalflags = DOVACHECK;
- if ((XPsize(args) == 0 || Flag(FKEYWORD))
- && is_wdvarassign(yylval.cp))
+ if ((XPsize(args) == 0 || Flag(FKEYWORD)) &&
+ is_wdvarassign(yylval.cp))
XPput(vars, yylval.cp);
else
XPput(args, yylval.cp);
break;
- case '(':
+ case '(':
/* Check for "> foo (echo hi)", which at&t ksh
* allows (not POSIX, but not disallowed)
*/
@@ -253,8 +253,8 @@ get_command(int cf)
goto Subshell;
}
/* Must be a function */
- if (iopn != 0 || XPsize(args) != 1
- || XPsize(vars) != 0)
+ if (iopn != 0 || XPsize(args) != 1 ||
+ XPsize(vars) != 0)
syntaxerr((char *) 0);
ACCEPT;
/*(*/
@@ -262,7 +262,7 @@ get_command(int cf)
t = function_body(XPptrv(args)[0], false);
goto Leave;
- default:
+ default:
goto Leave;
}
}
@@ -270,18 +270,20 @@ get_command(int cf)
break;
Subshell:
- case '(':
+ case '(':
t = nested(TPAREN, '(', ')');
break;
- case '{': /*}*/
+ case '{': /*}*/
t = nested(TBRACE, '{', '}');
break;
- case MDPAREN:
+ case MDPAREN:
{
- static const char let_cmd[] = { CHAR, 'l', CHAR, 'e',
- CHAR, 't', EOS };
+ static const char let_cmd[] = {
+ CHAR, 'l', CHAR, 'e',
+ CHAR, 't', EOS
+ };
/* Leave KEYWORD in syniocf (allow if (( 1 )) then ...) */
t = newtp(TCOM);
t->lineno = source->line;
@@ -292,7 +294,7 @@ get_command(int cf)
break;
}
- case DBRACKET: /* [[ .. ]] */
+ case DBRACKET: /* [[ .. ]] */
/* Leave KEYWORD in syniocf (allow if [[ -n 1 ]] then ...) */
t = newtp(TDBRACKET);
ACCEPT;
@@ -310,13 +312,13 @@ get_command(int cf)
}
break;
- case FOR:
- case SELECT:
+ case FOR:
+ case SELECT:
t = newtp((c == FOR) ? TFOR : TSELECT);
musthave(LWORD, ARRAYVAR);
if (!is_wdvarname(yylval.cp, true))
yyerror("%s: bad identifier\n",
- c == FOR ? "for" : "select");
+ c == FOR ? "for" : "select");
t->str = str_save(ident, ATEMP);
nesting_push(&old_nesting, c);
t->vars = wordlist();
@@ -324,8 +326,8 @@ get_command(int cf)
nesting_pop(&old_nesting);
break;
- case WHILE:
- case UNTIL:
+ case WHILE:
+ case UNTIL:
nesting_push(&old_nesting, c);
t = newtp((c == WHILE) ? TWHILE : TUNTIL);
t->left = c_list(true);
@@ -333,7 +335,7 @@ get_command(int cf)
nesting_pop(&old_nesting);
break;
- case CASE:
+ case CASE:
t = newtp(TCASE);
musthave(LWORD, 0);
t->str = yylval.cp;
@@ -342,7 +344,7 @@ get_command(int cf)
nesting_pop(&old_nesting);
break;
- case IF:
+ case IF:
nesting_push(&old_nesting, c);
t = newtp(TIF);
t->left = c_list(true);
@@ -351,7 +353,7 @@ get_command(int cf)
nesting_pop(&old_nesting);
break;
- case BANG:
+ case BANG:
syniocf &= ~(KEYWORD|ALIAS);
t = pipeline(0);
if (t == (struct op *) 0)
@@ -359,13 +361,13 @@ get_command(int cf)
t = block(TBANG, NOBLOCK, t, NOWORDS);
break;
- case TIME:
+ case TIME:
syniocf &= ~(KEYWORD|ALIAS);
t = pipeline(0);
t = block(TTIME, t, NOBLOCK, NOWORDS);
break;
- case FUNCTION:
+ case FUNCTION:
musthave(LWORD, 0);
t = function_body(yylval.cp, true);
break;
@@ -383,7 +385,7 @@ get_command(int cf)
} else {
iops[iopn++] = NULL;
iops = (struct ioword **) aresize((void*) iops,
- sizeofN(struct ioword *, iopn), ATEMP);
+ sizeofN(struct ioword *, iopn), ATEMP);
t->ioact = iops;
}
@@ -443,18 +445,18 @@ elsepart(void)
struct op *t;
switch (token(KEYWORD|ALIAS|VARASN)) {
- case ELSE:
+ case ELSE:
if ((t = c_list(true)) == NULL)
syntaxerr((char *) 0);
return (t);
- case ELIF:
+ case ELIF:
t = newtp(TELIF);
t->left = c_list(true);
t->right = thenpart();
return (t);
- default:
+ default:
REJECT;
}
return NULL;
@@ -779,10 +781,10 @@ assign_command(char *s)
if (Flag(FPOSIX) || !*s)
return 0;
- return (c == 'a' && strcmp(s, "alias") == 0)
- || (c == 'e' && strcmp(s, "export") == 0)
- || (c == 'r' && strcmp(s, "readonly") == 0)
- || (c == 't' && strcmp(s, "typeset") == 0);
+ return (c == 'a' && strcmp(s, "alias") == 0) ||
+ (c == 'e' && strcmp(s, "export") == 0) ||
+ (c == 'r' && strcmp(s, "readonly") == 0) ||
+ (c == 't' && strcmp(s, "typeset") == 0);
}
/* Check if we are in the middle of reading an alias */
@@ -840,13 +842,11 @@ dbtestp_isa(Test_env *te, Test_meta meta)
else if (meta == TM_CPAREN)
ret = c == /*(*/ ')';
else if (meta == TM_UNOP || meta == TM_BINOP) {
- if (meta == TM_BINOP && c == REDIR
- && (yylval.iop->flag == IOREAD
- || yylval.iop->flag == IOWRITE))
- {
+ if (meta == TM_BINOP && c == REDIR &&
+ (yylval.iop->flag == IOREAD || yylval.iop->flag == IOWRITE)) {
ret = 1;
save = wdcopy(yylval.iop->flag == IOREAD ?
- db_lthan : db_gthan, ATEMP);
+ db_lthan : db_gthan, ATEMP);
} else if (uqword && (ret = (int) test_isop(te, meta, ident)))
save = yylval.cp;
} else /* meta == TM_END */
@@ -892,8 +892,8 @@ dbtestp_error(Test_env *te, int offset, const char *msg)
REJECT;
/* Kludgy to say the least... */
symbol = LWORD;
- yylval.cp = *(XPptrv(*te->pos.av) + XPsize(*te->pos.av)
- + offset);
+ yylval.cp = *(XPptrv(*te->pos.av) + XPsize(*te->pos.av) +
+ offset);
}
syntaxerr(msg);
}
diff --git a/bin/ksh/table.c b/bin/ksh/table.c
index d3251870dbb..bf7ff59c8de 100644
--- a/bin/ksh/table.c
+++ b/bin/ksh/table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.c,v 1.10 2005/03/28 21:28:22 deraadt Exp $ */
+/* $OpenBSD: table.c,v 1.11 2005/03/30 17:16:37 deraadt Exp $ */
/*
* dynamic hashed associative table for commands and variables
@@ -8,8 +8,8 @@
#define INIT_TBLS 8 /* initial table size (power of 2) */
-static void texpand(struct table *, int);
-static int tnamecmp(void *, void *);
+static void texpand(struct table *, int);
+static int tnamecmp(void *, void *);
unsigned int
@@ -51,9 +51,8 @@ texpand(struct table *tp, int nsize)
for (i = 0; i < osize; i++)
if ((tblp = otblp[i]) != NULL) {
if ((tblp->flag&DEFINED)) {
- for (p = &ntblp[hash(tblp->name)
- & (tp->size-1)];
- *p != NULL; p--)
+ for (p = &ntblp[hash(tblp->name) &
+ (tp->size-1)]; *p != NULL; p--)
if (p == ntblp) /* wrap */
p += tp->size;
*p = tblp;
@@ -78,8 +77,8 @@ tsearch(struct table *tp, const char *n, unsigned int h)
/* search for name in hashed table */
for (pp = &tp->tbls[h & (tp->size-1)]; (p = *pp) != NULL; pp--) {
- if (*p->name == *n && strcmp(p->name, n) == 0
- && (p->flag&DEFINED))
+ if (*p->name == *n && strcmp(p->name, n) == 0 &&
+ (p->flag&DEFINED))
return p;
if (pp == tp->tbls) /* wrap */
pp += tp->size;
@@ -171,7 +170,7 @@ tsort(struct table *tp)
dp = p; /* dest */
for (i = 0; i < tp->size; i++)
if ((*dp = *sp++) != NULL && (((*dp)->flag&DEFINED) ||
- ((*dp)->flag&ARRAY)))
+ ((*dp)->flag&ARRAY)))
dp++;
i = dp - p;
qsortp((void**)p, (size_t)i, tnamecmp);
@@ -206,8 +205,8 @@ tprintinfo(struct table *tp)
/* taken from tsearch() and added counter */
for (pp = &tp->tbls[h & (tp->size-1)]; (p = *pp); pp--) {
ncmp++;
- if (*p->name == *n && strcmp(p->name, n) == 0
- && (p->flag&DEFINED))
+ if (*p->name == *n && strcmp(p->name, n) == 0 &&
+ (p->flag&DEFINED))
break; /* return p; */
if (pp == tp->tbls) /* wrap */
pp += tp->size;
@@ -220,8 +219,8 @@ tprintinfo(struct table *tp)
}
if (nentries)
shellf(" %d entries, worst ncmp %d, avg ncmp %d.%02d\n",
- nentries, maxncmp,
- totncmp / nentries,
- (totncmp % nentries) * 100 / nentries);
+ nentries, maxncmp,
+ totncmp / nentries,
+ (totncmp % nentries) * 100 / nentries);
}
#endif /* PERF_DEBUG */
diff --git a/bin/ksh/trap.c b/bin/ksh/trap.c
index 2e8bac87b56..b7bb8066abf 100644
--- a/bin/ksh/trap.c
+++ b/bin/ksh/trap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: trap.c,v 1.21 2005/02/25 11:21:16 deraadt Exp $ */
+/* $OpenBSD: trap.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */
/*
* signal handling
@@ -165,9 +165,8 @@ trap_pending(void)
Trap *p;
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
- if (p->set && ((p->trap && p->trap[0])
- || ((p->flags & (TF_DFL_INTR|TF_FATAL))
- && !p->trap)))
+ if (p->set && ((p->trap && p->trap[0]) ||
+ ((p->flags & (TF_DFL_INTR|TF_FATAL)) && !p->trap)))
return p->signal;
return 0;
}
@@ -198,8 +197,8 @@ runtraps(int flag)
if (flag & TF_FATAL)
fatal_trap = 0;
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
- if (p->set && (!flag
- || ((p->flags & flag) && p->trap == (char *) 0)))
+ if (p->set && (!flag ||
+ ((p->flags & flag) && p->trap == (char *) 0)))
runtrap(p);
}
@@ -275,7 +274,7 @@ restoresigs(void)
for (i = NSIG+1, p = sigtraps; --i >= 0; p++)
if (p->flags & (TF_EXEC_IGN|TF_EXEC_DFL))
setsig(p, (p->flags & TF_EXEC_IGN) ? SIG_IGN : SIG_DFL,
- SS_RESTORE_CURR|SS_FORCE);
+ SS_RESTORE_CURR|SS_FORCE);
}
void
@@ -301,6 +300,7 @@ settrap(Trap *p, char *s)
else
p->flags |= TF_EXEC_DFL;
}
+
/* assumes handler already set to what shell wants it
* (normally trapsig, but could be j_sigchld() or SIG_IGN)
*/
@@ -357,7 +357,7 @@ setsig(Trap *p, sig_t f, int flags)
if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL))) {
sigaction(p->signal, &Sigact_ign, &sigact);
p->flags |= sigact.sa_handler == SIG_IGN ?
- TF_ORIG_IGN : TF_ORIG_DFL;
+ TF_ORIG_IGN : TF_ORIG_DFL;
p->cursig = SIG_IGN;
}
@@ -365,8 +365,8 @@ setsig(Trap *p, sig_t f, int flags)
* - the user of an interactive shell wants to change it
* - the shell wants for force a change
*/
- if ((p->flags & TF_ORIG_IGN) && !(flags & SS_FORCE)
- && (!(flags & SS_USER) || !Flag(FTALKING)))
+ if ((p->flags & TF_ORIG_IGN) && !(flags & SS_FORCE) &&
+ (!(flags & SS_USER) || !Flag(FTALKING)))
return 0;
setexecsig(p, flags & SS_RESTORE_MASK);
@@ -400,20 +400,20 @@ setexecsig(Trap *p, int restore)
/* XXX debugging */
if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL)))
internal_errorf(1, "setexecsig: unset signal %d(%s)",
- p->signal, p->name);
+ p->signal, p->name);
/* restore original value for exec'd kids */
p->flags &= ~(TF_EXEC_IGN|TF_EXEC_DFL);
switch (restore & SS_RESTORE_MASK) {
- case SS_RESTORE_CURR: /* leave things as they currently are */
+ case SS_RESTORE_CURR: /* leave things as they currently are */
break;
- case SS_RESTORE_ORIG:
+ case SS_RESTORE_ORIG:
p->flags |= p->flags & TF_ORIG_IGN ? TF_EXEC_IGN : TF_EXEC_DFL;
break;
- case SS_RESTORE_DFL:
+ case SS_RESTORE_DFL:
p->flags |= TF_EXEC_DFL;
break;
- case SS_RESTORE_IGN:
+ case SS_RESTORE_IGN:
p->flags |= TF_EXEC_IGN;
break;
}
diff --git a/bin/ksh/tree.c b/bin/ksh/tree.c
index b932316e51c..8cecead2ae4 100644
--- a/bin/ksh/tree.c
+++ b/bin/ksh/tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tree.c,v 1.16 2005/03/28 21:28:22 deraadt Exp $ */
+/* $OpenBSD: tree.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */
/*
* command tree climbing
@@ -32,7 +32,7 @@ ptree(struct op *t, int indent, struct shf *shf)
if (t == NULL)
return;
switch (t->type) {
- case TCOM:
+ case TCOM:
if (t->vars)
for (w = t->vars; *w != NULL; )
fptreef(shf, indent, "%S ", *w++);
@@ -44,7 +44,7 @@ ptree(struct op *t, int indent, struct shf *shf)
else
fptreef(shf, indent, "#no-args# ");
break;
- case TEXEC:
+ case TEXEC:
#if 0 /* ?not useful - can't be called? */
/* Print original vars */
if (t->left->vars)
@@ -64,27 +64,27 @@ ptree(struct op *t, int indent, struct shf *shf)
t = t->left;
goto Chain;
#endif
- case TPAREN:
+ case TPAREN:
fptreef(shf, indent + 2, "( %T) ", t->left);
break;
- case TPIPE:
+ case TPIPE:
fptreef(shf, indent, "%T| ", t->left);
t = t->right;
goto Chain;
- case TLIST:
+ case TLIST:
fptreef(shf, indent, "%T%;", t->left);
t = t->right;
goto Chain;
- case TOR:
- case TAND:
+ case TOR:
+ case TAND:
fptreef(shf, indent, "%T%s %T",
- t->left, (t->type==TOR) ? "||" : "&&", t->right);
+ t->left, (t->type==TOR) ? "||" : "&&", t->right);
break;
- case TBANG:
+ case TBANG:
fptreef(shf, indent, "! ");
t = t->right;
goto Chain;
- case TDBRACKET:
+ case TDBRACKET:
{
int i;
@@ -94,10 +94,10 @@ ptree(struct op *t, int indent, struct shf *shf)
fptreef(shf, indent, " ]] ");
break;
}
- case TSELECT:
+ case TSELECT:
fptreef(shf, indent, "select %s ", t->str);
/* fall through */
- case TFOR:
+ case TFOR:
if (t->type == TFOR)
fptreef(shf, indent, "for %s ", t->str);
if (t->vars != NULL) {
@@ -109,19 +109,19 @@ ptree(struct op *t, int indent, struct shf *shf)
fptreef(shf, indent + INDENT, "do%N%T", t->left);
fptreef(shf, indent, "%;done ");
break;
- case TCASE:
+ case TCASE:
fptreef(shf, indent, "case %S in", t->str);
for (t1 = t->left; t1 != NULL; t1 = t1->right) {
fptreef(shf, indent, "%N(");
for (w = t1->vars; *w != NULL; w++)
fptreef(shf, indent, "%S%c", *w,
- (w[1] != NULL) ? '|' : ')');
+ (w[1] != NULL) ? '|' : ')');
fptreef(shf, indent + INDENT, "%;%T%N;;", t1->left);
}
fptreef(shf, indent, "%Nesac ");
break;
- case TIF:
- case TELIF:
+ case TIF:
+ case TELIF:
/* 3 == strlen("if ") */
fptreef(shf, indent + 3, "if %T", t->left);
for (;;) {
@@ -129,7 +129,7 @@ ptree(struct op *t, int indent, struct shf *shf)
if (t->left != NULL) {
fptreef(shf, indent, "%;");
fptreef(shf, indent + INDENT, "then%N%T",
- t->left);
+ t->left);
}
if (t->right == NULL || t->right->type != TELIF)
break;
@@ -144,35 +144,35 @@ ptree(struct op *t, int indent, struct shf *shf)
}
fptreef(shf, indent, "%;fi ");
break;
- case TWHILE:
- case TUNTIL:
+ case TWHILE:
+ case TUNTIL:
/* 6 == strlen("while"/"until") */
fptreef(shf, indent + 6, "%s %T",
- (t->type==TWHILE) ? "while" : "until",
- t->left);
+ (t->type==TWHILE) ? "while" : "until",
+ t->left);
fptreef(shf, indent, "%;do");
fptreef(shf, indent + INDENT, "%;%T", t->right);
fptreef(shf, indent, "%;done ");
break;
- case TBRACE:
+ case TBRACE:
fptreef(shf, indent + INDENT, "{%;%T", t->left);
fptreef(shf, indent, "%;} ");
break;
- case TCOPROC:
+ case TCOPROC:
fptreef(shf, indent, "%T|& ", t->left);
break;
- case TASYNC:
+ case TASYNC:
fptreef(shf, indent, "%T& ", t->left);
break;
- case TFUNCT:
+ case TFUNCT:
fptreef(shf, indent,
- t->u.ksh_func ? "function %s %T" : "%s() %T",
- t->str, t->left);
+ t->u.ksh_func ? "function %s %T" : "%s() %T",
+ t->str, t->left);
break;
- case TTIME:
+ case TTIME:
fptreef(shf, indent, "time %T", t->left);
break;
- default:
+ default:
fptreef(shf, indent, "<botch>");
break;
}
@@ -190,7 +190,7 @@ ptree(struct op *t, int indent, struct shf *shf)
tputc('\n', shf);
shf_puts(iop->heredoc, shf);
fptreef(shf, indent, "%s",
- evalstr(iop->delim, 0));
+ evalstr(iop->delim, 0));
need_nl = 1;
}
}
@@ -210,11 +210,10 @@ pioact(struct shf *shf, int indent, struct ioword *iop)
int type = flag & IOTYPE;
int expected;
- expected = (type == IOREAD || type == IORDWR || type == IOHERE) ? 0
- : (type == IOCAT || type == IOWRITE) ? 1
- : (type == IODUP && (iop->unit == !(flag & IORDUP))) ?
- iop->unit
- : iop->unit + 1;
+ expected = (type == IOREAD || type == IORDWR || type == IOHERE) ? 0 :
+ (type == IOCAT || type == IOWRITE) ? 1 :
+ (type == IODUP && (iop->unit == !(flag & IORDUP))) ? iop->unit :
+ iop->unit + 1;
if (iop->unit != expected)
tputc('0' + iop->unit, shf);
@@ -253,7 +252,7 @@ pioact(struct shf *shf, int indent, struct ioword *iop)
fptreef(shf, indent, "%S ", iop->delim);
} else if (iop->name)
fptreef(shf, indent, (iop->flag & IONAMEXP) ? "%s " : "%S ",
- iop->name);
+ iop->name);
}
@@ -288,18 +287,18 @@ tputS(char *wp, struct shf *shf)
*/
while (1)
switch ((c = *wp++)) {
- case EOS:
+ case EOS:
return;
- case CHAR:
+ case CHAR:
tputC(*wp++, shf);
break;
- case QCHAR:
+ case QCHAR:
c = *wp++;
if (!quoted || (c == '"' || c == '`' || c == '$'))
tputc('\\', shf);
tputC(c, shf);
break;
- case COMSUB:
+ case COMSUB:
tputc('$', shf);
tputc('(', shf);
while (*wp != 0)
@@ -307,7 +306,7 @@ tputS(char *wp, struct shf *shf)
tputc(')', shf);
wp++;
break;
- case EXPRSUB:
+ case EXPRSUB:
tputc('$', shf);
tputc('(', shf);
tputc('(', shf);
@@ -317,33 +316,33 @@ tputS(char *wp, struct shf *shf)
tputc(')', shf);
wp++;
break;
- case OQUOTE:
+ case OQUOTE:
quoted = 1;
tputc('"', shf);
break;
- case CQUOTE:
+ case CQUOTE:
quoted = 0;
tputc('"', shf);
break;
- case OSUBST:
+ case OSUBST:
tputc('$', shf);
if (*wp++ == '{')
tputc('{', shf);
while ((c = *wp++) != 0)
tputC(c, shf);
break;
- case CSUBST:
+ case CSUBST:
if (*wp++ == '}')
tputc('}', shf);
break;
- case OPAT:
+ case OPAT:
tputc(*wp++, shf);
tputc('(', shf);
break;
- case SPAT:
+ case SPAT:
tputc('|', shf);
break;
- case CPAT:
+ case CPAT:
tputc(')', shf);
break;
}
@@ -387,63 +386,64 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
{
int c;
- while ((c = *fmt++))
- if (c == '%') {
- long n;
- char *p;
- int neg;
+ while ((c = *fmt++)) {
+ if (c == '%') {
+ long n;
+ char *p;
+ int neg;
- switch ((c = *fmt++)) {
- case 'c':
- tputc(va_arg(va, int), shf);
- break;
- case 's':
- p = va_arg(va, char *);
- while (*p)
- tputc(*p++, shf);
- break;
- case 'S': /* word */
- p = va_arg(va, char *);
- tputS(p, shf);
- break;
- case 'd': case 'u': /* decimal */
- n = (c == 'd') ? va_arg(va, int)
- : va_arg(va, unsigned int);
- neg = c=='d' && n<0;
- p = ulton((neg) ? -n : n, 10);
- if (neg)
- *--p = '-';
- while (*p)
- tputc(*p++, shf);
- break;
- case 'T': /* format tree */
- ptree(va_arg(va, struct op *), indent, shf);
- break;
- case ';': /* newline or ; */
- case 'N': /* newline or space */
- if (shf->flags & SHF_STRING) {
- if (c == ';')
- tputc(';', shf);
- tputc(' ', shf);
- } else {
- int i;
-
- tputc('\n', shf);
- for (i = indent; i >= 8; i -= 8)
- tputc('\t', shf);
- for (; i > 0; --i)
+ switch ((c = *fmt++)) {
+ case 'c':
+ tputc(va_arg(va, int), shf);
+ break;
+ case 's':
+ p = va_arg(va, char *);
+ while (*p)
+ tputc(*p++, shf);
+ break;
+ case 'S': /* word */
+ p = va_arg(va, char *);
+ tputS(p, shf);
+ break;
+ case 'd': case 'u': /* decimal */
+ n = (c == 'd') ? va_arg(va, int) :
+ va_arg(va, unsigned int);
+ neg = c=='d' && n<0;
+ p = ulton((neg) ? -n : n, 10);
+ if (neg)
+ *--p = '-';
+ while (*p)
+ tputc(*p++, shf);
+ break;
+ case 'T': /* format tree */
+ ptree(va_arg(va, struct op *), indent, shf);
+ break;
+ case ';': /* newline or ; */
+ case 'N': /* newline or space */
+ if (shf->flags & SHF_STRING) {
+ if (c == ';')
+ tputc(';', shf);
tputc(' ', shf);
+ } else {
+ int i;
+
+ tputc('\n', shf);
+ for (i = indent; i >= 8; i -= 8)
+ tputc('\t', shf);
+ for (; i > 0; --i)
+ tputc(' ', shf);
+ }
+ break;
+ case 'R':
+ pioact(shf, indent, va_arg(va, struct ioword *));
+ break;
+ default:
+ tputc(c, shf);
+ break;
}
- break;
- case 'R':
- pioact(shf, indent, va_arg(va, struct ioword *));
- break;
- default:
+ } else
tputc(c, shf);
- break;
- }
- } else
- tputc(c, shf);
+ }
}
/*
@@ -514,46 +514,46 @@ wdscan(const char *wp, int c)
while (1)
switch (*wp++) {
- case EOS:
+ case EOS:
return (char *) wp;
- case CHAR:
- case QCHAR:
+ case CHAR:
+ case QCHAR:
wp++;
break;
- case COMSUB:
- case EXPRSUB:
+ case COMSUB:
+ case EXPRSUB:
while (*wp++ != 0)
;
break;
- case OQUOTE:
- case CQUOTE:
+ case OQUOTE:
+ case CQUOTE:
break;
- case OSUBST:
+ case OSUBST:
nest++;
while (*wp++ != '\0')
;
break;
- case CSUBST:
+ case CSUBST:
wp++;
if (c == CSUBST && nest == 0)
return (char *) wp;
nest--;
break;
- case OPAT:
+ case OPAT:
nest++;
wp++;
break;
- case SPAT:
- case CPAT:
+ case SPAT:
+ case CPAT:
if (c == wp[-1] && nest == 0)
return (char *) wp;
if (wp[-1] == CPAT)
nest--;
break;
- default:
+ default:
internal_errorf(0,
- "wdscan: unknown char 0x%x (carrying on)",
- wp[-1]);
+ "wdscan: unknown char 0x%x (carrying on)",
+ wp[-1]);
}
}
@@ -576,20 +576,20 @@ wdstrip(const char *wp)
*/
while (1)
switch ((c = *wp++)) {
- case EOS:
+ case EOS:
return shf_sclose(&shf); /* null terminates */
- case CHAR:
- case QCHAR:
+ case CHAR:
+ case QCHAR:
shf_putchar(*wp++, &shf);
break;
- case COMSUB:
+ case COMSUB:
shf_putchar('$', &shf);
shf_putchar('(', &shf);
while (*wp != 0)
shf_putchar(*wp++, &shf);
shf_putchar(')', &shf);
break;
- case EXPRSUB:
+ case EXPRSUB:
shf_putchar('$', &shf);
shf_putchar('(', &shf);
shf_putchar('(', &shf);
@@ -598,29 +598,29 @@ wdstrip(const char *wp)
shf_putchar(')', &shf);
shf_putchar(')', &shf);
break;
- case OQUOTE:
+ case OQUOTE:
break;
- case CQUOTE:
+ case CQUOTE:
break;
- case OSUBST:
+ case OSUBST:
shf_putchar('$', &shf);
if (*wp++ == '{')
shf_putchar('{', &shf);
while ((c = *wp++) != 0)
shf_putchar(c, &shf);
break;
- case CSUBST:
+ case CSUBST:
if (*wp++ == '}')
shf_putchar('}', &shf);
break;
- case OPAT:
+ case OPAT:
shf_putchar(*wp++, &shf);
shf_putchar('(', &shf);
break;
- case SPAT:
+ case SPAT:
shf_putchar('|', &shf);
break;
- case CPAT:
+ case CPAT:
shf_putchar(')', &shf);
break;
}
diff --git a/bin/ksh/tty.c b/bin/ksh/tty.c
index 20953494acb..9546724faf3 100644
--- a/bin/ksh/tty.c
+++ b/bin/ksh/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.7 2004/12/22 17:14:34 millert Exp $ */
+/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h"
#include <sys/stat.h>
@@ -22,12 +22,11 @@ tty_init(int init_ttystate)
tty_devtty = 1;
if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) {
-
if (tfd < 0) {
tty_devtty = 0;
warningf(false,
- "No controlling tty (open /dev/tty: %s)",
- strerror(errno));
+ "No controlling tty (open /dev/tty: %s)",
+ strerror(errno));
}
}
@@ -44,10 +43,10 @@ tty_init(int init_ttystate)
}
if ((tty_fd = fcntl(tfd, F_DUPFD, FDBASE)) < 0) {
warningf(false, "j_ttyinit: dup of tty fd failed: %s",
- strerror(errno));
+ strerror(errno));
} else if (fcntl(tty_fd, F_SETFD, FD_CLOEXEC) < 0) {
warningf(false, "j_ttyinit: can't set close-on-exec flag: %s",
- strerror(errno));
+ strerror(errno));
close(tty_fd);
tty_fd = -1;
} else if (init_ttystate)
diff --git a/bin/ksh/var.c b/bin/ksh/var.c
index cbfc084a014..cd58c4b3d40 100644
--- a/bin/ksh/var.c
+++ b/bin/ksh/var.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: var.c,v 1.25 2005/03/28 21:33:04 deraadt Exp $ */
+/* $OpenBSD: var.c,v 1.26 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h"
#include <time.h>
@@ -189,25 +189,25 @@ global(const char *n)
return vp;
vp->flag |= ISSET|INTEGER;
switch (c) {
- case '$':
+ case '$':
vp->val.i = kshpid;
break;
- case '!':
+ case '!':
/* If no job, expand to nothing */
if ((vp->val.i = j_async()) == 0)
vp->flag &= ~(ISSET|INTEGER);
break;
- case '?':
+ case '?':
vp->val.i = exstat;
break;
- case '#':
+ case '#':
vp->val.i = l->argc;
break;
- case '-':
+ case '-':
vp->flag &= ~INTEGER;
vp->val.s = getoptions();
break;
- default:
+ default:
vp->flag &= ~(ISSET|INTEGER);
}
return vp;
@@ -262,9 +262,9 @@ local(const char *n, bool copy)
while ((ll = ll->next) && !(vq = tsearch(&ll->vars, n, h)))
;
if (vq) {
- vp->flag |= vq->flag & (EXPORT|INTEGER|RDONLY
- |LJUST|RJUST|ZEROFIL
- |LCASEV|UCASEV_AL|INT_U|INT_L);
+ vp->flag |= vq->flag &
+ (EXPORT | INTEGER | RDONLY | LJUST | RJUST |
+ ZEROFIL | LCASEV | UCASEV_AL | INT_U | INT_L);
if (vq->flag & INTEGER)
vp->type = vq->type;
vp->u2.field = vq->u2.field;
@@ -292,11 +292,11 @@ str_val(struct tbl *vp)
s = vp->val.s + vp->type;
else { /* integer source */
/* worst case number length is when base=2, so use BITS(long) */
- /* minus base # number null */
+ /* minus base # number null */
static char strbuf[1 + 2 + 1 + BITS(long) + 1];
const char *digits = (vp->flag & UCASEV_AL) ?
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- : "0123456789abcdefghijklmnopqrstuvwxyz";
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" :
+ "0123456789abcdefghijklmnopqrstuvwxyz";
unsigned long n;
int base;
@@ -355,8 +355,8 @@ setstr(struct tbl *vq, const char *s, int error_ok)
if (!(vq->flag&INTEGER)) { /* string dest */
if ((vq->flag&ALLOC)) {
/* debugging */
- if (s >= vq->val.s
- && s <= vq->val.s + strlen(vq->val.s))
+ if (s >= vq->val.s &&
+ s <= vq->val.s + strlen(vq->val.s))
internal_errorf(true,
"setstr: %s=%s: assigning to self",
vq->name, s);
@@ -617,13 +617,12 @@ 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))
+ if (Flag(FRESTRICTED) && (strcmp(tvar, "PATH") == 0 ||
+ strcmp(tvar, "ENV") == 0 || strcmp(tvar, "SHELL") == 0))
errorf("%s: restricted", tvar);
- vp = (set&LOCAL) ? local(tvar, (set & LOCAL_COPY) ? true : false)
- : global(tvar);
+ vp = (set&LOCAL) ? local(tvar, (set & LOCAL_COPY) ? true : false) :
+ global(tvar);
set &= ~(LOCAL|LOCAL_COPY);
vpbase = (vp->flag & ARRAY) ? global(arrayname(var)) : vp;
@@ -632,8 +631,8 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
* be changed, which means it can be truncated or modified
* (-L/-R/-Z/-i).
*/
- if ((vpbase->flag&RDONLY)
- && (val || clr || (set & ~EXPORT)))
+ if ((vpbase->flag&RDONLY) &&
+ (val || clr || (set & ~EXPORT)))
/* XXX check calls - is error here ok by POSIX? */
errorf("%s: is read only", tvar);
if (val)
@@ -650,18 +649,18 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
char *s = NULL;
char *free_me = NULL;
- fake_assign = (t->flag & ISSET) && (!val || t != vp)
- && ((set & (UCASEV_AL|LCASEV|LJUST|RJUST|ZEROFIL))
- || ((t->flag & INTEGER) && (clr & INTEGER))
- || (!(t->flag & INTEGER) && (set & INTEGER)));
+ fake_assign = (t->flag & ISSET) && (!val || t != vp) &&
+ ((set & (UCASEV_AL|LCASEV|LJUST|RJUST|ZEROFIL)) ||
+ ((t->flag & INTEGER) && (clr & INTEGER)) ||
+ (!(t->flag & INTEGER) && (set & INTEGER)));
if (fake_assign) {
if (t->flag & INTEGER) {
s = str_val(t);
free_me = (char *) 0;
} else {
s = t->val.s + t->type;
- free_me = (t->flag & ALLOC) ? t->val.s
- : (char *) 0;
+ free_me = (t->flag & ALLOC) ? t->val.s :
+ (char *) 0;
}
t->flag &= ~ALLOC;
}
@@ -689,7 +688,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
else {
if (t->flag & ALLOC)
afree((void*) t->val.s,
- t->areap);
+ t->areap);
t->flag &= ~(ISSET|ALLOC);
t->type = 0;
}
@@ -715,8 +714,8 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
}
/* only x[0] is ever exported, so use vpbase */
- if ((vpbase->flag&EXPORT) && !(vpbase->flag&INTEGER)
- && vpbase->type == 0)
+ if ((vpbase->flag&EXPORT) && !(vpbase->flag&INTEGER) &&
+ vpbase->type == 0)
export(vpbase, (vpbase->flag&ISSET) ? vpbase->val.s : null);
return vp;
@@ -773,9 +772,9 @@ skip_wdvarname(const char *s,
int aok) /* skip array de-reference? */
{
if (s[0] == CHAR && letter(s[1])) {
- do
+ do {
s += 2;
- while (s[0] == CHAR && letnum(s[1]));
+ } while (s[0] == CHAR && letnum(s[1]));
if (aok && s[0] == CHAR && s[1] == '[') {
/* skip possible array de-reference */
const char *p = s;
@@ -831,8 +830,8 @@ makenv(void)
XPinit(env, 64);
for (l = e->loc; l != NULL; l = l->next)
for (vpp = l->vars.tbls, i = l->vars.size; --i >= 0; )
- if ((vp = *vpp++) != NULL
- && (vp->flag&(ISSET|EXPORT)) == (ISSET|EXPORT)) {
+ if ((vp = *vpp++) != NULL &&
+ (vp->flag&(ISSET|EXPORT)) == (ISSET|EXPORT)) {
struct block *l2;
struct tbl *vp2;
unsigned h = hash(vp->name);
@@ -907,7 +906,7 @@ static void
getspec(struct tbl *vp)
{
switch (special(vp->name)) {
- case V_SECONDS:
+ case V_SECONDS:
vp->flag &= ~SPECIAL;
/* On start up the value of SECONDS is used before seconds
* has been set - don't do anything in this case
@@ -917,7 +916,7 @@ getspec(struct tbl *vp)
setint(vp, (long) (time((time_t *)0) - seconds));
vp->flag |= SPECIAL;
break;
- case V_RANDOM:
+ case V_RANDOM:
vp->flag &= ~SPECIAL;
if (use_rand)
setint(vp, (long) (rand() & 0x7fff));
@@ -926,18 +925,18 @@ getspec(struct tbl *vp)
vp->flag |= SPECIAL;
break;
#ifdef HISTORY
- case V_HISTSIZE:
+ case V_HISTSIZE:
vp->flag &= ~SPECIAL;
setint(vp, (long) histsize);
vp->flag |= SPECIAL;
break;
#endif /* HISTORY */
- case V_OPTIND:
+ case V_OPTIND:
vp->flag &= ~SPECIAL;
setint(vp, (long) user_opt.uoptind);
vp->flag |= SPECIAL;
break;
- case V_LINENO:
+ case V_LINENO:
vp->flag &= ~SPECIAL;
setint(vp, (long) current_lineno + user_lineno);
vp->flag |= SPECIAL;
@@ -951,25 +950,25 @@ setspec(struct tbl *vp)
char *s;
switch (special(vp->name)) {
- case V_PATH:
+ case V_PATH:
if (path)
afree(path, APERM);
path = str_save(str_val(vp), APERM);
flushcom(1); /* clear tracked aliases */
break;
- case V_IFS:
+ case V_IFS:
setctypes(s = str_val(vp), C_IFS);
ifs0 = *s;
break;
- case V_OPTIND:
+ case V_OPTIND:
vp->flag &= ~SPECIAL;
getopts_reset((int) intval(vp));
vp->flag |= SPECIAL;
break;
- case V_POSIXLY_CORRECT:
+ case V_POSIXLY_CORRECT:
change_flag(FPOSIX, OF_SPECIAL, 1);
break;
- case V_TMPDIR:
+ case V_TMPDIR:
if (tmpdir) {
afree(tmpdir, APERM);
tmpdir = (char *) 0;
@@ -979,63 +978,64 @@ setspec(struct tbl *vp)
*/
{
struct stat statb;
+
s = str_val(vp);
- if (s[0] == '/' && access(s, W_OK|X_OK) == 0
- && stat(s, &statb) == 0 && S_ISDIR(statb.st_mode))
+ if (s[0] == '/' && access(s, W_OK|X_OK) == 0 &&
+ stat(s, &statb) == 0 && S_ISDIR(statb.st_mode))
tmpdir = str_save(s, APERM);
}
break;
#ifdef HISTORY
- case V_HISTSIZE:
+ case V_HISTSIZE:
vp->flag &= ~SPECIAL;
sethistsize((int) intval(vp));
vp->flag |= SPECIAL;
break;
- case V_HISTFILE:
+ case V_HISTFILE:
sethistfile(str_val(vp));
break;
#endif /* HISTORY */
#ifdef EDIT
- case V_VISUAL:
+ case V_VISUAL:
set_editmode(str_val(vp));
break;
- case V_EDITOR:
+ case V_EDITOR:
if (!(global("VISUAL")->flag & ISSET))
set_editmode(str_val(vp));
break;
- case V_COLUMNS:
+ case V_COLUMNS:
if ((x_cols = intval(vp)) <= MIN_COLS)
x_cols = MIN_COLS;
break;
#endif /* EDIT */
- case V_MAIL:
+ case V_MAIL:
mbset(str_val(vp));
break;
- case V_MAILPATH:
+ case V_MAILPATH:
mpset(str_val(vp));
break;
- case V_MAILCHECK:
+ case V_MAILCHECK:
vp->flag &= ~SPECIAL;
mcset(intval(vp));
vp->flag |= SPECIAL;
break;
- case V_RANDOM:
+ case V_RANDOM:
vp->flag &= ~SPECIAL;
srand((unsigned int)intval(vp));
use_rand = 1;
vp->flag |= SPECIAL;
break;
- case V_SECONDS:
+ case V_SECONDS:
vp->flag &= ~SPECIAL;
seconds = time((time_t*) 0) - intval(vp);
vp->flag |= SPECIAL;
break;
- case V_TMOUT:
+ case V_TMOUT:
/* at&t ksh seems to do this (only listen if integer) */
if (vp->flag & INTEGER)
ksh_tmout = vp->val.i >= 0 ? vp->val.i : 0;
break;
- case V_LINENO:
+ case V_LINENO:
vp->flag &= ~SPECIAL;
/* The -1 is because line numbering starts at 1. */
user_lineno = (unsigned int) intval(vp) - current_lineno - 1;
@@ -1048,34 +1048,34 @@ static void
unsetspec(struct tbl *vp)
{
switch (special(vp->name)) {
- case V_PATH:
+ case V_PATH:
if (path)
afree(path, APERM);
path = str_save(def_path, APERM);
flushcom(1); /* clear tracked aliases */
break;
- case V_IFS:
+ case V_IFS:
setctypes(" \t\n", C_IFS);
ifs0 = ' ';
break;
- case V_TMPDIR:
+ case V_TMPDIR:
/* should not become unspecial */
if (tmpdir) {
afree(tmpdir, APERM);
tmpdir = (char *) 0;
}
break;
- case V_MAIL:
+ case V_MAIL:
mbset((char *) 0);
break;
- case V_MAILPATH:
+ case V_MAILPATH:
mpset((char *) 0);
break;
- case V_LINENO:
- case V_MAILCHECK: /* at&t ksh leaves previous value in place */
- case V_RANDOM:
- case V_SECONDS:
- case V_TMOUT: /* at&t ksh leaves previous value in place */
+ case V_LINENO:
+ case V_MAILCHECK: /* at&t ksh leaves previous value in place */
+ case V_RANDOM:
+ case V_SECONDS:
+ case V_TMOUT: /* at&t ksh leaves previous value in place */
unspecial(vp->name);
break;
diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c
index db25af41d7b..2fcde68eea6 100644
--- a/bin/ksh/vi.c
+++ b/bin/ksh/vi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vi.c,v 1.20 2005/03/28 21:28:22 deraadt Exp $ */
+/* $OpenBSD: vi.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
/*
* vi command editing
@@ -207,9 +207,9 @@ x_vi(char *buf, size_t len)
vi_macro_reset();
c = x_getc();
}
- } else {
+ } else
c = x_getc();
- }
+
if (c == -1)
break;
if (state != VLIT) {
@@ -250,10 +250,8 @@ x_vi(char *buf, size_t len)
static int
vi_hook(int ch)
{
- static char curcmd[MAXVICMD];
- static char locpat[SRCHLEN];
- static int cmdlen;
- static int argc1, argc2;
+ static char curcmd[MAXVICMD], locpat[SRCHLEN];
+ static int cmdlen, argc1, argc2;
switch (state) {
@@ -294,11 +292,10 @@ vi_hook(int ch)
es->cursor = 0;
es->linelen = 0;
if (ch == '/') {
- if (putbuf("/", 1, 0) != 0) {
+ if (putbuf("/", 1, 0) != 0)
return -1;
- }
} else if (putbuf("?", 1, 0) != 0)
- return -1;
+ return -1;
refresh(0);
}
if (state == VVERSION) {
@@ -306,7 +303,7 @@ vi_hook(int ch)
es->cursor = 0;
es->linelen = 0;
putbuf(ksh_version + 4,
- strlen(ksh_version + 4), 0);
+ strlen(ksh_version + 4), 0);
refresh(0);
}
}
@@ -401,7 +398,7 @@ vi_hook(int ch)
} else if (ch == edchars.erase || ch == Ctrl('h')) {
if (srchlen != 0) {
srchlen--;
- es->linelen -= char_len((unsigned char) locpat[srchlen]);
+ es->linelen -= char_len((unsigned char)locpat[srchlen]);
es->cursor = es->linelen;
refresh(0);
return 0;
@@ -424,7 +421,7 @@ vi_hook(int ch)
while (n > 0 && !isspace(locpat[n - 1]))
n--;
for (i = srchlen; --i >= n; )
- es->linelen -= char_len((unsigned char) locpat[i]);
+ es->linelen -= char_len((unsigned char)locpat[i]);
srchlen = n;
es->cursor = es->linelen;
refresh(0);
@@ -493,7 +490,7 @@ vi_hook(int ch)
case 0:
if (insert != 0) {
if (lastcmd[0] == 's' || lastcmd[0] == 'c' ||
- lastcmd[0] == 'C') {
+ lastcmd[0] == 'C') {
if (redo_insert(1) != 0)
vi_error();
} else {
@@ -581,7 +578,7 @@ vi_insert(int ch)
es->cursor--;
es->linelen--;
memmove(&es->cbuf[es->cursor], &es->cbuf[es->cursor+1],
- es->linelen - es->cursor + 1);
+ es->linelen - es->cursor + 1);
}
expanded = NONE;
return 0;
@@ -590,7 +587,7 @@ vi_insert(int ch)
if (es->cursor != 0) {
inslen = 0;
memmove(es->cbuf, &es->cbuf[es->cursor],
- es->linelen - es->cursor);
+ es->linelen - es->cursor);
es->linelen -= es->cursor;
es->cursor = 0;
}
@@ -601,7 +598,7 @@ vi_insert(int ch)
if (es->cursor != 0) {
tcursor = Backword(1);
memmove(&es->cbuf[tcursor], &es->cbuf[es->cursor],
- es->linelen - es->cursor);
+ es->linelen - es->cursor);
es->linelen -= es->cursor - tcursor;
if (inslen < es->cursor - tcursor)
inslen = 0;
@@ -638,7 +635,7 @@ vi_insert(int ch)
lastac = 1;
}
if (lastcmd[0] == 's' || lastcmd[0] == 'c' ||
- lastcmd[0] == 'C')
+ lastcmd[0] == 'C')
return redo_insert(0);
else
return redo_insert(lastac - 1);
@@ -670,7 +667,7 @@ vi_insert(int ch)
ibuf[inslen++] = ch;
if (insert == INSERT) {
memmove(&es->cbuf[es->cursor+1], &es->cbuf[es->cursor],
- es->linelen - es->cursor);
+ es->linelen - es->cursor);
es->linelen++;
}
es->cbuf[es->cursor++] = ch;
@@ -735,8 +732,8 @@ vi_cmd(int argcnt, const char *cmd)
return -1;
/* insert alias into macro buffer */
nlen = strlen(ap->val.s) + 1;
- olen = !macro.p ? 2
- : macro.len - (macro.p - macro.buf);
+ olen = !macro.p ? 2 :
+ macro.len - (macro.p - macro.buf);
nbuf = alloc(nlen + 1 + olen, APERM);
memcpy(nbuf, ap->val.s, nlen);
nbuf[nlen++] = cmd[1];
@@ -789,8 +786,8 @@ vi_cmd(int argcnt, const char *cmd)
if ((ncursor = domove(argcnt, &cmd[1], 1)) < 0)
return -1;
if (*cmd == 'c' &&
- (cmd[1]=='w' || cmd[1]=='W') &&
- !isspace(es->cbuf[es->cursor])) {
+ (cmd[1]=='w' || cmd[1]=='W') &&
+ !isspace(es->cbuf[es->cursor])) {
while (isspace(es->cbuf[--ncursor]))
;
ncursor++;
@@ -948,9 +945,9 @@ vi_cmd(int argcnt, const char *cmd)
- (hlast - hnum);
}
shf_snprintf(es->cbuf, es->cbufsize,
- argcnt ? "%s %d" : "%s",
- "fc -e ${VISUAL:-${EDITOR:-vi}} --",
- argcnt);
+ argcnt ? "%s %d" : "%s",
+ "fc -e ${VISUAL:-${EDITOR:-vi}} --",
+ argcnt);
es->linelen = strlen(es->cbuf);
return 2;
@@ -1011,7 +1008,7 @@ vi_cmd(int argcnt, const char *cmd)
if (*cmd == 'N')
c1 = !c1;
if ((c2 = grabsearch(modified, hnum,
- c1, srchpat)) < 0) {
+ c1, srchpat)) < 0) {
if (c3) {
restore_cbuf();
refresh(0);
@@ -1101,7 +1098,7 @@ vi_cmd(int argcnt, const char *cmd)
case '#':
{
int ret = x_do_comment(es->cbuf, es->cbufsize,
- &es->linelen);
+ &es->linelen);
if (ret >= 0)
es->cursor = 0;
return ret;
@@ -1257,7 +1254,7 @@ domove(int argcnt, const char *cmd, int sub)
case '%':
ncursor = es->cursor;
while (ncursor < es->linelen &&
- (i = bracktype(es->cbuf[ncursor])) == 0)
+ (i = bracktype(es->cbuf[ncursor])) == 0)
ncursor++;
if (ncursor == es->linelen)
return -1;
@@ -1462,7 +1459,7 @@ putbuf(const char *buf, int len, int repl)
if (es->linelen + len >= es->cbufsize)
return -1;
memmove(&es->cbuf[es->cursor + len], &es->cbuf[es->cursor],
- es->linelen - es->cursor);
+ es->linelen - es->cursor);
es->linelen += len;
}
memmove(&es->cbuf[es->cursor], buf, len);
@@ -1515,12 +1512,12 @@ forwword(int argcnt)
while (ncursor < es->linelen && argcnt--) {
if (is_wordch(es->cbuf[ncursor]))
while (is_wordch(es->cbuf[ncursor]) &&
- ncursor < es->linelen)
+ ncursor < es->linelen)
ncursor++;
else if (!isspace(es->cbuf[ncursor]))
while (!is_wordch(es->cbuf[ncursor]) &&
- !isspace(es->cbuf[ncursor]) &&
- ncursor < es->linelen)
+ !isspace(es->cbuf[ncursor]) &&
+ ncursor < es->linelen)
ncursor++;
while (isspace(es->cbuf[ncursor]) && ncursor < es->linelen)
ncursor++;
@@ -1540,12 +1537,12 @@ backword(int argcnt)
if (ncursor > 0) {
if (is_wordch(es->cbuf[ncursor]))
while (--ncursor >= 0 &&
- is_wordch(es->cbuf[ncursor]))
+ is_wordch(es->cbuf[ncursor]))
;
else
while (--ncursor >= 0 &&
- !is_wordch(es->cbuf[ncursor]) &&
- !isspace(es->cbuf[ncursor]))
+ !is_wordch(es->cbuf[ncursor]) &&
+ !isspace(es->cbuf[ncursor]))
;
ncursor++;
}
@@ -1561,17 +1558,17 @@ endword(int argcnt)
ncursor = es->cursor;
while (ncursor < es->linelen && argcnt--) {
while (++ncursor < es->linelen - 1 &&
- isspace(es->cbuf[ncursor]))
+ isspace(es->cbuf[ncursor]))
;
if (ncursor < es->linelen - 1) {
if (is_wordch(es->cbuf[ncursor]))
while (++ncursor < es->linelen &&
- is_wordch(es->cbuf[ncursor]))
+ is_wordch(es->cbuf[ncursor]))
;
else
while (++ncursor < es->linelen &&
- !is_wordch(es->cbuf[ncursor]) &&
- !isspace(es->cbuf[ncursor]))
+ !is_wordch(es->cbuf[ncursor]) &&
+ !isspace(es->cbuf[ncursor]))
;
ncursor--;
}
@@ -1618,11 +1615,11 @@ Endword(int argcnt)
ncursor = es->cursor;
while (ncursor < es->linelen - 1 && argcnt--) {
while (++ncursor < es->linelen - 1 &&
- isspace(es->cbuf[ncursor]))
+ isspace(es->cbuf[ncursor]))
;
if (ncursor < es->linelen - 1) {
while (++ncursor < es->linelen &&
- !isspace(es->cbuf[ncursor]))
+ !isspace(es->cbuf[ncursor]))
;
ncursor--;
}
@@ -1753,7 +1750,7 @@ rewindow(void)
}
while (tcol - holdcol1 > winwidth / 2)
holdcol1 = newcol((unsigned char) es->cbuf[holdcur1++],
- holdcol1);
+ holdcol1);
es->winleft = holdcur1;
}
@@ -1905,8 +1902,8 @@ expand_word(int command)
}
nwords = x_cf_glob(XCF_COMMAND_FILE|XCF_FULLPATH,
- es->cbuf, es->linelen, es->cursor,
- &start, &end, &words, (int *) 0);
+ es->cbuf, es->linelen, es->cursor,
+ &start, &end, &words, (int *) 0);
if (nwords == 0) {
vi_error();
return -1;
@@ -1970,8 +1967,8 @@ complete_word(int command, int count)
* was done this way.
*/
nwords = x_cf_glob(XCF_COMMAND_FILE | (count ? XCF_FULLPATH : 0),
- es->cbuf, es->linelen, es->cursor,
- &start, &end, &words, &is_command);
+ es->cbuf, es->linelen, es->cursor,
+ &start, &end, &words, &is_command);
if (nwords == 0) {
vi_error();
return -1;
@@ -1991,15 +1988,13 @@ complete_word(int command, int count)
* Expand the count'th word to its basename
*/
if (is_command) {
- match = words[count]
- + x_basename(words[count], (char *) 0);
+ match = words[count] +
+ x_basename(words[count], (char *) 0);
/* If more than one possible match, use full path */
for (i = 0; i < nwords; i++)
if (i != count &&
- strcmp(words[i]
- + x_basename(words[i], (char *) 0),
- match) == 0)
- {
+ strcmp(words[i] + x_basename(words[i],
+ (char *) 0), match) == 0) {
match = words[count];
break;
}
@@ -2052,8 +2047,8 @@ print_expansions(struct edstate *e, int command)
int is_command;
nwords = x_cf_glob(XCF_COMMAND_FILE|XCF_FULLPATH,
- e->cbuf, e->linelen, e->cursor,
- &start, &end, &words, &is_command);
+ e->cbuf, e->linelen, e->cursor,
+ &start, &end, &words, &is_command);
if (nwords == 0) {
vi_error();
return -1;