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