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 #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);
66 dispose_command (command->value.Group->command);
67 free (command->value.Group);
76 c = command->value.Case;
77 dispose_word (c->word);
79 for (p = c->clauses; p; )
81 dispose_words (p->patterns);
82 dispose_command (p->action);
94 register WHILE_COM *c;
96 c = command->value.While;
97 dispose_command (c->test);
98 dispose_command (c->action);
107 c = command->value.If;
108 dispose_command (c->test);
109 dispose_command (c->true_case);
110 dispose_command (c->false_case);
117 register SIMPLE_COM *c;
119 c = command->value.Simple;
120 dispose_words (c->words);
121 dispose_redirects (c->redirects);
128 register CONNECTION *c;
130 c = command->value.Connection;
131 dispose_command (c->first);
132 dispose_command (c->second);
137 #if defined (DPAREN_ARITHMETIC)
140 register ARITH_COM *c;
142 c = command->value.Arith;
143 dispose_words (c->exp);
147 #endif /* DPAREN_ARITHMETIC */
149 #if defined (COND_COMMAND)
152 register COND_COM *c;
154 c = command->value.Cond;
155 dispose_cond_node (c);
158 #endif /* COND_COMMAND */
160 case cm_function_def:
162 register FUNCTION_DEF *c;
164 c = command->value.Function_def;
165 dispose_word (c->name);
166 dispose_command (c->command);
172 programming_error ("dispose_command: bad command type `%d'", command->type);
178 #if defined (COND_COMMAND)
179 /* How to free a node in a conditional command. */
181 dispose_cond_node (cond)
187 dispose_cond_node (cond->left);
189 dispose_cond_node (cond->right);
191 dispose_word (cond->op);
195 #endif /* COND_COMMAND */
197 /* How to free a WORD_DESC. */
206 /* How to get rid of a linked list of words. A WORD_LIST. */
217 dispose_word (t->word);
222 #ifdef INCLUDE_UNUSED
223 /* How to dispose of an array of pointers to char. This is identical to
224 free_array in stringlib.c. */
226 dispose_word_array (array)
234 for (count = 0; array[count]; count++)
241 /* How to dispose of an list of redirections. A REDIRECT. */
243 dispose_redirects (list)
246 register REDIRECT *t;
252 switch (t->instruction)
254 case r_reading_until:
255 case r_deblank_reading_until:
256 free (t->here_doc_eof);
258 case r_output_direction:
259 case r_input_direction:
260 case r_inputa_direction:
265 case r_duplicating_input_word:
266 case r_duplicating_output_word:
267 dispose_word (t->redirectee.filename);