home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / k / ksh48.zip / sh / table.h < prev    next >
C/C++ Source or Header  |  1992-08-25  |  4KB  |  124 lines

  1. /* $Id: table.h,v 1.4 1992/08/12 14:15:50 sjg Exp $ */
  2.  
  3. /*
  4.  * generic hashed associative table for commands and variables.
  5.  */
  6.  
  7. struct table {
  8.     Area   *areap;        /* area to allocate entries */
  9.     int    size, free;    /* hash size (always 2^^n), free entries */
  10.     struct    tbl **tbls;    /* hashed table items */
  11. };
  12.  
  13. struct tbl {            /* table item */
  14.     int    flag;        /* flags */
  15.     int    type;        /* command type or base, see below */
  16.     union {
  17.         char *s;    /* string */
  18.         long i;        /* integer */
  19.         int (*f) ARGS ((char**)); /* int function */
  20.         struct op *t;    /* "function" tree */
  21.     } val;            /* value */
  22.     char    name[4];    /* name -- variable length */
  23. };
  24.  
  25. /* flag bits */
  26. #define    ALLOC    BIT(0)        /* val.s has been allocated */
  27. #define    DEFINED    BIT(1)        /* is defined in block */
  28. #define    ISSET    BIT(2)        /* has value, vp->val.[si] */
  29. #define    SPECIAL    BIT(3)        /* PATH, IFS, SECONDS, etc */
  30. #define    INTEGER    BIT(4)        /* val.i contains integer value */
  31. #define    RDONLY    BIT(8)        /* read-only variable */
  32. #define    EXPORT    BIT(9)        /* exported variable */
  33. #define    LOCAL    BIT(10)        /* for local typeset() */
  34. #define    TRACE    BIT(11)        /* trace (-t) */
  35. #define    FUNCT    BIT(12)        /* function */
  36. #define    EXPALIAS BIT(13)    /* expanding this alias */
  37.  
  38. /* command types */
  39. #define    CNONE    0        /* undefined */
  40. #define    CSHELL    1        /* built-in */
  41. #define    CFUNC    2        /* function */
  42. #define    CEXEC    4        /* executable command */
  43. #define    CALIAS    5        /* alias */
  44. #define    CKEYWD    6        /* keyword */
  45.  
  46. void tinit ARGS((struct table *, Area *)); /* initialize table */
  47. unsigned int hash();        /* name hash function */
  48. struct tbl *tsearch();        /* table lookup primative */
  49. struct tbl *tenter();        /* table lookup/enter primative */
  50. void tdelete();            /* mark tbl entry for deletion */
  51. void twalk();            /* initialize walk of table */
  52. struct tbl *tnext();        /* walk table returning table time */
  53. struct tbl **tsort();        /* sort table entries by name */
  54.  
  55. /*
  56.  * activation record for function blocks
  57.  */
  58. struct block {
  59.     Area    area;        /* area to allocate things */
  60.     int    argc;        /* current $# */
  61.     char **    argv;        /* current $* */
  62.     struct    table vars;    /* local variables */
  63.     struct    table funs;    /* local functions */
  64. #if 1
  65.     char *    error;        /* error handler */
  66.     char *    exit;        /* exit handler */
  67. #else
  68.     struct    trap error, exit;
  69. #endif
  70.     struct    block *next;    /* enclosing block */
  71. };
  72.  
  73. EXTERN    struct block globals;    /* global variables and functions */
  74. EXTERN    struct table commands;    /* hashed commands */
  75. EXTERN    struct table builtins;    /* built-in commands */
  76. EXTERN    struct table lexicals;    /* keywords and aliases */
  77. EXTERN    struct table homedirs;    /* homedir() cache */
  78.  
  79. struct builtin {
  80.     char   *name;
  81.     int  (*func)();
  82. };
  83.  
  84. /* these really are externs! Look in table.c for them */
  85.  
  86. extern const struct builtin shbuiltins [], kshbuiltins [];
  87.  
  88. /* var spec values */
  89. #define    V_NONE    0
  90. #define    V_PATH    1
  91. #define    V_IFS    2
  92. #define    V_SECONDS 3
  93. #define    V_OPTIND 4
  94. #define    V_MAIL    5
  95. #define    V_MAILPATH 6
  96. #define    V_RANDOM 7
  97. #ifndef EASY_HISTORY
  98. #define V_HISTSIZE 8
  99. #define V_HISTFILE 9
  100. #endif
  101. #define V_FCEDIT 10
  102. #define V_COLUMNS 11
  103.  
  104. EXTERN    Area   *lastarea;    /* area of last variable/function looked up */
  105. EXTERN    char   *path;        /* PATH value */
  106. EXTERN    char   *prompt;        /* PS1 or PS2 */
  107.  
  108. void    newblock();
  109. void    popblock();
  110. struct tbl *global(/* char *s */);
  111. struct tbl *local(/* char *s */);
  112. struct tbl *typeset(/* char *var; int set, clr */);
  113. struct tbl *setvar(/* struct tbl *vdst, *vsrc */);
  114. struct tbl *strint(/* struct tbl *vdst, *vsrc */);
  115. long    intval(/* struct tbl *vp */);
  116. void    setint(/* struct tbl *vp; long n */);
  117. char   *strval(/* struct tbl *vp */);
  118. void    setstr(/* struct tbl *vp; char *s */);
  119. void    unset(/* struct tbl *vp */);
  120. int    import(/* char *s */);
  121. char  **makenv();
  122. int    isassign(/* char *s */);
  123.  
  124.