ref: ee9b0eef895209023ab7d7cc1808f33318834999
parent: ed76659c054ce781ae6050e563de9ad40b3d25cd
author: ftrvxmtrx <ftrvxmtrx@gmail.com>
date: Thu Nov 17 18:07:54 EST 2016
libavl, libregexp: put debug functions back
--- a/sys/src/libavl/avl.c
+++ b/sys/src/libavl/avl.c
@@ -204,6 +204,17 @@
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
{
Avl *root;
@@ -412,4 +423,14 @@
}
}
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);
}
--- a/sys/src/libregexp/regcomp.c
+++ b/sys/src/libregexp/regcomp.c
@@ -156,6 +156,17 @@
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*
regcomp1(char *regstr, int nl, int lit)
{
@@ -179,6 +190,7 @@
maxthr = regstrlen;
parsetr = node(&plex, TSUB, e0(&plex), nil);
+// prtree(parsetr, 0, 1);
reprog = malloc(sizeof(Reprog) +
sizeof(Reinst) * plex.instrs +
sizeof(Rethread) * maxthr);
@@ -502,4 +514,66 @@
n->nclass = i++;
}
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;
+ }
}