init version.
[bush.git] / builtins / common.h
bloba1ac2fe67bba6fbcb7c24b34196d83e34fd787df
1 /* common.h -- extern declarations for functions defined in common.c. */
3 /* Copyright (C) 1993-2020 Free Software Foundation, Inc.
5 This file is part of GNU Bush, the Bourne Again SHell.
7 Bush 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 Bush 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 Bush. If not, see <http://www.gnu.org/licenses/>.
21 #if !defined (__COMMON_H)
22 # define __COMMON_H
24 #include "stdc.h"
26 #define ISOPTION(s, c) (s[0] == '-' && s[1] == c && !s[2])
27 #define ISHELP(s) (STREQ ((s), "--help"))
29 #define CHECK_HELPOPT(l) \
30 do { \
31 if ((l) && (l)->word && ISHELP((l)->word->word)) \
32 { \
33 builtin_help (); \
34 return (EX_USAGE); \
35 } \
36 } while (0)
38 #define CASE_HELPOPT \
39 case GETOPT_HELP: \
40 builtin_help (); \
41 return (EX_USAGE)
43 /* Flag values for parse_and_execute () */
44 #define SEVAL_NONINT 0x001
45 #define SEVAL_INTERACT 0x002
46 #define SEVAL_NOHIST 0x004
47 #define SEVAL_NOFREE 0x008
48 #define SEVAL_RESETLINE 0x010
49 #define SEVAL_PARSEONLY 0x020
50 #define SEVAL_NOLONGJMP 0x040
51 #define SEVAL_FUNCDEF 0x080 /* only allow function definitions */
52 #define SEVAL_ONECMD 0x100 /* only allow a single command */
53 #define SEVAL_NOHISTEXP 0x200 /* inhibit history expansion */
55 /* Flags for describe_command, shared between type.def and command.def */
56 #define CDESC_ALL 0x001 /* type -a */
57 #define CDESC_SHORTDESC 0x002 /* command -V */
58 #define CDESC_REUSABLE 0x004 /* command -v */
59 #define CDESC_TYPE 0x008 /* type -t */
60 #define CDESC_PATH_ONLY 0x010 /* type -p */
61 #define CDESC_FORCE_PATH 0x020 /* type -ap or type -P */
62 #define CDESC_NOFUNCS 0x040 /* type -f */
63 #define CDESC_ABSPATH 0x080 /* convert to absolute path, no ./ */
64 #define CDESC_STDPATH 0x100 /* command -p */
66 /* Flags for get_job_by_name */
67 #define JM_PREFIX 0x01 /* prefix of job name */
68 #define JM_SUBSTRING 0x02 /* substring of job name */
69 #define JM_EXACT 0x04 /* match job name exactly */
70 #define JM_STOPPED 0x08 /* match stopped jobs only */
71 #define JM_FIRSTMATCH 0x10 /* return first matching job */
73 /* Flags for remember_args and value of changed_dollar_vars */
74 #define ARGS_NONE 0x0
75 #define ARGS_INVOC 0x01
76 #define ARGS_FUNC 0x02
77 #define ARGS_SETBLTIN 0x04
79 /* Maximum number of attribute letters */
80 #define MAX_ATTRIBUTES 16
82 /* Functions from common.c */
83 extern void builtin_error PARAMS((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
84 extern void builtin_warning PARAMS((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
85 extern void builtin_usage PARAMS((void));
86 extern void no_args PARAMS((WORD_LIST *));
87 extern int no_options PARAMS((WORD_LIST *));
89 /* common error message functions */
90 extern void sh_needarg PARAMS((char *));
91 extern void sh_neednumarg PARAMS((char *));
92 extern void sh_notfound PARAMS((char *));
93 extern void sh_invalidopt PARAMS((char *));
94 extern void sh_invalidoptname PARAMS((char *));
95 extern void sh_invalidid PARAMS((char *));
96 extern void sh_invalidnum PARAMS((char *));
97 extern void sh_invalidsig PARAMS((char *));
98 extern void sh_erange PARAMS((char *, char *));
99 extern void sh_badpid PARAMS((char *));
100 extern void sh_badjob PARAMS((char *));
101 extern void sh_readonly PARAMS((const char *));
102 extern void sh_nojobs PARAMS((char *));
103 extern void sh_restricted PARAMS((char *));
104 extern void sh_notbuiltin PARAMS((char *));
105 extern void sh_wrerror PARAMS((void));
106 extern void sh_ttyerror PARAMS((int));
107 extern int sh_chkwrite PARAMS((int));
109 extern char **make_builtin_argv PARAMS((WORD_LIST *, int *));
110 extern void remember_args PARAMS((WORD_LIST *, int));
111 extern void shift_args PARAMS((int));
112 extern int number_of_args PARAMS((void));
114 extern int dollar_vars_changed PARAMS((void));
115 extern void set_dollar_vars_unchanged PARAMS((void));
116 extern void set_dollar_vars_changed PARAMS((void));
118 extern int get_numeric_arg PARAMS((WORD_LIST *, int, intmax_t *));
119 extern int get_exitstat PARAMS((WORD_LIST *));
120 extern int read_octal PARAMS((char *));
122 /* Keeps track of the current working directory. */
123 extern char *the_current_working_directory;
124 extern char *get_working_directory PARAMS((char *));
125 extern void set_working_directory PARAMS((char *));
127 #if defined (JOB_CONTROL)
128 extern int get_job_by_name PARAMS((const char *, int));
129 extern int get_job_spec PARAMS((WORD_LIST *));
130 #endif
131 extern int display_signal_list PARAMS((WORD_LIST *, int));
133 /* It's OK to declare a function as returning a Function * without
134 providing a definition of what a `Function' is. */
135 extern struct builtin *builtin_address_internal PARAMS((char *, int));
136 extern sh_builtin_func_t *find_shell_builtin PARAMS((char *));
137 extern sh_builtin_func_t *builtin_address PARAMS((char *));
138 extern sh_builtin_func_t *find_special_builtin PARAMS((char *));
139 extern void initialize_shell_builtins PARAMS((void));
141 /* Functions from exit.def */
142 extern void bush_logout PARAMS((void));
144 /* Functions from getopts.def */
145 extern void getopts_reset PARAMS((int));
147 /* Functions from help.def */
148 extern void builtin_help PARAMS((void));
150 /* Functions from read.def */
151 extern void read_tty_cleanup PARAMS((void));
152 extern int read_tty_modified PARAMS((void));
154 /* Functions from set.def */
155 extern int minus_o_option_value PARAMS((char *));
156 extern void list_minus_o_opts PARAMS((int, int));
157 extern char **get_minus_o_opts PARAMS((void));
158 extern int set_minus_o_option PARAMS((int, char *));
160 extern void set_shellopts PARAMS((void));
161 extern void parse_shellopts PARAMS((char *));
162 extern void initialize_shell_options PARAMS((int));
164 extern void reset_shell_options PARAMS((void));
166 extern char *get_current_options PARAMS((void));
167 extern void set_current_options PARAMS((const char *));
169 /* Functions from shopt.def */
170 extern void reset_shopt_options PARAMS((void));
171 extern char **get_shopt_options PARAMS((void));
173 extern int shopt_setopt PARAMS((char *, int));
174 extern int shopt_listopt PARAMS((char *, int));
176 extern int set_login_shell PARAMS((char *, int));
178 extern void set_bushopts PARAMS((void));
179 extern void parse_bushopts PARAMS((char *));
180 extern void initialize_bushopts PARAMS((int));
182 extern void set_compatibility_opts PARAMS((void));
184 /* Functions from type.def */
185 extern int describe_command PARAMS((char *, int));
187 /* Functions from setattr.def */
188 extern int set_or_show_attributes PARAMS((WORD_LIST *, int, int));
189 extern int show_all_var_attributes PARAMS((int, int));
190 extern int show_local_var_attributes PARAMS((int, int));
191 extern int show_var_attributes PARAMS((SHELL_VAR *, int, int));
192 extern int show_name_attributes PARAMS((char *, int));
193 extern int show_localname_attributes PARAMS((char *, int));
194 extern int show_func_attributes PARAMS((char *, int));
195 extern void set_var_attribute PARAMS((char *, int, int));
196 extern int var_attribute_string PARAMS((SHELL_VAR *, int, char *));
198 /* Functions from pushd.def */
199 extern char *get_dirstack_from_string PARAMS((char *));
200 extern char *get_dirstack_element PARAMS((intmax_t, int));
201 extern void set_dirstack_element PARAMS((intmax_t, int, char *));
202 extern WORD_LIST *get_directory_stack PARAMS((int));
204 /* Functions from evalstring.c */
205 extern int parse_and_execute PARAMS((char *, const char *, int));
206 extern int evalstring PARAMS((char *, const char *, int));
207 extern void parse_and_execute_cleanup PARAMS((int));
208 extern int parse_string PARAMS((char *, const char *, int, char **));
209 extern int should_suppress_fork PARAMS((COMMAND *));
210 extern int can_optimize_connection PARAMS((COMMAND *));
211 extern void optimize_fork PARAMS((COMMAND *));
212 extern void optimize_subshell_command PARAMS((COMMAND *));
213 extern void optimize_shell_function PARAMS((COMMAND *));
215 /* Functions from evalfile.c */
216 extern int maybe_execute_file PARAMS((const char *, int));
217 extern int force_execute_file PARAMS((const char *, int));
218 extern int source_file PARAMS((const char *, int));
219 extern int fc_execute_file PARAMS((const char *));
221 /* variables from common.c */
222 extern sh_builtin_func_t *this_shell_builtin;
223 extern sh_builtin_func_t *last_shell_builtin;
225 extern SHELL_VAR *builtin_bind_variable PARAMS((char *, char *, int));
226 extern int builtin_unbind_variable PARAMS((const char *));
228 /* variables from evalfile.c */
229 extern int sourcelevel;
231 /* variables from evalstring.c */
232 extern int parse_and_execute_level;
234 /* variables from break.def/continue.def */
235 extern int breaking;
236 extern int continuing;
237 extern int loop_level;
239 /* variables from read.def */
240 extern int sigalrm_seen;
242 /* variables from shift.def */
243 extern int print_shift_error;
245 /* variables from source.def */
246 extern int source_searches_cwd;
247 extern int source_uses_path;
249 /* variables from wait.def */
250 extern int wait_intr_flag;
252 #endif /* !__COMMON_H */