- C89-style function declarations
- add `const' and `inline' where it makes sense
+ 1/2/2023
+ --------
+lib/sh/{stringvec.c,inet_aton.c,strnlen.c,spell.c,netopen.c,stringlist.c}
+lib/sh/{strtrans.c,tmpfile.c,uconvert.c,zcatfd.c}
+builtins/{common.c,common.h}
+mailcheck.c,bashline.c,pathexp.c,stringlib.c,locale.c,pcomplete.c,redir.c
+test.c,trap.c,variables.c,bashhist.c,expr.c,arrayfunc.c,assoc.c,variables.c
+subst.c,findcmd.c
+arrayfunc.h,variables.h,findcmd.h,bashline.h,trap.h,pathexp.h,externs.h,
+pcomplete.h,bashhist.h,assoc.h,general.h,subst.h
+ - more `const' changes, remove `register'
/* arrayfunc.c -- High-level array functions used by other parts of the shell. */
-/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
/* Ditto for indexed array subscripts -- currently unused */
int array_expand_once = 0;
-static SHELL_VAR *bind_array_var_internal (SHELL_VAR *, arrayind_t, char *, char *, int);
-static SHELL_VAR *assign_array_element_internal (SHELL_VAR *, char *, char *, char *, int, char *, int, array_eltstate_t *);
+static SHELL_VAR *bind_array_var_internal (SHELL_VAR *, arrayind_t, char *, const char *, int);
+static SHELL_VAR *assign_array_element_internal (SHELL_VAR *, const char *, char *, char *, int, const char *, int, array_eltstate_t *);
static void assign_assoc_from_kvlist (SHELL_VAR *, WORD_LIST *, HASH_TABLE *, int);
}
char *
-make_array_variable_value (SHELL_VAR *entry, arrayind_t ind, char *key, char *value, int flags)
+make_array_variable_value (SHELL_VAR *entry, arrayind_t ind, const char *key, const char *value, int flags)
{
SHELL_VAR *dentry;
char *newval;
XXX - make sure that any dynamic associative array variables recreate the
hash table on each assignment. BASH_CMDS and BASH_ALIASES already do this */
static SHELL_VAR *
-bind_assoc_var_internal (SHELL_VAR *entry, HASH_TABLE *hash, char *key, char *value, int flags)
+bind_assoc_var_internal (SHELL_VAR *entry, HASH_TABLE *hash, char *key, const char *value, int flags)
{
char *newval;
/* Perform ENTRY[IND]=VALUE or ENTRY[KEY]=VALUE. This is not called for every
assignment to an associative array; see assign_compound_array_list below. */
static SHELL_VAR *
-bind_array_var_internal (SHELL_VAR *entry, arrayind_t ind, char *key, char *value, int flags)
+bind_array_var_internal (SHELL_VAR *entry, arrayind_t ind, char *key, const char *value, int flags)
{
char *newval;
If NAME does not exist, just create an array variable, no matter what
IND's value may be. */
SHELL_VAR *
-bind_array_variable (char *name, arrayind_t ind, char *value, int flags)
+bind_array_variable (const char *name, arrayind_t ind, const char *value, int flags)
{
SHELL_VAR *entry;
}
SHELL_VAR *
-bind_assoc_variable (SHELL_VAR *entry, char *name, char *key, char *value, int flags)
+bind_assoc_variable (SHELL_VAR *entry, const char *name, char *key, const char *value, int flags)
{
if ((readonly_p (entry) && (flags&ASS_FORCE) == 0) || noassign_p (entry))
{
assign VALUE to that array element by calling bind_array_variable().
Flags are ASS_ assignment flags */
SHELL_VAR *
-assign_array_element (char *name, char *value, int flags, array_eltstate_t *estatep)
+assign_array_element (const char *name, const char *value, int flags, array_eltstate_t *estatep)
{
char *sub, *vname;
int sublen, isassoc, avflags;
}
static SHELL_VAR *
-assign_array_element_internal (SHELL_VAR *entry, char *name, char *vname,
- char *sub, int sublen, char *value,
+assign_array_element_internal (SHELL_VAR *entry, const char *name, char *vname,
+ char *sub, int sublen, const char *value,
int flags, array_eltstate_t *estatep)
{
char *akey, *nkey;
for assignment (e.g., by the `read' builtin). If FLAGS&2 is non-zero, we
create an associative array. */
SHELL_VAR *
-find_or_make_array_variable (char *name, int flags)
+find_or_make_array_variable (const char *name, int flags)
{
SHELL_VAR *var;
/* Perform a compound assignment statement for array NAME, where VALUE is
the text between the parens: NAME=( VALUE ) */
SHELL_VAR *
-assign_array_from_string (char *name, char *value, int flags)
+assign_array_from_string (const char *name, char *value, int flags)
{
SHELL_VAR *var;
int vflags;
}
char *
-expand_and_quote_kvpair_word (char *w)
+expand_and_quote_kvpair_word (const char *w)
{
char *r, *s, *t;
not be modified. */
/* We need to reserve 1 for FLAGS, which we pass to skipsubscript. */
int
-tokenize_array_reference (char *name, int flags, char **subp)
+tokenize_array_reference (const char *name, int flags, char **subp)
{
char *t;
int r, len, isassoc, ssflags;
int
valid_array_reference (const char *name, int flags)
{
- return tokenize_array_reference ((char *)name, flags, (char **)NULL);
+ return tokenize_array_reference (name, flags, (char **)NULL);
}
/* Expand the array index beginning at S and extending LEN characters. */
arrayind_t
-array_expand_index (SHELL_VAR *var, char *s, int len, int flags)
+array_expand_index (SHELL_VAR *var, const char *s, int len, int flags)
{
char *exp, *t, *savecmd;
int expok, eflag;
}
char *
-array_keys (char *s, int quoted, int pflags)
+array_keys (const char *s, int quoted, int pflags)
{
int len;
char *retval, *t, *temp;
/* arrayfunc.h -- declarations for miscellaneous array functions in arrayfunc.c */
-/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
extern SHELL_VAR *convert_var_to_array (SHELL_VAR *);
extern SHELL_VAR *convert_var_to_assoc (SHELL_VAR *);
-extern char *make_array_variable_value (SHELL_VAR *, arrayind_t, char *, char *, int);
+extern char *make_array_variable_value (SHELL_VAR *, arrayind_t, const char *, const char *, int);
-extern SHELL_VAR *bind_array_variable (char *, arrayind_t, char *, int);
+extern SHELL_VAR *bind_array_variable (const char *, arrayind_t, const char *, int);
extern SHELL_VAR *bind_array_element (SHELL_VAR *, arrayind_t, char *, int);
-extern SHELL_VAR *assign_array_element (char *, char *, int, array_eltstate_t *);
+extern SHELL_VAR *assign_array_element (const char *, const char *, int, array_eltstate_t *);
-extern SHELL_VAR *bind_assoc_variable (SHELL_VAR *, char *, char *, char *, int);
+extern SHELL_VAR *bind_assoc_variable (SHELL_VAR *, const char *, char *, const char *, int);
-extern SHELL_VAR *find_or_make_array_variable (char *, int);
+extern SHELL_VAR *find_or_make_array_variable (const char *, int);
-extern SHELL_VAR *assign_array_from_string (char *, char *, int);
+extern SHELL_VAR *assign_array_from_string (const char *, char *, int);
extern SHELL_VAR *assign_array_var_from_word_list (SHELL_VAR *, WORD_LIST *, int);
extern WORD_LIST *expand_compound_array_assignment (SHELL_VAR *, char *, int);
extern void quote_compound_array_list (WORD_LIST *, int);
extern int kvpair_assignment_p (WORD_LIST *);
-extern char *expand_and_quote_kvpair_word (char *);
+extern char *expand_and_quote_kvpair_word (const char *);
extern int unbind_array_element (SHELL_VAR *, char *, int);
extern int skipsubscript (const char *, int, int);
extern void print_array_assignment (SHELL_VAR *, int);
extern void print_assoc_assignment (SHELL_VAR *, int);
-extern arrayind_t array_expand_index (SHELL_VAR *, char *, int, int);
+extern arrayind_t array_expand_index (SHELL_VAR *, const char *, int, int);
extern int valid_array_reference (const char *, int);
-extern int tokenize_array_reference (char *, int, char **);
+extern int tokenize_array_reference (const char *, int, char **);
extern char *array_value (const char *, int, int, array_eltstate_t *);
extern char *get_array_value (const char *, int, array_eltstate_t *);
-extern char *array_keys (char *, int, int);
+extern char *array_keys (const char *, int, int);
extern char *array_variable_name (const char *, int, char **, int *);
extern SHELL_VAR *array_variable_part (const char *, int, char **, int *);
* chet@ins.cwru.edu
*/
-/* Copyright (C) 2008,2009,2011-2022 Free Software Foundation, Inc.
+/* Copyright (C) 2008,2009,2011-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
}
void
-assoc_remove (HASH_TABLE *hash, char *string)
+assoc_remove (HASH_TABLE *hash, const char *string)
{
BUCKET_CONTENTS *b;
}
char *
-assoc_reference (HASH_TABLE *hash, char *string)
+assoc_reference (HASH_TABLE *hash, const char *string)
{
BUCKET_CONTENTS *b;
/* assoc.h -- definitions for the interface exported by assoc.c that allows
the rest of the shell to manipulate associative array variables. */
-/* Copyright (C) 2008,2009-2021 Free Software Foundation, Inc.
+/* Copyright (C) 2008,2009-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
extern int assoc_insert (HASH_TABLE *, char *, char *);
extern PTR_T assoc_replace (HASH_TABLE *, char *, char *);
-extern void assoc_remove (HASH_TABLE *, char *);
+extern void assoc_remove (HASH_TABLE *, const char *);
-extern char *assoc_reference (HASH_TABLE *, char *);
+extern char *assoc_reference (HASH_TABLE *, const char *);
extern char *assoc_subrange (HASH_TABLE *, arrayind_t, arrayind_t, int, int, int);
extern char *assoc_patsub (HASH_TABLE *, char *, char *, int);
/* bashhist.c -- bash interface to the GNU history library. */
-/* Copyright (C) 1993-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
}
void
-setup_history_ignore (char *varname)
+setup_history_ignore (const char *varname)
{
setup_ignore_patterns (&histignore);
}
/* bashhist.h -- interface to the bash history functions in bashhist.c. */
-/* Copyright (C) 1993-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
extern int check_add_history (char *, int);
extern int history_number (void);
-extern void setup_history_ignore (char *);
+extern void setup_history_ignore (const char *);
extern char *last_history_line (void);
/* bashline.c -- Bash's interface to the readline library. */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
static int bash_spell_correct_shellword (int, int);
/* Helper functions for Readline. */
-static char *restore_tilde (char *, char *);
+static char *restore_tilde (const char *, char *);
static char *maybe_restore_tilde (char *, char *);
static char *bash_filename_rewrite_hook (char *, int);
static int directory_exists (const char *, int);
static void cleanup_expansion_error (void);
-static void maybe_make_readline_line (char *);
+static void maybe_make_readline_line (const char *);
static void set_up_new_line (char *);
static int check_redir (int);
static int bash_dabbrev_expand (int, int);
static void initialize_hostname_list (void);
-static void add_host_name (char *);
-static void snarf_hosts_from_file (char *);
-static char **hostnames_matching (char *);
+static void add_host_name (const char *);
+static void snarf_hosts_from_file (const char *);
+static char **hostnames_matching (const char *);
static void _ignore_completion_names (char **, sh_ignore_func_t *);
static int name_is_acceptable (const char *);
#endif /* SPECIFIC_COMPLETION_FUNCTIONS */
-static int edit_and_execute_command (int, int, int, char *);
+static int edit_and_execute_command (int, int, int, const char *);
#if defined (VI_MODE)
static int vi_edit_and_execute_command (int, int);
static int bash_vi_complete (int, int);
/* Call this to set the initial text for the next line to read
from readline. */
int
-bash_re_edit (char *line)
+bash_re_edit (const char *line)
{
FREE (push_to_readline);
/* Add NAME to the list of hosts. */
static void
-add_host_name (char *name)
+add_host_name (const char *name)
{
if (hostname_list_length + 2 > hostname_list_size)
{
#define cr_whitespace(c) ((c) == '\r' || (c) == '\n' || whitespace(c))
static void
-snarf_hosts_from_file (char *filename)
+snarf_hosts_from_file (const char *filename)
{
FILE *file;
char *temp, buffer[256], name[256];
Initialize the hostname list the first time if necessary.
The array is malloc ()'ed, but not the individual strings. */
static char **
-hostnames_matching (char *text)
+hostnames_matching (const char *text)
{
register int i, len, nmatch, rsize;
char **result;
#define POSIX_VI_EDIT_COMMAND "fc -e vi"
static int
-edit_and_execute_command (int count, int c, int editing_mode, char *edit_command)
+edit_and_execute_command (int count, int c, int editing_mode, const char *edit_command)
{
char *command, *metaval;
int r, rrs, metaflag;
undo record to get from the readline line buffer contents to the new
line and make NEW_LINE the current readline line. */
static void
-maybe_make_readline_line (char *new_line)
+maybe_make_readline_line (const char *new_line)
{
if (new_line && strcmp (new_line, rl_line_buffer) != 0)
{
#if 0
static int
-ignore_dot_names (char *name)
+ignore_dot_names (const char *name)
{
return (name[0] != '.');
}
is an expanded filename. DIRECTORY_PART is the tilde-prefix portion
of the un-tilde-expanded version of VAL (what the user typed). */
static char *
-restore_tilde (char *val, char *directory_part)
+restore_tilde (const char *val, char *directory_part)
{
int l, vl, dl2, xl;
char *dh2, *expdir, *ret, *v;
/* bashline.h -- interface to the bash readline functions in bashline.c. */
-/* Copyright (C) 1993-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
extern void initialize_readline (void);
extern void bashline_reset (void);
extern void bashline_reinitialize (void);
-extern int bash_re_edit (char *);
+extern int bash_re_edit (const char *);
extern void bashline_set_event_hook (void);
extern void bashline_reset_event_hook (void);
}
void
-sh_needarg (char *s)
+sh_needarg (const char *s)
{
builtin_error (_("%s: option requires an argument"), s);
}
void
-sh_neednumarg (char *s)
+sh_neednumarg (const char *s)
{
builtin_error (_("%s: numeric argument required"), s);
}
void
-sh_notfound (char *s)
+sh_notfound (const char *s)
{
builtin_error (_("%s: not found"), s);
}
/* Function called when one of the builtin commands detects an invalid
option. */
void
-sh_invalidopt (char *s)
+sh_invalidopt (const char *s)
{
builtin_error (_("%s: invalid option"), s);
}
void
-sh_invalidoptname (char *s)
+sh_invalidoptname (const char *s)
{
builtin_error (_("%s: invalid option name"), s);
}
void
-sh_invalidid (char *s)
+sh_invalidid (const char *s)
{
builtin_error (_("`%s': not a valid identifier"), s);
}
void
-sh_invalidnum (char *s)
+sh_invalidnum (const char *s)
{
char *msg;
}
void
-sh_invalidsig (char *s)
+sh_invalidsig (const char *s)
{
builtin_error (_("%s: invalid signal specification"), s);
}
void
-sh_badpid (char *s)
+sh_badpid (const char *s)
{
builtin_error (_("`%s': not a pid or valid job spec"), s);
}
}
void
-sh_erange (char *s, char *desc)
+sh_erange (const char *s, const char *desc)
{
if (s)
builtin_error (_("%s: %s out of range"), s, desc ? desc : _("argument"));
#if defined (JOB_CONTROL)
void
-sh_badjob (char *s)
+sh_badjob (const char *s)
{
builtin_error (_("%s: no such job"), s);
}
void
-sh_nojobs (char *s)
+sh_nojobs (const char *s)
{
if (s)
builtin_error (_("%s: no job control"), s);
#if defined (RESTRICTED_SHELL)
void
-sh_restricted (char *s)
+sh_restricted (const char *s)
{
if (s)
builtin_error (_("%s: restricted"), s);
#endif
void
-sh_notbuiltin (char *s)
+sh_notbuiltin (const char *s)
{
builtin_error (_("%s: not a shell builtin"), s);
}
char *the_current_working_directory = (char *)NULL;
char *
-get_working_directory (char *for_whom)
+get_working_directory (const char *for_whom)
{
if (no_symbolic_links)
{
/* Make NAME our internal idea of the current working directory. */
void
-set_working_directory (char *name)
+set_working_directory (const char *name)
{
FREE (the_current_working_directory);
the_current_working_directory = savestring (name);
}
static int
-shell_builtin_compare (struct builtin *sbp1, struct builtin *sbp2)
+shell_builtin_compare (const struct builtin *sbp1, const struct builtin *sbp2)
{
int result;
extern int no_options (WORD_LIST *);
/* common error message functions */
-extern void sh_needarg (char *);
-extern void sh_neednumarg (char *);
-extern void sh_notfound (char *);
-extern void sh_invalidopt (char *);
-extern void sh_invalidoptname (char *);
-extern void sh_invalidid (char *);
-extern void sh_invalidnum (char *);
-extern void sh_invalidsig (char *);
+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 (char *, char *);
-extern void sh_badpid (char *);
-extern void sh_badjob (char *);
-extern void sh_nojobs (char *);
-extern void sh_restricted (char *);
-extern void sh_notbuiltin (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);
/* Keeps track of the current working directory. */
extern char *the_current_working_directory;
-extern char *get_working_directory (char *);
-extern void set_working_directory (char *);
+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);
/* expr.c -- arithmetic expression evaluation. */
-/* Copyright (C) 1990-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1990-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
static void pushexp (void);
static void popexp (void);
static void expr_unwind (void);
-static void expr_bind_variable (char *, char *);
+static void expr_bind_variable (const char *, const char *);
#if defined (ARRAY_VARS)
-static void expr_bind_array_element (char *, arrayind_t, char *);
+static void expr_bind_array_element (const char *, arrayind_t, const char *);
#endif
-static intmax_t subexpr (char *);
+static intmax_t subexpr (const char *);
static intmax_t expcomma (void);
static intmax_t expassign (void);
}
static void
-expr_bind_variable (char *lhs, char *rhs)
+expr_bind_variable (const char *lhs, const char *rhs)
{
SHELL_VAR *v;
int aflags;
/* Rewrite tok, which is of the form vname[expression], to vname[ind], where
IND is the already-calculated value of expression. */
static void
-expr_bind_array_element (char *tok, arrayind_t ind, char *rhs)
+expr_bind_array_element (const char *tok, arrayind_t ind, const char *rhs)
{
char *lhs, *vname;
size_t llen;
safe to let the loop terminate when expr_depth == 0, without freeing up
any of the expr_depth[0] stuff. */
intmax_t
-evalexp (char *expr, int flags, int *validp)
+evalexp (const char *expr, int flags, int *validp)
{
intmax_t val;
int c;
}
static intmax_t
-subexpr (char *expr)
+subexpr (const char *expr)
{
intmax_t val;
char *p;
- for (p = expr; p && *p && cr_whitespace (*p); p++)
+ for (p = (char *)expr; p && *p && cr_whitespace (*p); p++)
;
if (p == NULL || *p == '\0')
return (tval);
}
-static int
+static inline int
_is_multiop (int c)
{
switch (c)
}
}
-static int
+static inline int
_is_arithop (int c)
{
switch (c)
/* externs.h -- extern function declarations which do not appear in their
own header file. */
-/* Copyright (C) 1993-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
/* Functions from expr.c. */
#define EXP_EXPANDED 0x01
-extern intmax_t evalexp (char *, int, int *);
+extern intmax_t evalexp (const char *, int, int *);
/* Functions from print_cmd.c. */
#define FUNC_MULTILINE 0x01
extern int yyparse (void);
extern int return_EOF (void);
extern void push_token (int);
-extern char *xparse_dolparen (char *, char *, int *, int);
+extern char *xparse_dolparen (const char *, char *, int *, int);
extern COMMAND *parse_string_to_command (char *, int);
extern void reset_parser (void);
extern void reset_readahead_token (void);
/* Declarations for functions defined in locale.c */
extern void set_default_locale (void);
extern void set_default_locale_vars (void);
-extern int set_locale_var (char *, char *);
-extern int set_lang (char *, char *);
+extern int set_locale_var (const char *, const char *);
+extern int set_lang (const char *, const char *);
extern void set_default_lang (void);
-extern char *get_locale_var (char *);
-extern char *localetrans (char *, int, int *);
+extern char *get_locale_var (const char *);
+extern char *localetrans (const char *, int, int *);
extern char *mk_msgstr (char *, int *);
-extern char *locale_expand (char *, int, int, int, int *);
+extern char *locale_expand (const char *, int, int, int, int *);
#ifndef locale_decpoint
extern int locale_decpoint (void);
#endif
extern int find_index_in_alist (char *, STRING_INT_ALIST *, int);
extern char *substring (const char *, int, int);
-extern char *strsub (char *, char *, char *, int);
-extern char *strcreplace (char *, int, const char *, int);
+extern char *strsub (const char *, const char *, const char *, int);
+extern char *strcreplace (const char *, int, const char *, int);
extern void strip_leading (char *);
extern void strip_trailing (char *, int, int);
extern void xbcopy (char *, char *, size_t);
extern STRINGLIST *strlist_resize (STRINGLIST *, int);
extern void strlist_flush (STRINGLIST *);
extern void strlist_dispose (STRINGLIST *);
-extern int strlist_remove (STRINGLIST *, char *);
+extern int strlist_remove (STRINGLIST *, const char *);
extern STRINGLIST *strlist_copy (STRINGLIST *);
extern STRINGLIST *strlist_merge (STRINGLIST *, STRINGLIST *);
extern STRINGLIST *strlist_append (STRINGLIST *, STRINGLIST *);
-extern STRINGLIST *strlist_prefix_suffix (STRINGLIST *, char *, char *);
-extern void strlist_print (STRINGLIST *, char *);
+extern STRINGLIST *strlist_prefix_suffix (STRINGLIST *, const char *, const char *);
+extern void strlist_print (STRINGLIST *, const char *);
extern void strlist_walk (STRINGLIST *, sh_strlist_map_func_t *);
extern void strlist_sort (STRINGLIST *);
extern char **strvec_mresize (char **, int);
extern void strvec_flush (char **);
extern void strvec_dispose (char **);
-extern int strvec_remove (char **, char *);
-extern int strvec_len (char **);
-extern int strvec_search (char **, char *);
-extern char **strvec_copy (char **);
+extern int strvec_remove (char **, const char *);
+extern int strvec_len (char * const *);
+extern int strvec_search (char **, const char *);
+extern char **strvec_copy (char * const *);
extern int strvec_posixcmp (char **, char **);
extern int strvec_strcmp (char **, char **);
extern void strvec_sort (char **, int);
#endif
/* declarations for functions defined in lib/sh/strtrans.c */
-extern char *ansicstr (char *, int, int, int *, int *);
-extern char *ansic_quote (char *, int, int *);
+extern char *ansicstr (const char *, int, int, int *, int *);
+extern char *ansic_quote (const char *, int, int *);
extern int ansic_shouldquote (const char *);
-extern char *ansiexpand (char *, int, int, int *);
+extern char *ansiexpand (const char *, int, int, int *);
/* declarations for functions defined in lib/sh/strvis.c */
extern int sh_charvis (const char *, size_t *, size_t, char *, size_t *);
#define MT_USERANDOM 0x0004
#define MT_TEMPLATE 0x0008
-extern char *sh_mktmpname (char *, int);
-extern int sh_mktmpfd (char *, int, char **);
-/* extern FILE *sh_mktmpfp (char *, int, char **); */
-extern char *sh_mktmpdir (char *, int);
+extern char *sh_mktmpname (const char *, int);
+extern int sh_mktmpfd (const char *, int, char **);
+/* extern FILE *sh_mktmpfp (const char *, int, char **); */
+extern char *sh_mktmpdir (const char *, int);
/* declarations for functions defined in lib/sh/uconvert.c */
-extern int uconvert (char *, long *, long *, char **);
+extern int uconvert (const char *, long *, long *, char **);
/* declarations for functions defined in lib/sh/ufuncs.c */
extern unsigned int falarm (unsigned int, unsigned int);
extern void get_new_window_size (int, int *, int *);
/* declarations for functions defined in lib/sh/zcatfd.c */
-extern int zcatfd (int, int, char *);
+extern int zcatfd (int, int, const char *);
/* declarations for functions defined in lib/sh/zgetline.c */
extern ssize_t zgetline (int, char **, size_t *, int, int);
/* findcmd.c -- Functions to search for commands by name. */
-/* Copyright (C) 1997-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
};
void
-setup_exec_ignore (char *varname)
+setup_exec_ignore (const char *varname)
{
setup_ignore_patterns (&execignore);
}
/* findcmd.h - functions from findcmd.c. */
-/* Copyright (C) 1997-2015,2020-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2015,2020-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
extern char *find_path_file (const char *);
extern char *search_for_command (const char *, int);
extern char *user_command_matches (const char *, int, int);
-extern void setup_exec_ignore (char *);
+extern void setup_exec_ignore (const char *);
extern int dot_found_in_search;
/* general.h -- defines that everybody likes to use. */
-/* Copyright (C) 1993-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
/* Specific function pointer typedefs. Most of these could be done
with #defines. */
-typedef void sh_sv_func_t (char *); /* sh_vcpfunc_t */
+typedef void sh_sv_func_t (const char *);
typedef void sh_free_func_t (PTR_T); /* sh_vptrfunc_t */
typedef void sh_resetsig_func_t (int); /* sh_vintfunc_t */
typedef int sh_ignore_func_t (const char *); /* sh_icpfunc_t */
typedef int sh_assign_func_t (const char *);
-typedef int sh_wassign_func_t (WORD_DESC *, int);
+typedef int sh_wassign_func_t (const WORD_DESC *, int);
typedef int sh_load_func_t (char *);
typedef void sh_unload_func_t (char *);
the inode corresponding to PATH/DIR is identical to THISINO. */
#if !defined (D_FILENO_AVAILABLE)
static int
-_path_checkino (char *dotp, char *name, ino_t thisino)
+_path_checkino (const char *dotp, const char *name, ino_t thisino)
{
char *fullpath;
int r, e;
* The value returned is in network order.
*/
u_long
-inet_addr(register const char *cp)
+inet_addr(const char *cp)
{
struct in_addr val;
* cannot distinguish between failure and a local broadcast address.
*/
int
-inet_aton(register const char *cp, struct in_addr *addr)
+inet_aton(const char *cp, struct in_addr *addr)
{
register u_bits32_t val;
register int base, n;
#endif
#ifndef HAVE_GETADDRINFO
-static int _getaddr (char *, struct in_addr *);
-static int _getserv (char *, int, unsigned short *);
-static int _netopen4 (char *, char *, int);
+static int _getaddr (const char *, struct in_addr *);
+static int _getserv (const char *, int, unsigned short *);
+static int _netopen4 (const char *, const char *, int);
#else /* HAVE_GETADDRINFO */
-static int _netopen6 (char *, char *, int);
+static int _netopen6 (const char *, const char *, int);
#endif
-static int _netopen (char *, char *, int);
+static int _netopen (const char *, const char *, int);
#ifndef HAVE_GETADDRINFO
/* Stuff the internet address corresponding to HOST into AP, in network
byte order. Return 1 on success, 0 on failure. */
static int
-_getaddr (char *host, struct in_addr *ap)
+_getaddr (const char *host, struct in_addr *ap)
{
struct hostent *h;
int r;
/* Return 1 if SERV is a valid port number and stuff the converted value into
PP in network byte order. */
static int
-_getserv (char *serv, int proto, unsigned short *pp)
+_getserv (const char *serv, int proto, unsigned short *pp)
{
intmax_t l;
unsigned short s;
* traditional BSD mechanisms. Returns the connected socket or -1 on error.
*/
static int
-_netopen4(char *host, char *serv, int typ)
+_netopen4(const char *host, const char *serv, int typ)
{
struct in_addr ina;
struct sockaddr_in sin;
* on error.
*/
static int
-_netopen6 (char *host, char *serv, int typ)
+_netopen6 (const char *host, const char *serv, int typ)
{
int s, e;
struct addrinfo hints, *res, *res0;
* Returns the connected socket or -1 on error.
*/
static int
-_netopen(char *host, char *serv, int typ)
+_netopen(const char *host, const char *serv, int typ)
{
#ifdef HAVE_GETADDRINFO
return (_netopen6 (host, serv, typ));
#include <maxpath.h>
#include <stdc.h>
-static int mindist (char *, char *, char *);
+static int mindist (const char *, char *, char *);
static int spdist (char *, char *);
/*
* Search directory for a guess
*/
static int
-mindist(char *dir, char *guess, char *best)
+mindist(const char *dir, char *guess, char *best)
{
DIR *fd;
struct dirent *dp;
}
int
-strlist_remove (STRINGLIST *sl, char *s)
+strlist_remove (STRINGLIST *sl, const char *s)
{
int r;
}
STRINGLIST *
-strlist_prefix_suffix (STRINGLIST *sl, char *prefix, char *suffix)
+strlist_prefix_suffix (STRINGLIST *sl, const char *prefix, const char *suffix)
{
int plen, slen, tlen, llen, i;
char *t;
}
void
-strlist_print (STRINGLIST *sl, char *prefix)
+strlist_print (STRINGLIST *sl, const char *prefix)
{
register int i;
/* Return the length of ARRAY, a NULL terminated array of char *. */
int
-strvec_len (char **array)
+strvec_len (char * const *array)
{
register int i;
}
int
-strvec_remove (char **array, char *name)
+strvec_remove (char **array, const char *name)
{
register int i, j;
char *x;
/* Find NAME in ARRAY. Return the index of NAME, or -1 if not present.
ARRAY should be NULL terminated. */
int
-strvec_search (char **array, char *name)
+strvec_search (char **array, const char *name)
{
int i;
/* Allocate and return a new copy of ARRAY and its contents. */
char **
-strvec_copy (char **array)
+strvec_copy (char * const *array)
{
register int i;
int len;
/* Find the length of S, but scan at most MAXLEN characters. If no '\0'
terminator is found within the first MAXLEN characters, return MAXLEN. */
size_t
-strnlen (register const char *s, size_t maxlen)
+strnlen (const char *s, size_t maxlen)
{
register const char *e;
size_t n;
quote CTLESC and CTLNUL with CTLESC. If (flags&4) is non-zero, we want
to remove the backslash before any unrecognized escape sequence. */
char *
-ansicstr (char *string, int len, int flags, int *sawc, int *rlen)
+ansicstr (const char *string, int len, int flags, int *sawc, int *rlen)
{
int c, temp;
char *ret, *r, *s;
#else
ret = (char *)xmalloc (2*len + 1); /* 2*len for possible CTLESC */
#endif
- for (r = ret, s = string; s && *s; )
+ for (r = ret, s = (char *)string; s && *s; )
{
c = *s++;
if (c != '\\' || *s == '\0')
/* Take a string STR, possibly containing non-printing characters, and turn it
into a $'...' ANSI-C style quoted string. Returns a new string. */
char *
-ansic_quote (char *str, int flags, int *rlen)
+ansic_quote (const char *str, int flags, int *rlen)
{
char *r, *ret, *s;
int l, rsize;
*r++ = '$';
*r++ = '\'';
- for (s = str; c = *s; s++)
+ for (s = (char *)str; c = *s; s++)
{
b = l = 1; /* 1 == add backslash; 0 == no backslash */
clen = 1;
/* $'...' ANSI-C expand the portion of STRING between START and END and
return the result. The result cannot be longer than the input string. */
char *
-ansiexpand (char *string, int start, int end, int *lenp)
+ansiexpand (const char *string, int start, int end, int *lenp)
{
char *temp, *t;
int len, tlen;
}
char *
-sh_mktmpname (char *nameroot, int flags)
+sh_mktmpname (const char *nameroot, int flags)
{
- char *filename, *tdir, *lroot;
+ char *filename, *tdir;
+ const char *lroot;
struct stat sb;
int r, tdlen;
static int seeded = 0;
}
int
-sh_mktmpfd (char *nameroot, int flags, char **namep)
+sh_mktmpfd (const char *nameroot, int flags, char **namep)
{
- char *filename, *tdir, *lroot;
+ char *filename, *tdir;
+ const char *lroot;
int fd, tdlen;
filename = (char *)xmalloc (PATH_MAX + 1);
}
FILE *
-sh_mktmpfp (char *nameroot, int flags, char **namep)
+sh_mktmpfp (const char *nameroot, int flags, char **namep)
{
int fd;
FILE *fp;
}
char *
-sh_mktmpdir (char *nameroot, int flags)
+sh_mktmpdir (const char *nameroot, int flags)
{
- char *filename, *tdir, *lroot, *dirname;
+ char *filename, *tdir, *dirname;
+ const char *lroot;
int fd, tdlen;
#ifdef USE_MKDTEMP
Return 1 if value converted; 0 if invalid integer for either whole or
fractional parts. */
int
-uconvert(char *s, long *ip, long *up, char **ep)
+uconvert(const char *s, long *ip, long *up, char **ep)
{
int n, mult;
long ipart, upart;
if (s && (*s == '-' || *s == '+'))
{
mult = (*s == '-') ? -1 : 1;
- p = s + 1;
+ p = (char *)s + 1;
}
else
- p = s;
+ p = (char *)s;
for ( ; p && *p; p++)
{
/* Dump contents of file descriptor FD to OFD. FN is the filename for
error messages (not used right now). */
int
-zcatfd (int fd, int ofd, char *fn)
+zcatfd (int fd, int ofd, const char *fn)
{
ssize_t nr;
int rval;
/* locale.c - Miscellaneous internationalization functions. */
-/* Copyright (C) 1996-2009,2012,2016-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2009,2012,2016-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
/* Set one of the locale categories (specified by VAR) to VALUE. Returns 1
if successful, 0 otherwise. */
int
-set_locale_var (char *var, char *value)
+set_locale_var (const char *var, const char *value)
{
int r;
char *x;
reset_locale_vars() to reset any default values if LC_ALL is unset or
null. */
int
-set_lang (char *var, char *value)
+set_lang (const char *var, const char *value)
{
FREE (lang);
if (value)
The precedence is as POSIX.2 specifies: LC_ALL has precedence over
the specific locale variables, and LANG, if set, is used as the default. */
char *
-get_locale_var (char *var)
+get_locale_var (const char *var)
{
char *locale;
is not available, the passed string is returned unchanged. The
length of the translated string is returned in LENP, if non-null. */
char *
-localetrans (char *string, int len, int *lenp)
+localetrans (const char *string, int len, int *lenp)
{
char *locale, *t;
char *translated;
if (default_domain && *default_domain)
translated = dgettext (default_domain, string);
else
- translated = string;
+ translated = (char *)string;
if (translated == string) /* gettext returns its argument if untranslatable */
{
by the caller. The length of the translated string is returned in LENP,
if non-null. */
char *
-locale_expand (char *string, int start, int end, int lineno, int *lenp)
+locale_expand (const char *string, int start, int end, int lineno, int *lenp)
{
int len, tlen, foundnl;
char *temp, *t, *t2;
/* mailcheck.c -- The check is in the mail... */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
static int find_mail_file (const char *);
static void init_mail_file (int);
static void update_mail_file (int);
-static int add_mail_file (char *, char *);
+static int add_mail_file (char *, const char *);
-static FILEINFO *alloc_mail_file (char *, char *);
+static FILEINFO *alloc_mail_file (char *, const char *);
static void dispose_mail_file (FILEINFO *);
static int file_mod_date_changed (int);
/* Add this file to the list of remembered files and return its index
in the list of mail files. */
static int
-add_mail_file (char *file, char *msg)
+add_mail_file (char *file, const char *msg)
{
struct stat finfo;
char *filename;
}
static FILEINFO *
-alloc_mail_file (char *filename, char *msg)
+alloc_mail_file (char *filename, const char *msg)
{
FILEINFO *mf;
called by the word expansion code and so does not have to reset as much
parser state before calling yyparse(). */
char *
-xparse_dolparen (char *base, char *string, int *indp, int flags)
+xparse_dolparen (const char *base, char *string, int *indp, int flags)
{
sh_parser_state_t ps;
sh_input_line_state_t ls;
/* pathexp.c -- The shell interface to the globbing library. */
-/* Copyright (C) 1995-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
has changed. If GLOBIGNORE is being unset, we also need to disable
the globbing of filenames beginning with a `.'. */
void
-setup_glob_ignore (char *name)
+setup_glob_ignore (const char *name)
{
char *v;
/* pathexp.h -- The shell interface to the globbing library. */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
extern void setup_ignore_patterns (struct ignorevar *);
-extern void setup_glob_ignore (char *);
+extern void setup_glob_ignore (const char *);
extern int should_ignore_glob_matches (void);
extern void ignore_glob_matches (char **);
/* pcomplete.c - functions to generate lists of matches for programmable completion. */
-/* Copyright (C) 1999-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1999-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
static int it_init_shopts (ITEMLIST *);
static int shouldexp_filterpat (char *);
-static char *preproc_filterpat (char *, const char *);
+static char *preproc_filterpat (const char *, const char *);
static void init_itemlist_from_varlist (ITEMLIST *, SVFUNC *);
#endif
static void bind_compfunc_variables (char *, int, WORD_LIST *, int, int);
static void unbind_compfunc_variables (int);
-static WORD_LIST *build_arg_list (char *, const char *, const char *, WORD_LIST *, int);
+static WORD_LIST *build_arg_list (const char *, const char *, const char *, WORD_LIST *, int);
static WORD_LIST *command_line_to_word_list (char *, int, int, int *, int *);
static int compgen_compspec = 0; /* are we generating completions for compgen? */
quote a `&' and inhibit substitution. Returns a new string. This just
calls stringlib.c:strcreplace(). */
static char *
-preproc_filterpat (char *pat, const char *text)
+preproc_filterpat (const char *pat, const char *text)
{
char *ret;
make do with the COMP_LINE and COMP_POINT variables. */
static WORD_LIST *
-build_arg_list (char *cmd, const char *cname, const char *text, WORD_LIST *lwords, int ind)
+build_arg_list (const char *cmd, const char *cname, const char *text, WORD_LIST *lwords, int ind)
{
WORD_LIST *ret, *cl, *l;
WORD_DESC *w;
/* pcomplete.h - structure definitions and other stuff for programmable
completion. */
-/* Copyright (C) 1999-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1999-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
static int do_redirection_internal (REDIRECT *, int, char **);
static char *heredoc_expand (WORD_DESC *, enum r_instruction, size_t *);
-static int heredoc_write (int, char *, size_t);
+static int heredoc_write (int, const char *, size_t);
static int here_document_to_fd (WORD_DESC *, enum r_instruction);
static int redir_special_open (int, char *, int, int, enum r_instruction);
-static int noclobber_open (char *, int, int, enum r_instruction);
+static int noclobber_open (const char *, int, int, enum r_instruction);
static int redir_open (char *, int, int, enum r_instruction);
static int redir_varassign (REDIRECT *, int);
/* Write HEREDOC (of length HDLEN) to FD, returning 0 on success and ERRNO on
error. Don't handle interrupts. */
static int
-heredoc_write (int fd, char *heredoc, size_t herelen)
+heredoc_write (int fd, const char *heredoc, size_t herelen)
{
ssize_t nw;
int e;
race conditions and avoiding the problem where the file is replaced
between the stat(2) and open(2). */
static int
-noclobber_open (char *filename, int flags, int mode, enum r_instruction ri)
+noclobber_open (const char *filename, int flags, int mode, enum r_instruction ri)
{
int r, fd;
struct stat finfo, finfo2;
/* stringlib.c - Miscellaneous string functions. */
-/* Copyright (C) 1996-2009,2022 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2009,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
replace all occurrences, otherwise replace only the first.
This returns a new string; the caller should free it. */
char *
-strsub (char *string, char *pat, char *rep, int global)
+strsub (const char *string, const char *pat, const char *rep, int global)
{
size_t patlen, replen, templen, tempsize, i;
int repl;
if (replen)
RESIZE_MALLOCED_BUFFER (temp, templen, replen, tempsize, (replen * 2));
- for (r = rep; *r; ) /* can rep == "" */
+#if 0
+ for (r = (char *)rep; *r; ) /* can rep == "" */
temp[templen++] = *r++;
+#else
+ memcpy (temp + templen, rep, replen);
+ templen += replen;
+#endif
i += patlen ? patlen : 1; /* avoid infinite recursion */
repl = global != 0;
globbing. Backslash may be used to quote C. If (FLAGS & 2) we allow
backslash to escape backslash as well. */
char *
-strcreplace (char *string, int c, const char *text, int flags)
+strcreplace (const char *string, int c, const char *text, int flags)
{
- char *ret, *p, *r, *t;
+ char *ret, *r, *p, *t;
size_t len, rlen, ind, tlen;
int do_glob, escape_backslash;
rlen = len + strlen (string) + 2;
ret = (char *)xmalloc (rlen);
- for (p = string, r = ret; p && *p; )
+ for (p = (char *)string, r = ret; p && *p; )
{
if (*p == c)
{
/* ``Have a little faith, there's magic in the night. You ain't a
beauty, but, hey, you're alright.'' */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
/* An expansion function that takes a string and a quoted flag and returns
a WORD_LIST *. Used as the type of the third argument to
expand_string_if_necessary(). */
-typedef WORD_LIST *EXPFUNC (char *, int);
+typedef WORD_LIST *EXPFUNC (const char *, int);
/* Process ID of the last command executed within command substitution. */
pid_t last_command_subst_pid = NO_PID;
static char *expand_string_if_necessary (char *, int, EXPFUNC *);
static inline char *expand_string_to_string_internal (char *, int, EXPFUNC *);
static WORD_LIST *call_expand_word_internal (WORD_DESC *, int, int, int *, int *);
-static WORD_LIST *expand_string_internal (char *, int);
-static WORD_LIST *expand_string_leave_quoted (char *, int);
-static WORD_LIST *expand_string_for_rhs (char *, int, int, int, int *, int *);
-static WORD_LIST *expand_string_for_pat (char *, int, int *, int *);
+static WORD_LIST *expand_string_internal (const char *, int);
+static WORD_LIST *expand_string_leave_quoted (const char *, int);
+static WORD_LIST *expand_string_for_rhs (const char *, int, int, int, int *, int *);
+static WORD_LIST *expand_string_for_pat (const char *, int, int *, int *);
static char *quote_escapes_internal (const char *, int);
static char *make_quoted_char (int);
static WORD_LIST *quote_list (WORD_LIST *);
-static int unquoted_substring (char *, char *);
-static int unquoted_member (int, char *);
+static int unquoted_substring (const char *, const char *);
+static int unquoted_member (int, const char *);
#if defined (ARRAY_VARS)
-static SHELL_VAR *do_compound_assignment (char *, char *, int);
+static SHELL_VAR *do_compound_assignment (const char *, char *, int);
#endif
static int do_assignment_internal (const WORD_DESC *, int);
-static char *string_extract_verbatim (char *, size_t, int *, char *, int);
-static char *string_extract (char *, int *, char *, int);
-static char *string_extract_double_quoted (char *, int *, int);
-static inline char *string_extract_single_quoted (char *, int *, int);
+static char *string_extract_verbatim (const char *, size_t, int *, char *, int);
+static char *string_extract (const char *, int *, const char *, int);
+static char *string_extract_double_quoted (const char *, int *, int);
+static inline char *string_extract_single_quoted (const char *, int *, int);
static inline int skip_single_quoted (const char *, size_t, int, int);
-static int skip_double_quoted (char *, size_t, int, int);
-static char *extract_delimited_string (char *, int *, char *, char *, char *, int);
-static char *extract_heredoc_dolbrace_string (char *, int *, int, int);
-static char *extract_dollar_brace_string (char *, int *, int, int);
+static int skip_double_quoted (const char *, size_t, int, int);
+static char *extract_delimited_string (const char *, int *, char *, char *, char *, int);
+static char *extract_heredoc_dolbrace_string (const char *, int *, int, int);
+static char *extract_dollar_brace_string (const char *, int *, int, int);
static int skip_matched_pair (const char *, int, int, int, int);
-static char *pos_params (char *, int, int, int, int);
+static char *pos_params (const char *, int, int, int, int);
-static unsigned char *mb_getcharlens (char *, int);
+static unsigned char *mb_getcharlens (const char *, int);
static char *remove_upattern (char *, char *, int);
#if defined (HANDLE_MULTIBYTE)
static int match_wpattern (wchar_t *, char **, size_t, wchar_t *, int, char **, char **);
#endif
static int match_pattern (char *, char *, int, char **, char **);
-static int getpatspec (int, char *);
+static int getpatspec (int, const char *);
static char *getpattern (char *, int, int);
static char *variable_remove_pattern (char *, char *, int, int);
static char *list_remove_pattern (WORD_LIST *, char *, int, int, int);
static char *array_transform (int, SHELL_VAR *, int, int);
#endif
static char *parameter_brace_transform (char *, char *, array_eltstate_t *, char *, int, int, int, int);
-static int valid_parameter_transform (char *);
+static int valid_parameter_transform (const char *);
static char *process_substitute (char *, int);
static char *read_comsub (int, int, int, int *);
#ifdef ARRAY_VARS
-static arrayind_t array_length_reference (char *);
+static arrayind_t array_length_reference (const char *);
#endif
-static int valid_brace_expansion_word (char *, int);
-static int chk_atstar (char *, int, int, int *, int *);
+static int valid_brace_expansion_word (const char *, int);
+static int chk_atstar (const char *, int, int, int *, int *);
static int chk_arithsub (const char *, int);
static WORD_DESC *parameter_brace_expand_word (char *, int, int, int, array_eltstate_t *);
static WORD_DESC *parameter_brace_expand_rhs (char *, char *, int, int, int, int *, int *);
static void parameter_brace_expand_error (char *, char *, int);
-static int valid_length_expression (char *);
+static int valid_length_expression (const char *);
static intmax_t parameter_brace_expand_length (char *);
static char *skiparith (char *, int);
static int verify_substring_values (SHELL_VAR *, char *, char *, int, intmax_t *, intmax_t *);
static int get_var_and_type (char *, char *, array_eltstate_t *, int, int, SHELL_VAR **, char **);
-static char *mb_substring (char *, int, int);
+static char *mb_subfstring (const char *, int, int);
static char *parameter_brace_substring (char *, char *, array_eltstate_t *, char *, int, int, int);
-static int shouldexp_replacement (char *);
+static int shouldexp_replacement (const char *);
static char *pos_params_pat_subst (char *, char *, char *, int);
/* Return 1 if CHARACTER appears in an unquoted portion of
STRING. Return 0 otherwise. CHARACTER must be a single-byte character. */
static int
-unquoted_member (int character, char *string)
+unquoted_member (int character, const char *string)
{
size_t slen;
int sindex, c;
/* Return 1 if SUBSTR appears in an unquoted portion of STRING. */
static int
-unquoted_substring (char *substr, char *string)
+unquoted_substring (const char *substr, const char *string)
{
size_t slen;
int sindex, c, sublen;
update SINDEX. If (flags & SX_REQMATCH) is non-zero, the string must
contain a closing character from CHARLIST. */
static char *
-string_extract (char *string, int *sindex, char *charlist, int flags)
+string_extract (const char *string, int *sindex, const char *charlist, int flags)
{
register int c, i;
int found;
Backslashes between the embedded double quotes are processed. If STRIPDQ
is zero, an unquoted `"' terminates the string. */
static char *
-string_extract_double_quoted (char *string, int *sindex, int flags)
+string_extract_double_quoted (const char *string, int *sindex, int flags)
{
size_t slen;
- char *send;
+ const char *send;
int j, i, t;
unsigned char c;
char *temp, *ret; /* The new string we return. */
if (ret == 0 && no_longjmp_on_fatal_error)
{
free_ret = 0;
- ret = string + i + 2;
+ ret = (char *)string + i + 2;
}
/* XXX - CHECK_STRING_OVERRUN here? */
/* This should really be another option to string_extract_double_quoted. */
static int
-skip_double_quoted (char *string, size_t slen, int sind, int flags)
+skip_double_quoted (const char *string, size_t slen, int sind, int flags)
{
int c, i;
char *ret;
the closing single quote. ALLOWESC allows the single quote to be quoted by
a backslash; it's not used yet. */
static inline char *
-string_extract_single_quoted (char *string, int *sindex, int allowesc)
+string_extract_single_quoted (const char *string, int *sindex, int allowesc)
{
register int i;
size_t slen;
/* Just like string_extract, but doesn't hack backslashes or any of
that other stuff. Obeys CTLESC quoting. Used to do splitting on $IFS. */
static char *
-string_extract_verbatim (char *string, size_t slen, int *sindex, char *charlist, int flags)
+string_extract_verbatim (const char *string, size_t slen, int *sindex, char *charlist, int flags)
{
register int i;
#if defined (HANDLE_MULTIBYTE)
*sindex */
if (*charlist == 0)
{
- temp = string + *sindex;
- c = (*sindex == 0) ? slen : STRLEN (temp);
- temp = savestring (temp);
+ const char *xtemp;
+ xtemp = string + *sindex;
+ c = (*sindex == 0) ? slen : STRLEN (xtemp);
+ temp = savestring (xtemp);
*sindex += c;
return temp;
}
Make (SINDEX) get the position of the matching ")". )
XFLAGS is additional flags to pass to other extraction functions. */
char *
-extract_command_subst (char *string, int *sindex, int xflags)
+extract_command_subst (const char *string, int *sindex, int xflags)
{
char *ret;
+ char *xstr;
if (string[*sindex] == LPAREN || (xflags & SX_COMPLETE))
return (extract_delimited_string (string, sindex, "$(", "(", ")", xflags|SX_COMMAND)); /*)*/
else
{
xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0);
- ret = xparse_dolparen (string, string+*sindex, sindex, xflags);
+ xstr = (char *)string + *sindex;
+ ret = xparse_dolparen (string, xstr, sindex, xflags);
return ret;
}
}
Start extracting at (SINDEX) as if we had just seen "$[".
Make (SINDEX) get the position of the matching "]". */
char *
-extract_arithmetic_subst (char *string, int *sindex)
+extract_arithmetic_subst (const char *string, int *sindex)
{
return (extract_delimited_string (string, sindex, "$[", "[", "]", 0)); /*]*/
}
Start extracting at (SINDEX) as if we had just seen "<(".
Make (SINDEX) get the position of the matching ")". */ /*))*/
char *
-extract_process_subst (char *string, char *starter, int *sindex, int xflags)
+extract_process_subst (const char *string, char *starter, int *sindex, int xflags)
{
#if 0
/* XXX - check xflags&SX_COMPLETE here? */
return (extract_delimited_string (string, sindex, starter, "(", ")", SX_COMMAND));
#else
+ char *xstr;
+
xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0);
- return (xparse_dolparen (string, string+*sindex, sindex, xflags));
+ xstr = (char *)string + *sindex;
+ return (xparse_dolparen (string, xstr, sindex, xflags));
#endif
}
#endif /* PROCESS_SUBSTITUTION */
each caller verifies that the last character in STRING is a right paren,
we don't even need to call extract_delimited_string. */
char *
-extract_array_assignment_list (char *string, int *sindex)
+extract_array_assignment_list (const char *string, int *sindex)
{
int slen;
char *ret;
contains a character string that can also match CLOSER and thus
needs to be skipped. */
static char *
-extract_delimited_string (char *string, int *sindex, char *opener, char *alt_opener, char *closer, int flags)
+extract_delimited_string (const char *string, int *sindex, char *opener, char *alt_opener, char *closer, int flags)
{
int i, c, si;
size_t slen;
This needs to match the logic in parse.y:parse_matched_pair so we get
consistent behavior between here-documents and double-quoted strings. */
static char *
-extract_heredoc_dolbrace_string (char *string, int *sindex, int quoted, int flags)
+extract_heredoc_dolbrace_string (const char *string, int *sindex, int quoted, int flags)
{
register int i, c;
size_t slen, tlen, result_index, result_size;
int pass_character, nesting_level, si, dolbrace_state;
- char *result, *t, *send;
+ char *result, *t;
+ const char *send;
DECLARE_MBSTATE;
pass_character = 0;
occurs inside double quotes. */
/* XXX -- this is very similar to extract_delimited_string -- XXX */
static char *
-extract_dollar_brace_string (char *string, int *sindex, int quoted, int flags)
+extract_dollar_brace_string (const char *string, int *sindex, int quoted, int flags)
{
register int i, c;
size_t slen;
a lot of shell syntax. It's very similar to skip_double_quoted and other
functions of that ilk. */
int
-skip_to_delim (char *string, int start, char *delims, int flags)
+skip_to_delim (const char *string, int start, const char *delims, int flags)
{
int i, pass_next, backq, dquote, si, c, oldjmp;
int invert, skipquote, skipcmd, noprocsub, completeflag;
down version of skip_to_delims. The essential difference is that this
resets the quoting state when starting a command substitution */
int
-skip_to_histexp (char *string, int start, char *delims, int flags)
+skip_to_histexp (const char *string, int start, const char *delims, int flags)
{
int i, pass_next, backq, dquote, c, oldjmp;
int histexp_comsub, histexp_backq, old_dquote;
the index of the word containing SENTINEL. Non-whitespace chars in
DELIMS delimit separate fields. This is used by programmable completion. */
WORD_LIST *
-split_at_delims (char *string, int slen, const char *delims, int sentinel, int flags, int *nwp, int *cwp)
+split_at_delims (const char *string, int slen, const char *delims, int sentinel, int flags, int *nwp, int *cwp)
{
int ts, te, i, nw, cw, ifs_split, dflags;
char *token, *d, *d2;
/* UNUSED */
/* Extract the name of the variable to bind to from the assignment string. */
char *
-assignment_name (char *string)
+assignment_name (const char *string)
{
int offset;
char *temp;
#if defined (ARRAY_VARS)
static SHELL_VAR *
-do_compound_assignment (char *name, char *value, int flags)
+do_compound_assignment (const char *name, char *value, int flags)
{
SHELL_VAR *v;
int mklocal, mkassoc, mkglobal, chklocal;
return (v); /* XXX */
}
/* sanity check */
- newname = (v == 0) ? nameref_transform_name (name, flags) : name;
+ newname = (v == 0) ? nameref_transform_name (name, flags) : (char *)name;
list = expand_compound_array_assignment (v, value, flags);
if (v == 0 && mkassoc)
v = make_new_assoc_variable (newname);
}
int
-do_word_assignment (WORD_DESC *word, int flags)
+do_word_assignment (const WORD_DESC *word, int flags)
{
return do_assignment_internal (word, 1);
}
Q_HERE_DOCUMENT or Q_DOUBLE_QUOTES, this returns a quoted list, otherwise
no quoting chars are added. */
static char *
-pos_params (char *string, int start, int end, int quoted, int pflags)
+pos_params (const char *string, int start, int end, int quoted, int pflags)
{
WORD_LIST *save, *params, *h, *t;
char *ret;
or a backslash into a backslash. The output of this function must eventually
be processed by strcreplace(). */
static char *
-quote_string_for_repl (char *string, int flags)
+quote_string_for_repl (const char *string, int flags)
{
size_t slen;
char *result, *t;
#if defined (COND_COMMAND)
/* Just remove backslashes in STRING. Returns a new string. */
char *
-remove_backslashes (char *string)
+remove_backslashes (const char *string)
{
- char *r, *ret, *s;
+ char *r, *ret;
+ const char *s;
r = ret = (char *)xmalloc (strlen (string) + 1);
for (s = string; s && *s; )
FLAGS argument is 1 if this function should treat CTLESC as a quote
character (e.g., for here-documents) or not (e.g., for shell_expand_line). */
char *
-expand_string_dollar_quote (char *string, int flags)
+expand_string_dollar_quote (const char *string, int flags)
{
size_t slen, retind, retsize;
int sindex, c, translen, peekc, news;
- char *ret, *trans, *send, *t;
+ char *ret, *trans, *t;
+ const char *send;
DECLARE_MBSTATE;
slen = strlen (string);
Since this does not perform word splitting, it leaves quoted nulls
in the result. */
static WORD_LIST *
-expand_string_internal (char *string, int quoted)
+expand_string_internal (const char *string, int quoted)
{
WORD_DESC td;
WORD_LIST *tresult;
remove_quoted_nulls () is in here because word splitting normally
takes care of quote removal. */
WORD_LIST *
-expand_string_unsplit (char *string, int quoted)
+expand_string_unsplit (const char *string, int quoted)
{
WORD_LIST *value;
/* Expand the rhs of an assignment statement */
WORD_LIST *
-expand_string_assignment (char *string, int quoted)
+expand_string_assignment (const char *string, int quoted)
{
WORD_DESC td;
WORD_LIST *value;
passed string when an error occurs. Might want to trap other calls
to jump_to_top_level here so we don't endlessly loop. */
WORD_LIST *
-expand_prompt_string (char *string, int quoted, int wflags)
+expand_prompt_string (const char *string, int quoted, int wflags)
{
WORD_LIST *value;
WORD_DESC td;
things like ${1+"$@"}. This does parameter expansion, command
substitution, arithmetic expansion, and word splitting. */
static WORD_LIST *
-expand_string_leave_quoted (char *string, int quoted)
+expand_string_leave_quoted (const char *string, int quoted)
{
WORD_LIST *tlist;
WORD_LIST *tresult;
/* This does not perform word splitting or dequote the WORD_LIST
it returns. */
static WORD_LIST *
-expand_string_for_rhs (char *string, int quoted, int op, int pflags, int *dollar_at_p, int *expanded_p)
+expand_string_for_rhs (const char *string, int quoted, int op, int pflags, int *dollar_at_p, int *expanded_p)
{
WORD_DESC td;
WORD_LIST *tresult;
/* This does not perform word splitting or dequote the WORD_LIST
it returns and it treats $* as if it were quoted. */
static WORD_LIST *
-expand_string_for_pat (char *string, int quoted, int *dollar_at_p, int *expanded_p)
+expand_string_for_pat (const char *string, int quoted, int *dollar_at_p, int *expanded_p)
{
WORD_DESC td;
WORD_LIST *tresult;
does parameter expansion, command substitution, arithmetic expansion,
and word splitting. Dequote the resultant WORD_LIST before returning. */
WORD_LIST *
-expand_string (char *string, int quoted)
+expand_string (const char *string, int quoted)
{
WORD_LIST *result;
static WORD_LIST *
list_quote_escapes (WORD_LIST *list)
{
- register WORD_LIST *w;
+ WORD_LIST *w;
char *t;
for (w = list; w; w = w->next)
the W_HASQUOTEDNULL flag needs to be set in any resultant WORD_DESC where
this value is the word. */
char *
-quote_string (char *string)
+quote_string (const char *string)
{
register char *t;
size_t slen;
- char *result, *send;
+ char *result;
+ const char *send;
if (*string == 0)
{
/* De-quote quoted characters in STRING. */
char *
-dequote_string (char *string)
+dequote_string (const char *string)
{
register char *s, *t;
size_t slen;
- char *result, *send;
+ char *result;
+ const char *send;
DECLARE_MBSTATE;
if (string[0] == CTLESC && string[1] == 0)
return (strcpy (result, string));
send = string + slen;
- s = string;
+ s = (char *)string;
while (*s)
{
if (*s == CTLESC)
static WORD_LIST *
quote_list (WORD_LIST *list)
{
- register WORD_LIST *w;
+ WORD_LIST *w;
char *t;
for (w = list; w; w = w->next)
WORD_DESC *
dequote_word (WORD_DESC *word)
{
- register char *s;
+ char *s;
s = dequote_string (word->word);
if (QUOTED_NULL (word->word))
WORD_LIST *
dequote_list (WORD_LIST *list)
{
- register char *s;
- register WORD_LIST *tlist;
+ char *s;
+ WORD_LIST *tlist;
for (tlist = list; tlist; tlist = tlist->next)
{
added to protect them from word splitting, but we need to remove them
if no word splitting takes place. This returns newly-allocated memory,
so callers can use it to replace savestring(). */
-char *
-remove_quoted_ifs (char *string)
+static char *
+remove_quoted_ifs (const char *string)
{
register size_t slen;
register int i, j;
- char *ret, *send;
+ char *ret;
+ const char *send;
DECLARE_MBSTATE;
slen = strlen (string);
#if defined (HANDLE_MULTIBYTE)
# ifdef INCLUDE_UNUSED
static unsigned char *
-mb_getcharlens (char *string, int len)
+mb_getcharlens (const char *string, int len)
{
int i, offset, last;
unsigned char *ret;
static char *
remove_upattern (char *param, char *pattern, int op)
{
- register size_t len;
- register char *end;
- register char *p, *ret, c;
+ size_t len;
+ char *end, *p;
+ char *ret, c;
len = STRLEN (param);
end = param + len;
}
static int
-getpatspec (int c, char *value)
+getpatspec (int c, const char *value)
{
if (c == '#')
return ((*value == '#') ? RP_LONG_LEFT : RP_SHORT_LEFT);
#if defined (ARRAY_VARS)
static arrayind_t
-array_length_reference (char *s)
+array_length_reference (const char *s)
{
int len;
arrayind_t ind;
#endif /* ARRAY_VARS */
static int
-valid_brace_expansion_word (char *name, int var_is_special)
+valid_brace_expansion_word (const char *name, int var_is_special)
{
if (DIGIT (*name) && all_digits (name))
return 1;
}
static int
-chk_atstar (char *name, int quoted, int pflags, int *quoted_dollar_atp, int *contains_dollar_at)
+chk_atstar (const char *name, int quoted, int pflags, int *quoted_dollar_atp, int *contains_dollar_at)
{
char *temp1;
/* Return 1 if NAME is something for which parameter_brace_expand_length is
OK to do. */
static int
-valid_length_expression (char *name)
+valid_length_expression (const char *name)
{
return (name[1] == '\0' || /* ${#} */
((sh_syntaxtab[(unsigned char) name[1]] & CSPECVAR) && name[2] == '\0') || /* special param */
#endif /* ARRAY_VARS */
static inline int
-valid_parameter_transform (char *xform)
+valid_parameter_transform (const char *xform)
{
if (xform[1])
return 0;
multibyte character) positions that require calculation.
Used by the ${param:offset[:length]} expansion. */
static char *
-mb_substring (char *string, int s, int e)
+mb_substring (const char *string, int s, int e)
{
char *tt;
int start, stop, i;
/****************************************************************/
static int
-shouldexp_replacement (char *s)
+shouldexp_replacement (const char *s)
{
size_t slen;
int sindex, c;
/* Run an array subscript through the appropriate word expansions. */
char *
-expand_subscript_string (char *string, int quoted)
+expand_subscript_string (const char *string, int quoted)
{
WORD_DESC td;
WORD_LIST *tlist;
only expand it once, we quote the characters that would start another
expansion and the bracket characters that are special to array subscripts. */
static char *
-expand_array_subscript (char *string, int *sindex, int quoted, int flags)
+expand_array_subscript (const char *string, int *sindex, int quoted, int flags)
{
char *ret, *exp, *t;
size_t slen;
/* Perform quote removal on STRING. If QUOTED > 0, assume we are obeying the
backslash quoting rules for within double quotes or a here document. */
char *
-string_quote_removal (char *string, int quoted)
+string_quote_removal (const char *string, int quoted)
{
size_t slen;
- char *r, *result_string, *temp, *send;
+ char *r, *result_string, *temp;
+ const char *send;
int sindex, tindex, dquote;
unsigned char c;
DECLARE_MBSTATE;
/* subst.h -- Names of externally visible functions in subst.c. */
-/* Copyright (C) 1993-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Start extracting at (SINDEX) as if we had just seen "$(".
Make (SINDEX) get the position just after the matching ")".
XFLAGS is additional flags to pass to other extraction functions, */
-extern char *extract_command_subst (char *, int *, int);
+extern char *extract_command_subst (const char *, int *, int);
/* Extract the $[ construct in STRING, and return a new string.
Start extracting at (SINDEX) as if we had just seen "$[".
Make (SINDEX) get the position just after the matching "]". */
-extern char *extract_arithmetic_subst (char *, int *);
+extern char *extract_arithmetic_subst (const char *, int *);
#if defined (PROCESS_SUBSTITUTION)
/* Extract the <( or >( construct in STRING, and return a new string.
Start extracting at (SINDEX) as if we had just seen "<(".
Make (SINDEX) get the position just after the matching ")". */
-extern char *extract_process_subst (char *, char *, int *, int);
+extern char *extract_process_subst (const char *, char *, int *, int);
#endif /* PROCESS_SUBSTITUTION */
/* Extract the name of the variable to bind to from the assignment string. */
-extern char *assignment_name (char *);
+extern char *assignment_name (const char *);
/* Return a single string of all the words present in LIST, separating
each word with SEP. */
splitting on the result of expansion. */
extern int do_assignment (char *);
extern int do_assignment_no_expand (char *);
-extern int do_word_assignment (WORD_DESC *, int);
+extern int do_word_assignment (const WORD_DESC *, int);
/* Append SOURCE to TARGET at INDEX. SIZE is the current amount
of space allocated to TARGET. SOURCE can be NULL, in which
returning it, but do not perform word splitting. The call to
remove_quoted_nulls () is made here because word splitting normally
takes care of quote removal. */
-extern WORD_LIST *expand_string_unsplit (char *, int);
+extern WORD_LIST *expand_string_unsplit (const char *, int);
/* Expand the rhs of an assignment statement. */
-extern WORD_LIST *expand_string_assignment (char *, int);
+extern WORD_LIST *expand_string_assignment (const char *, int);
/* Expand a prompt string. */
-extern WORD_LIST *expand_prompt_string (char *, int, int);
+extern WORD_LIST *expand_prompt_string (const char *, int, int);
/* Expand STRING just as if you were expanding a word. This also returns
a list of words. Note that filename globbing is *NOT* done for word
or string expansion, just when the shell is expanding a command. This
does parameter expansion, command substitution, arithmetic expansion,
and word splitting. Dequote the resultant WORD_LIST before returning. */
-extern WORD_LIST *expand_string (char *, int);
+extern WORD_LIST *expand_string (const char *, int);
/* Convenience functions that expand strings to strings, taking care of
converting the WORD_LIST * returned by the expand_string* functions
extern char *expand_string_to_string (char *, int);
extern char *expand_string_unsplit_to_string (char *, int);
extern char *expand_assignment_string_to_string (char *, int);
-extern char *expand_subscript_string (char *, int);
+extern char *expand_subscript_string (const char *, int);
/* Expand an arithmetic expression string */
extern char *expand_arith_string (char *, int);
/* Expand $'...' and $"..." in a string for code paths that do not. */
-extern char *expand_string_dollar_quote (char *, int);
+extern char *expand_string_dollar_quote (const char *, int);
/* De-quote quoted characters in STRING. */
-extern char *dequote_string (char *);
+extern char *dequote_string (const char *);
/* De-quote CTLESC-escaped CTLESC or CTLNUL characters in STRING. */
extern char *dequote_escapes (const char *);
extern char *get_dollar_var_value (intmax_t);
/* Quote a string to protect it from word splitting. */
-extern char *quote_string (char *);
+extern char *quote_string (const char *);
/* Quote escape characters (characters special to internals of expansion)
in a string. */
/* Perform quote removal on STRING. If QUOTED > 0, assume we are obeying the
backslash quoting rules for within double quotes. */
-extern char *string_quote_removal (char *, int);
+extern char *string_quote_removal (const char *, int);
/* Perform quote removal on word WORD. This allocates and returns a new
WORD_DESC *. */
extern WORD_LIST *list_string_with_quotes (char *);
#if defined (ARRAY_VARS)
-extern char *extract_array_assignment_list (char *, int *);
+extern char *extract_array_assignment_list (const char *, int *);
#endif
#if defined (COND_COMMAND)
-extern char *remove_backslashes (char *);
+extern char *remove_backslashes (const char *);
extern char *cond_expand_word (WORD_DESC *, int);
#endif
#define SD_ARITHEXP 0x400 /* skip_to_delim during arithmetic expansion */
#define SD_NOERROR 0x800 /* don't print error messages */
-extern int skip_to_delim (char *, int, char *, int);
+extern int skip_to_delim (const char *, int, const char *, int);
#if defined (BANG_HISTORY)
-extern int skip_to_histexp (char *, int, char *, int);
+extern int skip_to_histexp (const char *, int, const char *, int);
#endif
#if defined (READLINE)
extern int char_is_quoted (char *, int);
extern int unclosed_pair (char *, int, char *);
-extern WORD_LIST *split_at_delims (char *, int, const char *, int, int, int *, int *);
+extern WORD_LIST *split_at_delims (const char *, int, const char *, int, int, int *, int *);
#endif
/* Variables used to keep track of the characters in IFS. */
/* Modified to run with the GNU shell Apr 25, 1988 by bfox. */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
static int and (void);
static int or (void);
-static int filecomp (char *, char *, int);
+static int filecomp (const char *, const char *, int);
static int arithcomp (char *, char *, int, int);
static int patcomp (char *, char *, int);
}
static int
-stat_mtime (char *fn, struct stat *st, struct timespec *ts)
+stat_mtime (const char *fn, struct stat *st, struct timespec *ts)
{
int r;
}
static int
-filecomp (char *s, char *t, int op)
+filecomp (const char *s, const char *t, int op)
{
struct stat st1, st2;
struct timespec ts1, ts2;
/* trap.c -- Not the trap command, but useful functions for manipulating
those objects. The trap command is in builtins/trap.def. */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
static void reset_or_restore_signal_handlers (sh_resetsig_func_t *);
static void reinit_trap (int);
-static void trap_if_untrapped (int, char *);
+static void trap_if_untrapped (int, const char *);
/* Variables used here but defined in other files. */
then (int)2 is returned. Return NO_SIG if STRING doesn't
contain a valid signal descriptor. */
int
-decode_signal (char *string, int flags)
+decode_signal (const char *string, int flags)
{
intmax_t sig;
char *name;
#ifdef INCLUDE_UNUSED
/* Make COMMAND_STRING be executed when SIGCHLD is caught. */
void
-set_sigchld_trap (char *command_string)
+set_sigchld_trap (const char *command_string)
{
set_signal (SIGCHLD, command_string);
}
reset the disposition to the default and not have the original signal
accidentally restored, undoing the user's command. */
void
-maybe_set_sigchld_trap (char *command_string)
+maybe_set_sigchld_trap (const char *command_string)
{
if ((sigmodes[SIGCHLD] & SIG_TRAPPED) == 0 && trap_list[SIGCHLD] == (char *)IMPOSSIBLE_TRAP_HANDLER)
set_signal (SIGCHLD, command_string);
/* Set a trap for SIG only if SIG is not already trapped. */
static inline void
-trap_if_untrapped (int sig, char *command)
+trap_if_untrapped (int sig, const char *command)
{
if ((sigmodes[sig] & SIG_TRAPPED) == 0)
set_signal (sig, command);
}
void
-set_debug_trap (char *command)
+set_debug_trap (const char *command)
{
set_signal (DEBUG_TRAP, command);
}
SIG_TRAPPED will be set and we don't bother restoring the original trap string.
This is used by both functions and the source builtin. */
void
-maybe_set_debug_trap (char *command)
+maybe_set_debug_trap (const char *command)
{
trap_if_untrapped (DEBUG_TRAP, command);
}
void
-set_error_trap (char *command)
+set_error_trap (const char *command)
{
set_signal (ERROR_TRAP, command);
}
void
-maybe_set_error_trap (char *command)
+maybe_set_error_trap (const char *command)
{
trap_if_untrapped (ERROR_TRAP, command);
}
void
-set_return_trap (char *command)
+set_return_trap (const char *command)
{
set_signal (RETURN_TRAP, command);
}
void
-maybe_set_return_trap (char *command)
+maybe_set_return_trap (const char *command)
{
trap_if_untrapped (RETURN_TRAP, command);
}
#ifdef INCLUDE_UNUSED
void
-set_sigint_trap (char *command)
+set_sigint_trap (const char *command)
{
set_signal (SIGINT, command);
}
/* Set SIG to call STRING as a command. */
void
-set_signal (int sig, char *string)
+set_signal (int sig, const char *string)
{
sigset_t set, oset;
/* trap.h -- data structures used in the trap mechanism. */
-/* Copyright (C) 1993-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
extern void run_pending_traps (void);
extern void queue_sigchld_trap (int);
-extern void maybe_set_sigchld_trap (char *);
+extern void maybe_set_sigchld_trap (const char *);
extern void set_impossible_sigchld_trap (void);
-extern void set_sigchld_trap (char *);
+extern void set_sigchld_trap (const char *);
-extern void set_debug_trap (char *);
-extern void set_error_trap (char *);
-extern void set_return_trap (char *);
+extern void set_debug_trap (const char *);
+extern void set_error_trap (const char *);
+extern void set_return_trap (const char *);
-extern void maybe_set_debug_trap (char *);
-extern void maybe_set_error_trap (char *);
-extern void maybe_set_return_trap (char *);
+extern void maybe_set_debug_trap (const char *);
+extern void maybe_set_error_trap (const char *);
+extern void maybe_set_return_trap (const char *);
-extern void set_sigint_trap (char *);
-extern void set_signal (int, char *);
+extern void set_sigint_trap (const char *);
+extern void set_signal (int, const char *);
extern void restore_default_signal (int);
extern void ignore_signal (int);
extern char *signal_name (int);
-extern int decode_signal (char *, int);
+extern int decode_signal (const char *, int);
extern void run_interrupt_trap (int);
extern int maybe_call_trap_handler (int);
extern int signal_is_special (int);
/* variables.c -- Functions for hacking shell variables. */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
# endif
static SHELL_VAR *build_hashcmd (SHELL_VAR *);
static SHELL_VAR *get_hashcmd (SHELL_VAR *);
-static SHELL_VAR *assign_hashcmd (SHELL_VAR *, char *, arrayind_t, char *);
+static SHELL_VAR *assign_hashcmd (SHELL_VAR *, char *, arrayind_t, char *);
# if defined (ALIAS)
static SHELL_VAR *build_aliasvar (SHELL_VAR *);
static SHELL_VAR *get_aliasvar (SHELL_VAR *);
-static SHELL_VAR *assign_aliasvar (SHELL_VAR *, char *, arrayind_t, char *);
+static SHELL_VAR *assign_aliasvar (SHELL_VAR *, char *, arrayind_t, char *);
# endif
#endif
static void initialize_dynamic_variables (void);
-static SHELL_VAR *bind_invalid_envvar (const char *, char *, int);
+static SHELL_VAR *bind_invalid_envvar (const char *, const char *, int);
static int var_sametype (SHELL_VAR *, SHELL_VAR *);
static SHELL_VAR *hash_lookup (const char *, HASH_TABLE *);
static SHELL_VAR *new_shell_variable (const char *);
static SHELL_VAR *make_new_variable (const char *, HASH_TABLE *);
-static SHELL_VAR *bind_variable_internal (const char *, char *, HASH_TABLE *, int, int);
+static SHELL_VAR *bind_variable_internal (const char *, const char *, HASH_TABLE *, int, int);
static void dispose_variable_value (SHELL_VAR *);
static void free_variable_hash_data (PTR_T);
static SHELL_VAR *find_variable_nameref_context (SHELL_VAR *, VAR_CONTEXT *, VAR_CONTEXT **);
static SHELL_VAR *find_variable_last_nameref_context (SHELL_VAR *, VAR_CONTEXT *, VAR_CONTEXT **);
-static SHELL_VAR *bind_tempenv_variable (const char *, char *);
+static SHELL_VAR *bind_tempenv_variable (const char *, const char *);
static void push_posix_temp_var (PTR_T);
static void push_temp_var (PTR_T);
static void propagate_temp_var (PTR_T);
function, but dealing strictly with names. This takes assignment flags
so it can deal with the various assignment modes used by `declare'. */
char *
-nameref_transform_name (char *name, int flags)
+nameref_transform_name (const char *name, int flags)
{
SHELL_VAR *v;
char *newname;
: find_global_variable_last_nameref (name, 1);
if (v && nameref_p (v) && valid_nameref_value (nameref_cell (v), 1))
return nameref_cell (v);
- return name;
+ return (char *)name;
}
/* Find a variable, forcing a search of the temporary environment first */
/* Set NAME to VALUE if NAME has no value. */
SHELL_VAR *
-set_if_not (char *name, char *value)
+set_if_not (const char *name, const char *value)
{
SHELL_VAR *v;
#if defined (ARRAY_VARS)
SHELL_VAR *
-make_new_array_variable (char *name)
+make_new_array_variable (const char *name)
{
SHELL_VAR *entry;
ARRAY *array;
}
SHELL_VAR *
-make_local_array_variable (char *name, int flags)
+make_local_array_variable (const char *name, int flags)
{
SHELL_VAR *var;
ARRAY *array;
}
SHELL_VAR *
-make_new_assoc_variable (char *name)
+make_new_assoc_variable (const char *name)
{
SHELL_VAR *entry;
HASH_TABLE *hash;
}
SHELL_VAR *
-make_local_assoc_variable (char *name, int flags)
+make_local_assoc_variable (const char *name, int flags)
{
SHELL_VAR *var;
HASH_TABLE *hash;
#endif
char *
-make_variable_value (SHELL_VAR *var, char *value, int flags)
+make_variable_value (SHELL_VAR *var, const char *value, int flags)
{
char *retval, *oval;
intmax_t lval, rval;
/* If we can optimize appending to string variables, say so */
static int
-can_optimize_assignment (SHELL_VAR *entry, char *value, int aflags)
+can_optimize_assignment (SHELL_VAR *entry, const char *value, int aflags)
{
if ((aflags & ASS_APPEND) == 0)
return 0;
/* right now we optimize appends to string variables */
static SHELL_VAR *
-optimized_assignment (SHELL_VAR *entry, char *value, int aflags)
+optimized_assignment (SHELL_VAR *entry, const char *value, int aflags)
{
size_t len, vlen;
char *v, *new;
temporary environment (but usually is not). HFLAGS controls how NAME
is looked up in TABLE; AFLAGS controls how VALUE is assigned */
static SHELL_VAR *
-bind_variable_internal (const char *name, char *value, HASH_TABLE *table, int hflags, int aflags)
+bind_variable_internal (const char *name, const char *value, HASH_TABLE *table, int hflags, int aflags)
{
char *newval, *tname;
SHELL_VAR *entry, *tentry;
}
INVALIDATE_EXPORTSTR (entry);
- newval = (aflags & ASS_APPEND) ? make_variable_value (entry, value, aflags) : value;
+ newval = (aflags & ASS_APPEND) ? make_variable_value (entry, value, aflags) : (char *)value;
if (assoc_p (entry))
entry = (*(entry->assign_func)) (entry, newval, -1, savestring ("0"));
else if (array_p (entry))
first, then we bind into shell_variables. */
SHELL_VAR *
-bind_variable (const char *name, char *value, int flags)
+bind_variable (const char *name, const char *value, int flags)
{
SHELL_VAR *v, *nv;
VAR_CONTEXT *vc, *nvc;
}
SHELL_VAR *
-bind_global_variable (const char *name, char *value, int flags)
+bind_global_variable (const char *name, const char *value, int flags)
{
if (shell_variables == 0)
create_variable_tables ();
}
static SHELL_VAR *
-bind_invalid_envvar (const char *name, char *value, int aflags)
+bind_invalid_envvar (const char *name, const char *value, int aflags)
{
if (invalid_env == 0)
invalid_env = hash_create (64); /* XXX */
variable we set here, then turn it back on after binding as necessary. */
SHELL_VAR *
-bind_int_variable (char *lhs, char *rhs, int flags)
+bind_int_variable (const char *lhs, const char *rhs, int flags)
{
register SHELL_VAR *v;
int isint, isarr, implicitarray, vflags, avflags;
}
SHELL_VAR *
-bind_var_to_int (char *var, intmax_t val, int flags)
+bind_var_to_int (const char *var, intmax_t val, int flags)
{
char ibuf[INT_STRLEN_BOUND (intmax_t) + 1], *p;
responsible for moving the main temporary env to one of the other
temporary environments. The expansion code in subst.c calls this. */
int
-assign_in_env (WORD_DESC *word, int flags)
+assign_in_env (const WORD_DESC *word, int flags)
{
int offset, aflags;
char *name, *temp, *value, *newname;
/* Make variable NAME have VALUE in the temporary environment. */
static SHELL_VAR *
-bind_tempenv_variable (const char *name, char *value)
+bind_tempenv_variable (const char *name, const char *value)
{
SHELL_VAR *var;
/* The variable in NAME has just had its state changed. Check to see if it
is one of the special ones where something special happens. */
void
-stupidly_hack_special_variables (char *name)
+stupidly_hack_special_variables (const char *name)
{
static int sv_sorted = 0;
int i;
i = find_special_var (name);
if (i != -1)
- (*(special_vars[i].function)) (name);
+ (*(special_vars[i].function)) ((char *)name);
}
/* Special variables that need hooks to be run when they are unset as part
}
void
-sv_ifs (char *name)
+sv_ifs (const char *name)
{
SHELL_VAR *v;
/* What to do just after the PATH variable has changed. */
void
-sv_path (char *name)
+sv_path (const char *name)
{
/* hash -r */
phash_flush ();
is the name of the variable. This is called with NAME set to one of
MAIL, MAILCHECK, or MAILPATH. */
void
-sv_mail (char *name)
+sv_mail (const char *name)
{
/* If the time interval for checking the files has changed, then
reset the mail timer. Otherwise, one of the pathname vars
}
void
-sv_funcnest (char *name)
+sv_funcnest (const char *name)
{
SHELL_VAR *v;
intmax_t num;
/* What to do when EXECIGNORE changes. */
void
-sv_execignore (char *name)
+sv_execignore (const char *name)
{
setup_exec_ignore (name);
}
/* What to do when GLOBIGNORE changes. */
void
-sv_globignore (char *name)
+sv_globignore (const char *name)
{
if (privileged_mode == 0)
setup_glob_ignore (name);
#if defined (READLINE)
void
-sv_comp_wordbreaks (char *name)
+sv_comp_wordbreaks (const char *name)
{
SHELL_VAR *sv;
If we are an interactive shell, then try to reset the terminal
information in readline. */
void
-sv_terminal (char *name)
+sv_terminal (const char *name)
{
if (interactive_shell && no_line_editing == 0)
rl_reset_terminal (get_string_value ("TERM"));
}
void
-sv_hostfile (char *name)
+sv_hostfile (const char *name)
{
SHELL_VAR *v;
found in the initial environment) to override the terminal size reported by
the kernel. */
void
-sv_winsize (char *name)
+sv_winsize (const char *name)
{
SHELL_VAR *v;
intmax_t xd;
/* Update the value of HOME in the export environment so tilde expansion will
work on cygwin. */
#if defined (__CYGWIN__)
-sv_home (char *name)
+sv_home (const char *name)
{
array_needs_making = 1;
maybe_make_export_env ();
numeric, truncate the history file to hold no more than that many
lines. */
void
-sv_histsize (char *name)
+sv_histsize (const char *name)
{
char *temp;
intmax_t num;
/* What to do after the HISTIGNORE variable changes. */
void
-sv_histignore (char *name)
+sv_histignore (const char *name)
{
setup_history_ignore (name);
}
/* What to do after the HISTCONTROL variable changes. */
void
-sv_history_control (char *name)
+sv_history_control (const char *name)
{
char *temp;
char *val;
#if defined (BANG_HISTORY)
/* Setting/unsetting of the history expansion character. */
void
-sv_histchars (char *name)
+sv_histchars (const char *name)
{
char *temp;
#endif /* BANG_HISTORY */
void
-sv_histtimefmt (char *name)
+sv_histtimefmt (const char *name)
{
SHELL_VAR *v;
#if defined (HAVE_TZSET)
void
-sv_tz (char *name)
+sv_tz (const char *name)
{
SHELL_VAR *v;
of times we actually ignore the EOF. The default is small,
(smaller than csh, anyway). */
void
-sv_ignoreeof (char *name)
+sv_ignoreeof (const char *name)
{
SHELL_VAR *tmp_var;
char *temp;
}
void
-sv_optind (char *name)
+sv_optind (const char *name)
{
SHELL_VAR *var;
char *tt;
}
void
-sv_opterr (char *name)
+sv_opterr (const char *name)
{
char *tt;
}
void
-sv_strict_posix (char *name)
+sv_strict_posix (const char *name)
{
SHELL_VAR *var;
}
void
-sv_locale (char *name)
+sv_locale (const char *name)
{
char *v;
int r;
}
void
-sv_xtracefd (char *name)
+sv_xtracefd (const char *name)
{
SHELL_VAR *v;
char *t, *e;
#define MIN_COMPAT_LEVEL 31
void
-sv_shcompat (char *name)
+sv_shcompat (const char *name)
{
SHELL_VAR *v;
char *val;
#if defined (JOB_CONTROL)
void
-sv_childmax (char *name)
+sv_childmax (const char *name)
{
char *tt;
int s;
/* variables.h -- data structures for shell variables. */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
extern int validate_inherited_value (SHELL_VAR *, int);
-extern SHELL_VAR *set_if_not (char *, char *);
+extern SHELL_VAR *set_if_not (const char *, const char *);
extern void sh_set_lines_and_columns (int, int);
extern void set_pwd (void);
extern SHELL_VAR *find_tempenv_variable (const char *);
extern SHELL_VAR *find_variable_no_invisible (const char *);
extern SHELL_VAR *find_variable_for_assignment (const char *);
-extern char *nameref_transform_name (char *, int);
+extern char *nameref_transform_name (const char *, int);
extern SHELL_VAR *copy_variable (SHELL_VAR *);
extern SHELL_VAR *make_local_variable (const char *, int);
-extern SHELL_VAR *bind_variable (const char *, char *, int);
-extern SHELL_VAR *bind_global_variable (const char *, char *, int);
+extern SHELL_VAR *bind_variable (const char *, const char *, int);
+extern SHELL_VAR *bind_global_variable (const char *, const char *, int);
extern SHELL_VAR *bind_function (const char *, COMMAND *);
extern void bind_function_def (const char *, FUNCTION_DEF *, int);
extern char *get_variable_value (SHELL_VAR *);
extern char *get_string_value (const char *);
extern char *sh_get_env_value (const char *);
-extern char *make_variable_value (SHELL_VAR *, char *, int);
+extern char *make_variable_value (SHELL_VAR *, const char *, int);
extern SHELL_VAR *bind_variable_value (SHELL_VAR *, char *, int);
-extern SHELL_VAR *bind_int_variable (char *, char *, int);
-extern SHELL_VAR *bind_var_to_int (char *, intmax_t, int);
+extern SHELL_VAR *bind_int_variable (const char *, const char *, int);
+extern SHELL_VAR *bind_var_to_int (const char *, intmax_t, int);
-extern int assign_in_env (WORD_DESC *, int);
+extern int assign_in_env (const WORD_DESC *, int);
extern int unbind_variable (const char *);
extern int check_unbind_variable (const char *);
extern void print_var_function (SHELL_VAR *);
#if defined (ARRAY_VARS)
-extern SHELL_VAR *make_new_array_variable (char *);
-extern SHELL_VAR *make_local_array_variable (char *, int);
+extern SHELL_VAR *make_new_array_variable (const char *);
+extern SHELL_VAR *make_local_array_variable (const char *, int);
-extern SHELL_VAR *make_new_assoc_variable (char *);
-extern SHELL_VAR *make_local_assoc_variable (char *, int);
+extern SHELL_VAR *make_new_assoc_variable (const char *);
+extern SHELL_VAR *make_local_assoc_variable (const char *, int);
extern void set_pipestatus_array (int *, int);
extern ARRAY *save_pipestatus_array (void);
/* The variable in NAME has just had its state changed. Check to see if it
is one of the special ones where something special happens. */
-extern void stupidly_hack_special_variables (char *);
+extern void stupidly_hack_special_variables (const char *);
/* Reinitialize some special variables that have external effects upon unset
when the shell reinitializes itself. */
/* The `special variable' functions that get called when a particular
variable is set. */
-extern void sv_ifs (char *);
-extern void sv_path (char *);
-extern void sv_mail (char *);
-extern void sv_funcnest (char *);
-extern void sv_execignore (char *);
-extern void sv_globignore (char *);
-extern void sv_ignoreeof (char *);
-extern void sv_strict_posix (char *);
-extern void sv_optind (char *);
-extern void sv_opterr (char *);
-extern void sv_locale (char *);
-extern void sv_xtracefd (char *);
-extern void sv_shcompat (char *);
+extern void sv_ifs (const char *);
+extern void sv_path (const char *);
+extern void sv_mail (const char *);
+extern void sv_funcnest (const char *);
+extern void sv_execignore (const char *);
+extern void sv_globignore (const char *);
+extern void sv_ignoreeof (const char *);
+extern void sv_strict_posix (const char *);
+extern void sv_optind (const char *);
+extern void sv_opterr (const char *);
+extern void sv_locale (const char *);
+extern void sv_xtracefd (const char *);
+extern void sv_shcompat (const char *);
#if defined (READLINE)
-extern void sv_comp_wordbreaks (char *);
-extern void sv_terminal (char *);
-extern void sv_hostfile (char *);
-extern void sv_winsize (char *);
+extern void sv_comp_wordbreaks (const char *);
+extern void sv_terminal (const char *);
+extern void sv_hostfile (const char *);
+extern void sv_winsize (const char *);
#endif
#if defined (__CYGWIN__)
-extern void sv_home (char *);
+extern void sv_home (const char *);
#endif
#if defined (HISTORY)
-extern void sv_histsize (char *);
-extern void sv_histignore (char *);
-extern void sv_history_control (char *);
+extern void sv_histsize (const char *);
+extern void sv_histignore (const char *);
+extern void sv_history_control (const char *);
# if defined (BANG_HISTORY)
-extern void sv_histchars (char *);
+extern void sv_histchars (const char *);
# endif
-extern void sv_histtimefmt (char *);
+extern void sv_histtimefmt (const char *);
#endif /* HISTORY */
#if defined (HAVE_TZSET)
-extern void sv_tz (char *);
+extern void sv_tz (const char *);
#endif
#if defined (JOB_CONTROL)
-extern void sv_childmax (char *);
+extern void sv_childmax (const char *);
#endif
#endif /* !_VARIABLES_H_ */