aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-14 15:01:47 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-14 15:01:47 +0000
commit28bf671d6d92d0c2842bd5f4555f5af937a0a6db (patch)
tree2c4a7e733078ca46d6c14079f7a7a2b930ae3648
parentf1d93ec4206b50f7971f7df391dfc9bd52da8344 (diff)
downloadbusybox-w32-28bf671d6d92d0c2842bd5f4555f5af937a0a6db.tar.gz
busybox-w32-28bf671d6d92d0c2842bd5f4555f5af937a0a6db.tar.bz2
busybox-w32-28bf671d6d92d0c2842bd5f4555f5af937a0a6db.zip
ash: make ash -c 'if set -o barfoo 2>/dev/null; then echo foo; else echo bar; fi' work
(fixes bug 1142) function old new delta options 551 565 +14 ash_main 1397 1411 +14 setcmd 77 90 +13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 41/0) Total: 41 bytes
-rw-r--r--shell/ash.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 0634f1868..612172043 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9076,7 +9076,7 @@ setparam(char **argv)
9076 * Process shell options. The global variable argptr contains a pointer 9076 * Process shell options. The global variable argptr contains a pointer
9077 * to the argument list; we advance it past the options. 9077 * to the argument list; we advance it past the options.
9078 */ 9078 */
9079static void 9079static int
9080minus_o(char *name, int val) 9080minus_o(char *name, int val)
9081{ 9081{
9082 int i; 9082 int i;
@@ -9085,15 +9085,17 @@ minus_o(char *name, int val)
9085 for (i = 0; i < NOPTS; i++) { 9085 for (i = 0; i < NOPTS; i++) {
9086 if (strcmp(name, optnames(i)) == 0) { 9086 if (strcmp(name, optnames(i)) == 0) {
9087 optlist[i] = val; 9087 optlist[i] = val;
9088 return; 9088 return 0;
9089 } 9089 }
9090 } 9090 }
9091 ash_msg_and_raise_error("illegal option -o %s", name); 9091 ash_msg("illegal option -o %s", name);
9092 return 1;
9092 } 9093 }
9093 out1str("Current option settings\n"); 9094 out1str("Current option settings\n");
9094 for (i = 0; i < NOPTS; i++) 9095 for (i = 0; i < NOPTS; i++)
9095 out1fmt("%-16s%s\n", optnames(i), 9096 out1fmt("%-16s%s\n", optnames(i),
9096 optlist[i] ? "on" : "off"); 9097 optlist[i] ? "on" : "off");
9098 return 0;
9097} 9099}
9098static void 9100static void
9099setoption(int flag, int val) 9101setoption(int flag, int val)
@@ -9109,7 +9111,7 @@ setoption(int flag, int val)
9109 ash_msg_and_raise_error("illegal option -%c", flag); 9111 ash_msg_and_raise_error("illegal option -%c", flag);
9110 /* NOTREACHED */ 9112 /* NOTREACHED */
9111} 9113}
9112static void 9114static int
9113options(int cmdline) 9115options(int cmdline)
9114{ 9116{
9115 char *p; 9117 char *p;
@@ -9144,7 +9146,10 @@ options(int cmdline)
9144 if (c == 'c' && cmdline) { 9146 if (c == 'c' && cmdline) {
9145 minusc = p; /* command is after shell args */ 9147 minusc = p; /* command is after shell args */
9146 } else if (c == 'o') { 9148 } else if (c == 'o') {
9147 minus_o(*argptr, val); 9149 if (minus_o(*argptr, val)) {
9150 /* it already printed err message */
9151 return 1; /* error */
9152 }
9148 if (*argptr) 9153 if (*argptr)
9149 argptr++; 9154 argptr++;
9150 } else if (cmdline && (c == 'l')) { /* -l or +l == --login */ 9155 } else if (cmdline && (c == 'l')) { /* -l or +l == --login */
@@ -9159,6 +9164,7 @@ options(int cmdline)
9159 } 9164 }
9160 } 9165 }
9161 } 9166 }
9167 return 0;
9162} 9168}
9163 9169
9164/* 9170/*
@@ -9228,16 +9234,21 @@ showvars(const char *sep_prefix, int on, int off)
9228static int 9234static int
9229setcmd(int argc, char **argv) 9235setcmd(int argc, char **argv)
9230{ 9236{
9237 int retval;
9238
9231 if (argc == 1) 9239 if (argc == 1)
9232 return showvars(nullstr, 0, VUNSET); 9240 return showvars(nullstr, 0, VUNSET);
9233 INT_OFF; 9241 INT_OFF;
9234 options(0); 9242 retval = 1;
9235 optschanged(); 9243 if (!options(0)) { /* if no parse error... */
9236 if (*argptr != NULL) { 9244 retval = 0;
9237 setparam(argptr); 9245 optschanged();
9246 if (*argptr != NULL) {
9247 setparam(argptr);
9248 }
9238 } 9249 }
9239 INT_ON; 9250 INT_ON;
9240 return 0; 9251 return retval;
9241} 9252}
9242 9253
9243#if ENABLE_ASH_RANDOM_SUPPORT 9254#if ENABLE_ASH_RANDOM_SUPPORT
@@ -12790,7 +12801,10 @@ procargs(int argc, char **argv)
12790 for (i = 0; i < NOPTS; i++) 12801 for (i = 0; i < NOPTS; i++)
12791 optlist[i] = 2; 12802 optlist[i] = 2;
12792 argptr = xargv; 12803 argptr = xargv;
12793 options(1); 12804 if (options(1)) {
12805 /* it already printed err message */
12806 raise_exception(EXERROR);
12807 }
12794 xargv = argptr; 12808 xargv = argptr;
12795 xminusc = minusc; 12809 xminusc = minusc;
12796 if (*xargv == NULL) { 12810 if (*xargv == NULL) {