diff options
author | Chet Ramey <chet.ramey@case.edu> | 2014-01-29 17:00:07 -0500 |
---|---|---|
committer | Chet Ramey <chet.ramey@case.edu> | 2014-01-29 17:00:07 -0500 |
commit | b6e23235f28b1c85e18e9a2b7ba8c6b6c46aecbc (patch) | |
tree | 00fdd9c37c261d89c994fc1856252df719afec3a /y.tab.c | |
parent | 8581f42df9a1b1d848e2d4bdf3cc951b8d14b5be (diff) | |
download | bash-b6e23235f28b1c85e18e9a2b7ba8c6b6c46aecbc.tar.gz |
bash-4.3-rc2 overlaybash-4.3-rc2bash-4.3-testing
Diffstat (limited to 'y.tab.c')
-rw-r--r-- | y.tab.c | 68 |
1 files changed, 66 insertions, 2 deletions
@@ -4104,6 +4104,10 @@ restore_token_state (ts) * implement alias expansion on a per-token basis. */ +#define PSH_ALIAS 0x01 +#define PSH_DPAREN 0x02 +#define PSH_SOURCE 0x04 + typedef struct string_saver { struct string_saver *next; int expand_alias; /* Value to set expand_alias to when string is popped. */ @@ -4113,6 +4117,7 @@ typedef struct string_saver { #endif size_t saved_line_size, saved_line_index; int saved_line_terminator; + int flags; } STRING_SAVER; STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL; @@ -4138,8 +4143,11 @@ push_string (s, expand, ap) temp->saved_line_size = shell_input_line_size; temp->saved_line_index = shell_input_line_index; temp->saved_line_terminator = shell_input_line_terminator; + temp->flags = 0; #if defined (ALIAS) temp->expander = ap; + if (ap) + temp->flags = PSH_ALIAS; #endif temp->next = pushed_string_list; pushed_string_list = temp; @@ -4150,7 +4158,7 @@ push_string (s, expand, ap) #endif shell_input_line = s; - shell_input_line_size = strlen (s); + shell_input_line_size = STRLEN (s); shell_input_line_index = 0; shell_input_line_terminator = '\0'; #if 0 @@ -4224,6 +4232,34 @@ free_pushed_string_input () #endif } +int +parser_expanding_alias () +{ + return (expanding_alias ()); +} + +void +parser_save_alias () +{ +#if defined (ALIAS) || defined (DPAREN_ARITHMETIC) + push_string ((char *)NULL, 0, (alias_t *)NULL); + pushed_string_list->flags = PSH_SOURCE; /* XXX - for now */ +#else + ; +#endif +} + +void +parser_restore_alias () +{ +#if defined (ALIAS) || defined (DPAREN_ARITHMETIC) + if (pushed_string_list) + pop_string (); +#else + ; +#endif +} + /* Return a line of text, taken from wherever yylex () reads input. If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE is non-zero, we remove unquoted \<newline> pairs. This is used by @@ -4718,8 +4754,13 @@ next_alias_char: because we have fully consumed the result of the last alias expansion. Do it transparently; just return the next character of the string popped to. */ + /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not + currently tested) and the flags value is not PSH_SOURCE, we are not + parsing an alias, we have just saved one (push_string, when called by + the parse_dparen code) In this case, just go on as well. The PSH_SOURCE + case is handled below. */ pop_alias: - if (uc == 0 && (pushed_string_list != (STRING_SAVER *)NULL)) + if (uc == 0 && pushed_string_list && pushed_string_list->flags != PSH_SOURCE) { pop_string (); uc = shell_input_line[shell_input_line_index]; @@ -4759,6 +4800,28 @@ pop_alias: if (uc == 0 && shell_input_line_terminator == EOF) return ((shell_input_line_index != 0) ? '\n' : EOF); +#if defined (ALIAS) || defined (DPAREN_ARITHMETIC) + /* We already know that we are not parsing an alias expansion because of the + check for expanding_alias() above. This knows how parse_and_execute + handles switching to st_string input while an alias is being expanded, + hence the check for pushed_string_list without pushed_string_list->expander + and the check for PSH_SOURCE as pushed_string_list->flags. + parse_and_execute and parse_string both change the input type to st_string + and place the string to be parsed and executed into location.string, so + we should not stop reading that until the pointer is '\0'. + The check for shell_input_line_terminator may be superfluous. + + This solves the problem of `.' inside a multi-line alias with embedded + newlines executing things out of order. */ + if (uc == 0 && bash_input.type == st_string && *bash_input.location.string && + pushed_string_list && pushed_string_list->flags == PSH_SOURCE && + shell_input_line_terminator == 0) + { + shell_input_line_index = 0; + goto restart_read; + } +#endif + return (uc); } @@ -6334,6 +6397,7 @@ parse_dparen (c) else if (cmdtyp == 0) /* nested subshell */ { push_string (wval, 0, (alias_t *)NULL); + pushed_string_list->flags = PSH_DPAREN; if ((parser_state & PST_CASEPAT) == 0) parser_state |= PST_SUBSHELL; return (c); |