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: 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 $
@ -3704,5 +3704,5 @@ category: pdksh
stdin:
echo $KSH_VERSION
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 $ */
#include "sh.h"
#include <ctype.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
* needed for each particular state. */
@ -97,7 +97,7 @@ static int ignore_backslash_newline;
int
yylex(int cf)
{
Lex_state states[STATE_BSIZE], *statep;
Lex_state states[STATE_BSIZE], *statep, *s2, *base;
State_info state_info;
int c, state;
XString ws; /* expandable output word */
@ -319,20 +319,20 @@ yylex(int cf)
* $ ` \.").
*/
statep->ls_sbquote.indquotes = 0;
Lex_state *s = statep;
Lex_state *base = state_info.base;
s2 = statep;
base = state_info.base;
while (1) {
for (; s != base; s--) {
if (s->ls_state == SDQUOTE) {
for (; s2 != base; s2--) {
if (s2->ls_state == SDQUOTE) {
statep->ls_sbquote.indquotes = 1;
break;
}
}
if (s != base)
if (s2 != base)
break;
if (!(s = s->ls_info.base))
if (!(s2 = s2->ls_info.base))
break;
base = s-- - STATE_BSIZE;
base = s2-- - STATE_BSIZE;
}
break;
case QCHAR:

45
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: 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 $ */
@ -13,9 +13,9 @@
#include <time.h>
#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;
@ -67,6 +67,8 @@ main(int argc, char *argv[])
char **wp;
struct env env;
pid_t ppid;
struct tbl *vp;
struct stat s_stdin;
/* make sure argv[] is sane */
if (!*argv) {
@ -136,11 +138,9 @@ main(int argc, char *argv[])
/* Set PATH to def_path (will set the path global variable).
* (import of environment below will probably change this setting).
*/
{
struct tbl *vp = global("PATH");
/* setstr can't fail here */
setstr(vp, def_path, KSH_RETURN_ERROR);
}
vp = global("PATH");
/* setstr can't fail here */
setstr(vp, def_path, KSH_RETURN_ERROR);
/* Turn on nohup by default for now - will change to off
@ -150,7 +150,7 @@ main(int argc, char *argv[])
*/
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.
*/
Flag(FBRACEEXPAND) = 1;
@ -216,17 +216,12 @@ main(int argc, char *argv[])
kshgid = getgid();
safe_prompt = ksheuid ? "$ " : "# ";
{
struct tbl *vp = global("PS1");
/* 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), '#')))
/* setstr can't fail here */
setstr(vp, safe_prompt, KSH_RETURN_ERROR);
}
vp = global("PS1");
/* Set PS1 if unset or we are root and prompt doesn't contain a # */
if (!(vp->flag & ISSET) ||
(!ksheuid && !strchr(str_val(vp), '#')))
/* setstr can't fail here */
setstr(vp, safe_prompt, KSH_RETURN_ERROR);
/* Set this before parsing arguments */
Flag(FPRIVILEGED) = kshuid != ksheuid || kshgid != kshegid;
@ -268,13 +263,9 @@ main(int argc, char *argv[])
}
/* This bizarreness is mandated by POSIX */
{
struct stat s_stdin;
if (fstat(0, &s_stdin) >= 0 && S_ISCHR(s_stdin.st_mode) &&
Flag(FTALKING))
reset_nonblock(0);
}
if (fstat(0, &s_stdin) >= 0 && S_ISCHR(s_stdin.st_mode) &&
Flag(FTALKING))
reset_nonblock(0);
/* initialize job control */
i = Flag(FMONITOR) != 127;