1
/* entities.c -- recognize HTML ISO entities
3
(c) 1998-2001 (W3C) MIT, INRIA, Keio University
4
See tidy.c for the copyright notice.
8
$Author: terry_teague $
9
$Date: 2001/08/19 19:18:57 $
27
static struct nlist *hashtab[HASHSIZE];
291
static unsigned hash(char *s)
295
for (hashval = 0; *s != '\0'; s++)
296
hashval = *s + 31*hashval;
298
return hashval % HASHSIZE;
301
static struct nlist *lookup(char *s)
305
for (np = hashtab[hash(s)]; np != null; np = np->next)
306
if (wstrcmp(s, np->name) == 0)
311
static struct nlist *install(char *name, uint code)
316
if ((np = lookup(name)) == null)
318
np = (struct nlist *)MemAlloc(sizeof(*np));
320
if (np == null || (np->name = wstrdup(name)) == null)
323
hashval = hash(name);
324
np->next = hashtab[hashval];
325
hashtab[hashval] = np;
333
/* entity starting with "&" returns zero on error */
334
uint EntityCode(char *name)
339
/* numeric entitity: name = "&#" followed by number */
342
c = 0; /* zero on missing/bad number */
344
/* 'x' prefix denotes hexadecimal number format */
345
if (name[2] == 'x' || (!XmlTags && name[2] == 'X')) /* #427833 - fix by Bj�rn H�hrmann 05 Jun 01 */
346
sscanf(name+3, "%x", &c);
348
sscanf(name+2, "%d", &c);
353
/* Named entity: name ="&" followed by a name */
354
if ((np = lookup(name+1)))
357
return 0; /* zero signifies unknown entity name */
360
void InitEntities(void)
364
for(ep = entities; ep->name != null; ++ep)
365
install(ep->name, ep->code);
368
void FreeEntities(void)
370
struct nlist *prev, *next;
373
for (i = 0; i < HASHSIZE; ++i)
391
char *EntityName(uint n)
395
for(ep = entities; ep->name != null; ++ep)