clean up code

This commit is contained in:
tg 2005-07-04 12:47:13 +00:00
parent 76c700b3a6
commit f11d5ff712
3 changed files with 30 additions and 39 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.20 2005/07/04 12:27:25 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.21 2005/07/04 12:47:13 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas 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: 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 $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -3704,5 +3704,5 @@ category: pdksh
stdin: stdin:
echo $KSH_VERSION echo $KSH_VERSION
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R23 2005/07/04 @(#)MIRBSD KSH R24 2005/07/04
--- ---

20
lex.c
View File

@ -1,11 +1,11 @@
/** $MirOS: src/bin/mksh/lex.c,v 1.6 2005/07/04 12:34:23 tg Exp $ */ /** $MirOS: src/bin/mksh/lex.c,v 1.7 2005/07/04 12:47:13 tg Exp $ */
/* $OpenBSD: lex.c,v 1.36 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: lex.c,v 1.36 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
#include <ctype.h> #include <ctype.h>
#include <libgen.h> #include <libgen.h>
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.6 2005/07/04 12:34:23 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.7 2005/07/04 12:47:13 tg Exp $");
/* Structure to keep track of the lexing state and the various pieces of info /* Structure to keep track of the lexing state and the various pieces of info
* needed for each particular state. */ * needed for each particular state. */
@ -97,7 +97,7 @@ static int ignore_backslash_newline;
int int
yylex(int cf) yylex(int cf)
{ {
Lex_state states[STATE_BSIZE], *statep; Lex_state states[STATE_BSIZE], *statep, *s2, *base;
State_info state_info; State_info state_info;
int c, state; int c, state;
XString ws; /* expandable output word */ XString ws; /* expandable output word */
@ -319,20 +319,20 @@ yylex(int cf)
* $ ` \."). * $ ` \.").
*/ */
statep->ls_sbquote.indquotes = 0; statep->ls_sbquote.indquotes = 0;
Lex_state *s = statep; s2 = statep;
Lex_state *base = state_info.base; base = state_info.base;
while (1) { while (1) {
for (; s != base; s--) { for (; s2 != base; s2--) {
if (s->ls_state == SDQUOTE) { if (s2->ls_state == SDQUOTE) {
statep->ls_sbquote.indquotes = 1; statep->ls_sbquote.indquotes = 1;
break; break;
} }
} }
if (s != base) if (s2 != base)
break; break;
if (!(s = s->ls_info.base)) if (!(s2 = s2->ls_info.base))
break; break;
base = s-- - STATE_BSIZE; base = s2-- - STATE_BSIZE;
} }
break; break;
case QCHAR: case QCHAR:

27
main.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/main.c,v 1.19 2005/07/04 12:34:23 tg Exp $ */ /** $MirOS: src/bin/mksh/main.c,v 1.20 2005/07/04 12:47:13 tg Exp $ */
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
@ -13,9 +13,9 @@
#include <time.h> #include <time.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.19 2005/07/04 12:34:23 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.20 2005/07/04 12:47:13 tg Exp $");
const char ksh_version[] = "@(#)MIRBSD KSH R23 2005/07/04"; const char ksh_version[] = "@(#)MIRBSD KSH R24 2005/07/04";
extern char **environ; extern char **environ;
@ -67,6 +67,8 @@ main(int argc, char *argv[])
char **wp; char **wp;
struct env env; struct env env;
pid_t ppid; pid_t ppid;
struct tbl *vp;
struct stat s_stdin;
/* make sure argv[] is sane */ /* make sure argv[] is sane */
if (!*argv) { if (!*argv) {
@ -136,11 +138,9 @@ main(int argc, char *argv[])
/* Set PATH to def_path (will set the path global variable). /* Set PATH to def_path (will set the path global variable).
* (import of environment below will probably change this setting). * (import of environment below will probably change this setting).
*/ */
{ vp = global("PATH");
struct tbl *vp = global("PATH");
/* setstr can't fail here */ /* setstr can't fail here */
setstr(vp, def_path, KSH_RETURN_ERROR); setstr(vp, def_path, KSH_RETURN_ERROR);
}
/* Turn on nohup by default for now - will change to off /* Turn on nohup by default for now - will change to off
@ -150,7 +150,7 @@ main(int argc, char *argv[])
*/ */
Flag(FNOHUP) = 1; Flag(FNOHUP) = 1;
/* Turn on brace expansion by default. At&t kshs that have /* Turn on brace expansion by default. AT&T kshs that have
* alternation always have it on. * alternation always have it on.
*/ */
Flag(FBRACEEXPAND) = 1; Flag(FBRACEEXPAND) = 1;
@ -216,17 +216,12 @@ main(int argc, char *argv[])
kshgid = getgid(); kshgid = getgid();
safe_prompt = ksheuid ? "$ " : "# "; safe_prompt = ksheuid ? "$ " : "# ";
{ vp = global("PS1");
struct tbl *vp = global("PS1"); /* Set PS1 if unset or we are root and prompt doesn't contain a # */
/* Set PS1 if it isn't set, or we are root and prompt doesn't
* contain a #.
*/
if (!(vp->flag & ISSET) || if (!(vp->flag & ISSET) ||
(!ksheuid && !strchr(str_val(vp), '#'))) (!ksheuid && !strchr(str_val(vp), '#')))
/* setstr can't fail here */ /* setstr can't fail here */
setstr(vp, safe_prompt, KSH_RETURN_ERROR); setstr(vp, safe_prompt, KSH_RETURN_ERROR);
}
/* Set this before parsing arguments */ /* Set this before parsing arguments */
Flag(FPRIVILEGED) = kshuid != ksheuid || kshgid != kshegid; Flag(FPRIVILEGED) = kshuid != ksheuid || kshgid != kshegid;
@ -268,13 +263,9 @@ main(int argc, char *argv[])
} }
/* This bizarreness is mandated by POSIX */ /* This bizarreness is mandated by POSIX */
{
struct stat s_stdin;
if (fstat(0, &s_stdin) >= 0 && S_ISCHR(s_stdin.st_mode) && if (fstat(0, &s_stdin) >= 0 && S_ISCHR(s_stdin.st_mode) &&
Flag(FTALKING)) Flag(FTALKING))
reset_nonblock(0); reset_nonblock(0);
}
/* initialize job control */ /* initialize job control */
i = Flag(FMONITOR) != 127; i = Flag(FMONITOR) != 127;