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>
This commit is contained in:
parent
850b15bfaf
commit
5b6210cf49
28
shell/hush.c
28
shell/hush.c
@ -3151,16 +3151,16 @@ static char *fetch_till_str(o_string *as_string,
|
|||||||
int heredoc_flags)
|
int heredoc_flags)
|
||||||
{
|
{
|
||||||
o_string heredoc = NULL_O_STRING;
|
o_string heredoc = NULL_O_STRING;
|
||||||
int past_EOL = 0;
|
unsigned past_EOL;
|
||||||
int prev = 0; /* not \ */
|
int prev = 0; /* not \ */
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
goto jump_in;
|
goto jump_in;
|
||||||
while (1) {
|
while (1) {
|
||||||
ch = i_getch(input);
|
ch = i_getch(input);
|
||||||
nommu_addchr(as_string, ch);
|
if (ch != EOF)
|
||||||
if (ch == '\n'
|
nommu_addchr(as_string, ch);
|
||||||
/* TODO: or EOF? (heredoc delimiter may end with <eof>, not only <eol>) */
|
if ((ch == '\n' || ch == EOF)
|
||||||
&& ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\')
|
&& ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\')
|
||||||
) {
|
) {
|
||||||
if (strcmp(heredoc.data + past_EOL, word) == 0) {
|
if (strcmp(heredoc.data + past_EOL, word) == 0) {
|
||||||
@ -3168,28 +3168,29 @@ static char *fetch_till_str(o_string *as_string,
|
|||||||
debug_printf_parse("parsed heredoc '%s'\n", heredoc.data);
|
debug_printf_parse("parsed heredoc '%s'\n", heredoc.data);
|
||||||
return heredoc.data;
|
return heredoc.data;
|
||||||
}
|
}
|
||||||
do {
|
while (ch == '\n') {
|
||||||
o_addchr(&heredoc, '\n');
|
o_addchr(&heredoc, ch);
|
||||||
prev = 0; /* not \ */
|
prev = ch;
|
||||||
past_EOL = heredoc.length;
|
|
||||||
jump_in:
|
jump_in:
|
||||||
|
past_EOL = heredoc.length;
|
||||||
do {
|
do {
|
||||||
ch = i_getch(input);
|
ch = i_getch(input);
|
||||||
nommu_addchr(as_string, ch);
|
if (ch != EOF)
|
||||||
|
nommu_addchr(as_string, ch);
|
||||||
} while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t');
|
} while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t');
|
||||||
} while (ch == '\n');
|
}
|
||||||
}
|
}
|
||||||
if (ch == EOF) {
|
if (ch == EOF) {
|
||||||
o_free_unsafe(&heredoc);
|
o_free_unsafe(&heredoc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
o_addchr(&heredoc, ch);
|
o_addchr(&heredoc, ch);
|
||||||
|
nommu_addchr(as_string, ch);
|
||||||
if (prev == '\\' && ch == '\\')
|
if (prev == '\\' && ch == '\\')
|
||||||
/* Correctly handle foo\\<eol> (not a line cont.) */
|
/* Correctly handle foo\\<eol> (not a line cont.) */
|
||||||
prev = 0; /* not \ */
|
prev = 0; /* not \ */
|
||||||
else
|
else
|
||||||
prev = ch;
|
prev = ch;
|
||||||
nommu_addchr(as_string, ch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3748,8 +3749,6 @@ static int parse_stream_dquoted(o_string *as_string,
|
|||||||
if (ch != EOF)
|
if (ch != EOF)
|
||||||
nommu_addchr(as_string, ch);
|
nommu_addchr(as_string, ch);
|
||||||
if (ch == dquote_end) { /* may be only '"' or EOF */
|
if (ch == dquote_end) { /* may be only '"' or EOF */
|
||||||
if (dest->o_assignment == NOT_ASSIGNMENT)
|
|
||||||
dest->o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS;
|
|
||||||
debug_printf_parse("parse_stream_dquoted return 0\n");
|
debug_printf_parse("parse_stream_dquoted return 0\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -4159,9 +4158,10 @@ static struct pipe *parse_stream(char **pstring,
|
|||||||
case '"':
|
case '"':
|
||||||
dest.has_quoted_part = 1;
|
dest.has_quoted_part = 1;
|
||||||
if (dest.o_assignment == NOT_ASSIGNMENT)
|
if (dest.o_assignment == NOT_ASSIGNMENT)
|
||||||
dest.o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS;
|
dest.o_expflags |= EXP_FLAG_ESC_GLOB_CHARS;
|
||||||
if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"'))
|
if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"'))
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
|
dest.o_expflags &= ~EXP_FLAG_ESC_GLOB_CHARS;
|
||||||
break;
|
break;
|
||||||
#if ENABLE_HUSH_TICK
|
#if ENABLE_HUSH_TICK
|
||||||
case '`': {
|
case '`': {
|
||||||
|
Loading…
Reference in New Issue
Block a user