summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-09 13:32:21 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-09 13:32:21 +0200
commit5b6210cf492dba4474d83a138c95b1267777826b (patch)
treee1160764010d91c68818c58238fa8dc1c8f71dad
parent850b15bfafb08d24ae3e55f5ca8b848b17958f8a (diff)
downloadbusybox-w32-5b6210cf492dba4474d83a138c95b1267777826b.tar.gz
busybox-w32-5b6210cf492dba4474d83a138c95b1267777826b.tar.bz2
busybox-w32-5b6210cf492dba4474d83a138c95b1267777826b.zip
hush: simplification in parse_stream, parse_stream_dquoted
function old new delta parse_stream 2354 2369 +15 parse_stream_dquoted 250 228 -22 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--shell/hush.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 5af525982..b19d4ea01 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3151,16 +3151,16 @@ static char *fetch_till_str(o_string *as_string,
3151 int heredoc_flags) 3151 int heredoc_flags)
3152{ 3152{
3153 o_string heredoc = NULL_O_STRING; 3153 o_string heredoc = NULL_O_STRING;
3154 int past_EOL = 0; 3154 unsigned past_EOL;
3155 int prev = 0; /* not \ */ 3155 int prev = 0; /* not \ */
3156 int ch; 3156 int ch;
3157 3157
3158 goto jump_in; 3158 goto jump_in;
3159 while (1) { 3159 while (1) {
3160 ch = i_getch(input); 3160 ch = i_getch(input);
3161 nommu_addchr(as_string, ch); 3161 if (ch != EOF)
3162 if (ch == '\n' 3162 nommu_addchr(as_string, ch);
3163 /* TODO: or EOF? (heredoc delimiter may end with <eof>, not only <eol>) */ 3163 if ((ch == '\n' || ch == EOF)
3164 && ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') 3164 && ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\')
3165 ) { 3165 ) {
3166 if (strcmp(heredoc.data + past_EOL, word) == 0) { 3166 if (strcmp(heredoc.data + past_EOL, word) == 0) {
@@ -3168,28 +3168,29 @@ static char *fetch_till_str(o_string *as_string,
3168 debug_printf_parse("parsed heredoc '%s'\n", heredoc.data); 3168 debug_printf_parse("parsed heredoc '%s'\n", heredoc.data);
3169 return heredoc.data; 3169 return heredoc.data;
3170 } 3170 }
3171 do { 3171 while (ch == '\n') {
3172 o_addchr(&heredoc, '\n'); 3172 o_addchr(&heredoc, ch);
3173 prev = 0; /* not \ */ 3173 prev = ch;
3174 past_EOL = heredoc.length;
3175 jump_in: 3174 jump_in:
3175 past_EOL = heredoc.length;
3176 do { 3176 do {
3177 ch = i_getch(input); 3177 ch = i_getch(input);
3178 nommu_addchr(as_string, ch); 3178 if (ch != EOF)
3179 nommu_addchr(as_string, ch);
3179 } while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t'); 3180 } while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t');
3180 } while (ch == '\n'); 3181 }
3181 } 3182 }
3182 if (ch == EOF) { 3183 if (ch == EOF) {
3183 o_free_unsafe(&heredoc); 3184 o_free_unsafe(&heredoc);
3184 return NULL; 3185 return NULL;
3185 } 3186 }
3186 o_addchr(&heredoc, ch); 3187 o_addchr(&heredoc, ch);
3188 nommu_addchr(as_string, ch);
3187 if (prev == '\\' && ch == '\\') 3189 if (prev == '\\' && ch == '\\')
3188 /* Correctly handle foo\\<eol> (not a line cont.) */ 3190 /* Correctly handle foo\\<eol> (not a line cont.) */
3189 prev = 0; /* not \ */ 3191 prev = 0; /* not \ */
3190 else 3192 else
3191 prev = ch; 3193 prev = ch;
3192 nommu_addchr(as_string, ch);
3193 } 3194 }
3194} 3195}
3195 3196
@@ -3748,8 +3749,6 @@ static int parse_stream_dquoted(o_string *as_string,
3748 if (ch != EOF) 3749 if (ch != EOF)
3749 nommu_addchr(as_string, ch); 3750 nommu_addchr(as_string, ch);
3750 if (ch == dquote_end) { /* may be only '"' or EOF */ 3751 if (ch == dquote_end) { /* may be only '"' or EOF */
3751 if (dest->o_assignment == NOT_ASSIGNMENT)
3752 dest->o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS;
3753 debug_printf_parse("parse_stream_dquoted return 0\n"); 3752 debug_printf_parse("parse_stream_dquoted return 0\n");
3754 return 0; 3753 return 0;
3755 } 3754 }
@@ -4159,9 +4158,10 @@ static struct pipe *parse_stream(char **pstring,
4159 case '"': 4158 case '"':
4160 dest.has_quoted_part = 1; 4159 dest.has_quoted_part = 1;
4161 if (dest.o_assignment == NOT_ASSIGNMENT) 4160 if (dest.o_assignment == NOT_ASSIGNMENT)
4162 dest.o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS; 4161 dest.o_expflags |= EXP_FLAG_ESC_GLOB_CHARS;
4163 if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"')) 4162 if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"'))
4164 goto parse_error; 4163 goto parse_error;
4164 dest.o_expflags &= ~EXP_FLAG_ESC_GLOB_CHARS;
4165 break; 4165 break;
4166#if ENABLE_HUSH_TICK 4166#if ENABLE_HUSH_TICK
4167 case '`': { 4167 case '`': {