]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - variables.h
Bash-4.4 patch 4
[thirdparty/bash.git] / variables.h
index cd11fd97c8961fa6b5d56c79e623d1f718738099..25c9ae072a15fdffe0491d12c8d057bb5282a607 100644 (file)
@@ -1,28 +1,29 @@
 /* variables.h -- data structures for shell variables. */
 
-/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2015 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
-   Bash is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+   Bash is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-   Bash is distributed in the hope that it will be useful, but WITHOUT
-   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
-   License for more details.
+   Bash is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with Bash; see the file COPYING.  If not, write to the Free
-   Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+   along with Bash.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
 #if !defined (_VARIABLES_H_)
 #define _VARIABLES_H_
 
 #include "stdc.h"
 #include "array.h"
+#include "assoc.h"
 
 /* Shell variables and functions are stored in hash tables. */
 #include "hashlib.h"
@@ -61,7 +62,7 @@ typedef struct var_context {
 /* What a shell variable looks like. */
 
 typedef struct variable *sh_var_value_func_t __P((struct variable *));
-typedef struct variable *sh_var_assign_func_t __P((struct variable *, char *, arrayind_t));
+typedef struct variable *sh_var_assign_func_t __P((struct variable *, char *, arrayind_t, char *));
 
 /* For the future */
 union _value {
@@ -108,6 +109,12 @@ typedef struct _vlist {
 #define att_local      0x0000020       /* variable is local to a function */
 #define att_assoc      0x0000040       /* variable is an associative array */
 #define att_trace      0x0000080       /* function is traced with DEBUG trap */
+#define att_uppercase  0x0000100       /* word converted to uppercase on assignment */
+#define att_lowercase  0x0000200       /* word converted to lowercase on assignment */
+#define att_capcase    0x0000400       /* word capitalized on assignment */
+#define att_nameref    0x0000800       /* word is a name reference */
+
+#define user_attrs     (att_exported|att_readonly|att_integer|att_local|att_trace|att_uppercase|att_lowercase|att_capcase|att_nameref)
 
 #define attmask_user   0x0000fff
 
@@ -117,6 +124,7 @@ typedef struct _vlist {
 #define att_noassign   0x0004000       /* assignment not allowed */
 #define att_imported   0x0008000       /* came from environment */
 #define att_special    0x0010000       /* requires special handling */
+#define att_nofree     0x0020000       /* do not free value on unset */
 
 #define        attmask_int     0x00ff000
 
@@ -134,27 +142,42 @@ typedef struct _vlist {
 #define local_p(var)           ((((var)->attributes) & (att_local)))
 #define assoc_p(var)           ((((var)->attributes) & (att_assoc)))
 #define trace_p(var)           ((((var)->attributes) & (att_trace)))
+#define uppercase_p(var)       ((((var)->attributes) & (att_uppercase)))
+#define lowercase_p(var)       ((((var)->attributes) & (att_lowercase)))
+#define capcase_p(var)         ((((var)->attributes) & (att_capcase)))
+#define nameref_p(var)         ((((var)->attributes) & (att_nameref)))
 
 #define invisible_p(var)       ((((var)->attributes) & (att_invisible)))
 #define non_unsettable_p(var)  ((((var)->attributes) & (att_nounset)))
 #define noassign_p(var)                ((((var)->attributes) & (att_noassign)))
 #define imported_p(var)                ((((var)->attributes) & (att_imported)))
 #define specialvar_p(var)      ((((var)->attributes) & (att_special)))
+#define nofree_p(var)          ((((var)->attributes) & (att_nofree)))
 
 #define tempvar_p(var)         ((((var)->attributes) & (att_tempvar)))
 
+/* Variable names: lvalues */
+#define name_cell(var)         ((var)->name)
+
 /* Acessing variable values: rvalues */
 #define value_cell(var)                ((var)->value)
 #define function_cell(var)     (COMMAND *)((var)->value)
 #define array_cell(var)                (ARRAY *)((var)->value)
+#define assoc_cell(var)                (HASH_TABLE *)((var)->value)
+#define nameref_cell(var)      ((var)->value)          /* so it can change later */
+
+#define NAMEREF_MAX    8       /* only 8 levels of nameref indirection */
 
-#define var_isnull(var)                ((var)->value == 0)
 #define var_isset(var)         ((var)->value != 0)
+#define var_isunset(var)       ((var)->value == 0)
+#define var_isnull(var)                ((var)->value && *(var)->value == 0)
 
 /* Assigning variable values: lvalues */
 #define var_setvalue(var, str) ((var)->value = (str))
 #define var_setfunc(var, func) ((var)->value = (char *)(func))
 #define var_setarray(var, arr) ((var)->value = (char *)(arr))
+#define var_setassoc(var, arr) ((var)->value = (char *)(arr))
+#define var_setref(var, str)   ((var)->value = (str))
 
 /* Make VAR be auto-exported. */
 #define set_auto_export(var) \
@@ -192,6 +215,12 @@ typedef struct _vlist {
              (var)->exportstr = (char *)NULL; \
            } \
        } while (0)
+
+#define ifsname(s)     ((s)[0] == 'I' && (s)[1] == 'F' && (s)[2] == 'S' && (s)[3] == '\0')
+
+/* Special value for nameref with invalid value for creation or assignment */
+extern SHELL_VAR nameref_invalid_value;
+#define INVALID_NAMEREF_VALUE  (void *)&nameref_invalid_value
        
 /* Stuff for hacking variables. */
 typedef int sh_var_map_func_t __P((SHELL_VAR *));
@@ -220,11 +249,25 @@ extern SHELL_VAR *var_lookup __P((const char *, VAR_CONTEXT *));
 extern SHELL_VAR *find_function __P((const char *));
 extern FUNCTION_DEF *find_function_def __P((const char *));
 extern SHELL_VAR *find_variable __P((const char *));
-extern SHELL_VAR *find_variable_internal __P((const char *, int));
+extern SHELL_VAR *find_variable_noref __P((const char *));
+extern SHELL_VAR *find_variable_last_nameref __P((const char *, int));
+extern SHELL_VAR *find_global_variable_last_nameref __P((const char *, int));
+extern SHELL_VAR *find_variable_nameref __P((SHELL_VAR *));
+extern SHELL_VAR *find_variable_nameref_for_create __P((const char *, int));
+extern SHELL_VAR *find_variable_nameref_for_assignment __P((const char *, int));
+/*extern SHELL_VAR *find_variable_internal __P((const char *, int));*/
+extern SHELL_VAR *find_variable_tempenv __P((const char *));
+extern SHELL_VAR *find_variable_notempenv __P((const char *));
+extern SHELL_VAR *find_global_variable __P((const char *));
+extern SHELL_VAR *find_global_variable_noref __P((const char *));
+extern SHELL_VAR *find_shell_variable __P((const char *));
 extern SHELL_VAR *find_tempenv_variable __P((const char *));
+extern SHELL_VAR *find_variable_no_invisible __P((const char *));
+extern SHELL_VAR *find_variable_for_assignment __P((const char *));
 extern SHELL_VAR *copy_variable __P((SHELL_VAR *));
 extern SHELL_VAR *make_local_variable __P((const char *));
-extern SHELL_VAR *bind_variable __P((const char *, char *));
+extern SHELL_VAR *bind_variable __P((const char *, char *, int));
+extern SHELL_VAR *bind_global_variable __P((const char *, char *, int));
 extern SHELL_VAR *bind_function __P((const char *, COMMAND *));
 
 extern void bind_function_def __P((const char *, FUNCTION_DEF *));
@@ -250,16 +293,21 @@ extern char **add_or_supercede_exported_var __P((char *, int));
 extern char *get_variable_value __P((SHELL_VAR *));
 extern char *get_string_value __P((const char *));
 extern char *sh_get_env_value __P((const char *));
-extern char *make_variable_value __P((SHELL_VAR *, char *));
+extern char *make_variable_value __P((SHELL_VAR *, char *, int));
 
-extern SHELL_VAR *bind_variable_value __P((SHELL_VAR *, char *));
+extern SHELL_VAR *bind_variable_value __P((SHELL_VAR *, char *, int));
 extern SHELL_VAR *bind_int_variable __P((char *, char *));
 extern SHELL_VAR *bind_var_to_int __P((char *, intmax_t));
 
-extern int assign_in_env __P((const char *));
+extern int assign_in_env __P((WORD_DESC *, int));
+
 extern int unbind_variable __P((const char *));
+extern int check_unbind_variable __P((const char *));
+extern int unbind_nameref __P((const char *));
+extern int unbind_variable_noref __P((const char *));
 extern int unbind_func __P((const char *));
 extern int unbind_function_def __P((const char *));
+extern int delete_var __P((const char *, VAR_CONTEXT *));
 extern int makunbound __P((const char *, VAR_CONTEXT *));
 extern int kill_local_variable __P((const char *));
 extern void delete_all_variables __P((HASH_TABLE *));
@@ -288,6 +336,7 @@ extern void dispose_used_env_vars __P((void));
 extern void dispose_function_env __P((void));
 extern void dispose_builtin_env __P((void));
 extern void merge_temporary_env __P((void));
+extern void flush_temporary_env __P((void));
 extern void merge_builtin_env __P((void));
 extern void kill_all_local_variables __P((void));
 
@@ -298,6 +347,7 @@ extern void set_func_auto_export __P((const char *));
 
 extern void sort_variables __P((SHELL_VAR **));
 
+extern int chkexport __P((char *));
 extern void maybe_make_export_env __P((void));
 extern void update_export_env_inplace __P((char *, int, char *));
 extern void put_command_name_into_env __P((char *));
@@ -311,9 +361,14 @@ extern void print_var_function __P((SHELL_VAR *));
 
 #if defined (ARRAY_VARS)
 extern SHELL_VAR *make_new_array_variable __P((char *));
-extern SHELL_VAR *make_local_array_variable __P((char *));
+extern SHELL_VAR *make_local_array_variable __P((char *, int));
+
+extern SHELL_VAR *make_new_assoc_variable __P((char *));
+extern SHELL_VAR *make_local_assoc_variable __P((char *));
 
 extern void set_pipestatus_array __P((int *, int));
+extern ARRAY *save_pipestatus_array __P((void));
+extern void restore_pipestatus_array __P((ARRAY *));
 #endif
 
 extern void set_pipestatus_from_exit __P((int));
@@ -322,6 +377,10 @@ extern void set_pipestatus_from_exit __P((int));
    is one of the special ones where something special happens. */
 extern void stupidly_hack_special_variables __P((char *));
 
+/* Reinitialize some special variables that have external effects upon unset
+   when the shell reinitializes itself. */
+extern void reinit_special_variables __P((void));
+
 extern int get_random_number __P((void));
 
 /* The `special variable' functions that get called when a particular
@@ -329,21 +388,26 @@ extern int get_random_number __P((void));
 extern void sv_ifs __P((char *));
 extern void sv_path __P((char *));
 extern void sv_mail __P((char *));
+extern void sv_funcnest __P((char *));
+extern void sv_execignore __P((char *));
 extern void sv_globignore __P((char *));
 extern void sv_ignoreeof __P((char *));
 extern void sv_strict_posix __P((char *));
 extern void sv_optind __P((char *));
 extern void sv_opterr __P((char *));
 extern void sv_locale __P((char *));
+extern void sv_xtracefd __P((char *));
+extern void sv_shcompat __P((char *));
 
 #if defined (READLINE)
 extern void sv_comp_wordbreaks __P((char *));
 extern void sv_terminal __P((char *));
 extern void sv_hostfile __P((char *));
+extern void sv_winsize __P((char *));
 #endif
 
-#if defined (HAVE_TZSET) && defined (PROMPT_STRING_DECODE)
-extern void sv_tz __P((char *));
+#if defined (__CYGWIN__)
+extern void sv_home __P((char *));
 #endif
 
 #if defined (HISTORY)
@@ -356,4 +420,12 @@ extern void sv_histchars __P((char *));
 extern void sv_histtimefmt __P((char *));
 #endif /* HISTORY */
 
+#if defined (HAVE_TZSET)
+extern void sv_tz __P((char *));
+#endif
+
+#if defined (JOB_CONTROL)
+extern void sv_childmax __P((char *));
+#endif
+
 #endif /* !_VARIABLES_H_ */