1 | /* subst.h -- Names of externally visible functions in subst.c. */
|
---|
2 |
|
---|
3 | /* Copyright (C) 1993-2004 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 it under
|
---|
8 | the terms of the GNU General Public License as published by the Free
|
---|
9 | Software Foundation; either version 2, or (at your option) any later
|
---|
10 | version.
|
---|
11 |
|
---|
12 | Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
---|
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
---|
15 | for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License along
|
---|
18 | with Bash; see the file COPYING. If not, write to the Free Software
|
---|
19 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
---|
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. */
|
---|
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
|
---|
41 |
|
---|
42 | /* Flag values controlling how assignment statements are treated. */
|
---|
43 | #define ASS_APPEND 0x01
|
---|
44 | #define ASS_MKLOCAL 0x02
|
---|
45 |
|
---|
46 | /* Remove backslashes which are quoting backquotes from STRING. Modifies
|
---|
47 | STRING, and returns a pointer to it. */
|
---|
48 | extern char * de_backslash __P((char *));
|
---|
49 |
|
---|
50 | /* Replace instances of \! in a string with !. */
|
---|
51 | extern void unquote_bang __P((char *));
|
---|
52 |
|
---|
53 | /* Extract the $( construct in STRING, and return a new string.
|
---|
54 | Start extracting at (SINDEX) as if we had just seen "$(".
|
---|
55 | Make (SINDEX) get the position just after the matching ")". */
|
---|
56 | extern char *extract_command_subst __P((char *, int *));
|
---|
57 |
|
---|
58 | /* Extract the $[ construct in STRING, and return a new string.
|
---|
59 | Start extracting at (SINDEX) as if we had just seen "$[".
|
---|
60 | Make (SINDEX) get the position just after the matching "]". */
|
---|
61 | extern char *extract_arithmetic_subst __P((char *, int *));
|
---|
62 |
|
---|
63 | #if defined (PROCESS_SUBSTITUTION)
|
---|
64 | /* Extract the <( or >( 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 | extern char *extract_process_subst __P((char *, char *, int *));
|
---|
68 | #endif /* PROCESS_SUBSTITUTION */
|
---|
69 |
|
---|
70 | /* Extract the name of the variable to bind to from the assignment string. */
|
---|
71 | extern char *assignment_name __P((char *));
|
---|
72 |
|
---|
73 | /* Return a single string of all the words present in LIST, separating
|
---|
74 | each word with SEP. */
|
---|
75 | extern char *string_list_internal __P((WORD_LIST *, char *));
|
---|
76 |
|
---|
77 | /* Return a single string of all the words present in LIST, separating
|
---|
78 | each word with a space. */
|
---|
79 | extern char *string_list __P((WORD_LIST *));
|
---|
80 |
|
---|
81 | /* Turn $* into a single string, obeying POSIX rules. */
|
---|
82 | extern char *string_list_dollar_star __P((WORD_LIST *));
|
---|
83 |
|
---|
84 | /* Expand $@ into a single string, obeying POSIX rules. */
|
---|
85 | extern char *string_list_dollar_at __P((WORD_LIST *, int));
|
---|
86 |
|
---|
87 | /* Perform quoted null character removal on each element of LIST.
|
---|
88 | This modifies LIST. */
|
---|
89 | extern void word_list_remove_quoted_nulls __P((WORD_LIST *));
|
---|
90 |
|
---|
91 | /* This performs word splitting and quoted null character removal on
|
---|
92 | STRING. */
|
---|
93 | extern WORD_LIST *list_string __P((char *, char *, int));
|
---|
94 |
|
---|
95 | extern char *get_word_from_string __P((char **, char *, char **));
|
---|
96 | extern char *strip_trailing_ifs_whitespace __P((char *, char *, int));
|
---|
97 |
|
---|
98 | /* Given STRING, an assignment string, get the value of the right side
|
---|
99 | of the `=', and bind it to the left side. If EXPAND is true, then
|
---|
100 | perform tilde expansion, parameter expansion, command substitution,
|
---|
101 | and arithmetic expansion on the right-hand side. Do not perform word
|
---|
102 | splitting on the result of expansion. */
|
---|
103 | extern int do_assignment __P((char *));
|
---|
104 | extern int do_assignment_no_expand __P((char *));
|
---|
105 | extern int do_word_assignment __P((WORD_DESC *));
|
---|
106 |
|
---|
107 | /* Append SOURCE to TARGET at INDEX. SIZE is the current amount
|
---|
108 | of space allocated to TARGET. SOURCE can be NULL, in which
|
---|
109 | case nothing happens. Gets rid of SOURCE by free ()ing it.
|
---|
110 | Returns TARGET in case the location has changed. */
|
---|
111 | extern char *sub_append_string __P((char *, char *, int *, int *));
|
---|
112 |
|
---|
113 | /* Append the textual representation of NUMBER to TARGET.
|
---|
114 | INDEX and SIZE are as in SUB_APPEND_STRING. */
|
---|
115 | extern char *sub_append_number __P((intmax_t, char *, int *, int *));
|
---|
116 |
|
---|
117 | /* Return the word list that corresponds to `$*'. */
|
---|
118 | extern WORD_LIST *list_rest_of_args __P((void));
|
---|
119 |
|
---|
120 | /* Make a single large string out of the dollar digit variables,
|
---|
121 | and the rest_of_args. If DOLLAR_STAR is 1, then obey the special
|
---|
122 | case of "$*" with respect to IFS. */
|
---|
123 | extern char *string_rest_of_args __P((int));
|
---|
124 |
|
---|
125 | extern int number_of_args __P((void));
|
---|
126 |
|
---|
127 | /* Expand STRING by performing parameter expansion, command substitution,
|
---|
128 | and arithmetic expansion. Dequote the resulting WORD_LIST before
|
---|
129 | returning it, but do not perform word splitting. The call to
|
---|
130 | remove_quoted_nulls () is made here because word splitting normally
|
---|
131 | takes care of quote removal. */
|
---|
132 | extern WORD_LIST *expand_string_unsplit __P((char *, int));
|
---|
133 |
|
---|
134 | /* Expand the rhs of an assignment statement. */
|
---|
135 | extern WORD_LIST *expand_string_assignment __P((char *, int));
|
---|
136 |
|
---|
137 | /* Expand a prompt string. */
|
---|
138 | extern WORD_LIST *expand_prompt_string __P((char *, int));
|
---|
139 |
|
---|
140 | /* Expand STRING just as if you were expanding a word. This also returns
|
---|
141 | a list of words. Note that filename globbing is *NOT* done for word
|
---|
142 | or string expansion, just when the shell is expanding a command. This
|
---|
143 | does parameter expansion, command substitution, arithmetic expansion,
|
---|
144 | and word splitting. Dequote the resultant WORD_LIST before returning. */
|
---|
145 | extern WORD_LIST *expand_string __P((char *, int));
|
---|
146 |
|
---|
147 | /* Convenience functions that expand strings to strings, taking care of
|
---|
148 | converting the WORD_LIST * returned by the expand_string* functions
|
---|
149 | to a string and deallocating the WORD_LIST *. */
|
---|
150 | extern char *expand_string_to_string __P((char *, int));
|
---|
151 | extern char *expand_string_unsplit_to_string __P((char *, int));
|
---|
152 | extern char *expand_assignment_string_to_string __P((char *, int));
|
---|
153 |
|
---|
154 | /* Expand an arithmetic expression string */
|
---|
155 | extern char *expand_arith_string __P((char *, int));
|
---|
156 |
|
---|
157 | /* De-quoted quoted characters in STRING. */
|
---|
158 | extern char *dequote_string __P((char *));
|
---|
159 |
|
---|
160 | /* Expand WORD, performing word splitting on the result. This does
|
---|
161 | parameter expansion, command substitution, arithmetic expansion,
|
---|
162 | word splitting, and quote removal. */
|
---|
163 | extern WORD_LIST *expand_word __P((WORD_DESC *, int));
|
---|
164 |
|
---|
165 | /* Expand WORD, but do not perform word splitting on the result. This
|
---|
166 | does parameter expansion, command substitution, arithmetic expansion,
|
---|
167 | and quote removal. */
|
---|
168 | extern WORD_LIST *expand_word_unsplit __P((WORD_DESC *, int));
|
---|
169 | extern WORD_LIST *expand_word_leave_quoted __P((WORD_DESC *, int));
|
---|
170 |
|
---|
171 | /* Return the value of a positional parameter. This handles values > 10. */
|
---|
172 | extern char *get_dollar_var_value __P((intmax_t));
|
---|
173 |
|
---|
174 | /* Quote a string to protect it from word splitting. */
|
---|
175 | extern char *quote_string __P((char *));
|
---|
176 |
|
---|
177 | /* Quote escape characters (characters special to interals of expansion)
|
---|
178 | in a string. */
|
---|
179 | extern char *quote_escapes __P((char *));
|
---|
180 |
|
---|
181 | /* Perform quote removal on STRING. If QUOTED > 0, assume we are obeying the
|
---|
182 | backslash quoting rules for within double quotes. */
|
---|
183 | extern char *string_quote_removal __P((char *, int));
|
---|
184 |
|
---|
185 | /* Perform quote removal on word WORD. This allocates and returns a new
|
---|
186 | WORD_DESC *. */
|
---|
187 | extern WORD_DESC *word_quote_removal __P((WORD_DESC *, int));
|
---|
188 |
|
---|
189 | /* Perform quote removal on all words in LIST. If QUOTED is non-zero,
|
---|
190 | the members of the list are treated as if they are surrounded by
|
---|
191 | double quotes. Return a new list, or NULL if LIST is NULL. */
|
---|
192 | extern WORD_LIST *word_list_quote_removal __P((WORD_LIST *, int));
|
---|
193 |
|
---|
194 | /* Called when IFS is changed to maintain some private variables. */
|
---|
195 | extern void setifs __P((SHELL_VAR *));
|
---|
196 |
|
---|
197 | /* Return the value of $IFS, or " \t\n" if IFS is unset. */
|
---|
198 | extern char *getifs __P((void));
|
---|
199 |
|
---|
200 | /* This splits a single word into a WORD LIST on $IFS, but only if the word
|
---|
201 | is not quoted. list_string () performs quote removal for us, even if we
|
---|
202 | don't do any splitting. */
|
---|
203 | extern WORD_LIST *word_split __P((WORD_DESC *, char *));
|
---|
204 |
|
---|
205 | /* Take the list of words in LIST and do the various substitutions. Return
|
---|
206 | a new list of words which is the expanded list, and without things like
|
---|
207 | variable assignments. */
|
---|
208 | extern WORD_LIST *expand_words __P((WORD_LIST *));
|
---|
209 |
|
---|
210 | /* Same as expand_words (), but doesn't hack variable or environment
|
---|
211 | variables. */
|
---|
212 | extern WORD_LIST *expand_words_no_vars __P((WORD_LIST *));
|
---|
213 |
|
---|
214 | /* Perform the `normal shell expansions' on a WORD_LIST. These are
|
---|
215 | brace expansion, tilde expansion, parameter and variable substitution,
|
---|
216 | command substitution, arithmetic expansion, and word splitting. */
|
---|
217 | extern WORD_LIST *expand_words_shellexp __P((WORD_LIST *));
|
---|
218 |
|
---|
219 | extern char *command_substitute __P((char *, int));
|
---|
220 | extern char *pat_subst __P((char *, char *, char *, int));
|
---|
221 |
|
---|
222 | extern void unlink_fifo_list __P((void));
|
---|
223 |
|
---|
224 | extern WORD_LIST *list_string_with_quotes __P((char *));
|
---|
225 |
|
---|
226 | #if defined (ARRAY_VARS)
|
---|
227 | extern char *extract_array_assignment_list __P((char *, int *));
|
---|
228 | #endif
|
---|
229 |
|
---|
230 | #if defined (COND_COMMAND)
|
---|
231 | extern char *remove_backslashes __P((char *));
|
---|
232 | extern char *cond_expand_word __P((WORD_DESC *, int));
|
---|
233 | #endif
|
---|
234 |
|
---|
235 | #if defined (READLINE)
|
---|
236 | extern int char_is_quoted __P((char *, int));
|
---|
237 | extern int unclosed_pair __P((char *, int, char *));
|
---|
238 | extern int skip_to_delim __P((char *, int, char *));
|
---|
239 | extern WORD_LIST *split_at_delims __P((char *, int, char *, int, int *, int *));
|
---|
240 | #endif
|
---|
241 |
|
---|
242 | /* Variables used to keep track of the characters in IFS. */
|
---|
243 | extern SHELL_VAR *ifs_var;
|
---|
244 | extern char *ifs_value;
|
---|
245 | extern unsigned char ifs_cmap[];
|
---|
246 |
|
---|
247 | #if defined (HANDLE_MULTIBYTE)
|
---|
248 | extern unsigned char ifs_firstc[];
|
---|
249 | extern size_t ifs_firstc_len;
|
---|
250 | #else
|
---|
251 | extern unsigned char ifs_firstc;
|
---|
252 | #endif
|
---|
253 |
|
---|
254 | /* Evaluates to 1 if C is a character in $IFS. */
|
---|
255 | #define isifs(c) (ifs_cmap[(unsigned char)(c)] != 0)
|
---|
256 |
|
---|
257 | /* How to determine the quoted state of the character C. */
|
---|
258 | #define QUOTED_CHAR(c) ((c) == CTLESC)
|
---|
259 |
|
---|
260 | /* Is the first character of STRING a quoted NULL character? */
|
---|
261 | #define QUOTED_NULL(string) ((string)[0] == CTLNUL && (string)[1] == '\0')
|
---|
262 |
|
---|
263 | #endif /* !_SUBST_H_ */
|
---|