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