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