puttc(T('>'), fp);
}
-#ifdef DEBUG_UNPARSED_ENTITIES
-static void unparsedEntityDecl(void *userData,
- const XML_Char *entityName,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId,
- const XML_Char *notationName)
+static
+void metaLocation(XML_Parser parser)
{
- FILE *fp = userData;
- XML_Char lit = tcschr(systemId, T('"')) ? '\'' : '"';
- fputts(T("<!ENTITY "), fp);
- fputts(entityName, fp);
- if (publicId) {
- fputts(T(" PUBLIC \""), fp);
- fputts(publicId, fp);
- puttc(T('"'), fp);
- puttc(T(' '), fp);
- }
- else
- fputts(T(" SYSTEM "), fp);
- puttc(lit, fp);
- fputts(systemId, fp);
- puttc(lit, fp);
- fputts(T(" NDATA "), fp);
- fputts(notationName, fp);
- puttc(T('>'), fp);
+ const XML_Char *uri = XML_GetBase(parser);
+ if (uri)
+ ftprintf(XML_GetUserData(parser), T(" uri=\"%s\""), uri);
+ ftprintf(XML_GetUserData(parser),
+ T(" byte=\"%ld\" line=\"%d\" col=\"%d\""),
+ XML_GetCurrentByteIndex(parser),
+ XML_GetCurrentLineNumber(parser),
+ XML_GetCurrentColumnNumber(parser));
}
-static void notationDecl(void *userData,
- const XML_Char *notationName,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId)
+static
+void metaStartElement(XML_Parser parser, const XML_Char *name, const XML_Char **atts)
{
- FILE *fp = userData;
- fputts(T("<!NOTATION "), fp);
- fputts(notationName, fp);
- if (publicId) {
- fputts(T(" PUBLIC \""), fp);
- fputts(publicId, fp);
- puttc(T('"'), fp);
+ FILE *fp = XML_GetUserData(parser);
+ ftprintf(fp, T("<starttag name=\"%s\""), name);
+ metaLocation(parser);
+ if (*atts) {
+ fputts(T(">\n"), fp);
+ do {
+ ftprintf(fp, T("<starttag name=\"%s\" value=\""), atts[0]);
+ characterData(fp, atts[1], tcslen(atts[1]));
+ fputts(T("\"/>\n"), fp);
+ } while (*(atts += 2));
+ fputts(T("</starttag>\n"), fp);
}
else
- fputts(T(" SYSTEM"), fp);
- if (systemId) {
- XML_Char lit = tcschr(systemId, T('"')) ? '\'' : '"';
- puttc(T(' '), fp);
- puttc(lit, fp);
- fputts(systemId, fp);
- puttc(lit, fp);
- }
- puttc(T('>'), fp);
+ fputts(T("/>\n"), fp);
+}
+
+static
+void metaEndElement(XML_Parser parser, const XML_Char *name)
+{
+ FILE *fp = XML_GetUserData(parser);
+ ftprintf(fp, T("<endtag name=\"%s\""), name);
+ metaLocation(parser);
+ fputts(T("/>\n"), fp);
}
-#endif /* DEBUG_UNPARSED_ENTITIES */
+static
+void metaProcessingInstruction(XML_Parser parser, const XML_Char *target, const XML_Char *data)
+{
+ FILE *fp = XML_GetUserData(parser);
+ ftprintf(fp, T("<pi target=\"%s\" data=\""), target);
+ characterData(fp, data, tcslen(data));
+ puttc(T('"'), fp);
+ metaLocation(parser);
+ fputts(T("/>\n"), fp);
+}
static
-void metaLocation(XML_Parser parser)
+void metaCharacterData(XML_Parser parser, const XML_Char *s, int len)
{
- const XML_Char *uri = XML_GetBase(parser);
- if (uri)
- ftprintf(XML_GetUserData(parser), T(" uri='%s'"), uri);
- ftprintf(XML_GetUserData(parser),
- T(" byte='%ld' line='%d' col='%d'"),
- XML_GetCurrentByteIndex(parser),
- XML_GetCurrentLineNumber(parser),
- XML_GetCurrentColumnNumber(parser));
+ FILE *fp = XML_GetUserData(parser);
+ fputts(T("<chars str=\""), fp);
+ characterData(fp, s, len);
+ puttc(T('"'), fp);
+ metaLocation(parser);
+ fputts(T("/>\n"), fp);
}
static
-void metaStartElement(XML_Parser parser, const XML_Char *name, const XML_Char **atts)
+void metaUnparsedEntityDecl(XML_Parser parser,
+ const XML_Char *entityName,
+ const XML_Char *base,
+ const XML_Char *systemId,
+ const XML_Char *publicId,
+ const XML_Char *notationName)
{
FILE *fp = XML_GetUserData(parser);
- ftprintf(fp, T("<starttag name='%s'"), name);
+ ftprintf(fp, T("<entity name=\"%s\""), entityName);
+ if (publicId)
+ ftprintf(fp, T(" public=\"%s\""), publicId);
+ fputts(T(" system=\""), fp);
+ characterData(fp, systemId, tcslen(systemId));
+ puttc(T('"'), fp);
+ ftprintf(fp, T(" notation=\"%s\""), notationName);
metaLocation(parser);
fputts(T("/>\n"), fp);
}
static
-void metaEndElement(XML_Parser parser, const XML_Char *name)
+void metaNotationDecl(XML_Parser parser,
+ const XML_Char *notationName,
+ const XML_Char *base,
+ const XML_Char *systemId,
+ const XML_Char *publicId)
{
FILE *fp = XML_GetUserData(parser);
- ftprintf(fp, T("<endtag name='%s'"), name);
+ ftprintf(fp, T("<notation name=\"%s\""), notationName);
+ if (publicId)
+ ftprintf(fp, T(" public=\"%s\""), publicId);
+ if (systemId) {
+ fputts(T(" system=\""), fp);
+ characterData(fp, systemId, tcslen(systemId));
+ puttc(T('"'), fp);
+ }
metaLocation(parser);
fputts(T("/>\n"), fp);
}
XML_SetUserData(parser, fp);
if (metaOutput) {
XML_UseParserAsHandlerArg(parser);
+ fputts(T("<document>\n"), fp);
XML_SetElementHandler(parser, metaStartElement, metaEndElement);
+ XML_SetProcessingInstructionHandler(parser, metaProcessingInstruction);
+ XML_SetCharacterDataHandler(parser, metaCharacterData);
+ XML_SetUnparsedEntityDeclHandler(parser, metaUnparsedEntityDecl);
+ XML_SetNotationDeclHandler(parser, metaNotationDecl);
}
else {
XML_SetElementHandler(parser, startElement, endElement);
XML_SetCharacterDataHandler(parser, characterData);
XML_SetProcessingInstructionHandler(parser, processingInstruction);
-#ifdef DEBUG_UNPARSED_ENTITIES
- XML_SetUnparsedEntityDeclHandler(parser, unparsedEntityDecl);
- XML_SetNotationDeclHandler(parser, notationDecl);
-#endif
}
}
if (windowsCodePages)
else
result = processStream(argv[i], parser);
if (outputDir) {
+ if (metaOutput)
+ fputts(T("</document>\n"), fp);
fclose(fp);
if (!result)
tremove(outName);