on master help sign in
Add a more complete debugging step
cef599cNeil Mitchell
gen/test.c+28
@@ -413,6 +413,26 @@ document* hexml_document_parse(const char* s, int slen)
413/////////////////////////////////////////////////////////////////////
413/////////////////////////////////////////////////////////////////////
414// TEST HARNESS (temporary)
414// TEST HARNESS (temporary)
415
415
416+static char* resolve(const document* d, str loc)
417+{
418+ char* buf = malloc(loc.length + 3);
419+ memcpy(&buf[1], &d->body[loc.start], loc.length);
420+ buf[0] = '\"';
421+ buf[loc.length+1] = '\"';
422+ buf[loc.length+2] = 0;
423+ return buf;
424+}
425+
426+static char* disp(str loc)
427+{
428+ char* buf = malloc(100);
429+ if (loc.length == 0)
430+ strcpy(buf, "[]");
431+ else
432+ sprintf(buf, "[%i..%i]", loc.start, end(loc)-1);
433+ return buf;
434+}
435+
416int main()
436int main()
417{
437{
418 setbuf(stdout, NULL);
438 setbuf(stdout, NULL);
@@ -427,6 +447,14 @@ int main()
427 buf[len] = 0;
447 buf[len] = 0;
428 printf("Result = %s\n", buf);
448 printf("Result = %s\n", buf);
429 printf("Used nodes = %i, attributes = %i\n", d->nodes.used_front, d->attrs.used);
449 printf("Used nodes = %i, attributes = %i\n", d->nodes.used_front, d->attrs.used);
450+
451+ for (int i = 0; i < d->attrs.used; i++)
452+ printf("Attr %i: %s=%s\n", i, resolve(d, d->attrs.attrs[i].name), resolve(d, d->attrs.attrs[i].value));
453+ for (int i = 0; i < d->nodes.used_front; i++)
454+ {
455+ printf("Node %i: %s attrs=%s, nodes=%s\n", i, resolve(d, d->nodes.nodes[i].name), disp(d->nodes.nodes[i].attrs), disp(d->nodes.nodes[i].nodes));
456+ printf(" inner %s\n outer %s\n", resolve(d, d->nodes.nodes[i].inner), resolve(d, d->nodes.nodes[i].outer));
457+ }
430 }
458 }
431 hexml_document_free(d);
459 hexml_document_free(d);
432 return 0;
460 return 0;