diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-22 13:16:23 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-22 13:16:23 +0000 |
commit | b07a49622975ec6f92c008388fc5cb1e6a9e25f4 (patch) | |
tree | 8d109825c9077aa36c77cfbbaf1196858bb26459 | |
parent | c87339d5848ef63cd2968cb20ca007b3c8978773 (diff) | |
download | busybox-w32-b07a49622975ec6f92c008388fc5cb1e6a9e25f4.tar.gz busybox-w32-b07a49622975ec6f92c008388fc5cb1e6a9e25f4.tar.bz2 busybox-w32-b07a49622975ec6f92c008388fc5cb1e6a9e25f4.zip |
ash: minor shrink (mostly smallints) and variable renaming
function old new delta
optschanged 85 91 +6
tryexec 115 118 +3
xxreadtoken 290 292 +2
raise_error_unexpected_syntax 75 77 +2
bltincmd 6 8 +2
parseheredoc 128 129 +1
static.is_interactive 4 1 -3
readtoken 156 153 -3
lasttoken 4 1 -3
evalcommand 1147 1144 -3
checkkwd 4 1 -3
back_exitstatus 4 1 -3
pipeline 282 276 -6
list 369 360 -9
ash_main 1402 1393 -9
options 616 606 -10
readtoken1 2823 2811 -12
parse_command 1529 1507 -22
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 6/12 up/down: 21/-91) Total: -70 bytes
text data bss dec hex filename
807603 611 6908 815122 c7012 busybox_old
807545 611 6900 815056 c6fd0 busybox_unstripped
-rw-r--r-- | shell/ash.c | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/shell/ash.c b/shell/ash.c index f8e4e7d45..7924c4dd9 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -184,9 +184,9 @@ struct globals_misc { | |||
184 | #define EXSIG 5 /* trapped signal in wait(1) */ | 184 | #define EXSIG 5 /* trapped signal in wait(1) */ |
185 | 185 | ||
186 | /* trap handler commands */ | 186 | /* trap handler commands */ |
187 | char *trap[NSIG]; | ||
188 | smallint isloginsh; | 187 | smallint isloginsh; |
189 | char nullstr[1]; /* zero length string */ | 188 | char *trap[NSIG]; |
189 | char nullstr[1]; /* zero length string */ | ||
190 | /* | 190 | /* |
191 | * Sigmode records the current value of the signal handlers for the various | 191 | * Sigmode records the current value of the signal handlers for the various |
192 | * modes. A value of zero means that the current handler is not known. | 192 | * modes. A value of zero means that the current handler is not known. |
@@ -216,8 +216,8 @@ extern struct globals_misc *const ash_ptr_to_globals_misc; | |||
216 | #define intpending (G_misc.intpending ) | 216 | #define intpending (G_misc.intpending ) |
217 | //#define exsig (G_misc.exsig ) | 217 | //#define exsig (G_misc.exsig ) |
218 | #define pendingsig (G_misc.pendingsig ) | 218 | #define pendingsig (G_misc.pendingsig ) |
219 | #define trap (G_misc.trap ) | ||
220 | #define isloginsh (G_misc.isloginsh) | 219 | #define isloginsh (G_misc.isloginsh) |
220 | #define trap (G_misc.trap ) | ||
221 | #define nullstr (G_misc.nullstr ) | 221 | #define nullstr (G_misc.nullstr ) |
222 | #define sigmode (G_misc.sigmode ) | 222 | #define sigmode (G_misc.sigmode ) |
223 | #define gotsig (G_misc.gotsig ) | 223 | #define gotsig (G_misc.gotsig ) |
@@ -1012,7 +1012,7 @@ struct parsefile { | |||
1012 | }; | 1012 | }; |
1013 | 1013 | ||
1014 | static struct parsefile basepf; /* top level input file */ | 1014 | static struct parsefile basepf; /* top level input file */ |
1015 | static struct parsefile *parsefile = &basepf; /* current input file */ | 1015 | static struct parsefile *g_parsefile = &basepf; /* current input file */ |
1016 | static int startlinno; /* line # where last token started */ | 1016 | static int startlinno; /* line # where last token started */ |
1017 | static char *commandname; /* currently executing command */ | 1017 | static char *commandname; /* currently executing command */ |
1018 | static struct strlist *cmdenviron; /* environment for builtin command */ | 1018 | static struct strlist *cmdenviron; /* environment for builtin command */ |
@@ -1028,7 +1028,7 @@ ash_vmsg(const char *msg, va_list ap) | |||
1028 | if (commandname) { | 1028 | if (commandname) { |
1029 | if (strcmp(arg0, commandname)) | 1029 | if (strcmp(arg0, commandname)) |
1030 | fprintf(stderr, "%s: ", commandname); | 1030 | fprintf(stderr, "%s: ", commandname); |
1031 | if (!iflag || parsefile->fd) | 1031 | if (!iflag || g_parsefile->fd) |
1032 | fprintf(stderr, "line %d: ", startlinno); | 1032 | fprintf(stderr, "line %d: ", startlinno); |
1033 | } | 1033 | } |
1034 | vfprintf(stderr, msg, ap); | 1034 | vfprintf(stderr, msg, ap); |
@@ -3261,10 +3261,10 @@ static int forkshell(struct job *, union node *, int); | |||
3261 | static int waitforjob(struct job *); | 3261 | static int waitforjob(struct job *); |
3262 | 3262 | ||
3263 | #if !JOBS | 3263 | #if !JOBS |
3264 | enum { jobctl = 0 }; | 3264 | enum { doing_jobctl = 0 }; |
3265 | #define setjobctl(on) do {} while (0) | 3265 | #define setjobctl(on) do {} while (0) |
3266 | #else | 3266 | #else |
3267 | static smallint jobctl; /* true if doing job control */ | 3267 | static smallint doing_jobctl; |
3268 | static void setjobctl(int); | 3268 | static void setjobctl(int); |
3269 | #endif | 3269 | #endif |
3270 | 3270 | ||
@@ -3562,7 +3562,7 @@ setjobctl(int on) | |||
3562 | int fd; | 3562 | int fd; |
3563 | int pgrp; | 3563 | int pgrp; |
3564 | 3564 | ||
3565 | if (on == jobctl || rootshell == 0) | 3565 | if (on == doing_jobctl || rootshell == 0) |
3566 | return; | 3566 | return; |
3567 | if (on) { | 3567 | if (on) { |
3568 | int ofd; | 3568 | int ofd; |
@@ -3621,7 +3621,7 @@ setjobctl(int on) | |||
3621 | fd = -1; | 3621 | fd = -1; |
3622 | } | 3622 | } |
3623 | ttyfd = fd; | 3623 | ttyfd = fd; |
3624 | jobctl = on; | 3624 | doing_jobctl = on; |
3625 | } | 3625 | } |
3626 | 3626 | ||
3627 | static int | 3627 | static int |
@@ -3785,7 +3785,7 @@ static int | |||
3785 | waitproc(int wait_flags, int *status) | 3785 | waitproc(int wait_flags, int *status) |
3786 | { | 3786 | { |
3787 | #if JOBS | 3787 | #if JOBS |
3788 | if (jobctl) | 3788 | if (doing_jobctl) |
3789 | wait_flags |= WUNTRACED; | 3789 | wait_flags |= WUNTRACED; |
3790 | #endif | 3790 | #endif |
3791 | /* NB: _not_ safe_waitpid, we need to detect EINTR */ | 3791 | /* NB: _not_ safe_waitpid, we need to detect EINTR */ |
@@ -4151,7 +4151,7 @@ makejob(/*union node *node,*/ int nprocs) | |||
4151 | if (jp->state != JOBDONE || !jp->waited) | 4151 | if (jp->state != JOBDONE || !jp->waited) |
4152 | continue; | 4152 | continue; |
4153 | #if JOBS | 4153 | #if JOBS |
4154 | if (jobctl) | 4154 | if (doing_jobctl) |
4155 | continue; | 4155 | continue; |
4156 | #endif | 4156 | #endif |
4157 | freejob(jp); | 4157 | freejob(jp); |
@@ -4161,7 +4161,7 @@ makejob(/*union node *node,*/ int nprocs) | |||
4161 | #if JOBS | 4161 | #if JOBS |
4162 | /* jp->jobctl is a bitfield. | 4162 | /* jp->jobctl is a bitfield. |
4163 | * "jp->jobctl |= jobctl" likely to give awful code */ | 4163 | * "jp->jobctl |= jobctl" likely to give awful code */ |
4164 | if (jobctl) | 4164 | if (doing_jobctl) |
4165 | jp->jobctl = 1; | 4165 | jp->jobctl = 1; |
4166 | #endif | 4166 | #endif |
4167 | jp->prev_job = curjob; | 4167 | jp->prev_job = curjob; |
@@ -4513,7 +4513,7 @@ forkchild(struct job *jp, /*union node *n,*/ int mode) | |||
4513 | clear_traps(); | 4513 | clear_traps(); |
4514 | #if JOBS | 4514 | #if JOBS |
4515 | /* do job control only in root shell */ | 4515 | /* do job control only in root shell */ |
4516 | jobctl = 0; | 4516 | doing_jobctl = 0; |
4517 | if (mode != FORK_NOJOB && jp->jobctl && !oldlvl) { | 4517 | if (mode != FORK_NOJOB && jp->jobctl && !oldlvl) { |
4518 | pid_t pgrp; | 4518 | pid_t pgrp; |
4519 | 4519 | ||
@@ -4584,7 +4584,7 @@ forkparent(struct job *jp, union node *n, int mode, pid_t pid) | |||
4584 | ps->status = -1; | 4584 | ps->status = -1; |
4585 | ps->cmd = nullstr; | 4585 | ps->cmd = nullstr; |
4586 | #if JOBS | 4586 | #if JOBS |
4587 | if (jobctl && n) | 4587 | if (doing_jobctl && n) |
4588 | ps->cmd = commandtext(n); | 4588 | ps->cmd = commandtext(n); |
4589 | #endif | 4589 | #endif |
4590 | } | 4590 | } |
@@ -5359,13 +5359,13 @@ exptilde(char *startp, char *p, int flag) | |||
5359 | */ | 5359 | */ |
5360 | struct backcmd { /* result of evalbackcmd */ | 5360 | struct backcmd { /* result of evalbackcmd */ |
5361 | int fd; /* file descriptor to read from */ | 5361 | int fd; /* file descriptor to read from */ |
5362 | char *buf; /* buffer */ | ||
5363 | int nleft; /* number of chars in buffer */ | 5362 | int nleft; /* number of chars in buffer */ |
5363 | char *buf; /* buffer */ | ||
5364 | struct job *jp; /* job structure for command */ | 5364 | struct job *jp; /* job structure for command */ |
5365 | }; | 5365 | }; |
5366 | 5366 | ||
5367 | /* These forward decls are needed to use "eval" code for backticks handling: */ | 5367 | /* These forward decls are needed to use "eval" code for backticks handling: */ |
5368 | static int back_exitstatus; /* exit status of backquoted command */ | 5368 | static smalluint back_exitstatus; /* exit status of backquoted command */ |
5369 | #define EV_EXIT 01 /* exit after evaluating tree */ | 5369 | #define EV_EXIT 01 /* exit after evaluating tree */ |
5370 | static void evaltree(union node *, int); | 5370 | static void evaltree(union node *, int); |
5371 | 5371 | ||
@@ -6846,14 +6846,12 @@ static void find_command(char *, struct cmdentry *, int, const char *); | |||
6846 | * would make the command name "hash" a misnomer. | 6846 | * would make the command name "hash" a misnomer. |
6847 | */ | 6847 | */ |
6848 | 6848 | ||
6849 | #define ARB 1 /* actual size determined at run time */ | ||
6850 | |||
6851 | struct tblentry { | 6849 | struct tblentry { |
6852 | struct tblentry *next; /* next entry in hash chain */ | 6850 | struct tblentry *next; /* next entry in hash chain */ |
6853 | union param param; /* definition of builtin function */ | 6851 | union param param; /* definition of builtin function */ |
6854 | smallint cmdtype; /* CMDxxx */ | 6852 | smallint cmdtype; /* CMDxxx */ |
6855 | char rehash; /* if set, cd done since entry created */ | 6853 | char rehash; /* if set, cd done since entry created */ |
6856 | char cmdname[ARB]; /* name of command */ | 6854 | char cmdname[1]; /* name of command */ |
6857 | }; | 6855 | }; |
6858 | 6856 | ||
6859 | static struct tblentry **cmdtable; | 6857 | static struct tblentry **cmdtable; |
@@ -6888,22 +6886,25 @@ tryexec(USE_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char * | |||
6888 | #else | 6886 | #else |
6889 | execve(cmd, argv, envp); | 6887 | execve(cmd, argv, envp); |
6890 | #endif | 6888 | #endif |
6891 | if (repeated++) { | 6889 | if (repeated) { |
6892 | free(argv); | 6890 | free(argv); |
6893 | } else if (errno == ENOEXEC) { | 6891 | return; |
6892 | } | ||
6893 | if (errno == ENOEXEC) { | ||
6894 | char **ap; | 6894 | char **ap; |
6895 | char **new; | 6895 | char **new; |
6896 | 6896 | ||
6897 | for (ap = argv; *ap; ap++) | 6897 | for (ap = argv; *ap; ap++) |
6898 | ; | 6898 | continue; |
6899 | ap = new = ckmalloc((ap - argv + 2) * sizeof(char *)); | 6899 | ap = new = ckmalloc((ap - argv + 2) * sizeof(ap[0])); |
6900 | ap[1] = cmd; | 6900 | ap[1] = cmd; |
6901 | ap[0] = cmd = (char *)DEFAULT_SHELL; | 6901 | ap[0] = cmd = (char *)DEFAULT_SHELL; |
6902 | ap += 2; | 6902 | ap += 2; |
6903 | argv++; | 6903 | argv++; |
6904 | while ((*ap++ = *argv++)) | 6904 | while ((*ap++ = *argv++) != NULL) |
6905 | continue; | 6905 | continue; |
6906 | argv = new; | 6906 | argv = new; |
6907 | repeated++; | ||
6907 | goto repeat; | 6908 | goto repeat; |
6908 | } | 6909 | } |
6909 | } | 6910 | } |
@@ -7041,8 +7042,10 @@ cmdlookup(const char *name, int add) | |||
7041 | pp = &cmdp->next; | 7042 | pp = &cmdp->next; |
7042 | } | 7043 | } |
7043 | if (add && cmdp == NULL) { | 7044 | if (add && cmdp == NULL) { |
7044 | cmdp = *pp = ckzalloc(sizeof(struct tblentry) - ARB | 7045 | cmdp = *pp = ckzalloc(sizeof(struct tblentry) |
7045 | + strlen(name) + 1); | 7046 | + strlen(name) |
7047 | /* + 1 - already done because | ||
7048 | * tblentry::cmdname is char[1] */); | ||
7046 | /*cmdp->next = NULL; - ckzalloc did it */ | 7049 | /*cmdp->next = NULL; - ckzalloc did it */ |
7047 | cmdp->cmdtype = CMDUNKNOWN; | 7050 | cmdp->cmdtype = CMDUNKNOWN; |
7048 | strcpy(cmdp->cmdname, name); | 7051 | strcpy(cmdp->cmdname, name); |
@@ -7221,6 +7224,7 @@ changepath(const char *new) | |||
7221 | #define TWHILE 26 | 7224 | #define TWHILE 26 |
7222 | #define TBEGIN 27 | 7225 | #define TBEGIN 27 |
7223 | #define TEND 28 | 7226 | #define TEND 28 |
7227 | typedef smallint token_id_t; | ||
7224 | 7228 | ||
7225 | /* first char is indicating which tokens mark the end of a list */ | 7229 | /* first char is indicating which tokens mark the end of a list */ |
7226 | static const char *const tokname_array[] = { | 7230 | static const char *const tokname_array[] = { |
@@ -8137,7 +8141,7 @@ evalpipe(union node *n, int flags) | |||
8137 | static void | 8141 | static void |
8138 | setinteractive(int on) | 8142 | setinteractive(int on) |
8139 | { | 8143 | { |
8140 | static int is_interactive; | 8144 | static smallint is_interactive; |
8141 | 8145 | ||
8142 | if (++on == is_interactive) | 8146 | if (++on == is_interactive) |
8143 | return; | 8147 | return; |
@@ -8163,15 +8167,6 @@ setinteractive(int on) | |||
8163 | #endif | 8167 | #endif |
8164 | } | 8168 | } |
8165 | 8169 | ||
8166 | #if ENABLE_FEATURE_EDITING_VI | ||
8167 | #define setvimode(on) do { \ | ||
8168 | if (on) line_input_state->flags |= VI_MODE; \ | ||
8169 | else line_input_state->flags &= ~VI_MODE; \ | ||
8170 | } while (0) | ||
8171 | #else | ||
8172 | #define setvimode(on) viflag = 0 /* forcibly keep the option off */ | ||
8173 | #endif | ||
8174 | |||
8175 | static void | 8170 | static void |
8176 | optschanged(void) | 8171 | optschanged(void) |
8177 | { | 8172 | { |
@@ -8180,7 +8175,14 @@ optschanged(void) | |||
8180 | #endif | 8175 | #endif |
8181 | setinteractive(iflag); | 8176 | setinteractive(iflag); |
8182 | setjobctl(mflag); | 8177 | setjobctl(mflag); |
8183 | setvimode(viflag); | 8178 | #if ENABLE_FEATURE_EDITING_VI |
8179 | if (viflag) | ||
8180 | line_input_state->flags |= VI_MODE; | ||
8181 | else | ||
8182 | line_input_state->flags &= ~VI_MODE; | ||
8183 | #else | ||
8184 | viflag = 0; /* forcibly keep the option off */ | ||
8185 | #endif | ||
8184 | } | 8186 | } |
8185 | 8187 | ||
8186 | static struct localvar *localvars; | 8188 | static struct localvar *localvars; |
@@ -8558,7 +8560,6 @@ find_builtin(const char *name) | |||
8558 | /* | 8560 | /* |
8559 | * Execute a simple command. | 8561 | * Execute a simple command. |
8560 | */ | 8562 | */ |
8561 | static int back_exitstatus; /* exit status of backquoted command */ | ||
8562 | static int | 8563 | static int |
8563 | isassignment(const char *p) | 8564 | isassignment(const char *p) |
8564 | { | 8565 | { |
@@ -8916,7 +8917,7 @@ static int parselleft; /* copy of parsefile->lleft */ | |||
8916 | /* next character in input buffer */ | 8917 | /* next character in input buffer */ |
8917 | static char *parsenextc; /* copy of parsefile->nextc */ | 8918 | static char *parsenextc; /* copy of parsefile->nextc */ |
8918 | 8919 | ||
8919 | static int checkkwd; | 8920 | static smallint checkkwd; |
8920 | /* values of checkkwd variable */ | 8921 | /* values of checkkwd variable */ |
8921 | #define CHKALIAS 0x1 | 8922 | #define CHKALIAS 0x1 |
8922 | #define CHKKWD 0x2 | 8923 | #define CHKKWD 0x2 |
@@ -8925,7 +8926,7 @@ static int checkkwd; | |||
8925 | static void | 8926 | static void |
8926 | popstring(void) | 8927 | popstring(void) |
8927 | { | 8928 | { |
8928 | struct strpush *sp = parsefile->strpush; | 8929 | struct strpush *sp = g_parsefile->strpush; |
8929 | 8930 | ||
8930 | INT_OFF; | 8931 | INT_OFF; |
8931 | #if ENABLE_ASH_ALIAS | 8932 | #if ENABLE_ASH_ALIAS |
@@ -8945,8 +8946,8 @@ popstring(void) | |||
8945 | parsenextc = sp->prevstring; | 8946 | parsenextc = sp->prevstring; |
8946 | parsenleft = sp->prevnleft; | 8947 | parsenleft = sp->prevnleft; |
8947 | /*dprintf("*** calling popstring: restoring to '%s'\n", parsenextc);*/ | 8948 | /*dprintf("*** calling popstring: restoring to '%s'\n", parsenextc);*/ |
8948 | parsefile->strpush = sp->prev; | 8949 | g_parsefile->strpush = sp->prev; |
8949 | if (sp != &(parsefile->basestrpush)) | 8950 | if (sp != &(g_parsefile->basestrpush)) |
8950 | free(sp); | 8951 | free(sp); |
8951 | INT_ON; | 8952 | INT_ON; |
8952 | } | 8953 | } |
@@ -8955,13 +8956,13 @@ static int | |||
8955 | preadfd(void) | 8956 | preadfd(void) |
8956 | { | 8957 | { |
8957 | int nr; | 8958 | int nr; |
8958 | char *buf = parsefile->buf; | 8959 | char *buf = g_parsefile->buf; |
8959 | parsenextc = buf; | 8960 | parsenextc = buf; |
8960 | 8961 | ||
8961 | #if ENABLE_FEATURE_EDITING | 8962 | #if ENABLE_FEATURE_EDITING |
8962 | retry: | 8963 | retry: |
8963 | if (!iflag || parsefile->fd) | 8964 | if (!iflag || g_parsefile->fd) |
8964 | nr = nonblock_safe_read(parsefile->fd, buf, BUFSIZ - 1); | 8965 | nr = nonblock_safe_read(g_parsefile->fd, buf, BUFSIZ - 1); |
8965 | else { | 8966 | else { |
8966 | #if ENABLE_FEATURE_TAB_COMPLETION | 8967 | #if ENABLE_FEATURE_TAB_COMPLETION |
8967 | line_input_state->path_lookup = pathval(); | 8968 | line_input_state->path_lookup = pathval(); |
@@ -9020,9 +9021,9 @@ preadbuffer(void) | |||
9020 | int more; | 9021 | int more; |
9021 | char savec; | 9022 | char savec; |
9022 | 9023 | ||
9023 | while (parsefile->strpush) { | 9024 | while (g_parsefile->strpush) { |
9024 | #if ENABLE_ASH_ALIAS | 9025 | #if ENABLE_ASH_ALIAS |
9025 | if (parsenleft == -1 && parsefile->strpush->ap && | 9026 | if (parsenleft == -1 && g_parsefile->strpush->ap && |
9026 | parsenextc[-1] != ' ' && parsenextc[-1] != '\t') { | 9027 | parsenextc[-1] != ' ' && parsenextc[-1] != '\t') { |
9027 | return PEOA; | 9028 | return PEOA; |
9028 | } | 9029 | } |
@@ -9031,7 +9032,7 @@ preadbuffer(void) | |||
9031 | if (--parsenleft >= 0) | 9032 | if (--parsenleft >= 0) |
9032 | return signed_char2int(*parsenextc++); | 9033 | return signed_char2int(*parsenextc++); |
9033 | } | 9034 | } |
9034 | if (parsenleft == EOF_NLEFT || parsefile->buf == NULL) | 9035 | if (parsenleft == EOF_NLEFT || g_parsefile->buf == NULL) |
9035 | return PEOF; | 9036 | return PEOF; |
9036 | flush_stdout_stderr(); | 9037 | flush_stdout_stderr(); |
9037 | 9038 | ||
@@ -9172,12 +9173,12 @@ pushstring(char *s, struct alias *ap) | |||
9172 | len = strlen(s); | 9173 | len = strlen(s); |
9173 | INT_OFF; | 9174 | INT_OFF; |
9174 | /*dprintf("*** calling pushstring: %s, %d\n", s, len);*/ | 9175 | /*dprintf("*** calling pushstring: %s, %d\n", s, len);*/ |
9175 | if (parsefile->strpush) { | 9176 | if (g_parsefile->strpush) { |
9176 | sp = ckzalloc(sizeof(struct strpush)); | 9177 | sp = ckzalloc(sizeof(struct strpush)); |
9177 | sp->prev = parsefile->strpush; | 9178 | sp->prev = g_parsefile->strpush; |
9178 | parsefile->strpush = sp; | 9179 | g_parsefile->strpush = sp; |
9179 | } else | 9180 | } else |
9180 | sp = parsefile->strpush = &(parsefile->basestrpush); | 9181 | sp = g_parsefile->strpush = &(g_parsefile->basestrpush); |
9181 | sp->prevstring = parsenextc; | 9182 | sp->prevstring = parsenextc; |
9182 | sp->prevnleft = parsenleft; | 9183 | sp->prevnleft = parsenleft; |
9183 | #if ENABLE_ASH_ALIAS | 9184 | #if ENABLE_ASH_ALIAS |
@@ -9201,22 +9202,22 @@ pushfile(void) | |||
9201 | { | 9202 | { |
9202 | struct parsefile *pf; | 9203 | struct parsefile *pf; |
9203 | 9204 | ||
9204 | parsefile->nleft = parsenleft; | 9205 | g_parsefile->nleft = parsenleft; |
9205 | parsefile->lleft = parselleft; | 9206 | g_parsefile->lleft = parselleft; |
9206 | parsefile->nextc = parsenextc; | 9207 | g_parsefile->nextc = parsenextc; |
9207 | parsefile->linno = plinno; | 9208 | g_parsefile->linno = plinno; |
9208 | pf = ckzalloc(sizeof(*pf)); | 9209 | pf = ckzalloc(sizeof(*pf)); |
9209 | pf->prev = parsefile; | 9210 | pf->prev = g_parsefile; |
9210 | pf->fd = -1; | 9211 | pf->fd = -1; |
9211 | /*pf->strpush = NULL; - ckzalloc did it */ | 9212 | /*pf->strpush = NULL; - ckzalloc did it */ |
9212 | /*pf->basestrpush.prev = NULL;*/ | 9213 | /*pf->basestrpush.prev = NULL;*/ |
9213 | parsefile = pf; | 9214 | g_parsefile = pf; |
9214 | } | 9215 | } |
9215 | 9216 | ||
9216 | static void | 9217 | static void |
9217 | popfile(void) | 9218 | popfile(void) |
9218 | { | 9219 | { |
9219 | struct parsefile *pf = parsefile; | 9220 | struct parsefile *pf = g_parsefile; |
9220 | 9221 | ||
9221 | INT_OFF; | 9222 | INT_OFF; |
9222 | if (pf->fd >= 0) | 9223 | if (pf->fd >= 0) |
@@ -9224,12 +9225,12 @@ popfile(void) | |||
9224 | free(pf->buf); | 9225 | free(pf->buf); |
9225 | while (pf->strpush) | 9226 | while (pf->strpush) |
9226 | popstring(); | 9227 | popstring(); |
9227 | parsefile = pf->prev; | 9228 | g_parsefile = pf->prev; |
9228 | free(pf); | 9229 | free(pf); |
9229 | parsenleft = parsefile->nleft; | 9230 | parsenleft = g_parsefile->nleft; |
9230 | parselleft = parsefile->lleft; | 9231 | parselleft = g_parsefile->lleft; |
9231 | parsenextc = parsefile->nextc; | 9232 | parsenextc = g_parsefile->nextc; |
9232 | plinno = parsefile->linno; | 9233 | plinno = g_parsefile->linno; |
9233 | INT_ON; | 9234 | INT_ON; |
9234 | } | 9235 | } |
9235 | 9236 | ||
@@ -9239,7 +9240,7 @@ popfile(void) | |||
9239 | static void | 9240 | static void |
9240 | popallfiles(void) | 9241 | popallfiles(void) |
9241 | { | 9242 | { |
9242 | while (parsefile != &basepf) | 9243 | while (g_parsefile != &basepf) |
9243 | popfile(); | 9244 | popfile(); |
9244 | } | 9245 | } |
9245 | 9246 | ||
@@ -9251,9 +9252,9 @@ static void | |||
9251 | closescript(void) | 9252 | closescript(void) |
9252 | { | 9253 | { |
9253 | popallfiles(); | 9254 | popallfiles(); |
9254 | if (parsefile->fd > 0) { | 9255 | if (g_parsefile->fd > 0) { |
9255 | close(parsefile->fd); | 9256 | close(g_parsefile->fd); |
9256 | parsefile->fd = 0; | 9257 | g_parsefile->fd = 0; |
9257 | } | 9258 | } |
9258 | } | 9259 | } |
9259 | 9260 | ||
@@ -9267,11 +9268,11 @@ setinputfd(int fd, int push) | |||
9267 | close_on_exec_on(fd); | 9268 | close_on_exec_on(fd); |
9268 | if (push) { | 9269 | if (push) { |
9269 | pushfile(); | 9270 | pushfile(); |
9270 | parsefile->buf = 0; | 9271 | g_parsefile->buf = 0; |
9271 | } | 9272 | } |
9272 | parsefile->fd = fd; | 9273 | g_parsefile->fd = fd; |
9273 | if (parsefile->buf == NULL) | 9274 | if (g_parsefile->buf == NULL) |
9274 | parsefile->buf = ckmalloc(IBUFSIZ); | 9275 | g_parsefile->buf = ckmalloc(IBUFSIZ); |
9275 | parselleft = parsenleft = 0; | 9276 | parselleft = parsenleft = 0; |
9276 | plinno = 1; | 9277 | plinno = 1; |
9277 | } | 9278 | } |
@@ -9316,7 +9317,7 @@ setinputstring(char *string) | |||
9316 | pushfile(); | 9317 | pushfile(); |
9317 | parsenextc = string; | 9318 | parsenextc = string; |
9318 | parsenleft = strlen(string); | 9319 | parsenleft = strlen(string); |
9319 | parsefile->buf = NULL; | 9320 | g_parsefile->buf = NULL; |
9320 | plinno = 1; | 9321 | plinno = 1; |
9321 | INT_ON; | 9322 | INT_ON; |
9322 | } | 9323 | } |
@@ -9766,20 +9767,28 @@ getoptscmd(int argc, char **argv) | |||
9766 | 9767 | ||
9767 | /* ============ Shell parser */ | 9768 | /* ============ Shell parser */ |
9768 | 9769 | ||
9769 | /* | 9770 | struct heredoc { |
9770 | * NEOF is returned by parsecmd when it encounters an end of file. It | 9771 | struct heredoc *next; /* next here document in list */ |
9771 | * must be distinct from NULL, so we use the address of a variable that | 9772 | union node *here; /* redirection node */ |
9772 | * happens to be handy. | 9773 | char *eofmark; /* string indicating end of input */ |
9773 | */ | 9774 | smallint striptabs; /* if set, strip leading tabs */ |
9775 | }; | ||
9776 | |||
9774 | static smallint tokpushback; /* last token pushed back */ | 9777 | static smallint tokpushback; /* last token pushed back */ |
9775 | #define NEOF ((union node *)&tokpushback) | ||
9776 | static smallint parsebackquote; /* nonzero if we are inside backquotes */ | 9778 | static smallint parsebackquote; /* nonzero if we are inside backquotes */ |
9777 | static int lasttoken; /* last token read */ | 9779 | static smallint quoteflag; /* set if (part of) last token was quoted */ |
9780 | static token_id_t lasttoken; /* last token read (integer id Txxx) */ | ||
9781 | static struct heredoc *heredoclist; /* list of here documents to read */ | ||
9778 | static char *wordtext; /* text of last word returned by readtoken */ | 9782 | static char *wordtext; /* text of last word returned by readtoken */ |
9779 | static struct nodelist *backquotelist; | 9783 | static struct nodelist *backquotelist; |
9780 | static union node *redirnode; | 9784 | static union node *redirnode; |
9781 | static struct heredoc *heredoc; | 9785 | static struct heredoc *heredoc; |
9782 | static smallint quoteflag; /* set if (part of) last token was quoted */ | 9786 | /* |
9787 | * NEOF is returned by parsecmd when it encounters an end of file. It | ||
9788 | * must be distinct from NULL, so we use the address of a variable that | ||
9789 | * happens to be handy. | ||
9790 | */ | ||
9791 | #define NEOF ((union node *)&tokpushback) | ||
9783 | 9792 | ||
9784 | static void raise_error_syntax(const char *) ATTRIBUTE_NORETURN; | 9793 | static void raise_error_syntax(const char *) ATTRIBUTE_NORETURN; |
9785 | static void | 9794 | static void |
@@ -9810,15 +9819,6 @@ raise_error_unexpected_syntax(int token) | |||
9810 | 9819 | ||
9811 | #define EOFMARKLEN 79 | 9820 | #define EOFMARKLEN 79 |
9812 | 9821 | ||
9813 | struct heredoc { | ||
9814 | struct heredoc *next; /* next here document in list */ | ||
9815 | union node *here; /* redirection node */ | ||
9816 | char *eofmark; /* string indicating end of input */ | ||
9817 | int striptabs; /* if set, strip leading tabs */ | ||
9818 | }; | ||
9819 | |||
9820 | static struct heredoc *heredoclist; /* list of here documents to read */ | ||
9821 | |||
9822 | /* parsing is heavily cross-recursive, need these forward decls */ | 9822 | /* parsing is heavily cross-recursive, need these forward decls */ |
9823 | static union node *andor(void); | 9823 | static union node *andor(void); |
9824 | static union node *pipeline(void); | 9824 | static union node *pipeline(void); |
@@ -11391,7 +11391,7 @@ cmdloop(int top) | |||
11391 | 11391 | ||
11392 | setstackmark(&smark); | 11392 | setstackmark(&smark); |
11393 | #if JOBS | 11393 | #if JOBS |
11394 | if (jobctl) | 11394 | if (doing_jobctl) |
11395 | showjobs(stderr, SHOW_CHANGED); | 11395 | showjobs(stderr, SHOW_CHANGED); |
11396 | #endif | 11396 | #endif |
11397 | inter = 0; | 11397 | inter = 0; |