From 742fbf024fd50dcc54c3ab77e6ddf3da3224db58 Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Fri, 25 Aug 2017 17:26:57 +0100 Subject: [PATCH] Make xmlwf build with XML_UNICODE_WCHAR_T on MinGW This seems to need some extra mangling of Makefile.am for MinGW. * Add "-mwindows" to AM_CPPFLAGS * Add "AM_LDFLAGS = -municode" Running the XML tests (xmltest.sh) is problematic: it needs a unicode-aware differ for starters --- expat/xmlwf/readfilemap.c | 19 ++++++++++--------- expat/xmlwf/xmlfile.c | 6 +++--- expat/xmlwf/xmltchar.h | 2 ++ expat/xmlwf/xmlwf.c | 6 +++++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/expat/xmlwf/readfilemap.c b/expat/xmlwf/readfilemap.c index 2ee2fe95..8aa81754 100644 --- a/expat/xmlwf/readfilemap.c +++ b/expat/xmlwf/readfilemap.c @@ -71,10 +71,11 @@ #endif #include "filemap.h" +#include "xmltchar.h" int -filemap(const char *name, - void (*processor)(const void *, size_t, const char *, void *arg), +filemap(const tchar *name, + void (*processor)(const void *, size_t, const tchar *, void *arg), void *arg) { size_t nbytes; @@ -83,18 +84,18 @@ filemap(const char *name, struct stat sb; void *p; - fd = open(name, O_RDONLY|O_BINARY); + fd = topen(name, O_RDONLY|O_BINARY); if (fd < 0) { - perror(name); + tperror(name); return 0; } if (fstat(fd, &sb) < 0) { - perror(name); + tperror(name); close(fd); return 0; } if (!S_ISREG(sb.st_mode)) { - fprintf(stderr, "%s: not a regular file\n", name); + ftprintf(stderr, T("%s: not a regular file\n"), name); close(fd); return 0; } @@ -113,19 +114,19 @@ filemap(const char *name, } p = malloc(nbytes); if (!p) { - fprintf(stderr, "%s: out of memory\n", name); + ftprintf(stderr, T("%s: out of memory\n"), name); close(fd); return 0; } n = _EXPAT_read(fd, p, nbytes); if (n < 0) { - perror(name); + tperror(name); free(p); close(fd); return 0; } if (n != (_EXPAT_read_count_t)nbytes) { - fprintf(stderr, "%s: read unexpected number of bytes\n", name); + ftprintf(stderr, T("%s: read unexpected number of bytes\n"), name); free(p); close(fd); return 0; diff --git a/expat/xmlwf/xmlfile.c b/expat/xmlwf/xmlfile.c index 7799a59f..232cc47d 100644 --- a/expat/xmlwf/xmlfile.c +++ b/expat/xmlwf/xmlfile.c @@ -202,18 +202,18 @@ processStream(const XML_Char *filename, XML_Parser parser) if (filename != NULL) close(fd); ftprintf(stderr, T("%s: out of memory\n"), - filename != NULL ? filename : "xmlwf"); + filename != NULL ? filename : T("xmlwf")); return 0; } nread = read(fd, buf, READ_SIZE); if (nread < 0) { - tperror(filename != NULL ? filename : "STDIN"); + tperror(filename != NULL ? filename : T("STDIN")); if (filename != NULL) close(fd); return 0; } if (XML_ParseBuffer(parser, nread, nread == 0) == XML_STATUS_ERROR) { - reportError(parser, filename != NULL ? filename : "STDIN"); + reportError(parser, filename != NULL ? filename : T("STDIN")); if (filename != NULL) close(fd); return 0; diff --git a/expat/xmlwf/xmltchar.h b/expat/xmlwf/xmltchar.h index 92477e0d..5ba344ac 100644 --- a/expat/xmlwf/xmltchar.h +++ b/expat/xmlwf/xmltchar.h @@ -49,6 +49,7 @@ #define topen _wopen #define tmain wmain #define tremove _wremove +#define tchar wchar_t #else /* not XML_UNICODE */ #define T(x) x #define ftprintf fprintf @@ -65,4 +66,5 @@ #define topen open #define tmain main #define tremove remove +#define tchar char #endif /* not XML_UNICODE */ diff --git a/expat/xmlwf/xmlwf.c b/expat/xmlwf/xmlwf.c index a2e88df5..a55f5498 100644 --- a/expat/xmlwf/xmlwf.c +++ b/expat/xmlwf/xmlwf.c @@ -46,6 +46,10 @@ #include #endif +#ifdef XML_UNICODE +#include +#endif + /* Structures for handler user data */ typedef struct NotationList { struct NotationList *next; @@ -1018,7 +1022,7 @@ tmain(int argc, XML_Char **argv) parser = XML_ParserCreate(encoding); if (! parser) { - tperror("Could not instantiate parser"); + tperror(T("Could not instantiate parser")); exit(1); }