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 /* Dispose of the command structure passed. */
34 dispose_command (command)
40 if (command->redirects)
41 dispose_redirects (command->redirects);
43 switch (command->type)
46 #if defined (SELECT_COMMAND)
51 #if defined (SELECT_COMMAND)
52 if (command->type == cm_select)
53 c = (FOR_COM *)command->value.Select;
56 c = command->value.For;
57 dispose_word (c->name);
58 dispose_words (c->map_list);
59 dispose_command (c->action);
64 #if defined (ARITH_FOR_COMMAND)
67 register ARITH_FOR_COM *c;
69 c = command->value.ArithFor;
70 dispose_words (c->init);
71 dispose_words (c->test);
72 dispose_words (c->step);
73 dispose_command (c->action);
77 #endif /* ARITH_FOR_COMMAND */
81 dispose_command (command->value.Group->command);
82 free (command->value.Group);
88 dispose_command (command->value.Subshell->command);
89 free (command->value.Subshell);
98 c = command->value.Case;
99 dispose_word (c->word);
101 for (p = c->clauses; p; )
103 dispose_words (p->patterns);
104 dispose_command (p->action);
116 register WHILE_COM *c;
118 c = command->value.While;
119 dispose_command (c->test);
120 dispose_command (c->action);
129 c = command->value.If;
130 dispose_command (c->test);
131 dispose_command (c->true_case);
132 dispose_command (c->false_case);
139 register SIMPLE_COM *c;
141 c = command->value.Simple;
142 dispose_words (c->words);
143 dispose_redirects (c->redirects);
150 register CONNECTION *c;
152 c = command->value.Connection;
153 dispose_command (c->first);
154 dispose_command (c->second);
159 #if defined (DPAREN_ARITHMETIC)
162 register ARITH_COM *c;
164 c = command->value.Arith;
165 dispose_words (c->exp);
169 #endif /* DPAREN_ARITHMETIC */
171 #if defined (COND_COMMAND)
174 register COND_COM *c;
176 c = command->value.Cond;
177 dispose_cond_node (c);
180 #endif /* COND_COMMAND */
182 case cm_function_def:
184 register FUNCTION_DEF *c;
186 c = command->value.Function_def;
187 dispose_word (c->name);
188 dispose_command (c->command);
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 */
219 /* How to free a WORD_DESC. */
228 /* How to get rid of a linked list of words. A WORD_LIST. */
239 dispose_word (t->word);
244 #ifdef INCLUDE_UNUSED
245 /* How to dispose of an array of pointers to char. This is identical to
246 free_array in stringlib.c. */
248 dispose_word_array (array)
256 for (count = 0; array[count]; count++)
263 /* How to dispose of an list of redirections. A REDIRECT. */
265 dispose_redirects (list)
268 register REDIRECT *t;
274 switch (t->instruction)
276 case r_reading_until:
277 case r_deblank_reading_until:
278 free (t->here_doc_eof);
280 case r_output_direction:
281 case r_input_direction:
282 case r_inputa_direction:
287 case r_duplicating_input_word:
288 case r_duplicating_output_word:
289 dispose_word (t->redirectee.filename);