sconst.c

来自「Unix下的MUD客户端程序」· C语言 代码 · 共 58 行

C
58
字号
/* sconst.c: Handle addition and removal of string constants */#include "vt.h"#define STSIZE 101struct sconst {	Rstr *rs;			/* Given to program		*/	int refs;			/* Ref count from programs only */	struct sconst *next;};static struct sconst *sctab[STSIZE];Rstr *add_sconst(cstr)	Cstr *cstr;{	int ind;	struct sconst *new, *sc;	ind = hash(cstr->s, STSIZE);	for (sc = sctab[ind]; sc; sc = sc->next) {		if (streq(sc->rs->str.c.s, cstr->s))			break;	}	if (sc) {		sc->refs++;		return sc->rs;	}	new = New(struct sconst);	new->rs = New(Rstr);	new->rs->str.c = *cstr;	new->rs->str.sz = cstr->l + 1;	new->rs->refs = 1;	new->refs = 1;	new->next = sctab[ind];	sctab[ind] = new;	cstr->s = NULL;	return new->rs;}void del_sconst(rs)	Rstr *rs;{	int ind;	struct sconst **sc, *next;	ind = hash(rs->str.c.s, STSIZE);	for (sc = &sctab[ind]; (*sc)->rs != rs; sc = &(*sc)->next);	if (--(*sc)->refs)		return;	dec_ref_rstr(rs);	next = (*sc)->next;	Discard(*sc, struct sconst);	*sc = next;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?