1997-12-08 03:40:12 +00:00
|
|
|
#if defined(__ORCAC__) && defined(DO_SEGMENTS)
|
1997-12-02 08:05:53 +00:00
|
|
|
segment "cpp_3_____";
|
|
|
|
#endif
|
1997-10-30 05:51:13 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A hideset is a null-terminated array of Nlist pointers.
|
|
|
|
* They are referred to by indices in the hidesets array.
|
|
|
|
* Hideset 0 is empty.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define HSSIZ 32
|
|
|
|
typedef Nlist **Hideset;
|
|
|
|
Hideset *hidesets;
|
|
|
|
int nhidesets = 0;
|
|
|
|
int maxhidesets = 3;
|
|
|
|
int inserths(Hideset, Hideset, Nlist *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test for membership in a hideset
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
checkhideset(int hs, Nlist *np)
|
|
|
|
{
|
|
|
|
Hideset hsp;
|
|
|
|
|
|
|
|
if (hs>=nhidesets)
|
|
|
|
abort();
|
|
|
|
for (hsp = hidesets[hs]; *hsp; hsp++) {
|
|
|
|
if (*hsp == np)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the (possibly new) hideset obtained by adding np to hs.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
newhideset(int hs, Nlist *np)
|
|
|
|
{
|
|
|
|
int i, len;
|
1997-12-02 08:05:53 +00:00
|
|
|
STATIC Nlist *nhs[HSSIZ+3];
|
1997-10-30 05:51:13 +00:00
|
|
|
Hideset hs1, hs2;
|
|
|
|
|
1997-12-02 08:05:53 +00:00
|
|
|
CHECKIN();
|
1997-10-30 05:51:13 +00:00
|
|
|
len = inserths(nhs, hidesets[hs], np);
|
|
|
|
for (i=0; i<nhidesets; i++) {
|
|
|
|
for (hs1=nhs, hs2=hidesets[i]; *hs1==*hs2; hs1++, hs2++)
|
1997-12-02 08:05:53 +00:00
|
|
|
if (*hs1 == NULL) {
|
|
|
|
CHECKOUT();
|
1997-10-30 05:51:13 +00:00
|
|
|
return i;
|
1997-12-02 08:05:53 +00:00
|
|
|
}
|
1997-10-30 05:51:13 +00:00
|
|
|
}
|
1997-12-02 08:05:53 +00:00
|
|
|
if (len>=HSSIZ) {
|
|
|
|
CHECKOUT();
|
1997-10-30 05:51:13 +00:00
|
|
|
return hs;
|
1997-12-02 08:05:53 +00:00
|
|
|
}
|
1997-10-30 05:51:13 +00:00
|
|
|
if (nhidesets >= maxhidesets) {
|
|
|
|
maxhidesets = 3*maxhidesets/2+1;
|
|
|
|
hidesets = (Hideset *)realloc(hidesets, (sizeof (Hideset *))*maxhidesets);
|
|
|
|
if (hidesets == NULL)
|
|
|
|
error(FATAL, "Out of memory from realloc");
|
|
|
|
}
|
|
|
|
hs1 = (Hideset)domalloc(len*sizeof(Hideset));
|
|
|
|
memmove(hs1, nhs, len*sizeof(Hideset));
|
|
|
|
hidesets[nhidesets] = hs1;
|
1997-12-02 08:05:53 +00:00
|
|
|
CHECKOUT();
|
1997-10-30 05:51:13 +00:00
|
|
|
return nhidesets++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
inserths(Hideset dhs, Hideset shs, Nlist *np)
|
|
|
|
{
|
|
|
|
Hideset odhs = dhs;
|
|
|
|
|
|
|
|
while (*shs && *shs < np)
|
|
|
|
*dhs++ = *shs++;
|
|
|
|
if (*shs != np)
|
|
|
|
*dhs++ = np;
|
|
|
|
do {
|
|
|
|
*dhs++ = *shs;
|
|
|
|
} while (*shs++);
|
|
|
|
return dhs - odhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hideset union
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
unionhideset(int hs1, int hs2)
|
|
|
|
{
|
|
|
|
Hideset hp;
|
|
|
|
|
|
|
|
for (hp = hidesets[hs2]; *hp; hp++)
|
|
|
|
hs1 = newhideset(hs1, *hp);
|
|
|
|
return hs1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iniths(void)
|
|
|
|
{
|
|
|
|
hidesets = (Hideset *)domalloc(maxhidesets*sizeof(Hideset *));
|
|
|
|
hidesets[0] = (Hideset)domalloc(sizeof(Hideset));
|
|
|
|
*hidesets[0] = NULL;
|
|
|
|
nhidesets++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prhideset(int hs)
|
|
|
|
{
|
|
|
|
Hideset np;
|
|
|
|
|
|
|
|
for (np = hidesets[hs]; *np; np++) {
|
|
|
|
fprintf(stderr, (char*)(*np)->name, (*np)->len);
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
}
|
|
|
|
}
|