libexpat/expat/xmlwf/xmlwf.c

94 lines
2.1 KiB
C
Raw Normal View History

1997-11-11 00:52:10 -05:00
#define STRICT 1
#include <windows.h>
#include <stddef.h>
#include <stdio.h>
#include "wfcheck.h"
static
int doFile(const char *name)
{
HANDLE f;
HANDLE m;
DWORD size;
1997-11-12 05:38:58 -05:00
DWORD sizeHi;
1997-11-11 00:52:10 -05:00
const char *p;
1997-11-12 05:38:58 -05:00
const char *badPtr = 0;
unsigned long badLine = 0;
unsigned long badCol = 0;
1997-11-11 00:52:10 -05:00
int ret;
enum WfCheckResult result;
f = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (f == INVALID_HANDLE_VALUE) {
fprintf(stderr, "%s: CreateFile failed\n", name);
return 0;
}
1997-11-12 05:38:58 -05:00
size = GetFileSize(f, &sizeHi);
if (sizeHi) {
fprintf(stderr, "%s: too big (limit 2Gb)\n", name);
return 0;
}
/* CreateFileMapping barfs on zero length files */
if (size == 0) {
fprintf(stderr, "%s: zero-length file\n", name);
return 0;
}
1997-11-11 00:52:10 -05:00
m = CreateFileMapping(f, NULL, PAGE_READONLY, 0, 0, NULL);
if (m == NULL) {
fprintf(stderr, "%s: CreateFileMapping failed\n", name);
CloseHandle(f);
return 0;
}
p = (const char *)MapViewOfFile(m, FILE_MAP_READ, 0, 0, 0);
if (p == NULL) {
CloseHandle(m);
CloseHandle(f);
fprintf(stderr, "%s: MapViewOfFile failed\n", name);
return 0;
}
1997-11-12 05:38:58 -05:00
result = wfCheck(p, size, &badPtr, &badLine, &badCol);
1997-11-11 00:52:10 -05:00
if (result) {
static const char *message[] = {
0,
1997-11-13 04:05:46 -05:00
"DOCTYPE declaration ignored",
1997-11-11 00:52:10 -05:00
"out of memory",
"no element found",
1997-11-12 05:38:58 -05:00
"invalid token",
"unclosed token",
"unclosed token",
"mismatched tag",
"duplicate attribute",
"junk after document element",
1997-11-11 00:52:10 -05:00
};
1997-11-12 05:38:58 -05:00
fprintf(stderr, "%s:", name);
if (badPtr != 0)
fprintf(stderr, "%lu:%lu:", badLine+1, badCol);
1997-11-13 04:05:46 -05:00
fprintf(stderr, "%c: %s", (result == wellFormedOutsideDtd ? 'W' : 'E'), message[result]);
1997-11-11 00:52:10 -05:00
putc('\n', stderr);
ret = 1;
}
else
ret = 0;
UnmapViewOfFile(p);
CloseHandle(m);
CloseHandle(f);
return ret;
}
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++) {
int n = doFile(argv[i]);
if (n > ret)
ret = n;
}
return ret;
}