libavl, libregexp: put debug functions back
This commit is contained in:
parent
ed76659c05
commit
ee9b0eef89
2 changed files with 95 additions and 0 deletions
|
@ -204,6 +204,17 @@ _deleteavl(Avl **tp, Avl *p, Avl *rx, int(*cmp)(Avl*,Avl*), Avl **del,
|
||||||
return -(ob != 0 && (*tp)->bal == 0);
|
return -(ob != 0 && (*tp)->bal == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
checkparents(Avl *a, Avl *p)
|
||||||
|
{
|
||||||
|
if(a == nil)
|
||||||
|
return;
|
||||||
|
if(a->p != p)
|
||||||
|
print("bad parent\n");
|
||||||
|
checkparents(a->n[0], a);
|
||||||
|
checkparents(a->n[1], a);
|
||||||
|
}
|
||||||
|
|
||||||
struct Avltree
|
struct Avltree
|
||||||
{
|
{
|
||||||
Avl *root;
|
Avl *root;
|
||||||
|
@ -413,3 +424,13 @@ endwalk(Avlwalk *w)
|
||||||
}
|
}
|
||||||
free(w);
|
free(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
walkavl(Avl *t, void (*f)(Avl*, void*), void *v)
|
||||||
|
{
|
||||||
|
if(t == nil)
|
||||||
|
return;
|
||||||
|
walkavl(t->n[0], f, v);
|
||||||
|
f(t, v);
|
||||||
|
walkavl(t->n[1], f, v);
|
||||||
|
}
|
||||||
|
|
|
@ -156,6 +156,17 @@ initplex(Parselex *plex, char *regstr, int lit)
|
||||||
return plex;
|
return plex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
maxthreads(Renode *tree)
|
||||||
|
{
|
||||||
|
tree = tree->left;
|
||||||
|
if(tree->op == TCAT)
|
||||||
|
tree = tree->left;
|
||||||
|
if(tree->op == TBOL)
|
||||||
|
return 2;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static Reprog*
|
static Reprog*
|
||||||
regcomp1(char *regstr, int nl, int lit)
|
regcomp1(char *regstr, int nl, int lit)
|
||||||
{
|
{
|
||||||
|
@ -179,6 +190,7 @@ regcomp1(char *regstr, int nl, int lit)
|
||||||
maxthr = regstrlen;
|
maxthr = regstrlen;
|
||||||
parsetr = node(&plex, TSUB, e0(&plex), nil);
|
parsetr = node(&plex, TSUB, e0(&plex), nil);
|
||||||
|
|
||||||
|
// prtree(parsetr, 0, 1);
|
||||||
reprog = malloc(sizeof(Reprog) +
|
reprog = malloc(sizeof(Reprog) +
|
||||||
sizeof(Reinst) * plex.instrs +
|
sizeof(Reinst) * plex.instrs +
|
||||||
sizeof(Rethread) * maxthr);
|
sizeof(Rethread) * maxthr);
|
||||||
|
@ -503,3 +515,65 @@ buildclass(Parselex *l)
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
prtree(Renode *tree, int d, int f)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(tree == nil)
|
||||||
|
return;
|
||||||
|
if(f)
|
||||||
|
for(i = 0; i < d; i++)
|
||||||
|
print("\t");
|
||||||
|
switch(tree->op) {
|
||||||
|
case TCAT:
|
||||||
|
prtree(tree->left, d, 0);
|
||||||
|
prtree(tree->right, d, 1);
|
||||||
|
break;
|
||||||
|
case TOR:
|
||||||
|
print("TOR\n");
|
||||||
|
prtree(tree->left, d+1, 1);
|
||||||
|
for(i = 0; i < d; i++)
|
||||||
|
print("\t");
|
||||||
|
print("|\n");
|
||||||
|
prtree(tree->right, d+1, 1);
|
||||||
|
break;
|
||||||
|
case TSTAR:
|
||||||
|
print("*\n");
|
||||||
|
prtree(tree->left, d+1, 1);
|
||||||
|
break;
|
||||||
|
case TPLUS:
|
||||||
|
print("+\n");
|
||||||
|
prtree(tree->left, d+1, 1);
|
||||||
|
break;
|
||||||
|
case TQUES:
|
||||||
|
print("?\n");
|
||||||
|
prtree(tree->left, d+1, 1);
|
||||||
|
break;
|
||||||
|
case TANY:
|
||||||
|
print(".\n");
|
||||||
|
prtree(tree->left, d+1, 1);
|
||||||
|
break;
|
||||||
|
case TBOL:
|
||||||
|
print("^\n");
|
||||||
|
break;
|
||||||
|
case TEOL:
|
||||||
|
print("$\n");
|
||||||
|
break;
|
||||||
|
case TSUB:
|
||||||
|
print("TSUB\n");
|
||||||
|
prtree(tree->left, d+1, 1);
|
||||||
|
break;
|
||||||
|
case TRUNE:
|
||||||
|
print("TRUNE: %C\n", tree->r);
|
||||||
|
break;
|
||||||
|
case TNOTNL:
|
||||||
|
print("TNOTNL: !\\n\n");
|
||||||
|
break;
|
||||||
|
case TCLASS:
|
||||||
|
print("CLASS: %C-%C\n", tree->r, tree->r1);
|
||||||
|
prtree(tree->left, d, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue