home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Shells / zsh-3.0.5-MIHS / src / Src / hashtable.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-03  |  13.9 KB  |  347 lines

  1. /*
  2.  * $Id: hashtable.h,v 2.30 1996/10/15 20:16:35 hzoli Exp $
  3.  *
  4.  * hashtable.h - header file for hash table handling code
  5.  *
  6.  * This file is part of zsh, the Z shell.
  7.  *
  8.  * Copyright (c) 1992-1996 Paul Falstad
  9.  * All rights reserved.
  10.  *
  11.  * Permission is hereby granted, without written agreement and without
  12.  * license or royalty fees, to use, copy, modify, and distribute this
  13.  * software and to distribute modified versions of this software for any
  14.  * purpose, provided that the above copyright notice and the following
  15.  * two paragraphs appear in all copies of this software.
  16.  *
  17.  * In no event shall Paul Falstad or the Zsh Development Group be liable
  18.  * to any party for direct, indirect, special, incidental, or consequential
  19.  * damages arising out of the use of this software and its documentation,
  20.  * even if Paul Falstad and the Zsh Development Group have been advised of
  21.  * the possibility of such damage.
  22.  *
  23.  * Paul Falstad and the Zsh Development Group specifically disclaim any
  24.  * warranties, including, but not limited to, the implied warranties of
  25.  * merchantability and fitness for a particular purpose.  The software
  26.  * provided hereunder is on an "as is" basis, and Paul Falstad and the
  27.  * Zsh Development Group have no obligation to provide maintenance,
  28.  * support, updates, enhancements, or modifications.
  29.  *
  30.  */
  31.  
  32. /* Nodes for reserved word hash table */
  33.  
  34. #ifdef GLOBALS
  35. struct reswd reswds[] =
  36. {
  37.     {NULL, "!", 0, BANG},
  38.     {NULL, "[[", 0, DINBRACK},
  39.     {NULL, "{", 0, INBRACE},
  40.     {NULL, "}", 0, OUTBRACE},
  41.     {NULL, "case", 0, CASE},
  42.     {NULL, "coproc", 0, COPROC},
  43.     {NULL, "do", 0, DO},
  44.     {NULL, "done", 0, DONE},
  45.     {NULL, "elif", 0, ELIF},
  46.     {NULL, "else", 0, ELSE},
  47.     {NULL, "end", 0, ZEND},
  48.     {NULL, "esac", 0, ESAC},
  49.     {NULL, "fi", 0, FI},
  50.     {NULL, "for", 0, FOR},
  51.     {NULL, "foreach", 0, FOREACH},
  52.     {NULL, "function", 0, FUNC},
  53.     {NULL, "if", 0, IF},
  54.     {NULL, "nocorrect", 0, NOCORRECT},
  55.     {NULL, "repeat", 0, REPEAT},
  56.     {NULL, "select", 0, SELECT},
  57.     {NULL, "then", 0, THEN},
  58.     {NULL, "time", 0, TIME},
  59.     {NULL, "until", 0, UNTIL},
  60.     {NULL, "while", 0, WHILE},
  61.     {NULL, NULL}
  62. };
  63. #else
  64. extern struct reswd reswds[];
  65. #endif
  66.  
  67.  
  68. /* Nodes for special parameters for parameter hash table */
  69.  
  70. #ifdef GLOBALS
  71. # ifdef HAVE_UNION_INIT
  72. #  define BR(X) {X}
  73. struct param
  74. # else
  75. #  define BR(X) X
  76. struct iparam {
  77.     struct hashnode *next;
  78.     char *nam;            /* hash data                             */
  79.     int flags;            /* PM_* flags (defined in zsh.h)         */
  80.     void *value;
  81.     void (*func1) _((void));    /* set func                              */
  82.     char *(*func2) _((void));    /* get func                              */
  83.     int ct;            /* output base or field width            */
  84.     void *data;            /* used by getfns                        */
  85.     char *env;            /* location in environment, if exported  */
  86.     char *ename;        /* name of corresponding environment var */
  87.     Param old;            /* old struct for use with local         */
  88.     int level;            /* if (old != NULL), level of localness  */
  89. }
  90. # endif
  91. special_params[] ={
  92. #define SFN(X) BR(((void (*)_((Param, char *)))(X)))
  93. #define GFN(X) BR(((char *(*)_((Param)))(X)))
  94. #define IPDEF1(A,B,C,D) {NULL,A,PM_INTEGER|PM_SPECIAL|D,BR(NULL),SFN(C),GFN(B),10,NULL,NULL,NULL,NULL,0}
  95. IPDEF1("#", poundgetfn, nullsetfn, PM_READONLY),
  96. IPDEF1("ERRNO", errnogetfn, nullsetfn, PM_READONLY),
  97. IPDEF1("GID", gidgetfn, gidsetfn, PM_DONTIMPORT),
  98. IPDEF1("EGID", egidgetfn, egidsetfn, PM_DONTIMPORT),
  99. IPDEF1("HISTSIZE", histsizegetfn, histsizesetfn, 0),
  100. IPDEF1("RANDOM", randomgetfn, randomsetfn, 0),
  101. IPDEF1("SECONDS", secondsgetfn, secondssetfn, 0),
  102. IPDEF1("UID", uidgetfn, uidsetfn, PM_DONTIMPORT),
  103. IPDEF1("EUID", euidgetfn, euidsetfn, PM_DONTIMPORT),
  104. IPDEF1("TTYIDLE", ttyidlegetfn, nullsetfn, PM_READONLY),
  105.  
  106. #define IPDEF2(A,B,C,D) {NULL,A,PM_SCALAR|PM_SPECIAL|D,BR(NULL),BR(C),BR(B),0,NULL,NULL,NULL,NULL,0}
  107. IPDEF2("USERNAME", usernamegetfn, usernamesetfn, PM_DONTIMPORT),
  108. IPDEF2("-", dashgetfn, nullsetfn, PM_READONLY),
  109. IPDEF2("histchars", histcharsgetfn, histcharssetfn, PM_DONTIMPORT),
  110. IPDEF2("HOME", homegetfn, homesetfn, 0),
  111. IPDEF2("TERM", termgetfn, termsetfn, 0),
  112. IPDEF2("WORDCHARS", wordcharsgetfn, wordcharssetfn, 0),
  113. IPDEF2("IFS", ifsgetfn, ifssetfn, PM_DONTIMPORT),
  114. IPDEF2("_", underscoregetfn, nullsetfn, PM_READONLY),
  115.  
  116. #ifdef LC_ALL
  117. #define LCIPDEF(A,B) {NULL,A,PM_SCALAR|PM_SPECIAL|PM_UNSET,BR(NULL),BR(lcsetfn),BR(strgetfn),0,(void *)B,NULL,NULL,NULL,0}
  118. IPDEF2("LANG", strgetfn, langsetfn, PM_UNSET),
  119. IPDEF2("LC_ALL", strgetfn, lc_allsetfn, PM_UNSET),
  120. #ifdef LC_COLLATE
  121. LCIPDEF("LC_COLLATE", LC_COLLATE),
  122. #endif
  123. #ifdef LC_CTYPE
  124. LCIPDEF("LC_CTYPE", LC_CTYPE),
  125. #endif
  126. #ifdef LC_MESSAGES
  127. LCIPDEF("LC_MESSAGES", LC_MESSAGES),
  128. #endif
  129. #ifdef LC_TIME
  130. LCIPDEF("LC_TIME", LC_TIME),
  131. #endif
  132. #endif
  133.  
  134. #define IPDEF4(A,B) {NULL,A,PM_INTEGER|PM_READONLY|PM_SPECIAL,BR(NULL),BR(nullsetfn),GFN(intvargetfn),10,(void *)B,NULL,NULL,NULL,0}
  135. IPDEF4("!", &lastpid),
  136. IPDEF4("$", &mypid),
  137. IPDEF4("?", &lastval),
  138. IPDEF4("LINENO", &lineno),
  139. IPDEF4("PPID", &ppid),
  140.  
  141. #define IPDEF5(A,B,F) {NULL,A,PM_INTEGER|PM_SPECIAL,BR(NULL),SFN(F),GFN(intvargetfn),10,(void *)B,NULL,NULL,NULL,0}
  142. IPDEF5("COLUMNS", &columns, zlevarsetfn),
  143. IPDEF5("LINES", &lines, zlevarsetfn),
  144. IPDEF5("OPTIND", &zoptind, intvarsetfn),
  145. IPDEF5("SHLVL", &shlvl, intvarsetfn),
  146.  
  147. #define IPDEF6(A,B) {NULL,A,PM_SCALAR|PM_READONLY|PM_SPECIAL,BR(NULL),SFN(nullsetfn),BR(strvargetfn),0,(void *)B,NULL,NULL,NULL,0}
  148. IPDEF6("PWD", &pwd),
  149.  
  150. #define IPDEF7(A,B) {NULL,A,PM_SCALAR|PM_SPECIAL,BR(NULL),BR(strvarsetfn),BR(strvargetfn),0,(void *)B,NULL,NULL,NULL,0}
  151. IPDEF7("OLDPWD", &oldpwd),
  152. IPDEF7("OPTARG", &zoptarg),
  153. IPDEF7("NULLCMD", &nullcmd),
  154. IPDEF7("POSTEDIT", &postedit),
  155. IPDEF7("READNULLCMD", &readnullcmd),
  156. IPDEF7("RPROMPT", &rprompt),
  157. IPDEF7("PS1", &prompt),
  158. IPDEF7("PS2", &prompt2),
  159. IPDEF7("PS3", &prompt3),
  160. IPDEF7("PS4", &prompt4),
  161. IPDEF7("RPS1", &rprompt),
  162. IPDEF7("SPROMPT", &sprompt),
  163. IPDEF7("0", &argzero),
  164.  
  165. #define IPDEF8(A,B,C) {NULL,A,PM_SCALAR|PM_SPECIAL,BR(NULL),SFN(colonarrsetfn),GFN(colonarrgetfn),0,(void *)B,NULL,C,NULL,0}
  166. IPDEF8("CDPATH", &cdpath, "cdpath"),
  167. IPDEF8("FIGNORE", &fignore, "fignore"),
  168. IPDEF8("FPATH", &fpath, "fpath"),
  169. IPDEF8("MAILPATH", &mailpath, "mailpath"),
  170. IPDEF8("WATCH", &watch, "watch"),
  171. IPDEF8("PATH", &path, "path"),
  172. IPDEF8("PSVAR", &psvar, "psvar"),
  173.  
  174. #define IPDEF9(A,B,C) {NULL,A,PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT,BR(NULL),SFN(arrvarsetfn),GFN(arrvargetfn),0,(void *)B,NULL,C,NULL,0}
  175. IPDEF9("*", &pparams, NULL),
  176. IPDEF9("@", &pparams, NULL),
  177. {NULL, NULL},
  178.  
  179. /* The following parameters are not avaible in sh/ksh compatibility *
  180.  * mode. All of these has sh compatible equivalents.                */
  181. IPDEF1("ARGC", poundgetfn, nullsetfn, PM_READONLY),
  182. IPDEF2("HISTCHARS", histcharsgetfn, histcharssetfn, PM_DONTIMPORT),
  183. IPDEF4("status", &lastval),
  184. IPDEF7("prompt", &prompt),
  185. IPDEF7("PROMPT", &prompt),
  186. IPDEF7("PROMPT2", &prompt2),
  187. IPDEF7("PROMPT3", &prompt3),
  188. IPDEF7("PROMPT4", &prompt4),
  189. IPDEF8("MANPATH", &manpath, "manpath"),
  190. IPDEF9("argv", &pparams, NULL),
  191. IPDEF9("fignore", &fignore, "FIGNORE"),
  192. IPDEF9("cdpath", &cdpath, "CDPATH"),
  193. IPDEF9("fpath", &fpath, "FPATH"),
  194. IPDEF9("mailpath", &mailpath, "MAILPATH"),
  195. IPDEF9("manpath", &manpath, "MANPATH"),
  196. IPDEF9("watch", &watch, "WATCH"),
  197. IPDEF9("path", &path, "PATH"),
  198. IPDEF9("psvar", &psvar, "PSVAR"),
  199.  
  200. {NULL, NULL}
  201. };
  202. # undef BR
  203. #else
  204. extern struct param special_params[];
  205. #endif
  206.  
  207.  
  208. /* Builtin function numbers; used by handler functions that handle more *
  209.  * than one builtin.  Note that builtins such as compctl, that are not  *
  210.  * overloaded, don't get a number.                                      */
  211.  
  212. #define BIN_TYPESET   0
  213. #define BIN_BG        1
  214. #define BIN_FG        2
  215. #define BIN_JOBS      3
  216. #define BIN_WAIT      4
  217. #define BIN_DISOWN    5
  218. #define BIN_BREAK     6
  219. #define BIN_CONTINUE  7
  220. #define BIN_EXIT      8
  221. #define BIN_RETURN    9
  222. #define BIN_CD       10
  223. #define BIN_POPD     11
  224. #define BIN_PUSHD    12
  225. #define BIN_PRINT    13
  226. #define BIN_EVAL     14
  227. #define BIN_SCHED    15
  228. #define BIN_FC       16
  229. #define BIN_PUSHLINE 17
  230. #define BIN_LOGOUT   18
  231. #define BIN_TEST     19
  232. #define BIN_BRACKET  20
  233. #define BIN_EXPORT   21
  234. #define BIN_ECHO     22
  235. #define BIN_DISABLE  23
  236. #define BIN_ENABLE   24
  237.  
  238. /* These currently depend on being 0 and 1. */
  239. #define BIN_SETOPT    0
  240. #define BIN_UNSETOPT  1
  241.  
  242. #define NULLBINCMD ((int (*) _((char *,char **,char *,int))) 0)
  243. #define PREFIX(X,Y) {NULL,X,Y | BINF_PREFIX, NULLBINCMD, 0, 0, 0, NULL, NULL},
  244.  
  245. /* Nodes for builtin function hash table */
  246.  
  247. #ifdef GLOBALS
  248. struct builtin builtins[] =
  249. {
  250.     PREFIX("-", BINF_DASH)
  251.     PREFIX("builtin", BINF_BUILTIN)
  252.     PREFIX("command", BINF_COMMAND)
  253.     PREFIX("exec", BINF_EXEC)
  254.     PREFIX("noglob", BINF_NOGLOB)
  255.     {NULL, "[", 0, bin_test, 0, -1, BIN_BRACKET, NULL, NULL},
  256.     {NULL, ".", BINF_PSPECIAL, bin_dot, 1, -1, 0, NULL, NULL},
  257.     {NULL, ":", BINF_PSPECIAL, bin_true, 0, -1, 0, NULL, NULL},
  258.     {NULL, "alias", BINF_MAGICEQUALS, bin_alias, 0, -1, 0, "Lgmr", NULL},
  259.     {NULL, "autoload", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "t", "u"},
  260.     {NULL, "bg", 0, bin_fg, 0, -1, BIN_BG, NULL, NULL},
  261.     {NULL, "bindkey", 0, bin_bindkey, 0, -1, 0, "asvemdr", NULL},
  262.     {NULL, "break", BINF_PSPECIAL, bin_break, 0, 1, BIN_BREAK, NULL, NULL},
  263.     {NULL, "bye", 0, bin_break, 0, 1, BIN_EXIT, NULL, NULL},
  264.     {NULL, "cd", 0, bin_cd, 0, 2, BIN_CD, NULL, NULL},
  265.     {NULL, "chdir", 0, bin_cd, 0, 2, BIN_CD, NULL, NULL},
  266.     {NULL, "compctl", 0, bin_compctl, 0, -1, 0, NULL, NULL},
  267.     {NULL, "continue", BINF_PSPECIAL, bin_break, 0, 1, BIN_CONTINUE, NULL, NULL},
  268.     {NULL, "declare", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "LRUZfilrtux", NULL},
  269.     {NULL, "dirs", 0, bin_dirs, 0, -1, 0, "v", NULL},
  270.     {NULL, "disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmr", NULL},
  271.     {NULL, "disown", 0, bin_fg, 0, -1, BIN_DISOWN, NULL, NULL},
  272.     {NULL, "echo", BINF_PRINTOPTS | BINF_ECHOPTS, bin_print, 0, -1, BIN_ECHO, "neE", "-"},
  273.     {NULL, "echotc", 0, bin_echotc, 1, -1, 0, NULL, NULL},
  274.     {NULL, "emulate", 0, bin_emulate, 1, 1, 0, "R", NULL},
  275.     {NULL, "enable", 0, bin_enable, 0, -1, BIN_ENABLE, "afmr", NULL},
  276.     {NULL, "eval", BINF_PSPECIAL, bin_eval, 0, -1, BIN_EVAL, NULL, NULL},
  277.     {NULL, "exit", BINF_PSPECIAL, bin_break, 0, 1, BIN_EXIT, NULL, NULL},
  278.     {NULL, "export", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, BIN_EXPORT, "LRUZfilrtu", "x"},
  279.     {NULL, "false", 0, bin_false, 0, -1, 0, NULL, NULL},
  280.     {NULL, "fc", BINF_FCOPTS, bin_fc, 0, -1, BIN_FC, "nlreIRWAdDfEim", NULL},
  281.     {NULL, "fg", 0, bin_fg, 0, -1, BIN_FG, NULL, NULL},
  282.     {NULL, "functions", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "mtu", NULL},
  283.     {NULL, "getln", 0, bin_read, 0, -1, 0, "ecnAlE", "zr"},
  284.     {NULL, "getopts", 0, bin_getopts, 2, -1, 0, NULL, NULL},
  285.     {NULL, "hash", BINF_MAGICEQUALS, bin_hash, 0, -1, 0, "dfmr", NULL},
  286.  
  287. #ifdef ZSH_HASH_DEBUG
  288.     {NULL, "hashinfo", 0, bin_hashinfo, 0, 0, 0, NULL, NULL},
  289. #endif
  290.  
  291.     {NULL, "history", 0, bin_fc, 0, -1, BIN_FC, "nrdDfEim", "l"},
  292.     {NULL, "integer", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "lrtux", "i"},
  293.     {NULL, "jobs", 0, bin_fg, 0, -1, BIN_JOBS, "lpZrs", NULL},
  294.     {NULL, "kill", 0, bin_kill, 0, -1, 0, NULL, NULL},
  295.     {NULL, "let", 0, bin_let, 1, -1, 0, NULL, NULL},
  296.     {NULL, "limit", 0, bin_limit, 0, -1, 0, "sh", NULL},
  297.     {NULL, "local", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "LRUZilrtu", NULL},
  298.     {NULL, "log", 0, bin_log, 0, 0, 0, NULL, NULL},
  299.     {NULL, "logout", 0, bin_break, 0, 1, BIN_LOGOUT, NULL, NULL},
  300.  
  301. #if defined(ZSH_MEM) & defined(ZSH_MEM_DEBUG)
  302.     {NULL, "mem", 0, bin_mem, 0, 0, 0, "v", NULL},
  303. #endif
  304.  
  305.     {NULL, "popd", 0, bin_cd, 0, 2, BIN_POPD, NULL, NULL},
  306.     {NULL, "print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "RDPnrslzNu0123456789pioOcm-", NULL},
  307.     {NULL, "pushd", 0, bin_cd, 0, 2, BIN_PUSHD, NULL, NULL},
  308.     {NULL, "pushln", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"},
  309.     {NULL, "pwd", 0, bin_pwd, 0, 0, 0, "r", NULL},
  310.     {NULL, "r", BINF_R, bin_fc, 0, -1, BIN_FC, "nrl", NULL},
  311.     {NULL, "read", 0, bin_read, 0, -1, 0, "rzu0123456789pkqecnAlE", NULL},
  312.     {NULL, "readonly", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "LRUZfiltux", "r"},
  313.     {NULL, "rehash", 0, bin_hash, 0, 0, 0, "df", "r"},
  314.     {NULL, "return", BINF_PSPECIAL, bin_break, 0, 1, BIN_RETURN, NULL, NULL},
  315.     {NULL, "sched", 0, bin_sched, 0, -1, 0, NULL, NULL},
  316.     {NULL, "set", BINF_PSPECIAL, bin_set, 0, -1, 0, NULL, NULL},
  317.     {NULL, "setopt", 0, bin_setopt, 0, -1, BIN_SETOPT, NULL, NULL},
  318.     {NULL, "shift", BINF_PSPECIAL, bin_shift, 0, -1, 0, NULL, NULL},
  319.     {NULL, "source", BINF_PSPECIAL, bin_dot, 1, -1, 0, NULL, NULL},
  320.     {NULL, "suspend", 0, bin_suspend, 0, 0, 0, "f", NULL},
  321.     {NULL, "test", 0, bin_test, 0, -1, BIN_TEST, NULL, NULL},
  322.     {NULL, "ttyctl", 0, bin_ttyctl, 0, 0, 0, "fu", NULL},
  323.     {NULL, "times", BINF_PSPECIAL, bin_times, 0, 0, 0, NULL, NULL},
  324.     {NULL, "trap", BINF_PSPECIAL, bin_trap, 0, -1, 0, NULL, NULL},
  325.     {NULL, "true", 0, bin_true, 0, -1, 0, NULL, NULL},
  326.     {NULL, "type", 0, bin_whence, 0, -1, 0, "ampf", "v"},
  327.     {NULL, "typeset", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "LRUZfilrtuxm", NULL},
  328.     {NULL, "ulimit", 0, bin_ulimit, 0, -1, 0, NULL, NULL},
  329.     {NULL, "umask", 0, bin_umask, 0, 1, 0, "S", NULL},
  330.     {NULL, "unalias", 0, bin_unhash, 1, -1, 0, "m", "a"},
  331.     {NULL, "unfunction", 0, bin_unhash, 1, -1, 0, "m", "f"},
  332.     {NULL, "unhash", 0, bin_unhash, 1, -1, 0, "adfm", NULL},
  333.     {NULL, "unlimit", 0, bin_unlimit, 0, -1, 0, "hs", NULL},
  334.     {NULL, "unset", BINF_PSPECIAL, bin_unset, 1, -1, 0, "fm", NULL},
  335.     {NULL, "unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL},
  336.     {NULL, "vared", 0, bin_vared, 1, 7, 0, NULL, NULL},
  337.     {NULL, "wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL},
  338.     {NULL, "whence", 0, bin_whence, 0, -1, 0, "acmpvf", NULL},
  339.     {NULL, "where", 0, bin_whence, 0, -1, 0, "pm", "ca"},
  340.     {NULL, "which", 0, bin_whence, 0, -1, 0, "amp", "c"},
  341.     {NULL, NULL}
  342. };
  343. #else
  344. extern struct builtin builtins[];
  345. #endif
  346.  
  347.