aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-12 23:29:57 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-12 23:29:57 +0100
commit03dad22f8a1b8b1410fdcccf69af1bb5cce4de7c (patch)
treeb134cbc7f0afbf76c54847624310e6a1d2774f83 /shell/hush.c
parent045f4ad92c07434625e168bc8c37aa0e89f6e58e (diff)
downloadbusybox-w32-03dad22f8a1b8b1410fdcccf69af1bb5cce4de7c.tar.gz
busybox-w32-03dad22f8a1b8b1410fdcccf69af1bb5cce4de7c.tar.bz2
busybox-w32-03dad22f8a1b8b1410fdcccf69af1bb5cce4de7c.zip
hush: use ash's read builtin
function old new delta shell_builtin_read - 1000 +1000 set_local_var_from_halves - 24 +24 setvar2 - 7 +7 ... popstring 140 134 -6 ash_main 1375 1368 -7 setvar 184 174 -10 arith_set_local_var 36 - -36 builtin_read 1096 185 -911 ------------------------------------------------------------------------------ (add/remove: 3/1 grow/shrink: 5/23 up/down: 1038/-1007) Total: 31 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c59
1 files changed, 37 insertions, 22 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 88a7b988a..bb0ab8408 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -84,6 +84,9 @@
84#if ENABLE_HUSH_CASE 84#if ENABLE_HUSH_CASE
85# include <fnmatch.h> 85# include <fnmatch.h>
86#endif 86#endif
87
88#include "shell_common.h"
89#include "builtin_read.h"
87#include "math.h" 90#include "math.h"
88#include "match.h" 91#include "match.h"
89#if ENABLE_HUSH_RANDOM_SUPPORT 92#if ENABLE_HUSH_RANDOM_SUPPORT
@@ -1307,7 +1310,7 @@ static struct variable *get_local_var(const char *name)
1307 return NULL; 1310 return NULL;
1308} 1311}
1309 1312
1310static const char *get_local_var_value(const char *name) 1313static const char* FAST_FUNC get_local_var_value(const char *name)
1311{ 1314{
1312 struct variable **pp = get_ptr_to_local_var(name); 1315 struct variable **pp = get_ptr_to_local_var(name);
1313 if (pp) 1316 if (pp)
@@ -1510,7 +1513,7 @@ static void unset_vars(char **strings)
1510#if ENABLE_SH_MATH_SUPPORT 1513#if ENABLE_SH_MATH_SUPPORT
1511#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) 1514#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c)))
1512#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) 1515#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c)))
1513static char *endofname(const char *name) 1516static char* FAST_FUNC endofname(const char *name)
1514{ 1517{
1515 char *p; 1518 char *p;
1516 1519
@@ -1524,11 +1527,10 @@ static char *endofname(const char *name)
1524 return p; 1527 return p;
1525} 1528}
1526 1529
1527static void arith_set_local_var(const char *name, const char *val, int flags) 1530static void FAST_FUNC set_local_var_from_halves(const char *name, const char *val)
1528{ 1531{
1529 /* arith code doesnt malloc space, so do it for it */
1530 char *var = xasprintf("%s=%s", name, val); 1532 char *var = xasprintf("%s=%s", name, val);
1531 set_local_var(var, flags, /*lvl:*/ 0, /*ro:*/ 0); 1533 set_local_var(var, /*flags:*/ 0, /*lvl:*/ 0, /*ro:*/ 0);
1532} 1534}
1533#endif 1535#endif
1534 1536
@@ -2538,7 +2540,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char
2538 2540
2539 exp_str = expand_pseudo_dquoted(arg); 2541 exp_str = expand_pseudo_dquoted(arg);
2540 hooks.lookupvar = get_local_var_value; 2542 hooks.lookupvar = get_local_var_value;
2541 hooks.setvar = arith_set_local_var; 2543 hooks.setvar = set_local_var_from_halves;
2542 hooks.endofname = endofname; 2544 hooks.endofname = endofname;
2543 res = arith(exp_str ? exp_str : arg, &errcode, &hooks); 2545 res = arith(exp_str ? exp_str : arg, &errcode, &hooks);
2544 free(exp_str); 2546 free(exp_str);
@@ -6157,7 +6159,7 @@ static struct pipe *parse_stream(char **pstring,
6157 6159
6158 G.ifs = get_local_var_value("IFS"); 6160 G.ifs = get_local_var_value("IFS");
6159 if (G.ifs == NULL) 6161 if (G.ifs == NULL)
6160 G.ifs = " \t\n"; 6162 G.ifs = defifs;
6161 6163
6162 reset: 6164 reset:
6163#if ENABLE_HUSH_INTERACTIVE 6165#if ENABLE_HUSH_INTERACTIVE
@@ -7727,24 +7729,37 @@ static int FAST_FUNC builtin_pwd(char **argv UNUSED_PARAM)
7727 7729
7728static int FAST_FUNC builtin_read(char **argv) 7730static int FAST_FUNC builtin_read(char **argv)
7729{ 7731{
7730 char *string; 7732 const char *r;
7731 const char *name = "REPLY"; 7733 char *opt_n = NULL;
7734 char *opt_p = NULL;
7735 char *opt_t = NULL;
7736 char *opt_u = NULL;
7737 int read_flags;
7732 7738
7733 if (argv[1]) { 7739 /* "!": do not abort on errors.
7734 name = argv[1]; 7740 * Option string must start with "sr" to match BUILTIN_READ_xxx
7735 /* bash (3.2.33(1)) bug: "read 0abcd" will execute, 7741 */
7736 * and _after_ that_ it will complain */ 7742 read_flags = getopt32(argv, "!srn:p:t:u:", &opt_n, &opt_p, &opt_t, &opt_u);
7737 if (!is_well_formed_var_name(name, '\0')) { 7743 if (read_flags == (uint32_t)-1)
7738 /* Mimic bash message */ 7744 return EXIT_FAILURE;
7739 bb_error_msg("read: '%s': not a valid identifier", name); 7745 argv += optind;
7740 return 1;
7741 }
7742 }
7743 7746
7744//TODO: bash unbackslashes input, splits words and puts them in argv[i] 7747 r = shell_builtin_read(set_local_var_from_halves,
7748 argv,
7749 get_local_var_value("IFS"), /* can be NULL */
7750 read_flags,
7751 opt_n,
7752 opt_p,
7753 opt_t,
7754 opt_u
7755 );
7756
7757 if ((uintptr_t)r > 1) {
7758 bb_error_msg("%s", r);
7759 r = (char*)(uintptr_t)1;
7760 }
7745 7761
7746 string = xmalloc_reads(STDIN_FILENO, xasprintf("%s=", name), NULL); 7762 return (uintptr_t)r;
7747 return set_local_var(string, /*exp:*/ 0, /*lvl:*/ 0, /*ro:*/ 0);
7748} 7763}
7749 7764
7750/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set 7765/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set