fprintf(output, "Result (%d nodes):\n", size);
for(i = 0; i < size; ++i) {
fprintf(output, "Result (%d nodes):\n", size);
for(i = 0; i < size; ++i) {
- assert(nodes->nodeTab[i]);
-
- if(nodes->nodeTab[i]->type == XML_NAMESPACE_DECL)
- {
- xmlNsPtr ns;
-
- ns = (xmlNsPtr)nodes->nodeTab[i];
- cur = (xmlNodePtr)ns->next;
- if(cur->ns) {
- fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n",
- ns->prefix, ns->href, cur->ns->href, cur->name);
- } else {
- fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n",
- ns->prefix, ns->href, cur->name);
- }
- }
- else if(nodes->nodeTab[i]->type == XML_ELEMENT_NODE)
- {
- cur = nodes->nodeTab[i];
- if(cur->ns) {
- fprintf(output, "= element node \"%s:%s\"\n",
- cur->ns->href, cur->name);
- }
- else
- {
- fprintf(output, "= element node \"%s\"\n",
- cur->name);
- }
- }
- else
- {
- cur = nodes->nodeTab[i];
- fprintf(output, "= node \"%s\": type %d\n", cur->name, cur->type);
- }
+ assert(nodes->nodeTab[i]);
+
+ if(nodes->nodeTab[i]->type == XML_NAMESPACE_DECL)
+ {
+ xmlNsPtr ns;
+
+ ns = (xmlNsPtr)nodes->nodeTab[i];
+ cur = (xmlNodePtr)ns->next;
+ if(cur->ns) {
+ fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n",
+ ns->prefix, ns->href, cur->ns->href, cur->name);
+ } else {
+ fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n",
+ ns->prefix, ns->href, cur->name);
+ }
+ }
+ else if(nodes->nodeTab[i]->type == XML_ELEMENT_NODE)
+ {
+ cur = nodes->nodeTab[i];
+ if(cur->ns) {
+ fprintf(output, "= element node \"%s:%s\"\n",
+ cur->ns->href, cur->name);
+ }
+ else
+ {
+ fprintf(output, "= element node \"%s\"\n",
+ cur->name);
+ }
+ }
+ else
+ {
+ cur = nodes->nodeTab[i];
+ fprintf(output, "= node \"%s\": type %d\n", cur->name, cur->type);
+ }
- inf = fopen (arg, "rb");
- count = 0;
- if (!inf)
- {
- fprintf (stderr, "%s: cannot open %s:%s\n",
- prog, arg, strerror (errno));
- exit(1);
- }
- if (cfile)
- fprintf (cfile, "char *marc_records[] = {\n");
+ inf = fopen(arg, "rb");
+ count = 0;
+ if (!inf)
+ {
+ fprintf (stderr, "%s: cannot open %s:%s\n",
+ prog, arg, strerror (errno));
+ exit(1);
+ }
+ if (cfile)
+ fprintf (cfile, "char *marc_records[] = {\n");
- {
- if (r && print_offset)
- printf ("Extra %d bytes", r);
+ {
+ if (r && print_offset && verbose)
+ printf ("<!-- Extra %d bytes at end of file -->\n", r);
+ break;
+ }
+ while (*buf < '0' || *buf > '9')
+ {
+ int i;
+ long off = ftell(inf) - 5;
+ if (verbose || print_offset)
+ printf("<!-- Skipping bad byte %d (0x%02X) at offset "
+ "%ld (0x%lx) -->\n",
+ *buf & 0xff, *buf & 0xff,
+ off, off);
+ for (i = 0; i<4; i++)
+ buf[i] = buf[i+1];
+ r = fread(buf+4, 1, 1, inf);
+ if (r < 1)
+ break;
+ }
+ if (r < 1)
+ {
+ if (verbose || print_offset)
+ printf ("<!-- End of file with data -->\n");
len = len - 5;
r = fread (buf + 5, 1, len, inf);
if (r < len)
break;
r = yaz_marc_decode_buf (mt, buf, -1, &result, &rlen);
len = len - 5;
r = fread (buf + 5, 1, len, inf);
if (r < len)
break;
r = yaz_marc_decode_buf (mt, buf, -1, &result, &rlen);
- if (r > 0 && libxml_dom_test)
- {
- xmlDocPtr doc = xmlParseMemory(result, rlen);
- if (!doc)
- fprintf(stderr, "xmLParseMemory failed\n");
- else
- {
- int i;
- xmlXPathContextPtr xpathCtx;
- xmlXPathObjectPtr xpathObj;
- static const char *xpathExpr[] = {
- "/record/datafield[@tag='245']/subfield[@code='a']",
- "/record/datafield[@tag='100']/subfield",
- "/record/datafield[@tag='245']/subfield[@code='a']",
- "/record/datafield[@tag='650']/subfield",
- "/record/datafield[@tag='650']",
- 0};
-
- xpathCtx = xmlXPathNewContext(doc);
+ if (r > 0 && libxml_dom_test)
+ {
+ xmlDocPtr doc = xmlParseMemory(result, rlen);
+ if (!doc)
+ fprintf(stderr, "xmLParseMemory failed\n");
+ else
+ {
+ int i;
+ xmlXPathContextPtr xpathCtx;
+ xmlXPathObjectPtr xpathObj;
+ static const char *xpathExpr[] = {
+ "/record/datafield[@tag='245']/subfield[@code='a']",
+ "/record/datafield[@tag='100']/subfield",
+ "/record/datafield[@tag='245']/subfield[@code='a']",
+ "/record/datafield[@tag='650']/subfield",
+ "/record/datafield[@tag='650']",
+ 0};
+
+ xpathCtx = xmlXPathNewContext(doc);
- for (i = 0; xpathExpr[i]; i++) {
- xpathObj = xmlXPathEvalExpression(xpathExpr[i], xpathCtx);
- if(xpathObj == NULL) {
- fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr[i]);
- }
- else
- {
- print_xpath_nodes(xpathObj->nodesetval, stdout);
- xmlXPathFreeObject(xpathObj);
- }
- }
- xmlXPathFreeContext(xpathCtx);
- xmlFreeDoc(doc);
- }
- }
+ for (i = 0; xpathExpr[i]; i++) {
+ xpathObj = xmlXPathEvalExpression(BAD_CAST xpathExpr[i], xpathCtx);
+ if(xpathObj == NULL) {
+ fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr[i]);
+ }
+ else
+ {
+ print_xpath_nodes(xpathObj->nodesetval, stdout);
+ xmlXPathFreeObject(xpathObj);
+ }
+ }
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+ }
+ }