ANSIise to fix warnings.
This commit is contained in:
parent
24380e2a93
commit
f992eb28ac
|
@ -5,11 +5,11 @@
|
||||||
#define IDF_HASHSIZE 307 /* size of hashtable, must be odd */
|
#define IDF_HASHSIZE 307 /* size of hashtable, must be odd */
|
||||||
|
|
||||||
#define IDF_STARTHASH(hs) (hs = 0)
|
#define IDF_STARTHASH(hs) (hs = 0)
|
||||||
#define IDF_ENHASH(hs,ch) (hs = (hs << 2) + ch)
|
#define IDF_ENHASH(hs, ch) (hs = (hs << 2) + ch)
|
||||||
#define IDF_STOPHASH(hs) (hs = hs % IDF_HASHSIZE)
|
#define IDF_STOPHASH(hs) (hs = hs % IDF_HASHSIZE)
|
||||||
|
|
||||||
static struct idf *IDF_hashtable[IDF_HASHSIZE];
|
static struct idf* IDF_hashtable[IDF_HASHSIZE];
|
||||||
/* All identifiers can in principle be reached through
|
/* All identifiers can in principle be reached through
|
||||||
IDF_hashtable; IDF_hashtable[hc] is the start of a chain of
|
IDF_hashtable; IDF_hashtable[hc] is the start of a chain of
|
||||||
idf's whose tags all hash to hc.
|
idf's whose tags all hash to hc.
|
||||||
Any identifier is entered into this
|
Any identifier is entered into this
|
||||||
|
@ -17,69 +17,71 @@ static struct idf *IDF_hashtable[IDF_HASHSIZE];
|
||||||
(variable, selector, structure tag, etc.).
|
(variable, selector, structure tag, etc.).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_PROTOTYPE(static struct idf *IDF_new, (char *, int, int));
|
static struct idf* IDF_new(char* tg, int size, int cpy);
|
||||||
|
|
||||||
void
|
void init_idf()
|
||||||
init_idf()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct idf *
|
static struct idf* IDF_new(char* tg, int size, int cpy)
|
||||||
IDF_new(tg, size, cpy)
|
|
||||||
register char *tg;
|
|
||||||
register int size;
|
|
||||||
{
|
{
|
||||||
static int nidf;
|
static int nidf;
|
||||||
static struct idf *pidf;
|
static struct idf* pidf;
|
||||||
static struct idf null_idf;
|
static struct idf null_idf;
|
||||||
register struct idf *id;
|
register struct idf* id;
|
||||||
#define NIDS 50
|
#define NIDS 50
|
||||||
#define IBUFSIZ 2048
|
#define IBUFSIZ 2048
|
||||||
static unsigned int icnt;
|
static unsigned int icnt;
|
||||||
static char *ip;
|
static char* ip;
|
||||||
register char *p;
|
register char* p;
|
||||||
|
|
||||||
|
if (!nidf--)
|
||||||
if (! nidf--) {
|
{
|
||||||
nidf += NIDS;
|
nidf += NIDS;
|
||||||
pidf = (struct idf *) Malloc(NIDS * sizeof (struct idf));
|
pidf = (struct idf*)Malloc(NIDS * sizeof(struct idf));
|
||||||
}
|
}
|
||||||
|
|
||||||
id = pidf;
|
id = pidf;
|
||||||
pidf++;
|
pidf++;
|
||||||
*id = null_idf;
|
*id = null_idf;
|
||||||
|
|
||||||
if (cpy) {
|
if (cpy)
|
||||||
if (size > icnt) {
|
{
|
||||||
|
if (size > icnt)
|
||||||
|
{
|
||||||
icnt = size > IBUFSIZ ? size : IBUFSIZ;
|
icnt = size > IBUFSIZ ? size : IBUFSIZ;
|
||||||
p = Malloc(icnt);
|
p = Malloc(icnt);
|
||||||
}
|
}
|
||||||
else p = ip;
|
else
|
||||||
|
p = ip;
|
||||||
icnt -= size;
|
icnt -= size;
|
||||||
id->id_text = p;
|
id->id_text = p;
|
||||||
while (size--) {
|
while (size--)
|
||||||
|
{
|
||||||
*p++ = *tg++;
|
*p++ = *tg++;
|
||||||
}
|
}
|
||||||
ip = p;
|
ip = p;
|
||||||
}
|
}
|
||||||
else id->id_text = tg;
|
else
|
||||||
|
id->id_text = tg;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef IDF_DEBUG
|
#ifdef IDF_DEBUG
|
||||||
void
|
void hash_stat(void)
|
||||||
hash_stat()
|
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
int total_count = 0;
|
int total_count = 0;
|
||||||
|
|
||||||
print("Hash table tally:\n");
|
print("Hash table tally:\n");
|
||||||
for (i = 0; i < IDF_HASHSIZE; i++) {
|
for (i = 0; i < IDF_HASHSIZE; i++)
|
||||||
register struct idf *notch = IDF_hashtable[i];
|
{
|
||||||
|
register struct idf* notch = IDF_hashtable[i];
|
||||||
register int cnt = 0;
|
register int cnt = 0;
|
||||||
|
|
||||||
print ("%d ", i);
|
print("%d ", i);
|
||||||
while (notch) {
|
while (notch)
|
||||||
|
{
|
||||||
cnt++;
|
cnt++;
|
||||||
print("'%s' ", notch->id_text);
|
print("'%s' ", notch->id_text);
|
||||||
notch = notch->id_next;
|
notch = notch->id_next;
|
||||||
|
@ -91,17 +93,16 @@ hash_stat()
|
||||||
print("End hash table tally\n");
|
print("End hash table tally\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void idfappfun(int (*fun)(), int opt)
|
||||||
idfappfun(fun, opt)
|
|
||||||
int (*fun)();
|
|
||||||
int opt;
|
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
for (i = 0; i < IDF_HASHSIZE; i++) {
|
for (i = 0; i < IDF_HASHSIZE; i++)
|
||||||
register struct idf *notch = IDF_hashtable[i];
|
{
|
||||||
|
register struct idf* notch = IDF_hashtable[i];
|
||||||
|
|
||||||
while (notch) {
|
while (notch)
|
||||||
|
{
|
||||||
(*fun)(notch, opt);
|
(*fun)(notch, opt);
|
||||||
notch = notch->id_next;
|
notch = notch->id_next;
|
||||||
}
|
}
|
||||||
|
@ -109,22 +110,21 @@ idfappfun(fun, opt)
|
||||||
}
|
}
|
||||||
#endif /* IDF_DEBUG */
|
#endif /* IDF_DEBUG */
|
||||||
|
|
||||||
struct idf *
|
struct idf* str2idf(char tg[], int cpy)
|
||||||
str2idf(tg, cpy)
|
|
||||||
char tg[];
|
|
||||||
{
|
{
|
||||||
/* str2idf() returns an entry in the symbol table for the
|
/* str2idf() returns an entry in the symbol table for the
|
||||||
identifier tg. If necessary, an entry is created.
|
identifier tg. If necessary, an entry is created.
|
||||||
*/
|
*/
|
||||||
register char *cp = tg;
|
register char* cp = tg;
|
||||||
struct idf **hook;
|
struct idf** hook;
|
||||||
register struct idf *notch;
|
register struct idf* notch;
|
||||||
register unsigned int hash;
|
register unsigned int hash;
|
||||||
register int c;
|
register int c;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
IDF_STARTHASH(hash);
|
IDF_STARTHASH(hash);
|
||||||
while (c = *cp++) {
|
while (c = *cp++)
|
||||||
|
{
|
||||||
IDF_ENHASH(hash, c);
|
IDF_ENHASH(hash, c);
|
||||||
}
|
}
|
||||||
IDF_STOPHASH(hash);
|
IDF_STOPHASH(hash);
|
||||||
|
@ -137,23 +137,29 @@ str2idf(tg, cpy)
|
||||||
*/
|
*/
|
||||||
hook = &IDF_hashtable[hash];
|
hook = &IDF_hashtable[hash];
|
||||||
|
|
||||||
while ((notch = *hook)) {
|
while ((notch = *hook))
|
||||||
register char *s1 = tg;
|
{
|
||||||
|
register char* s1 = tg;
|
||||||
|
|
||||||
cp = notch->id_text;
|
cp = notch->id_text;
|
||||||
|
|
||||||
while (!(c = (*s1 - *cp++))) {
|
while (!(c = (*s1 - *cp++)))
|
||||||
if (*s1++ == '\0') {
|
{
|
||||||
|
if (*s1++ == '\0')
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 0) return notch;
|
if (c == 0)
|
||||||
if (c < 0) break;
|
return notch;
|
||||||
|
if (c < 0)
|
||||||
|
break;
|
||||||
hook = ¬ch->id_next;
|
hook = ¬ch->id_next;
|
||||||
}
|
}
|
||||||
/* a new struct idf must be inserted at the hook */
|
/* a new struct idf must be inserted at the hook */
|
||||||
if (cpy < 0) return 0;
|
if (cpy < 0)
|
||||||
|
return 0;
|
||||||
notch = IDF_new(tg, size, cpy);
|
notch = IDF_new(tg, size, cpy);
|
||||||
notch->id_next = *hook;
|
notch->id_next = *hook;
|
||||||
*hook = notch; /* hooked in */
|
*hook = notch; /* hooked in */
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct idf {
|
||||||
|
|
||||||
Initializes the namelist.
|
Initializes the namelist.
|
||||||
*/
|
*/
|
||||||
_PROTOTYPE(void init_idf, (void));
|
extern void init_idf(void);
|
||||||
|
|
||||||
/* struct idf * str2idf(tg, cp)
|
/* struct idf * str2idf(tg, cp)
|
||||||
char *tg;
|
char *tg;
|
||||||
|
@ -40,6 +40,6 @@ _PROTOTYPE(void init_idf, (void));
|
||||||
If cp < 0, the string is not entered, but only looked for.
|
If cp < 0, the string is not entered, but only looked for.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_PROTOTYPE(struct idf *str2idf, (char *, int));
|
struct idf *str2idf(char* tg, int cp);
|
||||||
|
|
||||||
#define findidf(tg) str2idf(tg, -1)
|
#define findidf(tg) str2idf(tg, -1)
|
||||||
|
|
Loading…
Reference in a new issue