1 /* dispose_command.c -- dispose of a COMMAND structure. */
3 /* Copyright (C) 1987-2009 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
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
23 #include "bashtypes.h"
25 #if defined (HAVE_UNISTD_H)
32 extern sh_obj_cache_t wdcache, wlcache;
34 /* Dispose of the command structure passed. */
36 dispose_command (command)
42 if (command->redirects)
43 dispose_redirects (command->redirects);
45 switch (command->type)
48 #if defined (SELECT_COMMAND)
53 #if defined (SELECT_COMMAND)
54 if (command->type == cm_select)
55 c = (FOR_COM *)command->value.Select;
58 c = command->value.For;
59 dispose_word (c->name);
60 dispose_words (c->map_list);
61 dispose_command (c->action);
66 #if defined (ARITH_FOR_COMMAND)
69 register ARITH_FOR_COM *c;
71 c = command->value.ArithFor;
72 dispose_words (c->init);
73 dispose_words (c->test);
74 dispose_words (c->step);
75 dispose_command (c->action);
79 #endif /* ARITH_FOR_COMMAND */
83 dispose_command (command->value.Group->command);
84 free (command->value.Group);
90 dispose_command (command->value.Subshell->command);
91 free (command->value.Subshell);
97 free (command->value.Coproc->name);
98 dispose_command (command->value.Coproc->command);
99 free (command->value.Coproc);
105 register CASE_COM *c;
108 c = command->value.Case;
109 dispose_word (c->word);
111 for (p = c->clauses; p; )
113 dispose_words (p->patterns);
114 dispose_command (p->action);
126 register WHILE_COM *c;
128 c = command->value.While;
129 dispose_command (c->test);
130 dispose_command (c->action);
139 c = command->value.If;
140 dispose_command (c->test);
141 dispose_command (c->true_case);
142 dispose_command (c->false_case);
149 register SIMPLE_COM *c;
151 c = command->value.Simple;
152 dispose_words (c->words);
153 dispose_redirects (c->redirects);
160 register CONNECTION *c;
162 c = command->value.Connection;
163 dispose_command (c->first);
164 dispose_command (c->second);
169 #if defined (DPAREN_ARITHMETIC)
172 register ARITH_COM *c;
174 c = command->value.Arith;
175 dispose_words (c->exp);
179 #endif /* DPAREN_ARITHMETIC */
181 #if defined (COND_COMMAND)
184 register COND_COM *c;
186 c = command->value.Cond;
187 dispose_cond_node (c);
190 #endif /* COND_COMMAND */
192 case cm_function_def:
194 register FUNCTION_DEF *c;
196 c = command->value.Function_def;
197 dispose_function_def (c);
202 command_error ("dispose_command", CMDERR_BADTYPE, command->type, 0);
208 #if defined (COND_COMMAND)
209 /* How to free a node in a conditional command. */
211 dispose_cond_node (cond)
217 dispose_cond_node (cond->left);
219 dispose_cond_node (cond->right);
221 dispose_word (cond->op);
225 #endif /* COND_COMMAND */
228 dispose_function_def_contents (c)
231 dispose_word (c->name);
232 dispose_command (c->command);
233 FREE (c->source_file);
237 dispose_function_def (c)
240 dispose_function_def_contents (c);
244 /* How to free a WORD_DESC. */
250 ocache_free (wdcache, WORD_DESC, w);
253 /* Free a WORD_DESC, but not the word contained within. */
255 dispose_word_desc (w)
259 ocache_free (wdcache, WORD_DESC, w);
262 /* How to get rid of a linked list of words. A WORD_LIST. */
273 dispose_word (t->word);
277 ocache_free (wlcache, WORD_LIST, t);
282 #ifdef INCLUDE_UNUSED
283 /* How to dispose of an array of pointers to char. This is identical to
284 free_array in stringlib.c. */
286 dispose_word_array (array)
294 for (count = 0; array[count]; count++)
301 /* How to dispose of an list of redirections. A REDIRECT. */
303 dispose_redirects (list)
306 register REDIRECT *t;
313 if (t->rflags & REDIR_VARASSIGN)
314 dispose_word (t->redirector.filename);
316 switch (t->instruction)
318 case r_reading_until:
319 case r_deblank_reading_until:
320 free (t->here_doc_eof);
322 case r_reading_string:
323 case r_output_direction:
324 case r_input_direction:
325 case r_inputa_direction:
328 case r_append_err_and_out:
331 case r_duplicating_input_word:
332 case r_duplicating_output_word:
333 case r_move_input_word:
334 case r_move_output_word:
335 dispose_word (t->redirectee.filename);