summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-05 14:49:40 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-05 14:49:40 +0200
commit38292b68c962b9d470fa4e577020749c8c69226d (patch)
tree755adb0df0532af7f0faa856fcedbac20cc87226
parentf2dc20c2d5dd82001e4da765caef60228a856ff8 (diff)
downloadbusybox-w32-38292b68c962b9d470fa4e577020749c8c69226d.tar.gz
busybox-w32-38292b68c962b9d470fa4e577020749c8c69226d.tar.bz2
busybox-w32-38292b68c962b9d470fa4e577020749c8c69226d.zip
hush: rename o_quoted to has_quoted_part; small code shrink
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--shell/hush.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 821a7a77f..1bed72159 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -400,8 +400,7 @@ typedef struct o_string {
400 smallint o_glob; 400 smallint o_glob;
401 /* At least some part of the string was inside '' or "", 401 /* At least some part of the string was inside '' or "",
402 * possibly empty one: word"", wo''rd etc. */ 402 * possibly empty one: word"", wo''rd etc. */
403//TODO: rename to no_empty_expansion? 403 smallint has_quoted_part;
404 smallint o_quoted;
405 smallint has_empty_slot; 404 smallint has_empty_slot;
406 smallint o_assignment; /* 0:maybe, 1:yes, 2:no */ 405 smallint o_assignment; /* 0:maybe, 1:yes, 2:no */
407} o_string; 406} o_string;
@@ -1964,7 +1963,7 @@ static void setup_string_in_str(struct in_str *i, const char *s)
1964static void o_reset_to_empty_unquoted(o_string *o) 1963static void o_reset_to_empty_unquoted(o_string *o)
1965{ 1964{
1966 o->length = 0; 1965 o->length = 0;
1967 o->o_quoted = 0; 1966 o->has_quoted_part = 0;
1968 if (o->data) 1967 if (o->data)
1969 o->data[0] = '\0'; 1968 o->data[0] = '\0';
1970} 1969}
@@ -2088,7 +2087,7 @@ static void o_addQchr(o_string *o, int ch)
2088 o->data[o->length] = '\0'; 2087 o->data[o->length] = '\0';
2089} 2088}
2090 2089
2091static void o_addQstr(o_string *o, const char *str, int len) 2090static void o_addQblock(o_string *o, const char *str, int len)
2092{ 2091{
2093 if (!o->o_escape) { 2092 if (!o->o_escape) {
2094 o_addblock(o, str, len); 2093 o_addblock(o, str, len);
@@ -2120,6 +2119,11 @@ static void o_addQstr(o_string *o, const char *str, int len)
2120 } 2119 }
2121} 2120}
2122 2121
2122static void o_addQstr(o_string *o, const char *str)
2123{
2124 o_addQblock(o, str, strlen(str));
2125}
2126
2123/* A special kind of o_string for $VAR and `cmd` expansion. 2127/* A special kind of o_string for $VAR and `cmd` expansion.
2124 * It contains char* list[] at the beginning, which is grown in 16 element 2128 * It contains char* list[] at the beginning, which is grown in 16 element
2125 * increments. Actual string data starts at the next multiple of 16 * (char*). 2129 * increments. Actual string data starts at the next multiple of 16 * (char*).
@@ -2139,7 +2143,7 @@ static void debug_print_list(const char *prefix, o_string *o, int n)
2139 2143
2140 indent(); 2144 indent();
2141 fprintf(stderr, "%s: list:%p n:%d string_start:%d length:%d maxlen:%d glob:%d quoted:%d escape:%d\n", 2145 fprintf(stderr, "%s: list:%p n:%d string_start:%d length:%d maxlen:%d glob:%d quoted:%d escape:%d\n",
2142 prefix, list, n, string_start, o->length, o->maxlen, o->o_glob, o->o_quoted, o->o_escape); 2146 prefix, list, n, string_start, o->length, o->maxlen, o->o_glob, o->has_quoted_part, o->o_escape);
2143 while (i < n) { 2147 while (i < n) {
2144 indent(); 2148 indent();
2145 fprintf(stderr, " list[%d]=%d '%s' %p\n", i, (int)list[i], 2149 fprintf(stderr, " list[%d]=%d '%s' %p\n", i, (int)list[i],
@@ -2544,7 +2548,7 @@ static int expand_on_ifs(o_string *output, int n, const char *str)
2544 int word_len = strcspn(str, G.ifs); 2548 int word_len = strcspn(str, G.ifs);
2545 if (word_len) { 2549 if (word_len) {
2546 if (output->o_escape || !output->o_glob) 2550 if (output->o_escape || !output->o_glob)
2547 o_addQstr(output, str, word_len); 2551 o_addQblock(output, str, word_len);
2548 else /* protect backslashes against globbing up :) */ 2552 else /* protect backslashes against globbing up :) */
2549 o_addblock_duplicate_backslash(output, str, word_len); 2553 o_addblock_duplicate_backslash(output, str, word_len);
2550 str += word_len; 2554 str += word_len;
@@ -2994,7 +2998,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char
2994 * and in this case should treat it like '$*' - see 'else...' below */ 2998 * and in this case should treat it like '$*' - see 'else...' below */
2995 if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */ 2999 if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */
2996 while (1) { 3000 while (1) {
2997 o_addQstr(output, G.global_argv[i], strlen(G.global_argv[i])); 3001 o_addQstr(output, G.global_argv[i]);
2998 if (++i >= G.global_argc) 3002 if (++i >= G.global_argc)
2999 break; 3003 break;
3000 o_addchr(output, '\0'); 3004 o_addchr(output, '\0');
@@ -3003,7 +3007,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char
3003 } 3007 }
3004 } else { /* quoted $*: add as one word */ 3008 } else { /* quoted $*: add as one word */
3005 while (1) { 3009 while (1) {
3006 o_addQstr(output, G.global_argv[i], strlen(G.global_argv[i])); 3010 o_addQstr(output, G.global_argv[i]);
3007 if (!G.global_argv[++i]) 3011 if (!G.global_argv[++i])
3008 break; 3012 break;
3009 if (G.ifs[0]) 3013 if (G.ifs[0])
@@ -3081,7 +3085,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char
3081 } /* switch (char after <SPECIAL_VAR_SYMBOL>) */ 3085 } /* switch (char after <SPECIAL_VAR_SYMBOL>) */
3082 3086
3083 if (val && val[0]) { 3087 if (val && val[0]) {
3084 o_addQstr(output, val, strlen(val)); 3088 o_addQstr(output, val);
3085 } 3089 }
3086 free(to_be_freed); 3090 free(to_be_freed);
3087 /* Do the check to avoid writing to a const string */ 3091 /* Do the check to avoid writing to a const string */
@@ -3109,6 +3113,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char
3109 } else { 3113 } else {
3110 o_addchr(output, '\0'); 3114 o_addchr(output, '\0');
3111 } 3115 }
3116
3112 return n; 3117 return n;
3113} 3118}
3114 3119
@@ -5485,7 +5490,7 @@ static int reserved_word(o_string *word, struct parse_context *ctx)
5485# endif 5490# endif
5486 const struct reserved_combo *r; 5491 const struct reserved_combo *r;
5487 5492
5488 if (word->o_quoted) 5493 if (word->has_quoted_part)
5489 return 0; 5494 return 0;
5490 r = match_reserved_word(word); 5495 r = match_reserved_word(word);
5491 if (!r) 5496 if (!r)
@@ -5561,7 +5566,7 @@ static int done_word(o_string *word, struct parse_context *ctx)
5561 struct command *command = ctx->command; 5566 struct command *command = ctx->command;
5562 5567
5563 debug_printf_parse("done_word entered: '%s' %p\n", word->data, command); 5568 debug_printf_parse("done_word entered: '%s' %p\n", word->data, command);
5564 if (word->length == 0 && word->o_quoted == 0) { 5569 if (word->length == 0 && !word->has_quoted_part) {
5565 debug_printf_parse("done_word return 0: true null, ignored\n"); 5570 debug_printf_parse("done_word return 0: true null, ignored\n");
5566 return 0; 5571 return 0;
5567 } 5572 }
@@ -5588,7 +5593,7 @@ static int done_word(o_string *word, struct parse_context *ctx)
5588 if (ctx->pending_redirect->rd_type == REDIRECT_HEREDOC) { 5593 if (ctx->pending_redirect->rd_type == REDIRECT_HEREDOC) {
5589 unbackslash(ctx->pending_redirect->rd_filename); 5594 unbackslash(ctx->pending_redirect->rd_filename);
5590 /* Is it <<"HEREDOC"? */ 5595 /* Is it <<"HEREDOC"? */
5591 if (word->o_quoted) { 5596 if (word->has_quoted_part) {
5592 ctx->pending_redirect->rd_dup |= HEREDOC_QUOTED; 5597 ctx->pending_redirect->rd_dup |= HEREDOC_QUOTED;
5593 } 5598 }
5594 } 5599 }
@@ -5657,7 +5662,7 @@ static int done_word(o_string *word, struct parse_context *ctx)
5657 "groups and arglists don't mix\n"); 5662 "groups and arglists don't mix\n");
5658 return 1; 5663 return 1;
5659 } 5664 }
5660 if (word->o_quoted /* word had "xx" or 'xx' at least as part of it. */ 5665 if (word->has_quoted_part
5661 /* optimization: and if it's ("" or '') or ($v... or `cmd`...): */ 5666 /* optimization: and if it's ("" or '') or ($v... or `cmd`...): */
5662 && (word->data[0] == '\0' || word->data[0] == SPECIAL_VAR_SYMBOL) 5667 && (word->data[0] == '\0' || word->data[0] == SPECIAL_VAR_SYMBOL)
5663 /* (otherwise it's known to be not empty and is already safe) */ 5668 /* (otherwise it's known to be not empty and is already safe) */
@@ -5685,7 +5690,7 @@ static int done_word(o_string *word, struct parse_context *ctx)
5685 5690
5686#if ENABLE_HUSH_LOOPS 5691#if ENABLE_HUSH_LOOPS
5687 if (ctx->ctx_res_w == RES_FOR) { 5692 if (ctx->ctx_res_w == RES_FOR) {
5688 if (word->o_quoted 5693 if (word->has_quoted_part
5689 || !is_well_formed_var_name(command->argv[0], '\0') 5694 || !is_well_formed_var_name(command->argv[0], '\0')
5690 ) { 5695 ) {
5691 /* bash says just "not a valid identifier" */ 5696 /* bash says just "not a valid identifier" */
@@ -5842,7 +5847,7 @@ static int parse_redirect(struct parse_context *ctx,
5842 * the redirection expression. For example: 5847 * the redirection expression. For example:
5843 * echo \2>a 5848 * echo \2>a
5844 * writes the character 2 into file a" 5849 * writes the character 2 into file a"
5845 * We are getting it right by setting ->o_quoted on any \<char> 5850 * We are getting it right by setting ->has_quoted_part on any \<char>
5846 * 5851 *
5847 * A -1 return means no valid number was found, 5852 * A -1 return means no valid number was found,
5848 * the caller should use the appropriate default for this redirection. 5853 * the caller should use the appropriate default for this redirection.
@@ -6042,7 +6047,9 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p)
6042 *pid_p = pid; 6047 *pid_p = pid;
6043# if ENABLE_HUSH_FAST 6048# if ENABLE_HUSH_FAST
6044 G.count_SIGCHLD++; 6049 G.count_SIGCHLD++;
6045//bb_error_msg("[%d] fork in generate_stream_from_string: G.count_SIGCHLD:%d G.handled_SIGCHLD:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD); 6050//bb_error_msg("[%d] fork in generate_stream_from_string:"
6051// " G.count_SIGCHLD:%d G.handled_SIGCHLD:%d",
6052// getpid(), G.count_SIGCHLD, G.handled_SIGCHLD);
6046# endif 6053# endif
6047 enable_restore_tty_pgrp_on_exit(); 6054 enable_restore_tty_pgrp_on_exit();
6048# if !BB_MMU 6055# if !BB_MMU
@@ -6105,7 +6112,7 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
6105 6112
6106 debug_printf_parse("parse_group entered\n"); 6113 debug_printf_parse("parse_group entered\n");
6107#if ENABLE_HUSH_FUNCTIONS 6114#if ENABLE_HUSH_FUNCTIONS
6108 if (ch == '(' && !dest->o_quoted) { 6115 if (ch == '(' && !dest->has_quoted_part) {
6109 if (dest->length) 6116 if (dest->length)
6110 if (done_word(dest, ctx)) 6117 if (done_word(dest, ctx))
6111 return 1; 6118 return 1;
@@ -6140,7 +6147,7 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
6140#if 0 /* Prevented by caller */ 6147#if 0 /* Prevented by caller */
6141 if (command->argv /* word [word]{... */ 6148 if (command->argv /* word [word]{... */
6142 || dest->length /* word{... */ 6149 || dest->length /* word{... */
6143 || dest->o_quoted /* ""{... */ 6150 || dest->has_quoted_part /* ""{... */
6144 ) { 6151 ) {
6145 syntax_error(NULL); 6152 syntax_error(NULL);
6146 debug_printf_parse("parse_group return 1: " 6153 debug_printf_parse("parse_group return 1: "
@@ -6705,7 +6712,7 @@ static struct pipe *parse_stream(char **pstring,
6705 redir_type redir_style; 6712 redir_type redir_style;
6706 6713
6707 if (is_in_dquote) { 6714 if (is_in_dquote) {
6708 /* dest.o_quoted = 1; - already is (see below) */ 6715 /* dest.has_quoted_part = 1; - already is (see below) */
6709 if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"')) { 6716 if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"')) {
6710 goto parse_error; 6717 goto parse_error;
6711 } 6718 }
@@ -6766,7 +6773,7 @@ static struct pipe *parse_stream(char **pstring,
6766 /* Are { and } special here? */ 6773 /* Are { and } special here? */
6767 if (ctx.command->argv /* word [word]{... - non-special */ 6774 if (ctx.command->argv /* word [word]{... - non-special */
6768 || dest.length /* word{... - non-special */ 6775 || dest.length /* word{... - non-special */
6769 || dest.o_quoted /* ""{... - non-special */ 6776 || dest.has_quoted_part /* ""{... - non-special */
6770 || (next != ';' /* }; - special */ 6777 || (next != ';' /* }; - special */
6771 && next != ')' /* }) - special */ 6778 && next != ')' /* }) - special */
6772 && next != '&' /* }& and }&& ... - special */ 6779 && next != '&' /* }& and }&& ... - special */
@@ -6830,7 +6837,7 @@ static struct pipe *parse_stream(char **pstring,
6830 if (ch == '}') { 6837 if (ch == '}') {
6831 if (!IS_NULL_CMD(ctx.command) /* cmd } */ 6838 if (!IS_NULL_CMD(ctx.command) /* cmd } */
6832 || dest.length != 0 /* word} */ 6839 || dest.length != 0 /* word} */
6833 || dest.o_quoted /* ""} */ 6840 || dest.has_quoted_part /* ""} */
6834 ) { 6841 ) {
6835 goto ordinary_char; 6842 goto ordinary_char;
6836 } 6843 }
@@ -6844,7 +6851,7 @@ static struct pipe *parse_stream(char **pstring,
6844#if ENABLE_HUSH_CASE 6851#if ENABLE_HUSH_CASE
6845 && (ch != ')' 6852 && (ch != ')'
6846 || ctx.ctx_res_w != RES_MATCH 6853 || ctx.ctx_res_w != RES_MATCH
6847 || (!dest.o_quoted && strcmp(dest.data, "esac") == 0) 6854 || (!dest.has_quoted_part && strcmp(dest.data, "esac") == 0)
6848 ) 6855 )
6849#endif 6856#endif
6850 ) { 6857 ) {
@@ -6979,7 +6986,7 @@ static struct pipe *parse_stream(char **pstring,
6979 nommu_addchr(&ctx.as_string, ch); 6986 nommu_addchr(&ctx.as_string, ch);
6980 /* Example: echo Hello \2>file 6987 /* Example: echo Hello \2>file
6981 * we need to know that word 2 is quoted */ 6988 * we need to know that word 2 is quoted */
6982 dest.o_quoted = 1; 6989 dest.has_quoted_part = 1;
6983 } 6990 }
6984#if !BB_MMU 6991#if !BB_MMU
6985 else { 6992 else {
@@ -6996,7 +7003,7 @@ static struct pipe *parse_stream(char **pstring,
6996 } 7003 }
6997 break; 7004 break;
6998 case '\'': 7005 case '\'':
6999 dest.o_quoted = 1; 7006 dest.has_quoted_part = 1;
7000 while (1) { 7007 while (1) {
7001 ch = i_getch(input); 7008 ch = i_getch(input);
7002 if (ch == EOF) { 7009 if (ch == EOF) {
@@ -7010,7 +7017,7 @@ static struct pipe *parse_stream(char **pstring,
7010 } 7017 }
7011 break; 7018 break;
7012 case '"': 7019 case '"':
7013 dest.o_quoted = 1; 7020 dest.has_quoted_part = 1;
7014 is_in_dquote ^= 1; /* invert */ 7021 is_in_dquote ^= 1; /* invert */
7015 if (dest.o_assignment == NOT_ASSIGNMENT) 7022 if (dest.o_assignment == NOT_ASSIGNMENT)
7016 dest.o_escape ^= 1; 7023 dest.o_escape ^= 1;
@@ -7101,7 +7108,7 @@ static struct pipe *parse_stream(char **pstring,
7101 if (ctx.ctx_res_w == RES_MATCH 7108 if (ctx.ctx_res_w == RES_MATCH
7102 && ctx.command->argv == NULL /* not (word|(... */ 7109 && ctx.command->argv == NULL /* not (word|(... */
7103 && dest.length == 0 /* not word(... */ 7110 && dest.length == 0 /* not word(... */
7104 && dest.o_quoted == 0 /* not ""(... */ 7111 && dest.has_quoted_part == 0 /* not ""(... */
7105 ) { 7112 ) {
7106 continue; 7113 continue;
7107 } 7114 }