diff options
author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-08-29 07:29:30 +0000 |
---|---|---|
committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-08-29 07:29:30 +0000 |
commit | 311cf8f5f35b48d3ad77d052b12a5f1a0eaf8944 (patch) | |
tree | f15b6c928209cc41ad172054caa8831e618066b4 /shell | |
parent | d39815693f59827ce9be496281d6a86cb246acc7 (diff) | |
download | busybox-w32-311cf8f5f35b48d3ad77d052b12a5f1a0eaf8944.tar.gz busybox-w32-311cf8f5f35b48d3ad77d052b12a5f1a0eaf8944.tar.bz2 busybox-w32-311cf8f5f35b48d3ad77d052b12a5f1a0eaf8944.zip |
vodz, last patch 103
git-svn-id: svn://busybox.net/trunk/busybox@7278 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 109 |
1 files changed, 45 insertions, 64 deletions
diff --git a/shell/ash.c b/shell/ash.c index 547ad906b..ec33a106c 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -1625,9 +1625,8 @@ static int fmtstr(char *, size_t, const char *, ...) | |||
1625 | __attribute__((__format__(__printf__,3,4))); | 1625 | __attribute__((__format__(__printf__,3,4))); |
1626 | static void xwrite(int, const void *, size_t); | 1626 | static void xwrite(int, const void *, size_t); |
1627 | 1627 | ||
1628 | static int preverrout_fd; /* save fd2 before print debug if xflag is set. */ | ||
1628 | 1629 | ||
1629 | #define outerr(f) ferror(f) | ||
1630 | #define out2c(c) outcslow((c), stderr) | ||
1631 | 1630 | ||
1632 | static void out1str(const char *p) | 1631 | static void out1str(const char *p) |
1633 | { | 1632 | { |
@@ -1637,15 +1636,7 @@ static void out1str(const char *p) | |||
1637 | static void out2str(const char *p) | 1636 | static void out2str(const char *p) |
1638 | { | 1637 | { |
1639 | outstr(p, stderr); | 1638 | outstr(p, stderr); |
1640 | } | 1639 | flushout(stderr); |
1641 | |||
1642 | static void out1c(char c) | ||
1643 | { | ||
1644 | char s[2]; | ||
1645 | |||
1646 | s[0] = c; | ||
1647 | s[1] = 0; | ||
1648 | outstr(s, stdout); | ||
1649 | } | 1640 | } |
1650 | 1641 | ||
1651 | /* | 1642 | /* |
@@ -1988,6 +1979,7 @@ static int nextopt(const char *); | |||
1988 | 1979 | ||
1989 | /* flags passed to redirect */ | 1980 | /* flags passed to redirect */ |
1990 | #define REDIR_PUSH 01 /* save previous values of file descriptors */ | 1981 | #define REDIR_PUSH 01 /* save previous values of file descriptors */ |
1982 | #define REDIR_SAVEFD2 03 /* set preverrout */ | ||
1991 | 1983 | ||
1992 | union node; | 1984 | union node; |
1993 | static void redirect(union node *, int); | 1985 | static void redirect(union node *, int); |
@@ -2674,7 +2666,6 @@ static void evalcommand(union node *, int); | |||
2674 | static int evalbltin(const struct builtincmd *, int, char **); | 2666 | static int evalbltin(const struct builtincmd *, int, char **); |
2675 | static int evalfun(struct funcnode *, int, char **, int); | 2667 | static int evalfun(struct funcnode *, int, char **, int); |
2676 | static void prehash(union node *); | 2668 | static void prehash(union node *); |
2677 | static int eprintlist(struct strlist *, int); | ||
2678 | static int bltincmd(int, char **); | 2669 | static int bltincmd(int, char **); |
2679 | 2670 | ||
2680 | 2671 | ||
@@ -2765,7 +2756,7 @@ evaltree(union node *n, int flags) | |||
2765 | default: | 2756 | default: |
2766 | #ifdef DEBUG | 2757 | #ifdef DEBUG |
2767 | out1fmt("Node type = %d\n", n->type); | 2758 | out1fmt("Node type = %d\n", n->type); |
2768 | flushout(stdout); | 2759 | fflush(stdout); |
2769 | break; | 2760 | break; |
2770 | #endif | 2761 | #endif |
2771 | case NNOT: | 2762 | case NNOT: |
@@ -3201,7 +3192,7 @@ evalcommand(union node *cmd, int flags) | |||
3201 | struct arglist varlist; | 3192 | struct arglist varlist; |
3202 | char **argv; | 3193 | char **argv; |
3203 | int argc; | 3194 | int argc; |
3204 | struct strlist *sp; | 3195 | const struct strlist *sp; |
3205 | struct cmdentry cmdentry; | 3196 | struct cmdentry cmdentry; |
3206 | struct job *jp; | 3197 | struct job *jp; |
3207 | char *lastarg; | 3198 | char *lastarg; |
@@ -3244,8 +3235,9 @@ evalcommand(union node *cmd, int flags) | |||
3244 | if (iflag && funcnest == 0 && argc > 0) | 3235 | if (iflag && funcnest == 0 && argc > 0) |
3245 | lastarg = nargv[-1]; | 3236 | lastarg = nargv[-1]; |
3246 | 3237 | ||
3238 | preverrout_fd = 2; | ||
3247 | expredir(cmd->ncmd.redirect); | 3239 | expredir(cmd->ncmd.redirect); |
3248 | status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH); | 3240 | status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH|REDIR_SAVEFD2); |
3249 | 3241 | ||
3250 | path = vpath.text; | 3242 | path = vpath.text; |
3251 | for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) { | 3243 | for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) { |
@@ -3266,14 +3258,24 @@ evalcommand(union node *cmd, int flags) | |||
3266 | 3258 | ||
3267 | /* Print the command if xflag is set. */ | 3259 | /* Print the command if xflag is set. */ |
3268 | if (xflag) { | 3260 | if (xflag) { |
3269 | int sep; | 3261 | int n; |
3262 | const char *p = " %s"; | ||
3270 | 3263 | ||
3271 | out2str(ps4val()); | 3264 | p++; |
3272 | sep = 0; | 3265 | dprintf(preverrout_fd, p, ps4val()); |
3273 | sep = eprintlist(varlist.list, sep); | 3266 | |
3274 | eprintlist(arglist.list, sep); | 3267 | sp = varlist.list; |
3275 | out2c('\n'); | 3268 | for(n = 0; n < 2; n++) { |
3276 | flushall(); | 3269 | while (sp) { |
3270 | dprintf(preverrout_fd, p, sp->text); | ||
3271 | sp = sp->next; | ||
3272 | if(*p == '%') { | ||
3273 | p--; | ||
3274 | } | ||
3275 | } | ||
3276 | sp = arglist.list; | ||
3277 | } | ||
3278 | xwrite(preverrout_fd, "\n", 1); | ||
3277 | } | 3279 | } |
3278 | 3280 | ||
3279 | cmd_is_exec = 0; | 3281 | cmd_is_exec = 0; |
@@ -3418,7 +3420,7 @@ evalbltin(const struct builtincmd *cmd, int argc, char **argv) { | |||
3418 | exitstatus = (*cmd->builtin)(argc, argv); | 3420 | exitstatus = (*cmd->builtin)(argc, argv); |
3419 | flushall(); | 3421 | flushall(); |
3420 | cmddone: | 3422 | cmddone: |
3421 | exitstatus |= outerr(stdout); | 3423 | exitstatus |= ferror(stdout); |
3422 | commandname = savecmdname; | 3424 | commandname = savecmdname; |
3423 | exsig = 0; | 3425 | exsig = 0; |
3424 | handler = savehandler; | 3426 | handler = savehandler; |
@@ -3588,20 +3590,6 @@ execcmd(int argc, char **argv) | |||
3588 | } | 3590 | } |
3589 | 3591 | ||
3590 | 3592 | ||
3591 | static int | ||
3592 | eprintlist(struct strlist *sp, int sep) | ||
3593 | { | ||
3594 | while (sp) { | ||
3595 | const char *p; | ||
3596 | |||
3597 | p = " %s" + (1 - sep); | ||
3598 | sep |= 1; | ||
3599 | fprintf(stderr, p, sp->text); | ||
3600 | sp = sp->next; | ||
3601 | } | ||
3602 | |||
3603 | return sep; | ||
3604 | } | ||
3605 | /* $NetBSD: exec.c,v 1.35 2003/01/22 20:36:04 dsl Exp $ */ | 3593 | /* $NetBSD: exec.c,v 1.35 2003/01/22 20:36:04 dsl Exp $ */ |
3606 | 3594 | ||
3607 | /* | 3595 | /* |
@@ -3632,7 +3620,6 @@ static int builtinloc = -1; /* index in path of %builtin, or -1 */ | |||
3632 | 3620 | ||
3633 | 3621 | ||
3634 | static void tryexec(char *, char **, char **); | 3622 | static void tryexec(char *, char **, char **); |
3635 | static void printentry(struct tblentry *); | ||
3636 | static void clearcmdentry(int); | 3623 | static void clearcmdentry(int); |
3637 | static struct tblentry *cmdlookup(const char *, int); | 3624 | static struct tblentry *cmdlookup(const char *, int); |
3638 | static void delete_cmd_entry(void); | 3625 | static void delete_cmd_entry(void); |
@@ -3797,9 +3784,24 @@ padvance(const char **path, const char *name) | |||
3797 | } | 3784 | } |
3798 | 3785 | ||
3799 | 3786 | ||
3800 | |||
3801 | /*** Command hashing code ***/ | 3787 | /*** Command hashing code ***/ |
3802 | 3788 | ||
3789 | static void | ||
3790 | printentry(struct tblentry *cmdp) | ||
3791 | { | ||
3792 | int idx; | ||
3793 | const char *path; | ||
3794 | char *name; | ||
3795 | |||
3796 | idx = cmdp->param.index; | ||
3797 | path = pathval(); | ||
3798 | do { | ||
3799 | name = padvance(&path, cmdp->cmdname); | ||
3800 | stunalloc(name); | ||
3801 | } while (--idx >= 0); | ||
3802 | out1fmt("%s%s\n", name, (cmdp->rehash ? "*" : nullstr)); | ||
3803 | } | ||
3804 | |||
3803 | 3805 | ||
3804 | static int | 3806 | static int |
3805 | hashcmd(int argc, char **argv) | 3807 | hashcmd(int argc, char **argv) |
@@ -3838,25 +3840,6 @@ hashcmd(int argc, char **argv) | |||
3838 | } | 3840 | } |
3839 | 3841 | ||
3840 | 3842 | ||
3841 | static void | ||
3842 | printentry(struct tblentry *cmdp) | ||
3843 | { | ||
3844 | int idx; | ||
3845 | const char *path; | ||
3846 | char *name; | ||
3847 | |||
3848 | idx = cmdp->param.index; | ||
3849 | path = pathval(); | ||
3850 | do { | ||
3851 | name = padvance(&path, cmdp->cmdname); | ||
3852 | stunalloc(name); | ||
3853 | } while (--idx >= 0); | ||
3854 | out1str(name); | ||
3855 | out1fmt(snlfmt, cmdp->rehash ? "*" : nullstr); | ||
3856 | } | ||
3857 | |||
3858 | |||
3859 | |||
3860 | /* | 3843 | /* |
3861 | * Resolve a command name. If you change this routine, you may have to | 3844 | * Resolve a command name. If you change this routine, you may have to |
3862 | * change the shellexec routine as well. | 3845 | * change the shellexec routine as well. |
@@ -4401,7 +4384,7 @@ describe_command(char *command) | |||
4401 | } | 4384 | } |
4402 | 4385 | ||
4403 | out: | 4386 | out: |
4404 | out1c('\n'); | 4387 | outstr("\n", stdout); |
4405 | return 0; | 4388 | return 0; |
4406 | } | 4389 | } |
4407 | 4390 | ||
@@ -6155,7 +6138,6 @@ check: | |||
6155 | 6138 | ||
6156 | if (vflag) { | 6139 | if (vflag) { |
6157 | out2str(parsenextc); | 6140 | out2str(parsenextc); |
6158 | flushout(stderr); | ||
6159 | } | 6141 | } |
6160 | 6142 | ||
6161 | *q = savec; | 6143 | *q = savec; |
@@ -9208,9 +9190,8 @@ nextopt(const char *optstring) | |||
9208 | return c; | 9190 | return c; |
9209 | } | 9191 | } |
9210 | 9192 | ||
9211 | /* $NetBSD: output.c,v 1.27 2002/11/24 22:35:42 christos Exp $ */ | ||
9212 | |||
9213 | 9193 | ||
9194 | /* $NetBSD: output.c,v 1.27 2002/11/24 22:35:42 christos Exp $ */ | ||
9214 | 9195 | ||
9215 | void | 9196 | void |
9216 | outstr(const char *p, FILE *file) | 9197 | outstr(const char *p, FILE *file) |
@@ -9229,7 +9210,6 @@ flushall(void) | |||
9229 | INTON; | 9210 | INTON; |
9230 | } | 9211 | } |
9231 | 9212 | ||
9232 | |||
9233 | void | 9213 | void |
9234 | flushout(FILE *dest) | 9214 | flushout(FILE *dest) |
9235 | { | 9215 | { |
@@ -11119,6 +11099,8 @@ redirect(union node *redir, int flags) | |||
11119 | dupredirect(n, newfd); | 11099 | dupredirect(n, newfd); |
11120 | } while ((n = n->nfile.next)); | 11100 | } while ((n = n->nfile.next)); |
11121 | INTON; | 11101 | INTON; |
11102 | if (flags & REDIR_SAVEFD2 && sv && sv->renamed[2] >= 0) | ||
11103 | preverrout_fd = sv->renamed[2]; | ||
11122 | } | 11104 | } |
11123 | 11105 | ||
11124 | 11106 | ||
@@ -12544,7 +12526,6 @@ readcmd(int argc, char **argv) | |||
12544 | } | 12526 | } |
12545 | if (prompt && isatty(0)) { | 12527 | if (prompt && isatty(0)) { |
12546 | out2str(prompt); | 12528 | out2str(prompt); |
12547 | flushall(); | ||
12548 | } | 12529 | } |
12549 | if (*(ap = argptr) == NULL) | 12530 | if (*(ap = argptr) == NULL) |
12550 | error("arg count"); | 12531 | error("arg count"); |