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