From cd5fb875b403c25c93a8e0d4a2b47a34ce17a38d Mon Sep 17 00:00:00 2001 From: James Clark Date: Sat, 15 Nov 1997 00:37:29 +0000 Subject: [PATCH] Separate file mapping code into separate file --- expat/xmlwf/xmlwf.c | 61 ++++++++------------------------------------- 1 file changed, 10 insertions(+), 51 deletions(-) diff --git a/expat/xmlwf/xmlwf.c b/expat/xmlwf/xmlwf.c index 1f73ce94..c9e32ad5 100755 --- a/expat/xmlwf/xmlwf.c +++ b/expat/xmlwf/xmlwf.c @@ -1,53 +1,17 @@ -#define STRICT 1 -#include -#include #include #include "wfcheck.h" +#include "filemap.h" static -int doFile(const char *name) +void processFile(const void *data, size_t size, const char *filename, void *arg) { - HANDLE f; - HANDLE m; - DWORD size; - DWORD sizeHi; - const char *p; const char *badPtr = 0; unsigned long badLine = 0; unsigned long badCol = 0; - int ret; + int *ret = arg; 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; - } - 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; - } - 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; - } - result = wfCheck(p, size, &badPtr, &badLine, &badCol); + result = wfCheck(data, size, &badPtr, &badLine, &badCol); if (result) { static const char *message[] = { 0, @@ -61,21 +25,17 @@ int doFile(const char *name) "duplicate attribute", "junk after document element", }; - fprintf(stderr, "%s:", name); + fprintf(stderr, "%s:", filename); if (badPtr != 0) fprintf(stderr, "%lu:%lu:", badLine+1, badCol); fprintf(stderr, "%c: %s", (result == wellFormedOutsideDtd ? 'W' : 'E'), message[result]); putc('\n', stderr); - ret = 1; + if (!*ret) + *ret = 1; } - else - ret = 0; - UnmapViewOfFile(p); - CloseHandle(m); - CloseHandle(f); - return ret; } + int main(int argc, char **argv) { int i; @@ -85,9 +45,8 @@ int main(int argc, char **argv) return 1; } for (i = 1; i < argc; i++) { - int n = doFile(argv[i]); - if (n > ret) - ret = n; + if (!filemap(argv[i], processFile, &ret)) + ret = 2; } return ret; }