]> git.ipfire.org Git - thirdparty/bash.git/blob - subst.h
Bash-5.2 patch 26: fix typo when specifying readline's custom color prefix
[thirdparty/bash.git] / subst.h
1 /* subst.h -- Names of externally visible functions in subst.c. */
2
3 /* Copyright (C) 1993-2021 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 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 */
45
46 /* Flag values controlling how assignment statements are treated. */
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 */
52 #define ASS_FORCE 0x0020 /* force assignment even to readonly variable */
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 */
57 #define ASS_NOINVIS 0x0400 /* don't resolve local invisible variables */
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 */
60
61 /* Flags for the string extraction functions. */
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 */
71 #define SX_WORD 0x0200 /* extracting word in ${param op word} */
72 #define SX_COMPLETE 0x0400 /* extracting word for completion */
73 #define SX_STRIPDQ 0x0800 /* strip double quotes when extracting double-quoted string */
74 #define SX_NOERROR 0x1000 /* don't print parser error messages */
75
76 /* Remove backslashes which are quoting backquotes from STRING. Modifies
77 STRING, and returns a pointer to it. */
78 extern char * de_backslash PARAMS((char *));
79
80 /* Replace instances of \! in a string with !. */
81 extern void unquote_bang PARAMS((char *));
82
83 /* Extract the $( construct in STRING, and return a new string.
84 Start extracting at (SINDEX) as if we had just seen "$(".
85 Make (SINDEX) get the position just after the matching ")".
86 XFLAGS is additional flags to pass to other extraction functions, */
87 extern char *extract_command_subst PARAMS((char *, int *, int));
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 "]". */
92 extern char *extract_arithmetic_subst PARAMS((char *, int *));
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 ")". */
98 extern char *extract_process_subst PARAMS((char *, char *, int *, int));
99 #endif /* PROCESS_SUBSTITUTION */
100
101 /* Extract the name of the variable to bind to from the assignment string. */
102 extern char *assignment_name PARAMS((char *));
103
104 /* Return a single string of all the words present in LIST, separating
105 each word with SEP. */
106 extern char *string_list_internal PARAMS((WORD_LIST *, char *));
107
108 /* Return a single string of all the words present in LIST, separating
109 each word with a space. */
110 extern char *string_list PARAMS((WORD_LIST *));
111
112 /* Turn $* into a single string, obeying POSIX rules. */
113 extern char *string_list_dollar_star PARAMS((WORD_LIST *, int, int));
114
115 /* Expand $@ into a single string, obeying POSIX rules. */
116 extern char *string_list_dollar_at PARAMS((WORD_LIST *, int, int));
117
118 /* Turn the positional parameters into a string, understanding quoting and
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. */
122 extern char *string_list_pos_params PARAMS((int, WORD_LIST *, int, int));
123
124 /* Perform quoted null character removal on each element of LIST.
125 This modifies LIST. */
126 extern void word_list_remove_quoted_nulls PARAMS((WORD_LIST *));
127
128 /* This performs word splitting and quoted null character removal on
129 STRING. */
130 extern WORD_LIST *list_string PARAMS((char *, char *, int));
131
132 extern char *ifs_firstchar PARAMS((int *));
133 extern char *get_word_from_string PARAMS((char **, char *, char **));
134 extern char *strip_trailing_ifs_whitespace PARAMS((char *, char *, int));
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
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. */
141 extern int do_assignment PARAMS((char *));
142 extern int do_assignment_no_expand PARAMS((char *));
143 extern int do_word_assignment PARAMS((WORD_DESC *, int));
144
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. */
149 extern char *sub_append_string PARAMS((char *, char *, size_t *, size_t *));
150
151 /* Append the textual representation of NUMBER to TARGET.
152 INDEX and SIZE are as in SUB_APPEND_STRING. */
153 extern char *sub_append_number PARAMS((intmax_t, char *, int *, int *));
154
155 /* Return the word list that corresponds to `$*'. */
156 extern WORD_LIST *list_rest_of_args PARAMS((void));
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. */
161 extern char *string_rest_of_args PARAMS((int));
162
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
166 remove_quoted_nulls () is made here because word splitting normally
167 takes care of quote removal. */
168 extern WORD_LIST *expand_string_unsplit PARAMS((char *, int));
169
170 /* Expand the rhs of an assignment statement. */
171 extern WORD_LIST *expand_string_assignment PARAMS((char *, int));
172
173 /* Expand a prompt string. */
174 extern WORD_LIST *expand_prompt_string PARAMS((char *, int, int));
175
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. */
181 extern WORD_LIST *expand_string PARAMS((char *, int));
182
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 *. */
186 extern char *expand_string_to_string PARAMS((char *, int));
187 extern char *expand_string_unsplit_to_string PARAMS((char *, int));
188 extern char *expand_assignment_string_to_string PARAMS((char *, int));
189 extern char *expand_subscript_string PARAMS((char *, int));
190
191 /* Expand an arithmetic expression string */
192 extern char *expand_arith_string PARAMS((char *, int));
193
194 /* Expand $'...' and $"..." in a string for code paths that do not. */
195 extern char *expand_string_dollar_quote PARAMS((char *, int));
196
197 /* De-quote quoted characters in STRING. */
198 extern char *dequote_string PARAMS((char *));
199
200 /* De-quote CTLESC-escaped CTLESC or CTLNUL characters in STRING. */
201 extern char *dequote_escapes PARAMS((const char *));
202
203 extern WORD_DESC *dequote_word PARAMS((WORD_DESC *));
204
205 /* De-quote quoted characters in each word in LIST. */
206 extern WORD_LIST *dequote_list PARAMS((WORD_LIST *));
207
208 /* Expand WORD, performing word splitting on the result. This does
209 parameter expansion, command substitution, arithmetic expansion,
210 word splitting, and quote removal. */
211 extern WORD_LIST *expand_word PARAMS((WORD_DESC *, int));
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. */
216 extern WORD_LIST *expand_word_unsplit PARAMS((WORD_DESC *, int));
217 extern WORD_LIST *expand_word_leave_quoted PARAMS((WORD_DESC *, int));
218
219 /* Return the value of a positional parameter. This handles values > 10. */
220 extern char *get_dollar_var_value PARAMS((intmax_t));
221
222 /* Quote a string to protect it from word splitting. */
223 extern char *quote_string PARAMS((char *));
224
225 /* Quote escape characters (characters special to internals of expansion)
226 in a string. */
227 extern char *quote_escapes PARAMS((const char *));
228
229 /* And remove such quoted special characters. */
230 extern char *remove_quoted_escapes PARAMS((char *));
231
232 /* Remove CTLNUL characters from STRING unless they are quoted with CTLESC. */
233 extern char *remove_quoted_nulls PARAMS((char *));
234
235 /* Perform quote removal on STRING. If QUOTED > 0, assume we are obeying the
236 backslash quoting rules for within double quotes. */
237 extern char *string_quote_removal PARAMS((char *, int));
238
239 /* Perform quote removal on word WORD. This allocates and returns a new
240 WORD_DESC *. */
241 extern WORD_DESC *word_quote_removal PARAMS((WORD_DESC *, int));
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. */
246 extern WORD_LIST *word_list_quote_removal PARAMS((WORD_LIST *, int));
247
248 /* Called when IFS is changed to maintain some private variables. */
249 extern void setifs PARAMS((SHELL_VAR *));
250
251 /* Return the value of $IFS, or " \t\n" if IFS is unset. */
252 extern char *getifs PARAMS((void));
253
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. */
257 extern WORD_LIST *word_split PARAMS((WORD_DESC *, char *));
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. */
262 extern WORD_LIST *expand_words PARAMS((WORD_LIST *));
263
264 /* Same as expand_words (), but doesn't hack variable or environment
265 variables. */
266 extern WORD_LIST *expand_words_no_vars PARAMS((WORD_LIST *));
267
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. */
271 extern WORD_LIST *expand_words_shellexp PARAMS((WORD_LIST *));
272
273 extern WORD_DESC *command_substitute PARAMS((char *, int, int));
274 extern char *pat_subst PARAMS((char *, char *, char *, int));
275
276 #if defined (PROCESS_SUBSTITUTION)
277 extern int fifos_pending PARAMS((void));
278 extern int num_fifos PARAMS((void));
279 extern void unlink_fifo_list PARAMS((void));
280 extern void unlink_all_fifos PARAMS((void));
281 extern void unlink_fifo PARAMS((int));
282
283 extern void *copy_fifo_list PARAMS((int *));
284 extern void close_new_fifos PARAMS((void *, int));
285
286 extern void clear_fifo_list PARAMS((void));
287
288 extern int find_procsub_child PARAMS((pid_t));
289 extern void set_procsub_status PARAMS((int, pid_t, int));
290
291 extern void wait_procsubs PARAMS((void));
292 extern void reap_procsubs PARAMS((void));
293 #endif
294
295 extern WORD_LIST *list_string_with_quotes PARAMS((char *));
296
297 #if defined (ARRAY_VARS)
298 extern char *extract_array_assignment_list PARAMS((char *, int *));
299 #endif
300
301 #if defined (COND_COMMAND)
302 extern char *remove_backslashes PARAMS((char *));
303 extern char *cond_expand_word PARAMS((WORD_DESC *, int));
304 #endif
305
306 /* Flags for skip_to_delim */
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 */
318 #define SD_NOERROR 0x800 /* don't print error messages */
319
320 extern int skip_to_delim PARAMS((char *, int, char *, int));
321
322 #if defined (BANG_HISTORY)
323 extern int skip_to_histexp PARAMS((char *, int, char *, int));
324 #endif
325
326 #if defined (READLINE)
327 extern int char_is_quoted PARAMS((char *, int));
328 extern int unclosed_pair PARAMS((char *, int, char *));
329 extern WORD_LIST *split_at_delims PARAMS((char *, int, const char *, int, int, int *, int *));
330 #endif
331
332 /* Variables used to keep track of the characters in IFS. */
333 extern SHELL_VAR *ifs_var;
334 extern char *ifs_value;
335 extern unsigned char ifs_cmap[];
336 extern int ifs_is_set, ifs_is_null;
337
338 #if defined (HANDLE_MULTIBYTE)
339 extern unsigned char ifs_firstc[];
340 extern size_t ifs_firstc_len;
341 #else
342 extern unsigned char ifs_firstc;
343 #endif
344
345 extern int assigning_in_environment;
346 extern int expanding_redir;
347 extern int inherit_errexit;
348
349 extern pid_t last_command_subst_pid;
350
351 /* Evaluates to 1 if C is a character in $IFS. */
352 #define isifs(c) (ifs_cmap[(unsigned char)(c)] != 0)
353
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
360 extern void invalidate_cached_quoted_dollar_at PARAMS((void));
361
362 #endif /* !_SUBST_H_ */