home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / BASH_112.ZIP / BASH-112.TAR / bash-1.12 / variables.h < prev    next >
C/C++ Source or Header  |  1991-07-07  |  2KB  |  54 lines

  1. /* variables.h -- data structures for shell variables. */
  2.  
  3. /* Shell variables and functions are stored in hash tables. */
  4. #include "hash.h"
  5.  
  6. /* What a shell variable looks like. */
  7.  
  8. typedef struct variable *DYNAMIC_FUNC ();
  9.  
  10. typedef struct variable {
  11.   char *name;            /* Symbol that the user types. */
  12.   char *value;            /* Value that is returned. */
  13.   DYNAMIC_FUNC *dynamic_value;    /* Function called to return a `dynamic'
  14.                    value for a variable, like $SECONDS
  15.                    or $RANDOM. */
  16.   DYNAMIC_FUNC *assign_func;     /* Function called when this `special
  17.                    variable' is assigned a value in
  18.                    bind_variable. */
  19.   int attributes;        /* export, readonly, array, invisible... */
  20.   int context;            /* Which context this variable belongs to. */
  21.   struct variable *prev_context; /* Value from previous context or NULL. */
  22. } SHELL_VAR;
  23.  
  24. /* The various attributes that a given variable can have.
  25.    We only reserve one byte of the INT. */
  26. #define att_exported  0x01    /* %00000001 (export to environment) */
  27. #define att_readonly  0x02    /* %00000010 (cannot change)         */
  28. #define att_invisible 0x04    /* %00000100 (cannot see)         */
  29. #define att_array     0x08    /* %00001000 (value is an array)     */
  30. #define att_nounset   0x10    /* %00010000 (cannot unset)         */
  31. #define att_function  0x20    /* %00100000 (value is a function)   */
  32. #define att_integer   0x40    /* %01000000 (internal rep. is int)  */
  33.  
  34. #define exported_p(var)        ((((var)->attributes) & (att_exported)))
  35. #define readonly_p(var)        ((((var)->attributes) & (att_readonly)))
  36. #define invisible_p(var)    ((((var)->attributes) & (att_invisible)))
  37. #define array_p(var)        ((((var)->attributes) & (att_array)))
  38. #define function_p(var)        ((((var)->attributes) & (att_function)))
  39. #define integer_p(var)        ((((var)->attributes) & (att_integer)))
  40.  
  41. #define value_cell(var) ((var)->value)
  42. #define function_cell(var) (COMMAND *)((var)->value)
  43.  
  44. /* Stuff for hacking variables. */
  45. extern HASH_TABLE *shell_variables, *shell_functions;
  46. extern SHELL_VAR *find_function (), *find_variable (), *variable_lookup ();
  47. extern SHELL_VAR *copy_variable (), *bind_variable (), *bind_function ();
  48. extern char *get_string_value (), *dollar_vars[];
  49. extern char **export_env;
  50. extern SHELL_VAR **map_over ();
  51. extern SHELL_VAR **all_shell_variables (), **all_shell_functions ();
  52. extern int variable_in_context ();
  53. extern int variable_context;
  54.