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 /* Dispose of the command structure passed. */
25 dispose_command (command
)
30 if (command
->redirects
)
31 dispose_redirects (command
->redirects
);
33 switch (command
->type
)
37 register FOR_COM
*c
= command
->value
.For
;
38 dispose_word (c
->name
);
39 dispose_words (c
->map_list
);
40 dispose_command (c
->action
);
45 #if defined (SELECT_COMMAND)
48 register SELECT_COM
*c
= command
->value
.Select
;
49 dispose_word (c
->name
);
50 dispose_words (c
->map_list
);
51 dispose_command (c
->action
);
59 dispose_command (command
->value
.Group
->command
);
60 free (command
->value
.Group
);
66 register CASE_COM
*c
= command
->value
.Case
;
67 PATTERN_LIST
*t
, *p
= c
->clauses
;
69 dispose_word (c
->word
);
73 dispose_words (p
->patterns
);
74 dispose_command (p
->action
);
86 register WHILE_COM
*c
= command
->value
.While
;
88 dispose_command (c
->test
);
89 dispose_command (c
->action
);
96 register IF_COM
*c
= command
->value
.If
;
97 dispose_command (c
->test
);
98 dispose_command (c
->true_case
);
99 dispose_command (c
->false_case
);
106 register SIMPLE_COM
*c
= command
->value
.Simple
;
107 dispose_words (c
->words
);
108 dispose_redirects (c
->redirects
);
115 register CONNECTION
*c
= command
->value
.Connection
;
116 dispose_command (c
->first
);
117 dispose_command (c
->second
);
122 case cm_function_def
:
124 register FUNCTION_DEF
*c
= command
->value
.Function_def
;
125 dispose_word (c
->name
);
126 dispose_command (c
->command
);
132 report_error ("Attempt to free unknown command type `%d'.\n", command
->type
);
138 /* How to free a WORD_DESC. */
148 /* How to get rid of a linked list of words. A WORD_LIST. */
158 dispose_word (t
->word
);
163 /* How to dispose of an array of pointers to char. */
165 dispose_word_array (array
)
170 for (count
= 0; array
[count
]; count
++)
176 /* How to dispose of an list of redirections. A REDIRECT. */
178 dispose_redirects (list
)
181 register REDIRECT
*t
;
187 switch (t
->instruction
)
189 case r_reading_until
:
190 case r_deblank_reading_until
:
191 free (t
->here_doc_eof
);
193 case r_output_direction
:
194 case r_input_direction
:
195 case r_inputa_direction
:
200 case r_duplicating_input_word
:
201 case r_duplicating_output_word
:
202 dispose_word (t
->redirectee
.filename
);