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_word (c
->name
);
190 dispose_command (c
->command
);
196 command_error ("dispose_command", CMDERR_BADTYPE
, command
->type
, 0);
202 #if defined (COND_COMMAND)
203 /* How to free a node in a conditional command. */
205 dispose_cond_node (cond
)
211 dispose_cond_node (cond
->left
);
213 dispose_cond_node (cond
->right
);
215 dispose_word (cond
->op
);
219 #endif /* COND_COMMAND */
221 /* How to free a WORD_DESC. */
230 ocache_free (wdcache
, WORD_DESC
, w
);
234 /* How to get rid of a linked list of words. A WORD_LIST. */
245 dispose_word (t
->word
);
249 ocache_free (wlcache
, WORD_LIST
, t
);
254 #ifdef INCLUDE_UNUSED
255 /* How to dispose of an array of pointers to char. This is identical to
256 free_array in stringlib.c. */
258 dispose_word_array (array
)
266 for (count
= 0; array
[count
]; count
++)
273 /* How to dispose of an list of redirections. A REDIRECT. */
275 dispose_redirects (list
)
278 register REDIRECT
*t
;
284 switch (t
->instruction
)
286 case r_reading_until
:
287 case r_deblank_reading_until
:
288 free (t
->here_doc_eof
);
290 case r_reading_string
:
291 case r_output_direction
:
292 case r_input_direction
:
293 case r_inputa_direction
:
298 case r_duplicating_input_word
:
299 case r_duplicating_output_word
:
300 case r_move_input_word
:
301 case r_move_output_word
:
302 dispose_word (t
->redirectee
.filename
);