sconst.c

来自「使用BorlandC++4.5编译的一个MUD客户端程序」· C语言 代码 · 共 99 行

C
99
字号
head	2.1;access;symbols;locks; strict;comment	@ * @;2.1date	95.10.24.15.46.14;	author tsurace;	state Release;branches;next	1.1;1.1date	95.10.12.20.52.34;	author tsurace;	state Beta;branches;next	;desc@String constant management.@2.1log@Roll.@text@/* sconst.c: Handle addition and removal of string constants */
/* $Id: sconst.c 1.1 1995/10/12 20:52:34 tsurace Beta tsurace $ */

#include "vt.h"
#define STSIZE 101

struct 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;
}


@1.1log@Initial revision@text@d2 1a2 1/* $Id$ */@

⌨️ 快捷键说明

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