syn68k/syngen/uniquestring.c

38 lines
557 B
C
Raw Normal View History

2008-09-26 14:25:10 +00:00
#include "hash.h"
#include "uniquestring.h"
#include "common.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
static SymbolTable *sym = NULL;
void
init_unique_string ()
{
if (sym == NULL)
sym = make_symbol_table ();
}
const char *
unique_string (const char *s)
{
SymbolInfo si;
const char *p;
if (lookup_symbol (sym, s, &si, &p) != HASH_NOERR)
{
char *newp;
newp = malloc (strlen (s) + 1);
assert(newp);
strcpy (newp, s);
insert_symbol (sym, newp, si);
p = newp;
}
return p;
}