1*1230fdc1SLionel Sambuc /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2*1230fdc1SLionel Sambuc See the file COPYING for copying permission.
3*1230fdc1SLionel Sambuc */
4*1230fdc1SLionel Sambuc
5*1230fdc1SLionel Sambuc #include <stddef.h>
6*1230fdc1SLionel Sambuc
7*1230fdc1SLionel Sambuc #ifdef COMPILED_FROM_DSP
8*1230fdc1SLionel Sambuc #include "winconfig.h"
9*1230fdc1SLionel Sambuc #elif defined(MACOS_CLASSIC)
10*1230fdc1SLionel Sambuc #include "macconfig.h"
11*1230fdc1SLionel Sambuc #elif defined(__amigaos__)
12*1230fdc1SLionel Sambuc #include "amigaconfig.h"
13*1230fdc1SLionel Sambuc #elif defined(__WATCOMC__)
14*1230fdc1SLionel Sambuc #include "watcomconfig.h"
15*1230fdc1SLionel Sambuc #else
16*1230fdc1SLionel Sambuc #ifdef HAVE_EXPAT_CONFIG_H
17*1230fdc1SLionel Sambuc #include <expat_config.h>
18*1230fdc1SLionel Sambuc #endif
19*1230fdc1SLionel Sambuc #endif /* ndef COMPILED_FROM_DSP */
20*1230fdc1SLionel Sambuc
21*1230fdc1SLionel Sambuc #include "expat_external.h"
22*1230fdc1SLionel Sambuc #include "internal.h"
23*1230fdc1SLionel Sambuc #include "xmltok.h"
24*1230fdc1SLionel Sambuc #include "nametab.h"
25*1230fdc1SLionel Sambuc
26*1230fdc1SLionel Sambuc #ifdef XML_DTD
27*1230fdc1SLionel Sambuc #define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok)
28*1230fdc1SLionel Sambuc #else
29*1230fdc1SLionel Sambuc #define IGNORE_SECTION_TOK_VTABLE /* as nothing */
30*1230fdc1SLionel Sambuc #endif
31*1230fdc1SLionel Sambuc
32*1230fdc1SLionel Sambuc #define VTABLE1 \
33*1230fdc1SLionel Sambuc { PREFIX(prologTok), PREFIX(contentTok), \
34*1230fdc1SLionel Sambuc PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \
35*1230fdc1SLionel Sambuc { PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \
36*1230fdc1SLionel Sambuc PREFIX(sameName), \
37*1230fdc1SLionel Sambuc PREFIX(nameMatchesAscii), \
38*1230fdc1SLionel Sambuc PREFIX(nameLength), \
39*1230fdc1SLionel Sambuc PREFIX(skipS), \
40*1230fdc1SLionel Sambuc PREFIX(getAtts), \
41*1230fdc1SLionel Sambuc PREFIX(charRefNumber), \
42*1230fdc1SLionel Sambuc PREFIX(predefinedEntityName), \
43*1230fdc1SLionel Sambuc PREFIX(updatePosition), \
44*1230fdc1SLionel Sambuc PREFIX(isPublicId)
45*1230fdc1SLionel Sambuc
46*1230fdc1SLionel Sambuc #define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16)
47*1230fdc1SLionel Sambuc
48*1230fdc1SLionel Sambuc #define UCS2_GET_NAMING(pages, hi, lo) \
49*1230fdc1SLionel Sambuc (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1 << ((lo) & 0x1F)))
50*1230fdc1SLionel Sambuc
51*1230fdc1SLionel Sambuc /* A 2 byte UTF-8 representation splits the characters 11 bits between
52*1230fdc1SLionel Sambuc the bottom 5 and 6 bits of the bytes. We need 8 bits to index into
53*1230fdc1SLionel Sambuc pages, 3 bits to add to that index and 5 bits to generate the mask.
54*1230fdc1SLionel Sambuc */
55*1230fdc1SLionel Sambuc #define UTF8_GET_NAMING2(pages, byte) \
56*1230fdc1SLionel Sambuc (namingBitmap[((pages)[(((byte)[0]) >> 2) & 7] << 3) \
57*1230fdc1SLionel Sambuc + ((((byte)[0]) & 3) << 1) \
58*1230fdc1SLionel Sambuc + ((((byte)[1]) >> 5) & 1)] \
59*1230fdc1SLionel Sambuc & (1 << (((byte)[1]) & 0x1F)))
60*1230fdc1SLionel Sambuc
61*1230fdc1SLionel Sambuc /* A 3 byte UTF-8 representation splits the characters 16 bits between
62*1230fdc1SLionel Sambuc the bottom 4, 6 and 6 bits of the bytes. We need 8 bits to index
63*1230fdc1SLionel Sambuc into pages, 3 bits to add to that index and 5 bits to generate the
64*1230fdc1SLionel Sambuc mask.
65*1230fdc1SLionel Sambuc */
66*1230fdc1SLionel Sambuc #define UTF8_GET_NAMING3(pages, byte) \
67*1230fdc1SLionel Sambuc (namingBitmap[((pages)[((((byte)[0]) & 0xF) << 4) \
68*1230fdc1SLionel Sambuc + ((((byte)[1]) >> 2) & 0xF)] \
69*1230fdc1SLionel Sambuc << 3) \
70*1230fdc1SLionel Sambuc + ((((byte)[1]) & 3) << 1) \
71*1230fdc1SLionel Sambuc + ((((byte)[2]) >> 5) & 1)] \
72*1230fdc1SLionel Sambuc & (1 << (((byte)[2]) & 0x1F)))
73*1230fdc1SLionel Sambuc
74*1230fdc1SLionel Sambuc #define UTF8_GET_NAMING(pages, p, n) \
75*1230fdc1SLionel Sambuc ((n) == 2 \
76*1230fdc1SLionel Sambuc ? UTF8_GET_NAMING2(pages, (const unsigned char *)(p)) \
77*1230fdc1SLionel Sambuc : ((n) == 3 \
78*1230fdc1SLionel Sambuc ? UTF8_GET_NAMING3(pages, (const unsigned char *)(p)) \
79*1230fdc1SLionel Sambuc : 0))
80*1230fdc1SLionel Sambuc
81*1230fdc1SLionel Sambuc /* Detection of invalid UTF-8 sequences is based on Table 3.1B
82*1230fdc1SLionel Sambuc of Unicode 3.2: http://www.unicode.org/unicode/reports/tr28/
83*1230fdc1SLionel Sambuc with the additional restriction of not allowing the Unicode
84*1230fdc1SLionel Sambuc code points 0xFFFF and 0xFFFE (sequences EF,BF,BF and EF,BF,BE).
85*1230fdc1SLionel Sambuc Implementation details:
86*1230fdc1SLionel Sambuc (A & 0x80) == 0 means A < 0x80
87*1230fdc1SLionel Sambuc and
88*1230fdc1SLionel Sambuc (A & 0xC0) == 0xC0 means A > 0xBF
89*1230fdc1SLionel Sambuc */
90*1230fdc1SLionel Sambuc
91*1230fdc1SLionel Sambuc #define UTF8_INVALID2(p) \
92*1230fdc1SLionel Sambuc ((*p) < 0xC2 || ((p)[1] & 0x80) == 0 || ((p)[1] & 0xC0) == 0xC0)
93*1230fdc1SLionel Sambuc
94*1230fdc1SLionel Sambuc #define UTF8_INVALID3(p) \
95*1230fdc1SLionel Sambuc (((p)[2] & 0x80) == 0 \
96*1230fdc1SLionel Sambuc || \
97*1230fdc1SLionel Sambuc ((*p) == 0xEF && (p)[1] == 0xBF \
98*1230fdc1SLionel Sambuc ? \
99*1230fdc1SLionel Sambuc (p)[2] > 0xBD \
100*1230fdc1SLionel Sambuc : \
101*1230fdc1SLionel Sambuc ((p)[2] & 0xC0) == 0xC0) \
102*1230fdc1SLionel Sambuc || \
103*1230fdc1SLionel Sambuc ((*p) == 0xE0 \
104*1230fdc1SLionel Sambuc ? \
105*1230fdc1SLionel Sambuc (p)[1] < 0xA0 || ((p)[1] & 0xC0) == 0xC0 \
106*1230fdc1SLionel Sambuc : \
107*1230fdc1SLionel Sambuc ((p)[1] & 0x80) == 0 \
108*1230fdc1SLionel Sambuc || \
109*1230fdc1SLionel Sambuc ((*p) == 0xED ? (p)[1] > 0x9F : ((p)[1] & 0xC0) == 0xC0)))
110*1230fdc1SLionel Sambuc
111*1230fdc1SLionel Sambuc #define UTF8_INVALID4(p) \
112*1230fdc1SLionel Sambuc (((p)[3] & 0x80) == 0 || ((p)[3] & 0xC0) == 0xC0 \
113*1230fdc1SLionel Sambuc || \
114*1230fdc1SLionel Sambuc ((p)[2] & 0x80) == 0 || ((p)[2] & 0xC0) == 0xC0 \
115*1230fdc1SLionel Sambuc || \
116*1230fdc1SLionel Sambuc ((*p) == 0xF0 \
117*1230fdc1SLionel Sambuc ? \
118*1230fdc1SLionel Sambuc (p)[1] < 0x90 || ((p)[1] & 0xC0) == 0xC0 \
119*1230fdc1SLionel Sambuc : \
120*1230fdc1SLionel Sambuc ((p)[1] & 0x80) == 0 \
121*1230fdc1SLionel Sambuc || \
122*1230fdc1SLionel Sambuc ((*p) == 0xF4 ? (p)[1] > 0x8F : ((p)[1] & 0xC0) == 0xC0)))
123*1230fdc1SLionel Sambuc
124*1230fdc1SLionel Sambuc static int PTRFASTCALL
isNever(const ENCODING * enc,const char * p)125*1230fdc1SLionel Sambuc isNever(const ENCODING *enc, const char *p)
126*1230fdc1SLionel Sambuc {
127*1230fdc1SLionel Sambuc return 0;
128*1230fdc1SLionel Sambuc }
129*1230fdc1SLionel Sambuc
130*1230fdc1SLionel Sambuc static int PTRFASTCALL
utf8_isName2(const ENCODING * enc,const char * p)131*1230fdc1SLionel Sambuc utf8_isName2(const ENCODING *enc, const char *p)
132*1230fdc1SLionel Sambuc {
133*1230fdc1SLionel Sambuc return UTF8_GET_NAMING2(namePages, (const unsigned char *)p);
134*1230fdc1SLionel Sambuc }
135*1230fdc1SLionel Sambuc
136*1230fdc1SLionel Sambuc static int PTRFASTCALL
utf8_isName3(const ENCODING * enc,const char * p)137*1230fdc1SLionel Sambuc utf8_isName3(const ENCODING *enc, const char *p)
138*1230fdc1SLionel Sambuc {
139*1230fdc1SLionel Sambuc return UTF8_GET_NAMING3(namePages, (const unsigned char *)p);
140*1230fdc1SLionel Sambuc }
141*1230fdc1SLionel Sambuc
142*1230fdc1SLionel Sambuc #define utf8_isName4 isNever
143*1230fdc1SLionel Sambuc
144*1230fdc1SLionel Sambuc static int PTRFASTCALL
utf8_isNmstrt2(const ENCODING * enc,const char * p)145*1230fdc1SLionel Sambuc utf8_isNmstrt2(const ENCODING *enc, const char *p)
146*1230fdc1SLionel Sambuc {
147*1230fdc1SLionel Sambuc return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p);
148*1230fdc1SLionel Sambuc }
149*1230fdc1SLionel Sambuc
150*1230fdc1SLionel Sambuc static int PTRFASTCALL
utf8_isNmstrt3(const ENCODING * enc,const char * p)151*1230fdc1SLionel Sambuc utf8_isNmstrt3(const ENCODING *enc, const char *p)
152*1230fdc1SLionel Sambuc {
153*1230fdc1SLionel Sambuc return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p);
154*1230fdc1SLionel Sambuc }
155*1230fdc1SLionel Sambuc
156*1230fdc1SLionel Sambuc #define utf8_isNmstrt4 isNever
157*1230fdc1SLionel Sambuc
158*1230fdc1SLionel Sambuc static int PTRFASTCALL
utf8_isInvalid2(const ENCODING * enc,const char * p)159*1230fdc1SLionel Sambuc utf8_isInvalid2(const ENCODING *enc, const char *p)
160*1230fdc1SLionel Sambuc {
161*1230fdc1SLionel Sambuc return UTF8_INVALID2((const unsigned char *)p);
162*1230fdc1SLionel Sambuc }
163*1230fdc1SLionel Sambuc
164*1230fdc1SLionel Sambuc static int PTRFASTCALL
utf8_isInvalid3(const ENCODING * enc,const char * p)165*1230fdc1SLionel Sambuc utf8_isInvalid3(const ENCODING *enc, const char *p)
166*1230fdc1SLionel Sambuc {
167*1230fdc1SLionel Sambuc return UTF8_INVALID3((const unsigned char *)p);
168*1230fdc1SLionel Sambuc }
169*1230fdc1SLionel Sambuc
170*1230fdc1SLionel Sambuc static int PTRFASTCALL
utf8_isInvalid4(const ENCODING * enc,const char * p)171*1230fdc1SLionel Sambuc utf8_isInvalid4(const ENCODING *enc, const char *p)
172*1230fdc1SLionel Sambuc {
173*1230fdc1SLionel Sambuc return UTF8_INVALID4((const unsigned char *)p);
174*1230fdc1SLionel Sambuc }
175*1230fdc1SLionel Sambuc
176*1230fdc1SLionel Sambuc struct normal_encoding {
177*1230fdc1SLionel Sambuc ENCODING enc;
178*1230fdc1SLionel Sambuc unsigned char type[256];
179*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
180*1230fdc1SLionel Sambuc int (PTRFASTCALL *byteType)(const ENCODING *, const char *);
181*1230fdc1SLionel Sambuc int (PTRFASTCALL *isNameMin)(const ENCODING *, const char *);
182*1230fdc1SLionel Sambuc int (PTRFASTCALL *isNmstrtMin)(const ENCODING *, const char *);
183*1230fdc1SLionel Sambuc int (PTRFASTCALL *byteToAscii)(const ENCODING *, const char *);
184*1230fdc1SLionel Sambuc int (PTRCALL *charMatches)(const ENCODING *, const char *, int);
185*1230fdc1SLionel Sambuc #endif /* XML_MIN_SIZE */
186*1230fdc1SLionel Sambuc int (PTRFASTCALL *isName2)(const ENCODING *, const char *);
187*1230fdc1SLionel Sambuc int (PTRFASTCALL *isName3)(const ENCODING *, const char *);
188*1230fdc1SLionel Sambuc int (PTRFASTCALL *isName4)(const ENCODING *, const char *);
189*1230fdc1SLionel Sambuc int (PTRFASTCALL *isNmstrt2)(const ENCODING *, const char *);
190*1230fdc1SLionel Sambuc int (PTRFASTCALL *isNmstrt3)(const ENCODING *, const char *);
191*1230fdc1SLionel Sambuc int (PTRFASTCALL *isNmstrt4)(const ENCODING *, const char *);
192*1230fdc1SLionel Sambuc int (PTRFASTCALL *isInvalid2)(const ENCODING *, const char *);
193*1230fdc1SLionel Sambuc int (PTRFASTCALL *isInvalid3)(const ENCODING *, const char *);
194*1230fdc1SLionel Sambuc int (PTRFASTCALL *isInvalid4)(const ENCODING *, const char *);
195*1230fdc1SLionel Sambuc };
196*1230fdc1SLionel Sambuc
197*1230fdc1SLionel Sambuc #define AS_NORMAL_ENCODING(enc) ((const struct normal_encoding *) (enc))
198*1230fdc1SLionel Sambuc
199*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
200*1230fdc1SLionel Sambuc
201*1230fdc1SLionel Sambuc #define STANDARD_VTABLE(E) \
202*1230fdc1SLionel Sambuc E ## byteType, \
203*1230fdc1SLionel Sambuc E ## isNameMin, \
204*1230fdc1SLionel Sambuc E ## isNmstrtMin, \
205*1230fdc1SLionel Sambuc E ## byteToAscii, \
206*1230fdc1SLionel Sambuc E ## charMatches,
207*1230fdc1SLionel Sambuc
208*1230fdc1SLionel Sambuc #else
209*1230fdc1SLionel Sambuc
210*1230fdc1SLionel Sambuc #define STANDARD_VTABLE(E) /* as nothing */
211*1230fdc1SLionel Sambuc
212*1230fdc1SLionel Sambuc #endif
213*1230fdc1SLionel Sambuc
214*1230fdc1SLionel Sambuc #define NORMAL_VTABLE(E) \
215*1230fdc1SLionel Sambuc E ## isName2, \
216*1230fdc1SLionel Sambuc E ## isName3, \
217*1230fdc1SLionel Sambuc E ## isName4, \
218*1230fdc1SLionel Sambuc E ## isNmstrt2, \
219*1230fdc1SLionel Sambuc E ## isNmstrt3, \
220*1230fdc1SLionel Sambuc E ## isNmstrt4, \
221*1230fdc1SLionel Sambuc E ## isInvalid2, \
222*1230fdc1SLionel Sambuc E ## isInvalid3, \
223*1230fdc1SLionel Sambuc E ## isInvalid4
224*1230fdc1SLionel Sambuc
225*1230fdc1SLionel Sambuc static int FASTCALL checkCharRefNumber(int);
226*1230fdc1SLionel Sambuc
227*1230fdc1SLionel Sambuc #include "xmltok_impl.h"
228*1230fdc1SLionel Sambuc #include "ascii.h"
229*1230fdc1SLionel Sambuc
230*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
231*1230fdc1SLionel Sambuc #define sb_isNameMin isNever
232*1230fdc1SLionel Sambuc #define sb_isNmstrtMin isNever
233*1230fdc1SLionel Sambuc #endif
234*1230fdc1SLionel Sambuc
235*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
236*1230fdc1SLionel Sambuc #define MINBPC(enc) ((enc)->minBytesPerChar)
237*1230fdc1SLionel Sambuc #else
238*1230fdc1SLionel Sambuc /* minimum bytes per character */
239*1230fdc1SLionel Sambuc #define MINBPC(enc) 1
240*1230fdc1SLionel Sambuc #endif
241*1230fdc1SLionel Sambuc
242*1230fdc1SLionel Sambuc #define SB_BYTE_TYPE(enc, p) \
243*1230fdc1SLionel Sambuc (((struct normal_encoding *)(enc))->type[(unsigned char)*(p)])
244*1230fdc1SLionel Sambuc
245*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
246*1230fdc1SLionel Sambuc static int PTRFASTCALL
sb_byteType(const ENCODING * enc,const char * p)247*1230fdc1SLionel Sambuc sb_byteType(const ENCODING *enc, const char *p)
248*1230fdc1SLionel Sambuc {
249*1230fdc1SLionel Sambuc return SB_BYTE_TYPE(enc, p);
250*1230fdc1SLionel Sambuc }
251*1230fdc1SLionel Sambuc #define BYTE_TYPE(enc, p) \
252*1230fdc1SLionel Sambuc (AS_NORMAL_ENCODING(enc)->byteType(enc, p))
253*1230fdc1SLionel Sambuc #else
254*1230fdc1SLionel Sambuc #define BYTE_TYPE(enc, p) SB_BYTE_TYPE(enc, p)
255*1230fdc1SLionel Sambuc #endif
256*1230fdc1SLionel Sambuc
257*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
258*1230fdc1SLionel Sambuc #define BYTE_TO_ASCII(enc, p) \
259*1230fdc1SLionel Sambuc (AS_NORMAL_ENCODING(enc)->byteToAscii(enc, p))
260*1230fdc1SLionel Sambuc static int PTRFASTCALL
sb_byteToAscii(const ENCODING * enc,const char * p)261*1230fdc1SLionel Sambuc sb_byteToAscii(const ENCODING *enc, const char *p)
262*1230fdc1SLionel Sambuc {
263*1230fdc1SLionel Sambuc return *p;
264*1230fdc1SLionel Sambuc }
265*1230fdc1SLionel Sambuc #else
266*1230fdc1SLionel Sambuc #define BYTE_TO_ASCII(enc, p) (*(p))
267*1230fdc1SLionel Sambuc #endif
268*1230fdc1SLionel Sambuc
269*1230fdc1SLionel Sambuc #define IS_NAME_CHAR(enc, p, n) \
270*1230fdc1SLionel Sambuc (AS_NORMAL_ENCODING(enc)->isName ## n(enc, p))
271*1230fdc1SLionel Sambuc #define IS_NMSTRT_CHAR(enc, p, n) \
272*1230fdc1SLionel Sambuc (AS_NORMAL_ENCODING(enc)->isNmstrt ## n(enc, p))
273*1230fdc1SLionel Sambuc #define IS_INVALID_CHAR(enc, p, n) \
274*1230fdc1SLionel Sambuc (AS_NORMAL_ENCODING(enc)->isInvalid ## n(enc, p))
275*1230fdc1SLionel Sambuc
276*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
277*1230fdc1SLionel Sambuc #define IS_NAME_CHAR_MINBPC(enc, p) \
278*1230fdc1SLionel Sambuc (AS_NORMAL_ENCODING(enc)->isNameMin(enc, p))
279*1230fdc1SLionel Sambuc #define IS_NMSTRT_CHAR_MINBPC(enc, p) \
280*1230fdc1SLionel Sambuc (AS_NORMAL_ENCODING(enc)->isNmstrtMin(enc, p))
281*1230fdc1SLionel Sambuc #else
282*1230fdc1SLionel Sambuc #define IS_NAME_CHAR_MINBPC(enc, p) (0)
283*1230fdc1SLionel Sambuc #define IS_NMSTRT_CHAR_MINBPC(enc, p) (0)
284*1230fdc1SLionel Sambuc #endif
285*1230fdc1SLionel Sambuc
286*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
287*1230fdc1SLionel Sambuc #define CHAR_MATCHES(enc, p, c) \
288*1230fdc1SLionel Sambuc (AS_NORMAL_ENCODING(enc)->charMatches(enc, p, c))
289*1230fdc1SLionel Sambuc static int PTRCALL
sb_charMatches(const ENCODING * enc,const char * p,int c)290*1230fdc1SLionel Sambuc sb_charMatches(const ENCODING *enc, const char *p, int c)
291*1230fdc1SLionel Sambuc {
292*1230fdc1SLionel Sambuc return *p == c;
293*1230fdc1SLionel Sambuc }
294*1230fdc1SLionel Sambuc #else
295*1230fdc1SLionel Sambuc /* c is an ASCII character */
296*1230fdc1SLionel Sambuc #define CHAR_MATCHES(enc, p, c) (*(p) == c)
297*1230fdc1SLionel Sambuc #endif
298*1230fdc1SLionel Sambuc
299*1230fdc1SLionel Sambuc #define PREFIX(ident) normal_ ## ident
300*1230fdc1SLionel Sambuc #define XML_TOK_IMPL_C
301*1230fdc1SLionel Sambuc #include "xmltok_impl.c"
302*1230fdc1SLionel Sambuc #undef XML_TOK_IMPL_C
303*1230fdc1SLionel Sambuc
304*1230fdc1SLionel Sambuc #undef MINBPC
305*1230fdc1SLionel Sambuc #undef BYTE_TYPE
306*1230fdc1SLionel Sambuc #undef BYTE_TO_ASCII
307*1230fdc1SLionel Sambuc #undef CHAR_MATCHES
308*1230fdc1SLionel Sambuc #undef IS_NAME_CHAR
309*1230fdc1SLionel Sambuc #undef IS_NAME_CHAR_MINBPC
310*1230fdc1SLionel Sambuc #undef IS_NMSTRT_CHAR
311*1230fdc1SLionel Sambuc #undef IS_NMSTRT_CHAR_MINBPC
312*1230fdc1SLionel Sambuc #undef IS_INVALID_CHAR
313*1230fdc1SLionel Sambuc
314*1230fdc1SLionel Sambuc enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */
315*1230fdc1SLionel Sambuc UTF8_cval1 = 0x00,
316*1230fdc1SLionel Sambuc UTF8_cval2 = 0xc0,
317*1230fdc1SLionel Sambuc UTF8_cval3 = 0xe0,
318*1230fdc1SLionel Sambuc UTF8_cval4 = 0xf0
319*1230fdc1SLionel Sambuc };
320*1230fdc1SLionel Sambuc
321*1230fdc1SLionel Sambuc static void PTRCALL
utf8_toUtf8(const ENCODING * enc,const char ** fromP,const char * fromLim,char ** toP,const char * toLim)322*1230fdc1SLionel Sambuc utf8_toUtf8(const ENCODING *enc,
323*1230fdc1SLionel Sambuc const char **fromP, const char *fromLim,
324*1230fdc1SLionel Sambuc char **toP, const char *toLim)
325*1230fdc1SLionel Sambuc {
326*1230fdc1SLionel Sambuc char *to;
327*1230fdc1SLionel Sambuc const char *from;
328*1230fdc1SLionel Sambuc if (fromLim - *fromP > toLim - *toP) {
329*1230fdc1SLionel Sambuc /* Avoid copying partial characters. */
330*1230fdc1SLionel Sambuc for (fromLim = *fromP + (toLim - *toP); fromLim > *fromP; fromLim--)
331*1230fdc1SLionel Sambuc if (((unsigned char)fromLim[-1] & 0xc0) != 0x80)
332*1230fdc1SLionel Sambuc break;
333*1230fdc1SLionel Sambuc }
334*1230fdc1SLionel Sambuc for (to = *toP, from = *fromP; from != fromLim; from++, to++)
335*1230fdc1SLionel Sambuc *to = *from;
336*1230fdc1SLionel Sambuc *fromP = from;
337*1230fdc1SLionel Sambuc *toP = to;
338*1230fdc1SLionel Sambuc }
339*1230fdc1SLionel Sambuc
340*1230fdc1SLionel Sambuc static void PTRCALL
utf8_toUtf16(const ENCODING * enc,const char ** fromP,const char * fromLim,unsigned short ** toP,const unsigned short * toLim)341*1230fdc1SLionel Sambuc utf8_toUtf16(const ENCODING *enc,
342*1230fdc1SLionel Sambuc const char **fromP, const char *fromLim,
343*1230fdc1SLionel Sambuc unsigned short **toP, const unsigned short *toLim)
344*1230fdc1SLionel Sambuc {
345*1230fdc1SLionel Sambuc unsigned short *to = *toP;
346*1230fdc1SLionel Sambuc const char *from = *fromP;
347*1230fdc1SLionel Sambuc while (from != fromLim && to != toLim) {
348*1230fdc1SLionel Sambuc switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) {
349*1230fdc1SLionel Sambuc case BT_LEAD2:
350*1230fdc1SLionel Sambuc *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f));
351*1230fdc1SLionel Sambuc from += 2;
352*1230fdc1SLionel Sambuc break;
353*1230fdc1SLionel Sambuc case BT_LEAD3:
354*1230fdc1SLionel Sambuc *to++ = (unsigned short)(((from[0] & 0xf) << 12)
355*1230fdc1SLionel Sambuc | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f));
356*1230fdc1SLionel Sambuc from += 3;
357*1230fdc1SLionel Sambuc break;
358*1230fdc1SLionel Sambuc case BT_LEAD4:
359*1230fdc1SLionel Sambuc {
360*1230fdc1SLionel Sambuc unsigned long n;
361*1230fdc1SLionel Sambuc if (to + 1 == toLim)
362*1230fdc1SLionel Sambuc goto after;
363*1230fdc1SLionel Sambuc n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12)
364*1230fdc1SLionel Sambuc | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f);
365*1230fdc1SLionel Sambuc n -= 0x10000;
366*1230fdc1SLionel Sambuc to[0] = (unsigned short)((n >> 10) | 0xD800);
367*1230fdc1SLionel Sambuc to[1] = (unsigned short)((n & 0x3FF) | 0xDC00);
368*1230fdc1SLionel Sambuc to += 2;
369*1230fdc1SLionel Sambuc from += 4;
370*1230fdc1SLionel Sambuc }
371*1230fdc1SLionel Sambuc break;
372*1230fdc1SLionel Sambuc default:
373*1230fdc1SLionel Sambuc *to++ = *from++;
374*1230fdc1SLionel Sambuc break;
375*1230fdc1SLionel Sambuc }
376*1230fdc1SLionel Sambuc }
377*1230fdc1SLionel Sambuc after:
378*1230fdc1SLionel Sambuc *fromP = from;
379*1230fdc1SLionel Sambuc *toP = to;
380*1230fdc1SLionel Sambuc }
381*1230fdc1SLionel Sambuc
382*1230fdc1SLionel Sambuc #ifdef XML_NS
383*1230fdc1SLionel Sambuc static const struct normal_encoding utf8_encoding_ns = {
384*1230fdc1SLionel Sambuc { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
385*1230fdc1SLionel Sambuc {
386*1230fdc1SLionel Sambuc #include "asciitab.h"
387*1230fdc1SLionel Sambuc #include "utf8tab.h"
388*1230fdc1SLionel Sambuc },
389*1230fdc1SLionel Sambuc STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)
390*1230fdc1SLionel Sambuc };
391*1230fdc1SLionel Sambuc #endif
392*1230fdc1SLionel Sambuc
393*1230fdc1SLionel Sambuc static const struct normal_encoding utf8_encoding = {
394*1230fdc1SLionel Sambuc { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
395*1230fdc1SLionel Sambuc {
396*1230fdc1SLionel Sambuc #define BT_COLON BT_NMSTRT
397*1230fdc1SLionel Sambuc #include "asciitab.h"
398*1230fdc1SLionel Sambuc #undef BT_COLON
399*1230fdc1SLionel Sambuc #include "utf8tab.h"
400*1230fdc1SLionel Sambuc },
401*1230fdc1SLionel Sambuc STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)
402*1230fdc1SLionel Sambuc };
403*1230fdc1SLionel Sambuc
404*1230fdc1SLionel Sambuc #ifdef XML_NS
405*1230fdc1SLionel Sambuc
406*1230fdc1SLionel Sambuc static const struct normal_encoding internal_utf8_encoding_ns = {
407*1230fdc1SLionel Sambuc { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
408*1230fdc1SLionel Sambuc {
409*1230fdc1SLionel Sambuc #include "iasciitab.h"
410*1230fdc1SLionel Sambuc #include "utf8tab.h"
411*1230fdc1SLionel Sambuc },
412*1230fdc1SLionel Sambuc STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)
413*1230fdc1SLionel Sambuc };
414*1230fdc1SLionel Sambuc
415*1230fdc1SLionel Sambuc #endif
416*1230fdc1SLionel Sambuc
417*1230fdc1SLionel Sambuc static const struct normal_encoding internal_utf8_encoding = {
418*1230fdc1SLionel Sambuc { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
419*1230fdc1SLionel Sambuc {
420*1230fdc1SLionel Sambuc #define BT_COLON BT_NMSTRT
421*1230fdc1SLionel Sambuc #include "iasciitab.h"
422*1230fdc1SLionel Sambuc #undef BT_COLON
423*1230fdc1SLionel Sambuc #include "utf8tab.h"
424*1230fdc1SLionel Sambuc },
425*1230fdc1SLionel Sambuc STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)
426*1230fdc1SLionel Sambuc };
427*1230fdc1SLionel Sambuc
428*1230fdc1SLionel Sambuc static void PTRCALL
latin1_toUtf8(const ENCODING * enc,const char ** fromP,const char * fromLim,char ** toP,const char * toLim)429*1230fdc1SLionel Sambuc latin1_toUtf8(const ENCODING *enc,
430*1230fdc1SLionel Sambuc const char **fromP, const char *fromLim,
431*1230fdc1SLionel Sambuc char **toP, const char *toLim)
432*1230fdc1SLionel Sambuc {
433*1230fdc1SLionel Sambuc for (;;) {
434*1230fdc1SLionel Sambuc unsigned char c;
435*1230fdc1SLionel Sambuc if (*fromP == fromLim)
436*1230fdc1SLionel Sambuc break;
437*1230fdc1SLionel Sambuc c = (unsigned char)**fromP;
438*1230fdc1SLionel Sambuc if (c & 0x80) {
439*1230fdc1SLionel Sambuc if (toLim - *toP < 2)
440*1230fdc1SLionel Sambuc break;
441*1230fdc1SLionel Sambuc *(*toP)++ = (char)((c >> 6) | UTF8_cval2);
442*1230fdc1SLionel Sambuc *(*toP)++ = (char)((c & 0x3f) | 0x80);
443*1230fdc1SLionel Sambuc (*fromP)++;
444*1230fdc1SLionel Sambuc }
445*1230fdc1SLionel Sambuc else {
446*1230fdc1SLionel Sambuc if (*toP == toLim)
447*1230fdc1SLionel Sambuc break;
448*1230fdc1SLionel Sambuc *(*toP)++ = *(*fromP)++;
449*1230fdc1SLionel Sambuc }
450*1230fdc1SLionel Sambuc }
451*1230fdc1SLionel Sambuc }
452*1230fdc1SLionel Sambuc
453*1230fdc1SLionel Sambuc static void PTRCALL
latin1_toUtf16(const ENCODING * enc,const char ** fromP,const char * fromLim,unsigned short ** toP,const unsigned short * toLim)454*1230fdc1SLionel Sambuc latin1_toUtf16(const ENCODING *enc,
455*1230fdc1SLionel Sambuc const char **fromP, const char *fromLim,
456*1230fdc1SLionel Sambuc unsigned short **toP, const unsigned short *toLim)
457*1230fdc1SLionel Sambuc {
458*1230fdc1SLionel Sambuc while (*fromP != fromLim && *toP != toLim)
459*1230fdc1SLionel Sambuc *(*toP)++ = (unsigned char)*(*fromP)++;
460*1230fdc1SLionel Sambuc }
461*1230fdc1SLionel Sambuc
462*1230fdc1SLionel Sambuc #ifdef XML_NS
463*1230fdc1SLionel Sambuc
464*1230fdc1SLionel Sambuc static const struct normal_encoding latin1_encoding_ns = {
465*1230fdc1SLionel Sambuc { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 },
466*1230fdc1SLionel Sambuc {
467*1230fdc1SLionel Sambuc #include "asciitab.h"
468*1230fdc1SLionel Sambuc #include "latin1tab.h"
469*1230fdc1SLionel Sambuc },
470*1230fdc1SLionel Sambuc STANDARD_VTABLE(sb_)
471*1230fdc1SLionel Sambuc };
472*1230fdc1SLionel Sambuc
473*1230fdc1SLionel Sambuc #endif
474*1230fdc1SLionel Sambuc
475*1230fdc1SLionel Sambuc static const struct normal_encoding latin1_encoding = {
476*1230fdc1SLionel Sambuc { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 },
477*1230fdc1SLionel Sambuc {
478*1230fdc1SLionel Sambuc #define BT_COLON BT_NMSTRT
479*1230fdc1SLionel Sambuc #include "asciitab.h"
480*1230fdc1SLionel Sambuc #undef BT_COLON
481*1230fdc1SLionel Sambuc #include "latin1tab.h"
482*1230fdc1SLionel Sambuc },
483*1230fdc1SLionel Sambuc STANDARD_VTABLE(sb_)
484*1230fdc1SLionel Sambuc };
485*1230fdc1SLionel Sambuc
486*1230fdc1SLionel Sambuc static void PTRCALL
ascii_toUtf8(const ENCODING * enc,const char ** fromP,const char * fromLim,char ** toP,const char * toLim)487*1230fdc1SLionel Sambuc ascii_toUtf8(const ENCODING *enc,
488*1230fdc1SLionel Sambuc const char **fromP, const char *fromLim,
489*1230fdc1SLionel Sambuc char **toP, const char *toLim)
490*1230fdc1SLionel Sambuc {
491*1230fdc1SLionel Sambuc while (*fromP != fromLim && *toP != toLim)
492*1230fdc1SLionel Sambuc *(*toP)++ = *(*fromP)++;
493*1230fdc1SLionel Sambuc }
494*1230fdc1SLionel Sambuc
495*1230fdc1SLionel Sambuc #ifdef XML_NS
496*1230fdc1SLionel Sambuc
497*1230fdc1SLionel Sambuc static const struct normal_encoding ascii_encoding_ns = {
498*1230fdc1SLionel Sambuc { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 },
499*1230fdc1SLionel Sambuc {
500*1230fdc1SLionel Sambuc #include "asciitab.h"
501*1230fdc1SLionel Sambuc /* BT_NONXML == 0 */
502*1230fdc1SLionel Sambuc },
503*1230fdc1SLionel Sambuc STANDARD_VTABLE(sb_)
504*1230fdc1SLionel Sambuc };
505*1230fdc1SLionel Sambuc
506*1230fdc1SLionel Sambuc #endif
507*1230fdc1SLionel Sambuc
508*1230fdc1SLionel Sambuc static const struct normal_encoding ascii_encoding = {
509*1230fdc1SLionel Sambuc { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 },
510*1230fdc1SLionel Sambuc {
511*1230fdc1SLionel Sambuc #define BT_COLON BT_NMSTRT
512*1230fdc1SLionel Sambuc #include "asciitab.h"
513*1230fdc1SLionel Sambuc #undef BT_COLON
514*1230fdc1SLionel Sambuc /* BT_NONXML == 0 */
515*1230fdc1SLionel Sambuc },
516*1230fdc1SLionel Sambuc STANDARD_VTABLE(sb_)
517*1230fdc1SLionel Sambuc };
518*1230fdc1SLionel Sambuc
519*1230fdc1SLionel Sambuc static int PTRFASTCALL
unicode_byte_type(char hi,char lo)520*1230fdc1SLionel Sambuc unicode_byte_type(char hi, char lo)
521*1230fdc1SLionel Sambuc {
522*1230fdc1SLionel Sambuc switch ((unsigned char)hi) {
523*1230fdc1SLionel Sambuc case 0xD8: case 0xD9: case 0xDA: case 0xDB:
524*1230fdc1SLionel Sambuc return BT_LEAD4;
525*1230fdc1SLionel Sambuc case 0xDC: case 0xDD: case 0xDE: case 0xDF:
526*1230fdc1SLionel Sambuc return BT_TRAIL;
527*1230fdc1SLionel Sambuc case 0xFF:
528*1230fdc1SLionel Sambuc switch ((unsigned char)lo) {
529*1230fdc1SLionel Sambuc case 0xFF:
530*1230fdc1SLionel Sambuc case 0xFE:
531*1230fdc1SLionel Sambuc return BT_NONXML;
532*1230fdc1SLionel Sambuc }
533*1230fdc1SLionel Sambuc break;
534*1230fdc1SLionel Sambuc }
535*1230fdc1SLionel Sambuc return BT_NONASCII;
536*1230fdc1SLionel Sambuc }
537*1230fdc1SLionel Sambuc
538*1230fdc1SLionel Sambuc #define DEFINE_UTF16_TO_UTF8(E) \
539*1230fdc1SLionel Sambuc static void PTRCALL \
540*1230fdc1SLionel Sambuc E ## toUtf8(const ENCODING *enc, \
541*1230fdc1SLionel Sambuc const char **fromP, const char *fromLim, \
542*1230fdc1SLionel Sambuc char **toP, const char *toLim) \
543*1230fdc1SLionel Sambuc { \
544*1230fdc1SLionel Sambuc const char *from; \
545*1230fdc1SLionel Sambuc for (from = *fromP; from != fromLim; from += 2) { \
546*1230fdc1SLionel Sambuc int plane; \
547*1230fdc1SLionel Sambuc unsigned char lo2; \
548*1230fdc1SLionel Sambuc unsigned char lo = GET_LO(from); \
549*1230fdc1SLionel Sambuc unsigned char hi = GET_HI(from); \
550*1230fdc1SLionel Sambuc switch (hi) { \
551*1230fdc1SLionel Sambuc case 0: \
552*1230fdc1SLionel Sambuc if (lo < 0x80) { \
553*1230fdc1SLionel Sambuc if (*toP == toLim) { \
554*1230fdc1SLionel Sambuc *fromP = from; \
555*1230fdc1SLionel Sambuc return; \
556*1230fdc1SLionel Sambuc } \
557*1230fdc1SLionel Sambuc *(*toP)++ = lo; \
558*1230fdc1SLionel Sambuc break; \
559*1230fdc1SLionel Sambuc } \
560*1230fdc1SLionel Sambuc /* fall through */ \
561*1230fdc1SLionel Sambuc case 0x1: case 0x2: case 0x3: \
562*1230fdc1SLionel Sambuc case 0x4: case 0x5: case 0x6: case 0x7: \
563*1230fdc1SLionel Sambuc if (toLim - *toP < 2) { \
564*1230fdc1SLionel Sambuc *fromP = from; \
565*1230fdc1SLionel Sambuc return; \
566*1230fdc1SLionel Sambuc } \
567*1230fdc1SLionel Sambuc *(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \
568*1230fdc1SLionel Sambuc *(*toP)++ = ((lo & 0x3f) | 0x80); \
569*1230fdc1SLionel Sambuc break; \
570*1230fdc1SLionel Sambuc default: \
571*1230fdc1SLionel Sambuc if (toLim - *toP < 3) { \
572*1230fdc1SLionel Sambuc *fromP = from; \
573*1230fdc1SLionel Sambuc return; \
574*1230fdc1SLionel Sambuc } \
575*1230fdc1SLionel Sambuc /* 16 bits divided 4, 6, 6 amongst 3 bytes */ \
576*1230fdc1SLionel Sambuc *(*toP)++ = ((hi >> 4) | UTF8_cval3); \
577*1230fdc1SLionel Sambuc *(*toP)++ = (((hi & 0xf) << 2) | (lo >> 6) | 0x80); \
578*1230fdc1SLionel Sambuc *(*toP)++ = ((lo & 0x3f) | 0x80); \
579*1230fdc1SLionel Sambuc break; \
580*1230fdc1SLionel Sambuc case 0xD8: case 0xD9: case 0xDA: case 0xDB: \
581*1230fdc1SLionel Sambuc if (toLim - *toP < 4) { \
582*1230fdc1SLionel Sambuc *fromP = from; \
583*1230fdc1SLionel Sambuc return; \
584*1230fdc1SLionel Sambuc } \
585*1230fdc1SLionel Sambuc plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \
586*1230fdc1SLionel Sambuc *(*toP)++ = ((plane >> 2) | UTF8_cval4); \
587*1230fdc1SLionel Sambuc *(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \
588*1230fdc1SLionel Sambuc from += 2; \
589*1230fdc1SLionel Sambuc lo2 = GET_LO(from); \
590*1230fdc1SLionel Sambuc *(*toP)++ = (((lo & 0x3) << 4) \
591*1230fdc1SLionel Sambuc | ((GET_HI(from) & 0x3) << 2) \
592*1230fdc1SLionel Sambuc | (lo2 >> 6) \
593*1230fdc1SLionel Sambuc | 0x80); \
594*1230fdc1SLionel Sambuc *(*toP)++ = ((lo2 & 0x3f) | 0x80); \
595*1230fdc1SLionel Sambuc break; \
596*1230fdc1SLionel Sambuc } \
597*1230fdc1SLionel Sambuc } \
598*1230fdc1SLionel Sambuc *fromP = from; \
599*1230fdc1SLionel Sambuc }
600*1230fdc1SLionel Sambuc
601*1230fdc1SLionel Sambuc #define DEFINE_UTF16_TO_UTF16(E) \
602*1230fdc1SLionel Sambuc static void PTRCALL \
603*1230fdc1SLionel Sambuc E ## toUtf16(const ENCODING *enc, \
604*1230fdc1SLionel Sambuc const char **fromP, const char *fromLim, \
605*1230fdc1SLionel Sambuc unsigned short **toP, const unsigned short *toLim) \
606*1230fdc1SLionel Sambuc { \
607*1230fdc1SLionel Sambuc /* Avoid copying first half only of surrogate */ \
608*1230fdc1SLionel Sambuc if (fromLim - *fromP > ((toLim - *toP) << 1) \
609*1230fdc1SLionel Sambuc && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \
610*1230fdc1SLionel Sambuc fromLim -= 2; \
611*1230fdc1SLionel Sambuc for (; *fromP != fromLim && *toP != toLim; *fromP += 2) \
612*1230fdc1SLionel Sambuc *(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \
613*1230fdc1SLionel Sambuc }
614*1230fdc1SLionel Sambuc
615*1230fdc1SLionel Sambuc #define SET2(ptr, ch) \
616*1230fdc1SLionel Sambuc (((ptr)[0] = ((ch) & 0xff)), ((ptr)[1] = ((ch) >> 8)))
617*1230fdc1SLionel Sambuc #define GET_LO(ptr) ((unsigned char)(ptr)[0])
618*1230fdc1SLionel Sambuc #define GET_HI(ptr) ((unsigned char)(ptr)[1])
619*1230fdc1SLionel Sambuc
620*1230fdc1SLionel Sambuc DEFINE_UTF16_TO_UTF8(little2_)
DEFINE_UTF16_TO_UTF16(little2_)621*1230fdc1SLionel Sambuc DEFINE_UTF16_TO_UTF16(little2_)
622*1230fdc1SLionel Sambuc
623*1230fdc1SLionel Sambuc #undef SET2
624*1230fdc1SLionel Sambuc #undef GET_LO
625*1230fdc1SLionel Sambuc #undef GET_HI
626*1230fdc1SLionel Sambuc
627*1230fdc1SLionel Sambuc #define SET2(ptr, ch) \
628*1230fdc1SLionel Sambuc (((ptr)[0] = ((ch) >> 8)), ((ptr)[1] = ((ch) & 0xFF)))
629*1230fdc1SLionel Sambuc #define GET_LO(ptr) ((unsigned char)(ptr)[1])
630*1230fdc1SLionel Sambuc #define GET_HI(ptr) ((unsigned char)(ptr)[0])
631*1230fdc1SLionel Sambuc
632*1230fdc1SLionel Sambuc DEFINE_UTF16_TO_UTF8(big2_)
633*1230fdc1SLionel Sambuc DEFINE_UTF16_TO_UTF16(big2_)
634*1230fdc1SLionel Sambuc
635*1230fdc1SLionel Sambuc #undef SET2
636*1230fdc1SLionel Sambuc #undef GET_LO
637*1230fdc1SLionel Sambuc #undef GET_HI
638*1230fdc1SLionel Sambuc
639*1230fdc1SLionel Sambuc #define LITTLE2_BYTE_TYPE(enc, p) \
640*1230fdc1SLionel Sambuc ((p)[1] == 0 \
641*1230fdc1SLionel Sambuc ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \
642*1230fdc1SLionel Sambuc : unicode_byte_type((p)[1], (p)[0]))
643*1230fdc1SLionel Sambuc #define LITTLE2_BYTE_TO_ASCII(enc, p) ((p)[1] == 0 ? (p)[0] : -1)
644*1230fdc1SLionel Sambuc #define LITTLE2_CHAR_MATCHES(enc, p, c) ((p)[1] == 0 && (p)[0] == c)
645*1230fdc1SLionel Sambuc #define LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) \
646*1230fdc1SLionel Sambuc UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0])
647*1230fdc1SLionel Sambuc #define LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) \
648*1230fdc1SLionel Sambuc UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[1], (unsigned char)p[0])
649*1230fdc1SLionel Sambuc
650*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
651*1230fdc1SLionel Sambuc
652*1230fdc1SLionel Sambuc static int PTRFASTCALL
653*1230fdc1SLionel Sambuc little2_byteType(const ENCODING *enc, const char *p)
654*1230fdc1SLionel Sambuc {
655*1230fdc1SLionel Sambuc return LITTLE2_BYTE_TYPE(enc, p);
656*1230fdc1SLionel Sambuc }
657*1230fdc1SLionel Sambuc
658*1230fdc1SLionel Sambuc static int PTRFASTCALL
little2_byteToAscii(const ENCODING * enc,const char * p)659*1230fdc1SLionel Sambuc little2_byteToAscii(const ENCODING *enc, const char *p)
660*1230fdc1SLionel Sambuc {
661*1230fdc1SLionel Sambuc return LITTLE2_BYTE_TO_ASCII(enc, p);
662*1230fdc1SLionel Sambuc }
663*1230fdc1SLionel Sambuc
664*1230fdc1SLionel Sambuc static int PTRCALL
little2_charMatches(const ENCODING * enc,const char * p,int c)665*1230fdc1SLionel Sambuc little2_charMatches(const ENCODING *enc, const char *p, int c)
666*1230fdc1SLionel Sambuc {
667*1230fdc1SLionel Sambuc return LITTLE2_CHAR_MATCHES(enc, p, c);
668*1230fdc1SLionel Sambuc }
669*1230fdc1SLionel Sambuc
670*1230fdc1SLionel Sambuc static int PTRFASTCALL
little2_isNameMin(const ENCODING * enc,const char * p)671*1230fdc1SLionel Sambuc little2_isNameMin(const ENCODING *enc, const char *p)
672*1230fdc1SLionel Sambuc {
673*1230fdc1SLionel Sambuc return LITTLE2_IS_NAME_CHAR_MINBPC(enc, p);
674*1230fdc1SLionel Sambuc }
675*1230fdc1SLionel Sambuc
676*1230fdc1SLionel Sambuc static int PTRFASTCALL
little2_isNmstrtMin(const ENCODING * enc,const char * p)677*1230fdc1SLionel Sambuc little2_isNmstrtMin(const ENCODING *enc, const char *p)
678*1230fdc1SLionel Sambuc {
679*1230fdc1SLionel Sambuc return LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p);
680*1230fdc1SLionel Sambuc }
681*1230fdc1SLionel Sambuc
682*1230fdc1SLionel Sambuc #undef VTABLE
683*1230fdc1SLionel Sambuc #define VTABLE VTABLE1, little2_toUtf8, little2_toUtf16
684*1230fdc1SLionel Sambuc
685*1230fdc1SLionel Sambuc #else /* not XML_MIN_SIZE */
686*1230fdc1SLionel Sambuc
687*1230fdc1SLionel Sambuc #undef PREFIX
688*1230fdc1SLionel Sambuc #define PREFIX(ident) little2_ ## ident
689*1230fdc1SLionel Sambuc #define MINBPC(enc) 2
690*1230fdc1SLionel Sambuc /* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */
691*1230fdc1SLionel Sambuc #define BYTE_TYPE(enc, p) LITTLE2_BYTE_TYPE(enc, p)
692*1230fdc1SLionel Sambuc #define BYTE_TO_ASCII(enc, p) LITTLE2_BYTE_TO_ASCII(enc, p)
693*1230fdc1SLionel Sambuc #define CHAR_MATCHES(enc, p, c) LITTLE2_CHAR_MATCHES(enc, p, c)
694*1230fdc1SLionel Sambuc #define IS_NAME_CHAR(enc, p, n) 0
695*1230fdc1SLionel Sambuc #define IS_NAME_CHAR_MINBPC(enc, p) LITTLE2_IS_NAME_CHAR_MINBPC(enc, p)
696*1230fdc1SLionel Sambuc #define IS_NMSTRT_CHAR(enc, p, n) (0)
697*1230fdc1SLionel Sambuc #define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p)
698*1230fdc1SLionel Sambuc
699*1230fdc1SLionel Sambuc #define XML_TOK_IMPL_C
700*1230fdc1SLionel Sambuc #include "xmltok_impl.c"
701*1230fdc1SLionel Sambuc #undef XML_TOK_IMPL_C
702*1230fdc1SLionel Sambuc
703*1230fdc1SLionel Sambuc #undef MINBPC
704*1230fdc1SLionel Sambuc #undef BYTE_TYPE
705*1230fdc1SLionel Sambuc #undef BYTE_TO_ASCII
706*1230fdc1SLionel Sambuc #undef CHAR_MATCHES
707*1230fdc1SLionel Sambuc #undef IS_NAME_CHAR
708*1230fdc1SLionel Sambuc #undef IS_NAME_CHAR_MINBPC
709*1230fdc1SLionel Sambuc #undef IS_NMSTRT_CHAR
710*1230fdc1SLionel Sambuc #undef IS_NMSTRT_CHAR_MINBPC
711*1230fdc1SLionel Sambuc #undef IS_INVALID_CHAR
712*1230fdc1SLionel Sambuc
713*1230fdc1SLionel Sambuc #endif /* not XML_MIN_SIZE */
714*1230fdc1SLionel Sambuc
715*1230fdc1SLionel Sambuc #ifdef XML_NS
716*1230fdc1SLionel Sambuc
717*1230fdc1SLionel Sambuc static const struct normal_encoding little2_encoding_ns = {
718*1230fdc1SLionel Sambuc { VTABLE, 2, 0,
719*1230fdc1SLionel Sambuc #if BYTEORDER == 1234
720*1230fdc1SLionel Sambuc 1
721*1230fdc1SLionel Sambuc #else
722*1230fdc1SLionel Sambuc 0
723*1230fdc1SLionel Sambuc #endif
724*1230fdc1SLionel Sambuc },
725*1230fdc1SLionel Sambuc {
726*1230fdc1SLionel Sambuc #include "asciitab.h"
727*1230fdc1SLionel Sambuc #include "latin1tab.h"
728*1230fdc1SLionel Sambuc },
729*1230fdc1SLionel Sambuc STANDARD_VTABLE(little2_)
730*1230fdc1SLionel Sambuc };
731*1230fdc1SLionel Sambuc
732*1230fdc1SLionel Sambuc #endif
733*1230fdc1SLionel Sambuc
734*1230fdc1SLionel Sambuc static const struct normal_encoding little2_encoding = {
735*1230fdc1SLionel Sambuc { VTABLE, 2, 0,
736*1230fdc1SLionel Sambuc #if BYTEORDER == 1234
737*1230fdc1SLionel Sambuc 1
738*1230fdc1SLionel Sambuc #else
739*1230fdc1SLionel Sambuc 0
740*1230fdc1SLionel Sambuc #endif
741*1230fdc1SLionel Sambuc },
742*1230fdc1SLionel Sambuc {
743*1230fdc1SLionel Sambuc #define BT_COLON BT_NMSTRT
744*1230fdc1SLionel Sambuc #include "asciitab.h"
745*1230fdc1SLionel Sambuc #undef BT_COLON
746*1230fdc1SLionel Sambuc #include "latin1tab.h"
747*1230fdc1SLionel Sambuc },
748*1230fdc1SLionel Sambuc STANDARD_VTABLE(little2_)
749*1230fdc1SLionel Sambuc };
750*1230fdc1SLionel Sambuc
751*1230fdc1SLionel Sambuc #if BYTEORDER != 4321
752*1230fdc1SLionel Sambuc
753*1230fdc1SLionel Sambuc #ifdef XML_NS
754*1230fdc1SLionel Sambuc
755*1230fdc1SLionel Sambuc static const struct normal_encoding internal_little2_encoding_ns = {
756*1230fdc1SLionel Sambuc { VTABLE, 2, 0, 1 },
757*1230fdc1SLionel Sambuc {
758*1230fdc1SLionel Sambuc #include "iasciitab.h"
759*1230fdc1SLionel Sambuc #include "latin1tab.h"
760*1230fdc1SLionel Sambuc },
761*1230fdc1SLionel Sambuc STANDARD_VTABLE(little2_)
762*1230fdc1SLionel Sambuc };
763*1230fdc1SLionel Sambuc
764*1230fdc1SLionel Sambuc #endif
765*1230fdc1SLionel Sambuc
766*1230fdc1SLionel Sambuc static const struct normal_encoding internal_little2_encoding = {
767*1230fdc1SLionel Sambuc { VTABLE, 2, 0, 1 },
768*1230fdc1SLionel Sambuc {
769*1230fdc1SLionel Sambuc #define BT_COLON BT_NMSTRT
770*1230fdc1SLionel Sambuc #include "iasciitab.h"
771*1230fdc1SLionel Sambuc #undef BT_COLON
772*1230fdc1SLionel Sambuc #include "latin1tab.h"
773*1230fdc1SLionel Sambuc },
774*1230fdc1SLionel Sambuc STANDARD_VTABLE(little2_)
775*1230fdc1SLionel Sambuc };
776*1230fdc1SLionel Sambuc
777*1230fdc1SLionel Sambuc #endif
778*1230fdc1SLionel Sambuc
779*1230fdc1SLionel Sambuc
780*1230fdc1SLionel Sambuc #define BIG2_BYTE_TYPE(enc, p) \
781*1230fdc1SLionel Sambuc ((p)[0] == 0 \
782*1230fdc1SLionel Sambuc ? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \
783*1230fdc1SLionel Sambuc : unicode_byte_type((p)[0], (p)[1]))
784*1230fdc1SLionel Sambuc #define BIG2_BYTE_TO_ASCII(enc, p) ((p)[0] == 0 ? (p)[1] : -1)
785*1230fdc1SLionel Sambuc #define BIG2_CHAR_MATCHES(enc, p, c) ((p)[0] == 0 && (p)[1] == c)
786*1230fdc1SLionel Sambuc #define BIG2_IS_NAME_CHAR_MINBPC(enc, p) \
787*1230fdc1SLionel Sambuc UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1])
788*1230fdc1SLionel Sambuc #define BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) \
789*1230fdc1SLionel Sambuc UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[0], (unsigned char)p[1])
790*1230fdc1SLionel Sambuc
791*1230fdc1SLionel Sambuc #ifdef XML_MIN_SIZE
792*1230fdc1SLionel Sambuc
793*1230fdc1SLionel Sambuc static int PTRFASTCALL
big2_byteType(const ENCODING * enc,const char * p)794*1230fdc1SLionel Sambuc big2_byteType(const ENCODING *enc, const char *p)
795*1230fdc1SLionel Sambuc {
796*1230fdc1SLionel Sambuc return BIG2_BYTE_TYPE(enc, p);
797*1230fdc1SLionel Sambuc }
798*1230fdc1SLionel Sambuc
799*1230fdc1SLionel Sambuc static int PTRFASTCALL
big2_byteToAscii(const ENCODING * enc,const char * p)800*1230fdc1SLionel Sambuc big2_byteToAscii(const ENCODING *enc, const char *p)
801*1230fdc1SLionel Sambuc {
802*1230fdc1SLionel Sambuc return BIG2_BYTE_TO_ASCII(enc, p);
803*1230fdc1SLionel Sambuc }
804*1230fdc1SLionel Sambuc
805*1230fdc1SLionel Sambuc static int PTRCALL
big2_charMatches(const ENCODING * enc,const char * p,int c)806*1230fdc1SLionel Sambuc big2_charMatches(const ENCODING *enc, const char *p, int c)
807*1230fdc1SLionel Sambuc {
808*1230fdc1SLionel Sambuc return BIG2_CHAR_MATCHES(enc, p, c);
809*1230fdc1SLionel Sambuc }
810*1230fdc1SLionel Sambuc
811*1230fdc1SLionel Sambuc static int PTRFASTCALL
big2_isNameMin(const ENCODING * enc,const char * p)812*1230fdc1SLionel Sambuc big2_isNameMin(const ENCODING *enc, const char *p)
813*1230fdc1SLionel Sambuc {
814*1230fdc1SLionel Sambuc return BIG2_IS_NAME_CHAR_MINBPC(enc, p);
815*1230fdc1SLionel Sambuc }
816*1230fdc1SLionel Sambuc
817*1230fdc1SLionel Sambuc static int PTRFASTCALL
big2_isNmstrtMin(const ENCODING * enc,const char * p)818*1230fdc1SLionel Sambuc big2_isNmstrtMin(const ENCODING *enc, const char *p)
819*1230fdc1SLionel Sambuc {
820*1230fdc1SLionel Sambuc return BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p);
821*1230fdc1SLionel Sambuc }
822*1230fdc1SLionel Sambuc
823*1230fdc1SLionel Sambuc #undef VTABLE
824*1230fdc1SLionel Sambuc #define VTABLE VTABLE1, big2_toUtf8, big2_toUtf16
825*1230fdc1SLionel Sambuc
826*1230fdc1SLionel Sambuc #else /* not XML_MIN_SIZE */
827*1230fdc1SLionel Sambuc
828*1230fdc1SLionel Sambuc #undef PREFIX
829*1230fdc1SLionel Sambuc #define PREFIX(ident) big2_ ## ident
830*1230fdc1SLionel Sambuc #define MINBPC(enc) 2
831*1230fdc1SLionel Sambuc /* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */
832*1230fdc1SLionel Sambuc #define BYTE_TYPE(enc, p) BIG2_BYTE_TYPE(enc, p)
833*1230fdc1SLionel Sambuc #define BYTE_TO_ASCII(enc, p) BIG2_BYTE_TO_ASCII(enc, p)
834*1230fdc1SLionel Sambuc #define CHAR_MATCHES(enc, p, c) BIG2_CHAR_MATCHES(enc, p, c)
835*1230fdc1SLionel Sambuc #define IS_NAME_CHAR(enc, p, n) 0
836*1230fdc1SLionel Sambuc #define IS_NAME_CHAR_MINBPC(enc, p) BIG2_IS_NAME_CHAR_MINBPC(enc, p)
837*1230fdc1SLionel Sambuc #define IS_NMSTRT_CHAR(enc, p, n) (0)
838*1230fdc1SLionel Sambuc #define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p)
839*1230fdc1SLionel Sambuc
840*1230fdc1SLionel Sambuc #define XML_TOK_IMPL_C
841*1230fdc1SLionel Sambuc #include "xmltok_impl.c"
842*1230fdc1SLionel Sambuc #undef XML_TOK_IMPL_C
843*1230fdc1SLionel Sambuc
844*1230fdc1SLionel Sambuc #undef MINBPC
845*1230fdc1SLionel Sambuc #undef BYTE_TYPE
846*1230fdc1SLionel Sambuc #undef BYTE_TO_ASCII
847*1230fdc1SLionel Sambuc #undef CHAR_MATCHES
848*1230fdc1SLionel Sambuc #undef IS_NAME_CHAR
849*1230fdc1SLionel Sambuc #undef IS_NAME_CHAR_MINBPC
850*1230fdc1SLionel Sambuc #undef IS_NMSTRT_CHAR
851*1230fdc1SLionel Sambuc #undef IS_NMSTRT_CHAR_MINBPC
852*1230fdc1SLionel Sambuc #undef IS_INVALID_CHAR
853*1230fdc1SLionel Sambuc
854*1230fdc1SLionel Sambuc #endif /* not XML_MIN_SIZE */
855*1230fdc1SLionel Sambuc
856*1230fdc1SLionel Sambuc #ifdef XML_NS
857*1230fdc1SLionel Sambuc
858*1230fdc1SLionel Sambuc static const struct normal_encoding big2_encoding_ns = {
859*1230fdc1SLionel Sambuc { VTABLE, 2, 0,
860*1230fdc1SLionel Sambuc #if BYTEORDER == 4321
861*1230fdc1SLionel Sambuc 1
862*1230fdc1SLionel Sambuc #else
863*1230fdc1SLionel Sambuc 0
864*1230fdc1SLionel Sambuc #endif
865*1230fdc1SLionel Sambuc },
866*1230fdc1SLionel Sambuc {
867*1230fdc1SLionel Sambuc #include "asciitab.h"
868*1230fdc1SLionel Sambuc #include "latin1tab.h"
869*1230fdc1SLionel Sambuc },
870*1230fdc1SLionel Sambuc STANDARD_VTABLE(big2_)
871*1230fdc1SLionel Sambuc };
872*1230fdc1SLionel Sambuc
873*1230fdc1SLionel Sambuc #endif
874*1230fdc1SLionel Sambuc
875*1230fdc1SLionel Sambuc static const struct normal_encoding big2_encoding = {
876*1230fdc1SLionel Sambuc { VTABLE, 2, 0,
877*1230fdc1SLionel Sambuc #if BYTEORDER == 4321
878*1230fdc1SLionel Sambuc 1
879*1230fdc1SLionel Sambuc #else
880*1230fdc1SLionel Sambuc 0
881*1230fdc1SLionel Sambuc #endif
882*1230fdc1SLionel Sambuc },
883*1230fdc1SLionel Sambuc {
884*1230fdc1SLionel Sambuc #define BT_COLON BT_NMSTRT
885*1230fdc1SLionel Sambuc #include "asciitab.h"
886*1230fdc1SLionel Sambuc #undef BT_COLON
887*1230fdc1SLionel Sambuc #include "latin1tab.h"
888*1230fdc1SLionel Sambuc },
889*1230fdc1SLionel Sambuc STANDARD_VTABLE(big2_)
890*1230fdc1SLionel Sambuc };
891*1230fdc1SLionel Sambuc
892*1230fdc1SLionel Sambuc #if BYTEORDER != 1234
893*1230fdc1SLionel Sambuc
894*1230fdc1SLionel Sambuc #ifdef XML_NS
895*1230fdc1SLionel Sambuc
896*1230fdc1SLionel Sambuc static const struct normal_encoding internal_big2_encoding_ns = {
897*1230fdc1SLionel Sambuc { VTABLE, 2, 0, 1 },
898*1230fdc1SLionel Sambuc {
899*1230fdc1SLionel Sambuc #include "iasciitab.h"
900*1230fdc1SLionel Sambuc #include "latin1tab.h"
901*1230fdc1SLionel Sambuc },
902*1230fdc1SLionel Sambuc STANDARD_VTABLE(big2_)
903*1230fdc1SLionel Sambuc };
904*1230fdc1SLionel Sambuc
905*1230fdc1SLionel Sambuc #endif
906*1230fdc1SLionel Sambuc
907*1230fdc1SLionel Sambuc static const struct normal_encoding internal_big2_encoding = {
908*1230fdc1SLionel Sambuc { VTABLE, 2, 0, 1 },
909*1230fdc1SLionel Sambuc {
910*1230fdc1SLionel Sambuc #define BT_COLON BT_NMSTRT
911*1230fdc1SLionel Sambuc #include "iasciitab.h"
912*1230fdc1SLionel Sambuc #undef BT_COLON
913*1230fdc1SLionel Sambuc #include "latin1tab.h"
914*1230fdc1SLionel Sambuc },
915*1230fdc1SLionel Sambuc STANDARD_VTABLE(big2_)
916*1230fdc1SLionel Sambuc };
917*1230fdc1SLionel Sambuc
918*1230fdc1SLionel Sambuc #endif
919*1230fdc1SLionel Sambuc
920*1230fdc1SLionel Sambuc #undef PREFIX
921*1230fdc1SLionel Sambuc
922*1230fdc1SLionel Sambuc static int FASTCALL
streqci(const char * s1,const char * s2)923*1230fdc1SLionel Sambuc streqci(const char *s1, const char *s2)
924*1230fdc1SLionel Sambuc {
925*1230fdc1SLionel Sambuc for (;;) {
926*1230fdc1SLionel Sambuc char c1 = *s1++;
927*1230fdc1SLionel Sambuc char c2 = *s2++;
928*1230fdc1SLionel Sambuc if (ASCII_a <= c1 && c1 <= ASCII_z)
929*1230fdc1SLionel Sambuc c1 += ASCII_A - ASCII_a;
930*1230fdc1SLionel Sambuc if (ASCII_a <= c2 && c2 <= ASCII_z)
931*1230fdc1SLionel Sambuc c2 += ASCII_A - ASCII_a;
932*1230fdc1SLionel Sambuc if (c1 != c2)
933*1230fdc1SLionel Sambuc return 0;
934*1230fdc1SLionel Sambuc if (!c1)
935*1230fdc1SLionel Sambuc break;
936*1230fdc1SLionel Sambuc }
937*1230fdc1SLionel Sambuc return 1;
938*1230fdc1SLionel Sambuc }
939*1230fdc1SLionel Sambuc
940*1230fdc1SLionel Sambuc static void PTRCALL
initUpdatePosition(const ENCODING * enc,const char * ptr,const char * end,POSITION * pos)941*1230fdc1SLionel Sambuc initUpdatePosition(const ENCODING *enc, const char *ptr,
942*1230fdc1SLionel Sambuc const char *end, POSITION *pos)
943*1230fdc1SLionel Sambuc {
944*1230fdc1SLionel Sambuc normal_updatePosition(&utf8_encoding.enc, ptr, end, pos);
945*1230fdc1SLionel Sambuc }
946*1230fdc1SLionel Sambuc
947*1230fdc1SLionel Sambuc static int
toAscii(const ENCODING * enc,const char * ptr,const char * end)948*1230fdc1SLionel Sambuc toAscii(const ENCODING *enc, const char *ptr, const char *end)
949*1230fdc1SLionel Sambuc {
950*1230fdc1SLionel Sambuc char buf[1];
951*1230fdc1SLionel Sambuc char *p = buf;
952*1230fdc1SLionel Sambuc XmlUtf8Convert(enc, &ptr, end, &p, p + 1);
953*1230fdc1SLionel Sambuc if (p == buf)
954*1230fdc1SLionel Sambuc return -1;
955*1230fdc1SLionel Sambuc else
956*1230fdc1SLionel Sambuc return buf[0];
957*1230fdc1SLionel Sambuc }
958*1230fdc1SLionel Sambuc
959*1230fdc1SLionel Sambuc static int FASTCALL
isSpace(int c)960*1230fdc1SLionel Sambuc isSpace(int c)
961*1230fdc1SLionel Sambuc {
962*1230fdc1SLionel Sambuc switch (c) {
963*1230fdc1SLionel Sambuc case 0x20:
964*1230fdc1SLionel Sambuc case 0xD:
965*1230fdc1SLionel Sambuc case 0xA:
966*1230fdc1SLionel Sambuc case 0x9:
967*1230fdc1SLionel Sambuc return 1;
968*1230fdc1SLionel Sambuc }
969*1230fdc1SLionel Sambuc return 0;
970*1230fdc1SLionel Sambuc }
971*1230fdc1SLionel Sambuc
972*1230fdc1SLionel Sambuc /* Return 1 if there's just optional white space or there's an S
973*1230fdc1SLionel Sambuc followed by name=val.
974*1230fdc1SLionel Sambuc */
975*1230fdc1SLionel Sambuc static int
parsePseudoAttribute(const ENCODING * enc,const char * ptr,const char * end,const char ** namePtr,const char ** nameEndPtr,const char ** valPtr,const char ** nextTokPtr)976*1230fdc1SLionel Sambuc parsePseudoAttribute(const ENCODING *enc,
977*1230fdc1SLionel Sambuc const char *ptr,
978*1230fdc1SLionel Sambuc const char *end,
979*1230fdc1SLionel Sambuc const char **namePtr,
980*1230fdc1SLionel Sambuc const char **nameEndPtr,
981*1230fdc1SLionel Sambuc const char **valPtr,
982*1230fdc1SLionel Sambuc const char **nextTokPtr)
983*1230fdc1SLionel Sambuc {
984*1230fdc1SLionel Sambuc int c;
985*1230fdc1SLionel Sambuc char open;
986*1230fdc1SLionel Sambuc if (ptr == end) {
987*1230fdc1SLionel Sambuc *namePtr = NULL;
988*1230fdc1SLionel Sambuc return 1;
989*1230fdc1SLionel Sambuc }
990*1230fdc1SLionel Sambuc if (!isSpace(toAscii(enc, ptr, end))) {
991*1230fdc1SLionel Sambuc *nextTokPtr = ptr;
992*1230fdc1SLionel Sambuc return 0;
993*1230fdc1SLionel Sambuc }
994*1230fdc1SLionel Sambuc do {
995*1230fdc1SLionel Sambuc ptr += enc->minBytesPerChar;
996*1230fdc1SLionel Sambuc } while (isSpace(toAscii(enc, ptr, end)));
997*1230fdc1SLionel Sambuc if (ptr == end) {
998*1230fdc1SLionel Sambuc *namePtr = NULL;
999*1230fdc1SLionel Sambuc return 1;
1000*1230fdc1SLionel Sambuc }
1001*1230fdc1SLionel Sambuc *namePtr = ptr;
1002*1230fdc1SLionel Sambuc for (;;) {
1003*1230fdc1SLionel Sambuc c = toAscii(enc, ptr, end);
1004*1230fdc1SLionel Sambuc if (c == -1) {
1005*1230fdc1SLionel Sambuc *nextTokPtr = ptr;
1006*1230fdc1SLionel Sambuc return 0;
1007*1230fdc1SLionel Sambuc }
1008*1230fdc1SLionel Sambuc if (c == ASCII_EQUALS) {
1009*1230fdc1SLionel Sambuc *nameEndPtr = ptr;
1010*1230fdc1SLionel Sambuc break;
1011*1230fdc1SLionel Sambuc }
1012*1230fdc1SLionel Sambuc if (isSpace(c)) {
1013*1230fdc1SLionel Sambuc *nameEndPtr = ptr;
1014*1230fdc1SLionel Sambuc do {
1015*1230fdc1SLionel Sambuc ptr += enc->minBytesPerChar;
1016*1230fdc1SLionel Sambuc } while (isSpace(c = toAscii(enc, ptr, end)));
1017*1230fdc1SLionel Sambuc if (c != ASCII_EQUALS) {
1018*1230fdc1SLionel Sambuc *nextTokPtr = ptr;
1019*1230fdc1SLionel Sambuc return 0;
1020*1230fdc1SLionel Sambuc }
1021*1230fdc1SLionel Sambuc break;
1022*1230fdc1SLionel Sambuc }
1023*1230fdc1SLionel Sambuc ptr += enc->minBytesPerChar;
1024*1230fdc1SLionel Sambuc }
1025*1230fdc1SLionel Sambuc if (ptr == *namePtr) {
1026*1230fdc1SLionel Sambuc *nextTokPtr = ptr;
1027*1230fdc1SLionel Sambuc return 0;
1028*1230fdc1SLionel Sambuc }
1029*1230fdc1SLionel Sambuc ptr += enc->minBytesPerChar;
1030*1230fdc1SLionel Sambuc c = toAscii(enc, ptr, end);
1031*1230fdc1SLionel Sambuc while (isSpace(c)) {
1032*1230fdc1SLionel Sambuc ptr += enc->minBytesPerChar;
1033*1230fdc1SLionel Sambuc c = toAscii(enc, ptr, end);
1034*1230fdc1SLionel Sambuc }
1035*1230fdc1SLionel Sambuc if (c != ASCII_QUOT && c != ASCII_APOS) {
1036*1230fdc1SLionel Sambuc *nextTokPtr = ptr;
1037*1230fdc1SLionel Sambuc return 0;
1038*1230fdc1SLionel Sambuc }
1039*1230fdc1SLionel Sambuc open = (char)c;
1040*1230fdc1SLionel Sambuc ptr += enc->minBytesPerChar;
1041*1230fdc1SLionel Sambuc *valPtr = ptr;
1042*1230fdc1SLionel Sambuc for (;; ptr += enc->minBytesPerChar) {
1043*1230fdc1SLionel Sambuc c = toAscii(enc, ptr, end);
1044*1230fdc1SLionel Sambuc if (c == open)
1045*1230fdc1SLionel Sambuc break;
1046*1230fdc1SLionel Sambuc if (!(ASCII_a <= c && c <= ASCII_z)
1047*1230fdc1SLionel Sambuc && !(ASCII_A <= c && c <= ASCII_Z)
1048*1230fdc1SLionel Sambuc && !(ASCII_0 <= c && c <= ASCII_9)
1049*1230fdc1SLionel Sambuc && c != ASCII_PERIOD
1050*1230fdc1SLionel Sambuc && c != ASCII_MINUS
1051*1230fdc1SLionel Sambuc && c != ASCII_UNDERSCORE) {
1052*1230fdc1SLionel Sambuc *nextTokPtr = ptr;
1053*1230fdc1SLionel Sambuc return 0;
1054*1230fdc1SLionel Sambuc }
1055*1230fdc1SLionel Sambuc }
1056*1230fdc1SLionel Sambuc *nextTokPtr = ptr + enc->minBytesPerChar;
1057*1230fdc1SLionel Sambuc return 1;
1058*1230fdc1SLionel Sambuc }
1059*1230fdc1SLionel Sambuc
1060*1230fdc1SLionel Sambuc static const char KW_version[] = {
1061*1230fdc1SLionel Sambuc ASCII_v, ASCII_e, ASCII_r, ASCII_s, ASCII_i, ASCII_o, ASCII_n, '\0'
1062*1230fdc1SLionel Sambuc };
1063*1230fdc1SLionel Sambuc
1064*1230fdc1SLionel Sambuc static const char KW_encoding[] = {
1065*1230fdc1SLionel Sambuc ASCII_e, ASCII_n, ASCII_c, ASCII_o, ASCII_d, ASCII_i, ASCII_n, ASCII_g, '\0'
1066*1230fdc1SLionel Sambuc };
1067*1230fdc1SLionel Sambuc
1068*1230fdc1SLionel Sambuc static const char KW_standalone[] = {
1069*1230fdc1SLionel Sambuc ASCII_s, ASCII_t, ASCII_a, ASCII_n, ASCII_d, ASCII_a, ASCII_l, ASCII_o,
1070*1230fdc1SLionel Sambuc ASCII_n, ASCII_e, '\0'
1071*1230fdc1SLionel Sambuc };
1072*1230fdc1SLionel Sambuc
1073*1230fdc1SLionel Sambuc static const char KW_yes[] = {
1074*1230fdc1SLionel Sambuc ASCII_y, ASCII_e, ASCII_s, '\0'
1075*1230fdc1SLionel Sambuc };
1076*1230fdc1SLionel Sambuc
1077*1230fdc1SLionel Sambuc static const char KW_no[] = {
1078*1230fdc1SLionel Sambuc ASCII_n, ASCII_o, '\0'
1079*1230fdc1SLionel Sambuc };
1080*1230fdc1SLionel Sambuc
1081*1230fdc1SLionel Sambuc static int
doParseXmlDecl(const ENCODING * (* encodingFinder)(const ENCODING *,const char *,const char *),int isGeneralTextEntity,const ENCODING * enc,const char * ptr,const char * end,const char ** badPtr,const char ** versionPtr,const char ** versionEndPtr,const char ** encodingName,const ENCODING ** encoding,int * standalone)1082*1230fdc1SLionel Sambuc doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
1083*1230fdc1SLionel Sambuc const char *,
1084*1230fdc1SLionel Sambuc const char *),
1085*1230fdc1SLionel Sambuc int isGeneralTextEntity,
1086*1230fdc1SLionel Sambuc const ENCODING *enc,
1087*1230fdc1SLionel Sambuc const char *ptr,
1088*1230fdc1SLionel Sambuc const char *end,
1089*1230fdc1SLionel Sambuc const char **badPtr,
1090*1230fdc1SLionel Sambuc const char **versionPtr,
1091*1230fdc1SLionel Sambuc const char **versionEndPtr,
1092*1230fdc1SLionel Sambuc const char **encodingName,
1093*1230fdc1SLionel Sambuc const ENCODING **encoding,
1094*1230fdc1SLionel Sambuc int *standalone)
1095*1230fdc1SLionel Sambuc {
1096*1230fdc1SLionel Sambuc const char *val = NULL;
1097*1230fdc1SLionel Sambuc const char *name = NULL;
1098*1230fdc1SLionel Sambuc const char *nameEnd = NULL;
1099*1230fdc1SLionel Sambuc ptr += 5 * enc->minBytesPerChar;
1100*1230fdc1SLionel Sambuc end -= 2 * enc->minBytesPerChar;
1101*1230fdc1SLionel Sambuc if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)
1102*1230fdc1SLionel Sambuc || !name) {
1103*1230fdc1SLionel Sambuc *badPtr = ptr;
1104*1230fdc1SLionel Sambuc return 0;
1105*1230fdc1SLionel Sambuc }
1106*1230fdc1SLionel Sambuc if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_version)) {
1107*1230fdc1SLionel Sambuc if (!isGeneralTextEntity) {
1108*1230fdc1SLionel Sambuc *badPtr = name;
1109*1230fdc1SLionel Sambuc return 0;
1110*1230fdc1SLionel Sambuc }
1111*1230fdc1SLionel Sambuc }
1112*1230fdc1SLionel Sambuc else {
1113*1230fdc1SLionel Sambuc if (versionPtr)
1114*1230fdc1SLionel Sambuc *versionPtr = val;
1115*1230fdc1SLionel Sambuc if (versionEndPtr)
1116*1230fdc1SLionel Sambuc *versionEndPtr = ptr;
1117*1230fdc1SLionel Sambuc if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) {
1118*1230fdc1SLionel Sambuc *badPtr = ptr;
1119*1230fdc1SLionel Sambuc return 0;
1120*1230fdc1SLionel Sambuc }
1121*1230fdc1SLionel Sambuc if (!name) {
1122*1230fdc1SLionel Sambuc if (isGeneralTextEntity) {
1123*1230fdc1SLionel Sambuc /* a TextDecl must have an EncodingDecl */
1124*1230fdc1SLionel Sambuc *badPtr = ptr;
1125*1230fdc1SLionel Sambuc return 0;
1126*1230fdc1SLionel Sambuc }
1127*1230fdc1SLionel Sambuc return 1;
1128*1230fdc1SLionel Sambuc }
1129*1230fdc1SLionel Sambuc }
1130*1230fdc1SLionel Sambuc if (XmlNameMatchesAscii(enc, name, nameEnd, KW_encoding)) {
1131*1230fdc1SLionel Sambuc int c = toAscii(enc, val, end);
1132*1230fdc1SLionel Sambuc if (!(ASCII_a <= c && c <= ASCII_z) && !(ASCII_A <= c && c <= ASCII_Z)) {
1133*1230fdc1SLionel Sambuc *badPtr = val;
1134*1230fdc1SLionel Sambuc return 0;
1135*1230fdc1SLionel Sambuc }
1136*1230fdc1SLionel Sambuc if (encodingName)
1137*1230fdc1SLionel Sambuc *encodingName = val;
1138*1230fdc1SLionel Sambuc if (encoding)
1139*1230fdc1SLionel Sambuc *encoding = encodingFinder(enc, val, ptr - enc->minBytesPerChar);
1140*1230fdc1SLionel Sambuc if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) {
1141*1230fdc1SLionel Sambuc *badPtr = ptr;
1142*1230fdc1SLionel Sambuc return 0;
1143*1230fdc1SLionel Sambuc }
1144*1230fdc1SLionel Sambuc if (!name)
1145*1230fdc1SLionel Sambuc return 1;
1146*1230fdc1SLionel Sambuc }
1147*1230fdc1SLionel Sambuc if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_standalone)
1148*1230fdc1SLionel Sambuc || isGeneralTextEntity) {
1149*1230fdc1SLionel Sambuc *badPtr = name;
1150*1230fdc1SLionel Sambuc return 0;
1151*1230fdc1SLionel Sambuc }
1152*1230fdc1SLionel Sambuc if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_yes)) {
1153*1230fdc1SLionel Sambuc if (standalone)
1154*1230fdc1SLionel Sambuc *standalone = 1;
1155*1230fdc1SLionel Sambuc }
1156*1230fdc1SLionel Sambuc else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_no)) {
1157*1230fdc1SLionel Sambuc if (standalone)
1158*1230fdc1SLionel Sambuc *standalone = 0;
1159*1230fdc1SLionel Sambuc }
1160*1230fdc1SLionel Sambuc else {
1161*1230fdc1SLionel Sambuc *badPtr = val;
1162*1230fdc1SLionel Sambuc return 0;
1163*1230fdc1SLionel Sambuc }
1164*1230fdc1SLionel Sambuc while (isSpace(toAscii(enc, ptr, end)))
1165*1230fdc1SLionel Sambuc ptr += enc->minBytesPerChar;
1166*1230fdc1SLionel Sambuc if (ptr != end) {
1167*1230fdc1SLionel Sambuc *badPtr = ptr;
1168*1230fdc1SLionel Sambuc return 0;
1169*1230fdc1SLionel Sambuc }
1170*1230fdc1SLionel Sambuc return 1;
1171*1230fdc1SLionel Sambuc }
1172*1230fdc1SLionel Sambuc
1173*1230fdc1SLionel Sambuc static int FASTCALL
checkCharRefNumber(int result)1174*1230fdc1SLionel Sambuc checkCharRefNumber(int result)
1175*1230fdc1SLionel Sambuc {
1176*1230fdc1SLionel Sambuc switch (result >> 8) {
1177*1230fdc1SLionel Sambuc case 0xD8: case 0xD9: case 0xDA: case 0xDB:
1178*1230fdc1SLionel Sambuc case 0xDC: case 0xDD: case 0xDE: case 0xDF:
1179*1230fdc1SLionel Sambuc return -1;
1180*1230fdc1SLionel Sambuc case 0:
1181*1230fdc1SLionel Sambuc if (latin1_encoding.type[result] == BT_NONXML)
1182*1230fdc1SLionel Sambuc return -1;
1183*1230fdc1SLionel Sambuc break;
1184*1230fdc1SLionel Sambuc case 0xFF:
1185*1230fdc1SLionel Sambuc if (result == 0xFFFE || result == 0xFFFF)
1186*1230fdc1SLionel Sambuc return -1;
1187*1230fdc1SLionel Sambuc break;
1188*1230fdc1SLionel Sambuc }
1189*1230fdc1SLionel Sambuc return result;
1190*1230fdc1SLionel Sambuc }
1191*1230fdc1SLionel Sambuc
1192*1230fdc1SLionel Sambuc int FASTCALL
XmlUtf8Encode(int c,char * buf)1193*1230fdc1SLionel Sambuc XmlUtf8Encode(int c, char *buf)
1194*1230fdc1SLionel Sambuc {
1195*1230fdc1SLionel Sambuc enum {
1196*1230fdc1SLionel Sambuc /* minN is minimum legal resulting value for N byte sequence */
1197*1230fdc1SLionel Sambuc min2 = 0x80,
1198*1230fdc1SLionel Sambuc min3 = 0x800,
1199*1230fdc1SLionel Sambuc min4 = 0x10000
1200*1230fdc1SLionel Sambuc };
1201*1230fdc1SLionel Sambuc
1202*1230fdc1SLionel Sambuc if (c < 0)
1203*1230fdc1SLionel Sambuc return 0;
1204*1230fdc1SLionel Sambuc if (c < min2) {
1205*1230fdc1SLionel Sambuc buf[0] = (char)(c | UTF8_cval1);
1206*1230fdc1SLionel Sambuc return 1;
1207*1230fdc1SLionel Sambuc }
1208*1230fdc1SLionel Sambuc if (c < min3) {
1209*1230fdc1SLionel Sambuc buf[0] = (char)((c >> 6) | UTF8_cval2);
1210*1230fdc1SLionel Sambuc buf[1] = (char)((c & 0x3f) | 0x80);
1211*1230fdc1SLionel Sambuc return 2;
1212*1230fdc1SLionel Sambuc }
1213*1230fdc1SLionel Sambuc if (c < min4) {
1214*1230fdc1SLionel Sambuc buf[0] = (char)((c >> 12) | UTF8_cval3);
1215*1230fdc1SLionel Sambuc buf[1] = (char)(((c >> 6) & 0x3f) | 0x80);
1216*1230fdc1SLionel Sambuc buf[2] = (char)((c & 0x3f) | 0x80);
1217*1230fdc1SLionel Sambuc return 3;
1218*1230fdc1SLionel Sambuc }
1219*1230fdc1SLionel Sambuc if (c < 0x110000) {
1220*1230fdc1SLionel Sambuc buf[0] = (char)((c >> 18) | UTF8_cval4);
1221*1230fdc1SLionel Sambuc buf[1] = (char)(((c >> 12) & 0x3f) | 0x80);
1222*1230fdc1SLionel Sambuc buf[2] = (char)(((c >> 6) & 0x3f) | 0x80);
1223*1230fdc1SLionel Sambuc buf[3] = (char)((c & 0x3f) | 0x80);
1224*1230fdc1SLionel Sambuc return 4;
1225*1230fdc1SLionel Sambuc }
1226*1230fdc1SLionel Sambuc return 0;
1227*1230fdc1SLionel Sambuc }
1228*1230fdc1SLionel Sambuc
1229*1230fdc1SLionel Sambuc int FASTCALL
XmlUtf16Encode(int charNum,unsigned short * buf)1230*1230fdc1SLionel Sambuc XmlUtf16Encode(int charNum, unsigned short *buf)
1231*1230fdc1SLionel Sambuc {
1232*1230fdc1SLionel Sambuc if (charNum < 0)
1233*1230fdc1SLionel Sambuc return 0;
1234*1230fdc1SLionel Sambuc if (charNum < 0x10000) {
1235*1230fdc1SLionel Sambuc buf[0] = (unsigned short)charNum;
1236*1230fdc1SLionel Sambuc return 1;
1237*1230fdc1SLionel Sambuc }
1238*1230fdc1SLionel Sambuc if (charNum < 0x110000) {
1239*1230fdc1SLionel Sambuc charNum -= 0x10000;
1240*1230fdc1SLionel Sambuc buf[0] = (unsigned short)((charNum >> 10) + 0xD800);
1241*1230fdc1SLionel Sambuc buf[1] = (unsigned short)((charNum & 0x3FF) + 0xDC00);
1242*1230fdc1SLionel Sambuc return 2;
1243*1230fdc1SLionel Sambuc }
1244*1230fdc1SLionel Sambuc return 0;
1245*1230fdc1SLionel Sambuc }
1246*1230fdc1SLionel Sambuc
1247*1230fdc1SLionel Sambuc struct unknown_encoding {
1248*1230fdc1SLionel Sambuc struct normal_encoding normal;
1249*1230fdc1SLionel Sambuc CONVERTER convert;
1250*1230fdc1SLionel Sambuc void *userData;
1251*1230fdc1SLionel Sambuc unsigned short utf16[256];
1252*1230fdc1SLionel Sambuc char utf8[256][4];
1253*1230fdc1SLionel Sambuc };
1254*1230fdc1SLionel Sambuc
1255*1230fdc1SLionel Sambuc #define AS_UNKNOWN_ENCODING(enc) ((const struct unknown_encoding *) (enc))
1256*1230fdc1SLionel Sambuc
1257*1230fdc1SLionel Sambuc int
XmlSizeOfUnknownEncoding(void)1258*1230fdc1SLionel Sambuc XmlSizeOfUnknownEncoding(void)
1259*1230fdc1SLionel Sambuc {
1260*1230fdc1SLionel Sambuc return sizeof(struct unknown_encoding);
1261*1230fdc1SLionel Sambuc }
1262*1230fdc1SLionel Sambuc
1263*1230fdc1SLionel Sambuc static int PTRFASTCALL
unknown_isName(const ENCODING * enc,const char * p)1264*1230fdc1SLionel Sambuc unknown_isName(const ENCODING *enc, const char *p)
1265*1230fdc1SLionel Sambuc {
1266*1230fdc1SLionel Sambuc const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc);
1267*1230fdc1SLionel Sambuc int c = uenc->convert(uenc->userData, p);
1268*1230fdc1SLionel Sambuc if (c & ~0xFFFF)
1269*1230fdc1SLionel Sambuc return 0;
1270*1230fdc1SLionel Sambuc return UCS2_GET_NAMING(namePages, c >> 8, c & 0xFF);
1271*1230fdc1SLionel Sambuc }
1272*1230fdc1SLionel Sambuc
1273*1230fdc1SLionel Sambuc static int PTRFASTCALL
unknown_isNmstrt(const ENCODING * enc,const char * p)1274*1230fdc1SLionel Sambuc unknown_isNmstrt(const ENCODING *enc, const char *p)
1275*1230fdc1SLionel Sambuc {
1276*1230fdc1SLionel Sambuc const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc);
1277*1230fdc1SLionel Sambuc int c = uenc->convert(uenc->userData, p);
1278*1230fdc1SLionel Sambuc if (c & ~0xFFFF)
1279*1230fdc1SLionel Sambuc return 0;
1280*1230fdc1SLionel Sambuc return UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xFF);
1281*1230fdc1SLionel Sambuc }
1282*1230fdc1SLionel Sambuc
1283*1230fdc1SLionel Sambuc static int PTRFASTCALL
unknown_isInvalid(const ENCODING * enc,const char * p)1284*1230fdc1SLionel Sambuc unknown_isInvalid(const ENCODING *enc, const char *p)
1285*1230fdc1SLionel Sambuc {
1286*1230fdc1SLionel Sambuc const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc);
1287*1230fdc1SLionel Sambuc int c = uenc->convert(uenc->userData, p);
1288*1230fdc1SLionel Sambuc return (c & ~0xFFFF) || checkCharRefNumber(c) < 0;
1289*1230fdc1SLionel Sambuc }
1290*1230fdc1SLionel Sambuc
1291*1230fdc1SLionel Sambuc static void PTRCALL
unknown_toUtf8(const ENCODING * enc,const char ** fromP,const char * fromLim,char ** toP,const char * toLim)1292*1230fdc1SLionel Sambuc unknown_toUtf8(const ENCODING *enc,
1293*1230fdc1SLionel Sambuc const char **fromP, const char *fromLim,
1294*1230fdc1SLionel Sambuc char **toP, const char *toLim)
1295*1230fdc1SLionel Sambuc {
1296*1230fdc1SLionel Sambuc const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc);
1297*1230fdc1SLionel Sambuc char buf[XML_UTF8_ENCODE_MAX];
1298*1230fdc1SLionel Sambuc for (;;) {
1299*1230fdc1SLionel Sambuc const char *utf8;
1300*1230fdc1SLionel Sambuc int n;
1301*1230fdc1SLionel Sambuc if (*fromP == fromLim)
1302*1230fdc1SLionel Sambuc break;
1303*1230fdc1SLionel Sambuc utf8 = uenc->utf8[(unsigned char)**fromP];
1304*1230fdc1SLionel Sambuc n = *utf8++;
1305*1230fdc1SLionel Sambuc if (n == 0) {
1306*1230fdc1SLionel Sambuc int c = uenc->convert(uenc->userData, *fromP);
1307*1230fdc1SLionel Sambuc n = XmlUtf8Encode(c, buf);
1308*1230fdc1SLionel Sambuc if (n > toLim - *toP)
1309*1230fdc1SLionel Sambuc break;
1310*1230fdc1SLionel Sambuc utf8 = buf;
1311*1230fdc1SLionel Sambuc *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP]
1312*1230fdc1SLionel Sambuc - (BT_LEAD2 - 2));
1313*1230fdc1SLionel Sambuc }
1314*1230fdc1SLionel Sambuc else {
1315*1230fdc1SLionel Sambuc if (n > toLim - *toP)
1316*1230fdc1SLionel Sambuc break;
1317*1230fdc1SLionel Sambuc (*fromP)++;
1318*1230fdc1SLionel Sambuc }
1319*1230fdc1SLionel Sambuc do {
1320*1230fdc1SLionel Sambuc *(*toP)++ = *utf8++;
1321*1230fdc1SLionel Sambuc } while (--n != 0);
1322*1230fdc1SLionel Sambuc }
1323*1230fdc1SLionel Sambuc }
1324*1230fdc1SLionel Sambuc
1325*1230fdc1SLionel Sambuc static void PTRCALL
unknown_toUtf16(const ENCODING * enc,const char ** fromP,const char * fromLim,unsigned short ** toP,const unsigned short * toLim)1326*1230fdc1SLionel Sambuc unknown_toUtf16(const ENCODING *enc,
1327*1230fdc1SLionel Sambuc const char **fromP, const char *fromLim,
1328*1230fdc1SLionel Sambuc unsigned short **toP, const unsigned short *toLim)
1329*1230fdc1SLionel Sambuc {
1330*1230fdc1SLionel Sambuc const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc);
1331*1230fdc1SLionel Sambuc while (*fromP != fromLim && *toP != toLim) {
1332*1230fdc1SLionel Sambuc unsigned short c = uenc->utf16[(unsigned char)**fromP];
1333*1230fdc1SLionel Sambuc if (c == 0) {
1334*1230fdc1SLionel Sambuc c = (unsigned short)
1335*1230fdc1SLionel Sambuc uenc->convert(uenc->userData, *fromP);
1336*1230fdc1SLionel Sambuc *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP]
1337*1230fdc1SLionel Sambuc - (BT_LEAD2 - 2));
1338*1230fdc1SLionel Sambuc }
1339*1230fdc1SLionel Sambuc else
1340*1230fdc1SLionel Sambuc (*fromP)++;
1341*1230fdc1SLionel Sambuc *(*toP)++ = c;
1342*1230fdc1SLionel Sambuc }
1343*1230fdc1SLionel Sambuc }
1344*1230fdc1SLionel Sambuc
1345*1230fdc1SLionel Sambuc ENCODING *
XmlInitUnknownEncoding(void * mem,int * table,CONVERTER convert,void * userData)1346*1230fdc1SLionel Sambuc XmlInitUnknownEncoding(void *mem,
1347*1230fdc1SLionel Sambuc int *table,
1348*1230fdc1SLionel Sambuc CONVERTER convert,
1349*1230fdc1SLionel Sambuc void *userData)
1350*1230fdc1SLionel Sambuc {
1351*1230fdc1SLionel Sambuc int i;
1352*1230fdc1SLionel Sambuc struct unknown_encoding *e = (struct unknown_encoding *)mem;
1353*1230fdc1SLionel Sambuc for (i = 0; i < (int)sizeof(struct normal_encoding); i++)
1354*1230fdc1SLionel Sambuc ((char *)mem)[i] = ((char *)&latin1_encoding)[i];
1355*1230fdc1SLionel Sambuc for (i = 0; i < 128; i++)
1356*1230fdc1SLionel Sambuc if (latin1_encoding.type[i] != BT_OTHER
1357*1230fdc1SLionel Sambuc && latin1_encoding.type[i] != BT_NONXML
1358*1230fdc1SLionel Sambuc && table[i] != i)
1359*1230fdc1SLionel Sambuc return 0;
1360*1230fdc1SLionel Sambuc for (i = 0; i < 256; i++) {
1361*1230fdc1SLionel Sambuc int c = table[i];
1362*1230fdc1SLionel Sambuc if (c == -1) {
1363*1230fdc1SLionel Sambuc e->normal.type[i] = BT_MALFORM;
1364*1230fdc1SLionel Sambuc /* This shouldn't really get used. */
1365*1230fdc1SLionel Sambuc e->utf16[i] = 0xFFFF;
1366*1230fdc1SLionel Sambuc e->utf8[i][0] = 1;
1367*1230fdc1SLionel Sambuc e->utf8[i][1] = 0;
1368*1230fdc1SLionel Sambuc }
1369*1230fdc1SLionel Sambuc else if (c < 0) {
1370*1230fdc1SLionel Sambuc if (c < -4)
1371*1230fdc1SLionel Sambuc return 0;
1372*1230fdc1SLionel Sambuc e->normal.type[i] = (unsigned char)(BT_LEAD2 - (c + 2));
1373*1230fdc1SLionel Sambuc e->utf8[i][0] = 0;
1374*1230fdc1SLionel Sambuc e->utf16[i] = 0;
1375*1230fdc1SLionel Sambuc }
1376*1230fdc1SLionel Sambuc else if (c < 0x80) {
1377*1230fdc1SLionel Sambuc if (latin1_encoding.type[c] != BT_OTHER
1378*1230fdc1SLionel Sambuc && latin1_encoding.type[c] != BT_NONXML
1379*1230fdc1SLionel Sambuc && c != i)
1380*1230fdc1SLionel Sambuc return 0;
1381*1230fdc1SLionel Sambuc e->normal.type[i] = latin1_encoding.type[c];
1382*1230fdc1SLionel Sambuc e->utf8[i][0] = 1;
1383*1230fdc1SLionel Sambuc e->utf8[i][1] = (char)c;
1384*1230fdc1SLionel Sambuc e->utf16[i] = (unsigned short)(c == 0 ? 0xFFFF : c);
1385*1230fdc1SLionel Sambuc }
1386*1230fdc1SLionel Sambuc else if (checkCharRefNumber(c) < 0) {
1387*1230fdc1SLionel Sambuc e->normal.type[i] = BT_NONXML;
1388*1230fdc1SLionel Sambuc /* This shouldn't really get used. */
1389*1230fdc1SLionel Sambuc e->utf16[i] = 0xFFFF;
1390*1230fdc1SLionel Sambuc e->utf8[i][0] = 1;
1391*1230fdc1SLionel Sambuc e->utf8[i][1] = 0;
1392*1230fdc1SLionel Sambuc }
1393*1230fdc1SLionel Sambuc else {
1394*1230fdc1SLionel Sambuc if (c > 0xFFFF)
1395*1230fdc1SLionel Sambuc return 0;
1396*1230fdc1SLionel Sambuc if (UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xff))
1397*1230fdc1SLionel Sambuc e->normal.type[i] = BT_NMSTRT;
1398*1230fdc1SLionel Sambuc else if (UCS2_GET_NAMING(namePages, c >> 8, c & 0xff))
1399*1230fdc1SLionel Sambuc e->normal.type[i] = BT_NAME;
1400*1230fdc1SLionel Sambuc else
1401*1230fdc1SLionel Sambuc e->normal.type[i] = BT_OTHER;
1402*1230fdc1SLionel Sambuc e->utf8[i][0] = (char)XmlUtf8Encode(c, e->utf8[i] + 1);
1403*1230fdc1SLionel Sambuc e->utf16[i] = (unsigned short)c;
1404*1230fdc1SLionel Sambuc }
1405*1230fdc1SLionel Sambuc }
1406*1230fdc1SLionel Sambuc e->userData = userData;
1407*1230fdc1SLionel Sambuc e->convert = convert;
1408*1230fdc1SLionel Sambuc if (convert) {
1409*1230fdc1SLionel Sambuc e->normal.isName2 = unknown_isName;
1410*1230fdc1SLionel Sambuc e->normal.isName3 = unknown_isName;
1411*1230fdc1SLionel Sambuc e->normal.isName4 = unknown_isName;
1412*1230fdc1SLionel Sambuc e->normal.isNmstrt2 = unknown_isNmstrt;
1413*1230fdc1SLionel Sambuc e->normal.isNmstrt3 = unknown_isNmstrt;
1414*1230fdc1SLionel Sambuc e->normal.isNmstrt4 = unknown_isNmstrt;
1415*1230fdc1SLionel Sambuc e->normal.isInvalid2 = unknown_isInvalid;
1416*1230fdc1SLionel Sambuc e->normal.isInvalid3 = unknown_isInvalid;
1417*1230fdc1SLionel Sambuc e->normal.isInvalid4 = unknown_isInvalid;
1418*1230fdc1SLionel Sambuc }
1419*1230fdc1SLionel Sambuc e->normal.enc.utf8Convert = unknown_toUtf8;
1420*1230fdc1SLionel Sambuc e->normal.enc.utf16Convert = unknown_toUtf16;
1421*1230fdc1SLionel Sambuc return &(e->normal.enc);
1422*1230fdc1SLionel Sambuc }
1423*1230fdc1SLionel Sambuc
1424*1230fdc1SLionel Sambuc /* If this enumeration is changed, getEncodingIndex and encodings
1425*1230fdc1SLionel Sambuc must also be changed. */
1426*1230fdc1SLionel Sambuc enum {
1427*1230fdc1SLionel Sambuc UNKNOWN_ENC = -1,
1428*1230fdc1SLionel Sambuc ISO_8859_1_ENC = 0,
1429*1230fdc1SLionel Sambuc US_ASCII_ENC,
1430*1230fdc1SLionel Sambuc UTF_8_ENC,
1431*1230fdc1SLionel Sambuc UTF_16_ENC,
1432*1230fdc1SLionel Sambuc UTF_16BE_ENC,
1433*1230fdc1SLionel Sambuc UTF_16LE_ENC,
1434*1230fdc1SLionel Sambuc /* must match encodingNames up to here */
1435*1230fdc1SLionel Sambuc NO_ENC
1436*1230fdc1SLionel Sambuc };
1437*1230fdc1SLionel Sambuc
1438*1230fdc1SLionel Sambuc static const char KW_ISO_8859_1[] = {
1439*1230fdc1SLionel Sambuc ASCII_I, ASCII_S, ASCII_O, ASCII_MINUS, ASCII_8, ASCII_8, ASCII_5, ASCII_9,
1440*1230fdc1SLionel Sambuc ASCII_MINUS, ASCII_1, '\0'
1441*1230fdc1SLionel Sambuc };
1442*1230fdc1SLionel Sambuc static const char KW_US_ASCII[] = {
1443*1230fdc1SLionel Sambuc ASCII_U, ASCII_S, ASCII_MINUS, ASCII_A, ASCII_S, ASCII_C, ASCII_I, ASCII_I,
1444*1230fdc1SLionel Sambuc '\0'
1445*1230fdc1SLionel Sambuc };
1446*1230fdc1SLionel Sambuc static const char KW_UTF_8[] = {
1447*1230fdc1SLionel Sambuc ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_8, '\0'
1448*1230fdc1SLionel Sambuc };
1449*1230fdc1SLionel Sambuc static const char KW_UTF_16[] = {
1450*1230fdc1SLionel Sambuc ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, '\0'
1451*1230fdc1SLionel Sambuc };
1452*1230fdc1SLionel Sambuc static const char KW_UTF_16BE[] = {
1453*1230fdc1SLionel Sambuc ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_B, ASCII_E,
1454*1230fdc1SLionel Sambuc '\0'
1455*1230fdc1SLionel Sambuc };
1456*1230fdc1SLionel Sambuc static const char KW_UTF_16LE[] = {
1457*1230fdc1SLionel Sambuc ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_L, ASCII_E,
1458*1230fdc1SLionel Sambuc '\0'
1459*1230fdc1SLionel Sambuc };
1460*1230fdc1SLionel Sambuc
1461*1230fdc1SLionel Sambuc static int FASTCALL
getEncodingIndex(const char * name)1462*1230fdc1SLionel Sambuc getEncodingIndex(const char *name)
1463*1230fdc1SLionel Sambuc {
1464*1230fdc1SLionel Sambuc static const char * const encodingNames[] = {
1465*1230fdc1SLionel Sambuc KW_ISO_8859_1,
1466*1230fdc1SLionel Sambuc KW_US_ASCII,
1467*1230fdc1SLionel Sambuc KW_UTF_8,
1468*1230fdc1SLionel Sambuc KW_UTF_16,
1469*1230fdc1SLionel Sambuc KW_UTF_16BE,
1470*1230fdc1SLionel Sambuc KW_UTF_16LE,
1471*1230fdc1SLionel Sambuc };
1472*1230fdc1SLionel Sambuc int i;
1473*1230fdc1SLionel Sambuc if (name == NULL)
1474*1230fdc1SLionel Sambuc return NO_ENC;
1475*1230fdc1SLionel Sambuc for (i = 0; i < (int)(sizeof(encodingNames)/sizeof(encodingNames[0])); i++)
1476*1230fdc1SLionel Sambuc if (streqci(name, encodingNames[i]))
1477*1230fdc1SLionel Sambuc return i;
1478*1230fdc1SLionel Sambuc return UNKNOWN_ENC;
1479*1230fdc1SLionel Sambuc }
1480*1230fdc1SLionel Sambuc
1481*1230fdc1SLionel Sambuc /* For binary compatibility, we store the index of the encoding
1482*1230fdc1SLionel Sambuc specified at initialization in the isUtf16 member.
1483*1230fdc1SLionel Sambuc */
1484*1230fdc1SLionel Sambuc
1485*1230fdc1SLionel Sambuc #define INIT_ENC_INDEX(enc) ((int)(enc)->initEnc.isUtf16)
1486*1230fdc1SLionel Sambuc #define SET_INIT_ENC_INDEX(enc, i) ((enc)->initEnc.isUtf16 = (char)i)
1487*1230fdc1SLionel Sambuc
1488*1230fdc1SLionel Sambuc /* This is what detects the encoding. encodingTable maps from
1489*1230fdc1SLionel Sambuc encoding indices to encodings; INIT_ENC_INDEX(enc) is the index of
1490*1230fdc1SLionel Sambuc the external (protocol) specified encoding; state is
1491*1230fdc1SLionel Sambuc XML_CONTENT_STATE if we're parsing an external text entity, and
1492*1230fdc1SLionel Sambuc XML_PROLOG_STATE otherwise.
1493*1230fdc1SLionel Sambuc */
1494*1230fdc1SLionel Sambuc
1495*1230fdc1SLionel Sambuc
1496*1230fdc1SLionel Sambuc static int
initScan(const ENCODING * const * encodingTable,const INIT_ENCODING * enc,int state,const char * ptr,const char * end,const char ** nextTokPtr)1497*1230fdc1SLionel Sambuc initScan(const ENCODING * const *encodingTable,
1498*1230fdc1SLionel Sambuc const INIT_ENCODING *enc,
1499*1230fdc1SLionel Sambuc int state,
1500*1230fdc1SLionel Sambuc const char *ptr,
1501*1230fdc1SLionel Sambuc const char *end,
1502*1230fdc1SLionel Sambuc const char **nextTokPtr)
1503*1230fdc1SLionel Sambuc {
1504*1230fdc1SLionel Sambuc const ENCODING **encPtr;
1505*1230fdc1SLionel Sambuc
1506*1230fdc1SLionel Sambuc if (ptr == end)
1507*1230fdc1SLionel Sambuc return XML_TOK_NONE;
1508*1230fdc1SLionel Sambuc encPtr = enc->encPtr;
1509*1230fdc1SLionel Sambuc if (ptr + 1 == end) {
1510*1230fdc1SLionel Sambuc /* only a single byte available for auto-detection */
1511*1230fdc1SLionel Sambuc #ifndef XML_DTD /* FIXME */
1512*1230fdc1SLionel Sambuc /* a well-formed document entity must have more than one byte */
1513*1230fdc1SLionel Sambuc if (state != XML_CONTENT_STATE)
1514*1230fdc1SLionel Sambuc return XML_TOK_PARTIAL;
1515*1230fdc1SLionel Sambuc #endif
1516*1230fdc1SLionel Sambuc /* so we're parsing an external text entity... */
1517*1230fdc1SLionel Sambuc /* if UTF-16 was externally specified, then we need at least 2 bytes */
1518*1230fdc1SLionel Sambuc switch (INIT_ENC_INDEX(enc)) {
1519*1230fdc1SLionel Sambuc case UTF_16_ENC:
1520*1230fdc1SLionel Sambuc case UTF_16LE_ENC:
1521*1230fdc1SLionel Sambuc case UTF_16BE_ENC:
1522*1230fdc1SLionel Sambuc return XML_TOK_PARTIAL;
1523*1230fdc1SLionel Sambuc }
1524*1230fdc1SLionel Sambuc switch ((unsigned char)*ptr) {
1525*1230fdc1SLionel Sambuc case 0xFE:
1526*1230fdc1SLionel Sambuc case 0xFF:
1527*1230fdc1SLionel Sambuc case 0xEF: /* possibly first byte of UTF-8 BOM */
1528*1230fdc1SLionel Sambuc if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
1529*1230fdc1SLionel Sambuc && state == XML_CONTENT_STATE)
1530*1230fdc1SLionel Sambuc break;
1531*1230fdc1SLionel Sambuc /* fall through */
1532*1230fdc1SLionel Sambuc case 0x00:
1533*1230fdc1SLionel Sambuc case 0x3C:
1534*1230fdc1SLionel Sambuc return XML_TOK_PARTIAL;
1535*1230fdc1SLionel Sambuc }
1536*1230fdc1SLionel Sambuc }
1537*1230fdc1SLionel Sambuc else {
1538*1230fdc1SLionel Sambuc switch (((unsigned char)ptr[0] << 8) | (unsigned char)ptr[1]) {
1539*1230fdc1SLionel Sambuc case 0xFEFF:
1540*1230fdc1SLionel Sambuc if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
1541*1230fdc1SLionel Sambuc && state == XML_CONTENT_STATE)
1542*1230fdc1SLionel Sambuc break;
1543*1230fdc1SLionel Sambuc *nextTokPtr = ptr + 2;
1544*1230fdc1SLionel Sambuc *encPtr = encodingTable[UTF_16BE_ENC];
1545*1230fdc1SLionel Sambuc return XML_TOK_BOM;
1546*1230fdc1SLionel Sambuc /* 00 3C is handled in the default case */
1547*1230fdc1SLionel Sambuc case 0x3C00:
1548*1230fdc1SLionel Sambuc if ((INIT_ENC_INDEX(enc) == UTF_16BE_ENC
1549*1230fdc1SLionel Sambuc || INIT_ENC_INDEX(enc) == UTF_16_ENC)
1550*1230fdc1SLionel Sambuc && state == XML_CONTENT_STATE)
1551*1230fdc1SLionel Sambuc break;
1552*1230fdc1SLionel Sambuc *encPtr = encodingTable[UTF_16LE_ENC];
1553*1230fdc1SLionel Sambuc return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
1554*1230fdc1SLionel Sambuc case 0xFFFE:
1555*1230fdc1SLionel Sambuc if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
1556*1230fdc1SLionel Sambuc && state == XML_CONTENT_STATE)
1557*1230fdc1SLionel Sambuc break;
1558*1230fdc1SLionel Sambuc *nextTokPtr = ptr + 2;
1559*1230fdc1SLionel Sambuc *encPtr = encodingTable[UTF_16LE_ENC];
1560*1230fdc1SLionel Sambuc return XML_TOK_BOM;
1561*1230fdc1SLionel Sambuc case 0xEFBB:
1562*1230fdc1SLionel Sambuc /* Maybe a UTF-8 BOM (EF BB BF) */
1563*1230fdc1SLionel Sambuc /* If there's an explicitly specified (external) encoding
1564*1230fdc1SLionel Sambuc of ISO-8859-1 or some flavour of UTF-16
1565*1230fdc1SLionel Sambuc and this is an external text entity,
1566*1230fdc1SLionel Sambuc don't look for the BOM,
1567*1230fdc1SLionel Sambuc because it might be a legal data.
1568*1230fdc1SLionel Sambuc */
1569*1230fdc1SLionel Sambuc if (state == XML_CONTENT_STATE) {
1570*1230fdc1SLionel Sambuc int e = INIT_ENC_INDEX(enc);
1571*1230fdc1SLionel Sambuc if (e == ISO_8859_1_ENC || e == UTF_16BE_ENC
1572*1230fdc1SLionel Sambuc || e == UTF_16LE_ENC || e == UTF_16_ENC)
1573*1230fdc1SLionel Sambuc break;
1574*1230fdc1SLionel Sambuc }
1575*1230fdc1SLionel Sambuc if (ptr + 2 == end)
1576*1230fdc1SLionel Sambuc return XML_TOK_PARTIAL;
1577*1230fdc1SLionel Sambuc if ((unsigned char)ptr[2] == 0xBF) {
1578*1230fdc1SLionel Sambuc *nextTokPtr = ptr + 3;
1579*1230fdc1SLionel Sambuc *encPtr = encodingTable[UTF_8_ENC];
1580*1230fdc1SLionel Sambuc return XML_TOK_BOM;
1581*1230fdc1SLionel Sambuc }
1582*1230fdc1SLionel Sambuc break;
1583*1230fdc1SLionel Sambuc default:
1584*1230fdc1SLionel Sambuc if (ptr[0] == '\0') {
1585*1230fdc1SLionel Sambuc /* 0 isn't a legal data character. Furthermore a document
1586*1230fdc1SLionel Sambuc entity can only start with ASCII characters. So the only
1587*1230fdc1SLionel Sambuc way this can fail to be big-endian UTF-16 if it it's an
1588*1230fdc1SLionel Sambuc external parsed general entity that's labelled as
1589*1230fdc1SLionel Sambuc UTF-16LE.
1590*1230fdc1SLionel Sambuc */
1591*1230fdc1SLionel Sambuc if (state == XML_CONTENT_STATE && INIT_ENC_INDEX(enc) == UTF_16LE_ENC)
1592*1230fdc1SLionel Sambuc break;
1593*1230fdc1SLionel Sambuc *encPtr = encodingTable[UTF_16BE_ENC];
1594*1230fdc1SLionel Sambuc return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
1595*1230fdc1SLionel Sambuc }
1596*1230fdc1SLionel Sambuc else if (ptr[1] == '\0') {
1597*1230fdc1SLionel Sambuc /* We could recover here in the case:
1598*1230fdc1SLionel Sambuc - parsing an external entity
1599*1230fdc1SLionel Sambuc - second byte is 0
1600*1230fdc1SLionel Sambuc - no externally specified encoding
1601*1230fdc1SLionel Sambuc - no encoding declaration
1602*1230fdc1SLionel Sambuc by assuming UTF-16LE. But we don't, because this would mean when
1603*1230fdc1SLionel Sambuc presented just with a single byte, we couldn't reliably determine
1604*1230fdc1SLionel Sambuc whether we needed further bytes.
1605*1230fdc1SLionel Sambuc */
1606*1230fdc1SLionel Sambuc if (state == XML_CONTENT_STATE)
1607*1230fdc1SLionel Sambuc break;
1608*1230fdc1SLionel Sambuc *encPtr = encodingTable[UTF_16LE_ENC];
1609*1230fdc1SLionel Sambuc return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
1610*1230fdc1SLionel Sambuc }
1611*1230fdc1SLionel Sambuc break;
1612*1230fdc1SLionel Sambuc }
1613*1230fdc1SLionel Sambuc }
1614*1230fdc1SLionel Sambuc *encPtr = encodingTable[INIT_ENC_INDEX(enc)];
1615*1230fdc1SLionel Sambuc return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
1616*1230fdc1SLionel Sambuc }
1617*1230fdc1SLionel Sambuc
1618*1230fdc1SLionel Sambuc
1619*1230fdc1SLionel Sambuc #define NS(x) x
1620*1230fdc1SLionel Sambuc #define ns(x) x
1621*1230fdc1SLionel Sambuc #define XML_TOK_NS_C
1622*1230fdc1SLionel Sambuc #include "xmltok_ns.c"
1623*1230fdc1SLionel Sambuc #undef XML_TOK_NS_C
1624*1230fdc1SLionel Sambuc #undef NS
1625*1230fdc1SLionel Sambuc #undef ns
1626*1230fdc1SLionel Sambuc
1627*1230fdc1SLionel Sambuc #ifdef XML_NS
1628*1230fdc1SLionel Sambuc
1629*1230fdc1SLionel Sambuc #define NS(x) x ## NS
1630*1230fdc1SLionel Sambuc #define ns(x) x ## _ns
1631*1230fdc1SLionel Sambuc
1632*1230fdc1SLionel Sambuc #define XML_TOK_NS_C
1633*1230fdc1SLionel Sambuc #include "xmltok_ns.c"
1634*1230fdc1SLionel Sambuc #undef XML_TOK_NS_C
1635*1230fdc1SLionel Sambuc
1636*1230fdc1SLionel Sambuc #undef NS
1637*1230fdc1SLionel Sambuc #undef ns
1638*1230fdc1SLionel Sambuc
1639*1230fdc1SLionel Sambuc ENCODING *
XmlInitUnknownEncodingNS(void * mem,int * table,CONVERTER convert,void * userData)1640*1230fdc1SLionel Sambuc XmlInitUnknownEncodingNS(void *mem,
1641*1230fdc1SLionel Sambuc int *table,
1642*1230fdc1SLionel Sambuc CONVERTER convert,
1643*1230fdc1SLionel Sambuc void *userData)
1644*1230fdc1SLionel Sambuc {
1645*1230fdc1SLionel Sambuc ENCODING *enc = XmlInitUnknownEncoding(mem, table, convert, userData);
1646*1230fdc1SLionel Sambuc if (enc)
1647*1230fdc1SLionel Sambuc ((struct normal_encoding *)enc)->type[ASCII_COLON] = BT_COLON;
1648*1230fdc1SLionel Sambuc return enc;
1649*1230fdc1SLionel Sambuc }
1650*1230fdc1SLionel Sambuc
1651*1230fdc1SLionel Sambuc #endif /* XML_NS */
1652