changes to text representation of parsed command substitution; small changes to tests

This commit is contained in:
Chet Ramey
2022-07-06 10:05:59 -04:00
parent 42768befc0
commit 67e47f224c
13 changed files with 863 additions and 1080 deletions
+46 -18
View File
@@ -129,6 +129,7 @@ static int inside_function_def;
static int skip_this_indent;
static int was_heredoc;
static int printing_connection;
static int printing_comsub;
static REDIRECT *deferred_heredocs;
/* The depth of the group commands that we are currently printing. This
@@ -162,6 +163,21 @@ make_command_string (command)
return (the_printed_command);
}
/* Print a command substitution after parsing it in parse_comsub to turn it
back into an external representation without turning newlines into `;'.
Placeholder for other changes, if any are necessary. */
char *
print_comsub (command)
COMMAND *command;
{
char *ret;
printing_comsub++;
ret = make_command_string (command);
printing_comsub--;
return ret;
}
/* The internal function. This is the real workhorse. */
static void
make_command_string_internal (command)
@@ -278,25 +294,35 @@ make_command_string_internal (command)
break;
case ';':
if (deferred_heredocs == 0)
{
if (was_heredoc == 0)
cprintf (";");
else
was_heredoc = 0;
}
else
print_deferred_heredocs (inside_function_def ? "" : ";");
case '\n': /* special case this */
{
char c = command->value.Connection->connector;
if (inside_function_def)
cprintf ("\n");
else
{
cprintf (" ");
if (command->value.Connection->second)
skip_this_indent++;
}
break;
s[0] = printing_comsub ? c : ';';
s[1] = '\0';
if (deferred_heredocs == 0)
{
if (was_heredoc == 0)
cprintf (s); /* inside_function_def? */
else
was_heredoc = 0;
}
else
/* print_deferred_heredocs special-cases `;' */
print_deferred_heredocs (inside_function_def ? "" : ";");
if (inside_function_def)
cprintf ("\n");
else
{
if (c == ';')
cprintf (" ");
if (command->value.Connection->second)
skip_this_indent++;
}
break;
}
default:
cprintf (_("print_command: bad connector `%d'"),
@@ -1293,6 +1319,7 @@ reset_locals ()
indentation = 0;
printing_connection = 0;
deferred_heredocs = 0;
printing_comsub = 0;
}
static void
@@ -1364,6 +1391,7 @@ named_function_string (name, command, flags)
old_amount = indentation_amount;
command_string_index = was_heredoc = 0;
deferred_heredocs = 0;
printing_comsub = 0;
if (name && *name)
{