]> granicus.if.org Git - libexpat/commitdiff
Make xmlwf build with XML_UNICODE_WCHAR_T on MinGW
authorRhodri James <rhodri@kynesim.co.uk>
Fri, 25 Aug 2017 16:26:57 +0000 (17:26 +0100)
committerRhodri James <rhodri@kynesim.co.uk>
Mon, 4 Sep 2017 13:29:39 +0000 (14:29 +0100)
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
expat/xmlwf/xmlfile.c
expat/xmlwf/xmltchar.h
expat/xmlwf/xmlwf.c

index 2ee2fe95638ae41f98e1a471c20b2df39e7183ca..8aa817547c9afb03fe6f59673088308da47391aa 100644 (file)
 #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;
index 7799a59fab1474684e844429dcd6911cdd79975c..232cc47d42451db3638762bc1720d3074b7bfbd8 100644 (file)
@@ -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;
index 92477e0da3c1df1a03c9009b888962239832a0a3..5ba344ac62d34e43a425077faf7e37cd871549c0 100644 (file)
@@ -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 */
index a2e88df504c0d766d91f2d765c02d20697280948..a55f549846a07194a5292ac65956b75adef1f199 100644 (file)
 #include <crtdbg.h>
 #endif
 
+#ifdef XML_UNICODE
+#include <wchar.h>
+#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);
     }