Bash  5.0-beta2
Bash - Bourne Again shell
variables.c File Reference
#include "config.h"
#include "bashtypes.h"
#include "posixstat.h"
#include "posixtime.h"
#include <stdio.h>
#include "chartypes.h"
#include "bashansi.h"
#include "bashintl.h"
#include "shell.h"
#include "parser.h"
#include "flags.h"
#include "execute_cmd.h"
#include "findcmd.h"
#include "mailcheck.h"
#include "input.h"
#include "hashcmd.h"
#include "pathexp.h"
#include "alias.h"
#include "jobs.h"
#include "version.h"
#include "builtins/getopt.h"
#include "builtins/common.h"
#include "builtins/builtext.h"
#include <tilde/tilde.h>

Go to the source code of this file.

Data Structures

struct  saved_dollar_vars
 
struct  name_and_function
 

Macros

#define NEED_XTRACE_SET_DECL
 
#define VARIABLES_HASH_BUCKETS   1024 /* must be power of two */
 
#define FUNCTIONS_HASH_BUCKETS   512
 
#define TEMPENV_HASH_BUCKETS   4 /* must be power of two */
 
#define BASHFUNC_PREFIX   "BASH_FUNC_"
 
#define BASHFUNC_PREFLEN   10 /* == strlen(BASHFUNC_PREFIX */
 
#define BASHFUNC_SUFFIX   "%%"
 
#define BASHFUNC_SUFFLEN   2 /* == strlen(BASHFUNC_SUFFIX) */
 
#define FV_FORCETEMPENV   0x01
 
#define FV_SKIPINVISIBLE   0x02
 
#define INIT_DYNAMIC_VAR(var, val, gfunc, afunc)
 
#define INIT_DYNAMIC_ARRAY_VAR(var, gfunc, afunc)
 
#define INIT_DYNAMIC_ASSOC_VAR(var, gfunc, afunc)
 
#define FIND_OR_MAKE_VARIABLE(name, entry)
 
#define USE_EXPORTSTR   (value == var->exportstr)
 
#define add_to_export_env(envstr, do_alloc)
 
#define SET_INT_VAR(name, intvar)   intvar = find_variable (name) != 0
 
#define N_SPECIAL_VARS   (sizeof (special_vars) / sizeof (special_vars[0]) - 1)
 
#define MIN_COMPAT_LEVEL   31
 

Functions

static void create_variable_tables __P ((void))
 
static SHELL_VAR *null_assign __P ((SHELL_VAR *, char *, arrayind_t, char *))
 
static SHELL_VAR *get_self __P ((SHELL_VAR *))
 
static void sbrand __P ((unsigned long))
 
static SHELL_VAR *bind_invalid_envvar __P ((const char *, char *, int))
 
static int var_sametype __P ((SHELL_VAR *, SHELL_VAR *))
 
static SHELL_VAR *hash_lookup __P ((const char *, HASH_TABLE *))
 
static SHELL_VAR *new_shell_variable __P ((const char *))
 
static SHELL_VAR *bind_variable_internal __P ((const char *, char *, HASH_TABLE *, int, int))
 
static void free_variable_hash_data __P ((char *))
 
static VARLIST *vlist_alloc __P ((int))
 
static VARLIST *vlist_realloc __P ((VARLIST *, int))
 
static void vlist_add __P ((VARLIST *, SHELL_VAR *, int))
 
static void flatten __P ((HASH_TABLE *, sh_var_map_func_t *, VARLIST *, int))
 
static int qsort_var_comp __P ((SHELL_VAR **, SHELL_VAR **))
 
static SHELL_VAR **vapply __P ((sh_var_map_func_t *))
 
static SHELL_VAR *find_variable_internal __P ((const char *, int))
 
static SHELL_VAR *find_nameref_at_context __P ((SHELL_VAR *, VAR_CONTEXT *))
 
static SHELL_VAR *find_variable_nameref_context __P ((SHELL_VAR *, VAR_CONTEXT *, VAR_CONTEXT **))
 
static SHELL_VAR *bind_tempenv_variable __P ((const char *, char *))
 
static void dispose_temporary_env __P ((sh_free_func_t *))
 
static char *mk_env_string __P ((const char *, const char *, int))
 
static char **make_env_array_from_var_list __P ((SHELL_VAR **))
 
static char **make_var_export_array __P ((VAR_CONTEXT *))
 
static void add_temp_array_to_env __P ((char **, int, int))
 
static void push_posix_tempvar_internal __P ((SHELL_VAR *, int))
 
static void create_variable_tables ()
 
void initialize_shell_variables (char **env, int privmode)
 
static void set_machine_vars ()
 
char * sh_get_home_dir ()
 
static void set_home_var ()
 
static void set_shell_var ()
 
static char * get_bash_name ()
 
void adjust_shell_level (int change)
 
static void initialize_shell_level ()
 
void set_pwd ()
 
void set_ppid ()
 
static void uidset ()
 
void sh_set_lines_and_columns (int lines, int cols)
 
void print_var_list (SHELL_VAR **list)
 
void print_func_list (SHELL_VAR **list)
 
void print_assignment (SHELL_VAR *var)
 
void print_var_value (SHELL_VAR *var, int quote)
 
void print_var_function (SHELL_VAR *var)
 
static SHELL_VARnull_assign (SHELL_VAR *self, char *value, arrayind_t unused, char *key)
 
static SHELL_VARget_self (SHELL_VAR *self)
 
static SHELL_VARassign_seconds (SHELL_VAR *self, char *value, arrayind_t unused, char *key)
 
static SHELL_VARget_seconds (SHELL_VAR *var)
 
static SHELL_VARinit_seconds_var ()
 
static int brand ()
 
static void sbrand (unsigned long seed)
 
static void seedrand ()
 
static SHELL_VARassign_random (SHELL_VAR *self, char *value, arrayind_t unused, char *key)
 
int get_random_number ()
 
static SHELL_VARget_random (SHELL_VAR *var)
 
static SHELL_VARassign_lineno (SHELL_VAR *var, char *value, arrayind_t unused, char *key)
 
static SHELL_VARget_lineno (SHELL_VAR *var)
 
static SHELL_VARassign_subshell (SHELL_VAR *var, char *value, arrayind_t unused, char *key)
 
static SHELL_VARget_subshell (SHELL_VAR *var)
 
static SHELL_VARget_epochseconds (SHELL_VAR *var)
 
static SHELL_VARget_epochrealtime (SHELL_VAR *var)
 
static SHELL_VARget_bashpid (SHELL_VAR *var)
 
static SHELL_VARget_bash_argv0 (SHELL_VAR *var)
 
static SHELL_VARassign_bash_argv0 (SHELL_VAR *var, char *value, arrayind_t unused, char *key)
 
static SHELL_VARget_bash_command (SHELL_VAR *var)
 
static SHELL_VARget_funcname (SHELL_VAR *self)
 
void make_funcname_visible (int on_or_off)
 
static SHELL_VARinit_funcname_var ()
 
static void initialize_dynamic_variables ()
 
static SHELL_VARhash_lookup (char *name, HASH_TABLE *hashed_vars) const
 
SHELL_VARvar_lookup (char *name, VAR_CONTEXT *vcontext) const
 
SHELL_VARfind_variable_internal (char *name, int flags) const
 
SHELL_VARfind_variable_nameref (SHELL_VAR *v)
 
SHELL_VARfind_variable_last_nameref (char *name, int vflags) const
 
SHELL_VARfind_global_variable_last_nameref (char *name, int vflags) const
 
static SHELL_VARfind_nameref_at_context (SHELL_VAR *v, VAR_CONTEXT *vc)
 
static SHELL_VARfind_variable_nameref_context (SHELL_VAR *v, VAR_CONTEXT *vc, VAR_CONTEXT **nvcp)
 
static SHELL_VARfind_variable_last_nameref_context (SHELL_VAR *v, VAR_CONTEXT *vc, VAR_CONTEXT **nvcp)
 
SHELL_VARfind_variable_nameref_for_create (char *name, int flags) const
 
SHELL_VARfind_variable_nameref_for_assignment (char *name, int flags) const
 
char * nameref_transform_name (char *name, int flags)
 
SHELL_VARfind_variable_tempenv (char *name) const
 
SHELL_VARfind_variable_notempenv (char *name) const
 
SHELL_VARfind_global_variable (char *name) const
 
SHELL_VARfind_global_variable_noref (char *name) const
 
SHELL_VARfind_shell_variable (char *name) const
 
SHELL_VARfind_variable (char *name) const
 
SHELL_VARfind_variable_no_invisible (char *name) const
 
SHELL_VARfind_variable_for_assignment (char *name) const
 
SHELL_VARfind_variable_noref (char *name) const
 
SHELL_VARfind_function (char *name) const
 
FUNCTION_DEFfind_function_def (char *name) const
 
char * get_variable_value (SHELL_VAR *var)
 
char * get_string_value (char *var_name) const
 
char * sh_get_env_value (char *v) const
 
static int var_sametype (SHELL_VAR *v1, SHELL_VAR *v2)
 
int validate_inherited_value (SHELL_VAR *var, int type)
 
SHELL_VARset_if_not (char *name, char *value)
 
SHELL_VARmake_local_variable (char *name, int flags) const
 
static SHELL_VARnew_shell_variable (char *name) const
 
static SHELL_VARmake_new_variable (char *name, HASH_TABLE *table) const
 
char * make_variable_value (SHELL_VAR *var, char *value, int flags)
 
static int can_optimize_assignment (SHELL_VAR *entry, char *value, int aflags)
 
static SHELL_VARoptimized_assignment (SHELL_VAR *entry, char *value, int aflags)
 
static SHELL_VARbind_variable_internal (char *name, char *value, HASH_TABLE *table, int hflags, int aflags) const
 
SHELL_VARbind_variable (char *name, char *value, int flags) const
 
SHELL_VARbind_global_variable (char *name, char *value, int flags) const
 
static SHELL_VARbind_invalid_envvar (char *name, char *value, int flags) const
 
SHELL_VARbind_variable_value (SHELL_VAR *var, char *value, int aflags)
 
SHELL_VARbind_int_variable (char *lhs, char *rhs, int flags)
 
SHELL_VARbind_var_to_int (char *var, intmax_t val)
 
SHELL_VARbind_function (char *name, COMMAND *value) const
 
int assign_in_env (WORD_DESC *word, int flags)
 
static void dispose_variable_value (SHELL_VAR *var)
 
void dispose_variable (SHELL_VAR *var)
 
int unbind_variable (char *name) const
 
int unbind_nameref (char *name) const
 
int unbind_variable_noref (char *name) const
 
int check_unbind_variable (char *name) const
 
int unbind_func (char *name) const
 
int delete_var (char *name, VAR_CONTEXT *vc) const
 
int makunbound (char *name, VAR_CONTEXT *vc) const
 
void kill_all_local_variables ()
 
static void free_variable_hash_data (char *data)
 
void delete_all_variables (HASH_TABLE *hashed_vars)
 
void set_var_read_only (char *name)
 
static VARLISTvlist_alloc (int nentries)
 
static VARLISTvlist_realloc (VARLIST *vlist, int n)
 
static void vlist_add (VARLIST *vlist, SHELL_VAR *var, int flags)
 
SHELL_VAR ** map_over (sh_var_map_func_t *function, VAR_CONTEXT *vc)
 
SHELL_VAR ** map_over_funcs (sh_var_map_func_t *function)
 
static void flatten (HASH_TABLE *var_hash_table, sh_var_map_func_t *func, VARLIST *vlist, int flags)
 
void sort_variables (SHELL_VAR **array)
 
static int qsort_var_comp (SHELL_VAR **var1, SHELL_VAR **var2)
 
static SHELL_VAR ** vapply (sh_var_map_func_t *func)
 
static SHELL_VAR ** fapply (sh_var_map_func_t *func)
 
SHELL_VAR ** all_shell_variables ()
 
SHELL_VAR ** all_shell_functions ()
 
static int visible_var (SHELL_VAR *var)
 
SHELL_VAR ** all_visible_functions ()
 
SHELL_VAR ** all_visible_variables ()
 
static int visible_and_exported (SHELL_VAR *var)
 
static int export_environment_candidate (SHELL_VAR *var)
 
static int local_and_exported (SHELL_VAR *var)
 
SHELL_VAR ** all_exported_variables ()
 
SHELL_VAR ** local_exported_variables ()
 
static int variable_in_context (SHELL_VAR *var)
 
SHELL_VAR ** all_local_variables ()
 
char ** all_variables_matching_prefix (char *prefix) const
 
static SHELL_VARbind_tempenv_variable (char *name, char *value) const
 
SHELL_VARfind_tempenv_variable (char *name) const
 
static void push_posix_temp_var (char *data)
 
static void push_temp_var (char *data)
 
static void propagate_temp_var (char *data)
 
static void dispose_temporary_env (sh_free_func_t *pushf)
 
void dispose_used_env_vars ()
 
void merge_temporary_env ()
 
void flush_temporary_env ()
 
static char * mk_env_string (char *name, char *value, int isfunc) const
 
static char ** make_env_array_from_var_list (SHELL_VAR **vars)
 
static char ** make_var_export_array (VAR_CONTEXT *vcxt)
 
static char ** make_func_export_array ()
 
char ** add_or_supercede_exported_var (char *assign, int do_alloc)
 
static void add_temp_array_to_env (char **temp_array, int do_alloc, int do_supercede)
 
static int n_shell_variables ()
 
int chkexport (char *name)
 
void maybe_make_export_env ()
 
void update_export_env_inplace (char *env_prefix, int preflen, char *value)
 
void put_command_name_into_env (char *command_name)
 
VAR_CONTEXTnew_var_context (char *name, int flags)
 
void dispose_var_context (VAR_CONTEXT *vc)
 
static int set_context (SHELL_VAR *var)
 
VAR_CONTEXTpush_var_context (char *name, int flags, HASH_TABLE *tempvars)
 
static void push_posix_tempvar_internal (SHELL_VAR *var, int isbltin)
 
static void push_func_var (char *data)
 
static void push_builtin_var (char *data)
 
void pop_var_context ()
 
void delete_all_contexts (VAR_CONTEXT *vcxt)
 
VAR_CONTEXTpush_scope (int flags, HASH_TABLE *tmpvars)
 
static void push_exported_var (char *data)
 
void pop_scope (int is_special)
 
static char ** save_dollar_vars ()
 
static void restore_dollar_vars (char **args)
 
static void free_dollar_vars ()
 
static void free_saved_dollar_vars (char **args)
 
void push_context (char *name, int is_subshell, HASH_TABLE *tempvars)
 
void pop_context ()
 
void push_dollar_vars ()
 
void pop_dollar_vars ()
 
void dispose_saved_dollar_vars ()
 
void init_bash_argv ()
 
void save_bash_argv ()
 
void push_args (WORD_LIST *list)
 
void pop_args ()
 
static int sv_compare (struct name_and_function *sv1, struct name_and_function *sv2)
 
static int find_special_var (char *name) const
 
void stupidly_hack_special_variables (char *name)
 
void reinit_special_variables ()
 
void sv_ifs (char *name)
 
void sv_path (char *name)
 
void sv_mail (char *name)
 
void sv_funcnest (char *name)
 
void sv_execignore (char *name)
 
void sv_globignore (char *name)
 
void sv_ignoreeof (char *name)
 
void sv_optind (char *name)
 
void sv_opterr (char *name)
 
void sv_strict_posix (char *name)
 
void sv_locale (char *name)
 
void set_pipestatus_from_exit (int s)
 
void sv_xtracefd (char *name)
 
void sv_shcompat (char *name)
 

Variables

char ** environ
 
time_t shell_start_time
 
VAR_CONTEXTglobal_variables = (VAR_CONTEXT *) 0x0
 
VAR_CONTEXTshell_variables = (VAR_CONTEXT *) 0x0
 
HASH_TABLEshell_functions = (HASH_TABLE *) 0x0
 
HASH_TABLEinvalid_env = (HASH_TABLE *) 0x0
 
int variable_context = 0
 
int localvar_inherit = 0
 
int localvar_unset = 0
 
HASH_TABLEtemporary_env = (HASH_TABLE *) 0x0
 
int tempenv_assign_error
 
char * dollar_vars [10]
 
WORD_LISTrest_of_args = (WORD_LIST *) 0x0
 
pid_t dollar_dollar_pid
 
int array_needs_making = 1
 
int shell_level = 0
 
char ** export_env = (char **) 0x0
 
static int export_env_index
 
static int export_env_size
 
SHELL_VAR nameref_invalid_value
 
static SHELL_VAR nameref_maxloop_value
 
static HASH_TABLElast_table_searched
 
static intmax_t seconds_value_assigned
 
static unsigned long rseed = 1
 
static int last_random_value
 
static int seeded_subshell = 0
 
static char * static_shell_name = 0
 
char ** tempvar_list
 
int tvlist_ind
 
static struct saved_dollar_varsdollar_arg_stack = (struct saved_dollar_vars *) 0x0
 
static int dollar_arg_stack_slots
 
static int dollar_arg_stack_index
 
static struct name_and_function special_vars []
 

Data Structure Documentation

◆ saved_dollar_vars

struct saved_dollar_vars

Definition at line 5328 of file variables.c.

Data Fields
char ** first_ten
WORD_LIST * rest

◆ name_and_function

struct name_and_function

Definition at line 5554 of file variables.c.

Data Fields
char * name
sh_sv_func_t * function

Macro Definition Documentation

◆ NEED_XTRACE_SET_DECL

#define NEED_XTRACE_SET_DECL

Definition at line 47 of file variables.c.

◆ VARIABLES_HASH_BUCKETS

#define VARIABLES_HASH_BUCKETS   1024 /* must be power of two */

◆ FUNCTIONS_HASH_BUCKETS

#define FUNCTIONS_HASH_BUCKETS   512

Definition at line 84 of file variables.c.

Referenced by create_variable_tables().

◆ TEMPENV_HASH_BUCKETS

#define TEMPENV_HASH_BUCKETS   4 /* must be power of two */

Definition at line 85 of file variables.c.

Referenced by assign_in_env(), make_local_variable(), and push_temp_var().

◆ BASHFUNC_PREFIX

#define BASHFUNC_PREFIX   "BASH_FUNC_"

Definition at line 87 of file variables.c.

Referenced by initialize_shell_variables(), and mk_env_string().

◆ BASHFUNC_PREFLEN

#define BASHFUNC_PREFLEN   10 /* == strlen(BASHFUNC_PREFIX */

Definition at line 88 of file variables.c.

Referenced by initialize_shell_variables(), and mk_env_string().

◆ BASHFUNC_SUFFIX

#define BASHFUNC_SUFFIX   "%%"

Definition at line 89 of file variables.c.

Referenced by initialize_shell_variables(), and mk_env_string().

◆ BASHFUNC_SUFFLEN

#define BASHFUNC_SUFFLEN   2 /* == strlen(BASHFUNC_SUFFIX) */

Definition at line 90 of file variables.c.

Referenced by initialize_shell_variables(), and mk_env_string().

◆ FV_FORCETEMPENV

◆ FV_SKIPINVISIBLE

#define FV_SKIPINVISIBLE   0x02

Definition at line 95 of file variables.c.

Referenced by find_variable_internal(), and find_variable_no_invisible().

◆ INIT_DYNAMIC_VAR

#define INIT_DYNAMIC_VAR (   var,
  val,
  gfunc,
  afunc 
)
Value:
do \
{ \
v = bind_variable (var, (val), 0); \
v->dynamic_value = gfunc; \
v->assign_func = afunc; \
} \
while (0)
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
INT val
Definition: sm_loop.c:353

Definition at line 1165 of file variables.c.

Referenced by init_funcname_var(), init_seconds_var(), and initialize_dynamic_variables().

◆ INIT_DYNAMIC_ARRAY_VAR

#define INIT_DYNAMIC_ARRAY_VAR (   var,
  gfunc,
  afunc 
)
Value:
do \
{ \
v = make_new_array_variable (var); \
v->dynamic_value = gfunc; \
v->assign_func = afunc; \
} \
while (0)

Definition at line 1174 of file variables.c.

Referenced by get_self(), and init_funcname_var().

◆ INIT_DYNAMIC_ASSOC_VAR

#define INIT_DYNAMIC_ASSOC_VAR (   var,
  gfunc,
  afunc 
)
Value:
do \
{ \
v = make_new_assoc_variable (var); \
v->dynamic_value = gfunc; \
v->assign_func = afunc; \
} \
while (0)

Definition at line 1183 of file variables.c.

Referenced by get_self().

◆ FIND_OR_MAKE_VARIABLE

#define FIND_OR_MAKE_VARIABLE (   name,
  entry 
)
Value:
do \
{ \
entry = find_variable (name); \
if (!entry) \
{ \
entry = bind_variable (name, "", 0); \
if (!no_invisible_vars && entry) entry->attributes |= att_invisible; \
} \
} \
while (0)
#define att_invisible
Definition: variables.h:122
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
int no_invisible_vars
Definition: flags.c:116

Definition at line 3981 of file variables.c.

Referenced by set_var_read_only().

◆ USE_EXPORTSTR

#define USE_EXPORTSTR   (value == var->exportstr)

◆ add_to_export_env

#define add_to_export_env (   envstr,
  do_alloc 
)
Value:
do \
{ \
{ \
export_env_size += 16; \
environ = export_env; \
} \
export_env[export_env_index++] = (do_alloc) ? savestring (envstr) : envstr; \
export_env[export_env_index] = (char *)NULL; \
} while (0)
char ** strvec_resize(char **array, int nsize)
Definition: stringvec.c:52
char ** export_env
Definition: variables.c:160
char * savestring(const char *s)
Definition: savestring.c:33
#define NULL
Definition: general.h:53
static int export_env_index
Definition: variables.c:161
static int export_env_size
Definition: variables.c:162

Definition at line 4799 of file variables.c.

Referenced by add_or_supercede_exported_var(), and add_temp_array_to_env().

◆ SET_INT_VAR

#define SET_INT_VAR (   name,
  intvar 
)    intvar = find_variable (name) != 0

Definition at line 5551 of file variables.c.

◆ N_SPECIAL_VARS

#define N_SPECIAL_VARS   (sizeof (special_vars) / sizeof (special_vars[0]) - 1)

Definition at line 5643 of file variables.c.

Referenced by stupidly_hack_special_variables().

◆ MIN_COMPAT_LEVEL

#define MIN_COMPAT_LEVEL   31

Definition at line 6240 of file variables.c.

Function Documentation

◆ __P() [1/26]

static void create_variable_tables __P ( (void)  )
static

◆ __P() [2/26]

static SHELL_VAR* null_assign __P ( (SHELL_VAR *, char *, arrayind_t, char *)  )
static

◆ __P() [3/26]

static SHELL_VAR* get_self __P ( (SHELL_VAR *)  )
static

◆ __P() [4/26]

static void sbrand __P ( (unsigned long)  )
static

◆ __P() [5/26]

static SHELL_VAR* bind_invalid_envvar __P ( (const char *, char *, int)  )
static

◆ __P() [6/26]

static int var_sametype __P ( (SHELL_VAR *, SHELL_VAR *)  )
static

◆ __P() [7/26]

static SHELL_VAR* hash_lookup __P ( (const char *, HASH_TABLE *)  )
static

◆ __P() [8/26]

static SHELL_VAR* new_shell_variable __P ( (const char *)  )
static

◆ __P() [9/26]

static SHELL_VAR* bind_variable_internal __P ( (const char *, char *, HASH_TABLE *, int, int)  )
static

◆ __P() [10/26]

static void free_variable_hash_data __P ( (char *)  )
static

◆ __P() [11/26]

static VARLIST* vlist_alloc __P ( (int)  )
static

◆ __P() [12/26]

static VARLIST* vlist_realloc __P ( (VARLIST *, int)  )
static

◆ __P() [13/26]

static void vlist_add __P ( (VARLIST *, SHELL_VAR *, int)  )
static

◆ __P() [14/26]

static void flatten __P ( (HASH_TABLE *, sh_var_map_func_t *, VARLIST *, int)  )
static

◆ __P() [15/26]

static int qsort_var_comp __P ( (SHELL_VAR **, SHELL_VAR **)  )
static

◆ __P() [16/26]

static SHELL_VAR** vapply __P ( (sh_var_map_func_t *)  )
static

◆ __P() [17/26]

static SHELL_VAR* find_variable_internal __P ( (const char *, int)  )
static

◆ __P() [18/26]

static SHELL_VAR* find_nameref_at_context __P ( (SHELL_VAR *, VAR_CONTEXT *)  )
static

◆ __P() [19/26]

◆ __P() [20/26]

static SHELL_VAR* bind_tempenv_variable __P ( (const char *, char *)  )
static

◆ __P() [21/26]

static void dispose_temporary_env __P ( (sh_free_func_t *)  )
static

◆ __P() [22/26]

static char* mk_env_string __P ( (const char *, const char *, int)  )
inlinestatic

◆ __P() [23/26]

static char** make_env_array_from_var_list __P ( (SHELL_VAR **)  )
static

◆ __P() [24/26]

static char** make_var_export_array __P ( (VAR_CONTEXT *)  )
static

◆ __P() [25/26]

static void add_temp_array_to_env __P ( (char **, int, int)  )
static

◆ __P() [26/26]

static void push_posix_tempvar_internal __P ( (SHELL_VAR *, int)  )
inlinestatic

◆ create_variable_tables()

static void create_variable_tables ( )
static

Definition at line 314 of file variables.c.

References FUNCTIONS_HASH_BUCKETS, hash_create(), new_var_context(), NULL, var_context::scope, var_context::table, and VARIABLES_HASH_BUCKETS.

Referenced by bind_global_variable(), bind_variable(), initialize_shell_variables(), make_new_variable(), and set_if_not().

315 {
316  if (shell_variables == 0)
317  {
319  shell_variables->scope = 0;
321  }
322 
323  if (shell_functions == 0)
325 
326 #if defined (DEBUGGER)
327  if (shell_function_defs == 0)
328  shell_function_defs = hash_create (FUNCTIONS_HASH_BUCKETS);
329 #endif
330 }
HASH_TABLE * table
Definition: variables.h:40
#define FUNCTIONS_HASH_BUCKETS
Definition: variables.c:84
HASH_TABLE * hash_create(int buckets)
Definition: hashlib.c:46
VAR_CONTEXT * new_var_context(char *name, int flags)
Definition: variables.c:5023
VAR_CONTEXT * shell_variables
Definition: variables.c:107
#define VARIABLES_HASH_BUCKETS
Definition: variables.c:83
#define NULL
Definition: general.h:53
HASH_TABLE * shell_functions
Definition: variables.c:111
VAR_CONTEXT * global_variables
Definition: variables.c:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize_shell_variables()

void initialize_shell_variables ( char **  env,
int  privmode 
)

Definition at line 336 of file variables.c.

References _(), absolute_program(), array_needs_making, att_exported, att_imported, att_integer, att_invisible, att_readonly, bash_tilde_expand(), BASHFUNC_PREFIX, BASHFUNC_PREFLEN, BASHFUNC_SUFFIX, BASHFUNC_SUFFLEN, bind_invalid_envvar(), bind_variable(), c, CACHE_IMPORTSTR, command_execution_string, create_variable_tables(), current_user, DEFAULT_PATH_VALUE, dollar_dollar_pid, dollar_vars, user_info::euid, find_function(), find_variable(), free(), FREE, function_p, get_bash_name(), get_current_user_info(), getpid(), imported_p, initialize_dynamic_variables(), initialize_shell_level(), interactive_shell, last_command_exit_value, legal_identifier(), login_shell, variable::name, no_line_editing, NULL, parse_and_execute(), posixly_correct, primary_prompt, read_but_dont_execute, readonly_p, remember_on_history, report_error(), rl_prefer_env_winsize, secondary_prompt, seedrand(), set_auto_export, set_home_var(), set_if_not(), set_machine_vars(), set_ppid(), set_pwd(), set_shell_var(), setifs(), SEVAL_FUNCDEF, SEVAL_NOHIST, SEVAL_NONINT, SEVAL_ONECMD, sh_opterr, shell_version_string(), STREQ, STREQN, string, sv_funcnest(), sv_ignoreeof(), sv_shcompat(), sv_strict_posix(), sv_xtracefd(), user_info::uid, uidset(), VSETATTR, VUNSETATTR, and xmalloc().

Referenced by shell_initialize().

339 {
340  char *name, *string, *temp_string;
341  int c, char_index, string_index, string_length, ro;
342  SHELL_VAR *temp_var;
343 
345 
346  for (string_index = 0; env && (string = env[string_index++]); )
347  {
348  char_index = 0;
349  name = string;
350  while ((c = *string++) && c != '=')
351  ;
352  if (string[-1] == '=')
353  char_index = string - name - 1;
354 
355  /* If there are weird things in the environment, like `=xxx' or a
356  string without an `=', just skip them. */
357  if (char_index == 0)
358  continue;
359 
360  /* ASSERT(name[char_index] == '=') */
361  name[char_index] = '\0';
362  /* Now, name = env variable name, string = env variable value, and
363  char_index == strlen (name) */
364 
365  temp_var = (SHELL_VAR *)NULL;
366 
367 #if defined (FUNCTION_IMPORT)
368  /* If exported function, define it now. Don't import functions from
369  the environment in privileged mode. */
370  if (privmode == 0 && read_but_dont_execute == 0 &&
372  STREQ (BASHFUNC_SUFFIX, name + char_index - BASHFUNC_SUFFLEN) &&
373  STREQN ("() {", string, 4))
374  {
375  size_t namelen;
376  char *tname; /* desired imported function name */
377 
378  namelen = char_index - BASHFUNC_PREFLEN - BASHFUNC_SUFFLEN;
379 
380  tname = name + BASHFUNC_PREFLEN; /* start of func name */
381  tname[namelen] = '\0'; /* now tname == func name */
382 
383  string_length = strlen (string);
384  temp_string = (char *)xmalloc (namelen + string_length + 2);
385 
386  memcpy (temp_string, tname, namelen);
387  temp_string[namelen] = ' ';
388  memcpy (temp_string + namelen + 1, string, string_length + 1);
389 
390  /* Don't import function names that are invalid identifiers from the
391  environment in posix mode, though we still allow them to be defined as
392  shell variables. */
393  if (absolute_program (tname) == 0 && (posixly_correct == 0 || legal_identifier (tname)))
395  else
396  free (temp_string); /* parse_and_execute does this */
397 
398  if (temp_var = find_function (tname))
399  {
400  VSETATTR (temp_var, (att_exported|att_imported));
401  array_needs_making = 1;
402  }
403  else
404  {
405  if (temp_var = bind_invalid_envvar (name, string, 0))
406  {
408  array_needs_making = 1;
409  }
411  report_error (_("error importing function definition for `%s'"), tname);
412  }
413 
414  /* Restore original suffix */
415  tname[namelen] = BASHFUNC_SUFFIX[0];
416  }
417  else
418 #endif /* FUNCTION_IMPORT */
419 #if defined (ARRAY_VARS)
420 # if ARRAY_EXPORT
421  /* Array variables may not yet be exported. */
422  if (*string == '(' && string[1] == '[' && string[strlen (string) - 1] == ')')
423  {
424  string_length = 1;
425  temp_string = extract_array_assignment_list (string, &string_length);
426  temp_var = assign_array_from_string (name, temp_string, 0);
427  FREE (temp_string);
428  VSETATTR (temp_var, (att_exported | att_imported));
429  array_needs_making = 1;
430  }
431  else
432 # endif /* ARRAY_EXPORT */
433 #endif
434  {
435  ro = 0;
436  /* If we processed a command-line option that caused SHELLOPTS to be
437  set, it may already be set (and read-only) by the time we process
438  the shell's environment. */
439  if (/* posixly_correct &&*/ STREQ (name, "SHELLOPTS"))
440  {
441  temp_var = find_variable ("SHELLOPTS");
442  ro = temp_var && readonly_p (temp_var);
443  if (temp_var)
444  VUNSETATTR (temp_var, att_readonly);
445  }
446  if (legal_identifier (name))
447  {
448  temp_var = bind_variable (name, string, 0);
449  if (temp_var)
450  {
451  VSETATTR (temp_var, (att_exported | att_imported));
452  if (ro)
453  VSETATTR (temp_var, att_readonly);
454  }
455  }
456  else
457  {
458  temp_var = bind_invalid_envvar (name, string, 0);
459  if (temp_var)
461  }
462  if (temp_var)
463  array_needs_making = 1;
464  }
465 
466  name[char_index] = '=';
467  /* temp_var can be NULL if it was an exported function with a syntax
468  error (a different bug, but it still shouldn't dump core). */
469  if (temp_var && function_p (temp_var) == 0) /* XXX not yet */
470  {
471  CACHE_IMPORTSTR (temp_var, name);
472  }
473  }
474 
475  set_pwd ();
476 
477  /* Set up initial value of $_ */
478  temp_var = set_if_not ("_", dollar_vars[0]);
479 
480  /* Remember this pid. */
482 
483  /* Now make our own defaults in case the vars that we think are
484  important are missing. */
485  temp_var = set_if_not ("PATH", DEFAULT_PATH_VALUE);
486  temp_var = set_if_not ("TERM", "dumb");
487 
488 #if defined (__QNX__)
489  /* set node id -- don't import it from the environment */
490  {
491  char node_name[22];
492 # if defined (__QNXNTO__)
493  netmgr_ndtostr(ND2S_LOCAL_STR, ND_LOCAL_NODE, node_name, sizeof(node_name));
494 # else
495  qnx_nidtostr (getnid (), node_name, sizeof (node_name));
496 # endif
497  temp_var = bind_variable ("NODE", node_name, 0);
498  if (temp_var)
499  set_auto_export (temp_var);
500  }
501 #endif
502 
503  /* set up the prompts. */
504  if (interactive_shell)
505  {
506 #if defined (PROMPT_STRING_DECODE)
507  set_if_not ("PS1", primary_prompt);
508 #else
509  if (current_user.uid == -1)
511  set_if_not ("PS1", current_user.euid == 0 ? "# " : primary_prompt);
512 #endif
513  set_if_not ("PS2", secondary_prompt);
514  }
515 
516  if (current_user.euid == 0)
517  bind_variable ("PS4", "+ ", 0);
518  else
519  set_if_not ("PS4", "+ ");
520 
521  /* Don't allow IFS to be imported from the environment. */
522  temp_var = bind_variable ("IFS", " \t\n", 0);
523  setifs (temp_var);
524 
525  /* Magic machine types. Pretty convenient. */
526  set_machine_vars ();
527 
528  /* Default MAILCHECK for interactive shells. Defer the creation of a
529  default MAILPATH until the startup files are read, because MAIL
530  names a mail file if MAILPATH is not set, and we should provide a
531  default only if neither is set. */
532  if (interactive_shell)
533  {
534  temp_var = set_if_not ("MAILCHECK", posixly_correct ? "600" : "60");
535  VSETATTR (temp_var, att_integer);
536  }
537 
538  /* Do some things with shell level. */
540 
541  set_ppid ();
542 
543  /* Initialize the `getopts' stuff. */
544  temp_var = bind_variable ("OPTIND", "1", 0);
545  VSETATTR (temp_var, att_integer);
546  getopts_reset (0);
547  bind_variable ("OPTERR", "1", 0);
548  sh_opterr = 1;
549 
550  if (login_shell == 1 && posixly_correct == 0)
551  set_home_var ();
552 
553  /* Get the full pathname to THIS shell, and set the BASH variable
554  to it. */
555  name = get_bash_name ();
556  temp_var = bind_variable ("BASH", name, 0);
557  free (name);
558 
559  /* Make the exported environment variable SHELL be the user's login
560  shell. Note that the `tset' command looks at this variable
561  to determine what style of commands to output; if it ends in "csh",
562  then C-shell commands are output, else Bourne shell commands. */
563  set_shell_var ();
564 
565  /* Make a variable called BASH_VERSION which contains the version info. */
566  bind_variable ("BASH_VERSION", shell_version_string (), 0);
567 #if defined (ARRAY_VARS)
568  make_vers_array ();
569 #endif
570 
572  bind_variable ("BASH_EXECUTION_STRING", command_execution_string, 0);
573 
574  /* Find out if we're supposed to be in Posix.2 mode via an
575  environment variable. */
576  temp_var = find_variable ("POSIXLY_CORRECT");
577  if (!temp_var)
578  temp_var = find_variable ("POSIX_PEDANTIC");
579  if (temp_var && imported_p (temp_var))
580  sv_strict_posix (temp_var->name);
581 
582 #if defined (HISTORY)
583  /* Set history variables to defaults, and then do whatever we would
584  do if the variable had just been set. Do this only in the case
585  that we are remembering commands on the history list. */
587  {
588  name = bash_tilde_expand (posixly_correct ? "~/.sh_history" : "~/.bash_history", 0);
589 
590  set_if_not ("HISTFILE", name);
591  free (name);
592  }
593 #endif /* HISTORY */
594 
595  /* Seed the random number generator. */
596  seedrand ();
597 
598  /* Handle some "special" variables that we may have inherited from a
599  parent shell. */
600  if (interactive_shell)
601  {
602  temp_var = find_variable ("IGNOREEOF");
603  if (!temp_var)
604  temp_var = find_variable ("ignoreeof");
605  if (temp_var && imported_p (temp_var))
606  sv_ignoreeof (temp_var->name);
607  }
608 
609 #if defined (HISTORY)
611  {
612  sv_history_control ("HISTCONTROL");
613  sv_histignore ("HISTIGNORE");
614  sv_histtimefmt ("HISTTIMEFORMAT");
615  }
616 #endif /* HISTORY */
617 
618 #if defined (READLINE) && defined (STRICT_POSIX)
619  /* POSIXLY_CORRECT will be 1 here if the shell was compiled
620  -DSTRICT_POSIX or if POSIXLY_CORRECT was supplied in the shell's
621  environment */
624 #endif /* READLINE && STRICT_POSIX */
625 
626  /*
627  * 24 October 2001
628  *
629  * I'm tired of the arguing and bug reports. Bash now leaves SSH_CLIENT
630  * and SSH2_CLIENT alone. I'm going to rely on the shell_level check in
631  * isnetconn() to avoid running the startup files more often than wanted.
632  * That will, of course, only work if the user's login shell is bash, so
633  * I've made that behavior conditional on SSH_SOURCE_BASHRC being defined
634  * in config-top.h.
635  */
636 #if 0
637  temp_var = find_variable ("SSH_CLIENT");
638  if (temp_var && imported_p (temp_var))
639  {
640  VUNSETATTR (temp_var, att_exported);
641  array_needs_making = 1;
642  }
643  temp_var = find_variable ("SSH2_CLIENT");
644  if (temp_var && imported_p (temp_var))
645  {
646  VUNSETATTR (temp_var, att_exported);
647  array_needs_making = 1;
648  }
649 #endif
650 
651  /* Get the user's real and effective user ids. */
652  uidset ();
653 
654  temp_var = find_variable ("BASH_XTRACEFD");
655  if (temp_var && imported_p (temp_var))
656  sv_xtracefd (temp_var->name);
657 
658  sv_shcompat ("BASH_COMPAT");
659 
660  /* Allow FUNCNEST to be inherited from the environment. */
661  sv_funcnest ("FUNCNEST");
662 
663  /* Initialize the dynamic variables, and seed their values. */
665 }
#define SEVAL_ONECMD
Definition: common.h:52
#define function_p(var)
Definition: variables.h:141
int sh_opterr
Definition: getopt.c:72
static void set_machine_vars()
Definition: variables.c:674
int interactive_shell
Definition: shell.c:140
char * primary_prompt
Definition: y.tab.c:269
void set_ppid()
Definition: variables.c:926
#define set_auto_export(var)
Definition: variables.h:186
int CHAR * string
Definition: gm_loop.c:46
void get_current_user_info()
Definition: shell.c:1804
void report_error(char *format, va_alist) const
Definition: error.c:186
#define att_invisible
Definition: variables.h:122
void sv_ignoreeof(char *name)
Definition: variables.c:6005
int parse_and_execute(char *string, const char *from_file, int flags)
Definition: evalstring.c:238
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
register GCHAR c
Definition: glob_loop.c:26
int posixly_correct
Definition: shell.c:232
int read_but_dont_execute
Definition: flags.c:70
char * shell_version_string()
Definition: version.c:60
int remember_on_history
#define BASHFUNC_PREFIX
Definition: variables.c:87
#define DEFAULT_PATH_VALUE
Definition: config-top.h:65
uid_t uid
Definition: shell.h:146
uid_t euid
Definition: shell.h:146
int absolute_program(char *string) const
Definition: general.c:722
int legal_identifier(char *name) const
Definition: general.c:216
#define BASHFUNC_SUFFIX
Definition: variables.c:89
#define readonly_p(var)
Definition: variables.h:139
int array_needs_making
Definition: variables.c:151
#define SEVAL_NONINT
Definition: common.h:44
void sv_shcompat(char *name)
Definition: variables.c:6243
static void set_home_var()
Definition: variables.c:699
void sv_xtracefd(char *name)
Definition: variables.c:6206
static char * get_bash_name()
Definition: variables.c:731
static void create_variable_tables()
Definition: variables.c:314
void xs_init _((void))
#define SEVAL_FUNCDEF
Definition: common.h:51
#define att_imported
Definition: variables.h:125
pid_t dollar_dollar_pid
Definition: variables.c:148
#define SEVAL_NOHIST
Definition: common.h:46
void free()
int rl_prefer_env_winsize
Definition: terminal.c:86
void sv_funcnest(char *name)
Definition: variables.c:5750
void setifs(SHELL_VAR *v)
Definition: subst.c:10688
#define VUNSETATTR(var, attr)
Definition: variables.h:194
#define STREQN(a, b, n)
Definition: general.h:167
int login_shell
Definition: shell.c:132
int no_line_editing
Definition: shell.c:220
char * dollar_vars[10]
Definition: variables.c:144
#define CACHE_IMPORTSTR(var, value)
Definition: variables.h:210
static void initialize_dynamic_variables()
Definition: variables.c:1883
struct user_info current_user
Definition: shell.c:116
#define NULL
Definition: general.h:53
#define imported_p(var)
Definition: variables.h:154
#define FREE(s)
Definition: general.h:172
pid_t getpid()
#define STREQ(a, b)
Definition: general.h:166
char * command_execution_string
Definition: shell.c:294
static void set_shell_var()
Definition: variables.c:714
#define BASHFUNC_SUFFLEN
Definition: variables.c:90
static void seedrand()
Definition: variables.c:1354
int last_command_exit_value
Definition: execute_cmd.c:215
static void initialize_shell_level()
Definition: variables.c:850
char * name
Definition: variables.h:83
SHELL_VAR * find_function(char *name) const
Definition: variables.c:2449
char * secondary_prompt
Definition: y.tab.c:270
void set_pwd()
Definition: variables.c:863
static SHELL_VAR * bind_invalid_envvar(char *name, char *value, int flags) const
Definition: variables.c:3280
#define att_integer
Definition: variables.h:108
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_exported
Definition: variables.h:104
SHELL_VAR * set_if_not(char *name, char *value)
Definition: variables.c:2553
#define BASHFUNC_PREFLEN
Definition: variables.c:88
static void uidset()
Definition: variables.c:940
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
void sv_strict_posix(char *name)
Definition: variables.c:6060
char * bash_tilde_expand(char *s, int assign_p) const
Definition: general.c:1115
static char * xmalloc()
#define att_readonly
Definition: variables.h:105
Here is the caller graph for this function:

◆ set_machine_vars()

static void set_machine_vars ( )
static

Definition at line 674 of file variables.c.

References current_host_name, HOSTTYPE, MACHTYPE, OSTYPE, and set_if_not().

Referenced by initialize_shell_variables().

675 {
676  SHELL_VAR *temp_var;
677 
678  temp_var = set_if_not ("HOSTTYPE", HOSTTYPE);
679  temp_var = set_if_not ("OSTYPE", OSTYPE);
680  temp_var = set_if_not ("MACHTYPE", MACHTYPE);
681 
682  temp_var = set_if_not ("HOSTNAME", current_host_name);
683 }
#define HOSTTYPE
Definition: conftypes.h:28
#define MACHTYPE
Definition: conftypes.h:30
#define OSTYPE
Definition: conftypes.h:29
SHELL_VAR * set_if_not(char *name, char *value)
Definition: variables.c:2553
char * current_host_name
Definition: shell.c:123
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sh_get_home_dir()

char* sh_get_home_dir ( void  )

Definition at line 691 of file variables.c.

References current_user, get_current_user_info(), getpwuid(), getuid, user_info::home_dir, NULL, and savestring().

Referenced by set_home_var(), and tilde_expand_word().

692 {
693  if (current_user.home_dir == 0)
695  return current_user.home_dir;
696 }
void get_current_user_info()
Definition: shell.c:1804
char * home_dir
Definition: shell.h:150
struct user_info current_user
Definition: shell.c:116
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_home_var()

static void set_home_var ( )
static

Definition at line 699 of file variables.c.

References att_exported, bind_variable(), find_variable(), sh_get_home_dir(), and VSETATTR.

Referenced by initialize_shell_variables().

700 {
701  SHELL_VAR *temp_var;
702 
703  temp_var = find_variable ("HOME");
704  if (temp_var == 0)
705  temp_var = bind_variable ("HOME", sh_get_home_dir (), 0);
706 #if 0
707  VSETATTR (temp_var, att_exported);
708 #endif
709 }
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
char * sh_get_home_dir()
Definition: variables.c:691
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_exported
Definition: variables.h:104
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_shell_var()

static void set_shell_var ( )
static

Definition at line 714 of file variables.c.

References att_exported, bind_variable(), current_user, find_variable(), get_current_user_info(), user_info::shell, and VSETATTR.

Referenced by initialize_shell_variables().

715 {
716  SHELL_VAR *temp_var;
717 
718  temp_var = find_variable ("SHELL");
719  if (temp_var == 0)
720  {
721  if (current_user.shell == 0)
723  temp_var = bind_variable ("SHELL", current_user.shell, 0);
724  }
725 #if 0
726  VSETATTR (temp_var, att_exported);
727 #endif
728 }
void get_current_user_info()
Definition: shell.c:1804
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
struct user_info current_user
Definition: shell.c:116
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_exported
Definition: variables.h:104
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
char * shell
Definition: shell.h:149
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_bash_name()

static char* get_bash_name ( )
static

Definition at line 731 of file variables.c.

References ABSPATH, current_user, file_status(), find_user_command(), free(), FS_EXECABLE, full_pathname(), get_current_user_info(), get_string_value(), login_shell, make_absolute(), PATH_CHECKDOTDOT, PATH_CHECKEXISTS, RELPATH, savestring(), sh_canonpath(), user_info::shell, shell_name, strcpy(), and xmalloc().

Referenced by initialize_shell_variables().

732 {
733  char *name;
734 
735  if ((login_shell == 1) && RELPATH(shell_name))
736  {
737  if (current_user.shell == 0)
739  name = savestring (current_user.shell);
740  }
741  else if (ABSPATH(shell_name))
742  name = savestring (shell_name);
743  else if (shell_name[0] == '.' && shell_name[1] == '/')
744  {
745  /* Fast path for common case. */
746  char *cdir;
747  int len;
748 
749  cdir = get_string_value ("PWD");
750  if (cdir)
751  {
752  len = strlen (cdir);
753  name = (char *)xmalloc (len + strlen (shell_name) + 1);
754  strcpy (name, cdir);
755  strcpy (name + len, shell_name + 1);
756  }
757  else
758  name = savestring (shell_name);
759  }
760  else
761  {
762  char *tname;
763  int s;
764 
765  tname = find_user_command (shell_name);
766 
767  if (tname == 0)
768  {
769  /* Try the current directory. If there is not an executable
770  there, just punt and use the login shell. */
771  s = file_status (shell_name);
772  if (s & FS_EXECABLE)
773  {
774  tname = make_absolute (shell_name, get_string_value ("PWD"));
775  if (*shell_name == '.')
776  {
778  if (name == 0)
779  name = tname;
780  else
781  free (tname);
782  }
783  else
784  name = tname;
785  }
786  else
787  {
788  if (current_user.shell == 0)
790  name = savestring (current_user.shell);
791  }
792  }
793  else
794  {
795  name = full_pathname (tname);
796  free (tname);
797  }
798  }
799 
800  return (name);
801 }
char * shell_name
Definition: shell.c:178
#define PATH_CHECKEXISTS
Definition: externs.h:299
void get_current_user_info()
Definition: shell.c:1804
#define ABSPATH(x)
Definition: general.h:273
#define FS_EXECABLE
Definition: general.h:252
char * savestring(const char *s)
Definition: savestring.c:33
char * strcpy()
char * full_pathname(char *file)
Definition: general.c:787
void free()
char * make_absolute(char *string, char *dot_path) const
Definition: general.c:739
int login_shell
Definition: shell.c:132
char * find_user_command(char *name) const
Definition: findcmd.c:241
struct user_info current_user
Definition: shell.c:116
int file_status(char *name) const
Definition: findcmd.c:115
#define PATH_CHECKDOTDOT
Definition: externs.h:298
char * sh_canonpath(char *path, int flags)
Definition: pathcanon.c:104
#define RELPATH(x)
Definition: general.h:274
char * shell
Definition: shell.h:149
static char * xmalloc()
char * get_string_value(char *var_name) const
Definition: variables.c:2492
Here is the caller graph for this function:

◆ adjust_shell_level()

void adjust_shell_level ( int  change)

Definition at line 804 of file variables.c.

References _(), bind_variable(), get_string_value(), internal_warning(), legal_number(), set_auto_export, and shell_level.

Referenced by execute_disk_command(), initialize_shell_level(), and push_builtin().

806 {
807  char new_level[5], *old_SHLVL;
808  intmax_t old_level;
809  SHELL_VAR *temp_var;
810 
811  old_SHLVL = get_string_value ("SHLVL");
812  if (old_SHLVL == 0 || *old_SHLVL == '\0' || legal_number (old_SHLVL, &old_level) == 0)
813  old_level = 0;
814 
815  shell_level = old_level + change;
816  if (shell_level < 0)
817  shell_level = 0;
818  else if (shell_level >= 1000)
819  {
820  internal_warning (_("shell level (%d) too high, resetting to 1"), shell_level);
821  shell_level = 1;
822  }
823 
824  /* We don't need the full generality of itos here. */
825  if (shell_level < 10)
826  {
827  new_level[0] = shell_level + '0';
828  new_level[1] = '\0';
829  }
830  else if (shell_level < 100)
831  {
832  new_level[0] = (shell_level / 10) + '0';
833  new_level[1] = (shell_level % 10) + '0';
834  new_level[2] = '\0';
835  }
836  else if (shell_level < 1000)
837  {
838  new_level[0] = (shell_level / 100) + '0';
839  old_level = shell_level % 100;
840  new_level[1] = (old_level / 10) + '0';
841  new_level[2] = (old_level % 10) + '0';
842  new_level[3] = '\0';
843  }
844 
845  temp_var = bind_variable ("SHLVL", new_level, 0);
846  set_auto_export (temp_var);
847 }
#define set_auto_export(var)
Definition: variables.h:186
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
int shell_level
Definition: variables.c:155
void xs_init _((void))
void internal_warning(char *format, va_alist) const
Definition: error.c:256
int legal_number(char *string, intmax_t *result) const
Definition: general.c:175
char * get_string_value(char *var_name) const
Definition: variables.c:2492
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize_shell_level()

static void initialize_shell_level ( )
static

Definition at line 850 of file variables.c.

References adjust_shell_level().

Referenced by initialize_shell_variables().

851 {
852  adjust_shell_level (1);
853 }
void adjust_shell_level(int change)
Definition: variables.c:804
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_pwd()

void set_pwd ( )

Definition at line 863 of file variables.c.

References att_exported, att_invisible, bind_variable(), file_isdir(), find_variable(), free(), get_working_directory(), imported_p, interactive_shell, login_shell, NULL, PATH_CHECKDOTDOT, PATH_CHECKEXISTS, posixly_correct, same_file(), set_auto_export, set_working_directory(), sh_canonpath(), value_cell, and VSETATTR.

Referenced by initialize_shell_variables().

864 {
865  SHELL_VAR *temp_var, *home_var;
866  char *temp_string, *home_string, *current_dir;
867 
868  home_var = find_variable ("HOME");
869  home_string = home_var ? value_cell (home_var) : (char *)NULL;
870 
871  temp_var = find_variable ("PWD");
872  /* Follow posix rules for importing PWD */
873  if (temp_var && imported_p (temp_var) &&
874  (temp_string = value_cell (temp_var)) &&
875  temp_string[0] == '/' &&
876  same_file (temp_string, ".", (struct stat *)NULL, (struct stat *)NULL))
877  {
878  current_dir = sh_canonpath (temp_string, PATH_CHECKDOTDOT|PATH_CHECKEXISTS);
879  if (current_dir == 0)
880  current_dir = get_working_directory ("shell_init");
881  else
882  set_working_directory (current_dir);
883  if (posixly_correct && current_dir)
884  {
885  temp_var = bind_variable ("PWD", current_dir, 0);
886  set_auto_export (temp_var);
887  }
888  free (current_dir);
889  }
890  else if (home_string && interactive_shell && login_shell &&
891  same_file (home_string, ".", (struct stat *)NULL, (struct stat *)NULL))
892  {
893  set_working_directory (home_string);
894  temp_var = bind_variable ("PWD", home_string, 0);
895  set_auto_export (temp_var);
896  }
897  else
898  {
899  temp_string = get_working_directory ("shell-init");
900  if (temp_string)
901  {
902  temp_var = bind_variable ("PWD", temp_string, 0);
903  set_auto_export (temp_var);
904  free (temp_string);
905  }
906  }
907 
908  /* According to the Single Unix Specification, v2, $OLDPWD is an
909  `environment variable' and therefore should be auto-exported. If we
910  don't find OLDPWD in the environment, or it doesn't name a directory,
911  make a dummy invisible variable for OLDPWD, and mark it as exported. */
912  temp_var = find_variable ("OLDPWD");
913 #if defined (OLDPWD_CHECK_DIRECTORY)
914  if (temp_var == 0 || value_cell (temp_var) == 0 || file_isdir (value_cell (temp_var)) == 0)
915 #else
916  if (temp_var == 0 || value_cell (temp_var) == 0)
917 #endif
918  {
919  temp_var = bind_variable ("OLDPWD", (char *)NULL, 0);
920  VSETATTR (temp_var, (att_exported | att_invisible));
921  }
922 }
int interactive_shell
Definition: shell.c:140
#define set_auto_export(var)
Definition: variables.h:186
#define PATH_CHECKEXISTS
Definition: externs.h:299
#define att_invisible
Definition: variables.h:122
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
int file_isdir(char *fn) const
Definition: general.c:666
int posixly_correct
Definition: shell.c:232
int same_file(char *path1, char *path2, struct stat *stp1, struct stat *stp2) const
Definition: general.c:527
void free()
int login_shell
Definition: shell.c:132
char * get_working_directory(char *for_whom)
Definition: common.c:561
#define NULL
Definition: general.h:53
#define imported_p(var)
Definition: variables.h:154
void set_working_directory(char *name)
Definition: common.c:591
#define PATH_CHECKDOTDOT
Definition: externs.h:298
char * sh_canonpath(char *path, int flags)
Definition: pathcanon.c:104
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_exported
Definition: variables.h:104
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_ppid()

void set_ppid ( )

Definition at line 926 of file variables.c.

References att_exported, att_integer, att_readonly, bind_variable(), find_variable(), INT_STRLEN_BOUND, inttostr(), VSETATTR, and VUNSETATTR.

Referenced by initialize_shell_variables(), and push_builtin().

927 {
928  char namebuf[INT_STRLEN_BOUND(pid_t) + 1], *name;
929  SHELL_VAR *temp_var;
930 
931  name = inttostr (getppid (), namebuf, sizeof(namebuf));
932  temp_var = find_variable ("PPID");
933  if (temp_var)
934  VUNSETATTR (temp_var, (att_readonly | att_exported));
935  temp_var = bind_variable ("PPID", name, 0);
936  VSETATTR (temp_var, (att_readonly | att_integer));
937 }
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
#define VUNSETATTR(var, attr)
Definition: variables.h:194
#define INT_STRLEN_BOUND(t)
Definition: general.h:109
#define att_integer
Definition: variables.h:108
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_exported
Definition: variables.h:104
char * inttostr(intmax_t i, char *buf, size_t len)
Definition: itos.c:33
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
#define att_readonly
Definition: variables.h:105
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uidset()

static void uidset ( )
static

Definition at line 940 of file variables.c.

References array_cell, att_integer, att_readonly, bind_variable(), build_version, current_user, dist_version, user_info::euid, find_variable(), INT_STRLEN_BOUND, inttostr(), MACHTYPE, patch_level, release_status, strchr(), strcpy(), user_info::uid, unbind_variable_noref(), and VSETATTR.

Referenced by initialize_shell_variables().

941 {
942  char buff[INT_STRLEN_BOUND(uid_t) + 1], *b;
943  register SHELL_VAR *v;
944 
945  b = inttostr (current_user.uid, buff, sizeof (buff));
946  v = find_variable ("UID");
947  if (v == 0)
948  {
949  v = bind_variable ("UID", b, 0);
951  }
952 
954  b = inttostr (current_user.euid, buff, sizeof (buff));
955 
956  v = find_variable ("EUID");
957  if (v == 0)
958  {
959  v = bind_variable ("EUID", b, 0);
961  }
962 }
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
uid_t uid
Definition: shell.h:146
uid_t euid
Definition: shell.h:146
struct user_info current_user
Definition: shell.c:116
#define INT_STRLEN_BOUND(t)
Definition: general.h:109
#define att_integer
Definition: variables.h:108
#define VSETATTR(var, attr)
Definition: variables.h:193
char * inttostr(intmax_t i, char *buf, size_t len)
Definition: itos.c:33
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
#define att_readonly
Definition: variables.h:105
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sh_set_lines_and_columns()

void sh_set_lines_and_columns ( int  lines,
int  cols 
)

Definition at line 996 of file variables.c.

References bind_variable(), INT_STRLEN_BOUND, inttostr(), and val.

998 {
999  char val[INT_STRLEN_BOUND(int) + 1], *v;
1000 
1001 #if defined (READLINE)
1002  /* If we are currently assigning to LINES or COLUMNS, don't do anything. */
1003  if (winsize_assignment)
1004  return;
1005 #endif
1006 
1007  v = inttostr (lines, val, sizeof (val));
1008  bind_variable ("LINES", v, 0);
1009 
1010  v = inttostr (cols, val, sizeof (val));
1011  bind_variable ("COLUMNS", v, 0);
1012 }
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
INT val
Definition: sm_loop.c:353
#define INT_STRLEN_BOUND(t)
Definition: general.h:109
char * inttostr(intmax_t i, char *buf, size_t len)
Definition: itos.c:33
Here is the call graph for this function:

◆ print_var_list()

void print_var_list ( SHELL_VAR **  list)

Definition at line 1023 of file variables.c.

References i, invisible_p, and print_assignment().

1025 {
1026  register int i;
1027  register SHELL_VAR *var;
1028 
1029  for (i = 0; list && (var = list[i]); i++)
1030  if (invisible_p (var) == 0)
1031  print_assignment (var);
1032 }
#define invisible_p(var)
Definition: variables.h:151
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
void print_assignment(SHELL_VAR *var)
Definition: variables.c:1055
Here is the call graph for this function:

◆ print_func_list()

void print_func_list ( SHELL_VAR **  list)

Definition at line 1037 of file variables.c.

References i, and print_var_function().

1039 {
1040  register int i;
1041  register SHELL_VAR *var;
1042 
1043  for (i = 0; list && (var = list[i]); i++)
1044  {
1045  printf ("%s ", var->name);
1046  print_var_function (var);
1047  printf ("\n");
1048  }
1049 }
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
void print_var_function(SHELL_VAR *var)
Definition: variables.c:1114
Here is the call graph for this function:

◆ print_assignment()

void print_assignment ( SHELL_VAR var)

Definition at line 1055 of file variables.c.

References array_p, assoc_p, function_p, variable::name, print_var_function(), print_var_value(), and var_isset.

Referenced by print_var_list().

1057 {
1058  if (var_isset (var) == 0)
1059  return;
1060 
1061  if (function_p (var))
1062  {
1063  printf ("%s", var->name);
1064  print_var_function (var);
1065  printf ("\n");
1066  }
1067 #if defined (ARRAY_VARS)
1068  else if (array_p (var))
1069  print_array_assignment (var, 0);
1070  else if (assoc_p (var))
1071  print_assoc_assignment (var, 0);
1072 #endif /* ARRAY_VARS */
1073  else
1074  {
1075  printf ("%s=", var->name);
1076  print_var_value (var, 1);
1077  printf ("\n");
1078  }
1079 }
#define function_p(var)
Definition: variables.h:141
#define array_p(var)
Definition: variables.h:140
void print_var_function(SHELL_VAR *var)
Definition: variables.c:1114
void print_var_value(SHELL_VAR *var, int quote)
Definition: variables.c:1086
char * name
Definition: variables.h:83
#define assoc_p(var)
Definition: variables.h:144
#define var_isset(var)
Definition: variables.h:174
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_var_value()

void print_var_value ( SHELL_VAR var,
int  quote 
)

Definition at line 1086 of file variables.c.

References ansic_quote(), ansic_shouldquote(), free(), posixly_correct, sh_contains_shell_metas(), sh_single_quote(), t, value_cell, and var_isset.

Referenced by print_assignment(), and printenv_builtin().

1089 {
1090  char *t;
1091 
1092  if (var_isset (var) == 0)
1093  return;
1094 
1095  if (quote && posixly_correct == 0 && ansic_shouldquote (value_cell (var)))
1096  {
1097  t = ansic_quote (value_cell (var), 0, (int *)0);
1098  printf ("%s", t);
1099  free (t);
1100  }
1101  else if (quote && sh_contains_shell_metas (value_cell (var)))
1102  {
1103  t = sh_single_quote (value_cell (var));
1104  printf ("%s", t);
1105  free (t);
1106  }
1107  else
1108  printf ("%s", value_cell (var));
1109 }
int posixly_correct
Definition: shell.c:232
int sh_contains_shell_metas(char *string) const
Definition: shquote.c:340
char * sh_single_quote()
int t
Definition: gm_loop.c:77
void free()
int ansic_shouldquote(char *string) const
Definition: strtrans.c:331
char * ansic_quote(char *str, int flags, int *rlen)
Definition: strtrans.c:210
#define value_cell(var)
Definition: variables.h:166
#define var_isset(var)
Definition: variables.h:174
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_var_function()

void print_var_function ( SHELL_VAR var)

Definition at line 1114 of file variables.c.

References FUNC_EXTERNAL, FUNC_MULTILINE, function_cell, function_p, named_function_string(), NULL, and var_isset.

Referenced by print_assignment(), print_func_list(), and printenv_builtin().

1116 {
1117  char *x;
1118 
1119  if (function_p (var) && var_isset (var))
1120  {
1122  printf ("%s", x);
1123  }
1124 }
#define function_p(var)
Definition: variables.h:141
#define function_cell(var)
Definition: variables.h:167
#define FUNC_MULTILINE
Definition: externs.h:35
#define NULL
Definition: general.h:53
#define FUNC_EXTERNAL
Definition: externs.h:36
#define var_isset(var)
Definition: variables.h:174
Here is the call graph for this function:
Here is the caller graph for this function:

◆ null_assign()

static SHELL_VAR* null_assign ( SHELL_VAR self,
char *  value,
arrayind_t  unused,
char *  key 
)
static

Definition at line 1193 of file variables.c.

Referenced by init_funcname_var(), and initialize_dynamic_variables().

1198 {
1199  return (self);
1200 }
Here is the caller graph for this function:

◆ get_self()

static SHELL_VAR* get_self ( SHELL_VAR self)
static

Definition at line 1217 of file variables.c.

References find_variable(), INIT_DYNAMIC_ARRAY_VAR, INIT_DYNAMIC_ASSOC_VAR, and VSETATTR.

Referenced by initialize_dynamic_variables().

1219 {
1220  return (self);
1221 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign_seconds()

static SHELL_VAR* assign_seconds ( SHELL_VAR self,
char *  value,
arrayind_t  unused,
char *  key 
)
static

Definition at line 1269 of file variables.c.

References legal_number(), NOW, and shell_start_time.

Referenced by init_seconds_var().

1274 {
1275  if (legal_number (value, &seconds_value_assigned) == 0)
1278  return (self);
1279 }
time_t shell_start_time
Definition: shell.c:181
static intmax_t seconds_value_assigned
Definition: variables.c:1266
int legal_number(char *string, intmax_t *result) const
Definition: general.c:175
#define NOW
Definition: general.h:248
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_seconds()

static SHELL_VAR* get_seconds ( SHELL_VAR var)
static

Definition at line 1282 of file variables.c.

References att_integer, FREE, itos(), NOW, p, shell_start_time, value_cell, var_setvalue, and VSETATTR.

Referenced by init_seconds_var().

1284 {
1285  time_t time_since_start;
1286  char *p;
1287 
1288  time_since_start = NOW - shell_start_time;
1289  p = itos(seconds_value_assigned + time_since_start);
1290 
1291  FREE (value_cell (var));
1292 
1293  VSETATTR (var, att_integer);
1294  var_setvalue (var, p);
1295  return (var);
1296 }
time_t shell_start_time
Definition: shell.c:181
#define var_setvalue(var, str)
Definition: variables.h:179
p
Definition: glob_loop.c:31
static intmax_t seconds_value_assigned
Definition: variables.c:1266
char * itos(intmax_t i)
Definition: itos.c:44
#define FREE(s)
Definition: general.h:172
#define att_integer
Definition: variables.h:108
#define VSETATTR(var, attr)
Definition: variables.h:193
#define value_cell(var)
Definition: variables.h:166
#define NOW
Definition: general.h:248
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_seconds_var()

static SHELL_VAR* init_seconds_var ( )
static

Definition at line 1299 of file variables.c.

References assign_seconds(), find_variable(), get_seconds(), INIT_DYNAMIC_VAR, legal_number(), NULL, and value_cell.

Referenced by initialize_dynamic_variables().

1300 {
1301  SHELL_VAR *v;
1302 
1303  v = find_variable ("SECONDS");
1304  if (v)
1305  {
1308  }
1309  INIT_DYNAMIC_VAR ("SECONDS", (v ? value_cell (v) : (char *)NULL), get_seconds, assign_seconds);
1310  return v;
1311 }
static SHELL_VAR * get_seconds(SHELL_VAR *var)
Definition: variables.c:1282
#define INIT_DYNAMIC_VAR(var, val, gfunc, afunc)
Definition: variables.c:1165
static intmax_t seconds_value_assigned
Definition: variables.c:1266
#define NULL
Definition: general.h:53
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
int legal_number(char *string, intmax_t *result) const
Definition: general.c:175
#define value_cell(var)
Definition: variables.h:166
static SHELL_VAR * assign_seconds(SHELL_VAR *self, char *value, arrayind_t unused, char *key)
Definition: variables.c:1269
Here is the call graph for this function:
Here is the caller graph for this function:

◆ brand()

static int brand ( )
static

Definition at line 1324 of file variables.c.

Referenced by get_random_number().

1325 {
1326  /* From "Random number generators: good ones are hard to find",
1327  Park and Miller, Communications of the ACM, vol. 31, no. 10,
1328  October 1988, p. 1195. filtered through FreeBSD */
1329  long h, l;
1330 
1331  /* Can't seed with 0. */
1332  if (rseed == 0)
1333  rseed = 123459876;
1334  h = rseed / 127773;
1335  l = rseed % 127773;
1336  rseed = 16807 * l - 2836 * h;
1337 #if 0
1338  if (rseed < 0)
1339  rseed += 0x7fffffff;
1340 #endif
1341  return ((unsigned int)(rseed & 32767)); /* was % 32768 */
1342 }
static unsigned long rseed
Definition: variables.c:1314
Here is the caller graph for this function:

◆ sbrand()

static void sbrand ( unsigned long  seed)
static

Definition at line 1346 of file variables.c.

Referenced by assign_random(), and seedrand().

1348 {
1349  rseed = seed;
1350  last_random_value = 0;
1351 }
static int last_random_value
Definition: variables.c:1315
static unsigned long rseed
Definition: variables.c:1314
Here is the caller graph for this function:

◆ seedrand()

static void seedrand ( )
static

Definition at line 1354 of file variables.c.

References getpid(), NULL, and sbrand().

Referenced by get_random_number(), and initialize_shell_variables().

1355 {
1356  struct timeval tv;
1357 
1358  gettimeofday (&tv, NULL);
1359  sbrand (tv.tv_sec ^ tv.tv_usec ^ getpid ());
1360 }
static void sbrand(unsigned long seed)
Definition: variables.c:1346
#define NULL
Definition: general.h:53
pid_t getpid()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign_random()

static SHELL_VAR* assign_random ( SHELL_VAR self,
char *  value,
arrayind_t  unused,
char *  key 
)
static

Definition at line 1363 of file variables.c.

References getpid(), NULL, sbrand(), and subshell_environment.

Referenced by initialize_dynamic_variables().

1368 {
1369  sbrand (strtoul (value, (char **)NULL, 10));
1371  seeded_subshell = getpid ();
1372  return (self);
1373 }
static int seeded_subshell
Definition: variables.c:1316
static void sbrand(unsigned long seed)
Definition: variables.c:1346
#define NULL
Definition: general.h:53
pid_t getpid()
int subshell_environment
Definition: execute_cmd.c:248
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_random_number()

int get_random_number ( )

Definition at line 1376 of file variables.c.

References brand(), getpid(), seedrand(), and subshell_environment.

Referenced by get_random().

1377 {
1378  int rv, pid;
1379 
1380  /* Reset for command and process substitution. */
1381  pid = getpid ();
1382  if (subshell_environment && seeded_subshell != pid)
1383  {
1384  seedrand ();
1385  seeded_subshell = pid;
1386  }
1387 
1388  do
1389  rv = brand ();
1390  while (rv == last_random_value);
1391  return rv;
1392 }
static int seeded_subshell
Definition: variables.c:1316
static int brand()
Definition: variables.c:1324
static int last_random_value
Definition: variables.c:1315
pid_t getpid()
static void seedrand()
Definition: variables.c:1354
int subshell_environment
Definition: execute_cmd.c:248
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_random()

static SHELL_VAR* get_random ( SHELL_VAR var)
static

Definition at line 1395 of file variables.c.

References att_integer, FREE, get_random_number(), itos(), p, value_cell, var_setvalue, and VSETATTR.

Referenced by initialize_dynamic_variables().

1397 {
1398  int rv;
1399  char *p;
1400 
1401  rv = get_random_number ();
1402  last_random_value = rv;
1403  p = itos (rv);
1404 
1405  FREE (value_cell (var));
1406 
1407  VSETATTR (var, att_integer);
1408  var_setvalue (var, p);
1409  return (var);
1410 }
int get_random_number()
Definition: variables.c:1376
#define var_setvalue(var, str)
Definition: variables.h:179
p
Definition: glob_loop.c:31
static int last_random_value
Definition: variables.c:1315
char * itos(intmax_t i)
Definition: itos.c:44
#define FREE(s)
Definition: general.h:172
#define att_integer
Definition: variables.h:108
#define VSETATTR(var, attr)
Definition: variables.h:193
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign_lineno()

static SHELL_VAR* assign_lineno ( SHELL_VAR var,
char *  value,
arrayind_t  unused,
char *  key 
)
static

Definition at line 1413 of file variables.c.

References legal_number(), line_number, and line_number_base.

Referenced by initialize_dynamic_variables().

1418 {
1419  intmax_t new_value;
1420 
1421  if (value == 0 || *value == '\0' || legal_number (value, &new_value) == 0)
1422  new_value = 0;
1423  line_number = line_number_base = new_value;
1424  return var;
1425 }
int line_number
int line_number_base
int legal_number(char *string, intmax_t *result) const
Definition: general.c:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_lineno()

static SHELL_VAR* get_lineno ( SHELL_VAR var)
static

Definition at line 1429 of file variables.c.

References executing_line_number(), FREE, itos(), p, value_cell, and var_setvalue.

Referenced by initialize_dynamic_variables().

1431 {
1432  char *p;
1433  int ln;
1434 
1435  ln = executing_line_number ();
1436  p = itos (ln);
1437  FREE (value_cell (var));
1438  var_setvalue (var, p);
1439  return (var);
1440 }
int executing_line_number()
Definition: execute_cmd.c:349
#define var_setvalue(var, str)
Definition: variables.h:179
p
Definition: glob_loop.c:31
char * itos(intmax_t i)
Definition: itos.c:44
#define FREE(s)
Definition: general.h:172
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign_subshell()

static SHELL_VAR* assign_subshell ( SHELL_VAR var,
char *  value,
arrayind_t  unused,
char *  key 
)
static

Definition at line 1443 of file variables.c.

References legal_number(), and subshell_level.

Referenced by initialize_dynamic_variables().

1448 {
1449  intmax_t new_value;
1450 
1451  if (value == 0 || *value == '\0' || legal_number (value, &new_value) == 0)
1452  new_value = 0;
1453  subshell_level = new_value;
1454  return var;
1455 }
int subshell_level
Definition: execute_cmd.c:251
int legal_number(char *string, intmax_t *result) const
Definition: general.c:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_subshell()

static SHELL_VAR* get_subshell ( SHELL_VAR var)
static

Definition at line 1458 of file variables.c.

References FREE, itos(), p, subshell_level, value_cell, and var_setvalue.

Referenced by initialize_dynamic_variables().

1460 {
1461  char *p;
1462 
1463  p = itos (subshell_level);
1464  FREE (value_cell (var));
1465  var_setvalue (var, p);
1466  return (var);
1467 }
#define var_setvalue(var, str)
Definition: variables.h:179
p
Definition: glob_loop.c:31
int subshell_level
Definition: execute_cmd.c:251
char * itos(intmax_t i)
Definition: itos.c:44
#define FREE(s)
Definition: general.h:172
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_epochseconds()

static SHELL_VAR* get_epochseconds ( SHELL_VAR var)
static

Definition at line 1470 of file variables.c.

References FREE, itos(), NOW, p, value_cell, and var_setvalue.

Referenced by initialize_dynamic_variables().

1472 {
1473  intmax_t now;
1474  char *p;
1475 
1476  now = NOW;
1477  p = itos (now);
1478 
1479  FREE (value_cell (var));
1480  var_setvalue (var, p);
1481  return (var);
1482 }
#define var_setvalue(var, str)
Definition: variables.h:179
p
Definition: glob_loop.c:31
char * itos(intmax_t i)
Definition: itos.c:44
#define FREE(s)
Definition: general.h:172
#define value_cell(var)
Definition: variables.h:166
#define NOW
Definition: general.h:248
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_epochrealtime()

static SHELL_VAR* get_epochrealtime ( SHELL_VAR var)
static

Definition at line 1485 of file variables.c.

References FREE, locale_decpoint(), NULL, p, savestring(), snprintf(), value_cell, and var_setvalue.

Referenced by initialize_dynamic_variables().

1487 {
1488  char buf[32];
1489  char *p;
1490  struct timeval tv;
1491 
1492  gettimeofday (&tv, NULL);
1493  snprintf (buf, sizeof (buf), "%u%c%06u", (unsigned)tv.tv_sec,
1494  locale_decpoint (),
1495  (unsigned)tv.tv_usec);
1496 
1497  p = savestring (buf);
1498  FREE (value_cell (var));
1499  var_setvalue (var, p);
1500  return (var);
1501 }
#define var_setvalue(var, str)
Definition: variables.h:179
p
Definition: glob_loop.c:31
char * savestring(const char *s)
Definition: savestring.c:33
int locale_decpoint()
Definition: locale.c:613
int snprintf(char *string, size_t length, const char *format, va_alist)
Definition: snprintf.c:1727
#define NULL
Definition: general.h:53
#define FREE(s)
Definition: general.h:172
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_bashpid()

static SHELL_VAR* get_bashpid ( SHELL_VAR var)
static

Definition at line 1504 of file variables.c.

References att_integer, FREE, getpid(), itos(), p, value_cell, var_setvalue, and VSETATTR.

Referenced by initialize_dynamic_variables().

1506 {
1507  int pid;
1508  char *p;
1509 
1510  pid = getpid ();
1511  p = itos (pid);
1512 
1513  FREE (value_cell (var));
1514  VSETATTR (var, att_integer); /* XXX - was also att_readonly */
1515  var_setvalue (var, p);
1516  return (var);
1517 }
#define var_setvalue(var, str)
Definition: variables.h:179
p
Definition: glob_loop.c:31
char * itos(intmax_t i)
Definition: itos.c:44
#define FREE(s)
Definition: general.h:172
pid_t getpid()
#define att_integer
Definition: variables.h:108
#define VSETATTR(var, attr)
Definition: variables.h:193
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_bash_argv0()

static SHELL_VAR* get_bash_argv0 ( SHELL_VAR var)
static

Definition at line 1520 of file variables.c.

References dollar_vars, FREE, p, savestring(), value_cell, and var_setvalue.

Referenced by initialize_dynamic_variables().

1522 {
1523  char *p;
1524 
1525  p = savestring (dollar_vars[0]);
1526  FREE (value_cell (var));
1527  var_setvalue (var, p);
1528  return var;
1529 }
#define var_setvalue(var, str)
Definition: variables.h:179
p
Definition: glob_loop.c:31
char * savestring(const char *s)
Definition: savestring.c:33
char * dollar_vars[10]
Definition: variables.c:144
#define FREE(s)
Definition: general.h:172
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign_bash_argv0()

static SHELL_VAR* assign_bash_argv0 ( SHELL_VAR var,
char *  value,
arrayind_t  unused,
char *  key 
)
static

Definition at line 1534 of file variables.c.

References dollar_vars, FREE, savestring(), shell_name, static_shell_name, strcpy(), STRLEN, and xrealloc().

Referenced by initialize_dynamic_variables().

1539 {
1540  size_t vlen;
1541 
1542  if (value == 0)
1543  return var;
1544 
1545  FREE (dollar_vars[0]);
1546  dollar_vars[0] = savestring (value);
1547 
1548  /* Need these gyrations because shell_name isn't dynamically allocated */
1549  vlen = STRLEN (value);
1551  strcpy (static_shell_name, value);
1552 
1554  return var;
1555 }
char * shell_name
Definition: shell.c:178
#define STRLEN(s)
Definition: general.h:171
static char * static_shell_name
Definition: variables.c:1531
char * savestring(const char *s)
Definition: savestring.c:33
char * strcpy()
static char * xrealloc()
char * dollar_vars[10]
Definition: variables.c:144
#define FREE(s)
Definition: general.h:172
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_bash_command()

static SHELL_VAR* get_bash_command ( SHELL_VAR var)
static

Definition at line 1558 of file variables.c.

References _(), aliases, array_cell, assoc_cell, assoc_create, bash_readline_initialized, bucket_contents::data, debugging_mode, dispose_words(), executable_file(), find_user_command(), free(), FREE, get_group_list(), HASH_ENTRIES, hash_items, hashed_filenames, i, init_bash_argv(), itos(), bucket_contents::key, legal_alias_name(), hash_table::nbuckets, bucket_contents::next, NULL, p, pathdata, perform_hostname_completion, phash_insert(), report_error(), rl_basic_word_break_characters, rl_completer_word_break_characters, savestring(), sh_notfound(), strchr(), the_printed_command_except_trap, value_cell, var_setarray, var_setvalue, variable_context, and xmalloc().

Referenced by initialize_dynamic_variables().

1560 {
1561  char *p;
1562 
1565  else
1566  {
1567  p = (char *)xmalloc (1);
1568  p[0] = '\0';
1569  }
1570  FREE (value_cell (var));
1571  var_setvalue (var, p);
1572  return (var);
1573 }
char * the_printed_command_except_trap
Definition: execute_cmd.c:207
#define var_setvalue(var, str)
Definition: variables.h:179
p
Definition: glob_loop.c:31
char * savestring(const char *s)
Definition: savestring.c:33
#define FREE(s)
Definition: general.h:172
static char * xmalloc()
#define value_cell(var)
Definition: variables.h:166
Here is the caller graph for this function:

◆ get_funcname()

static SHELL_VAR* get_funcname ( SHELL_VAR self)
static

Definition at line 1834 of file variables.c.

References FREE, variable::name, savestring(), t, this_shell_function, value_cell, var_setvalue, and variable_context.

Referenced by init_funcname_var().

1836 {
1837 #if ! defined (ARRAY_VARS)
1838  char *t;
1840  {
1841  FREE (value_cell (self));
1843  var_setvalue (self, t);
1844  }
1845 #endif
1846  return (self);
1847 }
#define var_setvalue(var, str)
Definition: variables.h:179
int t
Definition: gm_loop.c:77
char * savestring(const char *s)
Definition: savestring.c:33
SHELL_VAR * this_shell_function
Definition: execute_cmd.c:254
int variable_context
Definition: variables.c:123
#define FREE(s)
Definition: general.h:172
char * name
Definition: variables.h:83
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_funcname_visible()

void make_funcname_visible ( int  on_or_off)

Definition at line 1850 of file variables.c.

References att_invisible, variable::dynamic_value, find_variable(), VSETATTR, and VUNSETATTR.

Referenced by execute_function().

1852 {
1853  SHELL_VAR *v;
1854 
1855  v = find_variable ("FUNCNAME");
1856  if (v == 0 || v->dynamic_value == 0)
1857  return;
1858 
1859  if (on_or_off)
1861  else
1862  VSETATTR (v, att_invisible);
1863 }
#define att_invisible
Definition: variables.h:122
#define VUNSETATTR(var, attr)
Definition: variables.h:194
sh_var_value_func_t * dynamic_value
Definition: variables.h:86
#define VSETATTR(var, attr)
Definition: variables.h:193
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_funcname_var()

static SHELL_VAR* init_funcname_var ( )
static

Definition at line 1866 of file variables.c.

References att_invisible, att_noassign, find_variable(), get_funcname(), INIT_DYNAMIC_ARRAY_VAR, INIT_DYNAMIC_VAR, NULL, null_assign(), and VSETATTR.

Referenced by initialize_dynamic_variables().

1867 {
1868  SHELL_VAR *v;
1869 
1870  v = find_variable ("FUNCNAME");
1871  if (v)
1872  return v;
1873 #if defined (ARRAY_VARS)
1874  INIT_DYNAMIC_ARRAY_VAR ("FUNCNAME", get_funcname, null_array_assign);
1875 #else
1876  INIT_DYNAMIC_VAR ("FUNCNAME", (char *)NULL, get_funcname, null_assign);
1877 #endif
1879  return v;
1880 }
#define att_invisible
Definition: variables.h:122
#define att_noassign
Definition: variables.h:124
#define INIT_DYNAMIC_ARRAY_VAR(var, gfunc, afunc)
Definition: variables.c:1174
#define INIT_DYNAMIC_VAR(var, val, gfunc, afunc)
Definition: variables.c:1165
static SHELL_VAR * null_assign(SHELL_VAR *self, char *value, arrayind_t unused, char *key)
Definition: variables.c:1193
#define NULL
Definition: general.h:53
static SHELL_VAR * get_funcname(SHELL_VAR *self)
Definition: variables.c:1834
#define VSETATTR(var, attr)
Definition: variables.h:193
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize_dynamic_variables()

static void initialize_dynamic_variables ( )
static

Definition at line 1883 of file variables.c.

References assign_bash_argv0(), assign_lineno(), assign_random(), assign_subshell(), att_integer, att_noassign, att_nofree, att_nounset, att_regenerate, get_bash_argv0(), get_bash_command(), get_bashpid(), get_epochrealtime(), get_epochseconds(), get_lineno(), get_random(), get_self(), get_subshell(), INIT_DYNAMIC_VAR, init_funcname_var(), init_seconds_var(), NULL, null_assign(), and VSETATTR.

Referenced by initialize_shell_variables().

1884 {
1885  SHELL_VAR *v;
1886 
1887  v = init_seconds_var ();
1888 
1889  INIT_DYNAMIC_VAR ("BASH_ARGV0", (char *)NULL, get_bash_argv0, assign_bash_argv0);
1890 
1891  INIT_DYNAMIC_VAR ("BASH_COMMAND", (char *)NULL, get_bash_command, (sh_var_assign_func_t *)NULL);
1892  INIT_DYNAMIC_VAR ("BASH_SUBSHELL", (char *)NULL, get_subshell, assign_subshell);
1893 
1894  INIT_DYNAMIC_VAR ("RANDOM", (char *)NULL, get_random, assign_random);
1895  VSETATTR (v, att_integer);
1896  INIT_DYNAMIC_VAR ("LINENO", (char *)NULL, get_lineno, assign_lineno);
1898 
1899  INIT_DYNAMIC_VAR ("BASHPID", (char *)NULL, get_bashpid, null_assign);
1900  VSETATTR (v, att_integer);
1901 
1902  INIT_DYNAMIC_VAR ("EPOCHSECONDS", (char *)NULL, get_epochseconds, null_assign);
1903  VSETATTR (v, att_regenerate);
1904  INIT_DYNAMIC_VAR ("EPOCHREALTIME", (char *)NULL, get_epochrealtime, null_assign);
1905  VSETATTR (v, att_regenerate);
1906 
1907 #if defined (HISTORY)
1908  INIT_DYNAMIC_VAR ("HISTCMD", (char *)NULL, get_histcmd, (sh_var_assign_func_t *)NULL);
1909  VSETATTR (v, att_integer);
1910 #endif
1911 
1912 #if defined (READLINE)
1913  INIT_DYNAMIC_VAR ("COMP_WORDBREAKS", (char *)NULL, get_comp_wordbreaks, assign_comp_wordbreaks);
1914 #endif
1915 
1916 #if defined (PUSHD_AND_POPD) && defined (ARRAY_VARS)
1917  v = init_dynamic_array_var ("DIRSTACK", get_dirstack, assign_dirstack, 0);
1918 #endif /* PUSHD_AND_POPD && ARRAY_VARS */
1919 
1920 #if defined (ARRAY_VARS)
1921  v = init_dynamic_array_var ("GROUPS", get_groupset, null_array_assign, att_noassign);
1922 
1923 # if defined (DEBUGGER)
1924  v = init_dynamic_array_var ("BASH_ARGC", get_bashargcv, null_array_assign, att_noassign|att_nounset);
1925  v = init_dynamic_array_var ("BASH_ARGV", get_bashargcv, null_array_assign, att_noassign|att_nounset);
1926 # endif /* DEBUGGER */
1927  v = init_dynamic_array_var ("BASH_SOURCE", get_self, null_array_assign, att_noassign|att_nounset);
1928  v = init_dynamic_array_var ("BASH_LINENO", get_self, null_array_assign, att_noassign|att_nounset);
1929 
1930  v = init_dynamic_assoc_var ("BASH_CMDS", get_hashcmd, assign_hashcmd, att_nofree);
1931 # if defined (ALIAS)
1932  v = init_dynamic_assoc_var ("BASH_ALIASES", get_aliasvar, assign_aliasvar, att_nofree);
1933 # endif
1934 #endif
1935 
1936  v = init_funcname_var ();
1937 }
#define att_nofree
Definition: variables.h:127
static SHELL_VAR * assign_random(SHELL_VAR *self, char *value, arrayind_t unused, char *key)
Definition: variables.c:1363
static SHELL_VAR * get_self(SHELL_VAR *self)
Definition: variables.c:1217
static SHELL_VAR * get_bashpid(SHELL_VAR *var)
Definition: variables.c:1504
static SHELL_VAR * get_subshell(SHELL_VAR *var)
Definition: variables.c:1458
static SHELL_VAR * init_funcname_var()
Definition: variables.c:1866
static SHELL_VAR * assign_bash_argv0(SHELL_VAR *var, char *value, arrayind_t unused, char *key)
Definition: variables.c:1534
static SHELL_VAR * get_lineno(SHELL_VAR *var)
Definition: variables.c:1429
static SHELL_VAR * get_bash_argv0(SHELL_VAR *var)
Definition: variables.c:1520
#define att_noassign
Definition: variables.h:124
#define att_regenerate
Definition: variables.h:128
#define INIT_DYNAMIC_VAR(var, val, gfunc, afunc)
Definition: variables.c:1165
static SHELL_VAR * assign_lineno(SHELL_VAR *var, char *value, arrayind_t unused, char *key)
Definition: variables.c:1413
static SHELL_VAR * init_seconds_var()
Definition: variables.c:1299
static SHELL_VAR * get_epochseconds(SHELL_VAR *var)
Definition: variables.c:1470
static SHELL_VAR * get_random(SHELL_VAR *var)
Definition: variables.c:1395
static SHELL_VAR * null_assign(SHELL_VAR *self, char *value, arrayind_t unused, char *key)
Definition: variables.c:1193
#define NULL
Definition: general.h:53
static SHELL_VAR * get_epochrealtime(SHELL_VAR *var)
Definition: variables.c:1485
#define att_integer
Definition: variables.h:108
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_nounset
Definition: variables.h:123
static SHELL_VAR * assign_subshell(SHELL_VAR *var, char *value, arrayind_t unused, char *key)
Definition: variables.c:1443
static SHELL_VAR * get_bash_command(SHELL_VAR *var)
Definition: variables.c:1558
Here is the caller graph for this function:

◆ hash_lookup()

static SHELL_VAR* hash_lookup ( char *  name,
HASH_TABLE hashed_vars 
) const
static

Definition at line 1950 of file variables.c.

References bucket_contents::data, hash_search(), and NULL.

Referenced by assign_in_env(), bind_tempenv_variable(), bind_variable(), bind_variable_internal(), find_function(), find_function_def(), find_nameref_at_context(), find_tempenv_variable(), find_variable_internal(), and var_lookup().

1953 {
1954  BUCKET_CONTENTS *bucket;
1955 
1956  bucket = hash_search (name, hashed_vars, 0);
1957  /* If we find the name in HASHED_VARS, set LAST_TABLE_SEARCHED to that
1958  table. */
1959  if (bucket)
1960  last_table_searched = hashed_vars;
1961  return (bucket ? (SHELL_VAR *)bucket->data : (SHELL_VAR *)NULL);
1962 }
BUCKET_CONTENTS * hash_search(char *string, HASH_TABLE *table, int flags) const
Definition: hashlib.c:166
#define NULL
Definition: general.h:53
static HASH_TABLE * last_table_searched
Definition: variables.c:171
char * data
Definition: hashlib.h:37
Here is the call graph for this function:

◆ var_lookup()

SHELL_VAR* var_lookup ( char *  name,
VAR_CONTEXT vcontext 
) const

Definition at line 1965 of file variables.c.

References var_context::down, hash_lookup(), NULL, and var_context::table.

Referenced by find_global_variable(), find_global_variable_noref(), find_shell_variable(), find_variable_internal(), unbind_nameref(), unbind_variable(), and unbind_variable_noref().

1968 {
1969  VAR_CONTEXT *vc;
1970  SHELL_VAR *v;
1971 
1972  v = (SHELL_VAR *)NULL;
1973  for (vc = vcontext; vc; vc = vc->down)
1974  if (v = hash_lookup (name, vc->table))
1975  break;
1976 
1977  return v;
1978 }
HASH_TABLE * table
Definition: variables.h:40
#define NULL
Definition: general.h:53
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_variable_internal()

SHELL_VAR* find_variable_internal ( char *  name,
int  flags 
) const

Definition at line 1988 of file variables.c.

References var_context::down, variable::dynamic_value, expanding_redir, FV_FORCETEMPENV, FV_SKIPINVISIBLE, hash_lookup(), invisible_p, NULL, subshell_environment, var_context::table, and var_lookup().

Referenced by find_variable(), find_variable_for_assignment(), find_variable_last_nameref(), find_variable_nameref(), find_variable_no_invisible(), find_variable_noref(), find_variable_notempenv(), and find_variable_tempenv().

1991 {
1992  SHELL_VAR *var;
1993  int search_tempenv, force_tempenv;
1994  VAR_CONTEXT *vc;
1995 
1996  var = (SHELL_VAR *)NULL;
1997 
1998  force_tempenv = (flags & FV_FORCETEMPENV);
1999 
2000  /* If explicitly requested, first look in the temporary environment for
2001  the variable. This allows constructs such as "foo=x eval 'echo $foo'"
2002  to get the `exported' value of $foo. This happens if we are executing
2003  a function or builtin, or if we are looking up a variable in a
2004  "subshell environment". */
2005  search_tempenv = force_tempenv || (expanding_redir == 0 && subshell_environment);
2006 
2007  if (search_tempenv && temporary_env)
2008  var = hash_lookup (name, temporary_env);
2009 
2010  if (var == 0)
2011  {
2012  if ((flags & FV_SKIPINVISIBLE) == 0)
2013  var = var_lookup (name, shell_variables);
2014  else
2015  {
2016  /* essentially var_lookup expanded inline so we can check for
2017  att_invisible */
2018  for (vc = shell_variables; vc; vc = vc->down)
2019  {
2020  var = hash_lookup (name, vc->table);
2021  if (var && invisible_p (var))
2022  var = 0;
2023  if (var)
2024  break;
2025  }
2026  }
2027  }
2028 
2029  if (var == 0)
2030  return ((SHELL_VAR *)NULL);
2031 
2032  return (var->dynamic_value ? (*(var->dynamic_value)) (var) : var);
2033 }
int expanding_redir
Definition: redir.c:63
HASH_TABLE * table
Definition: variables.h:40
#define FV_SKIPINVISIBLE
Definition: variables.c:95
#define invisible_p(var)
Definition: variables.h:151
HASH_TABLE * temporary_env
Definition: variables.c:136
VAR_CONTEXT * shell_variables
Definition: variables.c:107
SHELL_VAR * var_lookup(char *name, VAR_CONTEXT *vcontext) const
Definition: variables.c:1965
#define NULL
Definition: general.h:53
sh_var_value_func_t * dynamic_value
Definition: variables.h:86
#define FV_FORCETEMPENV
Definition: variables.c:94
int flags
Definition: gm_loop.c:47
int subshell_environment
Definition: execute_cmd.c:248
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_variable_nameref()

SHELL_VAR* find_variable_nameref ( SHELL_VAR v)

Definition at line 2038 of file variables.c.

References _(), assigning_in_environment, variable::context, executing_builtin, expanding_redir, find_global_variable_noref(), find_variable_internal(), flags, FV_FORCETEMPENV, internal_warning(), variable::name, nameref_cell, NAMEREF_MAX, nameref_p, and variable_context.

Referenced by find_global_variable(), find_shell_variable(), find_variable(), find_variable_for_assignment(), find_variable_no_invisible(), find_variable_notempenv(), find_variable_tempenv(), and unbind_variable().

2040 {
2041  int level, flags;
2042  char *newname;
2043  SHELL_VAR *orig, *oldv;
2044 
2045  level = 0;
2046  orig = v;
2047  while (v && nameref_p (v))
2048  {
2049  level++;
2050  if (level > NAMEREF_MAX)
2051  return ((SHELL_VAR *)0); /* error message here? */
2052  newname = nameref_cell (v);
2053  if (newname == 0 || *newname == '\0')
2054  return ((SHELL_VAR *)0);
2055  oldv = v;
2056  flags = 0;
2058  flags |= FV_FORCETEMPENV;
2059  /* We don't handle array subscripts here. */
2060  v = find_variable_internal (newname, flags);
2061  if (v == orig || v == oldv)
2062  {
2063  internal_warning (_("%s: circular name reference"), orig->name);
2064 #if 1
2065  /* XXX - provisional change - circular refs go to
2066  global scope for resolution, without namerefs. */
2067  if (variable_context && v->context)
2068  return (find_global_variable_noref (v->name));
2069  else
2070 #endif
2071  return ((SHELL_VAR *)0);
2072  }
2073  }
2074  return v;
2075 }
int expanding_redir
Definition: redir.c:63
#define nameref_p(var)
Definition: variables.h:149
int assigning_in_environment
Definition: subst.c:171
SHELL_VAR * find_variable_internal(char *name, int flags) const
Definition: variables.c:1988
SHELL_VAR * find_global_variable_noref(char *name) const
Definition: variables.c:2346
#define NAMEREF_MAX
Definition: variables.h:172
void xs_init _((void))
int executing_builtin
Definition: execute_cmd.c:236
int variable_context
Definition: variables.c:123
void internal_warning(char *format, va_alist) const
Definition: error.c:256
#define nameref_cell(var)
Definition: variables.h:170
#define FV_FORCETEMPENV
Definition: variables.c:94
int flags
Definition: gm_loop.c:47
int context
Definition: variables.h:93
char * name
Definition: variables.h:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_variable_last_nameref()

SHELL_VAR* find_variable_last_nameref ( char *  name,
int  vflags 
) const

Definition at line 2079 of file variables.c.

References assigning_in_environment, executing_builtin, expanding_redir, find_variable_internal(), find_variable_noref(), flags, FV_FORCETEMPENV, invisible_p, nameref_cell, NAMEREF_MAX, and nameref_p.

Referenced by assign_in_env(), bind_variable_internal(), execute_for_command(), find_variable_nameref_for_assignment(), find_variable_nameref_for_create(), nameref_transform_name(), param_expand(), parameter_brace_expand_indir(), parameter_brace_expand_word(), parameter_brace_find_indir(), and redir_varvalue().

2082 {
2083  SHELL_VAR *v, *nv;
2084  char *newname;
2085  int level, flags;
2086 
2087  nv = v = find_variable_noref (name);
2088  level = 0;
2089  while (v && nameref_p (v))
2090  {
2091  level++;
2092  if (level > NAMEREF_MAX)
2093  return ((SHELL_VAR *)0); /* error message here? */
2094  newname = nameref_cell (v);
2095  if (newname == 0 || *newname == '\0')
2096  return ((vflags && invisible_p (v)) ? v : (SHELL_VAR *)0);
2097  nv = v;
2098  flags = 0;
2100  flags |= FV_FORCETEMPENV;
2101  /* We don't accommodate array subscripts here. */
2102  v = find_variable_internal (newname, flags);
2103  }
2104  return nv;
2105 }
int expanding_redir
Definition: redir.c:63
#define nameref_p(var)
Definition: variables.h:149
int assigning_in_environment
Definition: subst.c:171
#define invisible_p(var)
Definition: variables.h:151
SHELL_VAR * find_variable_internal(char *name, int flags) const
Definition: variables.c:1988
#define NAMEREF_MAX
Definition: variables.h:172
SHELL_VAR * find_variable_noref(char *name) const
Definition: variables.c:2433
int executing_builtin
Definition: execute_cmd.c:236
#define nameref_cell(var)
Definition: variables.h:170
#define FV_FORCETEMPENV
Definition: variables.c:94
int flags
Definition: gm_loop.c:47
Here is the call graph for this function:

◆ find_global_variable_last_nameref()

SHELL_VAR* find_global_variable_last_nameref ( char *  name,
int  vflags 
) const

Definition at line 2109 of file variables.c.

References find_global_variable_noref(), invisible_p, nameref_cell, NAMEREF_MAX, and nameref_p.

Referenced by nameref_transform_name().

2112 {
2113  SHELL_VAR *v, *nv;
2114  char *newname;
2115  int level;
2116 
2117  nv = v = find_global_variable_noref (name);
2118  level = 0;
2119  while (v && nameref_p (v))
2120  {
2121  level++;
2122  if (level > NAMEREF_MAX)
2123  return ((SHELL_VAR *)0); /* error message here? */
2124  newname = nameref_cell (v);
2125  if (newname == 0 || *newname == '\0')
2126  return ((vflags && invisible_p (v)) ? v : (SHELL_VAR *)0);
2127  nv = v;
2128  /* We don't accommodate array subscripts here. */
2129  v = find_global_variable_noref (newname);
2130  }
2131  return nv;
2132 }
#define nameref_p(var)
Definition: variables.h:149
#define invisible_p(var)
Definition: variables.h:151
SHELL_VAR * find_global_variable_noref(char *name) const
Definition: variables.c:2346
#define NAMEREF_MAX
Definition: variables.h:172
#define nameref_cell(var)
Definition: variables.h:170
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_nameref_at_context()

static SHELL_VAR* find_nameref_at_context ( SHELL_VAR v,
VAR_CONTEXT vc 
)
static

Definition at line 2135 of file variables.c.

References hash_lookup(), nameref_cell, NAMEREF_MAX, nameref_p, NULL, and var_context::table.

Referenced by find_variable_last_nameref_context(), and find_variable_nameref_context().

2138 {
2139  SHELL_VAR *nv, *nv2;
2140  char *newname;
2141  int level;
2142 
2143  nv = v;
2144  level = 1;
2145  while (nv && nameref_p (nv))
2146  {
2147  level++;
2148  if (level > NAMEREF_MAX)
2149  return (&nameref_maxloop_value);
2150  newname = nameref_cell (nv);
2151  if (newname == 0 || *newname == '\0')
2152  return ((SHELL_VAR *)NULL);
2153  nv2 = hash_lookup (newname, vc->table);
2154  if (nv2 == 0)
2155  break;
2156  nv = nv2;
2157  }
2158  return nv;
2159 }
HASH_TABLE * table
Definition: variables.h:40
#define nameref_p(var)
Definition: variables.h:149
static SHELL_VAR nameref_maxloop_value
Definition: variables.c:169
#define NAMEREF_MAX
Definition: variables.h:172
#define NULL
Definition: general.h:53
#define nameref_cell(var)
Definition: variables.h:170
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_variable_nameref_context()

static SHELL_VAR* find_variable_nameref_context ( SHELL_VAR v,
VAR_CONTEXT vc,
VAR_CONTEXT **  nvcp 
)
static

Definition at line 2167 of file variables.c.

References var_context::down, find_nameref_at_context(), nameref_p, and NULL.

Referenced by bind_variable().

2171 {
2172  SHELL_VAR *nv, *nv2;
2173  VAR_CONTEXT *nvc;
2174 
2175  /* Look starting at the current context all the way `up' */
2176  for (nv = v, nvc = vc; nvc; nvc = nvc->down)
2177  {
2178  nv2 = find_nameref_at_context (nv, nvc);
2179  if (nv2 == &nameref_maxloop_value)
2180  return (nv2); /* XXX */
2181  if (nv2 == 0)
2182  continue;
2183  nv = nv2;
2184  if (*nvcp)
2185  *nvcp = nvc;
2186  if (nameref_p (nv) == 0)
2187  break;
2188  }
2189  return (nameref_p (nv) ? (SHELL_VAR *)NULL : nv);
2190 }
#define nameref_p(var)
Definition: variables.h:149
static SHELL_VAR nameref_maxloop_value
Definition: variables.c:169
static SHELL_VAR * find_nameref_at_context(SHELL_VAR *v, VAR_CONTEXT *vc)
Definition: variables.c:2135
#define NULL
Definition: general.h:53
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_variable_last_nameref_context()

static SHELL_VAR* find_variable_last_nameref_context ( SHELL_VAR v,
VAR_CONTEXT vc,
VAR_CONTEXT **  nvcp 
)
static

Definition at line 2198 of file variables.c.

References var_context::down, find_nameref_at_context(), nameref_p, and NULL.

Referenced by bind_variable().

2202 {
2203  SHELL_VAR *nv, *nv2;
2204  VAR_CONTEXT *nvc;
2205 
2206  /* Look starting at the current context all the way `up' */
2207  for (nv = v, nvc = vc; nvc; nvc = nvc->down)
2208  {
2209  nv2 = find_nameref_at_context (nv, nvc);
2210  if (nv2 == &nameref_maxloop_value)
2211  return (nv2); /* XXX */
2212  if (nv2 == 0)
2213  continue;
2214  nv = nv2;
2215  if (*nvcp)
2216  *nvcp = nvc;
2217  }
2218  return (nameref_p (nv) ? nv : (SHELL_VAR *)NULL);
2219 }
#define nameref_p(var)
Definition: variables.h:149
static SHELL_VAR nameref_maxloop_value
Definition: variables.c:169
static SHELL_VAR * find_nameref_at_context(SHELL_VAR *v, VAR_CONTEXT *vc)
Definition: variables.c:2135
#define NULL
Definition: general.h:53
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_variable_nameref_for_create()

SHELL_VAR* find_variable_nameref_for_create ( char *  name,
int  flags 
) const

Definition at line 2222 of file variables.c.

References _(), att_nameref, find_variable_last_nameref(), internal_warning(), INVALID_NAMEREF_VALUE, invisible_p, legal_identifier(), nameref_cell, nameref_p, sh_invalidid(), and VUNSETATTR.

Referenced by execute_in_subshell().

2225 {
2226  SHELL_VAR *var;
2227 
2228  /* See if we have a nameref pointing to a variable that hasn't been
2229  created yet. */
2230  var = find_variable_last_nameref (name, 1);
2231  if ((flags&1) && var && nameref_p (var) && invisible_p (var))
2232  {
2233  internal_warning (_("%s: removing nameref attribute"), name);
2234  VUNSETATTR (var, att_nameref);
2235  }
2236  if (var && nameref_p (var))
2237  {
2238  if (legal_identifier (nameref_cell (var)) == 0)
2239  {
2240  sh_invalidid (nameref_cell (var) ? nameref_cell (var) : "");
2241  return ((SHELL_VAR *)INVALID_NAMEREF_VALUE);
2242  }
2243  }
2244  return (var);
2245 }
#define nameref_p(var)
Definition: variables.h:149
void sh_invalidid(char *s)
Definition: common.c:227
#define invisible_p(var)
Definition: variables.h:151
SHELL_VAR * find_variable_last_nameref(char *name, int vflags) const
Definition: variables.c:2079
#define INVALID_NAMEREF_VALUE
Definition: variables.h:229
int legal_identifier(char *name) const
Definition: general.c:216
void xs_init _((void))
#define VUNSETATTR(var, attr)
Definition: variables.h:194
void internal_warning(char *format, va_alist) const
Definition: error.c:256
#define nameref_cell(var)
Definition: variables.h:170
int flags
Definition: gm_loop.c:47
#define att_nameref
Definition: variables.h:115
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_variable_nameref_for_assignment()

SHELL_VAR* find_variable_nameref_for_assignment ( char *  name,
int  flags 
) const

Definition at line 2248 of file variables.c.

References _(), att_nameref, find_variable_last_nameref(), internal_warning(), INVALID_NAMEREF_VALUE, invisible_p, nameref_cell, nameref_p, sh_invalidid(), valid_nameref_value(), and VUNSETATTR.

2251 {
2252  SHELL_VAR *var;
2253 
2254  /* See if we have a nameref pointing to a variable that hasn't been
2255  created yet. */
2256  var = find_variable_last_nameref (name, 1);
2257  if (var && nameref_p (var) && invisible_p (var)) /* XXX - flags */
2258  {
2259  internal_warning (_("%s: removing nameref attribute"), name);
2260  VUNSETATTR (var, att_nameref);
2261  }
2262  if (var && nameref_p (var))
2263  {
2264  if (valid_nameref_value (nameref_cell (var), 1) == 0)
2265  {
2266  sh_invalidid (nameref_cell (var) ? nameref_cell (var) : "");
2267  return ((SHELL_VAR *)INVALID_NAMEREF_VALUE);
2268  }
2269  }
2270  return (var);
2271 }
#define nameref_p(var)
Definition: variables.h:149
void sh_invalidid(char *s)
Definition: common.c:227
#define invisible_p(var)
Definition: variables.h:151
int valid_nameref_value(char *name, int flags) const
Definition: general.c:239
SHELL_VAR * find_variable_last_nameref(char *name, int vflags) const
Definition: variables.c:2079
#define INVALID_NAMEREF_VALUE
Definition: variables.h:229
void xs_init _((void))
#define VUNSETATTR(var, attr)
Definition: variables.h:194
void internal_warning(char *format, va_alist) const
Definition: error.c:256
#define nameref_cell(var)
Definition: variables.h:170
#define att_nameref
Definition: variables.h:115
Here is the call graph for this function:

◆ nameref_transform_name()

char* nameref_transform_name ( char *  name,
int  flags 
)

Definition at line 2279 of file variables.c.

References ASS_CHKLOCAL, ASS_MKGLOBAL, ASS_MKLOCAL, variable::context, find_global_variable_last_nameref(), find_variable_last_nameref(), nameref_cell, nameref_p, valid_nameref_value(), and variable_context.

Referenced by strip_trailing_ifs_whitespace().

2282 {
2283  SHELL_VAR *v;
2284  char *newname;
2285 
2286  v = 0;
2287  if (flags & ASS_MKLOCAL)
2288  {
2289  v = find_variable_last_nameref (name, 1);
2290  /* If we're making local variables, only follow namerefs that point to
2291  non-existant variables at the same variable context. */
2292  if (v && v->context != variable_context)
2293  v = 0;
2294  }
2295  else if (flags & ASS_MKGLOBAL)
2296  v = (flags & ASS_CHKLOCAL) ? find_variable_last_nameref (name, 1)
2298  if (v && nameref_p (v) && valid_nameref_value (nameref_cell (v), 1))
2299  return nameref_cell (v);
2300  return name;
2301 }
#define nameref_p(var)
Definition: variables.h:149
#define ASS_MKGLOBAL
Definition: subst.h:50
#define ASS_MKLOCAL
Definition: subst.h:48
int valid_nameref_value(char *name, int flags) const
Definition: general.c:239
#define ASS_CHKLOCAL
Definition: subst.h:53
SHELL_VAR * find_variable_last_nameref(char *name, int vflags) const
Definition: variables.c:2079
int variable_context
Definition: variables.c:123
#define nameref_cell(var)
Definition: variables.h:170
int flags
Definition: gm_loop.c:47
SHELL_VAR * find_global_variable_last_nameref(char *name, int vflags) const
Definition: variables.c:2109
int context
Definition: variables.h:93
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_variable_tempenv()

SHELL_VAR* find_variable_tempenv ( char *  name) const

Definition at line 2305 of file variables.c.

References find_variable_internal(), find_variable_nameref(), FV_FORCETEMPENV, and nameref_p.

Referenced by _find_user_command_internal(), and search_for_command().

2307 {
2308  SHELL_VAR *var;
2309 
2311  if (var && nameref_p (var))
2312  var = find_variable_nameref (var);
2313  return (var);
2314 }
#define nameref_p(var)
Definition: variables.h:149
SHELL_VAR * find_variable_internal(char *name, int flags) const
Definition: variables.c:1988
SHELL_VAR * find_variable_nameref(SHELL_VAR *v)
Definition: variables.c:2038
#define FV_FORCETEMPENV
Definition: variables.c:94
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_variable_notempenv()

SHELL_VAR* find_variable_notempenv ( char *  name) const

Definition at line 2318 of file variables.c.

References find_variable_internal(), find_variable_nameref(), and nameref_p.

2320 {
2321  SHELL_VAR *var;
2322 
2323  var = find_variable_internal (name, 0);
2324  if (var && nameref_p (var))
2325  var = find_variable_nameref (var);
2326  return (var);
2327 }
#define nameref_p(var)
Definition: variables.h:149
SHELL_VAR * find_variable_internal(char *name, int flags) const
Definition: variables.c:1988
SHELL_VAR * find_variable_nameref(SHELL_VAR *v)
Definition: variables.c:2038
Here is the call graph for this function:

◆ find_global_variable()

SHELL_VAR* find_global_variable ( char *  name) const

Definition at line 2330 of file variables.c.

References variable::dynamic_value, find_variable_nameref(), nameref_p, NULL, and var_lookup().

Referenced by bind_variable_internal(), and strip_trailing_ifs_whitespace().

2332 {
2333  SHELL_VAR *var;
2334 
2335  var = var_lookup (name, global_variables);
2336  if (var && nameref_p (var))
2337  var = find_variable_nameref (var);
2338 
2339  if (var == 0)
2340  return ((SHELL_VAR *)NULL);
2341 
2342  return (var->dynamic_value ? (*(var->dynamic_value)) (var) : var);
2343 }
#define nameref_p(var)
Definition: variables.h:149
SHELL_VAR * var_lookup(char *name, VAR_CONTEXT *vcontext) const
Definition: variables.c:1965
SHELL_VAR * find_variable_nameref(SHELL_VAR *v)
Definition: variables.c:2038
#define NULL
Definition: general.h:53
sh_var_value_func_t * dynamic_value
Definition: variables.h:86
VAR_CONTEXT * global_variables
Definition: variables.c:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_global_variable_noref()

SHELL_VAR* find_global_variable_noref ( char *  name) const

Definition at line 2346 of file variables.c.

References variable::dynamic_value, NULL, and var_lookup().

Referenced by find_global_variable_last_nameref(), and find_variable_nameref().

2348 {
2349  SHELL_VAR *var;
2350 
2351  var = var_lookup (name, global_variables);
2352 
2353  if (var == 0)
2354  return ((SHELL_VAR *)NULL);
2355 
2356  return (var->dynamic_value ? (*(var->dynamic_value)) (var) : var);
2357 }
SHELL_VAR * var_lookup(char *name, VAR_CONTEXT *vcontext) const
Definition: variables.c:1965
#define NULL
Definition: general.h:53
sh_var_value_func_t * dynamic_value
Definition: variables.h:86
VAR_CONTEXT * global_variables
Definition: variables.c:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_shell_variable()

SHELL_VAR* find_shell_variable ( char *  name) const

Definition at line 2360 of file variables.c.

References variable::dynamic_value, find_variable_nameref(), nameref_p, NULL, and var_lookup().

2362 {
2363  SHELL_VAR *var;
2364 
2365  var = var_lookup (name, shell_variables);
2366  if (var && nameref_p (var))
2367  var = find_variable_nameref (var);
2368 
2369  if (var == 0)
2370  return ((SHELL_VAR *)NULL);
2371 
2372  return (var->dynamic_value ? (*(var->dynamic_value)) (var) : var);
2373 }
#define nameref_p(var)
Definition: variables.h:149
VAR_CONTEXT * shell_variables
Definition: variables.c:107
SHELL_VAR * var_lookup(char *name, VAR_CONTEXT *vcontext) const
Definition: variables.c:1965
SHELL_VAR * find_variable_nameref(SHELL_VAR *v)
Definition: variables.c:2038
#define NULL
Definition: general.h:53
sh_var_value_func_t * dynamic_value
Definition: variables.h:86
Here is the call graph for this function:

◆ find_variable()

SHELL_VAR* find_variable ( char *  name) const

Definition at line 2377 of file variables.c.

References assigning_in_environment, executing_builtin, expanding_redir, find_variable_internal(), find_variable_nameref(), flags, FV_FORCETEMPENV, and nameref_p.

Referenced by assign_in_env(), bind_int_variable(), check_unbind_variable(), chkexport(), execute_for_command(), execute_function(), execute_in_subshell(), expr_bind_variable(), expr_streval(), get_name_for_error(), get_self(), get_string_value(), get_var_and_type(), init_funcname_var(), init_seconds_var(), initialize_shell_variables(), make_funcname_visible(), make_local_variable(), param_expand(), parameter_brace_expand_length(), parameter_brace_expand_word(), parameter_brace_transform(), printenv_builtin(), read_command(), redir_varvalue(), run_startup_files(), set_home_var(), set_if_not(), set_ppid(), set_pwd(), set_shell_var(), strip_trailing_ifs_whitespace(), strlong(), sv_funcnest(), sv_globignore(), sv_ifs(), sv_ignoreeof(), sv_locale(), sv_optind(), sv_shcompat(), sv_strict_posix(), sv_xtracefd(), uidset(), and unary_test().

2379 {
2380  SHELL_VAR *v;
2381  int flags;
2382 
2383  last_table_searched = 0;
2384  flags = 0;
2386  flags |= FV_FORCETEMPENV;
2387  v = find_variable_internal (name, flags);
2388  if (v && nameref_p (v))
2389  v = find_variable_nameref (v);
2390  return v;
2391 }
int expanding_redir
Definition: redir.c:63
#define nameref_p(var)
Definition: variables.h:149
int assigning_in_environment
Definition: subst.c:171
SHELL_VAR * find_variable_internal(char *name, int flags) const
Definition: variables.c:1988
int executing_builtin
Definition: execute_cmd.c:236
SHELL_VAR * find_variable_nameref(SHELL_VAR *v)
Definition: variables.c:2038
#define FV_FORCETEMPENV
Definition: variables.c:94
int flags
Definition: gm_loop.c:47
static HASH_TABLE * last_table_searched
Definition: variables.c:171
Here is the call graph for this function:

◆ find_variable_no_invisible()

SHELL_VAR* find_variable_no_invisible ( char *  name) const

Definition at line 2397 of file variables.c.

References assigning_in_environment, executing_builtin, expanding_redir, find_variable_internal(), find_variable_nameref(), flags, FV_FORCETEMPENV, FV_SKIPINVISIBLE, and nameref_p.

2399 {
2400  SHELL_VAR *v;
2401  int flags;
2402 
2403  last_table_searched = 0;
2404  flags = FV_SKIPINVISIBLE;
2406  flags |= FV_FORCETEMPENV;
2407  v = find_variable_internal (name, flags);
2408  if (v && nameref_p (v))
2409  v = find_variable_nameref (v);
2410  return v;
2411 }
int expanding_redir
Definition: redir.c:63
#define nameref_p(var)
Definition: variables.h:149
#define FV_SKIPINVISIBLE
Definition: variables.c:95
int assigning_in_environment
Definition: subst.c:171
SHELL_VAR * find_variable_internal(char *name, int flags) const
Definition: variables.c:1988
int executing_builtin
Definition: execute_cmd.c:236
SHELL_VAR * find_variable_nameref(SHELL_VAR *v)
Definition: variables.c:2038
#define FV_FORCETEMPENV
Definition: variables.c:94
int flags
Definition: gm_loop.c:47
static HASH_TABLE * last_table_searched
Definition: variables.c:171
Here is the call graph for this function:

◆ find_variable_for_assignment()

SHELL_VAR* find_variable_for_assignment ( char *  name) const

Definition at line 2416 of file variables.c.

References assigning_in_environment, executing_builtin, expanding_redir, find_variable_internal(), find_variable_nameref(), flags, FV_FORCETEMPENV, and nameref_p.

2418 {
2419  SHELL_VAR *v;
2420  int flags;
2421 
2422  last_table_searched = 0;
2423  flags = 0;
2425  flags |= FV_FORCETEMPENV;
2426  v = find_variable_internal (name, flags);
2427  if (v && nameref_p (v))
2428  v = find_variable_nameref (v);
2429  return v;
2430 }
int expanding_redir
Definition: redir.c:63
#define nameref_p(var)
Definition: variables.h:149
int assigning_in_environment
Definition: subst.c:171
SHELL_VAR * find_variable_internal(char *name, int flags) const
Definition: variables.c:1988
int executing_builtin
Definition: execute_cmd.c:236
SHELL_VAR * find_variable_nameref(SHELL_VAR *v)
Definition: variables.c:2038
#define FV_FORCETEMPENV
Definition: variables.c:94
int flags
Definition: gm_loop.c:47
static HASH_TABLE * last_table_searched
Definition: variables.c:171
Here is the call graph for this function:

◆ find_variable_noref()

SHELL_VAR* find_variable_noref ( char *  name) const

Definition at line 2433 of file variables.c.

References assigning_in_environment, executing_builtin, expanding_redir, find_variable_internal(), flags, and FV_FORCETEMPENV.

Referenced by bind_variable_internal(), find_variable_last_nameref(), make_local_variable(), and unary_test().

2435 {
2436  SHELL_VAR *v;
2437  int flags;
2438 
2439  flags = 0;
2441  flags |= FV_FORCETEMPENV;
2442  v = find_variable_internal (name, flags);
2443  return v;
2444 }
int expanding_redir
Definition: redir.c:63
int assigning_in_environment
Definition: subst.c:171
SHELL_VAR * find_variable_internal(char *name, int flags) const
Definition: variables.c:1988
int executing_builtin
Definition: execute_cmd.c:236
#define FV_FORCETEMPENV
Definition: variables.c:94
int flags
Definition: gm_loop.c:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_function()

SHELL_VAR* find_function ( char *  name) const

Definition at line 2449 of file variables.c.

References hash_lookup().

Referenced by bind_function(), execute_disk_command(), execute_intern_function(), execute_simple_command(), expand_word_list_internal(), initialize_shell_variables(), and set_var_read_only().

2451 {
2452  return (hash_lookup (name, shell_functions));
2453 }
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
HASH_TABLE * shell_functions
Definition: variables.c:111
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_function_def()

FUNCTION_DEF* find_function_def ( char *  name) const

Definition at line 2458 of file variables.c.

References hash_lookup().

Referenced by bind_function(), and execute_function().

2460 {
2461 #if defined (DEBUGGER)
2462  return ((FUNCTION_DEF *)hash_lookup (name, shell_function_defs));
2463 #else
2464  return ((FUNCTION_DEF *)0);
2465 #endif
2466 }
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_variable_value()

char* get_variable_value ( SHELL_VAR var)

Definition at line 2471 of file variables.c.

References array_cell, array_p, assoc_cell, assoc_p, NULL, and value_cell.

Referenced by expr_streval(), get_string_value(), make_variable_value(), redir_varvalue(), and sv_optind().

2473 {
2474  if (var == 0)
2475  return ((char *)NULL);
2476 #if defined (ARRAY_VARS)
2477  else if (array_p (var))
2478  return (array_reference (array_cell (var), 0));
2479  else if (assoc_p (var))
2480  return (assoc_reference (assoc_cell (var), "0"));
2481 #endif
2482  else
2483  return (value_cell (var));
2484 }
#define array_p(var)
Definition: variables.h:140
#define assoc_cell(var)
Definition: variables.h:169
#define NULL
Definition: general.h:53
#define assoc_p(var)
Definition: variables.h:144
#define value_cell(var)
Definition: variables.h:166
#define array_cell(var)
Definition: variables.h:168
Here is the caller graph for this function:

◆ get_string_value()

◆ sh_get_env_value()

char* sh_get_env_value ( char *  v) const

Definition at line 2503 of file variables.c.

References get_string_value().

2505 {
2506  return get_string_value (v);
2507 }
char * get_string_value(char *var_name) const
Definition: variables.c:2492
Here is the call graph for this function:

◆ var_sametype()

static int var_sametype ( SHELL_VAR v1,
SHELL_VAR v2 
)
static

Definition at line 2516 of file variables.c.

References array_p, and assoc_p.

2519 {
2520  if (v1 == 0 || v2 == 0)
2521  return 0;
2522 #if defined (ARRAY_VARS)
2523  else if (assoc_p (v1) && assoc_p (v2))
2524  return 1;
2525  else if (array_p (v1) && array_p (v2))
2526  return 1;
2527  else if (array_p (v1) || array_p (v2))
2528  return 0;
2529  else if (assoc_p (v1) || assoc_p (v2))
2530  return 0;
2531 #endif
2532  else
2533  return 1;
2534 }
#define array_p(var)
Definition: variables.h:140
#define assoc_p(var)
Definition: variables.h:144

◆ validate_inherited_value()

int validate_inherited_value ( SHELL_VAR var,
int  type 
)

Definition at line 2537 of file variables.c.

References array_p, assoc_p, att_array, and att_assoc.

2540 {
2541 #if defined (ARRAY_VARS)
2542  if (type == att_array && assoc_p (var))
2543  return 0;
2544  else if (type == att_assoc && array_p (var))
2545  return 0;
2546  else
2547 #endif
2548  return 1; /* should we run convert_var_to_array here or let the caller? */
2549 }
#define array_p(var)
Definition: variables.h:140
#define att_assoc
Definition: variables.h:110
#define att_array
Definition: variables.h:106
#define assoc_p(var)
Definition: variables.h:144

◆ set_if_not()

SHELL_VAR* set_if_not ( char *  name,
char *  value 
)

Definition at line 2553 of file variables.c.

References bind_variable_internal(), create_variable_tables(), find_variable(), HASH_NOSRCH, and var_context::table.

Referenced by initialize_shell_variables(), and set_machine_vars().

2555 {
2556  SHELL_VAR *v;
2557 
2558  if (shell_variables == 0)
2560 
2561  v = find_variable (name);
2562  if (v == 0)
2563  v = bind_variable_internal (name, value, global_variables->table, HASH_NOSRCH, 0);
2564  return (v);
2565 }
static SHELL_VAR * bind_variable_internal(char *name, char *value, HASH_TABLE *table, int hflags, int aflags) const
Definition: variables.c:3026
HASH_TABLE * table
Definition: variables.h:40
VAR_CONTEXT * shell_variables
Definition: variables.c:107
static void create_variable_tables()
Definition: variables.c:314
#define HASH_NOSRCH
Definition: hashlib.h:81
VAR_CONTEXT * global_variables
Definition: variables.c:104
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_local_variable()

SHELL_VAR* make_local_variable ( char *  name,
int  flags 
) const

Definition at line 2569 of file variables.c.

References _(), array_cell, array_p, variable::assign_func, assoc_cell, assoc_copy, assoc_p, att_exported, att_invisible, att_local, att_nameref, variable::attributes, builtin_error(), variable::context, var_context::down, variable::dynamic_value, exported_p, find_variable(), find_variable_noref(), var_context::flags, hash_create(), ifsname, internal_error(), local_p, localvar_inherit, make_new_variable(), MKLOC_INHERIT, nameref_p, no_invisible_vars, noassign_p, NULL, readonly_p, savestring(), var_context::scope, setifs(), sh_readonly(), var_context::table, TEMPENV_HASH_BUCKETS, tempvar_p, value_cell, var_setarray, var_setassoc, var_setvalue, variable_context, VC_HASLOCAL, vc_isfuncenv, VSETATTR, and VUNSETATTR.

Referenced by make_new_variable().

2572 {
2573  SHELL_VAR *new_var, *old_var, *old_ref;
2574  VAR_CONTEXT *vc;
2575  int was_tmpvar;
2576  char *old_value;
2577 
2578  /* We don't want to follow the nameref chain when making local variables; we
2579  just want to create them. */
2580  old_ref = find_variable_noref (name);
2581  if (old_ref && nameref_p (old_ref) == 0)
2582  old_ref = 0;
2583  /* local foo; local foo; is a no-op. */
2584  old_var = find_variable (name);
2585  if (old_ref == 0 && old_var && local_p (old_var) && old_var->context == variable_context)
2586  return (old_var);
2587 
2588  /* local -n foo; local -n foo; is a no-op. */
2589  if (old_ref && local_p (old_ref) && old_ref->context == variable_context)
2590  return (old_ref);
2591 
2592  /* From here on, we want to use the refvar, not the variable it references */
2593  if (old_ref)
2594  old_var = old_ref;
2595 
2596  was_tmpvar = old_var && tempvar_p (old_var);
2597  /* If we're making a local variable in a shell function, the temporary env
2598  has already been merged into the function's variable context stack. We
2599  can assume that a temporary var in the same context appears in the same
2600  VAR_CONTEXT and can safely be returned without creating a new variable
2601  (which results in duplicate names in the same VAR_CONTEXT->table */
2602  /* We can't just test tmpvar_p because variables in the temporary env given
2603  to a shell function appear in the function's local variable VAR_CONTEXT
2604  but retain their tempvar attribute. We want temporary variables that are
2605  found in temporary_env, hence the test for last_table_searched, which is
2606  set in hash_lookup and only (so far) checked here. */
2607  if (was_tmpvar && old_var->context == variable_context && last_table_searched != temporary_env)
2608  {
2609  VUNSETATTR (old_var, att_invisible); /* XXX */
2610  return (old_var);
2611  }
2612 
2613  /* If we want to change to "inherit the old variable's value" semantics,
2614  here is where to save the old value. */
2615  old_value = was_tmpvar ? value_cell (old_var) : (char *)NULL;
2616 
2617  for (vc = shell_variables; vc; vc = vc->down)
2618  if (vc_isfuncenv (vc) && vc->scope == variable_context)
2619  break;
2620 
2621  if (vc == 0)
2622  {
2623  internal_error (_("make_local_variable: no function context at current scope"));
2624  return ((SHELL_VAR *)NULL);
2625  }
2626  else if (vc->table == 0)
2628 
2629  /* Since this is called only from the local/declare/typeset code, we can
2630  call builtin_error here without worry (of course, it will also work
2631  for anything that sets this_command_name). Variables with the `noassign'
2632  attribute may not be made local. The test against old_var's context
2633  level is to disallow local copies of readonly global variables (since I
2634  believe that this could be a security hole). Readonly copies of calling
2635  function local variables are OK. */
2636  if (old_var && (noassign_p (old_var) ||
2637  (readonly_p (old_var) && old_var->context == 0)))
2638  {
2639  if (readonly_p (old_var))
2640  sh_readonly (name);
2641  else if (noassign_p (old_var))
2642  builtin_error (_("%s: variable may not be assigned value"), name);
2643 #if 0
2644  /* Let noassign variables through with a warning */
2645  if (readonly_p (old_var))
2646 #endif
2647  return ((SHELL_VAR *)NULL);
2648  }
2649 
2650  if (old_var == 0)
2651  new_var = make_new_variable (name, vc->table);
2652  else
2653  {
2654  new_var = make_new_variable (name, vc->table);
2655 
2656  /* If we found this variable in one of the temporary environments,
2657  inherit its value. Watch to see if this causes problems with
2658  things like `x=4 local x'. XXX - see above for temporary env
2659  variables with the same context level as variable_context */
2660  /* XXX - we should only do this if the variable is not an array. */
2661  /* If we want to change the local variable semantics to "inherit
2662  the old variable's value" here is where to set it. And we would
2663  need to use copy_variable (currently unused) to do it for all
2664  possible variable values. */
2665  if (was_tmpvar)
2666  var_setvalue (new_var, savestring (old_value));
2667  else if (localvar_inherit || (flags & MKLOC_INHERIT))
2668  {
2669  /* This may not make sense for nameref variables that are shadowing
2670  variables with the same name, but we don't know that yet. */
2671 #if defined (ARRAY_VARS)
2672  if (assoc_p (old_var))
2673  var_setassoc (new_var, assoc_copy (assoc_cell (old_var)));
2674  else if (array_p (old_var))
2675  var_setarray (new_var, array_copy (array_cell (old_var)));
2676  else if (value_cell (old_var))
2677 #else
2678  if (value_cell (old_var))
2679 #endif
2680  var_setvalue (new_var, savestring (value_cell (old_var)));
2681  else
2682  var_setvalue (new_var, (char *)NULL);
2683  }
2684 
2685  if (localvar_inherit || (flags & MKLOC_INHERIT))
2686  {
2687  /* It doesn't make sense to inherit the nameref attribute */
2688  new_var->attributes = old_var->attributes & ~att_nameref;
2689  new_var->dynamic_value = old_var->dynamic_value;
2690  new_var->assign_func = old_var->assign_func;
2691  }
2692  else
2693  /* We inherit the export attribute, but no others. */
2694  new_var->attributes = exported_p (old_var) ? att_exported : 0;
2695  }
2696 
2697  vc->flags |= VC_HASLOCAL;
2698 
2699  new_var->context = variable_context;
2700  VSETATTR (new_var, att_local);
2701 
2702  if (ifsname (name))
2703  setifs (new_var);
2704 
2705  /* value_cell will be 0 if localvar_inherit == 0 or there was no old variable
2706  with the same name or the old variable was invisible */
2707  if (was_tmpvar == 0 && no_invisible_vars == 0 && value_cell (new_var) == 0)
2708  VSETATTR (new_var, att_invisible); /* XXX */
2709  return (new_var);
2710 }
HASH_TABLE * table
Definition: variables.h:40
#define nameref_p(var)
Definition: variables.h:149
HASH_TABLE * hash_create(int buckets)
Definition: hashlib.c:46
#define ifsname(s)
Definition: variables.h:222
#define array_p(var)
Definition: variables.h:140
#define exported_p(var)
Definition: variables.h:138
#define att_invisible
Definition: variables.h:122
#define assoc_copy(h)
Definition: assoc.h:33
#define var_setarray(var, arr)
Definition: variables.h:181
HASH_TABLE * temporary_env
Definition: variables.c:136
#define var_setvalue(var, str)
Definition: variables.h:179
#define assoc_cell(var)
Definition: variables.h:169
#define MKLOC_INHERIT
Definition: variables.h:225
#define noassign_p(var)
Definition: variables.h:153
void builtin_error(char *format, va_alist) const
Definition: common.c:106
#define readonly_p(var)
Definition: variables.h:139
int localvar_inherit
Definition: variables.c:127
int attributes
Definition: variables.h:92
VAR_CONTEXT * shell_variables
Definition: variables.c:107
char * savestring(const char *s)
Definition: savestring.c:33
void xs_init _((void))
SHELL_VAR * find_variable_noref(char *name) const
Definition: variables.c:2433
#define var_setassoc(var, arr)
Definition: variables.h:182
void setifs(SHELL_VAR *v)
Definition: subst.c:10688
#define VUNSETATTR(var, attr)
Definition: variables.h:194
static SHELL_VAR * make_new_variable(char *name, HASH_TABLE *table) const
Definition: variables.c:2741
int variable_context
Definition: variables.c:123
#define TEMPENV_HASH_BUCKETS
Definition: variables.c:85
#define NULL
Definition: general.h:53
void internal_error(char *format, va_alist) const
Definition: error.c:235
sh_var_value_func_t * dynamic_value
Definition: variables.h:86
int flags
Definition: gm_loop.c:47
#define tempvar_p(var)
Definition: variables.h:159
static HASH_TABLE * last_table_searched
Definition: variables.c:171
#define att_local
Definition: variables.h:109
#define vc_isfuncenv(vc)
Definition: variables.h:53
int context
Definition: variables.h:93
#define VC_HASLOCAL
Definition: variables.h:44
#define local_p(var)
Definition: variables.h:143
#define att_nameref
Definition: variables.h:115
#define assoc_p(var)
Definition: variables.h:144
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_exported
Definition: variables.h:104
void sh_readonly(char *s) const
Definition: common.c:263
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
int no_invisible_vars
Definition: flags.c:116
sh_var_assign_func_t * assign_func
Definition: variables.h:89
#define value_cell(var)
Definition: variables.h:166
#define array_cell(var)
Definition: variables.h:168
struct var_context * down
Definition: variables.h:39
Here is the caller graph for this function:

◆ new_shell_variable()

static SHELL_VAR* new_shell_variable ( char *  name) const
static

Definition at line 2714 of file variables.c.

References variable::assign_func, variable::attributes, CLEAR_EXPORTSTR, variable::context, variable::dynamic_value, variable::name, NULL, savestring(), var_setvalue, and xmalloc().

Referenced by bind_function(), and make_new_variable().

2716 {
2717  SHELL_VAR *entry;
2718 
2719  entry = (SHELL_VAR *)xmalloc (sizeof (SHELL_VAR));
2720 
2721  entry->name = savestring (name);
2722  var_setvalue (entry, (char *)NULL);
2723  CLEAR_EXPORTSTR (entry);
2724 
2725  entry->dynamic_value = (sh_var_value_func_t *)NULL;
2726  entry->assign_func = (sh_var_assign_func_t *)NULL;
2727 
2728  entry->attributes = 0;
2729 
2730  /* Always assume variables are to be made at toplevel!
2731  make_local_variable has the responsibility of changing the
2732  variable context. */
2733  entry->context = 0;
2734 
2735  return (entry);
2736 }
#define var_setvalue(var, str)
Definition: variables.h:179
int attributes
Definition: variables.h:92
char * savestring(const char *s)
Definition: savestring.c:33
#define CLEAR_EXPORTSTR(var)
Definition: variables.h:202
#define NULL
Definition: general.h:53
sh_var_value_func_t * dynamic_value
Definition: variables.h:86
int context
Definition: variables.h:93
char * name
Definition: variables.h:83
sh_var_assign_func_t * assign_func
Definition: variables.h:89
static char * xmalloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_new_variable()

static SHELL_VAR* make_new_variable ( char *  name,
HASH_TABLE table 
) const
static

Definition at line 2741 of file variables.c.

References array_create(), array_p, assoc_create, assoc_p, att_array, att_assoc, create_variable_tables(), bucket_contents::data, dispose_variable_value(), hash_insert(), HASH_NOSRCH, internal_warning(), localvar_inherit, make_local_variable(), new_shell_variable(), PTR_T, savestring(), var_context::table, var_setarray, var_setassoc, VSETATTR, and VUNSETATTR.

Referenced by assign_in_env(), bind_variable_internal(), and make_local_variable().

2744 {
2745  SHELL_VAR *entry;
2746  BUCKET_CONTENTS *elt;
2747 
2748  entry = new_shell_variable (name);
2749 
2750  /* Make sure we have a shell_variables hash table to add to. */
2751  if (shell_variables == 0)
2753 
2754  elt = hash_insert (savestring (name), table, HASH_NOSRCH);
2755  elt->data = (PTR_T)entry;
2756 
2757  return entry;
2758 }
#define PTR_T
Definition: hashlib.h:30
BUCKET_CONTENTS * hash_insert(char *string, HASH_TABLE *table, int flags)
Definition: hashlib.c:246
VAR_CONTEXT * shell_variables
Definition: variables.c:107
static void create_variable_tables()
Definition: variables.c:314
char * savestring(const char *s)
Definition: savestring.c:33
#define HASH_NOSRCH
Definition: hashlib.h:81
static SHELL_VAR * new_shell_variable(char *name) const
Definition: variables.c:2714
char * data
Definition: hashlib.h:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_variable_value()

char* make_variable_value ( SHELL_VAR var,
char *  value,
int  flags 
)

Definition at line 2869 of file variables.c.

References ASS_APPEND, ASS_NOEVAL, ASS_NOLONGJMP, capcase_p, CASE_CAPITALIZE, CASE_LOWER, CASE_UPPER, DISCARD, evalexp(), free(), get_variable_value(), integer_p, itos(), jump_to_top_level(), lowercase_p, NULL, savestring(), sh_modcase(), strcpy(), STRLEN, top_level_cleanup(), uppercase_p, value_cell, and xmalloc().

Referenced by assign_in_env(), bind_variable_internal(), and bind_variable_value().

2873 {
2874  char *retval, *oval;
2875  intmax_t lval, rval;
2876  int expok, olen, op;
2877 
2878  /* If this variable has had its type set to integer (via `declare -i'),
2879  then do expression evaluation on it and store the result. The
2880  functions in expr.c (evalexp()) and bind_int_variable() are responsible
2881  for turning off the integer flag if they don't want further
2882  evaluation done. Callers that find it inconvenient to do this can set
2883  the ASS_NOEVAL flag. For the special case of arithmetic expression
2884  evaluation, the caller can set ASS_NOLONGJMP to avoid jumping out to
2885  top_level. */
2886  if ((flags & ASS_NOEVAL) == 0 && integer_p (var))
2887  {
2888  if (flags & ASS_APPEND)
2889  {
2890  oval = value_cell (var);
2891  lval = evalexp (oval, 0, &expok); /* ksh93 seems to do this */
2892  if (expok == 0)
2893  {
2894  if (flags & ASS_NOLONGJMP)
2895  goto make_value;
2896  else
2897  {
2898  top_level_cleanup ();
2900  }
2901  }
2902  }
2903  rval = evalexp (value, 0, &expok);
2904  if (expok == 0)
2905  {
2906  if (flags & ASS_NOLONGJMP)
2907  goto make_value;
2908  else
2909  {
2910  top_level_cleanup ();
2912  }
2913  }
2914  /* This can be fooled if the variable's value changes while evaluating
2915  `rval'. We can change it if we move the evaluation of lval to here. */
2916  if (flags & ASS_APPEND)
2917  rval += lval;
2918  retval = itos (rval);
2919  }
2920 #if defined (CASEMOD_ATTRS)
2921  else if ((flags & ASS_NOEVAL) == 0 && (capcase_p (var) || uppercase_p (var) || lowercase_p (var)))
2922  {
2923  if (flags & ASS_APPEND)
2924  {
2925  oval = get_variable_value (var);
2926  if (oval == 0) /* paranoia */
2927  oval = "";
2928  olen = STRLEN (oval);
2929  retval = (char *)xmalloc (olen + (value ? STRLEN (value) : 0) + 1);
2930  strcpy (retval, oval);
2931  if (value)
2932  strcpy (retval+olen, value);
2933  }
2934  else if (*value)
2935  retval = savestring (value);
2936  else
2937  {
2938  retval = (char *)xmalloc (1);
2939  retval[0] = '\0';
2940  }
2941  op = capcase_p (var) ? CASE_CAPITALIZE
2942  : (uppercase_p (var) ? CASE_UPPER : CASE_LOWER);
2943  oval = sh_modcase (retval, (char *)0, op);
2944  free (retval);
2945  retval = oval;
2946  }
2947 #endif /* CASEMOD_ATTRS */
2948  else if (value)
2949  {
2950 make_value:
2951  if (flags & ASS_APPEND)
2952  {
2953  oval = get_variable_value (var);
2954  if (oval == 0) /* paranoia */
2955  oval = "";
2956  olen = STRLEN (oval);
2957  retval = (char *)xmalloc (olen + (value ? STRLEN (value) : 0) + 1);
2958  strcpy (retval, oval);
2959  if (value)
2960  strcpy (retval+olen, value);
2961  }
2962  else if (*value)
2963  retval = savestring (value);
2964  else
2965  {
2966  retval = (char *)xmalloc (1);
2967  retval[0] = '\0';
2968  }
2969  }
2970  else
2971  retval = (char *)NULL;
2972 
2973  return retval;
2974 }
void top_level_cleanup()
Definition: sig.c:372
#define integer_p(var)
Definition: variables.h:142
#define DISCARD
Definition: bashjmp.h:41
#define ASS_NOLONGJMP
Definition: subst.h:56
#define STRLEN(s)
Definition: general.h:171
void jump_to_top_level(int value)
Definition: sig.c:461
char * get_variable_value(SHELL_VAR *var)
Definition: variables.c:2471
#define CASE_UPPER
Definition: externs.h:181
#define lowercase_p(var)
Definition: variables.h:147
char * savestring(const char *s)
Definition: savestring.c:33
char * strcpy()
intmax_t evalexp(char *expr, int flags, int *validp)
Definition: expr.c:405
void free()
#define capcase_p(var)
Definition: variables.h:148
char * itos(intmax_t i)
Definition: itos.c:44
char * sh_modcase(char *string, char *pat, int flags) const
Definition: casemod.c:103
#define ASS_NOEVAL
Definition: subst.h:55
#define CASE_CAPITALIZE
Definition: externs.h:182
#define NULL
Definition: general.h:53
int flags
Definition: gm_loop.c:47
#define uppercase_p(var)
Definition: variables.h:146
#define ASS_APPEND
Definition: subst.h:47
static char * xmalloc()
#define CASE_LOWER
Definition: externs.h:180
#define value_cell(var)
Definition: variables.h:166
Here is the caller graph for this function:

◆ can_optimize_assignment()

static int can_optimize_assignment ( SHELL_VAR entry,
char *  value,
int  aflags 
)
static

Definition at line 2978 of file variables.c.

References array_p, ASS_APPEND, assoc_p, capcase_p, integer_p, lowercase_p, noassign_p, readonly_p, and uppercase_p.

Referenced by bind_variable_internal().

2982 {
2983  if ((aflags & ASS_APPEND) == 0)
2984  return 0;
2985 #if defined (ARRAY_VARS)
2986  if (array_p (entry) || assoc_p (entry))
2987  return 0;
2988 #endif
2989  if (integer_p (entry) || uppercase_p (entry) || lowercase_p (entry) || capcase_p (entry))
2990  return 0;
2991  if (readonly_p (entry) || noassign_p (entry))
2992  return 0;
2993  return 1;
2994 }
#define integer_p(var)
Definition: variables.h:142
#define array_p(var)
Definition: variables.h:140
#define noassign_p(var)
Definition: variables.h:153
#define readonly_p(var)
Definition: variables.h:139
#define lowercase_p(var)
Definition: variables.h:147
#define capcase_p(var)
Definition: variables.h:148
#define uppercase_p(var)
Definition: variables.h:146
#define assoc_p(var)
Definition: variables.h:144
#define ASS_APPEND
Definition: subst.h:47
Here is the caller graph for this function:

◆ optimized_assignment()

static SHELL_VAR* optimized_assignment ( SHELL_VAR entry,
char *  value,
int  aflags 
)
static

Definition at line 2998 of file variables.c.

References strcpy(), STRLEN, value_cell, var_setvalue, and xrealloc().

Referenced by bind_variable_internal().

3002 {
3003  size_t len, vlen;
3004  char *v, *new;
3005 
3006  v = value_cell (entry);
3007  len = STRLEN (v);
3008  vlen = STRLEN (value);
3009 
3010  new = (char *)xrealloc (v, len + vlen + 8); /* for now */
3011  if (vlen == 1)
3012  {
3013  new[len] = *value;
3014  new[len+1] = '\0';
3015  }
3016  else
3017  strcpy (new + len, value);
3018  var_setvalue (entry, new);
3019  return entry;
3020 }
#define STRLEN(s)
Definition: general.h:171
#define var_setvalue(var, str)
Definition: variables.h:179
char * strcpy()
static char * xrealloc()
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_variable_internal()

static SHELL_VAR* bind_variable_internal ( char *  name,
char *  value,
HASH_TABLE table,
int  hflags,
int  aflags 
) const
static

Definition at line 3026 of file variables.c.

References _(), array_cell, array_needs_making, array_p, ASS_APPEND, ASS_FORCE, ASS_NAMEREF, variable::assign_func, assoc_cell, assoc_p, att_exported, att_invisible, att_nameref, can_optimize_assignment(), err_readonly(), exported_p, find_global_variable(), find_variable_last_nameref(), find_variable_noref(), free(), FREE, hash_lookup(), HASH_NOSRCH, internal_warning(), INVALIDATE_EXPORTSTR, invisible_p, make_new_variable(), make_variable_value(), mark_modified_vars, variable::name, name_cell, nameref_cell, nameref_p, noassign_p, NULL, optimized_assignment(), readonly_p, savestring(), sh_invalidid(), var_context::table, valid_nameref_value(), value_cell, var_setvalue, VSETATTR, and VUNSETATTR.

Referenced by bind_global_variable(), bind_invalid_envvar(), bind_variable(), push_exported_var(), push_posix_temp_var(), push_posix_tempvar_internal(), push_temp_var(), and set_if_not().

3031 {
3032  char *newval, *tname;
3033  SHELL_VAR *entry, *tentry;
3034 
3035  entry = (hflags & HASH_NOSRCH) ? (SHELL_VAR *)NULL : hash_lookup (name, table);
3036  /* Follow the nameref chain here if this is the global variables table */
3037  if (entry && nameref_p (entry) && (invisible_p (entry) == 0) && table == global_variables->table)
3038  {
3039  entry = find_global_variable (entry->name);
3040  /* Let's see if we have a nameref referencing a variable that hasn't yet
3041  been created. */
3042  if (entry == 0)
3043  entry = find_variable_last_nameref (name, 0); /* XXX */
3044  if (entry == 0) /* just in case */
3045  return (entry);
3046  }
3047 
3048  /* The first clause handles `declare -n ref; ref=x;' or `declare -n ref;
3049  declare -n ref' */
3050  if (entry && invisible_p (entry) && nameref_p (entry))
3051  {
3052  if ((aflags & ASS_FORCE) == 0 && value && valid_nameref_value (value, 0) == 0)
3053  {
3054  sh_invalidid (value);
3055  return ((SHELL_VAR *)NULL);
3056  }
3057  goto assign_value;
3058  }
3059  else if (entry && nameref_p (entry))
3060  {
3061  newval = nameref_cell (entry); /* XXX - newval can't be NULL here */
3062  if (valid_nameref_value (newval, 0) == 0)
3063  {
3064  sh_invalidid (newval);
3065  return ((SHELL_VAR *)NULL);
3066  }
3067 #if defined (ARRAY_VARS)
3068  /* declare -n foo=x[2] ; foo=bar */
3069  if (valid_array_reference (newval, 0))
3070  {
3071  tname = array_variable_name (newval, 0, (char **)0, (int *)0);
3072  if (tname && (tentry = find_variable_noref (tname)) && nameref_p (tentry))
3073  {
3074  /* nameref variables can't be arrays */
3075  internal_warning (_("%s: removing nameref attribute"), name_cell (tentry));
3076  FREE (value_cell (tentry)); /* XXX - bash-4.3 compat */
3077  var_setvalue (tentry, (char *)NULL);
3078  VUNSETATTR (tentry, att_nameref);
3079  }
3080  free (tname);
3081  /* XXX - should it be aflags? */
3082  entry = assign_array_element (newval, make_variable_value (entry, value, aflags), aflags|ASS_NAMEREF);
3083  if (entry == 0)
3084  return entry;
3085  }
3086  else
3087 #endif
3088  {
3089  entry = make_new_variable (newval, table);
3090  var_setvalue (entry, make_variable_value (entry, value, aflags));
3091  }
3092  }
3093  else if (entry == 0)
3094  {
3095  entry = make_new_variable (name, table);
3096  var_setvalue (entry, make_variable_value (entry, value, aflags)); /* XXX */
3097  }
3098  else if (entry->assign_func) /* array vars have assign functions now */
3099  {
3100  INVALIDATE_EXPORTSTR (entry);
3101  newval = (aflags & ASS_APPEND) ? make_variable_value (entry, value, aflags) : value;
3102  if (assoc_p (entry))
3103  entry = (*(entry->assign_func)) (entry, newval, -1, savestring ("0"));
3104  else if (array_p (entry))
3105  entry = (*(entry->assign_func)) (entry, newval, 0, 0);
3106  else
3107  entry = (*(entry->assign_func)) (entry, newval, -1, 0);
3108  if (newval != value)
3109  free (newval);
3110  return (entry);
3111  }
3112  else
3113  {
3114 assign_value:
3115  if ((readonly_p (entry) && (aflags & ASS_FORCE) == 0) || noassign_p (entry))
3116  {
3117  if (readonly_p (entry))
3118  err_readonly (name_cell (entry));
3119  return (entry);
3120  }
3121 
3122  /* Variables which are bound are visible. */
3123  VUNSETATTR (entry, att_invisible);
3124 
3125  /* If we can optimize the assignment, do so and return. Right now, we
3126  optimize appends to string variables. */
3127  if (can_optimize_assignment (entry, value, aflags))
3128  {
3129  INVALIDATE_EXPORTSTR (entry);
3130  optimized_assignment (entry, value, aflags);
3131 
3132  if (mark_modified_vars)
3133  VSETATTR (entry, att_exported);
3134 
3135  if (exported_p (entry))
3136  array_needs_making = 1;
3137 
3138  return (entry);
3139  }
3140 
3141 #if defined (ARRAY_VARS)
3142  if (assoc_p (entry) || array_p (entry))
3143  newval = make_array_variable_value (entry, 0, "0", value, aflags);
3144  else
3145 #endif
3146  newval = make_variable_value (entry, value, aflags); /* XXX */
3147 
3148  /* Invalidate any cached export string */
3149  INVALIDATE_EXPORTSTR (entry);
3150 
3151 #if defined (ARRAY_VARS)
3152  /* XXX -- this bears looking at again -- XXX */
3153  /* If an existing array variable x is being assigned to with x=b or
3154  `read x' or something of that nature, silently convert it to
3155  x[0]=b or `read x[0]'. */
3156  if (assoc_p (entry))
3157  {
3158  assoc_insert (assoc_cell (entry), savestring ("0"), newval);
3159  free (newval);
3160  }
3161  else if (array_p (entry))
3162  {
3163  array_insert (array_cell (entry), 0, newval);
3164  free (newval);
3165  }
3166  else
3167 #endif
3168  {
3169  FREE (value_cell (entry));
3170  var_setvalue (entry, newval);
3171  }
3172  }
3173 
3174  if (mark_modified_vars)
3175  VSETATTR (entry, att_exported);
3176 
3177  if (exported_p (entry))
3178  array_needs_making = 1;
3179 
3180  return (entry);
3181 }
#define ASS_NAMEREF
Definition: subst.h:51
HASH_TABLE * table
Definition: variables.h:40
#define nameref_p(var)
Definition: variables.h:149
void sh_invalidid(char *s)
Definition: common.c:227
char * make_variable_value(SHELL_VAR *var, char *value, int flags)
Definition: variables.c:2869
#define invisible_p(var)
Definition: variables.h:151
#define array_p(var)
Definition: variables.h:140
#define exported_p(var)
Definition: variables.h:138
static int can_optimize_assignment(SHELL_VAR *entry, char *value, int aflags)
Definition: variables.c:2978
#define att_invisible
Definition: variables.h:122
SHELL_VAR * find_global_variable(char *name) const
Definition: variables.c:2330
#define var_setvalue(var, str)
Definition: variables.h:179
#define assoc_cell(var)
Definition: variables.h:169
int valid_nameref_value(char *name, int flags) const
Definition: general.c:239
SHELL_VAR * find_variable_last_nameref(char *name, int vflags) const
Definition: variables.c:2079
#define noassign_p(var)
Definition: variables.h:153
#define readonly_p(var)
Definition: variables.h:139
int array_needs_making
Definition: variables.c:151
char * savestring(const char *s)
Definition: savestring.c:33
void xs_init _((void))
SHELL_VAR * find_variable_noref(char *name) const
Definition: variables.c:2433
void free()
#define VUNSETATTR(var, attr)
Definition: variables.h:194
static SHELL_VAR * make_new_variable(char *name, HASH_TABLE *table) const
Definition: variables.c:2741
#define HASH_NOSRCH
Definition: hashlib.h:81
void internal_warning(char *format, va_alist) const
Definition: error.c:256
#define NULL
Definition: general.h:53
void err_readonly(char *s) const
Definition: error.c:507
#define nameref_cell(var)
Definition: variables.h:170
#define FREE(s)
Definition: general.h:172
#define ASS_FORCE
Definition: subst.h:52
#define INVALIDATE_EXPORTSTR(var)
Definition: variables.h:213
int mark_modified_vars
Definition: flags.c:47
static SHELL_VAR * optimized_assignment(SHELL_VAR *entry, char *value, int aflags)
Definition: variables.c:2998
char * name
Definition: variables.h:83
#define name_cell(var)
Definition: variables.h:163
#define att_nameref
Definition: variables.h:115
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
#define assoc_p(var)
Definition: variables.h:144
#define VSETATTR(var, attr)
Definition: variables.h:193
VAR_CONTEXT * global_variables
Definition: variables.c:104
#define att_exported
Definition: variables.h:104
#define ASS_APPEND
Definition: subst.h:47
sh_var_assign_func_t * assign_func
Definition: variables.h:89
#define value_cell(var)
Definition: variables.h:166
#define array_cell(var)
Definition: variables.h:168
Here is the caller graph for this function:

◆ bind_variable()

SHELL_VAR* bind_variable ( char *  name,
char *  value,
int  flags 
) const

Definition at line 3188 of file variables.c.

References _(), ASS_NAMEREF, bind_tempenv_variable(), bind_variable_internal(), bind_variable_value(), create_variable_tables(), var_context::down, find_variable_last_nameref_context(), find_variable_nameref_context(), hash_lookup(), internal_warning(), variable::name, nameref_cell, nameref_p, var_context::table, vc_isbltnenv, and vc_isfuncenv.

Referenced by adjust_shell_level(), bind_int_variable(), bind_lastarg(), check_mail(), do_assignment_internal(), execute_for_command(), execute_in_subshell(), initialize_shell_variables(), main(), parameter_brace_expand_rhs(), run_startup_files(), set_home_var(), set_ppid(), set_pwd(), set_shell_var(), sh_set_lines_and_columns(), strlong(), uidset(), and yyparse().

3192 {
3193  SHELL_VAR *v, *nv;
3194  VAR_CONTEXT *vc, *nvc;
3195 
3196  if (shell_variables == 0)
3198 
3199  /* If we have a temporary environment, look there first for the variable,
3200  and, if found, modify the value there before modifying it in the
3201  shell_variables table. This allows sourced scripts to modify values
3202  given to them in a temporary environment while modifying the variable
3203  value that the caller sees. */
3204  if (temporary_env && value) /* XXX - can value be null here? */
3205  bind_tempenv_variable (name, value);
3206 
3207  /* XXX -- handle local variables here. */
3208  for (vc = shell_variables; vc; vc = vc->down)
3209  {
3210  if (vc_isfuncenv (vc) || vc_isbltnenv (vc))
3211  {
3212  v = hash_lookup (name, vc->table);
3213  nvc = vc;
3214  if (v && nameref_p (v))
3215  {
3216  nv = find_variable_nameref_context (v, vc, &nvc);
3217  if (nv == 0)
3218  {
3219  nv = find_variable_last_nameref_context (v, vc, &nvc);
3220  if (nv && nameref_p (nv))
3221  {
3222  /* If this nameref variable doesn't have a value yet,
3223  set the value. Otherwise, assign using the value as
3224  normal. */
3225  if (nameref_cell (nv) == 0)
3226  return (bind_variable_internal (nv->name, value, nvc->table, 0, flags));
3227 #if defined (ARRAY_VARS)
3228  else if (valid_array_reference (nameref_cell (nv), 0))
3229  return (assign_array_element (nameref_cell (nv), value, flags));
3230  else
3231 #endif
3232  return (bind_variable_internal (nameref_cell (nv), value, nvc->table, 0, flags));
3233  }
3234  else if (nv == &nameref_maxloop_value)
3235  {
3236  internal_warning (_("%s: circular name reference"), v->name);
3237 #if 0
3238  return (bind_variable_value (v, value, flags|ASS_NAMEREF));
3239 #else
3240  v = 0; /* backwards compat */
3241 #endif
3242  }
3243  else
3244  v = nv;
3245  }
3246  else if (nv == &nameref_maxloop_value)
3247  {
3248  internal_warning (_("%s: circular name reference"), v->name);
3249 #if 0
3250  return (bind_variable_value (v, value, flags|ASS_NAMEREF));
3251 #else
3252  v = 0; /* backwards compat */
3253 #endif
3254  }
3255  else
3256  v = nv;
3257  }
3258  if (v)
3259  return (bind_variable_internal (v->name, value, nvc->table, 0, flags));
3260  }
3261  }
3262  /* bind_variable_internal will handle nameref resolution in this case */
3263  return (bind_variable_internal (name, value, global_variables->table, 0, flags));
3264 }
static SHELL_VAR * bind_tempenv_variable(char *name, char *value) const
Definition: variables.c:4391
#define ASS_NAMEREF
Definition: subst.h:51
static SHELL_VAR * bind_variable_internal(char *name, char *value, HASH_TABLE *table, int hflags, int aflags) const
Definition: variables.c:3026
HASH_TABLE * table
Definition: variables.h:40
#define nameref_p(var)
Definition: variables.h:149
static SHELL_VAR * find_variable_nameref_context(SHELL_VAR *v, VAR_CONTEXT *vc, VAR_CONTEXT **nvcp)
Definition: variables.c:2167
static SHELL_VAR nameref_maxloop_value
Definition: variables.c:169
HASH_TABLE * temporary_env
Definition: variables.c:136
static SHELL_VAR * find_variable_last_nameref_context(SHELL_VAR *v, VAR_CONTEXT *vc, VAR_CONTEXT **nvcp)
Definition: variables.c:2198
VAR_CONTEXT * shell_variables
Definition: variables.c:107
static void create_variable_tables()
Definition: variables.c:314
void xs_init _((void))
SHELL_VAR * bind_variable_value(SHELL_VAR *var, char *value, int aflags)
Definition: variables.c:3296
void internal_warning(char *format, va_alist) const
Definition: error.c:256
#define nameref_cell(var)
Definition: variables.h:170
int flags
Definition: gm_loop.c:47
#define vc_isfuncenv(vc)
Definition: variables.h:53
#define vc_isbltnenv(vc)
Definition: variables.h:54
char * name
Definition: variables.h:83
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
VAR_CONTEXT * global_variables
Definition: variables.c:104
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:

◆ bind_global_variable()

SHELL_VAR* bind_global_variable ( char *  name,
char *  value,
int  flags 
) const

Definition at line 3267 of file variables.c.

References bind_variable_internal(), create_variable_tables(), and var_context::table.

3271 {
3272  if (shell_variables == 0)
3274 
3275  /* bind_variable_internal will handle nameref resolution in this case */
3276  return (bind_variable_internal (name, value, global_variables->table, 0, flags));
3277 }
static SHELL_VAR * bind_variable_internal(char *name, char *value, HASH_TABLE *table, int hflags, int aflags) const
Definition: variables.c:3026
HASH_TABLE * table
Definition: variables.h:40
VAR_CONTEXT * shell_variables
Definition: variables.c:107
static void create_variable_tables()
Definition: variables.c:314
int flags
Definition: gm_loop.c:47
VAR_CONTEXT * global_variables
Definition: variables.c:104
Here is the call graph for this function:

◆ bind_invalid_envvar()

static SHELL_VAR* bind_invalid_envvar ( char *  name,
char *  value,
int  flags 
) const
static

Definition at line 3280 of file variables.c.

References bind_variable_internal(), hash_create(), and HASH_NOSRCH.

Referenced by initialize_shell_variables().

3284 {
3285  if (invalid_env == 0)
3286  invalid_env = hash_create (64); /* XXX */
3287  return (bind_variable_internal (name, value, invalid_env, HASH_NOSRCH, flags));
3288 }
static SHELL_VAR * bind_variable_internal(char *name, char *value, HASH_TABLE *table, int hflags, int aflags) const
Definition: variables.c:3026
HASH_TABLE * hash_create(int buckets)
Definition: hashlib.c:46
HASH_TABLE * invalid_env
Definition: variables.c:113
#define HASH_NOSRCH
Definition: hashlib.h:81
int flags
Definition: gm_loop.c:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_variable_value()

SHELL_VAR* bind_variable_value ( SHELL_VAR var,
char *  value,
int  aflags 
)

Definition at line 3296 of file variables.c.

References _(), array_needs_making, ASS_APPEND, ASS_FORCE, ASS_NAMEREF, variable::assign_func, att_exported, att_invisible, check_selfref(), exported_p, free(), FREE, internal_error(), internal_warning(), INVALIDATE_EXPORTSTR, invisible_p, make_variable_value(), mark_modified_vars, name_cell, NULL, t, valid_nameref_value(), value_cell, var_setvalue, variable_context, VSETATTR, and VUNSETATTR.

Referenced by bind_variable(), and execute_for_command().

3300 {
3301  char *t;
3302  int invis;
3303 
3304  invis = invisible_p (var);
3305  VUNSETATTR (var, att_invisible);
3306 
3307  if (var->assign_func)
3308  {
3309  /* If we're appending, we need the old value, so use
3310  make_variable_value */
3311  t = (aflags & ASS_APPEND) ? make_variable_value (var, value, aflags) : value;
3312  (*(var->assign_func)) (var, t, -1, 0);
3313  if (t != value && t)
3314  free (t);
3315  }
3316  else
3317  {
3318  t = make_variable_value (var, value, aflags);
3319  if ((aflags & (ASS_NAMEREF|ASS_FORCE)) == ASS_NAMEREF && check_selfref (name_cell (var), t, 0))
3320  {
3321  if (variable_context)
3322  internal_warning (_("%s: circular name reference"), name_cell (var));
3323  else
3324  {
3325  internal_error (_("%s: nameref variable self references not allowed"), name_cell (var));
3326  free (t);
3327  if (invis)
3328  VSETATTR (var, att_invisible); /* XXX */
3329  return ((SHELL_VAR *)NULL);
3330  }
3331  }
3332  if ((aflags & ASS_NAMEREF) && (valid_nameref_value (t, 0) == 0))
3333  {
3334  free (t);
3335  if (invis)
3336  VSETATTR (var, att_invisible); /* XXX */
3337  return ((SHELL_VAR *)NULL);
3338  }
3339  FREE (value_cell (var));
3340  var_setvalue (var, t);
3341  }
3342 
3343  INVALIDATE_EXPORTSTR (var);
3344 
3345  if (mark_modified_vars)
3346  VSETATTR (var, att_exported);
3347 
3348  if (exported_p (var))
3349  array_needs_making = 1;
3350 
3351  return (var);
3352 }
#define ASS_NAMEREF
Definition: subst.h:51
char * make_variable_value(SHELL_VAR *var, char *value, int flags)
Definition: variables.c:2869
#define invisible_p(var)
Definition: variables.h:151
#define exported_p(var)
Definition: variables.h:138
#define att_invisible
Definition: variables.h:122
#define var_setvalue(var, str)
Definition: variables.h:179
int valid_nameref_value(char *name, int flags) const
Definition: general.c:239
int array_needs_making
Definition: variables.c:151
int check_selfref(char *name, char *value, int flags) const
Definition: general.c:258
int t
Definition: gm_loop.c:77
void xs_init _((void))
void free()
#define VUNSETATTR(var, attr)
Definition: variables.h:194
int variable_context
Definition: variables.c:123
void internal_warning(char *format, va_alist) const
Definition: error.c:256
#define NULL
Definition: general.h:53
void internal_error(char *format, va_alist) const
Definition: error.c:235
#define FREE(s)
Definition: general.h:172
#define ASS_FORCE
Definition: subst.h:52
#define INVALIDATE_EXPORTSTR(var)
Definition: variables.h:213
int mark_modified_vars
Definition: flags.c:47
#define name_cell(var)
Definition: variables.h:163
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_exported
Definition: variables.h:104
#define ASS_APPEND
Definition: subst.h:47
sh_var_assign_func_t * assign_func
Definition: variables.h:89
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_int_variable()

SHELL_VAR* bind_int_variable ( char *  lhs,
char *  rhs,
int  flags 
)

Definition at line 3365 of file variables.c.

References _(), array_p, ASS_NOEXPAND, att_integer, att_invisible, bind_variable(), find_variable(), integer_p, internal_warning(), legal_identifier(), nameref_p, NULL, sh_invalidid(), VSETATTR, and VUNSETATTR.

Referenced by bind_var_to_int(), and expr_bind_variable().

3368 {
3369  register SHELL_VAR *v;
3370  int isint, isarr, implicitarray;
3371 
3372  isint = isarr = implicitarray = 0;
3373 #if defined (ARRAY_VARS)
3374  if (valid_array_reference (lhs, (flags & ASS_NOEXPAND) != 0))
3375  {
3376  isarr = 1;
3377  v = array_variable_part (lhs, (flags & ASS_NOEXPAND) != 0, (char **)0, (int *)0);
3378  }
3379  else if (legal_identifier (lhs) == 0)
3380  {
3381  sh_invalidid (lhs);
3382  return ((SHELL_VAR *)NULL);
3383  }
3384  else
3385 #endif
3386  v = find_variable (lhs);
3387 
3388  if (v)
3389  {
3390  isint = integer_p (v);
3391  VUNSETATTR (v, att_integer);
3392 #if defined (ARRAY_VARS)
3393  if (array_p (v) && isarr == 0)
3394  implicitarray = 1;
3395 #endif
3396  }
3397 
3398 #if defined (ARRAY_VARS)
3399  if (isarr)
3400  v = assign_array_element (lhs, rhs, flags);
3401  else if (implicitarray)
3402  v = bind_array_variable (lhs, 0, rhs, 0); /* XXX - check on flags */
3403  else
3404 #endif
3405  v = bind_variable (lhs, rhs, 0); /* why not use bind_variable_value? */
3406 
3407  if (v)
3408  {
3409  if (isint)
3410  VSETATTR (v, att_integer);
3412  }
3413 
3414  if (v && nameref_p (v))
3415  internal_warning (_("%s: assigning integer to name reference"), lhs);
3416 
3417  return (v);
3418 }
#define nameref_p(var)
Definition: variables.h:149
#define integer_p(var)
Definition: variables.h:142
void sh_invalidid(char *s)
Definition: common.c:227
#define array_p(var)
Definition: variables.h:140
#define att_invisible
Definition: variables.h:122
SHELL_VAR * bind_variable(char *name, char *value, int flags) const
Definition: variables.c:3188
int legal_identifier(char *name) const
Definition: general.c:216
void xs_init _((void))
#define VUNSETATTR(var, attr)
Definition: variables.h:194
void internal_warning(char *format, va_alist) const
Definition: error.c:256
#define NULL
Definition: general.h:53
int flags
Definition: gm_loop.c:47
#define att_integer
Definition: variables.h:108
#define VSETATTR(var, attr)
Definition: variables.h:193
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
#define ASS_NOEXPAND
Definition: subst.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_var_to_int()

SHELL_VAR* bind_var_to_int ( char *  var,
intmax_t  val 
)

Definition at line 3421 of file variables.c.

References bind_int_variable(), fmtulong(), INT_STRLEN_BOUND, and p.

Referenced by redir_varassign().

3424 {
3425  char ibuf[INT_STRLEN_BOUND (intmax_t) + 1], *p;
3426 
3427  p = fmtulong (val, 10, ibuf, sizeof (ibuf), 0);
3428  return (bind_int_variable (var, p, 0));
3429 }
char * fmtulong(unsigned long ui, int base, char *buf, size_t len, int flags)
Definition: fmtulong.c:84
p
Definition: glob_loop.c:31
INT val
Definition: sm_loop.c:353
SHELL_VAR * bind_int_variable(char *lhs, char *rhs, int flags)
Definition: variables.c:3365
#define INT_STRLEN_BOUND(t)
Definition: general.h:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_function()

SHELL_VAR* bind_function ( char *  name,
COMMAND value 
) const

Definition at line 3434 of file variables.c.

References array_needs_making, att_exported, att_function, att_invisible, function_def::command, copy_command(), copy_function_def(), copy_function_def_contents(), bucket_contents::data, dispose_command(), dispose_function_def_contents(), exported_p, find_function(), find_function_def(), flags, function_cell, hash_insert(), HASH_NOSRCH, INVALIDATE_EXPORTSTR, it_functions, mark_modified_vars, new_shell_variable(), PTR_T, savestring(), var_isset, var_setfunc, VSETATTR, and VUNSETATTR.

Referenced by execute_intern_function().

3437 {
3438  SHELL_VAR *entry;
3439 
3440  entry = find_function (name);
3441  if (entry == 0)
3442  {
3443  BUCKET_CONTENTS *elt;
3444 
3446  entry = new_shell_variable (name);
3447  elt->data = (PTR_T)entry;
3448  }
3449  else
3450  INVALIDATE_EXPORTSTR (entry);
3451 
3452  if (var_isset (entry))
3453  dispose_command (function_cell (entry));
3454 
3455  if (value)
3456  var_setfunc (entry, copy_command (value));
3457  else
3458  var_setfunc (entry, 0);
3459 
3460  VSETATTR (entry, att_function);
3461 
3462  if (mark_modified_vars)
3463  VSETATTR (entry, att_exported);
3464 
3465  VUNSETATTR (entry, att_invisible); /* Just to be sure */
3466 
3467  if (exported_p (entry))
3468  array_needs_making = 1;
3469 
3470 #if defined (PROGRAMMABLE_COMPLETION)
3471  set_itemlist_dirty (&it_functions);
3472 #endif
3473 
3474  return (entry);
3475 }
#define function_cell(var)
Definition: variables.h:167
#define exported_p(var)
Definition: variables.h:138
#define var_setfunc(var, func)
Definition: variables.h:180
#define att_invisible
Definition: variables.h:122
#define PTR_T
Definition: hashlib.h:30
BUCKET_CONTENTS * hash_insert(char *string, HASH_TABLE *table, int flags)
Definition: hashlib.c:246
COMMAND * copy_command(COMMAND *command)
Definition: copy_cmd.c:366
int array_needs_making
Definition: variables.c:151
void dispose_command(COMMAND *command)
Definition: dispose_cmd.c:36
ITEMLIST it_functions
#define att_function
Definition: variables.h:107
char * savestring(const char *s)
Definition: savestring.c:33
#define VUNSETATTR(var, attr)
Definition: variables.h:194
#define HASH_NOSRCH
Definition: hashlib.h:81
static SHELL_VAR * new_shell_variable(char *name) const
Definition: variables.c:2714
#define INVALIDATE_EXPORTSTR(var)
Definition: variables.h:213
int mark_modified_vars
Definition: flags.c:47
SHELL_VAR * find_function(char *name) const
Definition: variables.c:2449
#define VSETATTR(var, attr)
Definition: variables.h:193
HASH_TABLE * shell_functions
Definition: variables.c:111
#define att_exported
Definition: variables.h:104
char * data
Definition: hashlib.h:37
#define var_isset(var)
Definition: variables.h:174
Here is the caller graph for this function:

◆ assign_in_env()

int assign_in_env ( WORD_DESC word,
int  flags 
)

Definition at line 3518 of file variables.c.

References array_cell, array_needs_making, array_p, ASS_APPEND, variable::assign_func, assignment(), assoc_cell, assoc_copy, assoc_p, att_exported, att_tempvar, variable::attributes, variable::context, copy_command(), COPY_EXPORTSTR, variable::dynamic_value, echo_command_at_execute, err_readonly(), expand_assignment_string_to_string(), variable::exportstr, find_variable(), find_variable_last_nameref(), free(), FREE, function_cell, function_p, hash_create(), hash_lookup(), INVALIDATE_EXPORTSTR, legal_identifier(), make_new_variable(), make_variable_value(), mk_env_string(), variable::name, name_cell, nameref_cell, nameref_p, noassign_p, NULL, readonly_p, savestring(), sh_invalidid(), string, stupidly_hack_special_variables(), temp, TEMPENV_HASH_BUCKETS, valid_nameref_value(), value_cell, var_setarray, var_setassoc, var_setfunc, var_setref, var_setvalue, variable_context, word_desc::word, xmalloc(), and xtrace_print_assignment().

Referenced by expand_word_list_internal().

3521 {
3522  int offset, aflags;
3523  char *name, *temp, *value, *newname;
3524  SHELL_VAR *var;
3525  const char *string;
3526 
3527  string = word->word;
3528 
3529  aflags = 0;
3530  offset = assignment (string, 0);
3531  newname = name = savestring (string);
3532  value = (char *)NULL;
3533 
3534  if (name[offset] == '=')
3535  {
3536  name[offset] = 0;
3537 
3538  /* don't ignore the `+' when assigning temporary environment */
3539  if (name[offset - 1] == '+')
3540  {
3541  name[offset - 1] = '\0';
3542  aflags |= ASS_APPEND;
3543  }
3544 
3545  if (legal_identifier (name) == 0)
3546  {
3547  sh_invalidid (name);
3548  return (0);
3549  }
3550 
3551  var = find_variable (name);
3552  if (var == 0)
3553  {
3554  var = find_variable_last_nameref (name, 1);
3555  /* If we're assigning a value to a nameref variable in the temp
3556  environment, and the value of the nameref is valid for assignment,
3557  but the variable does not already exist, assign to the nameref
3558  target and add the target to the temporary environment. This is
3559  what ksh93 does */
3560  if (var && nameref_p (var) && valid_nameref_value (nameref_cell (var), 1))
3561  {
3562  newname = nameref_cell (var);
3563  var = 0; /* don't use it for append */
3564  }
3565  }
3566  else
3567  newname = name_cell (var); /* no-op if not nameref */
3568 
3569  if (var && (readonly_p (var) || noassign_p (var)))
3570  {
3571  if (readonly_p (var))
3572  err_readonly (name);
3573  free (name);
3574  return (0);
3575  }
3576  temp = name + offset + 1;
3577 
3578  value = expand_assignment_string_to_string (temp, 0);
3579 
3580  if (var && (aflags & ASS_APPEND))
3581  {
3582  if (value == 0)
3583  {
3584  value = (char *)xmalloc (1); /* like do_assignment_internal */
3585  value[0] = '\0';
3586  }
3587  temp = make_variable_value (var, value, aflags);
3588  FREE (value);
3589  value = temp;
3590  }
3591  }
3592 
3593  if (temporary_env == 0)
3595 
3596  var = hash_lookup (newname, temporary_env);
3597  if (var == 0)
3598  var = make_new_variable (newname, temporary_env);
3599  else
3600  FREE (value_cell (var));
3601 
3602  if (value == 0)
3603  {
3604  value = (char *)xmalloc (1); /* see above */
3605  value[0] = '\0';
3606  }
3607 
3608  var_setvalue (var, value);
3610  var->context = variable_context; /* XXX */
3611 
3612  INVALIDATE_EXPORTSTR (var);
3613  var->exportstr = mk_env_string (newname, value, 0);
3614 
3615  array_needs_making = 1;
3616 
3617  if (flags)
3619 
3621  /* The Korn shell prints the `+ ' in front of assignment statements,
3622  so we do too. */
3623  xtrace_print_assignment (name, value, 0, 1);
3624 
3625  free (name);
3626  return 1;
3627 }
#define nameref_p(var)
Definition: variables.h:149
char * expand_assignment_string_to_string(char *string, int quoted)
Definition: subst.c:3530
void sh_invalidid(char *s)
Definition: common.c:227
char * make_variable_value(SHELL_VAR *var, char *value, int flags)
Definition: variables.c:2869
HASH_TABLE * hash_create(int buckets)
Definition: hashlib.c:46
static char * mk_env_string(char *name, char *value, int isfunc) const
Definition: variables.c:4597
int CHAR * string
Definition: gm_loop.c:46
int assignment(char *string, int flags) const
Definition: general.c:358
HASH_TABLE * temporary_env
Definition: variables.c:136
char * word
Definition: command.h:127
#define var_setvalue(var, str)
Definition: variables.h:179
int valid_nameref_value(char *name, int flags) const
Definition: general.c:239
SHELL_VAR * find_variable_last_nameref(char *name, int vflags) const
Definition: variables.c:2079
#define noassign_p(var)
Definition: variables.h:153
int legal_identifier(char *name) const
Definition: general.c:216
#define readonly_p(var)
Definition: variables.h:139
void stupidly_hack_special_variables(char *name)
Definition: variables.c:5680
int array_needs_making
Definition: variables.c:151
int attributes
Definition: variables.h:92
char * exportstr
Definition: variables.h:85
char * savestring(const char *s)
Definition: savestring.c:33
int echo_command_at_execute
Definition: flags.c:88
void free()
static SHELL_VAR * make_new_variable(char *name, HASH_TABLE *table) const
Definition: variables.c:2741
int variable_context
Definition: variables.c:123
#define TEMPENV_HASH_BUCKETS
Definition: variables.c:85
#define NULL
Definition: general.h:53
void err_readonly(char *s) const
Definition: error.c:507
#define nameref_cell(var)
Definition: variables.h:170
#define FREE(s)
Definition: general.h:172
int flags
Definition: gm_loop.c:47
#define INVALIDATE_EXPORTSTR(var)
Definition: variables.h:213
int context
Definition: variables.h:93
#define name_cell(var)
Definition: variables.h:163
#define att_tempvar
Definition: variables.h:133
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
#define att_exported
Definition: variables.h:104
#define ASS_APPEND
Definition: subst.h:47
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
static char * xmalloc()
temp
Definition: subst.c:10040
#define value_cell(var)
Definition: variables.h:166
Here is the caller graph for this function:

◆ dispose_variable_value()

static void dispose_variable_value ( SHELL_VAR var)
static

Definition at line 3684 of file variables.c.

References array_cell, array_p, assoc_cell, assoc_p, dispose_command(), FREE, function_cell, function_p, nameref_cell, nameref_p, and value_cell.

Referenced by dispose_variable(), and make_new_variable().

3686 {
3687  if (function_p (var))
3689 #if defined (ARRAY_VARS)
3690  else if (array_p (var))
3691  array_dispose (array_cell (var));
3692  else if (assoc_p (var))
3693  assoc_dispose (assoc_cell (var));
3694 #endif
3695  else if (nameref_p (var))
3696  FREE (nameref_cell (var));
3697  else
3698  FREE (value_cell (var));
3699 }
#define function_p(var)
Definition: variables.h:141
#define nameref_p(var)
Definition: variables.h:149
#define function_cell(var)
Definition: variables.h:167
#define array_p(var)
Definition: variables.h:140
#define assoc_cell(var)
Definition: variables.h:169
void dispose_command(COMMAND *command)
Definition: dispose_cmd.c:36
#define nameref_cell(var)
Definition: variables.h:170
#define FREE(s)
Definition: general.h:172
#define assoc_p(var)
Definition: variables.h:144
#define value_cell(var)
Definition: variables.h:166
#define array_cell(var)
Definition: variables.h:168
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispose_variable()

void dispose_variable ( SHELL_VAR var)

Definition at line 3702 of file variables.c.

References array_needs_making, dispose_variable_value(), exported_p, free(), FREE_EXPORTSTR, variable::name, and nofree_p.

Referenced by delete_var(), execute_for_command(), free_variable_hash_data(), makunbound(), propagate_temp_var(), push_exported_var(), push_posix_temp_var(), push_posix_tempvar_internal(), push_temp_var(), and unbind_func().

3704 {
3705  if (var == 0)
3706  return;
3707 
3708  if (nofree_p (var) == 0)
3709  dispose_variable_value (var);
3710 
3711  FREE_EXPORTSTR (var);
3712 
3713  free (var->name);
3714 
3715  if (exported_p (var))
3716  array_needs_making = 1;
3717 
3718  free (var);
3719 }
#define nofree_p(var)
Definition: variables.h:156
#define exported_p(var)
Definition: variables.h:138
int array_needs_making
Definition: variables.c:151
void free()
#define FREE_EXPORTSTR(var)
Definition: variables.h:207
static void dispose_variable_value(SHELL_VAR *var)
Definition: variables.c:3684
char * name
Definition: variables.h:83
Here is the call graph for this function:

◆ unbind_variable()

int unbind_variable ( char *  name) const

Definition at line 3724 of file variables.c.

References find_variable_nameref(), makunbound(), variable::name, nameref_p, NULL, and var_lookup().

Referenced by check_mail(), check_unbind_variable(), enable_mypid_builtin_unload(), execute_for_command(), execute_in_subshell(), main(), and stat_builtin().

3726 {
3727  SHELL_VAR *v, *nv;
3728  int r;
3729 
3730  v = var_lookup (name, shell_variables);
3731  nv = (v && nameref_p (v)) ? find_variable_nameref (v) : (SHELL_VAR *)NULL;
3732 
3733  r = nv ? makunbound (nv->name, shell_variables) : makunbound (name, shell_variables);
3734  return r;
3735 }
#define nameref_p(var)
Definition: variables.h:149
VAR_CONTEXT * shell_variables
Definition: variables.c:107
SHELL_VAR * var_lookup(char *name, VAR_CONTEXT *vcontext) const
Definition: variables.c:1965
int makunbound(char *name, VAR_CONTEXT *vc) const
Definition: variables.c:3862
SHELL_VAR * find_variable_nameref(SHELL_VAR *v)
Definition: variables.c:2038
#define NULL
Definition: general.h:53
char * name
Definition: variables.h:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unbind_nameref()

int unbind_nameref ( char *  name) const

Definition at line 3739 of file variables.c.

References makunbound(), nameref_p, and var_lookup().

3741 {
3742  SHELL_VAR *v;
3743 
3744  v = var_lookup (name, shell_variables);
3745  if (v && nameref_p (v))
3746  return makunbound (name, shell_variables);
3747  return 0;
3748 }
#define nameref_p(var)
Definition: variables.h:149
VAR_CONTEXT * shell_variables
Definition: variables.c:107
SHELL_VAR * var_lookup(char *name, VAR_CONTEXT *vcontext) const
Definition: variables.c:1965
int makunbound(char *name, VAR_CONTEXT *vc) const
Definition: variables.c:3862
Here is the call graph for this function:

◆ unbind_variable_noref()

int unbind_variable_noref ( char *  name) const

Definition at line 3752 of file variables.c.

References makunbound(), and var_lookup().

Referenced by execute_in_subshell(), and uidset().

3754 {
3755  SHELL_VAR *v;
3756 
3757  v = var_lookup (name, shell_variables);
3758  if (v)
3759  return makunbound (name, shell_variables);
3760  return 0;
3761 }
VAR_CONTEXT * shell_variables
Definition: variables.c:107
SHELL_VAR * var_lookup(char *name, VAR_CONTEXT *vcontext) const
Definition: variables.c:1965
int makunbound(char *name, VAR_CONTEXT *vc) const
Definition: variables.c:3862
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_unbind_variable()

int check_unbind_variable ( char *  name) const

Definition at line 3764 of file variables.c.

References _(), find_variable(), internal_error(), readonly_p, and unbind_variable().

Referenced by execute_in_subshell().

3766 {
3767  SHELL_VAR *v;
3768 
3769  v = find_variable (name);
3770  if (v && readonly_p (v))
3771  {
3772  internal_error (_("%s: cannot unset: readonly %s"), name, "variable");
3773  return -1;
3774  }
3775  return (unbind_variable (name));
3776 }
#define readonly_p(var)
Definition: variables.h:139
void xs_init _((void))
int unbind_variable(char *name) const
Definition: variables.c:3724
void internal_error(char *format, va_alist) const
Definition: error.c:235
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unbind_func()

int unbind_func ( char *  name) const

Definition at line 3780 of file variables.c.

References array_needs_making, bucket_contents::data, dispose_function_def(), dispose_variable(), exported_p, free(), hash_remove(), if(), it_functions, and bucket_contents::key.

3782 {
3783  BUCKET_CONTENTS *elt;
3784  SHELL_VAR *func;
3785 
3786  elt = hash_remove (name, shell_functions, 0);
3787 
3788  if (elt == 0)
3789  return -1;
3790 
3791 #if defined (PROGRAMMABLE_COMPLETION)
3792  set_itemlist_dirty (&it_functions);
3793 #endif
3794 
3795  func = (SHELL_VAR *)elt->data;
3796  if (func)
3797  {
3798  if (exported_p (func))
3800  dispose_variable (func);
3801  }
3802 
3803  free (elt->key);
3804  free (elt);
3805 
3806  return 0;
3807 }
#define exported_p(var)
Definition: variables.h:138
BUCKET_CONTENTS * hash_remove(char *string, HASH_TABLE *table, int flags) const
Definition: hashlib.c:212
int array_needs_making
Definition: variables.c:151
char * key
Definition: hashlib.h:36
ITEMLIST it_functions
void free()
void dispose_variable(SHELL_VAR *var)
Definition: variables.c:3702
if(return(GMATCH(string==0||pattern==0)
Definition: sm_loop.c:42
HASH_TABLE * shell_functions
Definition: variables.c:111
char * data
Definition: hashlib.h:37
Here is the call graph for this function:

◆ delete_var()

int delete_var ( char *  name,
VAR_CONTEXT vc 
) const

Definition at line 3834 of file variables.c.

References bucket_contents::data, dispose_variable(), var_context::down, free(), hash_remove(), bucket_contents::key, NULL, and var_context::table.

3837 {
3838  BUCKET_CONTENTS *elt;
3839  SHELL_VAR *old_var;
3840  VAR_CONTEXT *v;
3841 
3842  for (elt = (BUCKET_CONTENTS *)NULL, v = vc; v; v = v->down)
3843  if (elt = hash_remove (name, v->table, 0))
3844  break;
3845 
3846  if (elt == 0)
3847  return (-1);
3848 
3849  old_var = (SHELL_VAR *)elt->data;
3850  free (elt->key);
3851  free (elt);
3852 
3853  dispose_variable (old_var);
3854  return (0);
3855 }
HASH_TABLE * table
Definition: variables.h:40
BUCKET_CONTENTS * hash_remove(char *string, HASH_TABLE *table, int flags) const
Definition: hashlib.c:212
char * key
Definition: hashlib.h:36
void free()
void dispose_variable(SHELL_VAR *var)
Definition: variables.c:3702
#define NULL
Definition: general.h:53
char * data
Definition: hashlib.h:37
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:

◆ makunbound()

int makunbound ( char *  name,
VAR_CONTEXT vc 
) const

Definition at line 3862 of file variables.c.

References array_cell, array_needs_making, array_p, assoc_cell, assoc_p, att_exported, att_invisible, att_local, variable::attributes, variable::context, bucket_contents::data, dispose_variable(), var_context::down, exported_p, free(), FREE, hash_insert(), hash_remove(), if(), INVALIDATE_EXPORTSTR, bucket_contents::key, local_p, localvar_unset, variable::name, nameref_cell, nameref_p, nofree_p, NULL, PTR_T, savestring(), stupidly_hack_special_variables(), t, var_context::table, tempvar_p, value_cell, var_setvalue, variable_context, and VSETATTR.

Referenced by unbind_nameref(), unbind_variable(), and unbind_variable_noref().

3865 {
3866  BUCKET_CONTENTS *elt, *new_elt;
3867  SHELL_VAR *old_var;
3868  VAR_CONTEXT *v;
3869  char *t;
3870 
3871  for (elt = (BUCKET_CONTENTS *)NULL, v = vc; v; v = v->down)
3872  if (elt = hash_remove (name, v->table, 0))
3873  break;
3874 
3875  if (elt == 0)
3876  return (-1);
3877 
3878  old_var = (SHELL_VAR *)elt->data;
3879 
3880  if (old_var && exported_p (old_var))
3882 
3883  /* If we're unsetting a local variable and we're still executing inside
3884  the function, just mark the variable as invisible. The function
3885  eventually called by pop_var_context() will clean it up later. This
3886  must be done so that if the variable is subsequently assigned a new
3887  value inside the function, the `local' attribute is still present.
3888  We also need to add it back into the correct hash table. */
3889  if (old_var && local_p (old_var) &&
3890  (old_var->context == variable_context || (localvar_unset && old_var->context < variable_context)))
3891  {
3892  if (nofree_p (old_var))
3893  var_setvalue (old_var, (char *)NULL);
3894 #if defined (ARRAY_VARS)
3895  else if (array_p (old_var))
3896  array_dispose (array_cell (old_var));
3897  else if (assoc_p (old_var))
3898  assoc_dispose (assoc_cell (old_var));
3899 #endif
3900  else if (nameref_p (old_var))
3901  FREE (nameref_cell (old_var));
3902  else
3903  FREE (value_cell (old_var));
3904  /* Reset the attributes. Preserve the export attribute if the variable
3905  came from a temporary environment. Make sure it stays local, and
3906  make it invisible. */
3907  old_var->attributes = (exported_p (old_var) && tempvar_p (old_var)) ? att_exported : 0;
3908  VSETATTR (old_var, att_local);
3909  VSETATTR (old_var, att_invisible);
3910  var_setvalue (old_var, (char *)NULL);
3911  INVALIDATE_EXPORTSTR (old_var);
3912 
3913  new_elt = hash_insert (savestring (old_var->name), v->table, 0);
3914  new_elt->data = (PTR_T)old_var;
3916 
3917  free (elt->key);
3918  free (elt);
3919  return (0);
3920  }
3921 
3922  /* Have to save a copy of name here, because it might refer to
3923  old_var->name. If so, stupidly_hack_special_variables will
3924  reference freed memory. */
3925  t = savestring (name);
3926 
3927  free (elt->key);
3928  free (elt);
3929 
3930  dispose_variable (old_var);
3932  free (t);
3933 
3934  return (0);
3935 }
#define nofree_p(var)
Definition: variables.h:156
HASH_TABLE * table
Definition: variables.h:40
#define nameref_p(var)
Definition: variables.h:149
#define array_p(var)
Definition: variables.h:140
#define exported_p(var)
Definition: variables.h:138
#define att_invisible
Definition: variables.h:122
BUCKET_CONTENTS * hash_remove(char *string, HASH_TABLE *table, int flags) const
Definition: hashlib.c:212
#define PTR_T
Definition: hashlib.h:30
BUCKET_CONTENTS * hash_insert(char *string, HASH_TABLE *table, int flags)
Definition: hashlib.c:246
#define var_setvalue(var, str)
Definition: variables.h:179
#define assoc_cell(var)
Definition: variables.h:169
void stupidly_hack_special_variables(char *name)
Definition: variables.c:5680
int array_needs_making
Definition: variables.c:151
char * key
Definition: hashlib.h:36
int attributes
Definition: variables.h:92
int t
Definition: gm_loop.c:77
char * savestring(const char *s)
Definition: savestring.c:33
void free()
int variable_context
Definition: variables.c:123
void dispose_variable(SHELL_VAR *var)
Definition: variables.c:3702
#define NULL
Definition: general.h:53
#define nameref_cell(var)
Definition: variables.h:170
#define FREE(s)
Definition: general.h:172
#define tempvar_p(var)
Definition: variables.h:159
#define INVALIDATE_EXPORTSTR(var)
Definition: variables.h:213
if(return(GMATCH(string==0||pattern==0)
Definition: sm_loop.c:42
#define att_local
Definition: variables.h:109
int localvar_unset
Definition: variables.c:132
int context
Definition: variables.h:93
char * name
Definition: variables.h:83
#define local_p(var)
Definition: variables.h:143
#define assoc_p(var)
Definition: variables.h:144
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_exported
Definition: variables.h:104
char * data
Definition: hashlib.h:37
#define value_cell(var)
Definition: variables.h:166
#define array_cell(var)
Definition: variables.h:168
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kill_all_local_variables()

void kill_all_local_variables ( )

Definition at line 3939 of file variables.c.

References delete_all_variables(), var_context::down, hash_dispose(), NULL, var_context::scope, var_context::table, variable_context, vc_haslocals, and vc_isfuncenv.

3940 {
3941  VAR_CONTEXT *vc;
3942 
3943  for (vc = shell_variables; vc; vc = vc->down)
3944  if (vc_isfuncenv (vc) && vc->scope == variable_context)
3945  break;
3946  if (vc == 0)
3947  return; /* XXX */
3948 
3949  if (vc->table && vc_haslocals (vc))
3950  {
3952  hash_dispose (vc->table);
3953  }
3954  vc->table = (HASH_TABLE *)NULL;
3955 }
HASH_TABLE * table
Definition: variables.h:40
VAR_CONTEXT * shell_variables
Definition: variables.c:107
int variable_context
Definition: variables.c:123
#define NULL
Definition: general.h:53
#define vc_isfuncenv(vc)
Definition: variables.h:53
#define vc_haslocals(vc)
Definition: variables.h:59
void delete_all_variables(HASH_TABLE *hashed_vars)
Definition: variables.c:3969
struct var_context * down
Definition: variables.h:39
void hash_dispose(HASH_TABLE *table)
Definition: hashlib.c:318
Here is the call graph for this function:

◆ free_variable_hash_data()

static void free_variable_hash_data ( char *  data)
static

Definition at line 3958 of file variables.c.

References dispose_variable().

Referenced by delete_all_variables(), and flush_temporary_env().

3960 {
3961  SHELL_VAR *var;
3962 
3963  var = (SHELL_VAR *)data;
3964  dispose_variable (var);
3965 }
void dispose_variable(SHELL_VAR *var)
Definition: variables.c:3702
Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_all_variables()

void delete_all_variables ( HASH_TABLE hashed_vars)

Definition at line 3969 of file variables.c.

References free_variable_hash_data(), and hash_flush().

Referenced by delete_all_contexts(), dispose_var_context(), kill_all_local_variables(), and shell_reinitialize().

3971 {
3972  hash_flush (hashed_vars, free_variable_hash_data);
3973 }
void hash_flush(HASH_TABLE *table, sh_free_func_t *free_data)
Definition: hashlib.c:284
static void free_variable_hash_data(char *data)
Definition: variables.c:3958
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_var_read_only()

void set_var_read_only ( char *  name)

Definition at line 3996 of file variables.c.

References att_readonly, find_function(), FIND_OR_MAKE_VARIABLE, set_auto_export, and VSETATTR.

Referenced by run_startup_files().

3998 {
3999  SHELL_VAR *entry;
4000 
4001  FIND_OR_MAKE_VARIABLE (name, entry);
4002  VSETATTR (entry, att_readonly);
4003 }
#define FIND_OR_MAKE_VARIABLE(name, entry)
Definition: variables.c:3981
#define VSETATTR(var, attr)
Definition: variables.h:193
#define att_readonly
Definition: variables.h:105
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vlist_alloc()

static VARLIST* vlist_alloc ( int  nentries)
static

Definition at line 4051 of file variables.c.

References _vlist::list, _vlist::list_len, _vlist::list_size, NULL, and xmalloc().

Referenced by all_local_variables(), map_over(), map_over_funcs(), and vlist_realloc().

4053 {
4054  VARLIST *vlist;
4055 
4056  vlist = (VARLIST *)xmalloc (sizeof (VARLIST));
4057  vlist->list = (SHELL_VAR **)xmalloc ((nentries + 1) * sizeof (SHELL_VAR *));
4058  vlist->list_size = nentries;
4059  vlist->list_len = 0;
4060  vlist->list[0] = (SHELL_VAR *)NULL;
4061 
4062  return vlist;
4063 }
SHELL_VAR ** list
Definition: variables.h:97
int list_size
Definition: variables.h:98
int list_len
Definition: variables.h:99
#define NULL
Definition: general.h:53
static char * xmalloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vlist_realloc()

static VARLIST* vlist_realloc ( VARLIST vlist,
int  n 
)
static

Definition at line 4066 of file variables.c.

References _vlist::list, _vlist::list_size, n, vlist_alloc(), and xrealloc().

Referenced by vlist_add().

4069 {
4070  if (vlist == 0)
4071  return (vlist = vlist_alloc (n));
4072  if (n > vlist->list_size)
4073  {
4074  vlist->list_size = n;
4075  vlist->list = (SHELL_VAR **)xrealloc (vlist->list, (vlist->list_size + 1) * sizeof (SHELL_VAR *));
4076  }
4077  return vlist;
4078 }
SHELL_VAR ** list
Definition: variables.h:97
unsigned long int n
Definition: eval-plural.h:35
int list_size
Definition: variables.h:98
static VARLIST * vlist_alloc(int nentries)
Definition: variables.c:4051
static char * xrealloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vlist_add()

static void vlist_add ( VARLIST vlist,
SHELL_VAR var,
int  flags 
)
static

Definition at line 4081 of file variables.c.

References i, _vlist::list, _vlist::list_len, _vlist::list_size, variable::name, NULL, STREQ, and vlist_realloc().

Referenced by flatten().

4085 {
4086  register int i;
4087 
4088  for (i = 0; i < vlist->list_len; i++)
4089  if (STREQ (var->name, vlist->list[i]->name))
4090  break;
4091  if (i < vlist->list_len)
4092  return;
4093 
4094  if (i >= vlist->list_size)
4095  vlist = vlist_realloc (vlist, vlist->list_size + 16);
4096 
4097  vlist->list[vlist->list_len++] = var;
4098  vlist->list[vlist->list_len] = (SHELL_VAR *)NULL;
4099 }
SHELL_VAR ** list
Definition: variables.h:97
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
static VARLIST * vlist_realloc(VARLIST *vlist, int n)
Definition: variables.c:4066
int list_size
Definition: variables.h:98
int list_len
Definition: variables.h:99
#define NULL
Definition: general.h:53
#define STREQ(a, b)
Definition: general.h:166
char * name
Definition: variables.h:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ map_over()

SHELL_VAR** map_over ( sh_var_map_func_t *  function,
VAR_CONTEXT vc 
)

Definition at line 4105 of file variables.c.

References var_context::down, flatten(), free(), HASH_ENTRIES, _vlist::list, NULL, var_context::table, and vlist_alloc().

Referenced by make_var_export_array(), and vapply().

4108 {
4109  VAR_CONTEXT *v;
4110  VARLIST *vlist;
4111  SHELL_VAR **ret;
4112  int nentries;
4113 
4114  for (nentries = 0, v = vc; v; v = v->down)
4115  nentries += HASH_ENTRIES (v->table);
4116 
4117  if (nentries == 0)
4118  return (SHELL_VAR **)NULL;
4119 
4120  vlist = vlist_alloc (nentries);
4121 
4122  for (v = vc; v; v = v->down)
4123  flatten (v->table, function, vlist, 0);
4124 
4125  ret = vlist->list;
4126  free (vlist);
4127  return ret;
4128 }
HASH_TABLE * table
Definition: variables.h:40
SHELL_VAR ** list
Definition: variables.h:97
static void flatten(HASH_TABLE *var_hash_table, sh_var_map_func_t *func, VARLIST *vlist, int flags)
Definition: variables.c:4156
static VARLIST * vlist_alloc(int nentries)
Definition: variables.c:4051
void free()
#define NULL
Definition: general.h:53
#define HASH_ENTRIES(ht)
Definition: hashlib.h:78
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ map_over_funcs()

SHELL_VAR** map_over_funcs ( sh_var_map_func_t *  function)

Definition at line 4131 of file variables.c.

References flatten(), free(), HASH_ENTRIES, _vlist::list, NULL, and vlist_alloc().

Referenced by fapply(), and make_func_export_array().

4133 {
4134  VARLIST *vlist;
4135  SHELL_VAR **ret;
4136 
4137  if (shell_functions == 0 || HASH_ENTRIES (shell_functions) == 0)
4138  return ((SHELL_VAR **)NULL);
4139 
4141 
4142  flatten (shell_functions, function, vlist, 0);
4143 
4144  ret = vlist->list;
4145  free (vlist);
4146  return ret;
4147 }
SHELL_VAR ** list
Definition: variables.h:97
static void flatten(HASH_TABLE *var_hash_table, sh_var_map_func_t *func, VARLIST *vlist, int flags)
Definition: variables.c:4156
static VARLIST * vlist_alloc(int nentries)
Definition: variables.c:4051
void free()
#define NULL
Definition: general.h:53
HASH_TABLE * shell_functions
Definition: variables.c:111
#define HASH_ENTRIES(ht)
Definition: hashlib.h:78
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flatten()

static void flatten ( HASH_TABLE var_hash_table,
sh_var_map_func_t *  func,
VARLIST vlist,
int  flags 
)
static

Definition at line 4156 of file variables.c.

References bucket_contents::data, HASH_ENTRIES, hash_items, i, hash_table::nbuckets, bucket_contents::next, and vlist_add().

Referenced by all_local_variables(), map_over(), map_over_funcs(), and push_var_context().

4161 {
4162  register int i;
4163  register BUCKET_CONTENTS *tlist;
4164  int r;
4165  SHELL_VAR *var;
4166 
4167  if (var_hash_table == 0 || (HASH_ENTRIES (var_hash_table) == 0) || (vlist == 0 && func == 0))
4168  return;
4169 
4170  for (i = 0; i < var_hash_table->nbuckets; i++)
4171  {
4172  for (tlist = hash_items (i, var_hash_table); tlist; tlist = tlist->next)
4173  {
4174  var = (SHELL_VAR *)tlist->data;
4175 
4176  r = func ? (*func) (var) : 1;
4177  if (r && vlist)
4178  vlist_add (vlist, var, flags);
4179  }
4180  }
4181 }
static void vlist_add(VARLIST *vlist, SHELL_VAR *var, int flags)
Definition: variables.c:4081
#define hash_items(bucket, table)
Definition: hashlib.h:70
int nbuckets
Definition: hashlib.h:44
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
int flags
Definition: gm_loop.c:47
struct bucket_contents * next
Definition: hashlib.h:35
#define HASH_ENTRIES(ht)
Definition: hashlib.h:78
char * data
Definition: hashlib.h:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sort_variables()

void sort_variables ( SHELL_VAR **  array)

Definition at line 4184 of file variables.c.

References qsort(), qsort_var_comp(), and strvec_len().

Referenced by all_local_variables(), fapply(), and vapply().

4186 {
4187  qsort (array, strvec_len ((char **)array), sizeof (SHELL_VAR *), (QSFUNC *)qsort_var_comp);
4188 }
static int qsort_var_comp(SHELL_VAR **var1, SHELL_VAR **var2)
Definition: variables.c:4191
int QSFUNC()
Definition: general.h:266
void qsort()
int strvec_len(char **array)
Definition: stringvec.c:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ qsort_var_comp()

static int qsort_var_comp ( SHELL_VAR **  var1,
SHELL_VAR **  var2 
)
static

Definition at line 4191 of file variables.c.

Referenced by sort_variables().

4193 {
4194  int result;
4195 
4196  if ((result = (*var1)->name[0] - (*var2)->name[0]) == 0)
4197  result = strcmp ((*var1)->name, (*var2)->name);
4198 
4199  return (result);
4200 }
Here is the caller graph for this function:

◆ vapply()

static SHELL_VAR** vapply ( sh_var_map_func_t *  func)
static

Definition at line 4205 of file variables.c.

References list, map_over(), and sort_variables().

Referenced by all_exported_variables(), all_local_variables(), all_shell_variables(), all_visible_variables(), and local_exported_variables().

4207 {
4208  SHELL_VAR **list;
4209 
4210  list = map_over (func, shell_variables);
4211  if (list /* && posixly_correct */)
4212  sort_variables (list);
4213  return (list);
4214 }
SHELL_VAR ** map_over(sh_var_map_func_t *function, VAR_CONTEXT *vc)
Definition: variables.c:4105
list
Definition: subst.c:10212
VAR_CONTEXT * shell_variables
Definition: variables.c:107
void sort_variables(SHELL_VAR **array)
Definition: variables.c:4184
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fapply()

static SHELL_VAR** fapply ( sh_var_map_func_t *  func)
static

Definition at line 4219 of file variables.c.

References list, map_over_funcs(), and sort_variables().

Referenced by all_shell_functions(), and all_visible_functions().

4221 {
4222  SHELL_VAR **list;
4223 
4224  list = map_over_funcs (func);
4225  if (list /* && posixly_correct */)
4226  sort_variables (list);
4227  return (list);
4228 }
list
Definition: subst.c:10212
void sort_variables(SHELL_VAR **array)
Definition: variables.c:4184
SHELL_VAR ** map_over_funcs(sh_var_map_func_t *function)
Definition: variables.c:4131
Here is the call graph for this function:
Here is the caller graph for this function:

◆ all_shell_variables()

SHELL_VAR** all_shell_variables ( )

Definition at line 4232 of file variables.c.

References NULL, and vapply().

4233 {
4234  return (vapply ((sh_var_map_func_t *)NULL));
4235 }
static SHELL_VAR ** vapply(sh_var_map_func_t *func)
Definition: variables.c:4205
#define NULL
Definition: general.h:53
Here is the call graph for this function:

◆ all_shell_functions()

SHELL_VAR** all_shell_functions ( )

Definition at line 4239 of file variables.c.

References fapply(), and NULL.

4240 {
4241  return (fapply ((sh_var_map_func_t *)NULL));
4242 }
#define NULL
Definition: general.h:53
static SHELL_VAR ** fapply(sh_var_map_func_t *func)
Definition: variables.c:4219
Here is the call graph for this function:

◆ visible_var()

static int visible_var ( SHELL_VAR var)
static

Definition at line 4245 of file variables.c.

References invisible_p.

Referenced by all_visible_functions(), and all_visible_variables().

4247 {
4248  return (invisible_p (var) == 0);
4249 }
#define invisible_p(var)
Definition: variables.h:151
Here is the caller graph for this function:

◆ all_visible_functions()

SHELL_VAR** all_visible_functions ( )

Definition at line 4252 of file variables.c.

References fapply(), and visible_var().

4253 {
4254  return (fapply (visible_var));
4255 }
static int visible_var(SHELL_VAR *var)
Definition: variables.c:4245
static SHELL_VAR ** fapply(sh_var_map_func_t *func)
Definition: variables.c:4219
Here is the call graph for this function:

◆ all_visible_variables()

SHELL_VAR** all_visible_variables ( )

Definition at line 4258 of file variables.c.

References vapply(), and visible_var().

Referenced by all_variables_matching_prefix().

4259 {
4260  return (vapply (visible_var));
4261 }
static int visible_var(SHELL_VAR *var)
Definition: variables.c:4245
static SHELL_VAR ** vapply(sh_var_map_func_t *func)
Definition: variables.c:4205
Here is the call graph for this function:
Here is the caller graph for this function:

◆ visible_and_exported()

static int visible_and_exported ( SHELL_VAR var)
static

Definition at line 4266 of file variables.c.

References exported_p, and invisible_p.

Referenced by all_exported_variables(), make_func_export_array(), and make_var_export_array().

4268 {
4269  return (invisible_p (var) == 0 && exported_p (var));
4270 }
#define invisible_p(var)
Definition: variables.h:151
#define exported_p(var)
Definition: variables.h:138
Here is the caller graph for this function:

◆ export_environment_candidate()

static int export_environment_candidate ( SHELL_VAR var)
static

Definition at line 4276 of file variables.c.

References exported_p, imported_p, and invisible_p.

Referenced by make_var_export_array().

4278 {
4279  return (exported_p (var) && (invisible_p (var) == 0 || imported_p (var)));
4280 }
#define invisible_p(var)
Definition: variables.h:151
#define exported_p(var)
Definition: variables.h:138
#define imported_p(var)
Definition: variables.h:154
Here is the caller graph for this function:

◆ local_and_exported()

static int local_and_exported ( SHELL_VAR var)
static

Definition at line 4285 of file variables.c.

References variable::context, exported_p, invisible_p, local_p, and variable_context.

Referenced by local_exported_variables().

4287 {
4288  return (invisible_p (var) == 0 && local_p (var) && var->context == variable_context && exported_p (var));
4289 }
#define invisible_p(var)
Definition: variables.h:151
#define exported_p(var)
Definition: variables.h:138
int variable_context
Definition: variables.c:123
int context
Definition: variables.h:93
#define local_p(var)
Definition: variables.h:143
Here is the caller graph for this function:

◆ all_exported_variables()

SHELL_VAR** all_exported_variables ( )

Definition at line 4292 of file variables.c.

References vapply(), and visible_and_exported().

4293 {
4294  return (vapply (visible_and_exported));
4295 }
static SHELL_VAR ** vapply(sh_var_map_func_t *func)
Definition: variables.c:4205
static int visible_and_exported(SHELL_VAR *var)
Definition: variables.c:4266
Here is the call graph for this function:

◆ local_exported_variables()

SHELL_VAR** local_exported_variables ( )

Definition at line 4298 of file variables.c.

References local_and_exported(), and vapply().

4299 {
4300  return (vapply (local_and_exported));
4301 }
static SHELL_VAR ** vapply(sh_var_map_func_t *func)
Definition: variables.c:4205
static int local_and_exported(SHELL_VAR *var)
Definition: variables.c:4285
Here is the call graph for this function:

◆ variable_in_context()

static int variable_in_context ( SHELL_VAR var)
static

Definition at line 4304 of file variables.c.

References variable::context, invisible_p, local_p, and variable_context.

Referenced by all_local_variables().

4306 {
4307  return (invisible_p (var) == 0 && local_p (var) && var->context == variable_context);
4308 }
#define invisible_p(var)
Definition: variables.h:151
int variable_context
Definition: variables.c:123
int context
Definition: variables.h:93
#define local_p(var)
Definition: variables.h:143
Here is the caller graph for this function:

◆ all_local_variables()

SHELL_VAR** all_local_variables ( )

Definition at line 4311 of file variables.c.

References _(), array_p, assoc_p, var_context::down, flatten(), free(), HASH_ENTRIES, internal_error(), invisible_p, _vlist::list, NULL, var_context::scope, shell_variables, sort_variables(), var_context::table, vapply(), variable_context, variable_in_context(), vc_haslocals, vc_isfuncenv, and vlist_alloc().

4312 {
4313  VARLIST *vlist;
4314  SHELL_VAR **ret;
4315  VAR_CONTEXT *vc;
4316 
4317  vc = shell_variables;
4318  for (vc = shell_variables; vc; vc = vc->down)
4319  if (vc_isfuncenv (vc) && vc->scope == variable_context)
4320  break;
4321 
4322  if (vc == 0)
4323  {
4324  internal_error (_("all_local_variables: no function context at current scope"));
4325  return (SHELL_VAR **)NULL;
4326  }
4327  if (vc->table == 0 || HASH_ENTRIES (vc->table) == 0 || vc_haslocals (vc) == 0)
4328  return (SHELL_VAR **)NULL;
4329 
4330  vlist = vlist_alloc (HASH_ENTRIES (vc->table));
4331 
4332  flatten (vc->table, variable_in_context, vlist, 0);
4333 
4334  ret = vlist->list;
4335  free (vlist);
4336  if (ret)
4337  sort_variables (ret);
4338  return ret;
4339 }
HASH_TABLE * table
Definition: variables.h:40
SHELL_VAR ** list
Definition: variables.h:97
VAR_CONTEXT * shell_variables
Definition: variables.c:107
static void flatten(HASH_TABLE *var_hash_table, sh_var_map_func_t *func, VARLIST *vlist, int flags)
Definition: variables.c:4156
void xs_init _((void))
static VARLIST * vlist_alloc(int nentries)
Definition: variables.c:4051
void free()
int variable_context
Definition: variables.c:123
#define NULL
Definition: general.h:53
void internal_error(char *format, va_alist) const
Definition: error.c:235
static int variable_in_context(SHELL_VAR *var)
Definition: variables.c:4304
void sort_variables(SHELL_VAR **array)
Definition: variables.c:4184
#define vc_isfuncenv(vc)
Definition: variables.h:53
#define vc_haslocals(vc)
Definition: variables.h:59
#define HASH_ENTRIES(ht)
Definition: hashlib.h:78
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:

◆ all_variables_matching_prefix()

char** all_variables_matching_prefix ( char *  prefix) const

Definition at line 4358 of file variables.c.

References all_visible_variables(), free(), NULL, savestring(), STREQN, STRLEN, and strvec_create().

Referenced by parameter_brace_expand().

4360 {
4361  SHELL_VAR **varlist;
4362  char **rlist;
4363  int vind, rind, plen;
4364 
4365  plen = STRLEN (prefix);
4366  varlist = all_visible_variables ();
4367  for (vind = 0; varlist && varlist[vind]; vind++)
4368  ;
4369  if (varlist == 0 || vind == 0)
4370  return ((char **)NULL);
4371  rlist = strvec_create (vind + 1);
4372  for (vind = rind = 0; varlist[vind]; vind++)
4373  {
4374  if (plen == 0 || STREQN (prefix, varlist[vind]->name, plen))
4375  rlist[rind++] = savestring (varlist[vind]->name);
4376  }
4377  rlist[rind] = (char *)0;
4378  free (varlist);
4379 
4380  return rlist;
4381 }
char ** strvec_create(int n)
Definition: stringvec.c:37
#define STRLEN(s)
Definition: general.h:171
char * savestring(const char *s)
Definition: savestring.c:33
void free()
#define STREQN(a, b, n)
Definition: general.h:167
#define NULL
Definition: general.h:53
SHELL_VAR ** all_visible_variables()
Definition: variables.c:4258
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_tempenv_variable()

static SHELL_VAR* bind_tempenv_variable ( char *  name,
char *  value 
) const
static

Definition at line 4391 of file variables.c.

References FREE, hash_lookup(), INVALIDATE_EXPORTSTR, NULL, savestring(), value_cell, and var_setvalue.

Referenced by bind_variable().

4394 {
4395  SHELL_VAR *var;
4396 
4397  var = temporary_env ? hash_lookup (name, temporary_env) : (SHELL_VAR *)NULL;
4398 
4399  if (var)
4400  {
4401  FREE (value_cell (var));
4402  var_setvalue (var, savestring (value));
4403  INVALIDATE_EXPORTSTR (var);
4404  }
4405 
4406  return (var);
4407 }
HASH_TABLE * temporary_env
Definition: variables.c:136
#define var_setvalue(var, str)
Definition: variables.h:179
char * savestring(const char *s)
Definition: savestring.c:33
#define NULL
Definition: general.h:53
#define FREE(s)
Definition: general.h:172
#define INVALIDATE_EXPORTSTR(var)
Definition: variables.h:213
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_tempenv_variable()

SHELL_VAR* find_tempenv_variable ( char *  name) const

Definition at line 4412 of file variables.c.

References hash_lookup(), and NULL.

4414 {
4415  return (temporary_env ? hash_lookup (name, temporary_env) : (SHELL_VAR *)NULL);
4416 }
HASH_TABLE * temporary_env
Definition: variables.c:136
#define NULL
Definition: general.h:53
static SHELL_VAR * hash_lookup(char *name, HASH_TABLE *hashed_vars) const
Definition: variables.c:1950
Here is the call graph for this function:

◆ push_posix_temp_var()

static void push_posix_temp_var ( char *  data)
static

Definition at line 4426 of file variables.c.

References ASS_FORCE, ASS_NOLONGJMP, att_propagate, att_tempvar, variable::attributes, bind_variable_internal(), dispose_variable(), find_special_var(), hash_create(), variable::name, savestring(), var_context::table, value_cell, and VARIABLES_HASH_BUCKETS.

Referenced by merge_temporary_env().

4428 {
4429  SHELL_VAR *var, *v;
4430  HASH_TABLE *binding_table;
4431 
4432  var = (SHELL_VAR *)data;
4433 
4434  binding_table = global_variables->table;
4435  if (binding_table == 0)
4437 
4438  v = bind_variable_internal (var->name, value_cell (var), binding_table, 0, ASS_FORCE|ASS_NOLONGJMP);
4439 
4440  /* global variables are no longer temporary and don't need propagating. */
4442  if (v)
4443  v->attributes |= var->attributes;
4444 
4445  if (find_special_var (var->name) >= 0)
4446  tempvar_list[tvlist_ind++] = savestring (var->name);
4447 
4448  dispose_variable (var);
4449 }
static SHELL_VAR * bind_variable_internal(char *name, char *value, HASH_TABLE *table, int hflags, int aflags) const
Definition: variables.c:3026
HASH_TABLE * table
Definition: variables.h:40
HASH_TABLE * hash_create(int buckets)
Definition: hashlib.c:46
#define att_propagate
Definition: variables.h:134
char ** tempvar_list
Definition: variables.c:4418
#define ASS_NOLONGJMP
Definition: subst.h:56
static int find_special_var(char *name) const
Definition: variables.c:5657
int tvlist_ind
Definition: variables.c:4419
int attributes
Definition: variables.h:92
char * savestring(const char *s)
Definition: savestring.c:33
#define VARIABLES_HASH_BUCKETS
Definition: variables.c:83
void dispose_variable(SHELL_VAR *var)
Definition: variables.c:3702
#define ASS_FORCE
Definition: subst.h:52
char * name
Definition: variables.h:83
#define att_tempvar
Definition: variables.h:133
VAR_CONTEXT * global_variables
Definition: variables.c:104
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_temp_var()

static void push_temp_var ( char *  data)
static

Definition at line 4462 of file variables.c.

References ASS_FORCE, ASS_NOLONGJMP, att_propagate, att_tempvar, variable::attributes, bind_variable_internal(), variable::context, dispose_variable(), find_special_var(), var_context::flags, hash_create(), variable::name, savestring(), var_context::scope, var_context::table, TEMPENV_HASH_BUCKETS, value_cell, VARIABLES_HASH_BUCKETS, and VC_HASTMPVAR.

Referenced by merge_temporary_env(), and propagate_temp_var().

4464 {
4465  SHELL_VAR *var, *v;
4466  HASH_TABLE *binding_table;
4467 
4468  var = (SHELL_VAR *)data;
4469 
4470  binding_table = shell_variables->table;
4471  if (binding_table == 0)
4472  {
4474  /* shouldn't happen */
4476  else
4478  }
4479 
4480  v = bind_variable_internal (var->name, value_cell (var), binding_table, 0, ASS_FORCE|ASS_NOLONGJMP);
4481 
4482  /* XXX - should we set the context here? It shouldn't matter because of how
4483  assign_in_env works, but we do it anyway. */
4484  if (v)
4486 
4487  if (binding_table == global_variables->table) /* XXX */
4489  else
4490  {
4491  var->attributes |= att_propagate;
4492  if (binding_table == shell_variables->table)
4494  }
4495  if (v)
4496  v->attributes |= var->attributes;
4497 
4498  if (find_special_var (var->name) >= 0)
4499  tempvar_list[tvlist_ind++] = savestring (var->name);
4500 
4501  dispose_variable (var);
4502 }
#define VC_HASTMPVAR
Definition: variables.h:45
static SHELL_VAR * bind_variable_internal(char *name, char *value, HASH_TABLE *table, int hflags, int aflags) const
Definition: variables.c:3026
HASH_TABLE * table
Definition: variables.h:40
HASH_TABLE * hash_create(int buckets)
Definition: hashlib.c:46
#define att_propagate
Definition: variables.h:134
char ** tempvar_list
Definition: variables.c:4418
#define ASS_NOLONGJMP
Definition: subst.h:56
static int find_special_var(char *name) const
Definition: variables.c:5657
int tvlist_ind
Definition: variables.c:4419
int attributes
Definition: variables.h:92
VAR_CONTEXT * shell_variables
Definition: variables.c:107
char * savestring(const char *s)
Definition: savestring.c:33
#define VARIABLES_HASH_BUCKETS
Definition: variables.c:83
void dispose_variable(SHELL_VAR *var)
Definition: variables.c:3702
#define TEMPENV_HASH_BUCKETS
Definition: variables.c:85
#define ASS_FORCE
Definition: subst.h:52
int context
Definition: variables.h:93
char * name
Definition: variables.h:83
#define att_tempvar
Definition: variables.h:133
VAR_CONTEXT * global_variables
Definition: variables.c:104
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ propagate_temp_var()

static void propagate_temp_var ( char *  data)
static

Definition at line 4509 of file variables.c.

References att_propagate, variable::attributes, dispose_variable(), find_special_var(), variable::name, push_temp_var(), savestring(), and tempvar_p.

Referenced by dispose_used_env_vars().

4511 {
4512  SHELL_VAR *var;
4513 
4514  var = (SHELL_VAR *)data;
4515  if (tempvar_p (var) && (var->attributes & att_propagate))
4516  push_temp_var (data);
4517  else
4518  {
4519  if (find_special_var (var->name) >= 0)
4520  tempvar_list[tvlist_ind++] = savestring (var->name);
4521  dispose_variable (var);
4522  }
4523 }
#define att_propagate
Definition: variables.h:134
char ** tempvar_list
Definition: variables.c:4418
static int find_special_var(char *name) const
Definition: variables.c:5657
int tvlist_ind
Definition: variables.c:4419
int attributes
Definition: variables.h:92
char * savestring(const char *s)
Definition: savestring.c:33
void dispose_variable(SHELL_VAR *var)
Definition: variables.c:3702
static void push_temp_var(char *data)
Definition: variables.c:4462
#define tempvar_p(var)
Definition: variables.h:159
char * name
Definition: variables.h:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispose_temporary_env()

static void dispose_temporary_env ( sh_free_func_t *  pushf)
static

Definition at line 4533 of file variables.c.

References array_needs_making, hash_dispose(), HASH_ENTRIES, hash_flush(), i, NULL, strvec_create(), strvec_dispose(), stupidly_hack_special_variables(), and tvlist_ind.

Referenced by dispose_used_env_vars(), and merge_temporary_env().

4535 {
4536  int i;
4537 
4539  tempvar_list[tvlist_ind = 0] = 0;
4540 
4541  hash_flush (temporary_env, pushf);
4544 
4545  tempvar_list[tvlist_ind] = 0;
4546 
4547  array_needs_making = 1;
4548 
4549  for (i = 0; i < tvlist_ind; i++)
4551 
4553  tempvar_list = 0;
4554  tvlist_ind = 0;
4555 }
char ** strvec_create(int n)
Definition: stringvec.c:37
char ** tempvar_list
Definition: variables.c:4418
HASH_TABLE * temporary_env
Definition: variables.c:136
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
void strvec_dispose(char **array)
Definition: stringvec.c:93
void stupidly_hack_special_variables(char *name)
Definition: variables.c:5680
int array_needs_making
Definition: variables.c:151
int tvlist_ind
Definition: variables.c:4419
#define NULL
Definition: general.h:53
void hash_flush(HASH_TABLE *table, sh_free_func_t *free_data)
Definition: hashlib.c:284
#define HASH_ENTRIES(ht)
Definition: hashlib.h:78
void hash_dispose(HASH_TABLE *table)
Definition: hashlib.c:318
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispose_used_env_vars()

void dispose_used_env_vars ( )

Definition at line 4558 of file variables.c.

References dispose_temporary_env(), maybe_make_export_env(), and propagate_temp_var().

Referenced by execute_command_internal(), and reader_loop().

4559 {
4560  if (temporary_env)
4561  {
4564  }
4565 }
HASH_TABLE * temporary_env
Definition: variables.c:136
static void propagate_temp_var(char *data)
Definition: variables.c:4509
void maybe_make_export_env()
Definition: variables.c:4911
static void dispose_temporary_env(sh_free_func_t *pushf)
Definition: variables.c:4533
Here is the call graph for this function:
Here is the caller graph for this function:

◆ merge_temporary_env()

void merge_temporary_env ( )

Definition at line 4573 of file variables.c.

References dispose_temporary_env(), posixly_correct, push_posix_temp_var(), and push_temp_var().

Referenced by execute_builtin(), execute_simple_command(), and push_var_context().

4574 {
4575  if (temporary_env)
4577 }
HASH_TABLE * temporary_env
Definition: variables.c:136
int posixly_correct
Definition: shell.c:232
static void push_temp_var(char *data)
Definition: variables.c:4462
static void push_posix_temp_var(char *data)
Definition: variables.c:4426
static void dispose_temporary_env(sh_free_func_t *pushf)
Definition: variables.c:4533
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flush_temporary_env()

void flush_temporary_env ( )

Definition at line 4580 of file variables.c.

References free_variable_hash_data(), hash_dispose(), hash_flush(), and NULL.

Referenced by command_substitute(), and parameter_brace_remove_pattern().

4581 {
4582  if (temporary_env)
4583  {
4587  }
4588 }
HASH_TABLE * temporary_env
Definition: variables.c:136
#define NULL
Definition: general.h:53
void hash_flush(HASH_TABLE *table, sh_free_func_t *free_data)
Definition: hashlib.c:284
static void free_variable_hash_data(char *data)
Definition: variables.c:3958
void hash_dispose(HASH_TABLE *table)
Definition: hashlib.c:318
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mk_env_string()

static char* mk_env_string ( char *  name,
char *  value,
int  isfunc 
) const
inlinestatic

Definition at line 4597 of file variables.c.

References _(), BASHFUNC_PREFIX, BASHFUNC_PREFLEN, BASHFUNC_SUFFIX, BASHFUNC_SUFFLEN, dequote_escapes(), variable::exportstr, free(), internal_error(), legal_variable_char, legal_variable_starter, p, STRLEN, t, and xmalloc().

Referenced by assign_in_env(), and make_env_array_from_var_list().

4600 {
4601  size_t name_len, value_len;
4602  char *p, *q, *t;
4603 
4604  name_len = strlen (name);
4605  value_len = STRLEN (value);
4606 
4607  /* If we are exporting a shell function, construct the encoded function
4608  name. */
4609  if (isfunc && value)
4610  {
4611  p = (char *)xmalloc (BASHFUNC_PREFLEN + name_len + BASHFUNC_SUFFLEN + value_len + 2);
4612  q = p;
4613  memcpy (q, BASHFUNC_PREFIX, BASHFUNC_PREFLEN);
4614  q += BASHFUNC_PREFLEN;
4615  memcpy (q, name, name_len);
4616  q += name_len;
4617  memcpy (q, BASHFUNC_SUFFIX, BASHFUNC_SUFFLEN);
4618  q += BASHFUNC_SUFFLEN;
4619  }
4620  else
4621  {
4622  p = (char *)xmalloc (2 + name_len + value_len);
4623  memcpy (p, name, name_len);
4624  q = p + name_len;
4625  }
4626 
4627  q[0] = '=';
4628  if (value && *value)
4629  {
4630  if (isfunc)
4631  {
4632  t = dequote_escapes (value);
4633  value_len = STRLEN (t);
4634  memcpy (q + 1, t, value_len + 1);
4635  free (t);
4636  }
4637  else
4638  memcpy (q + 1, value, value_len + 1);
4639  }
4640  else
4641  q[1] = '\0';
4642 
4643  return (p);
4644 }
char * dequote_escapes(char *string) const
Definition: subst.c:4091
#define STRLEN(s)
Definition: general.h:171
#define BASHFUNC_PREFIX
Definition: variables.c:87
p
Definition: glob_loop.c:31
#define BASHFUNC_SUFFIX
Definition: variables.c:89
int t
Definition: gm_loop.c:77
void free()
#define BASHFUNC_SUFFLEN
Definition: variables.c:90
#define BASHFUNC_PREFLEN
Definition: variables.c:88
static char * xmalloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_env_array_from_var_list()

static char** make_env_array_from_var_list ( SHELL_VAR **  vars)
static

Definition at line 4685 of file variables.c.

References array_cell, array_p, assoc_cell, assoc_p, variable::dynamic_value, variable::exportstr, free(), function_cell, function_p, i, INVALIDATE_EXPORTSTR, list, mk_env_string(), variable::name, named_function_string(), NULL, regen_p, SAVE_EXPORTSTR, savestring(), strvec_create(), strvec_len(), USE_EXPORTSTR, and value_cell.

Referenced by make_func_export_array(), and make_var_export_array().

4687 {
4688  register int i, list_index;
4689  register SHELL_VAR *var;
4690  char **list, *value;
4691 
4692  list = strvec_create ((1 + strvec_len ((char **)vars)));
4693 
4694 #define USE_EXPORTSTR (value == var->exportstr)
4695 
4696  for (i = 0, list_index = 0; var = vars[i]; i++)
4697  {
4698 #if defined (__CYGWIN__)
4699  /* We don't use the exportstr stuff on Cygwin at all. */
4700  INVALIDATE_EXPORTSTR (var);
4701 #endif
4702 
4703  /* If the value is generated dynamically, generate it here. */
4704  if (regen_p (var) && var->dynamic_value)
4705  {
4706  var = (*(var->dynamic_value)) (var);
4707  INVALIDATE_EXPORTSTR (var);
4708  }
4709 
4710  if (var->exportstr)
4711  value = var->exportstr;
4712  else if (function_p (var))
4713  value = named_function_string ((char *)NULL, function_cell (var), 0);
4714 #if defined (ARRAY_VARS)
4715  else if (array_p (var))
4716 # if ARRAY_EXPORT
4717  value = array_to_assign (array_cell (var), 0);
4718 # else
4719  continue; /* XXX array vars cannot yet be exported */
4720 # endif /* ARRAY_EXPORT */
4721  else if (assoc_p (var))
4722 # if 0
4723  value = assoc_to_assign (assoc_cell (var), 0);
4724 # else
4725  continue; /* XXX associative array vars cannot yet be exported */
4726 # endif
4727 #endif
4728  else
4729  value = value_cell (var);
4730 
4731  if (value)
4732  {
4733  /* Gee, I'd like to get away with not using savestring() if we're
4734  using the cached exportstr... */
4735  list[list_index] = USE_EXPORTSTR ? savestring (value)
4736  : mk_env_string (var->name, value, function_p (var));
4737 
4738  if (USE_EXPORTSTR == 0)
4739  SAVE_EXPORTSTR (var, list[list_index]);
4740 
4741  list_index++;
4742 #undef USE_EXPORTSTR
4743 
4744 #if 0 /* not yet */
4745 #if defined (ARRAY_VARS)
4746  if (array_p (var) || assoc_p (var))
4747  free (value);
4748 #endif
4749 #endif
4750  }
4751  }
4752 
4753  list[list_index] = (char *)NULL;
4754  return (list);
4755 }
#define function_p(var)
Definition: variables.h:141
#define USE_EXPORTSTR
char ** strvec_create(int n)
Definition: stringvec.c:37
list
Definition: subst.c:10212
static char * mk_env_string(char *name, char *value, int isfunc) const
Definition: variables.c:4597
#define function_cell(var)
Definition: variables.h:167
#define array_p(var)
Definition: variables.h:140
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
#define assoc_cell(var)
Definition: variables.h:169
#define SAVE_EXPORTSTR(var, value)
Definition: variables.h:205
char * exportstr
Definition: variables.h:85
char * savestring(const char *s)
Definition: savestring.c:33
void free()
#define NULL
Definition: general.h:53
sh_var_value_func_t * dynamic_value
Definition: variables.h:86
#define INVALIDATE_EXPORTSTR(var)
Definition: variables.h:213
int strvec_len(char **array)
Definition: stringvec.c:69
#define assoc_p(var)
Definition: variables.h:144
#define regen_p(var)
Definition: variables.h:157
#define value_cell(var)
Definition: variables.h:166
#define array_cell(var)
Definition: variables.h:168
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_var_export_array()

static char** make_var_export_array ( VAR_CONTEXT vcxt)
static

Definition at line 4761 of file variables.c.

References export_environment_candidate(), free(), list, make_env_array_from_var_list(), map_over(), NULL, and visible_and_exported().

Referenced by maybe_make_export_env().

4763 {
4764  char **list;
4765  SHELL_VAR **vars;
4766 
4767 #if 0
4768  vars = map_over (visible_and_exported, vcxt);
4769 #else
4770  vars = map_over (export_environment_candidate, vcxt);
4771 #endif
4772 
4773  if (vars == 0)
4774  return (char **)NULL;
4775 
4776  list = make_env_array_from_var_list (vars);
4777 
4778  free (vars);
4779  return (list);
4780 }
SHELL_VAR ** map_over(sh_var_map_func_t *function, VAR_CONTEXT *vc)
Definition: variables.c:4105
list
Definition: subst.c:10212
void free()
#define NULL
Definition: general.h:53
static char ** make_env_array_from_var_list(SHELL_VAR **vars)
Definition: variables.c:4685
static int visible_and_exported(SHELL_VAR *var)
Definition: variables.c:4266
static int export_environment_candidate(SHELL_VAR *var)
Definition: variables.c:4276
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_func_export_array()

static char** make_func_export_array ( )
static

Definition at line 4783 of file variables.c.

References free(), list, make_env_array_from_var_list(), map_over_funcs(), NULL, and visible_and_exported().

Referenced by maybe_make_export_env().

4784 {
4785  char **list;
4786  SHELL_VAR **vars;
4787 
4789  if (vars == 0)
4790  return (char **)NULL;
4791 
4792  list = make_env_array_from_var_list (vars);
4793 
4794  free (vars);
4795  return (list);
4796 }
list
Definition: subst.c:10212
void free()
#define NULL
Definition: general.h:53
static char ** make_env_array_from_var_list(SHELL_VAR **vars)
Definition: variables.c:4685
SHELL_VAR ** map_over_funcs(sh_var_map_func_t *function)
Definition: variables.c:4131
static int visible_and_exported(SHELL_VAR *var)
Definition: variables.c:4266
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_or_supercede_exported_var()

char** add_or_supercede_exported_var ( char *  assign,
int  do_alloc 
)

Definition at line 4815 of file variables.c.

References add_to_export_env, assignment(), export_env, export_env_index, free(), i, savestring(), and STREQN.

Referenced by add_temp_array_to_env(), and update_export_env_inplace().

4818 {
4819  register int i;
4820  int equal_offset;
4821 
4822  equal_offset = assignment (assign, 0);
4823  if (equal_offset == 0)
4824  return (export_env);
4825 
4826  /* If this is a function, then only supersede the function definition.
4827  We do this by including the `=() {' in the comparison, like
4828  initialize_shell_variables does. */
4829  if (assign[equal_offset + 1] == '(' &&
4830  strncmp (assign + equal_offset + 2, ") {", 3) == 0) /* } */
4831  equal_offset += 4;
4832 
4833  for (i = 0; i < export_env_index; i++)
4834  {
4835  if (STREQN (assign, export_env[i], equal_offset + 1))
4836  {
4837  free (export_env[i]);
4838  export_env[i] = do_alloc ? savestring (assign) : assign;
4839  return (export_env);
4840  }
4841  }
4842  add_to_export_env (assign, do_alloc);
4843  return (export_env);
4844 }
int assignment(char *string, int flags) const
Definition: general.c:358
char ** export_env
Definition: variables.c:160
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
char * savestring(const char *s)
Definition: savestring.c:33
void free()
#define STREQN(a, b, n)
Definition: general.h:167
static int export_env_index
Definition: variables.c:161
#define add_to_export_env(envstr, do_alloc)
Definition: variables.c:4799
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_temp_array_to_env()

static void add_temp_array_to_env ( char **  temp_array,
int  do_alloc,
int  do_supercede 
)
static

Definition at line 4847 of file variables.c.

References add_or_supercede_exported_var(), add_to_export_env, export_env, free(), and i.

Referenced by maybe_make_export_env().

4850 {
4851  register int i;
4852 
4853  if (temp_array == 0)
4854  return;
4855 
4856  for (i = 0; temp_array[i]; i++)
4857  {
4858  if (do_supercede)
4859  export_env = add_or_supercede_exported_var (temp_array[i], do_alloc);
4860  else
4861  add_to_export_env (temp_array[i], do_alloc);
4862  }
4863 
4864  free (temp_array);
4865 }
char ** add_or_supercede_exported_var(char *assign, int do_alloc)
Definition: variables.c:4815
char ** export_env
Definition: variables.c:160
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
void free()
#define add_to_export_env(envstr, do_alloc)
Definition: variables.c:4799
Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_shell_variables()

static int n_shell_variables ( )
static

Definition at line 4884 of file variables.c.

References var_context::down, HASH_ENTRIES, n, and var_context::table.

Referenced by maybe_make_export_env().

4885 {
4886  VAR_CONTEXT *vc;
4887  int n;
4888 
4889  for (n = 0, vc = shell_variables; vc; vc = vc->down)
4890  n += HASH_ENTRIES (vc->table);
4891  return n;
4892 }
HASH_TABLE * table
Definition: variables.h:40
unsigned long int n
Definition: eval-plural.h:35
VAR_CONTEXT * shell_variables
Definition: variables.c:107
#define HASH_ENTRIES(ht)
Definition: hashlib.h:78
struct var_context * down
Definition: variables.h:39
Here is the caller graph for this function:

◆ chkexport()

int chkexport ( char *  name)

Definition at line 4895 of file variables.c.

References array_needs_making, exported_p, find_variable(), and maybe_make_export_env().

Referenced by sv_globignore().

4897 {
4898  SHELL_VAR *v;
4899 
4900  v = find_variable (name);
4901  if (v && exported_p (v))
4902  {
4903  array_needs_making = 1;
4905  return 1;
4906  }
4907  return 0;
4908 }
#define exported_p(var)
Definition: variables.h:138
int array_needs_making
Definition: variables.c:151
void maybe_make_export_env()
Definition: variables.c:4911
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
Here is the call graph for this function:
Here is the caller graph for this function:

◆ maybe_make_export_env()

void maybe_make_export_env ( )

Definition at line 4911 of file variables.c.

References add_temp_array_to_env(), array_needs_making, var_context::down, environ, export_env, export_env_index, export_env_size, free(), HASH_ENTRIES, invalid_env, make_func_export_array(), make_var_export_array(), n_shell_variables(), new_var_context(), NULL, shell_variables, strvec_flush(), strvec_resize(), var_context::table, and temporary_env.

Referenced by chkexport(), command_substitute(), dispose_used_env_vars(), execute_disk_command(), execute_simple_command(), execute_subshell_builtin_or_function(), printenv_builtin(), reset_locale_vars(), and sv_globignore().

4912 {
4913  register char **temp_array;
4914  int new_size;
4915  VAR_CONTEXT *tcxt, *icxt;
4916 
4917  if (array_needs_making)
4918  {
4919  if (export_env)
4921 
4922  /* Make a guess based on how many shell variables and functions we
4923  have. Since there will always be array variables, and array
4924  variables are not (yet) exported, this will always be big enough
4925  for the exported variables and functions. */
4926  new_size = n_shell_variables () + HASH_ENTRIES (shell_functions) + 1 +
4928  if (new_size > export_env_size)
4929  {
4930  export_env_size = new_size;
4932  environ = export_env;
4933  }
4934  export_env[export_env_index = 0] = (char *)NULL;
4935 
4936  /* Make a dummy variable context from the temporary_env, stick it on
4937  the front of shell_variables, call make_var_export_array on the
4938  whole thing to flatten it, and convert the list of SHELL_VAR *s
4939  to the form needed by the environment. */
4940  if (temporary_env)
4941  {
4942  tcxt = new_var_context ((char *)NULL, 0);
4943  tcxt->table = temporary_env;
4944  tcxt->down = shell_variables;
4945  }
4946  else
4947  tcxt = shell_variables;
4948 
4949  if (invalid_env)
4950  {
4951  icxt = new_var_context ((char *)NULL, 0);
4952  icxt->table = invalid_env;
4953  icxt->down = tcxt;
4954  }
4955  else
4956  icxt = tcxt;
4957 
4958  temp_array = make_var_export_array (icxt);
4959  if (temp_array)
4960  add_temp_array_to_env (temp_array, 0, 0);
4961 
4962  if (icxt != tcxt)
4963  free (icxt);
4964 
4965  if (tcxt != shell_variables)
4966  free (tcxt);
4967 
4968 #if defined (RESTRICTED_SHELL)
4969  /* Restricted shells may not export shell functions. */
4970  temp_array = restricted ? (char **)0 : make_func_export_array ();
4971 #else
4972  temp_array = make_func_export_array ();
4973 #endif
4974  if (temp_array)
4975  add_temp_array_to_env (temp_array, 0, 0);
4976 
4977  array_needs_making = 0;
4978  }
4979 }
static void add_temp_array_to_env(char **temp_array, int do_alloc, int do_supercede)
Definition: variables.c:4847
static char ** make_func_export_array()
Definition: variables.c:4783
HASH_TABLE * table
Definition: variables.h:40
char ** strvec_resize(char **array, int nsize)
Definition: stringvec.c:52
char ** environ
VAR_CONTEXT * new_var_context(char *name, int flags)
Definition: variables.c:5023
HASH_TABLE * temporary_env
Definition: variables.c:136
static int n_shell_variables()
Definition: variables.c:4884
char ** export_env
Definition: variables.c:160
int array_needs_making
Definition: variables.c:151
VAR_CONTEXT * shell_variables
Definition: variables.c:107
void free()
HASH_TABLE * invalid_env
Definition: variables.c:113
void strvec_flush(char **array)
Definition: stringvec.c:80
#define NULL
Definition: general.h:53
static int export_env_index
Definition: variables.c:161
static char ** make_var_export_array(VAR_CONTEXT *vcxt)
Definition: variables.c:4761
HASH_TABLE * shell_functions
Definition: variables.c:111
#define HASH_ENTRIES(ht)
Definition: hashlib.h:78
struct var_context * down
Definition: variables.h:39
static int export_env_size
Definition: variables.c:162
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_export_env_inplace()

void update_export_env_inplace ( char *  env_prefix,
int  preflen,
char *  value 
)

Definition at line 4991 of file variables.c.

References add_or_supercede_exported_var(), export_env, strcpy(), STRLEN, and xmalloc().

Referenced by put_command_name_into_env().

4995 {
4996  char *evar;
4997 
4998  evar = (char *)xmalloc (STRLEN (value) + preflen + 1);
4999  strcpy (evar, env_prefix);
5000  if (value)
5001  strcpy (evar + preflen, value);
5003 }
char ** add_or_supercede_exported_var(char *assign, int do_alloc)
Definition: variables.c:4815
#define STRLEN(s)
Definition: general.h:171
char ** export_env
Definition: variables.c:160
char * strcpy()
static char * xmalloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ put_command_name_into_env()

void put_command_name_into_env ( char *  command_name)

Definition at line 5007 of file variables.c.

References update_export_env_inplace().

Referenced by execute_disk_command().

5009 {
5010  update_export_env_inplace ("_=", 2, command_name);
5011 }
void update_export_env_inplace(char *env_prefix, int preflen, char *value)
Definition: variables.c:4991
Here is the call graph for this function:
Here is the caller graph for this function:

◆ new_var_context()

VAR_CONTEXT* new_var_context ( char *  name,
int  flags 
)

Definition at line 5023 of file variables.c.

References var_context::down, var_context::flags, flags, var_context::name, NULL, savestring(), var_context::scope, var_context::table, var_context::up, variable_context, and xmalloc().

Referenced by create_variable_tables(), maybe_make_export_env(), and push_var_context().

5026 {
5027  VAR_CONTEXT *vc;
5028 
5029  vc = (VAR_CONTEXT *)xmalloc (sizeof (VAR_CONTEXT));
5030  vc->name = name ? savestring (name) : (char *)NULL;
5031  vc->scope = variable_context;
5032  vc->flags = flags;
5033 
5034  vc->up = vc->down = (VAR_CONTEXT *)NULL;
5035  vc->table = (HASH_TABLE *)NULL;
5036 
5037  return vc;
5038 }
HASH_TABLE * table
Definition: variables.h:40
struct var_context * up
Definition: variables.h:38
char * savestring(const char *s)
Definition: savestring.c:33
int variable_context
Definition: variables.c:123
#define NULL
Definition: general.h:53
int flags
Definition: gm_loop.c:47
char * name
Definition: variables.h:35
static char * xmalloc()
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispose_var_context()

void dispose_var_context ( VAR_CONTEXT vc)

Definition at line 5043 of file variables.c.

References delete_all_variables(), free(), FREE, hash_dispose(), var_context::name, and var_context::table.

Referenced by delete_all_contexts(), and pop_var_context().

5045 {
5046  FREE (vc->name);
5047 
5048  if (vc->table)
5049  {
5051  hash_dispose (vc->table);
5052  }
5053 
5054  free (vc);
5055 }
HASH_TABLE * table
Definition: variables.h:40
void free()
#define FREE(s)
Definition: general.h:172
void delete_all_variables(HASH_TABLE *hashed_vars)
Definition: variables.c:3969
char * name
Definition: variables.h:35
void hash_dispose(HASH_TABLE *table)
Definition: hashlib.c:318
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_context()

static int set_context ( SHELL_VAR var)
static

Definition at line 5059 of file variables.c.

References variable::context, and variable_context.

Referenced by push_var_context().

5061 {
5062  return (var->context = variable_context);
5063 }
int variable_context
Definition: variables.c:123
int context
Definition: variables.h:93
Here is the caller graph for this function:

◆ push_var_context()

VAR_CONTEXT* push_var_context ( char *  name,
int  flags,
HASH_TABLE tempvars 
)

Definition at line 5069 of file variables.c.

References var_context::down, var_context::flags, flatten(), merge_temporary_env(), new_var_context(), NULL, posixly_correct, set_context(), shell_variables, var_context::table, var_context::up, VC_FUNCENV, and VC_HASTMPVAR.

Referenced by push_context(), and push_scope().

5073 {
5074  VAR_CONTEXT *vc;
5075  int posix_func_behavior;
5076 
5077  /* As of IEEE Std 1003.1-2017, assignment statements preceding shell
5078  functions no longer behave like assignment statements preceding
5079  special builtins, and do not persist in the current shell environment.
5080  This is austin group interp #654, though nobody implements it yet. */
5081 #if 0 /* XXX - TAG: bash-5.1 */
5082  posix_func_behavior = 0;
5083 #else
5084  posix_func_behavior = posixly_correct;
5085 #endif
5086 
5087  vc = new_var_context (name, flags);
5088  /* Posix interp 1009, temporary assignments preceding function calls modify
5089  the current environment *before* the command is executed. */
5090  if (posix_func_behavior && (flags & VC_FUNCENV) && tempvars == temporary_env)
5092  else if (tempvars)
5093  {
5094  vc->table = tempvars;
5095  /* Have to do this because the temp environment was created before
5096  variable_context was incremented. */
5097  flatten (tempvars, set_context, (VARLIST *)NULL, 0);
5098  vc->flags |= VC_HASTMPVAR;
5099  }
5100  vc->down = shell_variables;
5101  shell_variables->up = vc;
5102 
5103  return (shell_variables = vc);
5104 }
#define VC_HASTMPVAR
Definition: variables.h:45
HASH_TABLE * table
Definition: variables.h:40
static int set_context(SHELL_VAR *var)
Definition: variables.c:5059
#define VC_FUNCENV
Definition: variables.h:46
VAR_CONTEXT * new_var_context(char *name, int flags)
Definition: variables.c:5023
HASH_TABLE * temporary_env
Definition: variables.c:136
int posixly_correct
Definition: shell.c:232
void merge_temporary_env()
Definition: variables.c:4573
struct var_context * up
Definition: variables.h:38
VAR_CONTEXT * shell_variables
Definition: variables.c:107
static void flatten(HASH_TABLE *var_hash_table, sh_var_map_func_t *func, VARLIST *vlist, int flags)
Definition: variables.c:4156
#define NULL
Definition: general.h:53
int flags
Definition: gm_loop.c:47
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_posix_tempvar_internal()

static void push_posix_tempvar_internal ( SHELL_VAR var,
int  isbltin 
)
inlinestatic

Definition at line 5119 of file variables.c.

References array_cell, array_p, assoc_cell, assoc_copy, assoc_p, att_propagate, att_tempvar, variable::attributes, bind_variable_internal(), variable::context, dispose_variable(), var_context::flags, FREE, hash_create(), local_p, variable::name, posixly_correct, var_context::scope, STREQ, stupidly_hack_special_variables(), var_context::table, tempvar_p, value_cell, var_setarray, var_setassoc, VARIABLES_HASH_BUCKETS, VC_HASTMPVAR, vc_isfuncenv, and vc_istempenv.

Referenced by push_builtin_var(), and push_func_var().

5122 {
5123  SHELL_VAR *v;
5124  int posix_var_behavior;
5125 
5126  /* As of IEEE Std 1003.1-2017, assignment statements preceding shell
5127  functions no longer behave like assignment statements preceding
5128  special builtins, and do not persist in the current shell environment.
5129  This is austin group interp #654, though nobody implements it yet. */
5130 #if 0 /* XXX - TAG: bash-5.1 */
5131  posix_var_behavior = posixly_correct && isbltin;
5132 #else
5133  posix_var_behavior = posixly_correct;
5134 #endif
5135 
5136  if (local_p (var) && STREQ (var->name, "-"))
5137  set_current_options (value_cell (var));
5138  else if (tempvar_p (var) && (posix_var_behavior || (var->attributes & att_propagate)))
5139  {
5140  /* Make sure we have a hash table to store the variable in while it is
5141  being propagated down to the global variables table. Create one if
5142  we have to */
5145  v = bind_variable_internal (var->name, value_cell (var), shell_variables->table, 0, 0);
5146  /* XXX - should we set v->context here? */
5147  if (v)
5149 #if defined (ARRAY_VARS)
5150  if (v && (array_p (var) || assoc_p (var)))
5151  {
5152  FREE (value_cell (v));
5153  if (array_p (var))
5154  var_setarray (v, array_copy (array_cell (var)));
5155  else
5156  var_setassoc (v, assoc_copy (assoc_cell (var)));
5157  }
5158 #endif
5161  else
5163  if (v)
5164  v->attributes |= var->attributes;
5165  }
5166  else
5167  stupidly_hack_special_variables (var->name); /* XXX */
5168 
5169  dispose_variable (var);
5170 }
#define VC_HASTMPVAR
Definition: variables.h:45
static SHELL_VAR * bind_variable_internal(char *name, char *value, HASH_TABLE *table, int hflags, int aflags) const
Definition: variables.c:3026
HASH_TABLE * table
Definition: variables.h:40
HASH_TABLE * hash_create(int buckets)
Definition: hashlib.c:46
#define array_p(var)
Definition: variables.h:140
#define att_propagate
Definition: variables.h:134
#define assoc_copy(h)
Definition: assoc.h:33
#define var_setarray(var, arr)
Definition: variables.h:181
int posixly_correct
Definition: shell.c:232
#define assoc_cell(var)
Definition: variables.h:169
void stupidly_hack_special_variables(char *name)
Definition: variables.c:5680
int attributes
Definition: variables.h:92
VAR_CONTEXT * shell_variables
Definition: variables.c:107
#define var_setassoc(var, arr)
Definition: variables.h:182
#define VARIABLES_HASH_BUCKETS
Definition: variables.c:83
void dispose_variable(SHELL_VAR *var)
Definition: variables.c:3702
#define FREE(s)
Definition: general.h:172
#define tempvar_p(var)
Definition: variables.h:159
#define STREQ(a, b)
Definition: general.h:166
#define vc_istempenv(vc)
Definition: variables.h:55
#define vc_isfuncenv(vc)
Definition: variables.h:53
int context
Definition: variables.h:93
char * name
Definition: variables.h:83
#define att_tempvar
Definition: variables.h:133
#define local_p(var)
Definition: variables.h:143
#define assoc_p(var)
Definition: variables.h:144
VAR_CONTEXT * global_variables
Definition: variables.c:104
#define value_cell(var)
Definition: variables.h:166
#define array_cell(var)
Definition: variables.h:168
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_func_var()

static void push_func_var ( char *  data)
static

Definition at line 5173 of file variables.c.

References push_posix_tempvar_internal().

Referenced by pop_var_context().

5175 {
5176  SHELL_VAR *var;
5177 
5178  var = (SHELL_VAR *)data;
5179  push_posix_tempvar_internal (var, 0);
5180 }
static void push_posix_tempvar_internal(SHELL_VAR *var, int isbltin)
Definition: variables.c:5119
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_builtin_var()

static void push_builtin_var ( char *  data)
static

Definition at line 5183 of file variables.c.

References push_posix_tempvar_internal().

Referenced by pop_scope().

5185 {
5186  SHELL_VAR *var;
5187 
5188  var = (SHELL_VAR *)data;
5189  push_posix_tempvar_internal (var, 1);
5190 }
static void push_posix_tempvar_internal(SHELL_VAR *var, int isbltin)
Definition: variables.c:5119
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_var_context()

void pop_var_context ( )

Definition at line 5195 of file variables.c.

References _(), dispose_var_context(), var_context::down, hash_flush(), internal_error(), NULL, push_func_var(), shell_variables, var_context::table, var_context::up, and vc_isfuncenv.

Referenced by pop_context().

5196 {
5197  VAR_CONTEXT *ret, *vcxt;
5198 
5199  vcxt = shell_variables;
5200  if (vc_isfuncenv (vcxt) == 0)
5201  {
5202  internal_error (_("pop_var_context: head of shell_variables not a function context"));
5203  return;
5204  }
5205 
5206  if (ret = vcxt->down)
5207  {
5208  ret->up = (VAR_CONTEXT *)NULL;
5209  shell_variables = ret;
5210  if (vcxt->table)
5211  hash_flush (vcxt->table, push_func_var);
5212  dispose_var_context (vcxt);
5213  }
5214  else
5215  internal_error (_("pop_var_context: no global_variables context"));
5216 }
HASH_TABLE * table
Definition: variables.h:40
struct var_context * up
Definition: variables.h:38
VAR_CONTEXT * shell_variables
Definition: variables.c:107
void xs_init _((void))
#define NULL
Definition: general.h:53
void internal_error(char *format, va_alist) const
Definition: error.c:235
static void push_func_var(char *data)
Definition: variables.c:5173
void hash_flush(HASH_TABLE *table, sh_free_func_t *free_data)
Definition: hashlib.c:284
void dispose_var_context(VAR_CONTEXT *vc)
Definition: variables.c:5043
#define vc_isfuncenv(vc)
Definition: variables.h:53
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_all_contexts()

void delete_all_contexts ( VAR_CONTEXT vcxt)

Definition at line 5221 of file variables.c.

References delete_all_variables(), dispose_var_context(), var_context::down, global_variables, t, and var_context::table.

Referenced by shell_reinitialize().

5223 {
5224  VAR_CONTEXT *v, *t;
5225 
5226  for (v = vcxt; v != global_variables; v = t)
5227  {
5228  t = v->down;
5229  dispose_var_context (v);
5230  }
5231 
5234 }
HASH_TABLE * table
Definition: variables.h:40
VAR_CONTEXT * shell_variables
Definition: variables.c:107
int t
Definition: gm_loop.c:77
void dispose_var_context(VAR_CONTEXT *vc)
Definition: variables.c:5043
void delete_all_variables(HASH_TABLE *hashed_vars)
Definition: variables.c:3969
VAR_CONTEXT * global_variables
Definition: variables.c:104
struct var_context * down
Definition: variables.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_scope()

VAR_CONTEXT* push_scope ( int  flags,
HASH_TABLE tmpvars 
)

Definition at line 5243 of file variables.c.

References NULL, and push_var_context().

Referenced by execute_builtin().

5246 {
5247  return (push_var_context ((char *)NULL, flags, tmpvars));
5248 }
VAR_CONTEXT * push_var_context(char *name, int flags, HASH_TABLE *tempvars)
Definition: variables.c:5069
#define NULL
Definition: general.h:53
int flags
Definition: gm_loop.c:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_exported_var()

static void push_exported_var ( char *  data)
static

Definition at line 5251 of file variables.c.

References att_propagate, att_tempvar, variable::attributes, bind_variable_internal(), variable::context, dispose_variable(), exported_p, variable::name, var_context::scope, stupidly_hack_special_variables(), var_context::table, tempvar_p, and value_cell.

Referenced by pop_scope().

5253 {
5254  SHELL_VAR *var, *v;
5255 
5256  var = (SHELL_VAR *)data;
5257 
5258  /* If a temp var had its export attribute set, or it's marked to be
5259  propagated, bind it in the previous scope before disposing it. */
5260  /* XXX - This isn't exactly right, because all tempenv variables have the
5261  export attribute set. */
5262  if (tempvar_p (var) && exported_p (var) && (var->attributes & att_propagate))
5263  {
5264  var->attributes &= ~att_tempvar; /* XXX */
5265  v = bind_variable_internal (var->name, value_cell (var), shell_variables->table, 0, 0);
5267  var->attributes &= ~att_propagate;
5268  if (v)
5269  {
5270  v->attributes |= var->attributes;
5272  }
5273  }
5274  else
5275  stupidly_hack_special_variables (var->name); /* XXX */
5276 
5277  dispose_variable (var);
5278 }
static SHELL_VAR * bind_variable_internal(char *name, char *value, HASH_TABLE *table, int hflags, int aflags) const
Definition: variables.c:3026
HASH_TABLE * table
Definition: variables.h:40
#define att_propagate
Definition: variables.h:134
#define exported_p(var)
Definition: variables.h:138
void stupidly_hack_special_variables(char *name)
Definition: variables.c:5680
int attributes
Definition: variables.h:92
VAR_CONTEXT * shell_variables
Definition: variables.c:107
void dispose_variable(SHELL_VAR *var)
Definition: variables.c:3702
#define tempvar_p(var)
Definition: variables.h:159
int context
Definition: variables.h:93
char * name
Definition: variables.h:83
#define att_tempvar
Definition: variables.h:133
VAR_CONTEXT * global_variables
Definition: variables.c:104
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_scope()

void pop_scope ( int  is_special)

Definition at line 5286 of file variables.c.

References _(), var_context::down, free(), FREE, hash_dispose(), hash_flush(), internal_error(), var_context::name, NULL, push_builtin_var(), push_exported_var(), shell_variables, sv_ifs(), var_context::table, var_context::up, vc_isbltnenv, and vc_istempscope.

Referenced by execute_builtin().

5288 {
5289  VAR_CONTEXT *vcxt, *ret;
5290  int is_bltinenv;
5291 
5292  vcxt = shell_variables;
5293  if (vc_istempscope (vcxt) == 0)
5294  {
5295  internal_error (_("pop_scope: head of shell_variables not a temporary environment scope"));
5296  return;
5297  }
5298  is_bltinenv = vc_isbltnenv (vcxt); /* XXX - for later */
5299 
5300  ret = vcxt->down;
5301  if (ret)
5302  ret->up = (VAR_CONTEXT *)NULL;
5303 
5304  shell_variables = ret;
5305 
5306  /* Now we can take care of merging variables in VCXT into set of scopes
5307  whose head is RET (shell_variables). */
5308  FREE (vcxt->name);
5309  if (vcxt->table)
5310  {
5311  if (is_special)
5313  else
5315  hash_dispose (vcxt->table);
5316  }
5317  free (vcxt);
5318 
5319  sv_ifs ("IFS"); /* XXX here for now */
5320 }
void sv_ifs(char *name)
Definition: variables.c:5711
HASH_TABLE * table
Definition: variables.h:40
struct var_context * up
Definition: variables.h:38
VAR_CONTEXT * shell_variables
Definition: variables.c:107
static void push_exported_var(char *data)
Definition: variables.c:5251
void xs_init _((void))
void free()
#define NULL
Definition: general.h:53
void internal_error(char *format, va_alist) const
Definition: error.c:235
#define FREE(s)
Definition: general.h:172
void hash_flush(HASH_TABLE *table, sh_free_func_t *free_data)
Definition: hashlib.c:284
static void push_builtin_var(char *data)
Definition: variables.c:5183
#define vc_isbltnenv(vc)
Definition: variables.h:54
#define vc_istempscope(vc)
Definition: variables.h:57
char * name
Definition: variables.h:35
struct var_context * down
Definition: variables.h:39
void hash_dispose(HASH_TABLE *table)
Definition: hashlib.c:318
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_dollar_vars()

static char** save_dollar_vars ( )
static

Definition at line 5340 of file variables.c.

References dollar_vars, i, NULL, and strvec_create().

Referenced by push_dollar_vars().

5341 {
5342  char **ret;
5343  int i;
5344 
5345  ret = strvec_create (10);
5346  for (i = 1; i < 10; i++)
5347  {
5348  ret[i] = dollar_vars[i];
5349  dollar_vars[i] = (char *)NULL;
5350  }
5351  return ret;
5352 }
char ** strvec_create(int n)
Definition: stringvec.c:37
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
char * dollar_vars[10]
Definition: variables.c:144
#define NULL
Definition: general.h:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_dollar_vars()

static void restore_dollar_vars ( char **  args)
static

Definition at line 5355 of file variables.c.

References dollar_vars, and i.

Referenced by pop_dollar_vars().

5357 {
5358  int i;
5359 
5360  for (i = 1; i < 10; i++)
5361  dollar_vars[i] = args[i];
5362 }
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
char * dollar_vars[10]
Definition: variables.c:144
Here is the caller graph for this function:

◆ free_dollar_vars()

static void free_dollar_vars ( )
static

Definition at line 5365 of file variables.c.

References dollar_vars, FREE, i, and NULL.

Referenced by pop_dollar_vars().

5366 {
5367  int i;
5368 
5369  for (i = 1; i < 10; i++)
5370  {
5371  FREE (dollar_vars[i]);
5372  dollar_vars[i] = (char *)NULL;
5373  }
5374 }
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
char * dollar_vars[10]
Definition: variables.c:144
#define NULL
Definition: general.h:53
#define FREE(s)
Definition: general.h:172
Here is the caller graph for this function:

◆ free_saved_dollar_vars()

static void free_saved_dollar_vars ( char **  args)
static

Definition at line 5377 of file variables.c.

References FREE, and i.

Referenced by dispose_saved_dollar_vars().

5379 {
5380  int i;
5381 
5382  for (i = 1; i < 10; i++)
5383  FREE (args[i]);
5384 }
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
#define FREE(s)
Definition: general.h:172
Here is the caller graph for this function:

◆ push_context()

void push_context ( char *  name,
int  is_subshell,
HASH_TABLE tempvars 
)

Definition at line 5388 of file variables.c.

References push_dollar_vars(), push_var_context(), variable_context, and VC_FUNCENV.

Referenced by execute_function().

5392 {
5393  if (is_subshell == 0)
5394  push_dollar_vars ();
5395  variable_context++;
5396  push_var_context (name, VC_FUNCENV, tempvars);
5397 }
VAR_CONTEXT * push_var_context(char *name, int flags, HASH_TABLE *tempvars)
Definition: variables.c:5069
void push_dollar_vars()
Definition: variables.c:5413
#define VC_FUNCENV
Definition: variables.h:46
int variable_context
Definition: variables.c:123
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_context()

void pop_context ( )

Definition at line 5402 of file variables.c.

References pop_dollar_vars(), pop_var_context(), sv_ifs(), and variable_context.

Referenced by execute_function().

5403 {
5404  pop_dollar_vars ();
5405  variable_context--;
5406  pop_var_context ();
5407 
5408  sv_ifs ("IFS"); /* XXX here for now */
5409 }
void sv_ifs(char *name)
Definition: variables.c:5711
void pop_var_context()
Definition: variables.c:5195
void pop_dollar_vars()
Definition: variables.c:5432
int variable_context
Definition: variables.c:123
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_dollar_vars()

void push_dollar_vars ( )

Definition at line 5413 of file variables.c.

References dollar_arg_stack_index, saved_dollar_vars::first_ten, NULL, saved_dollar_vars::rest, rest_of_args, save_dollar_vars(), and xrealloc().

Referenced by push_context().

5414 {
5416  {
5417  dollar_arg_stack = (struct saved_dollar_vars *)
5419  * sizeof (struct saved_dollar_vars));
5420  }
5421 
5425 
5428 }
static char ** save_dollar_vars()
Definition: variables.c:5340
WORD_LIST * rest_of_args
Definition: variables.c:145
static int dollar_arg_stack_index
Definition: variables.c:5335
static int dollar_arg_stack_slots
Definition: variables.c:5334
static char * xrealloc()
WORD_LIST * rest
Definition: variables.c:5330
#define NULL
Definition: general.h:53
static struct saved_dollar_vars * dollar_arg_stack
Definition: variables.c:5333
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_dollar_vars()

void pop_dollar_vars ( )

Definition at line 5432 of file variables.c.

References dispose_words(), dollar_arg_stack_index, saved_dollar_vars::first_ten, free(), free_dollar_vars(), invalidate_cached_quoted_dollar_at(), NULL, saved_dollar_vars::rest, restore_dollar_vars(), and set_dollar_vars_unchanged().

Referenced by pop_context().

5433 {
5434  if (dollar_arg_stack == 0 || dollar_arg_stack_index == 0)
5435  return;
5436 
5437  /* Do what remember_args (xxx, 1) would have done. */
5438  free_dollar_vars ();
5440 
5444 
5447 
5450 }
static void free_dollar_vars()
Definition: variables.c:5365
WORD_LIST * rest_of_args
Definition: variables.c:145
void set_dollar_vars_unchanged()
Definition: common.c:425
static void restore_dollar_vars(char **args)
Definition: variables.c:5355
static int dollar_arg_stack_index
Definition: variables.c:5335
void free()
void dispose_words(WORD_LIST *list)
Definition: dispose_cmd.c:264
WORD_LIST * rest
Definition: variables.c:5330
#define NULL
Definition: general.h:53
void invalidate_cached_quoted_dollar_at()
Definition: subst.c:9641
static struct saved_dollar_vars * dollar_arg_stack
Definition: variables.c:5333
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispose_saved_dollar_vars()

void dispose_saved_dollar_vars ( )

Definition at line 5453 of file variables.c.

References dispose_words(), dollar_arg_stack_index, saved_dollar_vars::first_ten, free(), free_saved_dollar_vars(), NULL, and saved_dollar_vars::rest.

5454 {
5455  if (dollar_arg_stack == 0 || dollar_arg_stack_index == 0)
5456  return;
5457 
5461 
5464 }
static int dollar_arg_stack_index
Definition: variables.c:5335
static void free_saved_dollar_vars(char **args)
Definition: variables.c:5377
void free()
void dispose_words(WORD_LIST *list)
Definition: dispose_cmd.c:264
WORD_LIST * rest
Definition: variables.c:5330
#define NULL
Definition: general.h:53
static struct saved_dollar_vars * dollar_arg_stack
Definition: variables.c:5333
Here is the call graph for this function:

◆ init_bash_argv()

void init_bash_argv ( )

Definition at line 5469 of file variables.c.

References bash_argv_initialized, and save_bash_argv().

Referenced by _evalfile(), execute_function(), and get_bash_command().

5470 {
5471  if (bash_argv_initialized == 0)
5472  {
5473  save_bash_argv ();
5475  }
5476 }
int bash_argv_initialized
Definition: shell.c:111
void save_bash_argv()
Definition: variables.c:5479
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_bash_argv()

void save_bash_argv ( )

Definition at line 5479 of file variables.c.

References dispose_words(), list, list_rest_of_args(), and push_args().

Referenced by init_bash_argv().

5480 {
5481  WORD_LIST *list;
5482 
5483  list = list_rest_of_args ();
5484  push_args (list);
5485  dispose_words (list);
5486 }
void push_args(WORD_LIST *list)
Definition: variables.c:5491
list
Definition: subst.c:10212
void dispose_words(WORD_LIST *list)
Definition: dispose_cmd.c:264
WORD_LIST * list_rest_of_args()
Definition: subst.c:3316
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_args()

void push_args ( WORD_LIST list)

Definition at line 5491 of file variables.c.

References array_push, free(), GET_ARRAY_FROM_VAR, i, itos(), word_list::next, t, word_desc::word, and word_list::word.

Referenced by bind_args(), execute_function(), and save_bash_argv().

5493 {
5494 #if defined (ARRAY_VARS) && defined (DEBUGGER)
5495  SHELL_VAR *bash_argv_v, *bash_argc_v;
5496  ARRAY *bash_argv_a, *bash_argc_a;
5497  WORD_LIST *l;
5498  arrayind_t i;
5499  char *t;
5500 
5501  GET_ARRAY_FROM_VAR ("BASH_ARGV", bash_argv_v, bash_argv_a);
5502  GET_ARRAY_FROM_VAR ("BASH_ARGC", bash_argc_v, bash_argc_a);
5503 
5504  for (l = list, i = 0; l; l = l->next, i++)
5505  array_push (bash_argv_a, l->word->word);
5506 
5507  t = itos (i);
5508  array_push (bash_argc_a, t);
5509  free (t);
5510 #endif /* ARRAY_VARS && DEBUGGER */
5511 }
intmax_t arrayind_t
Definition: array.h:28
char * word
Definition: command.h:127
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
int t
Definition: gm_loop.c:77
WORD_DESC * word
Definition: command.h:134
void free()
char * itos(intmax_t i)
Definition: itos.c:44
#define GET_ARRAY_FROM_VAR(n, v, a)
Definition: array.h:115
#define array_push(a, v)
Definition: array.h:110
struct word_list * next
Definition: command.h:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_args()

void pop_args ( )

Definition at line 5517 of file variables.c.

References array_pop, element_value, GET_ARRAY_FROM_VAR, i, and legal_number().

Referenced by _evalfile(), execute_function(), and unbind_args().

5518 {
5519 #if defined (ARRAY_VARS) && defined (DEBUGGER)
5520  SHELL_VAR *bash_argv_v, *bash_argc_v;
5521  ARRAY *bash_argv_a, *bash_argc_a;
5522  ARRAY_ELEMENT *ce;
5523  intmax_t i;
5524 
5525  GET_ARRAY_FROM_VAR ("BASH_ARGV", bash_argv_v, bash_argv_a);
5526  GET_ARRAY_FROM_VAR ("BASH_ARGC", bash_argc_v, bash_argc_a);
5527 
5528  ce = array_shift (bash_argc_a, 1, 0);
5529  if (ce == 0 || legal_number (element_value (ce), &i) == 0)
5530  i = 0;
5531 
5532  for ( ; i > 0; i--)
5533  array_pop (bash_argv_a);
5534  array_dispose_element (ce);
5535 #endif /* ARRAY_VARS && DEBUGGER */
5536 }
#define array_pop(a)
Definition: array.h:112
#define element_value(ae)
Definition: array.h:102
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
#define GET_ARRAY_FROM_VAR(n, v, a)
Definition: array.h:115
int legal_number(char *string, intmax_t *result) const
Definition: general.c:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sv_compare()

static int sv_compare ( struct name_and_function sv1,
struct name_and_function sv2 
)
static

Definition at line 5646 of file variables.c.

References name_and_function::name.

Referenced by stupidly_hack_special_variables().

5648 {
5649  int r;
5650 
5651  if ((r = sv1->name[0] - sv2->name[0]) == 0)
5652  r = strcmp (sv1->name, sv2->name);
5653  return r;
5654 }
Here is the caller graph for this function:

◆ find_special_var()

static int find_special_var ( char *  name) const
inlinestatic

Definition at line 5657 of file variables.c.

References i, and name_and_function::name.

Referenced by propagate_temp_var(), push_posix_temp_var(), push_temp_var(), and stupidly_hack_special_variables().

5659 {
5660  register int i, r;
5661 
5662  for (i = 0; special_vars[i].name; i++)
5663  {
5664  r = special_vars[i].name[0] - name[0];
5665  if (r == 0)
5666  r = strcmp (special_vars[i].name, name);
5667  if (r == 0)
5668  return i;
5669  else if (r > 0)
5670  /* Can't match any of rest of elements in sorted list. Take this out
5671  if it causes problems in certain environments. */
5672  break;
5673  }
5674  return -1;
5675 }
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
static struct name_and_function special_vars[]
Definition: variables.c:5559
Here is the caller graph for this function:

◆ stupidly_hack_special_variables()

void stupidly_hack_special_variables ( char *  name)

Definition at line 5680 of file variables.c.

References find_special_var(), name_and_function::function, i, N_SPECIAL_VARS, name_and_function::name, qsort(), and sv_compare().

Referenced by assign_in_env(), dispose_temporary_env(), do_assignment_internal(), expr_bind_variable(), makunbound(), parameter_brace_expand_rhs(), push_exported_var(), push_posix_tempvar_internal(), redir_varassign(), and run_startup_files().

5682 {
5683  static int sv_sorted = 0;
5684  int i;
5685 
5686  if (sv_sorted == 0) /* shouldn't need, but it's fairly cheap. */
5687  {
5689  (QSFUNC *)sv_compare);
5690  sv_sorted = 1;
5691  }
5692 
5693  i = find_special_var (name);
5694  if (i != -1)
5695  (*(special_vars[i].function)) (name);
5696 }
static int sv_compare(struct name_and_function *sv1, struct name_and_function *sv2)
Definition: variables.c:5646
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
static int find_special_var(char *name) const
Definition: variables.c:5657
sh_sv_func_t * function
Definition: variables.c:5556
int QSFUNC()
Definition: general.h:266
void qsort()
#define N_SPECIAL_VARS
Definition: variables.c:5643
static struct name_and_function special_vars[]
Definition: variables.c:5559
Here is the call graph for this function:

◆ reinit_special_variables()

void reinit_special_variables ( )

Definition at line 5701 of file variables.c.

References sv_globignore(), and sv_opterr().

Referenced by shell_reinitialize().

5702 {
5703 #if defined (READLINE)
5704  sv_comp_wordbreaks ("COMP_WORDBREAKS");
5705 #endif
5706  sv_globignore ("GLOBIGNORE");
5707  sv_opterr ("OPTERR");
5708 }
void sv_opterr(char *name)
Definition: variables.c:6050
void sv_globignore(char *name)
Definition: variables.c:5775
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sv_ifs()

void sv_ifs ( char *  name)

Definition at line 5711 of file variables.c.

References find_variable(), and setifs().

Referenced by pop_context(), pop_scope(), redirection_expand(), write_here_document(), and write_here_string().

5713 {
5714  SHELL_VAR *v;
5715 
5716  v = find_variable ("IFS");
5717  setifs (v);
5718 }
void setifs(SHELL_VAR *v)
Definition: subst.c:10688
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sv_path()

void sv_path ( char *  name)

Definition at line 5722 of file variables.c.

References phash_flush().

5724 {
5725  /* hash -r */
5726  phash_flush ();
5727 }
void phash_flush()
Definition: hashcmd.c:58
Here is the call graph for this function:

◆ sv_mail()

void sv_mail ( char *  name)

Definition at line 5733 of file variables.c.

References free_mail_files(), remember_mail_dates(), and reset_mail_timer().

5735 {
5736  /* If the time interval for checking the files has changed, then
5737  reset the mail timer. Otherwise, one of the pathname vars
5738  to the users mailbox has changed, so rebuild the array of
5739  filenames. */
5740  if (name[4] == 'C') /* if (strcmp (name, "MAILCHECK") == 0) */
5741  reset_mail_timer ();
5742  else
5743  {
5744  free_mail_files ();
5746  }
5747 }
void remember_mail_dates()
Definition: mailcheck.c:368
void free_mail_files()
Definition: mailcheck.c:235
void reset_mail_timer()
Definition: mailcheck.c:107
Here is the call graph for this function:

◆ sv_funcnest()

void sv_funcnest ( char *  name)

Definition at line 5750 of file variables.c.

References find_variable(), funcnest_max, legal_number(), and value_cell.

Referenced by initialize_shell_variables().

5752 {
5753  SHELL_VAR *v;
5754  intmax_t num;
5755 
5756  v = find_variable (name);
5757  if (v == 0)
5758  funcnest_max = 0;
5759  else if (legal_number (value_cell (v), &num) == 0)
5760  funcnest_max = 0;
5761  else
5762  funcnest_max = num;
5763 }
int funcnest_max
Definition: execute_cmd.c:283
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
int legal_number(char *string, intmax_t *result) const
Definition: general.c:175
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sv_execignore()

void sv_execignore ( char *  name)

Definition at line 5767 of file variables.c.

References setup_exec_ignore().

5769 {
5770  setup_exec_ignore (name);
5771 }
void setup_exec_ignore(char *varname)
Definition: findcmd.c:92
Here is the call graph for this function:

◆ sv_globignore()

◆ sv_ignoreeof()

void sv_ignoreeof ( char *  name)

Definition at line 6005 of file variables.c.

References all_digits(), atoi(), eof_encountered, eof_encountered_limit, find_variable(), ignoreeof, NULL, temp, value_cell, and var_isset.

Referenced by initialize_shell_variables().

6007 {
6008  SHELL_VAR *tmp_var;
6009  char *temp;
6010 
6011  eof_encountered = 0;
6012 
6013  tmp_var = find_variable (name);
6014  ignoreeof = tmp_var && var_isset (tmp_var);
6015  temp = tmp_var ? value_cell (tmp_var) : (char *)NULL;
6016  if (temp)
6017  eof_encountered_limit = (*temp && all_digits (temp)) ? atoi (temp) : 10;
6018  set_shellopts (); /* make sure `ignoreeof' is/is not in $SHELLOPTS */
6019 }
int ignoreeof
int eof_encountered
int atoi()
#define NULL
Definition: general.h:53
int eof_encountered_limit
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
temp
Definition: subst.c:10040
#define value_cell(var)
Definition: variables.h:166
#define var_isset(var)
Definition: variables.h:174
int all_digits(char *string) const
Definition: general.c:159
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sv_optind()

void sv_optind ( char *  name)

Definition at line 6022 of file variables.c.

References atoi(), find_variable(), get_variable_value(), and NULL.

6024 {
6025  SHELL_VAR *var;
6026  char *tt;
6027  int s;
6028 
6029  var = find_variable ("OPTIND");
6030  tt = var ? get_variable_value (var) : (char *)NULL;
6031 
6032  /* Assume that if var->context < variable_context and variable_context > 0
6033  then we are restoring the variables's previous state while returning
6034  from a function. */
6035  if (tt && *tt)
6036  {
6037  s = atoi (tt);
6038 
6039  /* According to POSIX, setting OPTIND=1 resets the internal state
6040  of getopt (). */
6041  if (s < 0 || s == 1)
6042  s = 0;
6043  }
6044  else
6045  s = 0;
6046  getopts_reset (s);
6047 }
int atoi()
char * get_variable_value(SHELL_VAR *var)
Definition: variables.c:2471
#define NULL
Definition: general.h:53
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
Here is the call graph for this function:

◆ sv_opterr()

void sv_opterr ( char *  name)

Definition at line 6050 of file variables.c.

References atoi(), get_string_value(), and sh_opterr.

Referenced by reinit_special_variables().

6052 {
6053  char *tt;
6054 
6055  tt = get_string_value ("OPTERR");
6056  sh_opterr = (tt && *tt) ? atoi (tt) : 1;
6057 }
int sh_opterr
Definition: getopt.c:72
int atoi()
char * get_string_value(char *var_name) const
Definition: variables.c:2492
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sv_strict_posix()

void sv_strict_posix ( char *  name)

Definition at line 6060 of file variables.c.

References find_variable(), interactive_shell, posix_initialize(), posixly_correct, and var_isset.

Referenced by initialize_shell_variables(), and main().

6062 {
6063  SHELL_VAR *var;
6064 
6065  var = find_variable (name);
6066  posixly_correct = var && var_isset (var);
6068 #if defined (READLINE)
6069  if (interactive_shell)
6070  posix_readline_initialize (posixly_correct);
6071 #endif /* READLINE */
6072  set_shellopts (); /* make sure `posix' is/is not in $SHELLOPTS */
6073 }
int interactive_shell
Definition: shell.c:140
int posixly_correct
Definition: shell.c:232
void posix_initialize(int on)
Definition: general.c:73
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
#define var_isset(var)
Definition: variables.h:174
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sv_locale()

void sv_locale ( char *  name)

Definition at line 6076 of file variables.c.

References array_cell, array_num_elements, array_p, element_forw, element_value, find_variable(), free(), get_string_value(), i, INT_STRLEN_BOUND, inttostr(), itos(), last_command_exit_value, NULL, posixly_correct, set_element_value, set_lang(), set_locale_var(), t, and var_setarray.

6078 {
6079  char *v;
6080  int r;
6081 
6082  v = get_string_value (name);
6083  if (name[0] == 'L' && name[1] == 'A') /* LANG */
6084  r = set_lang (name, v);
6085  else
6086  r = set_locale_var (name, v); /* LC_*, TEXTDOMAIN* */
6087 
6088 #if 1
6089  if (r == 0 && posixly_correct)
6091 #endif
6092 }
int posixly_correct
Definition: shell.c:232
int set_locale_var(char *var, char *value)
Definition: locale.c:163
int set_lang(char *var, char *value)
Definition: locale.c:284
int last_command_exit_value
Definition: execute_cmd.c:215
char * get_string_value(char *var_name) const
Definition: variables.c:2492
Here is the call graph for this function:

◆ set_pipestatus_from_exit()

void set_pipestatus_from_exit ( int  s)

Definition at line 6194 of file variables.c.

Referenced by execute_command_internal(), execute_simple_command(), and exp_jump_to_top_level().

6196 {
6197 #if defined (ARRAY_VARS)
6198  static int v[2] = { 0, -1 };
6199 
6200  v[0] = s;
6201  set_pipestatus_array (v, 1);
6202 #endif
6203 }
Here is the caller graph for this function:

◆ sv_xtracefd()

void sv_xtracefd ( char *  name)

Definition at line 6206 of file variables.c.

References _(), find_variable(), internal_error(), sh_validfd(), strtol(), t, value_cell, xtrace_reset(), and xtrace_set().

Referenced by initialize_shell_variables().

6208 {
6209  SHELL_VAR *v;
6210  char *t, *e;
6211  int fd;
6212  FILE *fp;
6213 
6214  v = find_variable (name);
6215  if (v == 0)
6216  {
6217  xtrace_reset ();
6218  return;
6219  }
6220 
6221  t = value_cell (v);
6222  if (t == 0 || *t == 0)
6223  xtrace_reset ();
6224  else
6225  {
6226  fd = (int)strtol (t, &e, 10);
6227  if (e != t && *e == '\0' && sh_validfd (fd))
6228  {
6229  fp = fdopen (fd, "w");
6230  if (fp == 0)
6231  internal_error (_("%s: %s: cannot open as FILE"), name, value_cell (v));
6232  else
6233  xtrace_set (fd, fp);
6234  }
6235  else
6236  internal_error (_("%s: %s: invalid value for trace file descriptor"), name, value_cell (v));
6237  }
6238 }
long int strtol(char *nptr, char **endptr, int base) const
Definition: strtol.c:93
int sh_validfd(int fd)
Definition: general.c:480
int t
Definition: gm_loop.c:77
void xs_init _((void))
void internal_error(char *format, va_alist) const
Definition: error.c:235
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sv_shcompat()

void sv_shcompat ( char *  name)

Definition at line 6243 of file variables.c.

References _(), atoi(), find_variable(), get_string_value(), internal_error(), ISDIGIT, name_and_function::name, set_maxchild(), shell_compatibility_level, val, and value_cell.

Referenced by initialize_shell_variables().

6245 {
6246  SHELL_VAR *v;
6247  char *val;
6248  int tens, ones, compatval;
6249 
6250  v = find_variable (name);
6251  if (v == 0)
6252  {
6253  shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
6254  set_compatibility_opts ();
6255  return;
6256  }
6257  val = value_cell (v);
6258  if (val == 0 || *val == '\0')
6259  {
6260  shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
6261  set_compatibility_opts ();
6262  return;
6263  }
6264  /* Handle decimal-like compatibility version specifications: 4.2 */
6265  if (ISDIGIT (val[0]) && val[1] == '.' && ISDIGIT (val[2]) && val[3] == 0)
6266  {
6267  tens = val[0] - '0';
6268  ones = val[2] - '0';
6269  compatval = tens*10 + ones;
6270  }
6271  /* Handle integer-like compatibility version specifications: 42 */
6272  else if (ISDIGIT (val[0]) && ISDIGIT (val[1]) && val[2] == 0)
6273  {
6274  tens = val[0] - '0';
6275  ones = val[1] - '0';
6276  compatval = tens*10 + ones;
6277  }
6278  else
6279  {
6280 compat_error:
6281  internal_error (_("%s: %s: compatibility value out of range"), name, val);
6282  shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
6283  set_compatibility_opts ();
6284  return;
6285  }
6286 
6287  if (compatval < MIN_COMPAT_LEVEL || compatval > DEFAULT_COMPAT_LEVEL)
6288  goto compat_error;
6289 
6290  shell_compatibility_level = compatval;
6291  set_compatibility_opts ();
6292 }
#define ISDIGIT(c)
Definition: chartypes.h:71
void xs_init _((void))
INT val
Definition: sm_loop.c:353
void internal_error(char *format, va_alist) const
Definition: error.c:235
SHELL_VAR * find_variable(char *name) const
Definition: variables.c:2377
int shell_compatibility_level
Definition: version.c:50
#define value_cell(var)
Definition: variables.h:166
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ environ

char** environ

Referenced by maybe_make_export_env().

◆ shell_start_time

time_t shell_start_time

Definition at line 181 of file shell.c.

Referenced by assign_seconds(), and get_seconds().

◆ global_variables

VAR_CONTEXT* global_variables = (VAR_CONTEXT *) 0x0

Definition at line 104 of file variables.c.

Referenced by delete_all_contexts().

◆ shell_variables

◆ shell_functions

HASH_TABLE* shell_functions = (HASH_TABLE *) 0x0

Definition at line 111 of file variables.c.

Referenced by shell_reinitialize().

◆ invalid_env

HASH_TABLE* invalid_env = (HASH_TABLE *) 0x0

Definition at line 113 of file variables.c.

Referenced by maybe_make_export_env().

◆ variable_context

◆ localvar_inherit

int localvar_inherit = 0

Definition at line 127 of file variables.c.

Referenced by make_local_variable(), and make_new_variable().

◆ localvar_unset

int localvar_unset = 0

Definition at line 132 of file variables.c.

Referenced by makunbound().

◆ temporary_env

◆ tempenv_assign_error

int tempenv_assign_error

Definition at line 140 of file variables.c.

Referenced by execute_simple_command(), and expand_word_list_internal().

◆ dollar_vars

◆ rest_of_args

WORD_LIST* rest_of_args = (WORD_LIST *) 0x0

◆ dollar_dollar_pid

◆ array_needs_making

◆ shell_level

int shell_level = 0

Definition at line 155 of file variables.c.

Referenced by adjust_shell_level(), get_tty_state(), run_startup_files(), and set_tty_state().

◆ export_env

◆ export_env_index

int export_env_index
static

Definition at line 161 of file variables.c.

Referenced by add_or_supercede_exported_var(), and maybe_make_export_env().

◆ export_env_size

int export_env_size
static

Definition at line 162 of file variables.c.

Referenced by maybe_make_export_env().

◆ nameref_invalid_value

SHELL_VAR nameref_invalid_value

Definition at line 168 of file variables.c.

◆ nameref_maxloop_value

SHELL_VAR nameref_maxloop_value
static

Definition at line 169 of file variables.c.

◆ last_table_searched

HASH_TABLE* last_table_searched
static

Definition at line 171 of file variables.c.

◆ seconds_value_assigned

intmax_t seconds_value_assigned
static

Definition at line 1266 of file variables.c.

◆ rseed

unsigned long rseed = 1
static

Definition at line 1314 of file variables.c.

◆ last_random_value

int last_random_value
static

Definition at line 1315 of file variables.c.

◆ seeded_subshell

int seeded_subshell = 0
static

Definition at line 1316 of file variables.c.

◆ static_shell_name

char* static_shell_name = 0
static

Definition at line 1531 of file variables.c.

Referenced by assign_bash_argv0().

◆ tempvar_list

char** tempvar_list

Definition at line 4418 of file variables.c.

◆ tvlist_ind

int tvlist_ind

Definition at line 4419 of file variables.c.

Referenced by dispose_temporary_env().

◆ dollar_arg_stack

struct saved_dollar_vars* dollar_arg_stack = (struct saved_dollar_vars *) 0x0
static

Definition at line 5333 of file variables.c.

◆ dollar_arg_stack_slots

int dollar_arg_stack_slots
static

Definition at line 5334 of file variables.c.

◆ dollar_arg_stack_index

int dollar_arg_stack_index
static

Definition at line 5335 of file variables.c.

Referenced by dispose_saved_dollar_vars(), pop_dollar_vars(), and push_dollar_vars().

◆ special_vars

struct name_and_function special_vars[]
static

Definition at line 5559 of file variables.c.