📄 sconst.c
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -