1 /* variables.h -- data structures for shell variables. */
3 #if !defined (_VARIABLES_H_)
9 /* Shell variables and functions are stored in hash tables. */
12 /* Placeholder for future modifications if cross-compiling or building a
13 `fat' binary, e.g. on Apple Rhapsody. These values are used in multiple
14 files, so they appear here. */
15 #define HOSTTYPE CONF_HOSTTYPE
16 #define OSTYPE CONF_OSTYPE
17 #define MACHTYPE CONF_MACHTYPE
19 /* What a shell variable looks like. */
21 typedef struct variable
*DYNAMIC_FUNC ();
23 typedef struct variable
{
24 char *name
; /* Symbol that the user types. */
25 char *value
; /* Value that is returned. */
26 DYNAMIC_FUNC
*dynamic_value
; /* Function called to return a `dynamic'
27 value for a variable, like $SECONDS
29 DYNAMIC_FUNC
*assign_func
; /* Function called when this `special
30 variable' is assigned a value in
32 int attributes
; /* export, readonly, array, invisible... */
33 int context
; /* Which context this variable belongs to. */
34 struct variable
*prev_context
; /* Value from previous context or NULL. */
37 /* The various attributes that a given variable can have. */
38 #define att_exported 0x001 /* export to environment */
39 #define att_readonly 0x002 /* cannot change */
40 #define att_invisible 0x004 /* cannot see */
41 #define att_array 0x008 /* value is an array */
42 #define att_nounset 0x010 /* cannot unset */
43 #define att_function 0x020 /* value is a function */
44 #define att_integer 0x040 /* internal representation is int */
45 #define att_imported 0x080 /* came from environment */
46 #define att_local 0x100 /* variable is local to a function */
47 #define att_tempvar 0x200 /* variable came from the temp environment */
49 #define exported_p(var) ((((var)->attributes) & (att_exported)))
50 #define readonly_p(var) ((((var)->attributes) & (att_readonly)))
51 #define invisible_p(var) ((((var)->attributes) & (att_invisible)))
52 #define array_p(var) ((((var)->attributes) & (att_array)))
53 #define non_unsettable_p(var) ((((var)->attributes) & (att_nounset)))
54 #define function_p(var) ((((var)->attributes) & (att_function)))
55 #define integer_p(var) ((((var)->attributes) & (att_integer)))
56 #define imported_p(var) ((((var)->attributes) & (att_imported)))
57 #define local_p(var) ((((var)->attributes) & (att_local)))
58 #define tempvar_p(var) ((((var)->attributes) & (att_tempvar)))
60 #define value_cell(var) ((var)->value)
61 #define function_cell(var) (COMMAND *)((var)->value)
62 #define array_cell(var) ((ARRAY *)(var)->value)
64 #define SETVARATTR(var, attr, undo) \
65 ((undo == 0) ? ((var)->attributes |= (attribute)) \
66 : ((var)->attributes &= ~(attribute)))
68 /* Stuff for hacking variables. */
69 extern int variable_context
;
70 extern HASH_TABLE
*shell_variables
, *shell_functions
;
71 extern char *dollar_vars
[];
72 extern char **export_env
;
73 extern char **non_unsettable_vars
;
75 extern void initialize_shell_variables
__P((char **, int));
76 extern SHELL_VAR
*set_if_not
__P((char *, char *));
77 extern void set_lines_and_columns
__P((int, int));
79 extern void set_ppid
__P((void));
81 extern SHELL_VAR
*find_function
__P((char *));
82 extern SHELL_VAR
*find_variable
__P((char *));
83 extern SHELL_VAR
*find_variable_internal
__P((char *, int));
84 extern SHELL_VAR
*find_tempenv_variable
__P((char *));
85 extern SHELL_VAR
*copy_variable
__P((SHELL_VAR
*));
86 extern SHELL_VAR
*make_local_variable
__P((char *));
87 extern SHELL_VAR
*bind_variable
__P((char *, char *));
88 extern SHELL_VAR
*bind_function
__P((char *, COMMAND
*));
89 extern SHELL_VAR
**map_over
__P((Function
*, HASH_TABLE
*));
90 extern SHELL_VAR
**all_shell_variables
__P((void));
91 extern SHELL_VAR
**all_shell_functions
__P((void));
92 extern SHELL_VAR
**all_visible_variables
__P((void));
93 extern SHELL_VAR
**all_visible_functions
__P((void));
95 extern char **make_var_array
__P((HASH_TABLE
*));
96 extern char **add_or_supercede_exported_var
__P((char *, int));
98 extern char *get_string_value
__P((char *));
99 extern char *make_variable_value
__P((SHELL_VAR
*, char *));
101 extern int assignment
__P((char *));
102 extern int variable_in_context
__P((SHELL_VAR
*));
103 extern int assign_in_env
__P((char *));
104 extern int unbind_variable
__P((char *));
105 extern int makunbound
__P((char *, HASH_TABLE
*));
106 extern int kill_local_variable
__P((char *));
107 extern void delete_all_variables
__P((HASH_TABLE
*));
109 extern void adjust_shell_level
__P((int));
110 extern void non_unsettable
__P((char *));
111 extern void dispose_variable
__P((SHELL_VAR
*));
112 extern void dispose_used_env_vars
__P((void));
113 extern void dispose_function_env
__P((void));
114 extern void dispose_builtin_env
__P((void));
115 extern void merge_temporary_env
__P((void));
116 extern void merge_builtin_env
__P((void));
117 extern void kill_all_local_variables
__P((void));
118 extern void set_var_read_only
__P((char *));
119 extern void set_func_read_only
__P((char *));
120 extern void set_var_auto_export
__P((char *));
121 extern void set_func_auto_export
__P((char *));
122 extern void sort_variables
__P((SHELL_VAR
**));
123 extern void maybe_make_export_env
__P((void));
124 extern void update_export_env_inplace
__P((char *, int, char *));
125 extern void put_command_name_into_env
__P((char *));
126 extern void put_gnu_argv_flags_into_env
__P((int, char *));
127 extern void print_var_list
__P((SHELL_VAR
**));
128 extern void print_assignment
__P((SHELL_VAR
*));
129 extern void print_var_value
__P((SHELL_VAR
*, int));
130 extern void print_var_function
__P((SHELL_VAR
*));
132 extern char *indirection_level_string
__P((void));
134 #if defined (ARRAY_VARS)
135 extern SHELL_VAR
*make_new_array_variable
__P((char *));
136 extern SHELL_VAR
*make_local_array_variable
__P((char *));
137 extern SHELL_VAR
*convert_var_to_array
__P((SHELL_VAR
*));
138 extern SHELL_VAR
*bind_array_variable
__P((char *, int, char *));
139 extern SHELL_VAR
*assign_array_from_string
__P((char *, char *));
140 extern SHELL_VAR
*assign_array_var_from_word_list
__P((SHELL_VAR
*, WORD_LIST
*));
141 extern SHELL_VAR
*assign_array_var_from_string
__P((SHELL_VAR
*, char *));
142 extern int unbind_array_element
__P((SHELL_VAR
*, char *));
143 extern int skipsubscript
__P((char *, int));
144 extern void print_array_assignment
__P((SHELL_VAR
*, int));
146 extern void set_pipestatus_array
__P((int *));
149 extern void set_pipestatus_from_exit
__P((int));
151 /* The variable in NAME has just had its state changed. Check to see if it
152 is one of the special ones where something special happens. */
153 extern void stupidly_hack_special_variables
__P((char *));
155 /* The `special variable' functions that get called when a particular
157 void sv_path (), sv_mail (), sv_ignoreeof (), sv_strict_posix ();
158 void sv_optind (), sv_opterr (), sv_globignore (), sv_locale ();
160 #if defined (READLINE)
161 void sv_terminal (), sv_hostfile ();
164 #if defined (HAVE_TZSET) && defined (PROMPT_STRING_DECODE)
168 #if defined (HISTORY)
169 void sv_histsize (), sv_histignore (), sv_history_control ();
170 # if defined (BANG_HISTORY)
171 void sv_histchars ();
175 #endif /* !_VARIABLES_H_ */