mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-05 11:20:50 +02:00
Bash-5.3-alpha release
This commit is contained in:
+64
-109
@@ -1,7 +1,7 @@
|
||||
/* make_cmd.c -- Functions for making instances of the various
|
||||
parser constructs. */
|
||||
|
||||
/* Copyright (C) 1989-2022 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1989-2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
@@ -55,21 +55,21 @@ sh_obj_cache_t wlcache = {0, 0, 0};
|
||||
#define WDCACHESIZE 128
|
||||
#define WLCACHESIZE 128
|
||||
|
||||
static COMMAND *make_for_or_select PARAMS((enum command_type, WORD_DESC *, WORD_LIST *, COMMAND *, int));
|
||||
static COMMAND *make_for_or_select (enum command_type, WORD_DESC *, WORD_LIST *, COMMAND *, int);
|
||||
#if defined (ARITH_FOR_COMMAND)
|
||||
static WORD_LIST *make_arith_for_expr PARAMS((char *));
|
||||
static WORD_LIST *make_arith_for_expr (char *);
|
||||
#endif
|
||||
static COMMAND *make_until_or_while PARAMS((enum command_type, COMMAND *, COMMAND *));
|
||||
static COMMAND *make_until_or_while (enum command_type, COMMAND *, COMMAND *);
|
||||
|
||||
void
|
||||
cmd_init ()
|
||||
cmd_init (void)
|
||||
{
|
||||
ocache_create (wdcache, WORD_DESC, WDCACHESIZE);
|
||||
ocache_create (wlcache, WORD_LIST, WLCACHESIZE);
|
||||
}
|
||||
|
||||
WORD_DESC *
|
||||
alloc_word_desc ()
|
||||
alloc_word_desc (void)
|
||||
{
|
||||
WORD_DESC *temp;
|
||||
|
||||
@@ -80,8 +80,7 @@ alloc_word_desc ()
|
||||
}
|
||||
|
||||
WORD_DESC *
|
||||
make_bare_word (string)
|
||||
const char *string;
|
||||
make_bare_word (const char *string)
|
||||
{
|
||||
WORD_DESC *temp;
|
||||
|
||||
@@ -99,9 +98,7 @@ make_bare_word (string)
|
||||
}
|
||||
|
||||
WORD_DESC *
|
||||
make_word_flags (w, string)
|
||||
WORD_DESC *w;
|
||||
const char *string;
|
||||
make_word_flags (WORD_DESC *w, const char *string)
|
||||
{
|
||||
register int i;
|
||||
size_t slen;
|
||||
@@ -132,8 +129,7 @@ make_word_flags (w, string)
|
||||
}
|
||||
|
||||
WORD_DESC *
|
||||
make_word (string)
|
||||
const char *string;
|
||||
make_word (const char *string)
|
||||
{
|
||||
WORD_DESC *temp;
|
||||
|
||||
@@ -142,8 +138,7 @@ make_word (string)
|
||||
}
|
||||
|
||||
WORD_DESC *
|
||||
make_word_from_token (token)
|
||||
int token;
|
||||
make_word_from_token (int token)
|
||||
{
|
||||
char tokenizer[2];
|
||||
|
||||
@@ -154,9 +149,7 @@ make_word_from_token (token)
|
||||
}
|
||||
|
||||
WORD_LIST *
|
||||
make_word_list (word, wlink)
|
||||
WORD_DESC *word;
|
||||
WORD_LIST *wlink;
|
||||
make_word_list (WORD_DESC *word, WORD_LIST *wlink)
|
||||
{
|
||||
WORD_LIST *temp;
|
||||
|
||||
@@ -168,9 +161,7 @@ make_word_list (word, wlink)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_command (type, pointer)
|
||||
enum command_type type;
|
||||
SIMPLE_COM *pointer;
|
||||
make_command (enum command_type type, SIMPLE_COM *pointer)
|
||||
{
|
||||
COMMAND *temp;
|
||||
|
||||
@@ -183,9 +174,7 @@ make_command (type, pointer)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
command_connect (com1, com2, connector)
|
||||
COMMAND *com1, *com2;
|
||||
int connector;
|
||||
command_connect (COMMAND *com1, COMMAND *com2, int connector)
|
||||
{
|
||||
CONNECTION *temp;
|
||||
|
||||
@@ -197,12 +186,7 @@ command_connect (com1, com2, connector)
|
||||
}
|
||||
|
||||
static COMMAND *
|
||||
make_for_or_select (type, name, map_list, action, lineno)
|
||||
enum command_type type;
|
||||
WORD_DESC *name;
|
||||
WORD_LIST *map_list;
|
||||
COMMAND *action;
|
||||
int lineno;
|
||||
make_for_or_select (enum command_type type, WORD_DESC *name, WORD_LIST *map_list, COMMAND *action, int lineno)
|
||||
{
|
||||
FOR_COM *temp;
|
||||
|
||||
@@ -216,21 +200,13 @@ make_for_or_select (type, name, map_list, action, lineno)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_for_command (name, map_list, action, lineno)
|
||||
WORD_DESC *name;
|
||||
WORD_LIST *map_list;
|
||||
COMMAND *action;
|
||||
int lineno;
|
||||
make_for_command (WORD_DESC *name, WORD_LIST *map_list, COMMAND *action, int lineno)
|
||||
{
|
||||
return (make_for_or_select (cm_for, name, map_list, action, lineno));
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_select_command (name, map_list, action, lineno)
|
||||
WORD_DESC *name;
|
||||
WORD_LIST *map_list;
|
||||
COMMAND *action;
|
||||
int lineno;
|
||||
make_select_command (WORD_DESC *name, WORD_LIST *map_list, COMMAND *action, int lineno)
|
||||
{
|
||||
#if defined (SELECT_COMMAND)
|
||||
return (make_for_or_select (cm_select, name, map_list, action, lineno));
|
||||
@@ -242,8 +218,7 @@ make_select_command (name, map_list, action, lineno)
|
||||
|
||||
#if defined (ARITH_FOR_COMMAND)
|
||||
static WORD_LIST *
|
||||
make_arith_for_expr (s)
|
||||
char *s;
|
||||
make_arith_for_expr (char *s)
|
||||
{
|
||||
WORD_LIST *result;
|
||||
WORD_DESC *wd;
|
||||
@@ -262,10 +237,7 @@ make_arith_for_expr (s)
|
||||
because no other function in this file requires that the caller free
|
||||
any arguments. */
|
||||
COMMAND *
|
||||
make_arith_for_command (exprs, action, lineno)
|
||||
WORD_LIST *exprs;
|
||||
COMMAND *action;
|
||||
int lineno;
|
||||
make_arith_for_command (WORD_LIST *exprs, COMMAND *action, int lineno)
|
||||
{
|
||||
#if defined (ARITH_FOR_COMMAND)
|
||||
ARITH_FOR_COM *temp;
|
||||
@@ -340,8 +312,7 @@ make_arith_for_command (exprs, action, lineno)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_group_command (command)
|
||||
COMMAND *command;
|
||||
make_group_command (COMMAND *command)
|
||||
{
|
||||
GROUP_COM *temp;
|
||||
|
||||
@@ -351,10 +322,7 @@ make_group_command (command)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_case_command (word, clauses, lineno)
|
||||
WORD_DESC *word;
|
||||
PATTERN_LIST *clauses;
|
||||
int lineno;
|
||||
make_case_command (WORD_DESC *word, PATTERN_LIST *clauses, int lineno)
|
||||
{
|
||||
CASE_COM *temp;
|
||||
|
||||
@@ -367,9 +335,7 @@ make_case_command (word, clauses, lineno)
|
||||
}
|
||||
|
||||
PATTERN_LIST *
|
||||
make_pattern_list (patterns, action)
|
||||
WORD_LIST *patterns;
|
||||
COMMAND *action;
|
||||
make_pattern_list (WORD_LIST *patterns, COMMAND *action)
|
||||
{
|
||||
PATTERN_LIST *temp;
|
||||
|
||||
@@ -382,8 +348,7 @@ make_pattern_list (patterns, action)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_if_command (test, true_case, false_case)
|
||||
COMMAND *test, *true_case, *false_case;
|
||||
make_if_command (COMMAND *test, COMMAND *true_case, COMMAND *false_case)
|
||||
{
|
||||
IF_COM *temp;
|
||||
|
||||
@@ -396,9 +361,7 @@ make_if_command (test, true_case, false_case)
|
||||
}
|
||||
|
||||
static COMMAND *
|
||||
make_until_or_while (which, test, action)
|
||||
enum command_type which;
|
||||
COMMAND *test, *action;
|
||||
make_until_or_while (enum command_type which, COMMAND *test, COMMAND *action)
|
||||
{
|
||||
WHILE_COM *temp;
|
||||
|
||||
@@ -410,22 +373,19 @@ make_until_or_while (which, test, action)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_while_command (test, action)
|
||||
COMMAND *test, *action;
|
||||
make_while_command (COMMAND *test, COMMAND *action)
|
||||
{
|
||||
return (make_until_or_while (cm_while, test, action));
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_until_command (test, action)
|
||||
COMMAND *test, *action;
|
||||
make_until_command (COMMAND *test, COMMAND *action)
|
||||
{
|
||||
return (make_until_or_while (cm_until, test, action));
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_arith_command (exp)
|
||||
WORD_LIST *exp;
|
||||
make_arith_command (WORD_LIST *exp)
|
||||
{
|
||||
#if defined (DPAREN_ARITHMETIC)
|
||||
COMMAND *command;
|
||||
@@ -451,10 +411,7 @@ make_arith_command (exp)
|
||||
|
||||
#if defined (COND_COMMAND)
|
||||
struct cond_com *
|
||||
make_cond_node (type, op, left, right)
|
||||
int type;
|
||||
WORD_DESC *op;
|
||||
struct cond_com *left, *right;
|
||||
make_cond_node (int type, WORD_DESC *op, struct cond_com *left, struct cond_com *right)
|
||||
{
|
||||
COND_COM *temp;
|
||||
|
||||
@@ -471,8 +428,7 @@ make_cond_node (type, op, left, right)
|
||||
#endif
|
||||
|
||||
COMMAND *
|
||||
make_cond_command (cond_node)
|
||||
COND_COM *cond_node;
|
||||
make_cond_command (COND_COM *cond_node)
|
||||
{
|
||||
#if defined (COND_COMMAND)
|
||||
COMMAND *command;
|
||||
@@ -493,7 +449,7 @@ make_cond_command (cond_node)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_bare_simple_command ()
|
||||
make_bare_simple_command (int line)
|
||||
{
|
||||
COMMAND *command;
|
||||
SIMPLE_COM *temp;
|
||||
@@ -502,7 +458,7 @@ make_bare_simple_command ()
|
||||
command->value.Simple = temp = (SIMPLE_COM *)xmalloc (sizeof (SIMPLE_COM));
|
||||
|
||||
temp->flags = 0;
|
||||
temp->line = line_number;
|
||||
temp->line = line;
|
||||
temp->words = (WORD_LIST *)NULL;
|
||||
temp->redirects = (REDIRECT *)NULL;
|
||||
|
||||
@@ -516,16 +472,14 @@ make_bare_simple_command ()
|
||||
/* Return a command which is the connection of the word or redirection
|
||||
in ELEMENT, and the command * or NULL in COMMAND. */
|
||||
COMMAND *
|
||||
make_simple_command (element, command)
|
||||
ELEMENT element;
|
||||
COMMAND *command;
|
||||
make_simple_command (ELEMENT element, COMMAND *command, int line)
|
||||
{
|
||||
/* If we are starting from scratch, then make the initial command
|
||||
structure. Also note that we have to fill in all the slots, since
|
||||
malloc doesn't return zeroed space. */
|
||||
if (command == 0)
|
||||
{
|
||||
command = make_bare_simple_command ();
|
||||
command = make_bare_simple_command (line);
|
||||
parser_state |= PST_REDIRLIST;
|
||||
}
|
||||
|
||||
@@ -555,13 +509,13 @@ make_simple_command (element, command)
|
||||
the redirectee.word with the new input text. If <<- is on,
|
||||
then remove leading TABS from each line. */
|
||||
void
|
||||
make_here_document (temp, lineno)
|
||||
REDIRECT *temp;
|
||||
int lineno;
|
||||
make_here_document (REDIRECT *temp, int lineno)
|
||||
{
|
||||
int kill_leading, redir_len;
|
||||
int kill_leading;
|
||||
size_t redir_len;
|
||||
char *redir_word, *document, *full_line;
|
||||
int document_index, document_size, delim_unquoted;
|
||||
int document_index, delim_unquoted;
|
||||
size_t document_size;
|
||||
|
||||
if (temp->instruction != r_deblank_reading_until &&
|
||||
temp->instruction != r_reading_until)
|
||||
@@ -573,7 +527,8 @@ make_here_document (temp, lineno)
|
||||
kill_leading = temp->instruction == r_deblank_reading_until;
|
||||
|
||||
full_line = document = (char *)NULL;
|
||||
document_index = document_size = 0;
|
||||
document_index = 0;
|
||||
document_size = 0;
|
||||
|
||||
delim_unquoted = (temp->redirectee.filename->flags & W_QUOTED) == 0;
|
||||
|
||||
@@ -614,11 +569,15 @@ make_here_document (temp, lineno)
|
||||
while (full_line = read_secondary_line (delim_unquoted))
|
||||
{
|
||||
register char *line;
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
here_doc_first_line = 0;
|
||||
line = full_line;
|
||||
line_number++;
|
||||
|
||||
/* if read_secondary_line uses shell_getc, that handles incrementing
|
||||
line_number where necessary. */
|
||||
if (heredoc_string == 0)
|
||||
line_number++;
|
||||
|
||||
/* If set -v is in effect, echo the line read. read_secondary_line/
|
||||
read_a_line leaves the newline at the end, so don't print another. */
|
||||
@@ -683,15 +642,11 @@ document_done:
|
||||
INSTRUCTION is the instruction type, SOURCE is a file descriptor,
|
||||
and DEST is a file descriptor or a WORD_DESC *. */
|
||||
REDIRECT *
|
||||
make_redirection (source, instruction, dest_and_filename, flags)
|
||||
REDIRECTEE source;
|
||||
enum r_instruction instruction;
|
||||
REDIRECTEE dest_and_filename;
|
||||
int flags;
|
||||
make_redirection (REDIRECTEE source, enum r_instruction instruction, REDIRECTEE dest_and_filename, int flags)
|
||||
{
|
||||
REDIRECT *temp;
|
||||
WORD_DESC *w;
|
||||
int wlen;
|
||||
size_t wlen;
|
||||
intmax_t lfd;
|
||||
|
||||
temp = (REDIRECT *)xmalloc (sizeof (REDIRECT));
|
||||
@@ -751,7 +706,7 @@ make_redirection (source, instruction, dest_and_filename, flags)
|
||||
if (w->word[wlen] == '-') /* Yuck */
|
||||
{
|
||||
w->word[wlen] = '\0';
|
||||
if (all_digits (w->word) && legal_number (w->word, &lfd) && lfd == (int)lfd)
|
||||
if (all_digits (w->word) && valid_number (w->word, &lfd) && lfd == (int)lfd)
|
||||
{
|
||||
dispose_word (w);
|
||||
temp->instruction = (instruction == r_duplicating_input_word) ? r_move_input : r_move_output;
|
||||
@@ -772,10 +727,7 @@ make_redirection (source, instruction, dest_and_filename, flags)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_function_def (name, command, lineno, lstart)
|
||||
WORD_DESC *name;
|
||||
COMMAND *command;
|
||||
int lineno, lstart;
|
||||
make_function_def (WORD_DESC *name, COMMAND *command, int lineno, int lstart)
|
||||
{
|
||||
FUNCTION_DEF *temp;
|
||||
#if defined (ARRAY_VARS)
|
||||
@@ -790,7 +742,7 @@ make_function_def (name, command, lineno, lstart)
|
||||
temp->flags = 0;
|
||||
command->line = lstart;
|
||||
|
||||
/* Information used primarily for debugging. */
|
||||
/* Information used primarily for debugging and error messages. */
|
||||
temp->source_file = 0;
|
||||
#if defined (ARRAY_VARS)
|
||||
GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a);
|
||||
@@ -801,7 +753,16 @@ make_function_def (name, command, lineno, lstart)
|
||||
initialized come from the environment. Otherwise default to "main"
|
||||
(usually functions being defined interactively) */
|
||||
if (temp->source_file == 0)
|
||||
temp->source_file = shell_initialized ? "main" : "environment";
|
||||
{
|
||||
if (shell_initialized == 0)
|
||||
temp->source_file = "environment";
|
||||
else if (interactive_shell)
|
||||
temp->source_file = "main";
|
||||
else if (interactive == 0) /* assume -c command */
|
||||
temp->source_file = dollar_vars[0];
|
||||
else
|
||||
temp->source_file = shell_name; /* this clause is never hit */
|
||||
}
|
||||
|
||||
#if defined (DEBUGGER)
|
||||
bind_function_def (name->word, temp, 0);
|
||||
@@ -813,8 +774,7 @@ make_function_def (name, command, lineno, lstart)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_subshell_command (command)
|
||||
COMMAND *command;
|
||||
make_subshell_command (COMMAND *command)
|
||||
{
|
||||
SUBSHELL_COM *temp;
|
||||
|
||||
@@ -826,9 +786,7 @@ make_subshell_command (command)
|
||||
}
|
||||
|
||||
COMMAND *
|
||||
make_coproc_command (name, command)
|
||||
char *name;
|
||||
COMMAND *command;
|
||||
make_coproc_command (char *name, COMMAND *command)
|
||||
{
|
||||
COPROC_COM *temp;
|
||||
|
||||
@@ -843,8 +801,7 @@ make_coproc_command (name, command)
|
||||
has just been parsed. It seems simpler to do this here the one
|
||||
time then by any other method that I can think of. */
|
||||
COMMAND *
|
||||
clean_simple_command (command)
|
||||
COMMAND *command;
|
||||
clean_simple_command (COMMAND *command)
|
||||
{
|
||||
if (command->type != cm_simple)
|
||||
command_error ("clean_simple_command", CMDERR_BADTYPE, command->type, 0);
|
||||
@@ -870,9 +827,7 @@ clean_simple_command (command)
|
||||
in the list. This is done only for lists connected by `;'; it makes
|
||||
`;' bind `tighter' than `&'. */
|
||||
COMMAND *
|
||||
connect_async_list (command, command2, connector)
|
||||
COMMAND *command, *command2;
|
||||
int connector;
|
||||
connect_async_list (COMMAND *command, COMMAND *command2, int connector)
|
||||
{
|
||||
COMMAND *t, *t1, *t2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user