Imported from ../bash-2.04.tar.gz.

This commit is contained in:
Jari Aalto 2000-03-17 21:46:59 +00:00
commit bb70624e96
387 changed files with 28522 additions and 9334 deletions

View file

@ -1,5 +1,23 @@
/* variables.h -- data structures for shell variables. */
/* Copyright (C) 1987,1991 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 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. */
#if !defined (_VARIABLES_H_)
#define _VARIABLES_H_
@ -12,9 +30,24 @@
/* Placeholder for future modifications if cross-compiling or building a
`fat' binary, e.g. on Apple Rhapsody. These values are used in multiple
files, so they appear here. */
#define HOSTTYPE CONF_HOSTTYPE
#define OSTYPE CONF_OSTYPE
#define MACHTYPE CONF_MACHTYPE
#if !defined (RHAPSODY)
# define HOSTTYPE CONF_HOSTTYPE
# define OSTYPE CONF_OSTYPE
# define MACHTYPE CONF_MACHTYPE
#else /* RHAPSODY */
# if defined(__powerpc__) || defined(__ppc__)
# define HOSTTYPE "powerpc"
# elif defined(__i386__)
# define HOSTTYPE "i386"
# else
# define HOSTTYPE CONF_HOSTTYPE
# endif
# define OSTYPE CONF_OSTYPE
# define VENDOR CONF_VENDOR
# define MACHTYPE HOSTTYPE "-" VENDOR "-" OSTYPE
#endif /* RHAPSODY */
/* What a shell variable looks like. */
@ -23,6 +56,7 @@ typedef struct variable *DYNAMIC_FUNC ();
typedef struct variable {
char *name; /* Symbol that the user types. */
char *value; /* Value that is returned. */
char *exportstr; /* String for the environment. */
DYNAMIC_FUNC *dynamic_value; /* Function called to return a `dynamic'
value for a variable, like $SECONDS
or $RANDOM. */
@ -45,6 +79,7 @@ typedef struct variable {
#define att_imported 0x080 /* came from environment */
#define att_local 0x100 /* variable is local to a function */
#define att_tempvar 0x200 /* variable came from the temp environment */
#define att_importstr 0x400 /* exportstr points into initial environment */
#define exported_p(var) ((((var)->attributes) & (att_exported)))
#define readonly_p(var) ((((var)->attributes) & (att_readonly)))
@ -62,9 +97,51 @@ typedef struct variable {
#define array_cell(var) ((ARRAY *)(var)->value)
#define SETVARATTR(var, attr, undo) \
((undo == 0) ? ((var)->attributes |= (attribute)) \
: ((var)->attributes &= ~(attribute)))
((undo == 0) ? ((var)->attributes |= (attr)) \
: ((var)->attributes &= ~(attr)))
#define VSETATTR(var, attr) ((var)->attributes |= (attr))
#define VUNSETATTR(var, attr) ((var)->attributes &= ~(attr))
/* Macros to perform various operations on `exportstr' member of a SHELL_VAR. */
#define CLEAR_EXPORTSTR(var) (var)->exportstr = (char *)NULL
#define COPY_EXPORTSTR(var) ((var)->exportstr) ? savestring ((var)->exportstr) : (char *)NULL
#define SET_EXPORTSTR(var, value) (var)->exportstr = (value)
#define SAVE_EXPORTSTR(var, value) (var)->exportstr = (value) ? savestring (value) : (char *)NULL
#define FREE_EXPORTSTR(var) \
do { \
if ((var)->exportstr) \
{ \
if (((var)->attributes & att_importstr) == 0) \
free ((var)->exportstr); \
} \
} while (0)
#if 0
#define CACHE_IMPORTSTR(var, value) \
do { \
(var)->exportstr = value; \
(var)->attributes |= att_importstr; \
} while (0)
#else
#define CACHE_IMPORTSTR(var, value) \
do { \
(var)->exportstr = savestring (value); \
} while (0)
#endif
#define INVALIDATE_EXPORTSTR(var) \
do { \
if ((var)->exportstr) \
{ \
if (((var)->attributes & att_importstr) == 0) \
free ((var)->exportstr); \
(var)->exportstr = (char *)NULL; \
(var)->attributes &= ~att_importstr; \
} \
} while (0)
/* Stuff for hacking variables. */
extern int variable_context;
extern HASH_TABLE *shell_variables, *shell_functions;
@ -78,6 +155,8 @@ extern void set_lines_and_columns __P((int, int));
extern void set_ppid __P((void));
extern void make_funcname_visible __P((int));
extern SHELL_VAR *find_function __P((char *));
extern SHELL_VAR *find_variable __P((char *));
extern SHELL_VAR *find_variable_internal __P((char *, int));
@ -86,11 +165,18 @@ extern SHELL_VAR *copy_variable __P((SHELL_VAR *));
extern SHELL_VAR *make_local_variable __P((char *));
extern SHELL_VAR *bind_variable __P((char *, char *));
extern SHELL_VAR *bind_function __P((char *, COMMAND *));
extern SHELL_VAR **map_over __P((Function *, HASH_TABLE *));
extern SHELL_VAR **all_shell_variables __P((void));
extern SHELL_VAR **all_shell_functions __P((void));
extern SHELL_VAR **all_visible_variables __P((void));
extern SHELL_VAR **all_visible_functions __P((void));
extern SHELL_VAR **all_exported_variables __P((void));
#if defined (ARRAY_VARS)
extern SHELL_VAR **all_array_variables __P((void));
#endif
extern char **all_variables_matching_prefix __P((char *));
extern char **make_var_array __P((HASH_TABLE *));
extern char **add_or_supercede_exported_var __P((char *, int));
@ -98,6 +184,9 @@ extern char **add_or_supercede_exported_var __P((char *, int));
extern char *get_string_value __P((char *));
extern char *make_variable_value __P((SHELL_VAR *, char *));
extern SHELL_VAR *bind_variable_value __P((SHELL_VAR *, char *));
extern SHELL_VAR *bind_int_variable __P((char *, char *));
extern int assignment __P((char *));
extern int variable_in_context __P((SHELL_VAR *));
extern int assign_in_env __P((char *));