static void dumpnode(Renode *node) { Rune *p; if (!node) { printf("Empty"); return; } switch (node->type) { case P_CAT: printf("Cat("); dumpnode(node->x); printf(", "); dumpnode(node->y); printf(")"); break; case P_ALT: printf("Alt("); dumpnode(node->x); printf(", "); dumpnode(node->y); printf(")"); break; case P_REP: printf(node->ng ? "NgRep(%d,%d," : "Rep(%d,%d,", node->m, node->n); dumpnode(node->x); printf(")"); break; case P_BOL: printf("Bol"); break; case P_EOL: printf("Eol"); break; case P_WORD: printf("Word"); break; case P_NWORD: printf("NotWord"); break; case P_PAR: printf("Par(%d,", node->n); dumpnode(node->x); printf(")"); break; case P_PLA: printf("PLA("); dumpnode(node->x); printf(")"); break; case P_NLA: printf("NLA("); dumpnode(node->x); printf(")"); break; case P_ANY: printf("Any"); break; case P_CHAR: printf("Char(%c)", node->c); break; case P_CCLASS: printf("Class("); for (p = node->cc->spans; p < node->cc->end; p += 2) printf("%02X-%02X,", p[0], p[1]); printf(")"); break; case P_NCCLASS: printf("NotClass("); for (p = node->cc->spans; p < node->cc->end; p += 2) printf("%02X-%02X,", p[0], p[1]); printf(")"); break; case P_REF: printf("Ref(%d)", node->n); break; } }
__pmHashWalkState walker(const __pmHashNode *n, void *v) { __pmHashWalkState state = (__pmHashWalkState)(long)v; dumpnode(n->key, (long)n->data); return state; }
void bt_dumptree(struct btree *btr) { bt_treestats(btr); if (btr->root != NULL) dumpnode(btr, btr->root, INT_MAX); }
Reprog *regcomp(const char *pattern, int cflags, const char **errorp) { struct cstate g; Renode *node; Reinst *split, *jump; int i; g.prog = malloc(sizeof (Reprog)); g.pstart = g.pend = malloc(sizeof (Renode) * strlen(pattern) * 2); if (setjmp(g.kaboom)) { if (errorp) *errorp = g.error; free(g.pstart); free(g.prog); return NULL; } g.source = pattern; g.ncclass = 0; g.nsub = 1; for (i = 0; i < MAXSUB; ++i) g.sub[i] = 0; g.prog->flags = cflags; next(&g); node = parsealt(&g); if (g.lookahead == ')') die(&g, "unmatched ')'"); if (g.lookahead != 0) die(&g, "syntax error"); g.prog->nsub = g.nsub; g.prog->start = g.prog->end = malloc((count(node) + 6) * sizeof (Reinst)); split = emit(g.prog, I_SPLIT); split->x = split + 3; split->y = split + 1; emit(g.prog, I_ANYNL); jump = emit(g.prog, I_JUMP); jump->x = split; emit(g.prog, I_LPAR); compile(g.prog, node); emit(g.prog, I_RPAR); emit(g.prog, I_END); #ifdef TEST dumpnode(node); putchar('\n'); dumpprog(g.prog); #endif free(g.pstart); if (errorp) *errorp = NULL; return g.prog; }
void chained(__pmHashCtl *h) { __pmHashNode *n; for (n = __pmHashWalk(h, PM_HASH_WALK_START); n != NULL; n = __pmHashWalk(h, PM_HASH_WALK_NEXT)) { dumpnode(n->key, (long)n->data); } }
void dumpall(struct filenode *node, int lastoff, FILE *f) { struct romfh ri; struct filenode *p; ri.nextfh = htonl(0x2d726f6d); ri.spec = htonl(0x3166732d); ri.size = htonl(lastoff); ri.checksum = htonl(0x55555555); dumpri(&ri, node, f); p = node->dirlist.head; while (p->next) { dumpnode(p, f); p = p->next; } /* Align the whole bunch to ROMBSIZE boundary */ if (lastoff&1023) dumpzero(1024-(lastoff&1023), f); }
static void dumpnode(struct btree *btr, struct btreenode *n, int nn) { int i; printf("%p: leaf: %d, n: %d", n, n->leaf, n->n); for (i = 0; i < n->n; i++) printf(", key%d: %p", i, KEYS(btr, n)[i]); if (!n->leaf) { for (i = 0; i <= n->n; i++) printf(", nodeptr%d: %p", i, NODES(btr, n)[i]); puts(""); if (nn) { nn--; for (i = 0; i <= n->n; i++) dumpnode(btr, NODES(btr, n)[i], nn); } } else puts(""); }
int dumpnode(struct filenode *node, FILE *f) { struct romfh ri; struct filenode *p; ri.nextfh = 0; ri.spec = 0; ri.size = htonl(node->size); ri.checksum = htonl(0x55555555); if(node->pad) dumpzero(node->pad, f); if(node->next && node->next->next) ri.nextfh = htonl(node->next->offset); if((node->modes & 0111) && (S_ISDIR(node->modes) || S_ISREG(node->modes))) ri.nextfh |= htonl(ROMFH_EXEC); if(node->orig_link) { ri.nextfh |= htonl(ROMFH_HRD); /* Don't allow hardlinks to convey attributes */ ri.nextfh &= ~htonl(ROMFH_EXEC); ri.spec = htonl(node->orig_link->offset); dumpri(&ri, node, f); } else if(S_ISDIR(node->modes)) { ri.nextfh |= htonl(ROMFH_DIR); if(listisempty(&node->dirlist)) { ri.spec = htonl(node->offset); } else { ri.spec = htonl(node->dirlist.head->offset); } dumpri(&ri, node, f); } else if(S_ISLNK(node->modes)) { ri.nextfh |= htonl(ROMFH_LNK); dumpri(&ri, node, f); memset(bigbuf, 0, sizeof(bigbuf)); if(readlink(node->realname, bigbuf, node->size) < 0) { return 1; } dumpdataa(bigbuf, node->size, f); } else if(S_ISREG(node->modes)) { int offset, len, fd, max, avail; ri.nextfh |= htonl(ROMFH_REG); dumpri(&ri, node, f); offset = 0; max = node->size; /* XXX warn about size mismatch */ fd = open(node->realname, O_RDONLY #ifdef O_BINARY | O_BINARY #endif ); if(fd) { while(offset < max) { avail = max - offset < sizeof(bigbuf) ? max - offset : sizeof(bigbuf); len = read(fd, bigbuf, avail); if(len <= 0) break; dumpdata(bigbuf, len, f); offset += len; } close(fd); } max = (max + 15)&~15; while(offset < max) { avail = max - offset < sizeof(bigbuf) ? max - offset : sizeof(bigbuf); memset(bigbuf, 0, avail); dumpdata(bigbuf, avail, f); offset += avail; } } else if(S_ISCHR(node->modes)) { ri.nextfh |= htonl(ROMFH_CHR); ri.spec = htonl(major(node->devnode) << 16 | minor(node->devnode)); dumpri(&ri, node, f); } else if(S_ISBLK(node->modes)) { ri.nextfh |= htonl(ROMFH_BLK); ri.spec = htonl(major(node->devnode) << 16 | minor(node->devnode)); dumpri(&ri, node, f); } else if(S_ISFIFO(node->modes)) { ri.nextfh |= htonl(ROMFH_FIF); dumpri(&ri, node, f); } else if(S_ISSOCK(node->modes)) { ri.nextfh |= htonl(ROMFH_SCK); dumpri(&ri, node, f); } p = node->dirlist.head; while(p->next) { if(dumpnode(p, f)) { return 1; } p = p->next; } return 0; }