third_party.expat/expat/xmlwf/xmlwf.c

53 lines
1.2 KiB
C
Raw Normal View History

1997-11-11 05:52:10 +00:00
#include <stdio.h>
#include "wfcheck.h"
#include "filemap.h"
1997-11-11 05:52:10 +00:00
static
void processFile(const void *data, size_t size, const char *filename, void *arg)
1997-11-11 05:52:10 +00:00
{
1997-11-12 10:38:58 +00:00
const char *badPtr = 0;
unsigned long badLine = 0;
unsigned long badCol = 0;
int *ret = arg;
1997-11-11 05:52:10 +00:00
enum WfCheckResult result;
result = wfCheck(data, size, &badPtr, &badLine, &badCol);
1997-11-11 05:52:10 +00:00
if (result) {
static const char *message[] = {
0,
1997-11-13 09:05:46 +00:00
"DOCTYPE declaration ignored",
1997-11-11 05:52:10 +00:00
"out of memory",
"no element found",
1997-11-12 10:38:58 +00:00
"invalid token",
"unclosed token",
"unclosed token",
"mismatched tag",
"duplicate attribute",
"junk after document element",
1997-11-11 05:52:10 +00:00
};
fprintf(stderr, "%s:", filename);
1997-11-12 10:38:58 +00:00
if (badPtr != 0)
fprintf(stderr, "%lu:%lu:", badLine+1, badCol);
1997-11-13 09:05:46 +00:00
fprintf(stderr, "%c: %s", (result == wellFormedOutsideDtd ? 'W' : 'E'), message[result]);
1997-11-11 05:52:10 +00:00
putc('\n', stderr);
if (!*ret)
*ret = 1;
1997-11-11 05:52:10 +00:00
}
}
1997-11-11 05:52:10 +00:00
int main(int argc, char **argv)
{
int i;
int ret = 0;
if (argc == 1) {
fprintf(stderr, "usage: %s filename ...\n", argv[0]);
return 1;
}
for (i = 1; i < argc; i++) {
if (!filemap(argv[i], processFile, &ret))
ret = 2;
1997-11-11 05:52:10 +00:00
}
return ret;
}