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