X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=copy_cmd.c;h=d36436c9c8437550b0c3bcd665849746dbcb1e1d;hb=95732b497d12c98613bb3c5db16b61f377501a59;hp=e28e6f079decf3e7db257655ceceb0bc55aad9b9;hpb=cce855bc5b117cb7ae70064131120687bc69fac0;p=platform%2Fupstream%2Fbash.git diff --git a/copy_cmd.c b/copy_cmd.c index e28e6f0..d36436c 100644 --- a/copy_cmd.c +++ b/copy_cmd.c @@ -8,7 +8,7 @@ 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) + the Free 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 @@ -18,7 +18,7 @@ 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. */ + Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #include "config.h" @@ -32,15 +32,33 @@ #include "shell.h" +static PATTERN_LIST *copy_case_clause __P((PATTERN_LIST *)); +static PATTERN_LIST *copy_case_clauses __P((PATTERN_LIST *)); +static FOR_COM *copy_for_command __P((FOR_COM *)); +#if defined (ARITH_FOR_COMMAND) +static ARITH_FOR_COM *copy_arith_for_command __P((ARITH_FOR_COM *)); +#endif +static GROUP_COM *copy_group_command __P((GROUP_COM *)); +static SUBSHELL_COM *copy_subshell_command __P((SUBSHELL_COM *)); +static CASE_COM *copy_case_command __P((CASE_COM *)); +static WHILE_COM *copy_while_command __P((WHILE_COM *)); +static IF_COM *copy_if_command __P((IF_COM *)); +#if defined (DPAREN_ARITHMETIC) +static ARITH_COM *copy_arith_command __P((ARITH_COM *)); +#endif +#if defined (COND_COMMAND) +static COND_COM *copy_cond_command __P((COND_COM *)); +#endif +static SIMPLE_COM *copy_simple_command __P((SIMPLE_COM *)); + WORD_DESC * copy_word (w) WORD_DESC *w; { WORD_DESC *new_word; - new_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC)); - FASTCOPY ((char *)w, (char *)new_word, sizeof (WORD_DESC)); - new_word->word = savestring (w->word); + new_word = make_bare_word (w->word); + new_word->flags = w->flags; return (new_word); } @@ -50,15 +68,11 @@ WORD_LIST * copy_word_list (list) WORD_LIST *list; { - WORD_LIST *new_list, *temp; + WORD_LIST *new_list; for (new_list = (WORD_LIST *)NULL; list; list = list->next) - { - temp = (WORD_LIST *)xmalloc (sizeof (WORD_LIST)); - temp->next = new_list; - new_list = temp; - new_list->word = copy_word (list->word); - } + new_list = make_word_list (copy_word (list->word), new_list); + return (REVERSE_LIST (new_list, WORD_LIST *)); } @@ -104,6 +118,7 @@ copy_redirect (redirect) case r_deblank_reading_until: new_redirect->here_doc_eof = savestring (redirect->here_doc_eof); /*FALLTHROUGH*/ + case r_reading_string: case r_appending_to: case r_output_direction: case r_input_direction: @@ -113,10 +128,14 @@ copy_redirect (redirect) case r_output_force: case r_duplicating_input_word: case r_duplicating_output_word: + case r_move_input_word: + case r_move_output_word: new_redirect->redirectee.filename = copy_word (redirect->redirectee.filename); break; case r_duplicating_input: case r_duplicating_output: + case r_move_input: + case r_move_output: case r_close_this: break; } @@ -146,12 +165,31 @@ copy_for_command (com) new_for = (FOR_COM *)xmalloc (sizeof (FOR_COM)); new_for->flags = com->flags; + new_for->line = com->line; new_for->name = copy_word (com->name); new_for->map_list = copy_word_list (com->map_list); new_for->action = copy_command (com->action); return (new_for); } +#if defined (ARITH_FOR_COMMAND) +static ARITH_FOR_COM * +copy_arith_for_command (com) + ARITH_FOR_COM *com; +{ + ARITH_FOR_COM *new_arith_for; + + new_arith_for = (ARITH_FOR_COM *)xmalloc (sizeof (ARITH_FOR_COM)); + new_arith_for->flags = com->flags; + new_arith_for->line = com->line; + new_arith_for->init = copy_word_list (com->init); + new_arith_for->test = copy_word_list (com->test); + new_arith_for->step = copy_word_list (com->step); + new_arith_for->action = copy_command (com->action); + return (new_arith_for); +} +#endif /* ARITH_FOR_COMMAND */ + static GROUP_COM * copy_group_command (com) GROUP_COM *com; @@ -163,6 +201,18 @@ copy_group_command (com) return (new_group); } +static SUBSHELL_COM * +copy_subshell_command (com) + SUBSHELL_COM *com; +{ + SUBSHELL_COM *new_subshell; + + new_subshell = (SUBSHELL_COM *)xmalloc (sizeof (SUBSHELL_COM)); + new_subshell->command = copy_command (com->command); + new_subshell->flags = com->flags; + return (new_subshell); +} + static CASE_COM * copy_case_command (com) CASE_COM *com; @@ -171,6 +221,7 @@ copy_case_command (com) new_case = (CASE_COM *)xmalloc (sizeof (CASE_COM)); new_case->flags = com->flags; + new_case->line = com->line; new_case->word = copy_word (com->word); new_case->clauses = copy_case_clauses (com->clauses); return (new_case); @@ -199,7 +250,7 @@ copy_if_command (com) new_if->flags = com->flags; new_if->test = copy_command (com->test); new_if->true_case = copy_command (com->true_case); - new_if->false_case = copy_command (com->false_case); + new_if->false_case = com->false_case ? copy_command (com->false_case) : com->false_case; return (new_if); } @@ -229,7 +280,8 @@ copy_cond_command (com) new_cond = (COND_COM *)xmalloc (sizeof (COND_COM)); new_cond->flags = com->flags; new_cond->line = com->line; - new_cond->op = copy_word (com->op); + new_cond->type = com->type; + new_cond->op = com->op ? copy_word (com->op) : com->op; new_cond->left = com->left ? copy_cond_command (com->left) : (COND_COM *)NULL; new_cond->right = com->right ? copy_cond_command (com->right) : (COND_COM *)NULL; @@ -246,20 +298,31 @@ copy_simple_command (com) new_simple = (SIMPLE_COM *)xmalloc (sizeof (SIMPLE_COM)); new_simple->flags = com->flags; new_simple->words = copy_word_list (com->words); - new_simple->redirects = copy_redirects (com->redirects); + new_simple->redirects = com->redirects ? copy_redirects (com->redirects) : (REDIRECT *)NULL; new_simple->line = com->line; return (new_simple); } -static FUNCTION_DEF * +FUNCTION_DEF * +copy_function_def_contents (old, new_def) + FUNCTION_DEF *old, *new_def; +{ + new_def->name = copy_word (old->name); + new_def->command = old->command ? copy_command (old->command) : old->command; + new_def->flags = old->flags; + new_def->line = old->line; + new_def->source_file = old->source_file ? savestring (old->source_file) : old->source_file; + return (new_def); +} + +FUNCTION_DEF * copy_function_def (com) FUNCTION_DEF *com; { FUNCTION_DEF *new_def; new_def = (FUNCTION_DEF *)xmalloc (sizeof (FUNCTION_DEF)); - new_def->name = copy_word (com->name); - new_def->command = copy_command (com->command); + new_def = copy_function_def_contents (com, new_def); return (new_def); } @@ -289,6 +352,12 @@ copy_command (command) new_command->value.For = copy_for_command (command->value.For); break; +#if defined (ARITH_FOR_COMMAND) + case cm_arith_for: + new_command->value.ArithFor = copy_arith_for_command (command->value.ArithFor); + break; +#endif + #if defined (SELECT_COMMAND) case cm_select: new_command->value.Select = @@ -300,6 +369,10 @@ copy_command (command) new_command->value.Group = copy_group_command (command->value.Group); break; + case cm_subshell: + new_command->value.Subshell = copy_subshell_command (command->value.Subshell); + break; + case cm_case: new_command->value.Case = copy_case_command (command->value.Case); break; @@ -315,8 +388,8 @@ copy_command (command) #if defined (DPAREN_ARITHMETIC) case cm_arith: - new_command->value.Arith = copy_arith_command (command->value.Arith); - break; + new_command->value.Arith = copy_arith_command (command->value.Arith); + break; #endif #if defined (COND_COMMAND)