From 2c080dd19f7bc8bae59595bdb61787a22394fca3 Mon Sep 17 00:00:00 2001 From: James Clark Date: Wed, 17 Jun 1998 11:19:44 +0000 Subject: [PATCH] Avoid dependence on Unicode wchar_t in xmlparse --- expat/xmlparse/xmlparse.c | 29 ++++++++++++++++------------- expat/xmlparse/xmlparse.h | 36 +++++++++++++++++++++++++++++------- expat/xmlwf/xmlwf.c | 3 +++ 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/expat/xmlparse/xmlparse.c b/expat/xmlparse/xmlparse.c index 0a9b2b18..93df6265 100755 --- a/expat/xmlparse/xmlparse.c +++ b/expat/xmlparse/xmlparse.c @@ -30,9 +30,6 @@ Contributor(s): #define XmlGetInternalEncoding XmlGetUtf16InternalEncoding #define XmlEncode XmlUtf16Encode #define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((unsigned long)s) & 1)) -#define xmlstrchr wcschr -#define xmlstrcmp wcscmp -#define XML_T(x) L ## x typedef unsigned short ICHAR; #else #define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX @@ -40,12 +37,15 @@ typedef unsigned short ICHAR; #define XmlGetInternalEncoding XmlGetUtf8InternalEncoding #define XmlEncode XmlUtf8Encode #define MUST_CONVERT(enc, s) (!(enc)->isUtf8) -#define xmlstrchr strchr -#define xmlstrcmp strcmp -#define XML_T(x) x typedef char ICHAR; #endif +#ifdef XML_UNICODE_WCHAR_T +#define XML_T(x) L ## x +#else +#define XML_T(x) x +#endif + /* Round up n to be a multiple of sz, where sz is a power of 2. */ #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) @@ -642,9 +642,9 @@ int XML_GetCurrentColumnNumber(XML_Parser parser) return position.columnNumber; } -const XML_Char *XML_ErrorString(int code) +const XML_LChar *XML_ErrorString(int code) { - static const XML_Char *message[] = { + static const XML_LChar *message[] = { 0, XML_T("out of memory"), XML_T("syntax error"), @@ -2017,11 +2017,14 @@ static void normalizeLines(XML_Char *s) { XML_Char *p; - s = xmlstrchr(s, XML_T('\r')); - if (!s) - return; + for (;; s++) { + if (*s == XML_T('\0')) + return; + if (*s == XML_T('\r')) + break; + } p = s; - while (*s) { + do { if (*s == XML_T('\r')) { *p++ = XML_T('\n'); if (*++s == XML_T('\n')) @@ -2029,7 +2032,7 @@ normalizeLines(XML_Char *s) } else *p++ = *s++; - } + } while (*s); *p = XML_T('\0'); } diff --git a/expat/xmlparse/xmlparse.h b/expat/xmlparse/xmlparse.h index 556688de..26554522 100755 --- a/expat/xmlparse/xmlparse.h +++ b/expat/xmlparse/xmlparse.h @@ -31,15 +31,38 @@ extern "C" { typedef void *XML_Parser; -#ifdef XML_UNICODE -/* Information is UTF-16 encoded. */ -/* XML_UNICODE will work only if sizeof(wchar_t) == 2. */ +#ifdef XML_UNICODE_WCHAR_T + +/* XML_UNICODE_WCHAR_T will work only if sizeof(wchar_t) == 2 and wchar_t +uses Unicode. */ +/* Information is UTF-16 encoded as wchar_ts */ + +#ifndef XML_UNICODE +#define XML_UNICODE +#endif + #include typedef wchar_t XML_Char; -#else +typedef wchar_t XML_LChar; + +#else /* not XML_UNICODE_WCHAR_T */ + +#ifdef XML_UNICODE + +/* Information is UTF-16 encoded as unsigned shorts */ +typedef unsigned short XML_Char; +typedef char XML_LChar; + +#else /* not XML_UNICODE */ + /* Information is UTF-8 encoded. */ typedef char XML_Char; -#endif +typedef char XML_LChar; + +#endif /* not XML_UNICODE */ + +#endif /* not XML_UNICODE_WCHAR_T */ + /* Constructs a new parser; encoding is the encoding specified by the external protocol or null if there is none specified. */ @@ -342,8 +365,7 @@ void XMLPARSEAPI XML_ParserFree(XML_Parser parser); /* Returns a string describing the error. */ -const XML_Char XMLPARSEAPI * -XML_ErrorString(int code); +const XML_LChar XMLPARSEAPI *XML_ErrorString(int code); #ifdef __cplusplus } diff --git a/expat/xmlwf/xmlwf.c b/expat/xmlwf/xmlwf.c index 8888232c..0cd9f48e 100755 --- a/expat/xmlwf/xmlwf.c +++ b/expat/xmlwf/xmlwf.c @@ -55,6 +55,9 @@ Contributor(s): #endif #ifdef XML_UNICODE +#ifndef XML_UNICODE_WCHAR_T +#error xmlwf requires a 16-bit Unicode-compatible wchar_t +#endif #define T(x) L ## x #define ftprintf fwprintf #define tfopen _wfopen -- 2.40.0