1 /* subst.h -- Names of externally visible functions in subst.c. */
3 /* Copyright (C) 1993 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 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
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
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. */
21 #if !defined (_SUBST_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. */
32 #define Q_DOUBLE_QUOTES 0x1
33 #define Q_HERE_DOCUMENT 0x2
34 #define Q_KEEP_BACKSLASH 0x4
37 #define Q_ADDEDQUOTES 0x20
38 #define Q_QUOTEDNULL 0x40
40 /* Cons a new string from STRING starting at START and ending at END,
42 extern char *substring __P((char *, int, int));
44 /* Remove backslashes which are quoting backquotes from STRING. Modifies
45 STRING, and returns a pointer to it. */
46 extern char * de_backslash __P((char *));
48 /* Replace instances of \! in a string with !. */
49 extern void unquote_bang __P((char *));
51 /* Extract the $( construct in STRING, and return a new string.
52 Start extracting at (SINDEX) as if we had just seen "$(".
53 Make (SINDEX) get the position just after the matching ")". */
54 extern char *extract_command_subst __P((char *, int *));
56 /* Extract the $[ construct in STRING, and return a new string.
57 Start extracting at (SINDEX) as if we had just seen "$[".
58 Make (SINDEX) get the position just after the matching "]". */
59 extern char *extract_arithmetic_subst __P((char *, int *));
61 #if defined (PROCESS_SUBSTITUTION)
62 /* Extract the <( or >( construct in STRING, and return a new string.
63 Start extracting at (SINDEX) as if we had just seen "<(".
64 Make (SINDEX) get the position just after the matching ")". */
65 extern char *extract_process_subst __P((char *, char *, int *));
66 #endif /* PROCESS_SUBSTITUTION */
68 /* Extract the name of the variable to bind to from the assignment string. */
69 extern char *assignment_name __P((char *));
71 /* Return a single string of all the words present in LIST, separating
72 each word with a space. */
73 extern char *string_list __P((WORD_LIST *));
75 /* Turn $* into a single string, obeying POSIX rules. */
76 extern char *string_list_dollar_star __P((WORD_LIST *));
78 /* Expand $@ into a single string, obeying POSIX rules. */
79 extern char *string_list_dollar_at __P((WORD_LIST *, int));
81 /* Perform quoted null character removal on each element of LIST.
82 This modifies LIST. */
83 extern void word_list_remove_quoted_nulls __P((WORD_LIST *));
85 /* This performs word splitting and quoted null character removal on
87 extern WORD_LIST *list_string __P((char *, char *, int));
89 extern char *get_word_from_string __P((char **, char *, char **));
90 extern char *strip_trailing_ifs_whitespace __P((char *, char *, int));
92 /* Given STRING, an assignment string, get the value of the right side
93 of the `=', and bind it to the left side. If EXPAND is true, then
94 perform parameter expansion, command substitution, and arithmetic
95 expansion on the right-hand side. Perform tilde expansion in any
96 case. Do not perform word splitting on the result of expansion. */
97 extern int do_assignment __P((const char *));
98 extern int do_assignment_no_expand __P((const char *));
100 /* Append SOURCE to TARGET at INDEX. SIZE is the current amount
101 of space allocated to TARGET. SOURCE can be NULL, in which
102 case nothing happens. Gets rid of SOURCE by free ()ing it.
103 Returns TARGET in case the location has changed. */
104 extern char *sub_append_string __P((char *, char *, int *, int *));
106 /* Append the textual representation of NUMBER to TARGET.
107 INDEX and SIZE are as in SUB_APPEND_STRING. */
108 extern char *sub_append_number __P((long, char *, int *, int *));
110 /* Return the word list that corresponds to `$*'. */
111 extern WORD_LIST *list_rest_of_args __P((void));
113 /* Make a single large string out of the dollar digit variables,
114 and the rest_of_args. If DOLLAR_STAR is 1, then obey the special
115 case of "$*" with respect to IFS. */
116 extern char *string_rest_of_args __P((int));
118 extern int number_of_args __P((void));
120 /* Expand STRING by performing parameter expansion, command substitution,
121 and arithmetic expansion. Dequote the resulting WORD_LIST before
122 returning it, but do not perform word splitting. The call to
123 remove_quoted_nulls () is made here because word splitting normally
124 takes care of quote removal. */
125 extern WORD_LIST *expand_string_unsplit __P((char *, int));
127 /* Expand a prompt string. */
128 extern WORD_LIST *expand_prompt_string __P((char *, int));
130 /* Expand STRING just as if you were expanding a word. This also returns
131 a list of words. Note that filename globbing is *NOT* done for word
132 or string expansion, just when the shell is expanding a command. This
133 does parameter expansion, command substitution, arithmetic expansion,
134 and word splitting. Dequote the resultant WORD_LIST before returning. */
135 extern WORD_LIST *expand_string __P((char *, int));
137 /* Convenience functions that expand strings to strings, taking care of
138 converting the WORD_LIST * returned by the expand_string* functions
139 to a string and deallocating the WORD_LIST *. */
140 extern char *expand_string_to_string __P((char *, int));
141 extern char *expand_string_unsplit_to_string __P((char *, int));
143 /* De-quoted quoted characters in STRING. */
144 extern char *dequote_string __P((char *));
146 /* Expand WORD, performing word splitting on the result. This does
147 parameter expansion, command substitution, arithmetic expansion,
148 word splitting, and quote removal. */
149 extern WORD_LIST *expand_word __P((WORD_DESC *, int));
151 /* Expand WORD, but do not perform word splitting on the result. This
152 does parameter expansion, command substitution, arithmetic expansion,
153 and quote removal. */
154 extern WORD_LIST *expand_word_unsplit __P((WORD_DESC *, int));
155 extern WORD_LIST *expand_word_leave_quoted __P((WORD_DESC *, int));
157 /* Return the value of a positional parameter. This handles values > 10. */
158 extern char *get_dollar_var_value __P((long));
160 /* Quote a string to protect it from word splitting. */
161 extern char *quote_string __P((char *));
163 /* Quote escape characters (characters special to interals of expansion)
165 extern char *quote_escapes __P((char *));
167 /* Perform quote removal on STRING. If QUOTED > 0, assume we are obeying the
168 backslash quoting rules for within double quotes. */
169 extern char *string_quote_removal __P((char *, int));
171 /* Perform quote removal on word WORD. This allocates and returns a new
173 extern WORD_DESC *word_quote_removal __P((WORD_DESC *, int));
175 /* Perform quote removal on all words in LIST. If QUOTED is non-zero,
176 the members of the list are treated as if they are surrounded by
177 double quotes. Return a new list, or NULL if LIST is NULL. */
178 extern WORD_LIST *word_list_quote_removal __P((WORD_LIST *, int));
180 /* This splits a single word into a WORD LIST on $IFS, but only if the word
181 is not quoted. list_string () performs quote removal for us, even if we
182 don't do any splitting. */
183 extern WORD_LIST *word_split __P((WORD_DESC *));
185 /* Take the list of words in LIST and do the various substitutions. Return
186 a new list of words which is the expanded list, and without things like
187 variable assignments. */
188 extern WORD_LIST *expand_words __P((WORD_LIST *));
190 /* Same as expand_words (), but doesn't hack variable or environment
192 extern WORD_LIST *expand_words_no_vars __P((WORD_LIST *));
194 /* Perform the `normal shell expansions' on a WORD_LIST. These are
195 brace expansion, tilde expansion, parameter and variable substitution,
196 command substitution, arithmetic expansion, and word splitting. */
197 extern WORD_LIST *expand_words_shellexp __P((WORD_LIST *));
199 extern char *command_substitute __P((char *, int));
200 extern char *pat_subst __P((char *, char *, char *, int));
202 extern void unlink_fifo_list __P((void));
204 extern WORD_LIST *list_string_with_quotes __P((char *));
206 #if defined (ARRAY_VARS)
207 extern char *extract_array_assignment_list __P((char *, int *));
210 #if defined (COND_COMMAND)
211 extern char *remove_backslashes __P((char *));
212 extern char *cond_expand_word __P((WORD_DESC *, int));
215 #if defined (READLINE)
216 extern int char_is_quoted __P((char *, int));
217 extern int unclosed_pair __P((char *, int, char *));
218 extern int skip_to_delim __P((char *, int, char *));
219 extern WORD_LIST *split_at_delims __P((char *, int, char *, int, int *, int *));
222 /* How to determine the quoted state of the character C. */
223 #define QUOTED_CHAR(c) ((c) == CTLESC)
225 /* Is the first character of STRING a quoted NULL character? */
226 #define QUOTED_NULL(string) ((string)[0] == CTLNUL && (string)[1] == '\0')
228 #endif /* !_SUBST_H_ */