diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-14 01:59:53 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-14 01:59:53 +0000 |
commit | c7131c3e58c2cef17263d03ac542f7fbea1ce2db (patch) | |
tree | df7aa8e9b9d20752440de4b33f60fd716cf2b717 | |
parent | b15ebe46fc97d7a870a54249b617904bb4a5fb92 (diff) | |
download | busybox-w32-c7131c3e58c2cef17263d03ac542f7fbea1ce2db.tar.gz busybox-w32-c7131c3e58c2cef17263d03ac542f7fbea1ce2db.tar.bz2 busybox-w32-c7131c3e58c2cef17263d03ac542f7fbea1ce2db.zip |
ash: fix breakage introduced in rev 21481.
Fixes ash-vars/var_posix1.tests testsuite entry.
-rw-r--r-- | shell/ash.c | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/shell/ash.c b/shell/ash.c index 409d084cf..80241381b 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -5691,13 +5691,39 @@ static char * | |||
5691 | scanleft(char *startp, char *rmesc, char *rmescend ATTRIBUTE_UNUSED, char *str, int quotes, | 5691 | scanleft(char *startp, char *rmesc, char *rmescend ATTRIBUTE_UNUSED, char *str, int quotes, |
5692 | int zero) | 5692 | int zero) |
5693 | { | 5693 | { |
5694 | char *loc, *loc2, *full; | 5694 | // This commented out code was added by James Simmons <jsimmons@infradead.org> |
5695 | // as part of a larger change when he added support for ${var/a/b}. | ||
5696 | // However, it broke # and % operators: | ||
5697 | // | ||
5698 | //var=ababcdcd | ||
5699 | // ok bad | ||
5700 | //echo ${var#ab} abcdcd abcdcd | ||
5701 | //echo ${var##ab} abcdcd abcdcd | ||
5702 | //echo ${var#a*b} abcdcd ababcdcd (!) | ||
5703 | //echo ${var##a*b} cdcd cdcd | ||
5704 | //echo ${var#?} babcdcd ababcdcd (!) | ||
5705 | //echo ${var##?} babcdcd babcdcd | ||
5706 | //echo ${var#*} ababcdcd babcdcd (!) | ||
5707 | //echo ${var##*} | ||
5708 | //echo ${var%cd} ababcd ababcd | ||
5709 | //echo ${var%%cd} ababcd abab (!) | ||
5710 | //echo ${var%c*d} ababcd ababcd | ||
5711 | //echo ${var%%c*d} abab ababcdcd (!) | ||
5712 | //echo ${var%?} ababcdc ababcdc | ||
5713 | //echo ${var%%?} ababcdc ababcdcd (!) | ||
5714 | //echo ${var%*} ababcdcd ababcdcd | ||
5715 | //echo ${var%%*} | ||
5716 | // | ||
5717 | // Commenting it back out helped. Remove it completely if it really | ||
5718 | // is not needed. | ||
5719 | |||
5720 | char *loc, *loc2; //, *full; | ||
5695 | char c; | 5721 | char c; |
5696 | 5722 | ||
5697 | loc = startp; | 5723 | loc = startp; |
5698 | loc2 = rmesc; | 5724 | loc2 = rmesc; |
5699 | do { | 5725 | do { |
5700 | int match = strlen(str); | 5726 | int match; // = strlen(str); |
5701 | const char *s = loc2; | 5727 | const char *s = loc2; |
5702 | 5728 | ||
5703 | c = *loc2; | 5729 | c = *loc2; |
@@ -5705,23 +5731,24 @@ scanleft(char *startp, char *rmesc, char *rmescend ATTRIBUTE_UNUSED, char *str, | |||
5705 | *loc2 = '\0'; | 5731 | *loc2 = '\0'; |
5706 | s = rmesc; | 5732 | s = rmesc; |
5707 | } | 5733 | } |
5708 | 5734 | match = pmatch(str, s); // this line was deleted | |
5709 | // chop off end if its '*' | 5735 | |
5710 | full = strrchr(str, '*'); | 5736 | // // chop off end if its '*' |
5711 | if (full && full != str) | 5737 | // full = strrchr(str, '*'); |
5712 | match--; | 5738 | // if (full && full != str) |
5713 | 5739 | // match--; | |
5714 | // If str starts with '*' replace with s. | 5740 | // |
5715 | if ((*str == '*') && strlen(s) >= match) { | 5741 | // // If str starts with '*' replace with s. |
5716 | full = xstrdup(s); | 5742 | // if ((*str == '*') && strlen(s) >= match) { |
5717 | strncpy(full+strlen(s)-match+1, str+1, match-1); | 5743 | // full = xstrdup(s); |
5718 | } else | 5744 | // strncpy(full+strlen(s)-match+1, str+1, match-1); |
5719 | full = xstrndup(str, match); | 5745 | // } else |
5720 | match = strncmp(s, full, strlen(full)); | 5746 | // full = xstrndup(str, match); |
5721 | free(full); | 5747 | // match = strncmp(s, full, strlen(full)); |
5722 | 5748 | // free(full); | |
5749 | // | ||
5723 | *loc2 = c; | 5750 | *loc2 = c; |
5724 | if (!match) | 5751 | if (match) // if (!match) |
5725 | return loc; | 5752 | return loc; |
5726 | if (quotes && *loc == CTLESC) | 5753 | if (quotes && *loc == CTLESC) |
5727 | loc++; | 5754 | loc++; |