diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 13:08:20 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-14 13:08:20 +1000 |
commit | 6a6efd31038d7afe977e3059508ae863e65cbdf5 (patch) | |
tree | 5cd69a751e893b83176751c80fcea7a7afeed1ae /shell/ash.c | |
parent | a6a2325ecf402054132daae169f71edb0fb849e3 (diff) | |
parent | 29082231d0cb1a5b327de5d515b16f332d4dbdaf (diff) | |
download | busybox-w32-6a6efd31038d7afe977e3059508ae863e65cbdf5.tar.gz busybox-w32-6a6efd31038d7afe977e3059508ae863e65cbdf5.tar.bz2 busybox-w32-6a6efd31038d7afe977e3059508ae863e65cbdf5.zip |
Merge branch 'origin/master' (early part)
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/shell/ash.c b/shell/ash.c index 5ac2a1922..e0b15e343 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -64,9 +64,7 @@ | |||
64 | # define CLEAR_RANDOM_T(rnd) ((void)0) | 64 | # define CLEAR_RANDOM_T(rnd) ((void)0) |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | #define SKIP_definitions 1 | 67 | #include "NUM_APPLETS.h" |
68 | #include "applet_tables.h" | ||
69 | #undef SKIP_definitions | ||
70 | #if NUM_APPLETS == 1 | 68 | #if NUM_APPLETS == 1 |
71 | /* STANDALONE does not make sense, and won't compile */ | 69 | /* STANDALONE does not make sense, and won't compile */ |
72 | # undef CONFIG_FEATURE_SH_STANDALONE | 70 | # undef CONFIG_FEATURE_SH_STANDALONE |
@@ -5216,7 +5214,7 @@ openredirect(union node *redir) | |||
5216 | break; | 5214 | break; |
5217 | case NFROMTO: | 5215 | case NFROMTO: |
5218 | fname = redir->nfile.expfname; | 5216 | fname = redir->nfile.expfname; |
5219 | f = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0666); | 5217 | f = open(fname, O_RDWR|O_CREAT, 0666); |
5220 | if (f < 0) | 5218 | if (f < 0) |
5221 | goto ecreate; | 5219 | goto ecreate; |
5222 | break; | 5220 | break; |
@@ -6507,8 +6505,7 @@ subevalvar(char *p, char *str, int strloc, int subtype, | |||
6507 | char *startp; | 6505 | char *startp; |
6508 | char *loc; | 6506 | char *loc; |
6509 | char *rmesc, *rmescend; | 6507 | char *rmesc, *rmescend; |
6510 | IF_ASH_BASH_COMPAT(char *repl = NULL;) | 6508 | IF_ASH_BASH_COMPAT(const char *repl = NULL;) |
6511 | IF_ASH_BASH_COMPAT(char null = '\0';) | ||
6512 | IF_ASH_BASH_COMPAT(int pos, len, orig_len;) | 6509 | IF_ASH_BASH_COMPAT(int pos, len, orig_len;) |
6513 | int saveherefd = herefd; | 6510 | int saveherefd = herefd; |
6514 | int amount, workloc, resetloc; | 6511 | int amount, workloc, resetloc; |
@@ -6629,7 +6626,7 @@ subevalvar(char *p, char *str, int strloc, int subtype, | |||
6629 | if (!repl) { | 6626 | if (!repl) { |
6630 | repl = parse_sub_pattern(str, varflags & VSQUOTE); | 6627 | repl = parse_sub_pattern(str, varflags & VSQUOTE); |
6631 | if (!repl) | 6628 | if (!repl) |
6632 | repl = &null; | 6629 | repl = nullstr; |
6633 | } | 6630 | } |
6634 | 6631 | ||
6635 | /* If there's no pattern to match, return the expansion unmolested */ | 6632 | /* If there's no pattern to match, return the expansion unmolested */ |
@@ -6680,8 +6677,12 @@ subevalvar(char *p, char *str, int strloc, int subtype, | |||
6680 | idx = loc; | 6677 | idx = loc; |
6681 | } | 6678 | } |
6682 | 6679 | ||
6683 | for (loc = repl; *loc; loc++) { | 6680 | for (loc = (char*)repl; *loc; loc++) { |
6684 | char *restart_detect = stackblock(); | 6681 | char *restart_detect = stackblock(); |
6682 | if (quotes && *loc == '\\') { | ||
6683 | STPUTC(CTLESC, expdest); | ||
6684 | len++; | ||
6685 | } | ||
6685 | STPUTC(*loc, expdest); | 6686 | STPUTC(*loc, expdest); |
6686 | if (stackblock() != restart_detect) | 6687 | if (stackblock() != restart_detect) |
6687 | goto restart; | 6688 | goto restart; |
@@ -6691,6 +6692,10 @@ subevalvar(char *p, char *str, int strloc, int subtype, | |||
6691 | if (subtype == VSREPLACE) { | 6692 | if (subtype == VSREPLACE) { |
6692 | while (*idx) { | 6693 | while (*idx) { |
6693 | char *restart_detect = stackblock(); | 6694 | char *restart_detect = stackblock(); |
6695 | if (quotes && *idx == '\\') { | ||
6696 | STPUTC(CTLESC, expdest); | ||
6697 | len++; | ||
6698 | } | ||
6694 | STPUTC(*idx, expdest); | 6699 | STPUTC(*idx, expdest); |
6695 | if (stackblock() != restart_detect) | 6700 | if (stackblock() != restart_detect) |
6696 | goto restart; | 6701 | goto restart; |
@@ -6704,11 +6709,10 @@ subevalvar(char *p, char *str, int strloc, int subtype, | |||
6704 | /* We've put the replaced text into a buffer at workloc, now | 6709 | /* We've put the replaced text into a buffer at workloc, now |
6705 | * move it to the right place and adjust the stack. | 6710 | * move it to the right place and adjust the stack. |
6706 | */ | 6711 | */ |
6707 | startp = stackblock() + startloc; | ||
6708 | STPUTC('\0', expdest); | 6712 | STPUTC('\0', expdest); |
6709 | memmove(startp, stackblock() + workloc, len); | 6713 | startp = (char *)stackblock() + startloc; |
6710 | startp[len++] = '\0'; | 6714 | memmove(startp, (char *)stackblock() + workloc, len + 1); |
6711 | amount = expdest - ((char *)stackblock() + startloc + len - 1); | 6715 | amount = expdest - (startp + len); |
6712 | STADJUST(-amount, expdest); | 6716 | STADJUST(-amount, expdest); |
6713 | return startp; | 6717 | return startp; |
6714 | } | 6718 | } |
@@ -7008,7 +7012,7 @@ evalvar(char *p, int flags, struct strlist *var_str_list) | |||
7008 | */ | 7012 | */ |
7009 | STPUTC('\0', expdest); | 7013 | STPUTC('\0', expdest); |
7010 | patloc = expdest - (char *)stackblock(); | 7014 | patloc = expdest - (char *)stackblock(); |
7011 | if (0 == subevalvar(p, /* str: */ NULL, patloc, subtype, | 7015 | if (NULL == subevalvar(p, /* str: */ NULL, patloc, subtype, |
7012 | startloc, varflags, | 7016 | startloc, varflags, |
7013 | //TODO: | EXP_REDIR too? All other such places do it too | 7017 | //TODO: | EXP_REDIR too? All other such places do it too |
7014 | /* quotes: */ flags & (EXP_FULL | EXP_CASE), | 7018 | /* quotes: */ flags & (EXP_FULL | EXP_CASE), |
@@ -7171,13 +7175,11 @@ addfname(const char *name) | |||
7171 | exparg.lastp = &sp->next; | 7175 | exparg.lastp = &sp->next; |
7172 | } | 7176 | } |
7173 | 7177 | ||
7174 | static char *expdir; | ||
7175 | |||
7176 | /* | 7178 | /* |
7177 | * Do metacharacter (i.e. *, ?, [...]) expansion. | 7179 | * Do metacharacter (i.e. *, ?, [...]) expansion. |
7178 | */ | 7180 | */ |
7179 | static void | 7181 | static void |
7180 | expmeta(char *enddir, char *name) | 7182 | expmeta(char *expdir, char *enddir, char *name) |
7181 | { | 7183 | { |
7182 | char *p; | 7184 | char *p; |
7183 | const char *cp; | 7185 | const char *cp; |
@@ -7276,7 +7278,7 @@ expmeta(char *enddir, char *name) | |||
7276 | for (p = enddir, cp = dp->d_name; (*p++ = *cp++) != '\0';) | 7278 | for (p = enddir, cp = dp->d_name; (*p++ = *cp++) != '\0';) |
7277 | continue; | 7279 | continue; |
7278 | p[-1] = '/'; | 7280 | p[-1] = '/'; |
7279 | expmeta(p, endname); | 7281 | expmeta(expdir, p, endname); |
7280 | } | 7282 | } |
7281 | } | 7283 | } |
7282 | } | 7284 | } |
@@ -7358,6 +7360,7 @@ expandmeta(struct strlist *str /*, int flag*/) | |||
7358 | /* TODO - EXP_REDIR */ | 7360 | /* TODO - EXP_REDIR */ |
7359 | 7361 | ||
7360 | while (str) { | 7362 | while (str) { |
7363 | char *expdir; | ||
7361 | struct strlist **savelastp; | 7364 | struct strlist **savelastp; |
7362 | struct strlist *sp; | 7365 | struct strlist *sp; |
7363 | char *p; | 7366 | char *p; |
@@ -7374,8 +7377,7 @@ expandmeta(struct strlist *str /*, int flag*/) | |||
7374 | int i = strlen(str->text); | 7377 | int i = strlen(str->text); |
7375 | expdir = ckmalloc(i < 2048 ? 2048 : i); /* XXX */ | 7378 | expdir = ckmalloc(i < 2048 ? 2048 : i); /* XXX */ |
7376 | } | 7379 | } |
7377 | 7380 | expmeta(expdir, expdir, p); | |
7378 | expmeta(expdir, p); | ||
7379 | free(expdir); | 7381 | free(expdir); |
7380 | if (p != str->text) | 7382 | if (p != str->text) |
7381 | free(p); | 7383 | free(p); |
@@ -9547,19 +9549,15 @@ evalcommand(union node *cmd, int flags) | |||
9547 | /* Print the command if xflag is set. */ | 9549 | /* Print the command if xflag is set. */ |
9548 | if (xflag) { | 9550 | if (xflag) { |
9549 | int n; | 9551 | int n; |
9550 | const char *p = " %s"; | 9552 | const char *p = " %s" + 1; |
9551 | 9553 | ||
9552 | p++; | ||
9553 | fdprintf(preverrout_fd, p, expandstr(ps4val())); | 9554 | fdprintf(preverrout_fd, p, expandstr(ps4val())); |
9554 | |||
9555 | sp = varlist.list; | 9555 | sp = varlist.list; |
9556 | for (n = 0; n < 2; n++) { | 9556 | for (n = 0; n < 2; n++) { |
9557 | while (sp) { | 9557 | while (sp) { |
9558 | fdprintf(preverrout_fd, p, sp->text); | 9558 | fdprintf(preverrout_fd, p, sp->text); |
9559 | sp = sp->next; | 9559 | sp = sp->next; |
9560 | if (*p == '%') { | 9560 | p = " %s"; |
9561 | p--; | ||
9562 | } | ||
9563 | } | 9561 | } |
9564 | sp = arglist.list; | 9562 | sp = arglist.list; |
9565 | } | 9563 | } |