1.5.1
by Matthias Klose
Import upstream version 4.3~rc1 |
1 |
/* subst.h -- Names of externally visible functions in subst.c. */
|
2 |
||
3 |
/* Copyright (C) 1993-2010 Free Software Foundation, Inc.
|
|
4 |
||
5 |
This file is part of GNU Bash, the Bourne Again SHell.
|
|
6 |
||
7 |
Bash is free software: you can redistribute it and/or modify
|
|
8 |
it under the terms of the GNU General Public License as published by
|
|
9 |
the Free Software Foundation, either version 3 of the License, or
|
|
10 |
(at your option) any later version.
|
|
11 |
||
12 |
Bash is distributed in the hope that it will be useful,
|
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
GNU General Public License for more details.
|
|
16 |
||
17 |
You should have received a copy of the GNU General Public License
|
|
18 |
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
|
19 |
*/
|
|
20 |
||
21 |
#if !defined (_SUBST_H_)
|
|
22 |
#define _SUBST_H_
|
|
23 |
||
24 |
#include "stdc.h" |
|
25 |
||
26 |
/* Constants which specify how to handle backslashes and quoting in
|
|
27 |
expand_word_internal (). Q_DOUBLE_QUOTES means to use the function
|
|
28 |
slashify_in_quotes () to decide whether the backslash should be
|
|
29 |
retained. Q_HERE_DOCUMENT means slashify_in_here_document () to
|
|
30 |
decide whether to retain the backslash. Q_KEEP_BACKSLASH means
|
|
31 |
to unconditionally retain the backslash. Q_PATQUOTE means that we're
|
|
32 |
expanding a pattern ${var%#[#%]pattern} in an expansion surrounded
|
|
33 |
by double quotes. Q_DOLBRACE means we are expanding a ${...} word, so
|
|
34 |
backslashes should also escape { and } and be removed. */
|
|
35 |
#define Q_DOUBLE_QUOTES 0x01
|
|
36 |
#define Q_HERE_DOCUMENT 0x02
|
|
37 |
#define Q_KEEP_BACKSLASH 0x04
|
|
38 |
#define Q_PATQUOTE 0x08
|
|
39 |
#define Q_QUOTED 0x10
|
|
40 |
#define Q_ADDEDQUOTES 0x20
|
|
41 |
#define Q_QUOTEDNULL 0x40
|
|
42 |
#define Q_DOLBRACE 0x80
|
|
43 |
||
44 |
/* Flag values controlling how assignment statements are treated. */
|
|
45 |
#define ASS_APPEND 0x0001
|
|
46 |
#define ASS_MKLOCAL 0x0002
|
|
47 |
#define ASS_MKASSOC 0x0004
|
|
48 |
#define ASS_MKGLOBAL 0x0008 /* force global assignment */ |
|
1.5.2
by Matthias Klose
Import upstream version 4.3~rc2 |
49 |
#define ASS_NAMEREF 0x0010 /* assigning to nameref variable */ |
1.5.1
by Matthias Klose
Import upstream version 4.3~rc1 |
50 |
|
51 |
/* Flags for the string extraction functions. */
|
|
52 |
#define SX_NOALLOC 0x0001 /* just skip; don't return substring */ |
|
53 |
#define SX_VARNAME 0x0002 /* variable name; for string_extract () */ |
|
54 |
#define SX_REQMATCH 0x0004 /* closing/matching delimiter required */ |
|
55 |
#define SX_COMMAND 0x0008 /* extracting a shell script/command */ |
|
56 |
#define SX_NOCTLESC 0x0010 /* don't honor CTLESC quoting */ |
|
57 |
#define SX_NOESCCTLNUL 0x0020 /* don't let CTLESC quote CTLNUL */ |
|
58 |
#define SX_NOLONGJMP 0x0040 /* don't longjmp on fatal error */ |
|
59 |
#define SX_ARITHSUB 0x0080 /* extracting $(( ... )) (currently unused) */ |
|
60 |
#define SX_POSIXEXP 0x0100 /* extracting new Posix pattern removal expansions in extract_dollar_brace_string */ |
|
61 |
#define SX_WORD 0x0200 /* extracting word in ${param op word} */ |
|
62 |
||
63 |
/* Remove backslashes which are quoting backquotes from STRING. Modifies
|
|
64 |
STRING, and returns a pointer to it. */
|
|
65 |
extern char * de_backslash __P((char *)); |
|
66 |
||
67 |
/* Replace instances of \! in a string with !. */
|
|
68 |
extern void unquote_bang __P((char *)); |
|
69 |
||
70 |
/* Extract the $( construct in STRING, and return a new string.
|
|
71 |
Start extracting at (SINDEX) as if we had just seen "$(".
|
|
72 |
Make (SINDEX) get the position just after the matching ")".
|
|
73 |
XFLAGS is additional flags to pass to other extraction functions, */
|
|
74 |
extern char *extract_command_subst __P((char *, int *, int)); |
|
75 |
||
76 |
/* Extract the $[ construct in STRING, and return a new string.
|
|
77 |
Start extracting at (SINDEX) as if we had just seen "$[".
|
|
78 |
Make (SINDEX) get the position just after the matching "]". */
|
|
79 |
extern char *extract_arithmetic_subst __P((char *, int *)); |
|
80 |
||
81 |
#if defined (PROCESS_SUBSTITUTION)
|
|
82 |
/* Extract the <( or >( construct in STRING, and return a new string.
|
|
83 |
Start extracting at (SINDEX) as if we had just seen "<(".
|
|
84 |
Make (SINDEX) get the position just after the matching ")". */
|
|
85 |
extern char *extract_process_subst __P((char *, char *, int *)); |
|
86 |
#endif /* PROCESS_SUBSTITUTION */ |
|
87 |
||
88 |
/* Extract the name of the variable to bind to from the assignment string. */
|
|
89 |
extern char *assignment_name __P((char *)); |
|
90 |
||
91 |
/* Return a single string of all the words present in LIST, separating
|
|
92 |
each word with SEP. */
|
|
93 |
extern char *string_list_internal __P((WORD_LIST *, char *)); |
|
94 |
||
95 |
/* Return a single string of all the words present in LIST, separating
|
|
96 |
each word with a space. */
|
|
97 |
extern char *string_list __P((WORD_LIST *)); |
|
98 |
||
99 |
/* Turn $* into a single string, obeying POSIX rules. */
|
|
100 |
extern char *string_list_dollar_star __P((WORD_LIST *)); |
|
101 |
||
102 |
/* Expand $@ into a single string, obeying POSIX rules. */
|
|
103 |
extern char *string_list_dollar_at __P((WORD_LIST *, int)); |
|
104 |
||
105 |
/* Turn the positional paramters into a string, understanding quoting and
|
|
106 |
the various subtleties of using the first character of $IFS as the
|
|
107 |
separator. Calls string_list_dollar_at, string_list_dollar_star, and
|
|
108 |
string_list as appropriate. */
|
|
109 |
extern char *string_list_pos_params __P((int, WORD_LIST *, int)); |
|
110 |
||
111 |
/* Perform quoted null character removal on each element of LIST.
|
|
112 |
This modifies LIST. */
|
|
113 |
extern void word_list_remove_quoted_nulls __P((WORD_LIST *)); |
|
114 |
||
115 |
/* This performs word splitting and quoted null character removal on
|
|
116 |
STRING. */
|
|
117 |
extern WORD_LIST *list_string __P((char *, char *, int)); |
|
118 |
||
119 |
extern char *ifs_firstchar __P((int *)); |
|
120 |
extern char *get_word_from_string __P((char **, char *, char **)); |
|
121 |
extern char *strip_trailing_ifs_whitespace __P((char *, char *, int)); |
|
122 |
||
123 |
/* Given STRING, an assignment string, get the value of the right side
|
|
124 |
of the `=', and bind it to the left side. If EXPAND is true, then
|
|
125 |
perform tilde expansion, parameter expansion, command substitution,
|
|
126 |
and arithmetic expansion on the right-hand side. Do not perform word
|
|
127 |
splitting on the result of expansion. */
|
|
128 |
extern int do_assignment __P((char *)); |
|
129 |
extern int do_assignment_no_expand __P((char *)); |
|
130 |
extern int do_word_assignment __P((WORD_DESC *, int)); |
|
131 |
||
132 |
/* Append SOURCE to TARGET at INDEX. SIZE is the current amount
|
|
133 |
of space allocated to TARGET. SOURCE can be NULL, in which
|
|
134 |
case nothing happens. Gets rid of SOURCE by free ()ing it.
|
|
135 |
Returns TARGET in case the location has changed. */
|
|
136 |
extern char *sub_append_string __P((char *, char *, int *, int *)); |
|
137 |
||
138 |
/* Append the textual representation of NUMBER to TARGET.
|
|
139 |
INDEX and SIZE are as in SUB_APPEND_STRING. */
|
|
140 |
extern char *sub_append_number __P((intmax_t, char *, int *, int *)); |
|
141 |
||
142 |
/* Return the word list that corresponds to `$*'. */
|
|
143 |
extern WORD_LIST *list_rest_of_args __P((void)); |
|
144 |
||
145 |
/* Make a single large string out of the dollar digit variables,
|
|
146 |
and the rest_of_args. If DOLLAR_STAR is 1, then obey the special
|
|
147 |
case of "$*" with respect to IFS. */
|
|
148 |
extern char *string_rest_of_args __P((int)); |
|
149 |
||
150 |
extern int number_of_args __P((void)); |
|
151 |
||
152 |
/* Expand STRING by performing parameter expansion, command substitution,
|
|
153 |
and arithmetic expansion. Dequote the resulting WORD_LIST before
|
|
154 |
returning it, but do not perform word splitting. The call to
|
|
155 |
remove_quoted_nulls () is made here because word splitting normally
|
|
156 |
takes care of quote removal. */
|
|
157 |
extern WORD_LIST *expand_string_unsplit __P((char *, int)); |
|
158 |
||
159 |
/* Expand the rhs of an assignment statement. */
|
|
160 |
extern WORD_LIST *expand_string_assignment __P((char *, int)); |
|
161 |
||
162 |
/* Expand a prompt string. */
|
|
163 |
extern WORD_LIST *expand_prompt_string __P((char *, int, int)); |
|
164 |
||
165 |
/* Expand STRING just as if you were expanding a word. This also returns
|
|
166 |
a list of words. Note that filename globbing is *NOT* done for word
|
|
167 |
or string expansion, just when the shell is expanding a command. This
|
|
168 |
does parameter expansion, command substitution, arithmetic expansion,
|
|
169 |
and word splitting. Dequote the resultant WORD_LIST before returning. */
|
|
170 |
extern WORD_LIST *expand_string __P((char *, int)); |
|
171 |
||
172 |
/* Convenience functions that expand strings to strings, taking care of
|
|
173 |
converting the WORD_LIST * returned by the expand_string* functions
|
|
174 |
to a string and deallocating the WORD_LIST *. */
|
|
175 |
extern char *expand_string_to_string __P((char *, int)); |
|
176 |
extern char *expand_string_unsplit_to_string __P((char *, int)); |
|
177 |
extern char *expand_assignment_string_to_string __P((char *, int)); |
|
178 |
||
179 |
/* Expand an arithmetic expression string */
|
|
180 |
extern char *expand_arith_string __P((char *, int)); |
|
181 |
||
182 |
/* De-quote quoted characters in STRING. */
|
|
183 |
extern char *dequote_string __P((char *)); |
|
184 |
||
185 |
/* De-quote CTLESC-escaped CTLESC or CTLNUL characters in STRING. */
|
|
186 |
extern char *dequote_escapes __P((char *)); |
|
187 |
||
188 |
/* De-quote quoted characters in each word in LIST. */
|
|
189 |
extern WORD_LIST *dequote_list __P((WORD_LIST *)); |
|
190 |
||
191 |
/* Expand WORD, performing word splitting on the result. This does
|
|
192 |
parameter expansion, command substitution, arithmetic expansion,
|
|
193 |
word splitting, and quote removal. */
|
|
194 |
extern WORD_LIST *expand_word __P((WORD_DESC *, int)); |
|
195 |
||
196 |
/* Expand WORD, but do not perform word splitting on the result. This
|
|
197 |
does parameter expansion, command substitution, arithmetic expansion,
|
|
198 |
and quote removal. */
|
|
199 |
extern WORD_LIST *expand_word_unsplit __P((WORD_DESC *, int)); |
|
200 |
extern WORD_LIST *expand_word_leave_quoted __P((WORD_DESC *, int)); |
|
201 |
||
202 |
/* Return the value of a positional parameter. This handles values > 10. */
|
|
203 |
extern char *get_dollar_var_value __P((intmax_t)); |
|
204 |
||
205 |
/* Quote a string to protect it from word splitting. */
|
|
206 |
extern char *quote_string __P((char *)); |
|
207 |
||
208 |
/* Quote escape characters (characters special to interals of expansion)
|
|
209 |
in a string. */
|
|
210 |
extern char *quote_escapes __P((char *)); |
|
211 |
||
212 |
/* And remove such quoted special characters. */
|
|
213 |
extern char *remove_quoted_escapes __P((char *)); |
|
214 |
||
215 |
/* Remove CTLNUL characters from STRING unless they are quoted with CTLESC. */
|
|
216 |
extern char *remove_quoted_nulls __P((char *)); |
|
217 |
||
218 |
/* Perform quote removal on STRING. If QUOTED > 0, assume we are obeying the
|
|
219 |
backslash quoting rules for within double quotes. */
|
|
220 |
extern char *string_quote_removal __P((char *, int)); |
|
221 |
||
222 |
/* Perform quote removal on word WORD. This allocates and returns a new
|
|
223 |
WORD_DESC *. */
|
|
224 |
extern WORD_DESC *word_quote_removal __P((WORD_DESC *, int)); |
|
225 |
||
226 |
/* Perform quote removal on all words in LIST. If QUOTED is non-zero,
|
|
227 |
the members of the list are treated as if they are surrounded by
|
|
228 |
double quotes. Return a new list, or NULL if LIST is NULL. */
|
|
229 |
extern WORD_LIST *word_list_quote_removal __P((WORD_LIST *, int)); |
|
230 |
||
231 |
/* Called when IFS is changed to maintain some private variables. */
|
|
232 |
extern void setifs __P((SHELL_VAR *)); |
|
233 |
||
234 |
/* Return the value of $IFS, or " \t\n" if IFS is unset. */
|
|
235 |
extern char *getifs __P((void)); |
|
236 |
||
237 |
/* This splits a single word into a WORD LIST on $IFS, but only if the word
|
|
238 |
is not quoted. list_string () performs quote removal for us, even if we
|
|
239 |
don't do any splitting. */
|
|
240 |
extern WORD_LIST *word_split __P((WORD_DESC *, char *)); |
|
241 |
||
242 |
/* Take the list of words in LIST and do the various substitutions. Return
|
|
243 |
a new list of words which is the expanded list, and without things like
|
|
244 |
variable assignments. */
|
|
245 |
extern WORD_LIST *expand_words __P((WORD_LIST *)); |
|
246 |
||
247 |
/* Same as expand_words (), but doesn't hack variable or environment
|
|
248 |
variables. */
|
|
249 |
extern WORD_LIST *expand_words_no_vars __P((WORD_LIST *)); |
|
250 |
||
251 |
/* Perform the `normal shell expansions' on a WORD_LIST. These are
|
|
252 |
brace expansion, tilde expansion, parameter and variable substitution,
|
|
253 |
command substitution, arithmetic expansion, and word splitting. */
|
|
254 |
extern WORD_LIST *expand_words_shellexp __P((WORD_LIST *)); |
|
255 |
||
256 |
extern WORD_DESC *command_substitute __P((char *, int)); |
|
257 |
extern char *pat_subst __P((char *, char *, char *, int)); |
|
258 |
||
259 |
extern int fifos_pending __P((void)); |
|
260 |
extern int num_fifos __P((void)); |
|
261 |
extern void unlink_fifo_list __P((void)); |
|
262 |
extern void unlink_fifo __P((int)); |
|
263 |
||
264 |
extern char *copy_fifo_list __P((int *)); |
|
265 |
extern void unlink_new_fifos __P((char *, int)); |
|
266 |
extern void close_new_fifos __P((char *, int)); |
|
267 |
||
268 |
extern WORD_LIST *list_string_with_quotes __P((char *)); |
|
269 |
||
270 |
#if defined (ARRAY_VARS)
|
|
271 |
extern char *extract_array_assignment_list __P((char *, int *)); |
|
272 |
#endif
|
|
273 |
||
274 |
#if defined (COND_COMMAND)
|
|
275 |
extern char *remove_backslashes __P((char *)); |
|
276 |
extern char *cond_expand_word __P((WORD_DESC *, int)); |
|
277 |
#endif
|
|
278 |
||
279 |
/* Flags for skip_to_delim */
|
|
280 |
#define SD_NOJMP 0x01 /* don't longjmp on fatal error. */ |
|
281 |
#define SD_INVERT 0x02 /* look for chars NOT in passed set */ |
|
282 |
#define SD_NOQUOTEDELIM 0x04 /* don't let single or double quotes act as delimiters */ |
|
283 |
#define SD_NOSKIPCMD 0x08 /* don't skip over $(, <(, or >( command/process substitution */ |
|
284 |
#define SD_EXTGLOB 0x10 /* skip over extended globbing patterns if appropriate */ |
|
285 |
#define SD_IGNOREQUOTE 0x20 /* single and double quotes are not special */ |
|
1.5.2
by Matthias Klose
Import upstream version 4.3~rc2 |
286 |
#define SD_GLOB 0x40 /* skip over glob patterns like bracket expressions */ |
1.5.1
by Matthias Klose
Import upstream version 4.3~rc1 |
287 |
|
288 |
extern int skip_to_delim __P((char *, int, char *, int)); |
|
289 |
||
290 |
#if defined (READLINE)
|
|
291 |
extern int char_is_quoted __P((char *, int)); |
|
292 |
extern int unclosed_pair __P((char *, int, char *)); |
|
293 |
extern WORD_LIST *split_at_delims __P((char *, int, char *, int, int, int *, int *)); |
|
294 |
#endif
|
|
295 |
||
296 |
/* Variables used to keep track of the characters in IFS. */
|
|
297 |
extern SHELL_VAR *ifs_var; |
|
298 |
extern char *ifs_value; |
|
299 |
extern unsigned char ifs_cmap[]; |
|
300 |
||
301 |
#if defined (HANDLE_MULTIBYTE)
|
|
302 |
extern unsigned char ifs_firstc[]; |
|
303 |
extern size_t ifs_firstc_len; |
|
304 |
#else
|
|
305 |
extern unsigned char ifs_firstc; |
|
306 |
#endif
|
|
307 |
||
308 |
/* Evaluates to 1 if C is a character in $IFS. */
|
|
309 |
#define isifs(c) (ifs_cmap[(unsigned char)(c)] != 0)
|
|
310 |
||
311 |
/* How to determine the quoted state of the character C. */
|
|
312 |
#define QUOTED_CHAR(c) ((c) == CTLESC)
|
|
313 |
||
314 |
/* Is the first character of STRING a quoted NULL character? */
|
|
315 |
#define QUOTED_NULL(string) ((string)[0] == CTLNUL && (string)[1] == '\0')
|
|
316 |
||
317 |
#endif /* !_SUBST_H_ */ |