made names more unique
This commit is contained in:
parent
acf34e54ec
commit
2df4da50da
|
@ -8,27 +8,27 @@
|
||||||
congruence generator.
|
congruence generator.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define HASHSIZE 256 /* size of hashtable, must be a power of 2 */
|
#define IDF_HASHSIZE 256 /* size of hashtable, must be a power of 2 */
|
||||||
#ifndef IDF_HSIZE
|
#ifndef IDF_HSIZE
|
||||||
#define IDF_HSIZE 16 /* # of significant characters for hashing.
|
#define IDF_HSIZE 16 /* # of significant characters for hashing.
|
||||||
This is NOT the number of significant
|
This is NOT the number of significant
|
||||||
characters!
|
characters!
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
#define HASH_X 0253 /* Knuth's X */
|
#define IDF_HASH_X 0253 /* Knuth's X */
|
||||||
#define HASH_A 77 /* Knuth's a */
|
#define IDF_HASH_A 77 /* Knuth's a */
|
||||||
#define HASH_C 153 /* Knuth's c */
|
#define IDF_HASH_C 153 /* Knuth's c */
|
||||||
|
|
||||||
#define HASHMASK (HASHSIZE-1) /* since it is a power of 2 */
|
#define IDF_HASHMASK (IDF_HASHSIZE-1) /* since it is a power of 2 */
|
||||||
#define STARTHASH(hs) (hs = 0)
|
#define IDF_STARTHASH(hs) (hs = 0)
|
||||||
#define ENHASH(hs,ch,hm) (hs += (ch ^ hm))
|
#define IDF_ENHASH(hs,ch,hm) (hs += (ch ^ hm))
|
||||||
#define STOPHASH(hs) (hs &= HASHMASK)
|
#define IDF_STOPHASH(hs) (hs &= IDF_HASHMASK)
|
||||||
|
|
||||||
static char hmask[IDF_HSIZE];
|
static char IDF_hmask[IDF_HSIZE];
|
||||||
|
|
||||||
static struct idf *id_hashtable[HASHSIZE];
|
static struct idf *IDF_hashtable[IDF_HASHSIZE];
|
||||||
/* All identifiers can in principle be reached through
|
/* All identifiers can in principle be reached through
|
||||||
id_hashtable; id_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
|
||||||
list, regardless of the nature of its declaration
|
list, regardless of the nature of its declaration
|
||||||
|
@ -36,7 +36,7 @@ static struct idf *id_hashtable[HASHSIZE];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static struct idf *
|
static struct idf *
|
||||||
new_idf(tg, size, cpy)
|
IDF_new(tg, size, cpy)
|
||||||
register char *tg;
|
register char *tg;
|
||||||
register int size;
|
register int size;
|
||||||
{
|
{
|
||||||
|
@ -78,8 +78,8 @@ hash_stat()
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
print("Hash table tally:\n");
|
print("Hash table tally:\n");
|
||||||
for (i = 0; i < HASHSIZE; i++) {
|
for (i = 0; i < IDF_HASHSIZE; i++) {
|
||||||
register struct idf *notch = id_hashtable[i];
|
register struct idf *notch = IDF_hashtable[i];
|
||||||
register int cnt = 0;
|
register int cnt = 0;
|
||||||
|
|
||||||
while (notch) {
|
while (notch) {
|
||||||
|
@ -100,17 +100,17 @@ str2idf(tg, cpy)
|
||||||
identifier tg. If necessary, an entry is created.
|
identifier tg. If necessary, an entry is created.
|
||||||
*/
|
*/
|
||||||
register char *cp = tg;
|
register char *cp = tg;
|
||||||
register char *phm = &hmask[0];
|
register char *phm = &IDF_hmask[0];
|
||||||
struct idf **hook;
|
struct idf **hook;
|
||||||
register struct idf *notch;
|
register struct idf *notch;
|
||||||
register int hash;
|
register int hash;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
STARTHASH(hash);
|
IDF_STARTHASH(hash);
|
||||||
while (*cp && phm < &hmask[IDF_HSIZE]) {
|
while (*cp && phm < &IDF_hmask[IDF_HSIZE]) {
|
||||||
ENHASH(hash, *cp++, *phm++);
|
IDF_ENHASH(hash, *cp++, *phm++);
|
||||||
}
|
}
|
||||||
STOPHASH(hash);
|
IDF_STOPHASH(hash);
|
||||||
while (*cp++) /* nothing. Find end of string */ ;
|
while (*cp++) /* nothing. Find end of string */ ;
|
||||||
size = cp - tg;
|
size = cp - tg;
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ str2idf(tg, cpy)
|
||||||
entered if cpy >= 0. A pointer to it is returned.
|
entered if cpy >= 0. A pointer to it is returned.
|
||||||
Notice that the chains of idf's are sorted alphabetically.
|
Notice that the chains of idf's are sorted alphabetically.
|
||||||
*/
|
*/
|
||||||
hook = &id_hashtable[hash];
|
hook = &IDF_hashtable[hash];
|
||||||
|
|
||||||
while ((notch = *hook)) {
|
while ((notch = *hook)) {
|
||||||
register char *s1 = tg;
|
register char *s1 = tg;
|
||||||
|
@ -139,7 +139,7 @@ str2idf(tg, cpy)
|
||||||
}
|
}
|
||||||
/* 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 = new_idf(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 */
|
||||||
return notch;
|
return notch;
|
||||||
|
@ -149,11 +149,11 @@ init_idf() {
|
||||||
/* A simple congruence random number generator, as
|
/* A simple congruence random number generator, as
|
||||||
described in Knuth, vol 2.
|
described in Knuth, vol 2.
|
||||||
*/
|
*/
|
||||||
register int rnd = HASH_X;
|
register int rnd = IDF_HASH_X;
|
||||||
register char *phm;
|
register char *phm;
|
||||||
|
|
||||||
for (phm = &hmask[0]; phm < &hmask[IDF_HSIZE];) {
|
for (phm = &IDF_hmask[0]; phm < &IDF_hmask[IDF_HSIZE];) {
|
||||||
*phm++ = rnd;
|
*phm++ = rnd;
|
||||||
rnd = (HASH_A * rnd + HASH_C) & HASHMASK;
|
rnd = (IDF_HASH_A * rnd + IDF_HASH_C) & IDF_HASHMASK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,13 +61,13 @@ extern INP_TYPE INP_VAR;
|
||||||
#endif INP_TYPE
|
#endif INP_TYPE
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define PRIVATE
|
#define INP_PRIVATE
|
||||||
#else
|
#else
|
||||||
#define PRIVATE static
|
#define INP_PRIVATE static
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct buffer_header {
|
struct INP_buffer_header {
|
||||||
struct buffer_header *next;
|
struct INP_buffer_header *bh_next;
|
||||||
int bh_size; /* = strlen (text), should be unsigned */
|
int bh_size; /* = strlen (text), should be unsigned */
|
||||||
char *bh_text; /* pointer to buffer containing text */
|
char *bh_text; /* pointer to buffer containing text */
|
||||||
char *bh_ipp; /* current read pointer (= stacked ipp) */
|
char *bh_ipp; /* current read pointer (= stacked ipp) */
|
||||||
|
@ -79,24 +79,24 @@ struct buffer_header {
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef INP_READ_IN_ONE
|
#ifndef INP_READ_IN_ONE
|
||||||
struct i_buf {
|
struct INP_i_buf {
|
||||||
struct i_buf *next;
|
struct INP_i_buf *ib_next;
|
||||||
char ib_text[INP_BUFSIZE+INP_NPUSHBACK];
|
char ib_text[INP_BUFSIZE+INP_NPUSHBACK];
|
||||||
};
|
};
|
||||||
|
|
||||||
# endif not INP_READ_IN_ONE
|
# endif not INP_READ_IN_ONE
|
||||||
|
|
||||||
char *_ipp;
|
char *_ipp;
|
||||||
PRIVATE struct buffer_header *head;
|
INP_PRIVATE struct INP_buffer_header *INP_head;
|
||||||
|
|
||||||
#ifdef INP_READ_IN_ONE
|
#ifdef INP_READ_IN_ONE
|
||||||
/* readfile() creates a buffer in which the text of the file
|
/* INP_rdfile() creates a buffer in which the text of the file
|
||||||
is situated. A pointer to the start of this text is
|
is situated. A pointer to the start of this text is
|
||||||
returned. *size is initialized with the buffer length.
|
returned. *size is initialized with the buffer length.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PRIVATE int
|
INP_PRIVATE int
|
||||||
readfile(fd, fn, size, pbuf)
|
INP_rdfile(fd, fn, size, pbuf)
|
||||||
register File *fd;
|
register File *fd;
|
||||||
char *fn; /* file name */
|
char *fn; /* file name */
|
||||||
register long *size;
|
register long *size;
|
||||||
|
@ -127,19 +127,19 @@ readfile(fd, fn, size, pbuf)
|
||||||
#endif INP_READ_IN_ONE
|
#endif INP_READ_IN_ONE
|
||||||
|
|
||||||
#ifndef INP_READ_IN_ONE
|
#ifndef INP_READ_IN_ONE
|
||||||
/* Input buffer supplying routines: pushbuf()
|
/* Input buffer supplying routines: INP_pbuf()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PRIVATE struct i_buf *i_ptr;
|
INP_PRIVATE struct INP_i_buf *i_ptr;
|
||||||
|
|
||||||
PRIVATE char *
|
INP_PRIVATE char *
|
||||||
pushbuf()
|
INP_pbuf()
|
||||||
{
|
{
|
||||||
register struct i_buf *ib =
|
register struct INP_i_buf *ib =
|
||||||
(struct i_buf *) malloc(sizeof(struct i_buf));
|
(struct INP_i_buf *) malloc(sizeof(struct INP_i_buf));
|
||||||
|
|
||||||
if (!ib) return 0;
|
if (!ib) return 0;
|
||||||
ib->next = i_ptr;
|
ib->ib_next = i_ptr;
|
||||||
i_ptr = ib;
|
i_ptr = ib;
|
||||||
|
|
||||||
/* Don't give him all of it, we need some to implement a good
|
/* Don't give him all of it, we need some to implement a good
|
||||||
|
@ -149,42 +149,42 @@ pushbuf()
|
||||||
}
|
}
|
||||||
#endif not INP_READ_IN_ONE
|
#endif not INP_READ_IN_ONE
|
||||||
|
|
||||||
/* Input buffer administration: push_bh() and pop_bh()
|
/* Input buffer administration: INP_push_bh() and INP_pop_bh()
|
||||||
*/
|
*/
|
||||||
PRIVATE struct buffer_header *
|
INP_PRIVATE struct INP_buffer_header *
|
||||||
push_bh()
|
INP_push_bh()
|
||||||
{
|
{
|
||||||
register struct buffer_header *bh;
|
register struct INP_buffer_header *bh;
|
||||||
|
|
||||||
if (bh = head) {
|
if (bh = INP_head) {
|
||||||
bh->bh_ipp = _ipp;
|
bh->bh_ipp = _ipp;
|
||||||
#ifdef INP_TYPE
|
#ifdef INP_TYPE
|
||||||
bh->bh_i = INP_VAR;
|
bh->bh_i = INP_VAR;
|
||||||
#endif INP_TYPE
|
#endif INP_TYPE
|
||||||
}
|
}
|
||||||
if (!(bh = (struct buffer_header *)malloc(sizeof(struct buffer_header)))) return 0;
|
if (!(bh = (struct INP_buffer_header *)malloc(sizeof(struct INP_buffer_header)))) return 0;
|
||||||
bh->next = head;
|
bh->bh_next = INP_head;
|
||||||
bh->bh_eofreturned = 0;
|
bh->bh_eofreturned = 0;
|
||||||
head = bh;
|
INP_head = bh;
|
||||||
return bh;
|
return bh;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pop_bh() uncovers the previous inputbuffer on the stack
|
/* INP_pop_bh() uncovers the previous inputbuffer on the stack
|
||||||
of headers. 0 is returned if there are no more
|
of headers. 0 is returned if there are no more
|
||||||
inputbuffers on the stack, 1 is returned in the other case.
|
inputbuffers on the stack, 1 is returned in the other case.
|
||||||
*/
|
*/
|
||||||
PRIVATE int
|
INP_PRIVATE int
|
||||||
pop_bh()
|
INP_pop_bh()
|
||||||
{
|
{
|
||||||
register struct buffer_header *bh = head;
|
register struct INP_buffer_header *bh = INP_head;
|
||||||
|
|
||||||
|
|
||||||
bh = bh->next;
|
bh = bh->bh_next;
|
||||||
free((char *) head);
|
free((char *) INP_head);
|
||||||
head = bh;
|
INP_head = bh;
|
||||||
|
|
||||||
if (!bh) { /* no more entries */
|
if (!bh) { /* no more entries */
|
||||||
head = (struct buffer_header *) 0;
|
INP_head = (struct INP_buffer_header *) 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,11 +198,11 @@ pop_bh()
|
||||||
|
|
||||||
#ifndef INP_READ_IN_ONE
|
#ifndef INP_READ_IN_ONE
|
||||||
/* low level I/O routine : read one block from current input
|
/* low level I/O routine : read one block from current input
|
||||||
stream : readblock
|
stream : INP_rdblock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PRIVATE int
|
INP_PRIVATE int
|
||||||
readblock(fd, buf, n)
|
INP_rdblock(fd, buf, n)
|
||||||
File *fd;
|
File *fd;
|
||||||
char buf[];
|
char buf[];
|
||||||
int *n;
|
int *n;
|
||||||
|
@ -217,13 +217,13 @@ readblock(fd, buf, n)
|
||||||
#endif not INP_READ_IN_ONE
|
#endif not INP_READ_IN_ONE
|
||||||
|
|
||||||
/* Miscellaneous routines :
|
/* Miscellaneous routines :
|
||||||
mk_filename()
|
INP_mk_filename()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* mk_filename() concatenates a dir and filename.
|
/* INP_mk_filename() concatenates a dir and filename.
|
||||||
*/
|
*/
|
||||||
PRIVATE int
|
INP_PRIVATE int
|
||||||
mk_filename(dir, file, newname)
|
INP_mk_filename(dir, file, newname)
|
||||||
register char *dir, *file;
|
register char *dir, *file;
|
||||||
char **newname;
|
char **newname;
|
||||||
{
|
{
|
||||||
|
@ -265,7 +265,7 @@ InsertFile(filnam, table, result)
|
||||||
else {
|
else {
|
||||||
while (*table) {
|
while (*table) {
|
||||||
/* look in the directory table */
|
/* look in the directory table */
|
||||||
if (!mk_filename(*table++, filnam, &newfn)) {
|
if (!INP_mk_filename(*table++, filnam, &newfn)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (sys_open(newfn, OP_READ, &fd)) {
|
if (sys_open(newfn, OP_READ, &fd)) {
|
||||||
|
@ -282,7 +282,7 @@ InsertFile(filnam, table, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd) {
|
if (fd) {
|
||||||
register struct buffer_header *bh = push_bh();
|
register struct INP_buffer_header *bh = INP_push_bh();
|
||||||
|
|
||||||
if (!bh) {
|
if (!bh) {
|
||||||
if (fd != STDIN) sys_close(fd);
|
if (fd != STDIN) sys_close(fd);
|
||||||
|
@ -290,7 +290,7 @@ InsertFile(filnam, table, result)
|
||||||
}
|
}
|
||||||
#ifdef INP_READ_IN_ONE
|
#ifdef INP_READ_IN_ONE
|
||||||
if (fd == STDIN) return 0; /* illegal */
|
if (fd == STDIN) return 0; /* illegal */
|
||||||
if (!readfile(fd, filnam, &size, &text)) {
|
if (!INP_rdfile(fd, filnam, &size, &text)) {
|
||||||
sys_close(fd);
|
sys_close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -298,9 +298,9 @@ InsertFile(filnam, table, result)
|
||||||
_ipp = bh->bh_text = text;
|
_ipp = bh->bh_text = text;
|
||||||
#else not INP_READ_IN_ONE
|
#else not INP_READ_IN_ONE
|
||||||
if (
|
if (
|
||||||
!(_ipp = bh->bh_text = pushbuf())
|
!(_ipp = bh->bh_text = INP_pbuf())
|
||||||
||
|
||
|
||||||
!readblock(fd,_ipp,&(bh->bh_size))) {
|
!INP_rdblock(fd,_ipp,&(bh->bh_size))) {
|
||||||
if (fd != STDIN) sys_close(fd);
|
if (fd != STDIN) sys_close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ int
|
||||||
InsertText(text, length)
|
InsertText(text, length)
|
||||||
char *text;
|
char *text;
|
||||||
{
|
{
|
||||||
register struct buffer_header *bh = push_bh();
|
register struct INP_buffer_header *bh = INP_push_bh();
|
||||||
|
|
||||||
if (!bh) return 0;
|
if (!bh) return 0;
|
||||||
bh->bh_size = (long) length;
|
bh->bh_size = (long) length;
|
||||||
|
@ -334,7 +334,7 @@ InsertText(text, length)
|
||||||
int
|
int
|
||||||
loadbuf()
|
loadbuf()
|
||||||
{
|
{
|
||||||
register struct buffer_header *bh = head;
|
register struct INP_buffer_header *bh = INP_head;
|
||||||
static char buf[INP_NPUSHBACK + 1];
|
static char buf[INP_NPUSHBACK + 1];
|
||||||
int FromFile;
|
int FromFile;
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ loadbuf()
|
||||||
*--de = *--so;
|
*--de = *--so;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ( readblock(bh->bh_fd, bh->bh_text, &(bh->bh_size))
|
if ( INP_rdblock(bh->bh_fd, bh->bh_text, &(bh->bh_size))
|
||||||
&&
|
&&
|
||||||
bh->bh_size > 0
|
bh->bh_size > 0
|
||||||
) {
|
) {
|
||||||
|
@ -376,9 +376,9 @@ loadbuf()
|
||||||
|
|
||||||
if (bh->bh_fd) { /* unstack a file */
|
if (bh->bh_fd) { /* unstack a file */
|
||||||
#ifndef INP_READ_IN_ONE
|
#ifndef INP_READ_IN_ONE
|
||||||
struct i_buf *ib;
|
struct INP_i_buf *ib;
|
||||||
|
|
||||||
ib = i_ptr->next;
|
ib = i_ptr->ib_next;
|
||||||
free((char *) i_ptr);
|
free((char *) i_ptr);
|
||||||
i_ptr = ib;
|
i_ptr = ib;
|
||||||
#else INP_READ_IN_ONE
|
#else INP_READ_IN_ONE
|
||||||
|
@ -395,7 +395,7 @@ loadbuf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pop_bh()) {
|
if (INP_pop_bh()) {
|
||||||
if (*_ipp) return *_ipp++;
|
if (*_ipp) return *_ipp++;
|
||||||
return loadbuf();
|
return loadbuf();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue