remove some more of this ugliness

This commit is contained in:
tg 2010-01-29 09:34:31 +00:00
parent c67bed8790
commit 4eb17f8752
9 changed files with 109 additions and 84 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.358 2010/01/28 20:58:30 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.359 2010/01/29 09:34:25 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R39 2010/01/28
@(#)MIRBSD KSH R39 2010/01/29
description:
Check version of shell.
stdin:

6
edit.c
View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.188 2010/01/08 22:21:04 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.189 2010/01/29 09:34:26 tg Exp $");
/* tty driver characters we are interested in */
typedef struct {
@ -4034,7 +4034,7 @@ vi_cmd(int argcnt, const char *cmd)
case 'g':
if (!argcnt)
argcnt = hlast;
/* FALLTHRU */
/* FALLTHROUGH */
case 'G':
if (!argcnt)
argcnt = 1;
@ -4188,7 +4188,7 @@ vi_cmd(int argcnt, const char *cmd)
c3 = 1;
srchlen = 0;
lastsearch = *cmd;
/* FALLTHRU */
/* FALLTHROUGH */
case 'n':
case 'N':
if (lastsearch == ' ')

4
eval.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.81 2010/01/25 14:07:38 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.82 2010/01/29 09:34:27 tg Exp $");
/*
* string expansion
@ -551,7 +551,7 @@ expand(const char *cp, /* input word */
case '?':
f &= ~DOBLANK;
f |= DOTEMP_;
/* FALLTHRU */
/* FALLTHROUGH */
default:
/* Enable tilde expansion */
tilde_ok = 1;

View File

@ -26,7 +26,7 @@
#include <sys/file.h>
#endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.91 2010/01/25 16:12:55 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.92 2010/01/29 09:34:28 tg Exp $");
/*-
* MirOS: This is the default mapping type, and need not be specified.
@ -790,8 +790,10 @@ hist_count_lines(unsigned char *base, int bytes)
case sn4:
state = sline; break;
case sline:
if (*base == '\0')
lines++, state = shdr;
if (*base == '\0') {
lines++;
state = shdr;
}
}
base++;
}

137
lex.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.106 2010/01/28 20:58:32 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.107 2010/01/29 09:34:28 tg Exp $");
/*
* states while lexing word
@ -206,7 +206,8 @@ yylex(int cf)
if (cf&ONEWORD)
state = SWORD;
else if (cf&LETEXPR) {
*wp++ = OQUOTE; /* enclose arguments in (double) quotes */
/* enclose arguments in (double) quotes */
*wp++ = OQUOTE;
state = SLETPAREN;
statep->ls_sletparen.nparen = 0;
#ifndef MKSH_SMALL
@ -273,7 +274,7 @@ yylex(int cf)
/* FALLTHROUGH */
case SBASE:
if (c == '[' && (cf & (VARASN|ARRAYVAR))) {
*wp = EOS; /* temporary */
*wp = EOS; /* temporary */
if (is_wdvarname(Xstring(ws, wp), false)) {
char *p, *tmp;
@ -302,7 +303,7 @@ yylex(int cf)
*wp++ = c;
break;
}
/* FALLTHRU */
/* FALLTHROUGH */
Sbase1: /* includes *(...|...) pattern (*+?@!) */
if (c == '*' || c == '@' || c == '+' || c == '?' ||
c == '!') {
@ -315,13 +316,16 @@ yylex(int cf)
}
ungetsc(c2);
}
/* FALLTHRU */
/* FALLTHROUGH */
Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */
switch (c) {
case '\\':
c = getsc();
if (c) /* trailing \ is lost */
*wp++ = QCHAR, *wp++ = c;
if (c) {
/* trailing \ is lost */
*wp++ = QCHAR;
*wp++ = c;
}
break;
case '\'':
*wp++ = OQUOTE;
@ -348,14 +352,18 @@ yylex(int cf)
/* FALLTHROUGH */
case '\\':
case '$': case '`':
*wp++ = QCHAR, *wp++ = c;
*wp++ = QCHAR;
*wp++ = c;
break;
default:
heredocquote:
Xcheck(ws, wp);
if (c) { /* trailing \ is lost */
*wp++ = CHAR, *wp++ = '\\';
*wp++ = CHAR, *wp++ = c;
if (c) {
/* trailing \ is lost */
*wp++ = CHAR;
*wp++ = '\\';
*wp++ = CHAR;
*wp++ = c;
}
break;
}
@ -384,7 +392,8 @@ yylex(int cf)
c = getsc();
/* allow :# and :% (ksh88 compat) */
if (c == ':') {
*wp++ = CHAR, *wp++ = c;
*wp++ = CHAR;
*wp++ = c;
c = getsc();
if (c == ':') {
*wp++ = CHAR;
@ -416,7 +425,8 @@ yylex(int cf)
break;
}
} else if (c == '/') {
*wp++ = CHAR, *wp++ = c;
*wp++ = CHAR;
*wp++ = c;
if ((c = getsc()) == '/') {
*wp++ = ADELIM;
*wp++ = c;
@ -468,7 +478,8 @@ yylex(int cf)
statep->ls_sequote.got_NUL = false;
break;
} else {
*wp++ = CHAR, *wp++ = '$';
*wp++ = CHAR;
*wp++ = '$';
ungetsc(c);
}
break;
@ -518,9 +529,10 @@ yylex(int cf)
*wp++ = getsc();
break;
}
/* FALLTHRU */
/* FALLTHROUGH */
default:
*wp++ = CHAR, *wp++ = c;
*wp++ = CHAR;
*wp++ = c;
}
break;
@ -537,9 +549,10 @@ yylex(int cf)
if (!statep->ls_sequote.got_NUL) {
char ts[4];
if ((unsigned int)c2 < 0x100)
*wp++ = QCHAR, *wp++ = c2;
else {
if ((unsigned int)c2 < 0x100) {
*wp++ = QCHAR;
*wp++ = c2;
} else {
c = utf_wctomb(ts, c2 - 0x100);
ts[c] = 0;
for (c = 0; ts[c]; ++c) {
@ -548,8 +561,10 @@ yylex(int cf)
}
}
}
} else if (!statep->ls_sequote.got_NUL)
*wp++ = QCHAR, *wp++ = c;
} else if (!statep->ls_sequote.got_NUL) {
*wp++ = QCHAR;
*wp++ = c;
}
break;
case SSQUOTE:
@ -557,8 +572,10 @@ yylex(int cf)
POP_STATE();
*wp++ = CQUOTE;
ignore_backslash_newline--;
} else
*wp++ = QCHAR, *wp++ = c;
} else {
*wp++ = QCHAR;
*wp++ = c;
}
break;
case SDQUOTE:
@ -569,14 +586,14 @@ 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 '(':
statep->ls_scsparen.nparen++;
@ -597,19 +614,19 @@ yylex(int cf)
}
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--;
@ -618,12 +635,12 @@ yylex(int cf)
}
if (statep->ls_scsparen.nparen == 0) {
POP_STATE();
*wp++ = 0; /* end of COMSUB */
*wp++ = 0; /* end of COMSUB */
} else
*wp++ = c;
break;
case SASPAREN: /* $(( ... )) */
case SASPAREN: /* $(( ... )) */
/* XXX should nest using existing state machine
* (embed "...", $(...), etc.) */
if (c == '(')
@ -634,7 +651,8 @@ yylex(int cf)
/*(*/
if ((c2 = getsc()) == ')') {
POP_STATE();
*wp++ = 0; /* end of EXPRSUB */
/* end of EXPRSUB */
*wp++ = 0;
break;
} else {
char *s;
@ -702,9 +720,10 @@ yylex(int cf)
*wp++ = c;
break;
}
/* FALLTHRU */
/* FALLTHROUGH */
default:
if (c) { /* trailing \ is lost */
if (c) {
/* trailing \ is lost */
*wp++ = '\\';
*wp++ = c;
}
@ -760,14 +779,16 @@ yylex(int cf)
c = 0;
goto Done;
}
*wp++ = CHAR, *wp++ = c;
*wp++ = CHAR;
*wp++ = c;
break;
#endif
case SHERESTRING: /* <<< delimiter */
if (c == '\\') {
c = getsc();
if (c) { /* trailing \ is lost */
if (c) {
/* trailing \ is lost */
*wp++ = QCHAR;
*wp++ = c;
}
@ -810,7 +831,8 @@ yylex(int cf)
*/
if (c == '\\') {
c = getsc();
if (c) { /* trailing \ is lost */
if (c) {
/* trailing \ is lost */
*wp++ = QCHAR;
*wp++ = c;
}
@ -851,7 +873,8 @@ yylex(int cf)
case '$': case '`':
break;
default:
if (c) { /* trailing \ lost */
if (c) {
/* trailing \ lost */
*wp++ = CHAR;
*wp++ = '\\';
}
@ -1289,7 +1312,7 @@ getsc__(void)
continue;
case SREREAD:
if (s->start != s->ugbuf) /* yuck */
if (s->start != s->ugbuf) /* yuck */
afree(s->u.freeme, ATEMP);
source = s = s->next;
continue;
@ -1365,9 +1388,9 @@ getsc_line(Source *s)
if (!p || (xp = p, xp[-1] == '\n'))
break;
/* double buffer size */
xp++; /* move past null so doubling works... */
xp++; /* move past NUL so doubling works... */
XcheckN(s->xs, xp, Xlength(s->xs, xp));
xp--; /* ...and move back again */
xp--; /* ...and move back again */
}
/* flush any unwanted input so other programs/builtins
* can read it. Not very optimal, but less error prone
@ -1409,7 +1432,8 @@ getsc_line(Source *s)
s->start = s->str = cp;
strip_nuls(Xstring(s->xs, xp), Xlength(s->xs, xp));
/* Note: if input is all nulls, this is not eof */
if (Xlength(s->xs, xp) == 0) { /* EOF */
if (Xlength(s->xs, xp) == 0) {
/* EOF */
if (s->type == SFILE)
shf_fdclose(s->u.shf);
s->str = NULL;
@ -1435,7 +1459,7 @@ set_prompt(int to, Source *s)
cur_prompt = to;
switch (to) {
case PS1: /* command */
case PS1: /* command */
/* Substitute ! and !! here, before substitutions are done
* so ! in expanded variables are not expanded.
* NOTE: this is not what AT&T ksh does (it does it after
@ -1473,7 +1497,7 @@ set_prompt(int to, Source *s)
quitenv(NULL);
}
break;
case PS2: /* command continuation */
case PS2: /* command continuation */
prompt = str_val(global("PS2"));
break;
}
@ -1548,7 +1572,7 @@ get_brace_var(XString *wsp, char *wp)
{
enum parse_state {
PS_INITIAL, PS_SAW_HASH, PS_IDENT,
PS_NUMBER, PS_VAR1, PS_END
PS_NUMBER, PS_VAR1
} state;
char c;
@ -1562,7 +1586,7 @@ get_brace_var(XString *wsp, char *wp)
state = PS_SAW_HASH;
break;
}
/* FALLTHRU */
/* FALLTHROUGH */
case PS_SAW_HASH:
if (ksh_isalphx(c))
state = PS_IDENT;
@ -1571,11 +1595,10 @@ get_brace_var(XString *wsp, char *wp)
else if (ctype(c, C_VAR1))
state = PS_VAR1;
else
state = PS_END;
goto out;
break;
case PS_IDENT:
if (!ksh_isalnux(c)) {
state = PS_END;
if (c == '[') {
char *tmp, *p;
@ -1587,28 +1610,24 @@ get_brace_var(XString *wsp, char *wp)
*wp++ = *p++;
}
afree(tmp, ATEMP);
c = getsc(); /* the ] */
c = getsc(); /* the ] */
}
goto out;
}
break;
case PS_NUMBER:
if (!ksh_isdigit(c))
state = PS_END;
goto out;
break;
case PS_VAR1:
state = PS_END;
break;
case PS_END: /* keep gcc happy */
break;
}
if (state == PS_END) {
*wp++ = '\0'; /* end of variable part */
ungetsc(c);
break;
goto out;
}
Xcheck(*wsp, wp);
*wp++ = c;
}
out:
*wp++ = '\0'; /* end of variable part */
ungetsc(c);
return (wp);
}

8
main.c
View File

@ -33,7 +33,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.161 2010/01/28 15:18:48 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.162 2010/01/29 09:34:29 tg Exp $");
extern char **environ;
@ -505,7 +505,7 @@ include(const char *name, int argc, const char **argv, int intr_ok)
*/
if (intr_ok && (exstat - 128) != SIGTERM)
return (1);
/* FALLTHRU */
/* FALLTHROUGH */
case LEXIT:
case LLEAVE:
case LSHELL:
@ -585,7 +585,7 @@ shell(Source * volatile s, volatile int toplevel)
s->start = s->str = null;
break;
}
/* FALLTHRU */
/* FALLTHROUGH */
case LEXIT:
case LLEAVE:
case LRETURN:
@ -672,7 +672,7 @@ unwind(int i)
case E_NONE:
if (i == LINTR)
e->flags |= EF_FAKE_SIGDIE;
/* FALLTHRU */
/* FALLTHROUGH */
default:
quitenv(NULL);
}

8
misc.c
View File

@ -29,7 +29,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.137 2010/01/28 15:18:49 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.138 2010/01/29 09:34:29 tg Exp $");
unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */
@ -551,8 +551,10 @@ has_globbing(const char *xp, const char *xpe)
} else if (nest)
nest--;
}
/* else must be a MAGIC-MAGIC, or MAGIC-!, MAGIC--, MAGIC-]
MAGIC-{, MAGIC-,, MAGIC-} */
/*
* else must be a MAGIC-MAGIC, or MAGIC-!,
* MAGIC--, MAGIC-], MAGIC-{, MAGIC-, MAGIC-}
*/
}
return (saw_glob && !in_bracket && !nest);
}

12
sh.h
View File

@ -150,9 +150,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.379 2010/01/28 20:58:34 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.380 2010/01/29 09:34:30 tg Exp $");
#endif
#define MKSH_VERSION "R39 2010/01/28"
#define MKSH_VERSION "R39 2010/01/29"
#ifndef MKSH_INCLUDES_ONLY
@ -797,9 +797,11 @@ EXTERN mksh_ari_t x_lins I__(-1); /* tty lines */
int shf_getc(struct shf *);
int shf_putc(int, struct shf *);
#else
#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)) : \
#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)))
#endif
#define shf_eof(shf) ((shf)->flags & SHF_EOF)

6
tree.c
View File

@ -1,7 +1,7 @@
/* $OpenBSD: tree.c,v 1.19 2008/08/11 21:50:35 jaredy Exp $ */
/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
* Thorsten Glaser <tg@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.28 2009/06/10 18:12:50 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.29 2010/01/29 09:34:31 tg Exp $");
#define INDENT 4
@ -95,7 +95,7 @@ ptree(struct op *t, int indent, struct shf *shf)
}
case TSELECT:
fptreef(shf, indent, "select %s ", t->str);
/* FALLTHRU */
/* FALLTHROUGH */
case TFOR:
if (t->type == TFOR)
fptreef(shf, indent, "for %s ", t->str);