summaryrefslogtreecommitdiff
path: root/builtins/common.h
blob: 630ebd4406098204bca5b334ea9add58dd49fee9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/* common.h -- extern declarations for functions defined in common.c. */

/* Copyright (C) 1993-2022 Free Software Foundation, Inc.

   This file is part of GNU Bash, the Bourne Again SHell.

   Bash is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Bash is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Bash.  If not, see <http://www.gnu.org/licenses/>.
*/

#if  !defined (__COMMON_H)
#  define __COMMON_H

#include "stdc.h"

#define ISOPTION(s, c)	(s[0] == '-' && s[1] == c && !s[2])
#define ISHELP(s)	(STREQ ((s), "--help"))

#define CHECK_HELPOPT(l) \
do { \
  if ((l) && (l)->word && ISHELP((l)->word->word)) \
    { \
      builtin_help (); \
      return (EX_USAGE); \
    } \
} while (0)

#define CASE_HELPOPT \
  case GETOPT_HELP: \
    builtin_help (); \
    return (EX_USAGE)

/* Flag values for parse_and_execute () and parse_string () */
#define SEVAL_NONINT	0x001
#define SEVAL_INTERACT	0x002
#define SEVAL_NOHIST	0x004
#define SEVAL_NOFREE	0x008
#define SEVAL_RESETLINE	0x010
#define SEVAL_PARSEONLY	0x020
#define SEVAL_NOLONGJMP 0x040
#define SEVAL_FUNCDEF	0x080		/* only allow function definitions */
#define SEVAL_ONECMD	0x100		/* only allow a single command */
#define SEVAL_NOHISTEXP	0x200		/* inhibit history expansion */
#define SEVAL_NOOPTIMIZE 0x400		/* don't try to set optimization flags */

/* Flags for describe_command, shared between type.def and command.def */
#define CDESC_ALL		0x001	/* type -a */
#define CDESC_SHORTDESC		0x002	/* command -V */
#define CDESC_REUSABLE		0x004	/* command -v */
#define CDESC_TYPE		0x008	/* type -t */
#define CDESC_PATH_ONLY		0x010	/* type -p */
#define CDESC_FORCE_PATH	0x020	/* type -ap or type -P */
#define CDESC_NOFUNCS		0x040	/* type -f */
#define CDESC_ABSPATH		0x080	/* convert to absolute path, no ./ */
#define CDESC_STDPATH		0x100	/* command -p */

/* Flags for get_job_by_name */
#define JM_PREFIX		0x01	/* prefix of job name */
#define JM_SUBSTRING		0x02	/* substring of job name */
#define JM_EXACT		0x04	/* match job name exactly */
#define JM_STOPPED		0x08	/* match stopped jobs only */
#define JM_FIRSTMATCH		0x10	/* return first matching job */

/* Flags for remember_args and value of changed_dollar_vars */
#define ARGS_NONE		0x0
#define ARGS_INVOC		0x01
#define ARGS_FUNC		0x02
#define ARGS_SETBLTIN		0x04

/* Maximum number of attribute letters */
#define MAX_ATTRIBUTES		16

/* Functions from common.c */
extern void builtin_error (const char *, ...)  __attribute__((__format__ (printf, 1, 2)));
extern void builtin_warning (const char *, ...)  __attribute__((__format__ (printf, 1, 2)));
extern void builtin_usage (void);
extern void no_args (WORD_LIST *);
extern int no_options (WORD_LIST *);

/* common error message functions */
extern void sh_needarg (const char *);
extern void sh_neednumarg (const char *);
extern void sh_notfound (const char *);
extern void sh_invalidopt (const char *);
extern void sh_invalidoptname (const char *);
extern void sh_invalidid (const char *);
extern void sh_invalidnum (const char *);
extern void sh_invalidsig (const char *);
extern void sh_readonly (const char *);
extern void sh_noassign (const char *);
extern void sh_erange (const char *, const char *);
extern void sh_badpid (const char *);
extern void sh_badjob (const char *);
extern void sh_nojobs (const char *);
extern void sh_restricted (const char *);
extern void sh_notbuiltin (const char *);
extern void sh_wrerror (void);
extern void sh_ttyerror (int);
extern int sh_chkwrite (int);

extern char **make_builtin_argv (WORD_LIST *, int *);
extern void remember_args (WORD_LIST *, int);
extern void shift_args (int);
extern int number_of_args (void);

extern int dollar_vars_changed (void);
extern void set_dollar_vars_unchanged (void);
extern void set_dollar_vars_changed (void);

extern int get_numeric_arg (WORD_LIST *, int, intmax_t *);
extern int get_exitstat (WORD_LIST *);
extern int read_octal (char *);

/* Keeps track of the current working directory. */
extern char *the_current_working_directory;
extern char *get_working_directory (const char *);
extern void set_working_directory (const char *);

#if defined (JOB_CONTROL)
extern int get_job_by_name (const char *, int);
extern int get_job_spec (WORD_LIST *);
#endif
extern int display_signal_list (WORD_LIST *, int);

/* It's OK to declare a function as returning a Function * without
   providing a definition of what a `Function' is. */
extern struct builtin *builtin_address_internal (const char *, int);
extern sh_builtin_func_t *find_shell_builtin (const char *);
extern sh_builtin_func_t *builtin_address (const char *);
extern sh_builtin_func_t *find_special_builtin (const char *);
extern void initialize_shell_builtins (void);

#if defined (ARRAY_VARS)
extern int set_expand_once (int, int);
#endif

/* Functions from exit.def */
extern void bash_logout (void);

/* Functions from getopts.def */
extern void getopts_reset (int);

/* Functions from help.def */
extern void builtin_help (void);

/* Functions from read.def */
extern void read_tty_cleanup (void);
extern int read_tty_modified (void);

extern int read_builtin_timeout (int);
extern void check_read_timeout (void);

/* Functions from set.def */
extern int minus_o_option_value (char *);
extern void list_minus_o_opts (int, int);
extern char **get_minus_o_opts (void);
extern int set_minus_o_option (int, char *);

extern void set_shellopts (void);
extern void parse_shellopts (char *);
extern void initialize_shell_options (int);

extern void reset_shell_options (void);

extern char *get_current_options (void);
extern void set_current_options (const char *);

/* Functions from shopt.def */
extern void reset_shopt_options (void);
extern char **get_shopt_options (void);

extern int shopt_setopt (char *, int);
extern int shopt_listopt (char *, int);

extern int set_login_shell (char *, int);

extern void set_bashopts (void);
extern void parse_bashopts (char *);
extern void initialize_bashopts (int);

extern void set_compatibility_opts (void);

/* Functions from type.def */
extern int describe_command (char *, int);

/* Functions from setattr.def */
extern int set_or_show_attributes (WORD_LIST *, int, int);
extern int show_all_var_attributes (int, int);
extern int show_local_var_attributes (int, int);
extern int show_var_attributes (SHELL_VAR *, int, int);
extern int show_name_attributes (char *, int);
extern int show_localname_attributes (char *, int);
extern int show_func_attributes (char *, int);
extern void set_var_attribute (char *, int, int);
extern int var_attribute_string (SHELL_VAR *, int, char *);

/* Functions from pushd.def */
extern char *get_dirstack_from_string (char *);
extern char *get_dirstack_element (intmax_t, int);
extern void set_dirstack_element (intmax_t, int, char *);
extern WORD_LIST *get_directory_stack (int);

/* Functions from evalstring.c */
extern int parse_and_execute (char *, const char *, int);
extern int evalstring (char *, const char *, int);
extern void parse_and_execute_cleanup (int);
extern int parse_string (char *, const char *, int, COMMAND **, char **);
extern int should_suppress_fork (COMMAND *);
extern int can_optimize_connection (COMMAND *);
extern int can_optimize_cat_file (COMMAND *);
extern void optimize_connection_fork (COMMAND *);
extern void optimize_subshell_command (COMMAND *);
extern void optimize_shell_function (COMMAND *);

/* Functions from evalfile.c */
extern int maybe_execute_file (const char *, int);
extern int force_execute_file (const char *, int);
extern int source_file (const char *, int);
extern int fc_execute_file (const char *);

/* variables from common.c */
extern sh_builtin_func_t *this_shell_builtin;
extern sh_builtin_func_t *last_shell_builtin;

extern SHELL_VAR *builtin_bind_variable (char *, char *, int);
extern SHELL_VAR *builtin_bind_var_to_int (char *, intmax_t, int);
extern int builtin_unbind_variable (const char *);

extern SHELL_VAR *builtin_find_indexed_array (char *, int);
extern int builtin_arrayref_flags (WORD_DESC *, int);

/* variables from evalfile.c */
extern int sourcelevel;

/* variables from evalstring.c */
extern int parse_and_execute_level;

/* variables from break.def/continue.def */
extern int breaking;
extern int continuing;
extern int loop_level;

/* variables from shift.def */
extern int print_shift_error;

/* variables from shopt.def */
#if defined (ARRAY_VARS)
extern int expand_once_flag;
#endif

#if defined (EXTENDED_GLOB)
extern int extglob_flag;
#endif

extern int expaliases_flag;

/* variables from source.def */
extern int source_searches_cwd;
extern int source_uses_path;

/* variables from wait.def */
extern int wait_intr_flag;

/* common code to set flags for valid_array_reference and builtin_bind_variable */
#if defined (ARRAY_VARS)
#define SET_VFLAGS(wordflags, vflags, bindflags) \
  do { \
    vflags = assoc_expand_once ?  VA_NOEXPAND : 0; \
    bindflags = assoc_expand_once ? ASS_NOEXPAND : 0; \
    if (assoc_expand_once && (wordflags & W_ARRAYREF)) \
      vflags |= VA_ONEWORD|VA_NOEXPAND; \
    if (vflags & VA_NOEXPAND) \
      bindflags |= ASS_NOEXPAND; \
    if (vflags & VA_ONEWORD) \
      bindflags |= ASS_ONEWORD; \
  } while (0)
#endif

#endif /* !__COMMON_H */