#

int istate;
# define NALTS 4
struct {int kstates[NALTS];} svec;
jumpfr(a0,a1)
	char *a0,*a1;
{
	char keyc[100], *kcp;
	int keyi[10], *kip;
	kip=keyi; kcp=keyc;
	*kip++ = a0;
	*kip++ = a1;
	*kcp= 0;
	return(aabinary(1,keyi, kip-keyi, keyc, sizeof(istate),0));
}
definition(a0,a1,a2)
	char *a0,*a1,*a2;
{
	char keyc[100], *kcp;
	int keyi[10], *kip;
	kip=keyi; kcp=keyc;
	while(*kcp++= *a0++);
	*kcp= 0;
	return(aabinary(2,keyi, kip-keyi, keyc, a1,a2));
}
startnam(a0)
	char *a0;
{
	char keyc[100], *kcp;
	int keyi[10], *kip;
	kip=keyi; kcp=keyc;
	while(*kcp++= *a0++);
	*kcp= 0;
	return(aabinary(3,keyi, kip-keyi, keyc, sizeof(istate),0));
}
struct node {char *aakey, *aadata; struct node *lp, *rp;};
struct node *aaroot[4];
# ifdef unix
# define cfree free
calloc(m,n)
{
int storep;
storep = alloc(m*n);
if (storep == -1)
	{write(2, "memory space exceeded\n",22); exit();}
return(storep);
}
# endif
aaclen(s)
	char *s;
{
int aak;
	for(aak=1; *s++; aak++);
return(aak);
}
aacomp(s, v, l, t)
	char *s, *t;
	int *v;
{
	int c,d, *p;
p = s;
while (l--)
	if ( (c= *p++) != (d= *v++))
		return(c > d ? '>' : '<');
s= p;
while ( (c= *s++) == (d= *t++) )
	if (c== 0)
		return('=');
return(c>d ? '>' : '<');
}
aabinary(ru,vi,li,s,len,ex)
	char *s;
	int *vi;
{
struct node *p, *op, *r, *st, **pp, *gr;
	char *cp; int *xp;
	gr = 0;
	pp = &(aaroot[ru]);
 while (*pp)
	{
	p  = *pp;
	switch(aacomp(p->aakey, vi, li, s))
		{
		case '<': small:
			pp= &(p->rp);
			break;
		case '>':
			pp= &(p->lp);
			gr = p;
			break;
		case '=':
			if (ex == 2)
				goto small;
			if (ex >= 0)
				return(p->aadata);
			cfree (p->aadata, len, 1);
			cfree(p->aakey, aaclen(p->aakey)+ li*sizeof(li), 1);
			if (p->rp == 0)
				*pp = p->lp;
			else
			{
			r = p->rp;
			if (r->lp == 0)
				{
				r->lp = p->lp;
				*pp = r;
				}
			else
			{
			st = r->lp;
			while (st->lp != 0)
				{
				r = st;
				st = r->lp;
				}
			st->lp = p->lp;
			r->lp = st->rp;
			st->rp = p->rp;
			*pp = st;
			}
			}
			cfree (p, sizeof(**aaroot), 1);
			return(0);
		}
	op=p;
	}
/* not there */
if (ex==2)
	return (gr ? gr->aakey : 0);
if (ex != 0) return(0);
p = *pp= calloc(1, sizeof(**aaroot));
p->aakey = calloc(aaclen(s)+li*sizeof(li),1);
xp = p->aakey;
while (li--)
	*xp++ = *vi++;
cp=xp;
while (*cp++ = *s++);
p->aadata = calloc(len,1);
cp = p->aadata;
while (len--)
  *cp++ = 0;
p->rp = p->lp = 0;
return(p->aadata);
}
