forked from bminor/bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_cmd.cc
183 lines (151 loc) · 3.88 KB
/
copy_cmd.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* copy_command.cc -- copy command objects. */
/* Copyright (C) 1987-2020 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "bashtypes.hh"
#include "shell.hh"
namespace bash
{
/* Copy the chain of words in LIST into the new object. */
WORD_LIST::WORD_LIST (const WORD_LIST &w)
: GENERIC_LIST (w.next_), word (w.word)
{
if (word)
word = new WORD_DESC (*word);
// Recursively clone the remaining list items.
WORD_LIST *next_word = next ();
if (next_word)
set_next (new WORD_LIST (*next_word));
}
/* Copy the chain of case clauses into the new object. */
PATTERN_LIST::PATTERN_LIST (const PATTERN_LIST &p)
: GENERIC_LIST (p.next_), patterns (p.patterns), action (p.action),
flags (p.flags)
{
if (patterns)
patterns = new WORD_LIST (*patterns);
if (action)
action = action->clone ();
// Recursively clone the remaining clauses.
PATTERN_LIST *next_clause = next ();
if (next_clause)
set_next (new PATTERN_LIST (*next_clause));
}
REDIRECT::REDIRECT (const REDIRECT &other)
: GENERIC_LIST (other.next_), here_doc_eof (other.here_doc_eof),
redirector (other.redirector), redirectee (other.redirectee),
rflags (other.rflags), flags (other.flags),
instruction (other.instruction)
{
if (rflags & REDIR_VARASSIGN)
redirector.r.filename = new WORD_DESC (*(redirector.r.filename));
switch (instruction)
{
case r_reading_until:
case r_deblank_reading_until:
case r_reading_string:
case r_appending_to:
case r_output_direction:
case r_input_direction:
case r_inputa_direction:
case r_err_and_out:
case r_append_err_and_out:
case r_input_output:
case r_output_force:
case r_duplicating_input_word:
case r_duplicating_output_word:
case r_move_input_word:
case r_move_output_word:
redirectee.r.filename = new WORD_DESC (*(redirectee.r.filename));
break;
case r_duplicating_input:
case r_duplicating_output:
case r_move_input:
case r_move_output:
case r_close_this:
break;
}
// Recursively clone the remaining redirections.
REDIRECT *next_redirection = next ();
if (next_redirection)
set_next (new REDIRECT (*next_redirection));
}
/* Copy the command structure in COMMAND. Return a pointer to the
copy. Don't forget to call delete on the returned copy. */
COMMAND *
CONNECTION::clone ()
{
return new CONNECTION (*this);
}
COMMAND *
CASE_COM::clone ()
{
return new CASE_COM (*this);
}
COMMAND *
FOR_SELECT_COM::clone ()
{
return new FOR_SELECT_COM (*this);
}
COMMAND *
ARITH_FOR_COM::clone ()
{
return new ARITH_FOR_COM (*this);
}
COMMAND *
IF_COM::clone ()
{
return new IF_COM (*this);
}
COMMAND *
UNTIL_WHILE_COM::clone ()
{
return new UNTIL_WHILE_COM (*this);
}
COMMAND *
ARITH_COM::clone ()
{
return new ARITH_COM (*this);
}
COMMAND *
COND_COM::clone ()
{
return new COND_COM (*this);
}
COMMAND *
SIMPLE_COM::clone ()
{
return new SIMPLE_COM (*this);
}
COMMAND *
FUNCTION_DEF::clone ()
{
return new FUNCTION_DEF (*this);
}
COMMAND *
GROUP_COM::clone ()
{
return new GROUP_COM (*this);
}
COMMAND *
SUBSHELL_COM::clone ()
{
return new SUBSHELL_COM (*this);
}
COMMAND *
COPROC_COM::clone ()
{
return new COPROC_COM (*this);
}
} // namespace bash