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 2, 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, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
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);
100 c = command->value.Case;
101 dispose_word (c->word);
103 for (p = c->clauses; p; )
105 dispose_words (p->patterns);
106 dispose_command (p->action);
118 register WHILE_COM *c;
120 c = command->value.While;
121 dispose_command (c->test);
122 dispose_command (c->action);
131 c = command->value.If;
132 dispose_command (c->test);
133 dispose_command (c->true_case);
134 dispose_command (c->false_case);
141 register SIMPLE_COM *c;
143 c = command->value.Simple;
144 dispose_words (c->words);
145 dispose_redirects (c->redirects);
152 register CONNECTION *c;
154 c = command->value.Connection;
155 dispose_command (c->first);
156 dispose_command (c->second);
161 #if defined (DPAREN_ARITHMETIC)
164 register ARITH_COM *c;
166 c = command->value.Arith;
167 dispose_words (c->exp);
171 #endif /* DPAREN_ARITHMETIC */
173 #if defined (COND_COMMAND)
176 register COND_COM *c;
178 c = command->value.Cond;
179 dispose_cond_node (c);
182 #endif /* COND_COMMAND */
184 case cm_function_def:
186 register FUNCTION_DEF *c;
188 c = command->value.Function_def;
189 dispose_function_def (c);
194 command_error ("dispose_command", CMDERR_BADTYPE, command->type, 0);
200 #if defined (COND_COMMAND)
201 /* How to free a node in a conditional command. */
203 dispose_cond_node (cond)
209 dispose_cond_node (cond->left);
211 dispose_cond_node (cond->right);
213 dispose_word (cond->op);
217 #endif /* COND_COMMAND */
220 dispose_function_def_contents (c)
223 dispose_word (c->name);
224 dispose_command (c->command);
225 FREE (c->source_file);
229 dispose_function_def (c)
232 dispose_function_def_contents (c);
236 /* How to free a WORD_DESC. */
245 ocache_free (wdcache, WORD_DESC, w);
249 /* How to get rid of a linked list of words. A WORD_LIST. */
260 dispose_word (t->word);
264 ocache_free (wlcache, WORD_LIST, t);
269 #ifdef INCLUDE_UNUSED
270 /* How to dispose of an array of pointers to char. This is identical to
271 free_array in stringlib.c. */
273 dispose_word_array (array)
281 for (count = 0; array[count]; count++)
288 /* How to dispose of an list of redirections. A REDIRECT. */
290 dispose_redirects (list)
293 register REDIRECT *t;
299 switch (t->instruction)
301 case r_reading_until:
302 case r_deblank_reading_until:
303 free (t->here_doc_eof);
305 case r_reading_string:
306 case r_output_direction:
307 case r_input_direction:
308 case r_inputa_direction:
313 case r_duplicating_input_word:
314 case r_duplicating_output_word:
315 case r_move_input_word:
316 case r_move_output_word:
317 dispose_word (t->redirectee.filename);