]> git.ipfire.org Git - thirdparty/bash.git/blame - subst.h
Bash-5.2 patch 26: fix typo when specifying readline's custom color prefix
[thirdparty/bash.git] / subst.h
CommitLineData
726f6388
JA
1/* subst.h -- Names of externally visible functions in subst.c. */
2
74091dd4 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
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 */
8868edaf 57#define ASS_NOINVIS 0x0400 /* don't resolve local invisible variables */
74091dd4
CR
58#define ASS_ALLOWALLSUB 0x0800 /* allow * and @ as associative array keys */
59#define ASS_ONEWORD 0x1000 /* don't check array subscripts, assume higher level has done that */
3185942a
JA
60
61/* Flags for the string extraction functions. */
495aee44
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 */
49ed961b 71#define SX_WORD 0x0200 /* extracting word in ${param op word} */
a0c0a00f
CR
72#define SX_COMPLETE 0x0400 /* extracting word for completion */
73#define SX_STRIPDQ 0x0800 /* strip double quotes when extracting double-quoted string */
74091dd4 74#define SX_NOERROR 0x1000 /* don't print parser error messages */
95732b49 75
726f6388
JA
76/* Remove backslashes which are quoting backquotes from STRING. Modifies
77 STRING, and returns a pointer to it. */
8868edaf 78extern char * de_backslash PARAMS((char *));
726f6388
JA
79
80/* Replace instances of \! in a string with !. */
8868edaf 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 "$(".
3185942a
JA
85 Make (SINDEX) get the position just after the matching ")".
86 XFLAGS is additional flags to pass to other extraction functions, */
8868edaf 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 "]". */
8868edaf 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 ")". */
8868edaf 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. */
8868edaf 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. */
8868edaf 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. */
8868edaf 110extern char *string_list PARAMS((WORD_LIST *));
726f6388 111
f73dda09 112/* Turn $* into a single string, obeying POSIX rules. */
8868edaf 113extern char *string_list_dollar_star PARAMS((WORD_LIST *, int, int));
f73dda09
JA
114
115/* Expand $@ into a single string, obeying POSIX rules. */
8868edaf 116extern char *string_list_dollar_at PARAMS((WORD_LIST *, int, int));
f73dda09 117
8868edaf 118/* Turn the positional parameters into a string, understanding quoting and
3185942a
JA
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. */
8868edaf 122extern char *string_list_pos_params PARAMS((int, WORD_LIST *, int, int));
3185942a 123
726f6388
JA
124/* Perform quoted null character removal on each element of LIST.
125 This modifies LIST. */
8868edaf 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. */
8868edaf 130extern WORD_LIST *list_string PARAMS((char *, char *, int));
726f6388 131
8868edaf
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
95732b49
JA
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. */
8868edaf
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. */
74091dd4 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. */
8868edaf 153extern char *sub_append_number PARAMS((intmax_t, char *, int *, int *));
726f6388
JA
154
155/* Return the word list that corresponds to `$*'. */
8868edaf 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. */
8868edaf 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. */
8868edaf 168extern WORD_LIST *expand_string_unsplit PARAMS((char *, int));
726f6388 169
95732b49 170/* Expand the rhs of an assignment statement. */
8868edaf 171extern WORD_LIST *expand_string_assignment PARAMS((char *, int));
95732b49 172
bb70624e 173/* Expand a prompt string. */
8868edaf 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. */
8868edaf 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 *. */
8868edaf
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));
74091dd4 189extern char *expand_subscript_string PARAMS((char *, int));
f73dda09 190
0628567a 191/* Expand an arithmetic expression string */
8868edaf 192extern char *expand_arith_string PARAMS((char *, int));
0628567a 193
74091dd4
CR
194/* Expand $'...' and $"..." in a string for code paths that do not. */
195extern char *expand_string_dollar_quote PARAMS((char *, int));
196
0628567a 197/* De-quote quoted characters in STRING. */
8868edaf 198extern char *dequote_string PARAMS((char *));
726f6388 199
3185942a 200/* De-quote CTLESC-escaped CTLESC or CTLNUL characters in STRING. */
8868edaf 201extern char *dequote_escapes PARAMS((const char *));
d233b485 202
8868edaf 203extern WORD_DESC *dequote_word PARAMS((WORD_DESC *));
3185942a 204
0628567a 205/* De-quote quoted characters in each word in LIST. */
8868edaf 206extern WORD_LIST *dequote_list PARAMS((WORD_LIST *));
0628567a 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. */
8868edaf 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. */
8868edaf
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. */
8868edaf 220extern char *get_dollar_var_value PARAMS((intmax_t));
726f6388 221
ccc6cda3 222/* Quote a string to protect it from word splitting. */
8868edaf 223extern char *quote_string PARAMS((char *));
ccc6cda3 224
8868edaf 225/* Quote escape characters (characters special to internals of expansion)
f73dda09 226 in a string. */
8868edaf 227extern char *quote_escapes PARAMS((const char *));
f73dda09 228
3185942a 229/* And remove such quoted special characters. */
8868edaf 230extern char *remove_quoted_escapes PARAMS((char *));
3185942a
JA
231
232/* Remove CTLNUL characters from STRING unless they are quoted with CTLESC. */
8868edaf 233extern char *remove_quoted_nulls PARAMS((char *));
3185942a 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. */
8868edaf 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 *. */
8868edaf 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. */
8868edaf 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. */
8868edaf 249extern void setifs PARAMS((SHELL_VAR *));
7117c2d2
JA
250
251/* Return the value of $IFS, or " \t\n" if IFS is unset. */
8868edaf 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. */
8868edaf 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. */
8868edaf 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. */
8868edaf 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. */
8868edaf 271extern WORD_LIST *expand_words_shellexp PARAMS((WORD_LIST *));
726f6388 272
8868edaf
CR
273extern WORD_DESC *command_substitute PARAMS((char *, int, int));
274extern char *pat_subst PARAMS((char *, char *, char *, int));
ccc6cda3 275
d233b485 276#if defined (PROCESS_SUBSTITUTION)
8868edaf
CR
277extern int fifos_pending PARAMS((void));
278extern int num_fifos PARAMS((void));
279extern void unlink_fifo_list PARAMS((void));
280extern void unlink_all_fifos PARAMS((void));
281extern void unlink_fifo PARAMS((int));
495aee44 282
8868edaf
CR
283extern void *copy_fifo_list PARAMS((int *));
284extern void close_new_fifos PARAMS((void *, int));
ccc6cda3 285
8868edaf 286extern void clear_fifo_list PARAMS((void));
a0c0a00f 287
8868edaf
CR
288extern int find_procsub_child PARAMS((pid_t));
289extern void set_procsub_status PARAMS((int, pid_t, int));
d233b485 290
8868edaf
CR
291extern void wait_procsubs PARAMS((void));
292extern void reap_procsubs PARAMS((void));
d233b485
CR
293#endif
294
8868edaf 295extern WORD_LIST *list_string_with_quotes PARAMS((char *));
bb70624e 296
ccc6cda3 297#if defined (ARRAY_VARS)
8868edaf 298extern char *extract_array_assignment_list PARAMS((char *, int *));
ccc6cda3
JA
299#endif
300
cce855bc 301#if defined (COND_COMMAND)
8868edaf
CR
302extern char *remove_backslashes PARAMS((char *));
303extern char *cond_expand_word PARAMS((WORD_DESC *, int));
ccc6cda3
JA
304#endif
305
3185942a 306/* Flags for skip_to_delim */
a0c0a00f
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 */
316#define SD_HISTEXP 0x200 /* skip_to_delim during history expansion */
317#define SD_ARITHEXP 0x400 /* skip_to_delim during arithmetic expansion */
74091dd4 318#define SD_NOERROR 0x800 /* don't print error messages */
3185942a 319
8868edaf 320extern int skip_to_delim PARAMS((char *, int, char *, int));
3185942a 321
a0c0a00f 322#if defined (BANG_HISTORY)
8868edaf 323extern int skip_to_histexp PARAMS((char *, int, char *, int));
a0c0a00f
CR
324#endif
325
bb70624e 326#if defined (READLINE)
8868edaf
CR
327extern int char_is_quoted PARAMS((char *, int));
328extern int unclosed_pair PARAMS((char *, int, char *));
74091dd4 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[];
d233b485 336extern int ifs_is_set, ifs_is_null;
95732b49
JA
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;
95732b49 343#endif
7117c2d2 344
d233b485
CR
345extern int assigning_in_environment;
346extern int expanding_redir;
347extern int inherit_errexit;
348
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
8868edaf 360extern void invalidate_cached_quoted_dollar_at PARAMS((void));
a0c0a00f 361
726f6388 362#endif /* !_SUBST_H_ */