diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-02 20:17:49 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-02 20:17:49 +0000 |
commit | b7aaae9052025426b669a0edeec1da5997fea8be (patch) | |
tree | 062eff7de09b9307a57260c47571888ed3f598b7 /shell/hush.c | |
parent | 7a79afa3cab4d35f6c042a1038554948ebe9b2e1 (diff) | |
download | busybox-w32-b7aaae9052025426b669a0edeec1da5997fea8be.tar.gz busybox-w32-b7aaae9052025426b669a0edeec1da5997fea8be.tar.bz2 busybox-w32-b7aaae9052025426b669a0edeec1da5997fea8be.zip |
hush: rename ->o_quote to ->o_escape
hush_test/hush-arith/*: new tests for arithmetic evaluation
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/shell/hush.c b/shell/hush.c index b46a1fd76..f0d372625 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -392,9 +392,9 @@ typedef struct o_string { | |||
392 | char *data; | 392 | char *data; |
393 | int length; /* position where data is appended */ | 393 | int length; /* position where data is appended */ |
394 | int maxlen; | 394 | int maxlen; |
395 | /* Misnomer! it's not "quoting", it's "protection against globbing"! | 395 | /* Protect newly added chars against globbing |
396 | * (by prepending \ to *, ?, [ and to \ too) */ | 396 | * (by prepending \ to *, ?, [, \) */ |
397 | smallint o_quote; | 397 | smallint o_escape; |
398 | smallint o_glob; | 398 | smallint o_glob; |
399 | smallint nonnull; | 399 | smallint nonnull; |
400 | smallint has_empty_slot; | 400 | smallint has_empty_slot; |
@@ -1440,7 +1440,7 @@ static void o_addqchr(o_string *o, int ch) | |||
1440 | static void o_addQchr(o_string *o, int ch) | 1440 | static void o_addQchr(o_string *o, int ch) |
1441 | { | 1441 | { |
1442 | int sz = 1; | 1442 | int sz = 1; |
1443 | if (o->o_quote && strchr("*?[\\", ch)) { | 1443 | if (o->o_escape && strchr("*?[\\", ch)) { |
1444 | sz++; | 1444 | sz++; |
1445 | o->data[o->length] = '\\'; | 1445 | o->data[o->length] = '\\'; |
1446 | o->length++; | 1446 | o->length++; |
@@ -1453,7 +1453,7 @@ static void o_addQchr(o_string *o, int ch) | |||
1453 | 1453 | ||
1454 | static void o_addQstr(o_string *o, const char *str, int len) | 1454 | static void o_addQstr(o_string *o, const char *str, int len) |
1455 | { | 1455 | { |
1456 | if (!o->o_quote) { | 1456 | if (!o->o_escape) { |
1457 | o_addstr(o, str, len); | 1457 | o_addstr(o, str, len); |
1458 | return; | 1458 | return; |
1459 | } | 1459 | } |
@@ -1668,7 +1668,7 @@ static int expand_on_ifs(o_string *output, int n, const char *str) | |||
1668 | while (1) { | 1668 | while (1) { |
1669 | int word_len = strcspn(str, G.ifs); | 1669 | int word_len = strcspn(str, G.ifs); |
1670 | if (word_len) { | 1670 | if (word_len) { |
1671 | if (output->o_quote || !output->o_glob) | 1671 | if (output->o_escape || !output->o_glob) |
1672 | o_addQstr(output, str, word_len); | 1672 | o_addQstr(output, str, word_len); |
1673 | else /* protect backslashes against globbing up :) */ | 1673 | else /* protect backslashes against globbing up :) */ |
1674 | o_addstr_duplicate_backslash(output, str, word_len); | 1674 | o_addstr_duplicate_backslash(output, str, word_len); |
@@ -1751,9 +1751,9 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
1751 | break; | 1751 | break; |
1752 | ored_ch |= first_ch; /* do it for "$@" _now_, when we know it's not empty */ | 1752 | ored_ch |= first_ch; /* do it for "$@" _now_, when we know it's not empty */ |
1753 | if (!(first_ch & 0x80)) { /* unquoted $* or $@ */ | 1753 | if (!(first_ch & 0x80)) { /* unquoted $* or $@ */ |
1754 | smallint sv = output->o_quote; | 1754 | smallint sv = output->o_escape; |
1755 | /* unquoted var's contents should be globbed, so don't quote */ | 1755 | /* unquoted var's contents should be globbed, so don't escape */ |
1756 | output->o_quote = 0; | 1756 | output->o_escape = 0; |
1757 | while (G.global_argv[i]) { | 1757 | while (G.global_argv[i]) { |
1758 | n = expand_on_ifs(output, n, G.global_argv[i]); | 1758 | n = expand_on_ifs(output, n, G.global_argv[i]); |
1759 | debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, G.global_argc - 1); | 1759 | debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, G.global_argc - 1); |
@@ -1766,7 +1766,7 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
1766 | debug_print_list("expand_vars_to_list[3]", output, n); | 1766 | debug_print_list("expand_vars_to_list[3]", output, n); |
1767 | } | 1767 | } |
1768 | } | 1768 | } |
1769 | output->o_quote = sv; | 1769 | output->o_escape = sv; |
1770 | } else | 1770 | } else |
1771 | /* If or_mask is nonzero, we handle assignment 'a=....$@.....' | 1771 | /* If or_mask is nonzero, we handle assignment 'a=....$@.....' |
1772 | * and in this case should treat it like '$*' - see 'else...' below */ | 1772 | * and in this case should treat it like '$*' - see 'else...' below */ |
@@ -1945,17 +1945,17 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask) | |||
1945 | store_val: | 1945 | store_val: |
1946 | #endif | 1946 | #endif |
1947 | if (!(first_ch & 0x80)) { /* unquoted $VAR */ | 1947 | if (!(first_ch & 0x80)) { /* unquoted $VAR */ |
1948 | debug_printf_expand("unquoted '%s', output->o_quote:%d\n", val, output->o_quote); | 1948 | debug_printf_expand("unquoted '%s', output->o_escape:%d\n", val, output->o_escape); |
1949 | if (val) { | 1949 | if (val) { |
1950 | /* unquoted var's contents should be globbed, so don't quote */ | 1950 | /* unquoted var's contents should be globbed, so don't escape */ |
1951 | smallint sv = output->o_quote; | 1951 | smallint sv = output->o_escape; |
1952 | output->o_quote = 0; | 1952 | output->o_escape = 0; |
1953 | n = expand_on_ifs(output, n, val); | 1953 | n = expand_on_ifs(output, n, val); |
1954 | val = NULL; | 1954 | val = NULL; |
1955 | output->o_quote = sv; | 1955 | output->o_escape = sv; |
1956 | } | 1956 | } |
1957 | } else { /* quoted $VAR, val will be appended below */ | 1957 | } else { /* quoted $VAR, val will be appended below */ |
1958 | debug_printf_expand("quoted '%s', output->o_quote:%d\n", val, output->o_quote); | 1958 | debug_printf_expand("quoted '%s', output->o_escape:%d\n", val, output->o_escape); |
1959 | } | 1959 | } |
1960 | } /* default: */ | 1960 | } /* default: */ |
1961 | } /* switch (char after <SPECIAL_VAR_SYMBOL>) */ | 1961 | } /* switch (char after <SPECIAL_VAR_SYMBOL>) */ |
@@ -1999,7 +1999,7 @@ static char **expand_variables(char **argv, int or_mask) | |||
1999 | o_string output = NULL_O_STRING; | 1999 | o_string output = NULL_O_STRING; |
2000 | 2000 | ||
2001 | if (or_mask & 0x100) { | 2001 | if (or_mask & 0x100) { |
2002 | output.o_quote = 1; /* protect against globbing for "$var" */ | 2002 | output.o_escape = 1; /* protect against globbing for "$var" */ |
2003 | /* (unquoted $var will temporarily switch it off) */ | 2003 | /* (unquoted $var will temporarily switch it off) */ |
2004 | output.o_glob = 1; | 2004 | output.o_glob = 1; |
2005 | } | 2005 | } |
@@ -3979,7 +3979,7 @@ static int handle_dollar(o_string *dest, struct in_str *input) | |||
3979 | { | 3979 | { |
3980 | int expansion; | 3980 | int expansion; |
3981 | int ch = i_peek(input); /* first character after the $ */ | 3981 | int ch = i_peek(input); /* first character after the $ */ |
3982 | unsigned char quote_mask = dest->o_quote ? 0x80 : 0; | 3982 | unsigned char quote_mask = dest->o_escape ? 0x80 : 0; |
3983 | 3983 | ||
3984 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); | 3984 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); |
3985 | if (isalpha(ch)) { | 3985 | if (isalpha(ch)) { |
@@ -4143,7 +4143,7 @@ static int parse_stream_dquoted(o_string *dest, struct in_str *input, int dquote | |||
4143 | if (ch == dquote_end) { /* may be only '"' or EOF */ | 4143 | if (ch == dquote_end) { /* may be only '"' or EOF */ |
4144 | dest->nonnull = 1; | 4144 | dest->nonnull = 1; |
4145 | if (dest->o_assignment == NOT_ASSIGNMENT) | 4145 | if (dest->o_assignment == NOT_ASSIGNMENT) |
4146 | dest->o_quote ^= 1; | 4146 | dest->o_escape ^= 1; |
4147 | debug_printf_parse("parse_stream_dquoted return 0\n"); | 4147 | debug_printf_parse("parse_stream_dquoted return 0\n"); |
4148 | return 0; | 4148 | return 0; |
4149 | } | 4149 | } |
@@ -4157,8 +4157,8 @@ static int parse_stream_dquoted(o_string *dest, struct in_str *input, int dquote | |||
4157 | if (ch != '\n') { | 4157 | if (ch != '\n') { |
4158 | next = i_peek(input); | 4158 | next = i_peek(input); |
4159 | } | 4159 | } |
4160 | debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n", | 4160 | debug_printf_parse(": ch=%c (%d) m=%d escape=%d\n", |
4161 | ch, ch, m, dest->o_quote); | 4161 | ch, ch, m, dest->o_escape); |
4162 | /* Basically, checking every CHAR_SPECIAL char except '"' */ | 4162 | /* Basically, checking every CHAR_SPECIAL char except '"' */ |
4163 | if (ch == '\\') { | 4163 | if (ch == '\\') { |
4164 | if (next == EOF) { | 4164 | if (next == EOF) { |
@@ -4225,13 +4225,13 @@ static int parse_stream(o_string *dest, struct parse_context *ctx, | |||
4225 | int is_in_dquote; | 4225 | int is_in_dquote; |
4226 | int next; | 4226 | int next; |
4227 | 4227 | ||
4228 | /* Only double-quote state is handled in the state variable dest->o_quote. | 4228 | /* Double-quote state is handled in the state variable is_in_dquote. |
4229 | * A single-quote triggers a bypass of the main loop until its mate is | 4229 | * A single-quote triggers a bypass of the main loop until its mate is |
4230 | * found. When recursing, quote state is passed in via dest->o_quote. */ | 4230 | * found. When recursing, quote state is passed in via dest->o_escape. */ |
4231 | 4231 | ||
4232 | debug_printf_parse("parse_stream entered, end_trigger='%s' dest->o_assignment:%d\n", end_trigger, dest->o_assignment); | 4232 | debug_printf_parse("parse_stream entered, end_trigger='%s' dest->o_assignment:%d\n", end_trigger, dest->o_assignment); |
4233 | 4233 | ||
4234 | is_in_dquote = dest->o_quote; | 4234 | is_in_dquote = dest->o_escape; |
4235 | while (1) { | 4235 | while (1) { |
4236 | if (is_in_dquote) { | 4236 | if (is_in_dquote) { |
4237 | if (parse_stream_dquoted(dest, input, '"')) | 4237 | if (parse_stream_dquoted(dest, input, '"')) |
@@ -4248,8 +4248,8 @@ static int parse_stream(o_string *dest, struct parse_context *ctx, | |||
4248 | next = i_peek(input); | 4248 | next = i_peek(input); |
4249 | } | 4249 | } |
4250 | } | 4250 | } |
4251 | debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n", | 4251 | debug_printf_parse(": ch=%c (%d) m=%d escape=%d\n", |
4252 | ch, ch, m, dest->o_quote); | 4252 | ch, ch, m, dest->o_escape); |
4253 | if (m == CHAR_ORDINARY) { | 4253 | if (m == CHAR_ORDINARY) { |
4254 | o_addQchr(dest, ch); | 4254 | o_addQchr(dest, ch); |
4255 | if ((dest->o_assignment == MAYBE_ASSIGNMENT | 4255 | if ((dest->o_assignment == MAYBE_ASSIGNMENT |
@@ -4365,7 +4365,7 @@ static int parse_stream(o_string *dest, struct parse_context *ctx, | |||
4365 | dest->nonnull = 1; | 4365 | dest->nonnull = 1; |
4366 | is_in_dquote ^= 1; /* invert */ | 4366 | is_in_dquote ^= 1; /* invert */ |
4367 | if (dest->o_assignment == NOT_ASSIGNMENT) | 4367 | if (dest->o_assignment == NOT_ASSIGNMENT) |
4368 | dest->o_quote ^= 1; | 4368 | dest->o_escape ^= 1; |
4369 | break; | 4369 | break; |
4370 | #if ENABLE_HUSH_TICK | 4370 | #if ENABLE_HUSH_TICK |
4371 | case '`': { | 4371 | case '`': { |
@@ -4594,7 +4594,7 @@ static int parse_and_run_stream(struct in_str *inp, int parse_flag) | |||
4594 | } | 4594 | } |
4595 | #endif | 4595 | #endif |
4596 | /*temp.nonnull = 0; - o_free does it below */ | 4596 | /*temp.nonnull = 0; - o_free does it below */ |
4597 | /*temp.o_quote = 0; - o_free does it below */ | 4597 | /*temp.o_escape = 0; - o_free does it below */ |
4598 | free_pipe_list(ctx.list_head, /* indent: */ 0); | 4598 | free_pipe_list(ctx.list_head, /* indent: */ 0); |
4599 | /* Discard all unprocessed line input, force prompt on */ | 4599 | /* Discard all unprocessed line input, force prompt on */ |
4600 | inp->p = NULL; | 4600 | inp->p = NULL; |