Imported from ../bash-2.04.tar.gz.

This commit is contained in:
Jari Aalto
2000-03-17 21:46:59 +00:00
parent b72432fdcc
commit bb70624e96
387 changed files with 28522 additions and 9334 deletions

View File

@@ -5,7 +5,7 @@ This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any later
Software Foundation; either version 2, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -15,7 +15,7 @@ for more details.
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include "config.h"
@@ -84,6 +84,9 @@ static void print_arith_command ();
static void print_cond_node ();
static void print_cond_command ();
#endif
#if defined (ARITH_FOR_COMMAND)
static void print_arith_for_command ();
#endif
#define PRINTED_COMMAND_INITIAL_SIZE 64
#define PRINTED_COMMAND_GROW_SIZE 128
@@ -137,9 +140,6 @@ make_command_string_internal (command)
else
indent (indentation);
if (command->flags & CMD_WANT_SUBSHELL)
cprintf ("( ");
if (command->flags & CMD_TIME_PIPELINE)
{
cprintf ("time ");
@@ -156,6 +156,12 @@ make_command_string_internal (command)
print_for_command (command->value.For);
break;
#if defined (ARITH_FOR_COMMAND)
case cm_arith_for:
print_arith_for_command (command->value.ArithFor);
break;
#endif
#if defined (SELECT_COMMAND)
case cm_select:
print_select_command (command->value.Select);
@@ -259,13 +265,18 @@ make_command_string_internal (command)
print_group_command (command->value.Group);
break;
case cm_subshell:
cprintf ("( ");
skip_this_indent++;
make_command_string_internal (command->value.Subshell->command);
cprintf (" )");
break;
default:
command_error ("print_command", CMDERR_BADTYPE, command->type, 0);
break;
}
if (command->flags & CMD_WANT_SUBSHELL)
cprintf (" )");
if (command->redirects)
{
@@ -344,6 +355,27 @@ print_for_command (for_command)
newline ("done");
}
#if defined (ARITH_FOR_COMMAND)
static void
print_arith_for_command (arith_for_command)
ARITH_FOR_COM *arith_for_command;
{
cprintf ("for (( ");
command_print_word_list (arith_for_command->init, " ");
cprintf (" ; ");
command_print_word_list (arith_for_command->test, " ");
cprintf (" ; ");
command_print_word_list (arith_for_command->step, " ");
cprintf (" ))");
newline ("do\n");
indentation += indentation_amount;
make_command_string_internal (arith_for_command->action);
semicolon ();
indentation -= indentation_amount;
newline ("done");
}
#endif /* ARITH_FOR_COMMAND */
#if defined (SELECT_COMMAND)
static void
print_select_command (select_command)
@@ -492,6 +524,7 @@ print_arith_command (arith_command)
command_print_word_list (arith_command->exp, " ");
cprintf (" ))");
}
#endif
#if defined (COND_COMMAND)
static void
@@ -586,6 +619,7 @@ xtrace_print_cond_term (type, invert, op, arg1, arg2)
}
#endif /* COND_COMMAND */
#if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
/* A function to print the words of an arithmetic command when set -x is on. */
void
xtrace_print_arith_cmd (list)
@@ -768,6 +802,9 @@ static void
print_function_def (func)
FUNCTION_DEF *func;
{
COMMAND *cmdcopy;
REDIRECT *func_redirects;
cprintf ("function %s () \n", func->name->word);
add_unwind_protect (reset_locals, 0);
@@ -777,15 +814,31 @@ print_function_def (func)
inside_function_def++;
indentation += indentation_amount;
make_command_string_internal (func->command->type == cm_group
? func->command->value.Group->command
: func->command);
func_redirects = (REDIRECT *)NULL;
cmdcopy = copy_command (func->command);
if (cmdcopy->type == cm_group)
{
func_redirects = cmdcopy->value.Group->command->redirects;
cmdcopy->value.Group->command->redirects = (REDIRECT *)NULL;
}
make_command_string_internal (cmdcopy->type == cm_group
? cmdcopy->value.Group->command
: cmdcopy);
remove_unwind_protect ();
indentation -= indentation_amount;
inside_function_def--;
newline ("}");
if (func_redirects)
{ /* { */
newline ("} ");
print_redirection_list (func_redirects);
cmdcopy->value.Group->command->redirects = func_redirects;
}
else
newline ("}");
dispose_command (cmdcopy);
}
/* Return the string representation of the named function.
@@ -801,6 +854,8 @@ named_function_string (name, command, multi_line)
{
char *result;
int old_indent, old_amount;
COMMAND *cmdcopy;
REDIRECT *func_redirects;
old_indent = indentation;
old_amount = indentation_amount;
@@ -826,15 +881,31 @@ named_function_string (name, command, multi_line)
cprintf (multi_line ? "{ \n" : "{ ");
make_command_string_internal (command->type == cm_group
? command->value.Group->command
: command);
cmdcopy = copy_command (command);
/* Take any redirections specified in the function definition (which should
apply to the function as a whole) and save them for printing later. */
func_redirects = (REDIRECT *)NULL;
if (cmdcopy->type == cm_group)
{
func_redirects = cmdcopy->value.Group->command->redirects;
cmdcopy->value.Group->command->redirects = (REDIRECT *)NULL;
}
make_command_string_internal (cmdcopy->type == cm_group
? cmdcopy->value.Group->command
: cmdcopy);
indentation = old_indent;
indentation_amount = old_amount;
inside_function_def--;
newline ("}");
if (func_redirects)
{ /* { */
newline ("} ");
print_redirection_list (func_redirects);
cmdcopy->value.Group->command->redirects = func_redirects;
}
else
newline ("}");
result = the_printed_command;
@@ -854,6 +925,8 @@ named_function_string (name, command, multi_line)
#endif
}
dispose_command (cmdcopy);
return (result);
}
@@ -1068,14 +1141,11 @@ the_printed_command_resize (length)
{
int new;
new = command_string_index + length + 1;
#if 1
/* Round up to the next multiple of PRINTED_COMMAND_GROW_SIZE. */
new = (new + PRINTED_COMMAND_GROW_SIZE - 1) & ~(PRINTED_COMMAND_GROW_SIZE - 1);
#else
new = new + 2 * PRINTED_COMMAND_GROW_SIZE - 1;
new -= new % PRINTED_COMMAND_GROW_SIZE;
#endif
the_printed_command_size = new;
the_printed_command = xrealloc (the_printed_command, the_printed_command_size);
}
}