blob: f5cd87f081f700f203c27fa315666f1189679024 [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001/* common.h -- extern declarations for functions defined in common.c. */
2
Chet Ramey74091dd2022-09-26 11:49:46 -04003/* Copyright (C) 1993-2022 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00004
5 This file is part of GNU Bash, the Bourne Again SHell.
6
Jari Aalto31859422009-01-12 13:36:28 +00007 Bash 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.
Jari Aalto726f6381996-08-26 18:22:31 +000011
Jari Aalto31859422009-01-12 13:36:28 +000012 Bash 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.
Jari Aalto726f6381996-08-26 18:22:31 +000016
Jari Aalto31859422009-01-12 13:36:28 +000017 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
19*/
Jari Aalto726f6381996-08-26 18:22:31 +000020
21#if !defined (__COMMON_H)
22# define __COMMON_H
23
Jari Aaltobb706242000-03-17 21:46:59 +000024#include "stdc.h"
Jari Aaltoccc6cda1996-12-23 17:02:34 +000025
Chet Rameyd233b482019-01-07 09:27:52 -050026#define ISOPTION(s, c) (s[0] == '-' && s[1] == c && !s[2])
Chet Rameya0c0a002016-09-15 16:59:08 -040027#define ISHELP(s) (STREQ ((s), "--help"))
28
29#define CHECK_HELPOPT(l) \
30do { \
31 if ((l) && (l)->word && ISHELP((l)->word->word)) \
32 { \
33 builtin_help (); \
34 return (EX_USAGE); \
35 } \
36} while (0)
37
38#define CASE_HELPOPT \
39 case GETOPT_HELP: \
40 builtin_help (); \
41 return (EX_USAGE)
Jari Aalto726f6381996-08-26 18:22:31 +000042
Chet Ramey74091dd2022-09-26 11:49:46 -040043/* Flag values for parse_and_execute () and parse_string () */
Jari Aalto7117c2d2002-07-17 14:10:11 +000044#define SEVAL_NONINT 0x001
45#define SEVAL_INTERACT 0x002
46#define SEVAL_NOHIST 0x004
47#define SEVAL_NOFREE 0x008
Jari Aaltob80f6442004-07-27 13:29:18 +000048#define SEVAL_RESETLINE 0x010
Jari Aalto31859422009-01-12 13:36:28 +000049#define SEVAL_PARSEONLY 0x020
50#define SEVAL_NOLONGJMP 0x040
Chet Rameyb64a0e12014-09-25 08:45:07 -040051#define SEVAL_FUNCDEF 0x080 /* only allow function definitions */
52#define SEVAL_ONECMD 0x100 /* only allow a single command */
Chet Rameya0c0a002016-09-15 16:59:08 -040053#define SEVAL_NOHISTEXP 0x200 /* inhibit history expansion */
Jari Aalto7117c2d2002-07-17 14:10:11 +000054
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 */
Jari Aalto95732b42005-12-07 14:08:12 +000063#define CDESC_ABSPATH 0x080 /* convert to absolute path, no ./ */
Chet Rameya0c0a002016-09-15 16:59:08 -040064#define CDESC_STDPATH 0x100 /* command -p */
Jari Aalto7117c2d2002-07-17 14:10:11 +000065
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 */
72
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
Jari Aaltod166f041997-06-05 14:59:13 +000078
Chet Rameya0c0a002016-09-15 16:59:08 -040079/* Maximum number of attribute letters */
80#define MAX_ATTRIBUTES 16
81
Jari Aaltocce855b1998-04-17 19:52:44 +000082/* Functions from common.c */
Chet Ramey8868eda2020-12-06 15:51:17 -050083extern void builtin_error PARAMS((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
84extern void builtin_warning PARAMS((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
85extern void builtin_usage PARAMS((void));
86extern void no_args PARAMS((WORD_LIST *));
87extern int no_options PARAMS((WORD_LIST *));
Jari Aalto726f6381996-08-26 18:22:31 +000088
Jari Aalto7117c2d2002-07-17 14:10:11 +000089/* common error message functions */
Chet Ramey8868eda2020-12-06 15:51:17 -050090extern void sh_needarg PARAMS((char *));
91extern void sh_neednumarg PARAMS((char *));
92extern void sh_notfound PARAMS((char *));
93extern void sh_invalidopt PARAMS((char *));
94extern void sh_invalidoptname PARAMS((char *));
95extern void sh_invalidid PARAMS((char *));
96extern void sh_invalidnum PARAMS((char *));
97extern void sh_invalidsig PARAMS((char *));
Chet Ramey74091dd2022-09-26 11:49:46 -040098extern void sh_readonly PARAMS((const char *));
99extern void sh_noassign PARAMS((const char *));
Chet Ramey8868eda2020-12-06 15:51:17 -0500100extern void sh_erange PARAMS((char *, char *));
101extern void sh_badpid PARAMS((char *));
102extern void sh_badjob PARAMS((char *));
Chet Ramey8868eda2020-12-06 15:51:17 -0500103extern void sh_nojobs PARAMS((char *));
104extern void sh_restricted PARAMS((char *));
105extern void sh_notbuiltin PARAMS((char *));
106extern void sh_wrerror PARAMS((void));
107extern void sh_ttyerror PARAMS((int));
108extern int sh_chkwrite PARAMS((int));
Jari Aalto7117c2d2002-07-17 14:10:11 +0000109
Chet Ramey8868eda2020-12-06 15:51:17 -0500110extern char **make_builtin_argv PARAMS((WORD_LIST *, int *));
111extern void remember_args PARAMS((WORD_LIST *, int));
112extern void shift_args PARAMS((int));
113extern int number_of_args PARAMS((void));
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000114
Chet Ramey8868eda2020-12-06 15:51:17 -0500115extern int dollar_vars_changed PARAMS((void));
116extern void set_dollar_vars_unchanged PARAMS((void));
117extern void set_dollar_vars_changed PARAMS((void));
Jari Aalto726f6381996-08-26 18:22:31 +0000118
Chet Ramey8868eda2020-12-06 15:51:17 -0500119extern int get_numeric_arg PARAMS((WORD_LIST *, int, intmax_t *));
120extern int get_exitstat PARAMS((WORD_LIST *));
121extern int read_octal PARAMS((char *));
Jari Aalto726f6381996-08-26 18:22:31 +0000122
123/* Keeps track of the current working directory. */
124extern char *the_current_working_directory;
Chet Ramey8868eda2020-12-06 15:51:17 -0500125extern char *get_working_directory PARAMS((char *));
126extern void set_working_directory PARAMS((char *));
Jari Aalto726f6381996-08-26 18:22:31 +0000127
128#if defined (JOB_CONTROL)
Chet Ramey8868eda2020-12-06 15:51:17 -0500129extern int get_job_by_name PARAMS((const char *, int));
130extern int get_job_spec PARAMS((WORD_LIST *));
Jari Aalto726f6381996-08-26 18:22:31 +0000131#endif
Chet Ramey8868eda2020-12-06 15:51:17 -0500132extern int display_signal_list PARAMS((WORD_LIST *, int));
Jari Aalto726f6381996-08-26 18:22:31 +0000133
134/* It's OK to declare a function as returning a Function * without
135 providing a definition of what a `Function' is. */
Chet Ramey8868eda2020-12-06 15:51:17 -0500136extern struct builtin *builtin_address_internal PARAMS((char *, int));
137extern sh_builtin_func_t *find_shell_builtin PARAMS((char *));
138extern sh_builtin_func_t *builtin_address PARAMS((char *));
139extern sh_builtin_func_t *find_special_builtin PARAMS((char *));
140extern void initialize_shell_builtins PARAMS((void));
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000141
Chet Ramey74091dd2022-09-26 11:49:46 -0400142#if defined (ARRAY_VARS)
143extern int set_expand_once PARAMS((int, int));
144#endif
145
Jari Aaltob80f6442004-07-27 13:29:18 +0000146/* Functions from exit.def */
Chet Ramey8868eda2020-12-06 15:51:17 -0500147extern void bash_logout PARAMS((void));
Jari Aaltob80f6442004-07-27 13:29:18 +0000148
Jari Aaltof73dda02001-11-13 17:56:06 +0000149/* Functions from getopts.def */
Chet Ramey8868eda2020-12-06 15:51:17 -0500150extern void getopts_reset PARAMS((int));
Jari Aaltof73dda02001-11-13 17:56:06 +0000151
Chet Rameya0c0a002016-09-15 16:59:08 -0400152/* Functions from help.def */
Chet Ramey8868eda2020-12-06 15:51:17 -0500153extern void builtin_help PARAMS((void));
Chet Rameya0c0a002016-09-15 16:59:08 -0400154
Chet Ramey84c617e2015-01-15 10:21:08 -0500155/* Functions from read.def */
Chet Ramey8868eda2020-12-06 15:51:17 -0500156extern void read_tty_cleanup PARAMS((void));
157extern int read_tty_modified PARAMS((void));
Chet Ramey84c617e2015-01-15 10:21:08 -0500158
Chet Ramey74091dd2022-09-26 11:49:46 -0400159extern int read_builtin_timeout PARAMS((int));
160extern void check_read_timeout PARAMS((void));
161
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000162/* Functions from set.def */
Chet Ramey8868eda2020-12-06 15:51:17 -0500163extern int minus_o_option_value PARAMS((char *));
164extern void list_minus_o_opts PARAMS((int, int));
165extern char **get_minus_o_opts PARAMS((void));
166extern int set_minus_o_option PARAMS((int, char *));
Jari Aaltof73dda02001-11-13 17:56:06 +0000167
Chet Ramey8868eda2020-12-06 15:51:17 -0500168extern void set_shellopts PARAMS((void));
169extern void parse_shellopts PARAMS((char *));
170extern void initialize_shell_options PARAMS((int));
Jari Aaltof73dda02001-11-13 17:56:06 +0000171
Chet Ramey8868eda2020-12-06 15:51:17 -0500172extern void reset_shell_options PARAMS((void));
Jari Aaltod166f041997-06-05 14:59:13 +0000173
Chet Ramey8868eda2020-12-06 15:51:17 -0500174extern char *get_current_options PARAMS((void));
175extern void set_current_options PARAMS((const char *));
Chet Rameya0c0a002016-09-15 16:59:08 -0400176
Jari Aaltod166f041997-06-05 14:59:13 +0000177/* Functions from shopt.def */
Chet Ramey8868eda2020-12-06 15:51:17 -0500178extern void reset_shopt_options PARAMS((void));
179extern char **get_shopt_options PARAMS((void));
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000180
Chet Ramey8868eda2020-12-06 15:51:17 -0500181extern int shopt_setopt PARAMS((char *, int));
182extern int shopt_listopt PARAMS((char *, int));
Jari Aaltof73dda02001-11-13 17:56:06 +0000183
Chet Ramey8868eda2020-12-06 15:51:17 -0500184extern int set_login_shell PARAMS((char *, int));
Chet Ramey00018032011-11-21 20:51:19 -0500185
Chet Ramey8868eda2020-12-06 15:51:17 -0500186extern void set_bashopts PARAMS((void));
187extern void parse_bashopts PARAMS((char *));
188extern void initialize_bashopts PARAMS((int));
Jari Aaltof73dda02001-11-13 17:56:06 +0000189
Chet Ramey8868eda2020-12-06 15:51:17 -0500190extern void set_compatibility_opts PARAMS((void));
Chet Rameyac50fba2014-02-26 09:36:43 -0500191
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000192/* Functions from type.def */
Chet Ramey8868eda2020-12-06 15:51:17 -0500193extern int describe_command PARAMS((char *, int));
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000194
195/* Functions from setattr.def */
Chet Ramey8868eda2020-12-06 15:51:17 -0500196extern int set_or_show_attributes PARAMS((WORD_LIST *, int, int));
197extern int show_all_var_attributes PARAMS((int, int));
198extern int show_local_var_attributes PARAMS((int, int));
199extern int show_var_attributes PARAMS((SHELL_VAR *, int, int));
200extern int show_name_attributes PARAMS((char *, int));
201extern int show_localname_attributes PARAMS((char *, int));
202extern int show_func_attributes PARAMS((char *, int));
203extern void set_var_attribute PARAMS((char *, int, int));
204extern int var_attribute_string PARAMS((SHELL_VAR *, int, char *));
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000205
206/* Functions from pushd.def */
Chet Ramey8868eda2020-12-06 15:51:17 -0500207extern char *get_dirstack_from_string PARAMS((char *));
208extern char *get_dirstack_element PARAMS((intmax_t, int));
209extern void set_dirstack_element PARAMS((intmax_t, int, char *));
210extern WORD_LIST *get_directory_stack PARAMS((int));
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000211
212/* Functions from evalstring.c */
Chet Ramey8868eda2020-12-06 15:51:17 -0500213extern int parse_and_execute PARAMS((char *, const char *, int));
214extern int evalstring PARAMS((char *, const char *, int));
215extern void parse_and_execute_cleanup PARAMS((int));
Chet Ramey74091dd2022-09-26 11:49:46 -0400216extern int parse_string PARAMS((char *, const char *, int, COMMAND **, char **));
Chet Ramey8868eda2020-12-06 15:51:17 -0500217extern int should_suppress_fork PARAMS((COMMAND *));
218extern int can_optimize_connection PARAMS((COMMAND *));
Chet Ramey74091dd2022-09-26 11:49:46 -0400219extern int can_optimize_cat_file PARAMS((COMMAND *));
220extern void optimize_connection_fork PARAMS((COMMAND *));
Chet Ramey8868eda2020-12-06 15:51:17 -0500221extern void optimize_subshell_command PARAMS((COMMAND *));
222extern void optimize_shell_function PARAMS((COMMAND *));
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000223
224/* Functions from evalfile.c */
Chet Ramey8868eda2020-12-06 15:51:17 -0500225extern int maybe_execute_file PARAMS((const char *, int));
226extern int force_execute_file PARAMS((const char *, int));
227extern int source_file PARAMS((const char *, int));
228extern int fc_execute_file PARAMS((const char *));
Jari Aalto726f6381996-08-26 18:22:31 +0000229
Chet Rameyd233b482019-01-07 09:27:52 -0500230/* variables from common.c */
231extern sh_builtin_func_t *this_shell_builtin;
232extern sh_builtin_func_t *last_shell_builtin;
233
Chet Ramey8868eda2020-12-06 15:51:17 -0500234extern SHELL_VAR *builtin_bind_variable PARAMS((char *, char *, int));
Chet Ramey74091dd2022-09-26 11:49:46 -0400235extern SHELL_VAR *builtin_bind_var_to_int PARAMS((char *, intmax_t, int));
Chet Ramey8868eda2020-12-06 15:51:17 -0500236extern int builtin_unbind_variable PARAMS((const char *));
237
Chet Ramey74091dd2022-09-26 11:49:46 -0400238extern SHELL_VAR *builtin_find_indexed_array PARAMS((char *, int));
239extern int builtin_arrayref_flags PARAMS((WORD_DESC *, int));
240
Chet Rameyd233b482019-01-07 09:27:52 -0500241/* variables from evalfile.c */
242extern int sourcelevel;
243
244/* variables from evalstring.c */
245extern int parse_and_execute_level;
246
247/* variables from break.def/continue.def */
248extern int breaking;
249extern int continuing;
250extern int loop_level;
251
Chet Rameyd233b482019-01-07 09:27:52 -0500252/* variables from shift.def */
253extern int print_shift_error;
254
Chet Ramey74091dd2022-09-26 11:49:46 -0400255/* variables from shopt.def */
256#if defined (ARRAY_VARS)
257extern int expand_once_flag;
258#endif
259
Chet Rameyd233b482019-01-07 09:27:52 -0500260/* variables from source.def */
261extern int source_searches_cwd;
262extern int source_uses_path;
263
264/* variables from wait.def */
265extern int wait_intr_flag;
266
Chet Ramey74091dd2022-09-26 11:49:46 -0400267/* common code to set flags for valid_array_reference and builtin_bind_variable */
268#if defined (ARRAY_VARS)
269#define SET_VFLAGS(wordflags, vflags, bindflags) \
270 do { \
271 vflags = assoc_expand_once ? VA_NOEXPAND : 0; \
272 bindflags = assoc_expand_once ? ASS_NOEXPAND : 0; \
273 if (assoc_expand_once && (wordflags & W_ARRAYREF)) \
274 vflags |= VA_ONEWORD|VA_NOEXPAND; \
275 if (vflags & VA_NOEXPAND) \
276 bindflags |= ASS_NOEXPAND; \
277 if (vflags & VA_ONEWORD) \
278 bindflags |= ASS_ONEWORD; \
279 } while (0)
280#endif
281
Jari Aalto726f6381996-08-26 18:22:31 +0000282#endif /* !__COMMON_H */