1 /* dispose_command.c -- dispose of a COMMAND structure. */
3 /* Copyright (C) 1987,1991 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
12 Bash is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bash; see the file COPYING. If not, write to the Free
19 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #if defined (HAVE_UNISTD_H)
30 /* Dispose of the command structure passed. */
32 dispose_command (command)
38 if (command->redirects)
39 dispose_redirects (command->redirects);
41 switch (command->type)
44 #if defined (SELECT_COMMAND)
49 #if defined (SELECT_COMMAND)
50 if (command->type == cm_select)
51 c = (FOR_COM *)command->value.Select;
54 c = command->value.For;
55 dispose_word (c->name);
56 dispose_words (c->map_list);
57 dispose_command (c->action);
64 dispose_command (command->value.Group->command);
65 free (command->value.Group);
74 c = command->value.Case;
75 dispose_word (c->word);
77 for (p = c->clauses; p; )
79 dispose_words (p->patterns);
80 dispose_command (p->action);
92 register WHILE_COM *c;
94 c = command->value.While;
95 dispose_command (c->test);
96 dispose_command (c->action);
105 c = command->value.If;
106 dispose_command (c->test);
107 dispose_command (c->true_case);
108 dispose_command (c->false_case);
115 register SIMPLE_COM *c;
117 c = command->value.Simple;
118 dispose_words (c->words);
119 dispose_redirects (c->redirects);
126 register CONNECTION *c;
128 c = command->value.Connection;
129 dispose_command (c->first);
130 dispose_command (c->second);
135 case cm_function_def:
137 register FUNCTION_DEF *c;
139 c = command->value.Function_def;
140 dispose_word (c->name);
141 dispose_command (c->command);
147 programming_error ("dispose_command: bad command type `%d'", command->type);
153 /* How to free a WORD_DESC. */
162 /* How to get rid of a linked list of words. A WORD_LIST. */
173 dispose_word (t->word);
178 /* How to dispose of an array of pointers to char. */
180 dispose_word_array (array)
185 for (count = 0; array[count]; count++)
191 /* How to dispose of an list of redirections. A REDIRECT. */
193 dispose_redirects (list)
196 register REDIRECT *t;
202 switch (t->instruction)
204 case r_reading_until:
205 case r_deblank_reading_until:
206 free (t->here_doc_eof);
208 case r_output_direction:
209 case r_input_direction:
210 case r_inputa_direction:
215 case r_duplicating_input_word:
216 case r_duplicating_output_word:
217 dispose_word (t->redirectee.filename);