diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-07 12:19:33 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-07 12:19:33 +0200 |
commit | 8b2f13d84def87b4ebd0901bf0c3157bc1f6dee3 (patch) | |
tree | 0bf072d3612c77dd8b0720973e46e8dbc37a040a /shell/ash.c | |
parent | 27c56f12670295286a881bbb87d506f0a5bfd40e (diff) | |
download | busybox-w32-8b2f13d84def87b4ebd0901bf0c3157bc1f6dee3.tar.gz busybox-w32-8b2f13d84def87b4ebd0901bf0c3157bc1f6dee3.tar.bz2 busybox-w32-8b2f13d84def87b4ebd0901bf0c3157bc1f6dee3.zip |
shell: unify endofname() in hush and ash
function old new delta
builtin_umask 132 133 +1
changepath 195 194 -1
expand_and_evaluate_arith 77 69 -8
ash_arith 143 135 -8
expand_one_var 1551 1515 -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/4 up/down: 1/-53) Total: -52 bytes
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/shell/ash.c b/shell/ash.c index 273ecabdb..70425b324 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -1982,10 +1982,6 @@ extern struct globals_var *const ash_ptr_to_globals_var; | |||
1982 | # define optindval() (voptind.var_text + 7) | 1982 | # define optindval() (voptind.var_text + 7) |
1983 | #endif | 1983 | #endif |
1984 | 1984 | ||
1985 | |||
1986 | #define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) | ||
1987 | #define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) | ||
1988 | |||
1989 | #if ENABLE_ASH_GETOPTS | 1985 | #if ENABLE_ASH_GETOPTS |
1990 | static void FAST_FUNC | 1986 | static void FAST_FUNC |
1991 | getoptsreset(const char *value) | 1987 | getoptsreset(const char *value) |
@@ -1995,24 +1991,26 @@ getoptsreset(const char *value) | |||
1995 | } | 1991 | } |
1996 | #endif | 1992 | #endif |
1997 | 1993 | ||
1994 | /* math.h has these, otherwise define our private copies */ | ||
1995 | #if !ENABLE_SH_MATH_SUPPORT | ||
1996 | #define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) | ||
1997 | #define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) | ||
1998 | /* | 1998 | /* |
1999 | * Return of a legal variable name (a letter or underscore followed by zero or | 1999 | * Return the pointer to the first char which is not part of a legal variable name |
2000 | * more letters, underscores, and digits). | 2000 | * (a letter or underscore followed by letters, underscores, and digits). |
2001 | */ | 2001 | */ |
2002 | static char* FAST_FUNC | 2002 | static const char* |
2003 | endofname(const char *name) | 2003 | endofname(const char *name) |
2004 | { | 2004 | { |
2005 | char *p; | 2005 | if (!is_name(*name)) |
2006 | 2006 | return name; | |
2007 | p = (char *) name; | 2007 | while (*++name) { |
2008 | if (!is_name(*p)) | 2008 | if (!is_in_name(*name)) |
2009 | return p; | ||
2010 | while (*++p) { | ||
2011 | if (!is_in_name(*p)) | ||
2012 | break; | 2009 | break; |
2013 | } | 2010 | } |
2014 | return p; | 2011 | return name; |
2015 | } | 2012 | } |
2013 | #endif | ||
2016 | 2014 | ||
2017 | /* | 2015 | /* |
2018 | * Compares two strings up to the first = or '\0'. The first | 2016 | * Compares two strings up to the first = or '\0'. The first |
@@ -2195,9 +2193,10 @@ setvareq(char *s, int flags) | |||
2195 | static void | 2193 | static void |
2196 | setvar(const char *name, const char *val, int flags) | 2194 | setvar(const char *name, const char *val, int flags) |
2197 | { | 2195 | { |
2198 | char *p, *q; | 2196 | const char *q; |
2199 | size_t namelen; | 2197 | char *p; |
2200 | char *nameeq; | 2198 | char *nameeq; |
2199 | size_t namelen; | ||
2201 | size_t vallen; | 2200 | size_t vallen; |
2202 | 2201 | ||
2203 | q = endofname(name); | 2202 | q = endofname(name); |
@@ -2211,12 +2210,13 @@ setvar(const char *name, const char *val, int flags) | |||
2211 | } else { | 2210 | } else { |
2212 | vallen = strlen(val); | 2211 | vallen = strlen(val); |
2213 | } | 2212 | } |
2213 | |||
2214 | INT_OFF; | 2214 | INT_OFF; |
2215 | nameeq = ckmalloc(namelen + vallen + 2); | 2215 | nameeq = ckmalloc(namelen + vallen + 2); |
2216 | p = (char *)memcpy(nameeq, name, namelen) + namelen; | 2216 | p = memcpy(nameeq, name, namelen) + namelen; |
2217 | if (val) { | 2217 | if (val) { |
2218 | *p++ = '='; | 2218 | *p++ = '='; |
2219 | p = (char *)memcpy(p, val, vallen) + vallen; | 2219 | p = memcpy(p, val, vallen) + vallen; |
2220 | } | 2220 | } |
2221 | *p = '\0'; | 2221 | *p = '\0'; |
2222 | setvareq(nameeq, flags | VNOSAVE); | 2222 | setvareq(nameeq, flags | VNOSAVE); |
@@ -5444,7 +5444,7 @@ ash_arith(const char *s) | |||
5444 | 5444 | ||
5445 | math_hooks.lookupvar = lookupvar; | 5445 | math_hooks.lookupvar = lookupvar; |
5446 | math_hooks.setvar = setvar2; | 5446 | math_hooks.setvar = setvar2; |
5447 | math_hooks.endofname = endofname; | 5447 | //math_hooks.endofname = endofname; |
5448 | 5448 | ||
5449 | INT_OFF; | 5449 | INT_OFF; |
5450 | result = arith(s, &errcode, &math_hooks); | 5450 | result = arith(s, &errcode, &math_hooks); |
@@ -9405,7 +9405,7 @@ evalbltin(const struct builtincmd *cmd, int argc, char **argv) | |||
9405 | static int | 9405 | static int |
9406 | goodname(const char *p) | 9406 | goodname(const char *p) |
9407 | { | 9407 | { |
9408 | return !*endofname(p); | 9408 | return endofname(p)[0] == '\0'; |
9409 | } | 9409 | } |
9410 | 9410 | ||
9411 | 9411 | ||