svn commit: r253650 - head/bin/sh
Jilles Tjoelker
jilles at FreeBSD.org
Thu Jul 25 15:08:44 UTC 2013
Author: jilles
Date: Thu Jul 25 15:08:41 2013
New Revision: 253650
URL: http://svnweb.freebsd.org/changeset/base/253650
Log:
sh: Remove mkinit.
Replace the RESET blocks with regular functions and a reset() function that
calls them all.
This code generation tool is unusual and does not appear to provide much
benefit. I do not think isolating the knowledge about which modules need to
be reset is worth an almost 500-line build tool and wider scope for
variables used by the reset functions.
Also, relying on reset functions is often wrong: the cleanup should be done
in exception handlers so that no stale state remains after 'command eval'
and the like.
Deleted:
head/bin/sh/init.h
head/bin/sh/mkinit.c
Modified:
head/bin/sh/Makefile
head/bin/sh/TOUR
head/bin/sh/eval.c
head/bin/sh/eval.h
head/bin/sh/exec.c
head/bin/sh/input.c
head/bin/sh/input.h
head/bin/sh/main.c
head/bin/sh/parser.c
head/bin/sh/parser.h
head/bin/sh/redir.c
head/bin/sh/redir.h
Modified: head/bin/sh/Makefile
==============================================================================
--- head/bin/sh/Makefile Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/Makefile Thu Jul 25 15:08:41 2013 (r253650)
@@ -8,7 +8,7 @@ SHSRCS= alias.c arith_yacc.c arith_yylex
histedit.c input.c jobs.c kill.c mail.c main.c memalloc.c miscbltin.c \
mystring.c options.c output.c parser.c printf.c redir.c show.c \
test.c trap.c var.c
-GENSRCS= builtins.c init.c nodes.c syntax.c
+GENSRCS= builtins.c nodes.c syntax.c
GENHDRS= builtins.h nodes.h syntax.h token.h
SRCS= ${SHSRCS} ${GENSRCS} ${GENHDRS}
@@ -30,26 +30,21 @@ WFORMAT=0
${.CURDIR}/../test \
${.CURDIR}/../../usr.bin/printf
-CLEANFILES+= mkinit mkinit.o mknodes mknodes.o \
+CLEANFILES+= mknodes mknodes.o \
mksyntax mksyntax.o
CLEANFILES+= ${GENSRCS} ${GENHDRS}
-build-tools: mkinit mknodes mksyntax
+build-tools: mknodes mksyntax
.ORDER: builtins.c builtins.h
builtins.c builtins.h: mkbuiltins builtins.def
sh ${.CURDIR}/mkbuiltins ${.CURDIR}
-init.c: mkinit alias.c eval.c exec.c input.c jobs.c options.c parser.c \
- redir.c trap.c var.c
- ./mkinit ${.ALLSRC:S/^mkinit$//}
-
# XXX this is just to stop the default .c rule being used, so that the
# intermediate object has a fixed name.
# XXX we have a default .c rule, but no default .o rule.
.o:
${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
-mkinit: mkinit.o
mknodes: mknodes.o
mksyntax: mksyntax.o
Modified: head/bin/sh/TOUR
==============================================================================
--- head/bin/sh/TOUR Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/TOUR Thu Jul 25 15:08:41 2013 (r253650)
@@ -25,38 +25,11 @@ programs is:
program input files generates
------- ----------- ---------
mkbuiltins builtins builtins.h builtins.c
- mkinit *.c init.c
mknodes nodetypes nodes.h nodes.c
mksyntax - syntax.h syntax.c
mktokens - token.h
-There are undoubtedly too many of these. Mkinit searches all the
-C source files for entries looking like:
-
- RESET {
- x = 2; /* executed when the shell does a longjmp
- back to the main command loop */
- }
-
-It pulls this code out into routines which are when particular
-events occur. The intent is to improve modularity by isolating
-the information about which modules need to be explicitly
-initialized/reset within the modules themselves.
-
-Mkinit recognizes several constructs for placing declarations in
-the init.c file.
- INCLUDE "file.h"
-includes a file. The storage class MKINIT makes a declaration
-available in the init.c file, for example:
- MKINIT int funcnest; /* depth of function calls */
-MKINIT alone on a line introduces a structure or union declara-
-tion:
- MKINIT
- struct redirtab {
- short renamed[10];
- };
-Preprocessor #define statements are copied to init.c without any
-special action to request this.
+There are undoubtedly too many of these.
EXCEPTIONS: Code for dealing with exceptions appears in
exceptions.c. The C language doesn't include exception handling,
Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/eval.c Thu Jul 25 15:08:41 2013 (r253650)
@@ -104,16 +104,13 @@ static void prehash(union node *);
* Called to reset things after an exception.
*/
-#ifdef mkinit
-INCLUDE "eval.h"
-
-RESET {
+void
+reseteval(void)
+{
evalskip = 0;
loopnest = 0;
funcnest = 0;
}
-#endif
-
/*
Modified: head/bin/sh/eval.h
==============================================================================
--- head/bin/sh/eval.h Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/eval.h Thu Jul 25 15:08:41 2013 (r253650)
@@ -46,6 +46,8 @@ struct backcmd { /* result of evalbackc
struct job *jp; /* job structure for command */
};
+void reseteval(void);
+
/* flags in argument to evaltree/evalstring */
#define EV_EXIT 01 /* exit after evaluating tree */
#define EV_TESTED 02 /* exit status is checked; ignore -e flag */
Modified: head/bin/sh/exec.c
==============================================================================
--- head/bin/sh/exec.c Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/exec.c Thu Jul 25 15:08:41 2013 (r253650)
@@ -70,7 +70,6 @@ __FBSDID("$FreeBSD$");
#include "syntax.h"
#include "memalloc.h"
#include "error.h"
-#include "init.h"
#include "mystring.h"
#include "show.h"
#include "jobs.h"
Modified: head/bin/sh/input.c
==============================================================================
--- head/bin/sh/input.c Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/input.c Thu Jul 25 15:08:41 2013 (r253650)
@@ -108,15 +108,12 @@ static void pushfile(void);
static int preadfd(void);
static void popstring(void);
-#ifdef mkinit
-INCLUDE "input.h"
-INCLUDE "error.h"
-
-RESET {
+void
+resetinput(void)
+{
popallfiles();
parselleft = parsenleft = 0; /* clear input buffer */
}
-#endif
/*
Modified: head/bin/sh/input.h
==============================================================================
--- head/bin/sh/input.h Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/input.h Thu Jul 25 15:08:41 2013 (r253650)
@@ -47,6 +47,7 @@ extern const char *parsenextc; /* next c
struct alias;
struct parsefile;
+void resetinput(void);
char *pfgets(char *, int);
int pgetc(void);
int preadbuffer(void);
Modified: head/bin/sh/main.c
==============================================================================
--- head/bin/sh/main.c Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/main.c Thu Jul 25 15:08:41 2013 (r253650)
@@ -68,10 +68,10 @@ __FBSDID("$FreeBSD$");
#include "show.h"
#include "memalloc.h"
#include "error.h"
-#include "init.h"
#include "mystring.h"
#include "exec.h"
#include "cd.h"
+#include "redir.h"
#include "builtins.h"
int rootpid;
@@ -79,6 +79,7 @@ int rootshell;
struct jmploc main_handler;
int localeisutf8, initial_localeisutf8;
+static void reset(void);
static void cmdloop(int);
static void read_profile(const char *);
static char *find_dot_file(char *);
@@ -179,6 +180,14 @@ state4:
return 0;
}
+static void
+reset(void)
+{
+ reseteval();
+ resetinput();
+ resetparser();
+ resetredir();
+}
/*
* Read and execute commands. "Top" is nonzero for the top level command
Modified: head/bin/sh/parser.c
==============================================================================
--- head/bin/sh/parser.c Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/parser.c Thu Jul 25 15:08:41 2013 (r253650)
@@ -1819,13 +1819,13 @@ parsearith: {
} /* end of readtoken */
-
-#ifdef mkinit
-RESET {
+void
+resetparser(void)
+{
tokpushback = 0;
checkkwd = 0;
}
-#endif
+
/*
* Returns true if the text contains nothing to expand (no dollar signs
Modified: head/bin/sh/parser.h
==============================================================================
--- head/bin/sh/parser.h Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/parser.h Thu Jul 25 15:08:41 2013 (r253650)
@@ -79,6 +79,7 @@ extern const char *const parsekwd[];
union node *parsecmd(int);
void fixredir(union node *, const char *, int);
+void resetparser(void);
int goodname(const char *);
int isassignment(const char *);
char *getprompt(void *);
Modified: head/bin/sh/redir.c
==============================================================================
--- head/bin/sh/redir.c Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/redir.c Thu Jul 25 15:08:41 2013 (r253650)
@@ -324,16 +324,13 @@ popredir(void)
* Undo all redirections. Called on error or interrupt.
*/
-#ifdef mkinit
-
-INCLUDE "redir.h"
-
-RESET {
+void
+resetredir(void)
+{
while (redirlist)
popredir();
}
-#endif
/* Return true if fd 0 has already been redirected at least once. */
int
Modified: head/bin/sh/redir.h
==============================================================================
--- head/bin/sh/redir.h Thu Jul 25 13:09:17 2013 (r253649)
+++ head/bin/sh/redir.h Thu Jul 25 15:08:41 2013 (r253650)
@@ -40,6 +40,7 @@
union node;
void redirect(union node *, int);
void popredir(void);
+void resetredir(void);
int fd0_redirected_p(void);
void clearredir(void);
More information about the svn-src-head
mailing list