var.c
来自「Unix下的MUD客户端程序」· C语言 代码 · 共 55 行
C
55 行
/* var.c: Maintains variable indices hash table */#include "vt.h"#define VTSIZE 203/* Variable values are kept in a global array. Variable names are** kept in a hash table used to access indices. The function** get_index() is called by walk.c. *//* Variables are hashed to unordered chains. */struct var { char *name; int ind; struct var *next;};static int vindex = 0;static struct var *vtab[VTSIZE];/* Return an index to a variable, creating one if necessary */int get_vindex(name) char *name;{ int hval; struct var *vp; hval = hash(name, VTSIZE); for (vp = vtab[hval]; vp; vp = vp->next) { if (streq(vp->name, name)) return vp->ind; } vp = New(struct var); vp->name = vtstrdup(name); vp->ind = vindex++; vp->next = vtab[hval]; vtab[hval] = vp; return vp->ind;}void write_vartab(fp) FILE *fp;{ int i; struct var *vp; fputs("VARS\n", fp); for (i = 0; i < VTSIZE; i++) { for (vp = vtab[i]; vp; vp = vp->next) fprintf(fp, "%d %s\n", vp->ind, vp->name); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?