aboutsummaryrefslogtreecommitdiffstats
path: root/xmlwf/xmlwf.c
diff options
context:
space:
mode:
Diffstat (limited to 'xmlwf/xmlwf.c')
-rw-r--r--xmlwf/xmlwf.c404
1 files changed, 196 insertions, 208 deletions
diff --git a/xmlwf/xmlwf.c b/xmlwf/xmlwf.c
index 82d028ea56fd..2d5a87e7d99d 100644
--- a/xmlwf/xmlwf.c
+++ b/xmlwf/xmlwf.c
@@ -38,16 +38,16 @@
#include "expat.h"
#include "codepage.h"
-#include "internal.h" /* for UNUSED_P only */
+#include "internal.h" /* for UNUSED_P only */
#include "xmlfile.h"
#include "xmltchar.h"
#ifdef _MSC_VER
-# include <crtdbg.h>
+# include <crtdbg.h>
#endif
#ifdef XML_UNICODE
-# include <wchar.h>
+# include <wchar.h>
#endif
/* Structures for handler user data */
@@ -64,14 +64,12 @@ typedef struct xmlwfUserData {
const XML_Char *currentDoctypeName;
} XmlwfUserData;
-
/* This ensures proper sorting. */
#define NSSEP T('\001')
static void XMLCALL
-characterData(void *userData, const XML_Char *s, int len)
-{
+characterData(void *userData, const XML_Char *s, int len) {
FILE *fp = ((XmlwfUserData *)userData)->fp;
for (; len > 0; --len, ++s) {
switch (*s) {
@@ -106,8 +104,7 @@ characterData(void *userData, const XML_Char *s, int len)
}
static void
-attributeValue(FILE *fp, const XML_Char *s)
-{
+attributeValue(FILE *fp, const XML_Char *s) {
puttc(T('='), fp);
puttc(T('"'), fp);
assert(s);
@@ -158,14 +155,12 @@ attributeValue(FILE *fp, const XML_Char *s)
is equivalent to lexicographically comparing based on the character number. */
static int
-attcmp(const void *att1, const void *att2)
-{
+attcmp(const void *att1, const void *att2) {
return tcscmp(*(const XML_Char **)att1, *(const XML_Char **)att2);
}
static void XMLCALL
-startElement(void *userData, const XML_Char *name, const XML_Char **atts)
-{
+startElement(void *userData, const XML_Char *name, const XML_Char **atts) {
int nAtts;
const XML_Char **p;
FILE *fp = ((XmlwfUserData *)userData)->fp;
@@ -188,8 +183,7 @@ startElement(void *userData, const XML_Char *name, const XML_Char **atts)
}
static void XMLCALL
-endElement(void *userData, const XML_Char *name)
-{
+endElement(void *userData, const XML_Char *name) {
FILE *fp = ((XmlwfUserData *)userData)->fp;
puttc(T('<'), fp);
puttc(T('/'), fp);
@@ -198,8 +192,7 @@ endElement(void *userData, const XML_Char *name)
}
static int
-nsattcmp(const void *p1, const void *p2)
-{
+nsattcmp(const void *p1, const void *p2) {
const XML_Char *att1 = *(const XML_Char **)p1;
const XML_Char *att2 = *(const XML_Char **)p2;
int sep1 = (tcsrchr(att1, NSSEP) != 0);
@@ -210,8 +203,7 @@ nsattcmp(const void *p1, const void *p2)
}
static void XMLCALL
-startElementNS(void *userData, const XML_Char *name, const XML_Char **atts)
-{
+startElementNS(void *userData, const XML_Char *name, const XML_Char **atts) {
int nAtts;
int nsi;
const XML_Char **p;
@@ -226,8 +218,7 @@ startElementNS(void *userData, const XML_Char *name, const XML_Char **atts)
fputts(T(" xmlns:n1"), fp);
attributeValue(fp, name);
nsi = 2;
- }
- else {
+ } else {
fputts(name, fp);
nsi = 1;
}
@@ -245,8 +236,7 @@ startElementNS(void *userData, const XML_Char *name, const XML_Char **atts)
if (sep) {
ftprintf(fp, T("n%d:"), nsi);
fputts(sep + 1, fp);
- }
- else
+ } else
fputts(name, fp);
attributeValue(fp, *atts);
if (sep) {
@@ -259,8 +249,7 @@ startElementNS(void *userData, const XML_Char *name, const XML_Char **atts)
}
static void XMLCALL
-endElementNS(void *userData, const XML_Char *name)
-{
+endElementNS(void *userData, const XML_Char *name) {
FILE *fp = ((XmlwfUserData *)userData)->fp;
const XML_Char *sep;
puttc(T('<'), fp);
@@ -269,8 +258,7 @@ endElementNS(void *userData, const XML_Char *name)
if (sep) {
fputts(T("n1:"), fp);
fputts(sep + 1, fp);
- }
- else
+ } else
fputts(name, fp);
puttc(T('>'), fp);
}
@@ -279,8 +267,7 @@ endElementNS(void *userData, const XML_Char *name)
static void XMLCALL
processingInstruction(void *userData, const XML_Char *target,
- const XML_Char *data)
-{
+ const XML_Char *data) {
FILE *fp = ((XmlwfUserData *)userData)->fp;
puttc(T('<'), fp);
puttc(T('?'), fp);
@@ -291,9 +278,8 @@ processingInstruction(void *userData, const XML_Char *target,
puttc(T('>'), fp);
}
-
-static XML_Char *xcsdup(const XML_Char *s)
-{
+static XML_Char *
+xcsdup(const XML_Char *s) {
XML_Char *result;
int count = 0;
int numBytes;
@@ -311,19 +297,18 @@ static XML_Char *xcsdup(const XML_Char *s)
}
static void XMLCALL
-startDoctypeDecl(void *userData,
- const XML_Char *doctypeName,
- const XML_Char *UNUSED_P(sysid),
- const XML_Char *UNUSED_P(publid),
- int UNUSED_P(has_internal_subset))
-{
+startDoctypeDecl(void *userData, const XML_Char *doctypeName,
+ const XML_Char *sysid, const XML_Char *publid,
+ int has_internal_subset) {
XmlwfUserData *data = (XmlwfUserData *)userData;
+ UNUSED_P(sysid);
+ UNUSED_P(publid);
+ UNUSED_P(has_internal_subset);
data->currentDoctypeName = xcsdup(doctypeName);
}
static void
-freeNotations(XmlwfUserData *data)
-{
+freeNotations(XmlwfUserData *data) {
NotationList *notationListHead = data->notationListHead;
while (notationListHead != NULL) {
@@ -337,8 +322,8 @@ freeNotations(XmlwfUserData *data)
data->notationListHead = NULL;
}
-static int xcscmp(const XML_Char *xs, const XML_Char *xt)
-{
+static int
+xcscmp(const XML_Char *xs, const XML_Char *xt) {
while (*xs != 0 && *xt != 0) {
if (*xs < *xt)
return -1;
@@ -355,17 +340,15 @@ static int xcscmp(const XML_Char *xs, const XML_Char *xt)
}
static int
-notationCmp(const void *a, const void *b)
-{
- const NotationList * const n1 = *(NotationList **)a;
- const NotationList * const n2 = *(NotationList **)b;
+notationCmp(const void *a, const void *b) {
+ const NotationList *const n1 = *(NotationList **)a;
+ const NotationList *const n2 = *(NotationList **)b;
return xcscmp(n1->notationName, n2->notationName);
}
static void XMLCALL
-endDoctypeDecl(void *userData)
-{
+endDoctypeDecl(void *userData) {
XmlwfUserData *data = (XmlwfUserData *)userData;
NotationList **notations;
int notationCount = 0;
@@ -389,9 +372,7 @@ endDoctypeDecl(void *userData)
return;
}
- for (p = data->notationListHead, i = 0;
- i < notationCount;
- p = p->next, i++) {
+ for (p = data->notationListHead, i = 0; i < notationCount; p = p->next, i++) {
notations[i] = p;
}
qsort(notations, notationCount, sizeof(NotationList *), notationCmp);
@@ -415,8 +396,7 @@ endDoctypeDecl(void *userData)
fputts(notations[i]->systemId, data->fp);
puttc(T('\''), data->fp);
}
- }
- else if (notations[i]->systemId != NULL) {
+ } else if (notations[i]->systemId != NULL) {
fputts(T(" SYSTEM '"), data->fp);
fputts(notations[i]->systemId, data->fp);
puttc(T('\''), data->fp);
@@ -435,16 +415,13 @@ endDoctypeDecl(void *userData)
}
static void XMLCALL
-notationDecl(void *userData,
- const XML_Char *notationName,
- const XML_Char *UNUSED_P(base),
- const XML_Char *systemId,
- const XML_Char *publicId)
-{
+notationDecl(void *userData, const XML_Char *notationName, const XML_Char *base,
+ const XML_Char *systemId, const XML_Char *publicId) {
XmlwfUserData *data = (XmlwfUserData *)userData;
NotationList *entry = malloc(sizeof(NotationList));
const char *errorMessage = "Unable to store NOTATION for output\n";
+ UNUSED_P(base);
if (entry == NULL) {
fputs(errorMessage, stderr);
return; /* Nothing we can really do about this */
@@ -463,8 +440,7 @@ notationDecl(void *userData,
free(entry);
return;
}
- }
- else {
+ } else {
entry->systemId = NULL;
}
if (publicId != NULL) {
@@ -476,8 +452,7 @@ notationDecl(void *userData,
free(entry);
return;
}
- }
- else {
+ } else {
entry->publicId = NULL;
}
@@ -488,101 +463,103 @@ notationDecl(void *userData,
#endif /* not W3C14N */
static void XMLCALL
-defaultCharacterData(void *userData, const XML_Char *UNUSED_P(s), int UNUSED_P(len))
-{
- XML_DefaultCurrent((XML_Parser) userData);
+defaultCharacterData(void *userData, const XML_Char *s, int len) {
+ UNUSED_P(s);
+ UNUSED_P(len);
+ XML_DefaultCurrent((XML_Parser)userData);
}
static void XMLCALL
-defaultStartElement(void *userData, const XML_Char *UNUSED_P(name),
- const XML_Char **UNUSED_P(atts))
-{
- XML_DefaultCurrent((XML_Parser) userData);
+defaultStartElement(void *userData, const XML_Char *name,
+ const XML_Char **atts) {
+ UNUSED_P(name);
+ UNUSED_P(atts);
+ XML_DefaultCurrent((XML_Parser)userData);
}
static void XMLCALL
-defaultEndElement(void *userData, const XML_Char *UNUSED_P(name))
-{
- XML_DefaultCurrent((XML_Parser) userData);
+defaultEndElement(void *userData, const XML_Char *name) {
+ UNUSED_P(name);
+ XML_DefaultCurrent((XML_Parser)userData);
}
static void XMLCALL
-defaultProcessingInstruction(void *userData, const XML_Char *UNUSED_P(target),
- const XML_Char *UNUSED_P(data))
-{
- XML_DefaultCurrent((XML_Parser) userData);
+defaultProcessingInstruction(void *userData, const XML_Char *target,
+ const XML_Char *data) {
+ UNUSED_P(target);
+ UNUSED_P(data);
+ XML_DefaultCurrent((XML_Parser)userData);
}
static void XMLCALL
-nopCharacterData(void *UNUSED_P(userData), const XML_Char *UNUSED_P(s), int UNUSED_P(len))
-{
+nopCharacterData(void *userData, const XML_Char *s, int len) {
+ UNUSED_P(userData);
+ UNUSED_P(s);
+ UNUSED_P(len);
}
static void XMLCALL
-nopStartElement(void *UNUSED_P(userData), const XML_Char *UNUSED_P(name), const XML_Char **UNUSED_P(atts))
-{
+nopStartElement(void *userData, const XML_Char *name, const XML_Char **atts) {
+ UNUSED_P(userData);
+ UNUSED_P(name);
+ UNUSED_P(atts);
}
static void XMLCALL
-nopEndElement(void *UNUSED_P(userData), const XML_Char *UNUSED_P(name))
-{
+nopEndElement(void *userData, const XML_Char *name) {
+ UNUSED_P(userData);
+ UNUSED_P(name);
}
static void XMLCALL
-nopProcessingInstruction(void *UNUSED_P(userData), const XML_Char *UNUSED_P(target),
- const XML_Char *UNUSED_P(data))
-{
+nopProcessingInstruction(void *userData, const XML_Char *target,
+ const XML_Char *data) {
+ UNUSED_P(userData);
+ UNUSED_P(target);
+ UNUSED_P(data);
}
static void XMLCALL
-markup(void *userData, const XML_Char *s, int len)
-{
- FILE *fp = ((XmlwfUserData *)XML_GetUserData((XML_Parser) userData))->fp;
+markup(void *userData, const XML_Char *s, int len) {
+ FILE *fp = ((XmlwfUserData *)XML_GetUserData((XML_Parser)userData))->fp;
for (; len > 0; --len, ++s)
puttc(*s, fp);
}
static void
-metaLocation(XML_Parser parser)
-{
+metaLocation(XML_Parser parser) {
const XML_Char *uri = XML_GetBase(parser);
FILE *fp = ((XmlwfUserData *)XML_GetUserData(parser))->fp;
if (uri)
ftprintf(fp, T(" uri=\"%s\""), uri);
ftprintf(fp,
- T(" byte=\"%") T(XML_FMT_INT_MOD) T("d\"")
- T(" nbytes=\"%d\"")
- T(" line=\"%") T(XML_FMT_INT_MOD) T("u\"")
- T(" col=\"%") T(XML_FMT_INT_MOD) T("u\""),
- XML_GetCurrentByteIndex(parser),
- XML_GetCurrentByteCount(parser),
+ T(" byte=\"%") T(XML_FMT_INT_MOD) T("d\"") T(" nbytes=\"%d\"")
+ T(" line=\"%") T(XML_FMT_INT_MOD) T("u\"") T(" col=\"%")
+ T(XML_FMT_INT_MOD) T("u\""),
+ XML_GetCurrentByteIndex(parser), XML_GetCurrentByteCount(parser),
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser));
}
static void
-metaStartDocument(void *userData)
-{
+metaStartDocument(void *userData) {
fputts(T("<document>\n"),
- ((XmlwfUserData *)XML_GetUserData((XML_Parser) userData))->fp);
+ ((XmlwfUserData *)XML_GetUserData((XML_Parser)userData))->fp);
}
static void
-metaEndDocument(void *userData)
-{
+metaEndDocument(void *userData) {
fputts(T("</document>\n"),
- ((XmlwfUserData *)XML_GetUserData((XML_Parser) userData))->fp);
+ ((XmlwfUserData *)XML_GetUserData((XML_Parser)userData))->fp);
}
static void XMLCALL
-metaStartElement(void *userData, const XML_Char *name,
- const XML_Char **atts)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaStartElement(void *userData, const XML_Char *name, const XML_Char **atts) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
const XML_Char **specifiedAttsEnd
- = atts + XML_GetSpecifiedAttributeCount(parser);
+ = atts + XML_GetSpecifiedAttributeCount(parser);
const XML_Char **idAttPtr;
int idAttIndex = XML_GetIdAttributeIndex(parser);
if (idAttIndex < 0)
@@ -605,15 +582,13 @@ metaStartElement(void *userData, const XML_Char *name,
fputts(T("\"/>\n"), fp);
} while (*(atts += 2));
fputts(T("</starttag>\n"), fp);
- }
- else
+ } else
fputts(T("/>\n"), fp);
}
static void XMLCALL
-metaEndElement(void *userData, const XML_Char *name)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaEndElement(void *userData, const XML_Char *name) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
ftprintf(fp, T("<endtag name=\"%s\""), name);
@@ -623,9 +598,8 @@ metaEndElement(void *userData, const XML_Char *name)
static void XMLCALL
metaProcessingInstruction(void *userData, const XML_Char *target,
- const XML_Char *data)
-{
- XML_Parser parser = (XML_Parser) userData;
+ const XML_Char *data) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *usrData = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = usrData->fp;
ftprintf(fp, T("<pi target=\"%s\" data=\""), target);
@@ -636,9 +610,8 @@ metaProcessingInstruction(void *userData, const XML_Char *target,
}
static void XMLCALL
-metaComment(void *userData, const XML_Char *data)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaComment(void *userData, const XML_Char *data) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *usrData = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = usrData->fp;
fputts(T("<comment data=\""), fp);
@@ -649,9 +622,8 @@ metaComment(void *userData, const XML_Char *data)
}
static void XMLCALL
-metaStartCdataSection(void *userData)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaStartCdataSection(void *userData) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
fputts(T("<startcdata"), fp);
@@ -660,9 +632,8 @@ metaStartCdataSection(void *userData)
}
static void XMLCALL
-metaEndCdataSection(void *userData)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaEndCdataSection(void *userData) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
fputts(T("<endcdata"), fp);
@@ -671,9 +642,8 @@ metaEndCdataSection(void *userData)
}
static void XMLCALL
-metaCharacterData(void *userData, const XML_Char *s, int len)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaCharacterData(void *userData, const XML_Char *s, int len) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
fputts(T("<chars str=\""), fp);
@@ -684,24 +654,23 @@ metaCharacterData(void *userData, const XML_Char *s, int len)
}
static void XMLCALL
-metaStartDoctypeDecl(void *userData,
- const XML_Char *doctypeName,
- const XML_Char *UNUSED_P(sysid),
- const XML_Char *UNUSED_P(pubid),
- int UNUSED_P(has_internal_subset))
-{
- XML_Parser parser = (XML_Parser) userData;
+metaStartDoctypeDecl(void *userData, const XML_Char *doctypeName,
+ const XML_Char *sysid, const XML_Char *pubid,
+ int has_internal_subset) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
+ UNUSED_P(sysid);
+ UNUSED_P(pubid);
+ UNUSED_P(has_internal_subset);
ftprintf(fp, T("<startdoctype name=\"%s\""), doctypeName);
metaLocation(parser);
fputts(T("/>\n"), fp);
}
static void XMLCALL
-metaEndDoctypeDecl(void *userData)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaEndDoctypeDecl(void *userData) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
fputts(T("<enddoctype"), fp);
@@ -710,15 +679,13 @@ metaEndDoctypeDecl(void *userData)
}
static void XMLCALL
-metaNotationDecl(void *userData,
- const XML_Char *notationName,
- const XML_Char *UNUSED_P(base),
- const XML_Char *systemId,
- const XML_Char *publicId)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaNotationDecl(void *userData, const XML_Char *notationName,
+ const XML_Char *base, const XML_Char *systemId,
+ const XML_Char *publicId) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
+ UNUSED_P(base);
ftprintf(fp, T("<notation name=\"%s\""), notationName);
if (publicId)
ftprintf(fp, T(" public=\"%s\""), publicId);
@@ -731,30 +698,24 @@ metaNotationDecl(void *userData,
fputts(T("/>\n"), fp);
}
-
static void XMLCALL
-metaEntityDecl(void *userData,
- const XML_Char *entityName,
- int UNUSED_P(is_param),
- const XML_Char *value,
- int value_length,
- const XML_Char *UNUSED_P(base),
- const XML_Char *systemId,
- const XML_Char *publicId,
- const XML_Char *notationName)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaEntityDecl(void *userData, const XML_Char *entityName, int is_param,
+ const XML_Char *value, int value_length, const XML_Char *base,
+ const XML_Char *systemId, const XML_Char *publicId,
+ const XML_Char *notationName) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
+ UNUSED_P(is_param);
+ UNUSED_P(base);
if (value) {
ftprintf(fp, T("<entity name=\"%s\""), entityName);
metaLocation(parser);
puttc(T('>'), fp);
characterData(data, value, value_length);
fputts(T("</entity/>\n"), fp);
- }
- else if (notationName) {
+ } else if (notationName) {
ftprintf(fp, T("<entity name=\"%s\""), entityName);
if (publicId)
ftprintf(fp, T(" public=\"%s\""), publicId);
@@ -764,8 +725,7 @@ metaEntityDecl(void *userData,
ftprintf(fp, T(" notation=\"%s\""), notationName);
metaLocation(parser);
fputts(T("/>\n"), fp);
- }
- else {
+ } else {
ftprintf(fp, T("<entity name=\"%s\""), entityName);
if (publicId)
ftprintf(fp, T(" public=\"%s\""), publicId);
@@ -778,11 +738,9 @@ metaEntityDecl(void *userData,
}
static void XMLCALL
-metaStartNamespaceDecl(void *userData,
- const XML_Char *prefix,
- const XML_Char *uri)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaStartNamespaceDecl(void *userData, const XML_Char *prefix,
+ const XML_Char *uri) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
fputts(T("<startns"), fp);
@@ -792,74 +750,70 @@ metaStartNamespaceDecl(void *userData,
fputts(T(" ns=\""), fp);
characterData(data, uri, (int)tcslen(uri));
fputts(T("\"/>\n"), fp);
- }
- else
+ } else
fputts(T("/>\n"), fp);
}
static void XMLCALL
-metaEndNamespaceDecl(void *userData, const XML_Char *prefix)
-{
- XML_Parser parser = (XML_Parser) userData;
+metaEndNamespaceDecl(void *userData, const XML_Char *prefix) {
+ XML_Parser parser = (XML_Parser)userData;
XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser);
FILE *fp = data->fp;
- if (!prefix)
+ if (! prefix)
fputts(T("<endns/>\n"), fp);
else
ftprintf(fp, T("<endns prefix=\"%s\"/>\n"), prefix);
}
static int XMLCALL
-unknownEncodingConvert(void *data, const char *p)
-{
+unknownEncodingConvert(void *data, const char *p) {
return codepageConvert(*(int *)data, p);
}
static int XMLCALL
-unknownEncoding(void *UNUSED_P(userData), const XML_Char *name, XML_Encoding *info)
-{
+unknownEncoding(void *userData, const XML_Char *name, XML_Encoding *info) {
int cp;
static const XML_Char prefixL[] = T("windows-");
static const XML_Char prefixU[] = T("WINDOWS-");
int i;
+ UNUSED_P(userData);
for (i = 0; prefixU[i]; i++)
if (name[i] != prefixU[i] && name[i] != prefixL[i])
return 0;
-
+
cp = 0;
for (; name[i]; i++) {
static const XML_Char digits[] = T("0123456789");
const XML_Char *s = tcschr(digits, name[i]);
- if (!s)
+ if (! s)
return 0;
cp *= 10;
cp += (int)(s - digits);
if (cp >= 0x10000)
return 0;
}
- if (!codepageMap(cp, info->map))
+ if (! codepageMap(cp, info->map))
return 0;
info->convert = unknownEncodingConvert;
/* We could just cast the code page integer to a void *,
and avoid the use of release. */
info->release = free;
info->data = malloc(sizeof(int));
- if (!info->data)
+ if (! info->data)
return 0;
*(int *)info->data = cp;
return 1;
}
static int XMLCALL
-notStandalone(void *UNUSED_P(userData))
-{
+notStandalone(void *userData) {
+ UNUSED_P(userData);
return 0;
}
static void
-showVersion(XML_Char *prog)
-{
+showVersion(XML_Char *prog) {
XML_Char *s = prog;
XML_Char ch;
const XML_Feature *features = XML_GetFeatureList();
@@ -868,7 +822,7 @@ showVersion(XML_Char *prog)
#if defined(_WIN32)
|| ch == '\\'
#endif
- )
+ )
prog = s + 1;
++s;
}
@@ -889,10 +843,46 @@ showVersion(XML_Char *prog)
}
static void
-usage(const XML_Char *prog, int rc)
-{
- ftprintf(stderr,
- T("usage: %s [-s] [-n] [-p] [-x] [-e encoding] [-w] [-d output-dir] [-c] [-m] [-r] [-t] [-N] [file ...]\n"), prog);
+usage(const XML_Char *prog, int rc) {
+ ftprintf(
+ stderr,
+ /* Generated with:
+ * $ xmlwf/xmlwf_helpgen.sh
+ */
+ /* clang-format off */
+ T("usage: %s [-s] [-n] [-p] [-x] [-e ENCODING] [-w] [-r] [-d DIRECTORY]\n")
+ T(" [-c | -m | -t] [-N]\n")
+ T(" [FILE [FILE ...]]\n")
+ T("\n")
+ T("xmlwf - Determines if an XML document is well-formed\n")
+ T("\n")
+ T("positional arguments:\n")
+ T(" FILE files to process (default: STDIN)\n")
+ T("\n")
+ T("input control arguments:\n")
+ T(" -s print an error if the document is not [s]tandalone\n")
+ T(" -n enable [n]amespace processing\n")
+ T(" -p enable processing external DTDs and [p]arameter entities\n")
+ T(" -x enable processing of e[x]ternal entities\n")
+ T(" -e ENCODING override any in-document [e]ncoding declaration\n")
+ T(" -w enable support for [W]indows code pages\n")
+ T(" -r disable memory-mapping and use normal file [r]ead IO calls instead\n")
+ T("\n")
+ T("output control arguments:\n")
+ T(" -d DIRECTORY output [d]estination directory\n")
+ T(" -c write a [c]opy of input XML, not canonical XML\n")
+ T(" -m write [m]eta XML, not canonical XML\n")
+ T(" -t write no XML output for [t]iming of plain parsing\n")
+ T(" -N enable adding doctype and [n]otation declarations\n")
+ T("\n")
+ T("info arguments:\n")
+ T(" -h show this [h]elp message and exit\n")
+ T(" -v show program's [v]ersion number and exit\n")
+ T("\n")
+ T("libexpat is software libre, licensed under the MIT license.\n")
+ T("Please report bugs at https://github.com/libexpat/libexpat/issues. Thank you!\n")
+ , /* clang-format on */
+ prog);
exit(rc);
}
@@ -902,8 +892,7 @@ int wmain(int argc, XML_Char **argv);
#endif
int
-tmain(int argc, XML_Char **argv)
-{
+tmain(int argc, XML_Char **argv) {
int i, j;
const XML_Char *outputDir = NULL;
const XML_Char *encoding = NULL;
@@ -913,13 +902,13 @@ tmain(int argc, XML_Char **argv)
int useNamespaces = 0;
int requireStandalone = 0;
int requiresNotations = 0;
- enum XML_ParamEntityParsing paramEntityParsing =
- XML_PARAM_ENTITY_PARSING_NEVER;
+ enum XML_ParamEntityParsing paramEntityParsing
+ = XML_PARAM_ENTITY_PARSING_NEVER;
int useStdin = 0;
- XmlwfUserData userData = { NULL, NULL, NULL };
+ XmlwfUserData userData = {NULL, NULL, NULL};
#ifdef _MSC_VER
- _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
+ _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
i = 1;
@@ -980,8 +969,7 @@ tmain(int argc, XML_Char **argv)
if (++i == argc)
usage(argv[0], 2);
outputDir = argv[i];
- }
- else
+ } else
outputDir = argv[i] + j + 1;
i++;
j = 0;
@@ -991,8 +979,7 @@ tmain(int argc, XML_Char **argv)
if (++i == argc)
usage(argv[0], 2);
encoding = argv[i];
- }
- else
+ } else
encoding = argv[i] + j + 1;
i++;
j = 0;
@@ -1043,18 +1030,17 @@ tmain(int argc, XML_Char **argv)
XML_SetElementHandler(parser, nopStartElement, nopEndElement);
XML_SetCharacterDataHandler(parser, nopCharacterData);
XML_SetProcessingInstructionHandler(parser, nopProcessingInstruction);
- }
- else if (outputDir) {
- const XML_Char * delim = T("/");
+ } else if (outputDir) {
+ const XML_Char *delim = T("/");
const XML_Char *file = useStdin ? T("STDIN") : argv[i];
- if (!useStdin) {
+ if (! useStdin) {
/* Jump after last (back)slash */
- const XML_Char * lastDelim = tcsrchr(file, delim[0]);
+ const XML_Char *lastDelim = tcsrchr(file, delim[0]);
if (lastDelim)
file = lastDelim + 1;
#if defined(_WIN32)
else {
- const XML_Char * winDelim = T("\\");
+ const XML_Char *winDelim = T("\\");
lastDelim = tcsrchr(file, winDelim[0]);
if (lastDelim) {
file = lastDelim + 1;
@@ -1064,12 +1050,12 @@ tmain(int argc, XML_Char **argv)
#endif
}
outName = (XML_Char *)malloc((tcslen(outputDir) + tcslen(file) + 2)
- * sizeof(XML_Char));
+ * sizeof(XML_Char));
tcscpy(outName, outputDir);
tcscat(outName, delim);
tcscat(outName, file);
userData.fp = tfopen(outName, T("wb"));
- if (!userData.fp) {
+ if (! userData.fp) {
tperror(outName);
exit(1);
}
@@ -1126,13 +1112,15 @@ tmain(int argc, XML_Char **argv)
if (outputType == 'm')
metaEndDocument(parser);
fclose(userData.fp);
- if (!result) {
+ if (! result) {
tremove(outName);
- exit(2);
}
free(outName);
}
XML_ParserFree(parser);
+ if (! result) {
+ exit(2);
+ }
}
return 0;
}