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