xref: /minix3/external/mit/expat/dist/lib/xmltok_ns.c (revision 1230fdc108a70388f87f1b3abdb6731e789a6d94)
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 /* This file is included! */
6*1230fdc1SLionel Sambuc #ifdef XML_TOK_NS_C
7*1230fdc1SLionel Sambuc 
8*1230fdc1SLionel Sambuc const ENCODING *
NS(XmlGetUtf8InternalEncoding)9*1230fdc1SLionel Sambuc NS(XmlGetUtf8InternalEncoding)(void)
10*1230fdc1SLionel Sambuc {
11*1230fdc1SLionel Sambuc   return &ns(internal_utf8_encoding).enc;
12*1230fdc1SLionel Sambuc }
13*1230fdc1SLionel Sambuc 
14*1230fdc1SLionel Sambuc const ENCODING *
NS(XmlGetUtf16InternalEncoding)15*1230fdc1SLionel Sambuc NS(XmlGetUtf16InternalEncoding)(void)
16*1230fdc1SLionel Sambuc {
17*1230fdc1SLionel Sambuc #if BYTEORDER == 1234
18*1230fdc1SLionel Sambuc   return &ns(internal_little2_encoding).enc;
19*1230fdc1SLionel Sambuc #elif BYTEORDER == 4321
20*1230fdc1SLionel Sambuc   return &ns(internal_big2_encoding).enc;
21*1230fdc1SLionel Sambuc #else
22*1230fdc1SLionel Sambuc   const short n = 1;
23*1230fdc1SLionel Sambuc   return (*(const char *)&n
24*1230fdc1SLionel Sambuc           ? &ns(internal_little2_encoding).enc
25*1230fdc1SLionel Sambuc           : &ns(internal_big2_encoding).enc);
26*1230fdc1SLionel Sambuc #endif
27*1230fdc1SLionel Sambuc }
28*1230fdc1SLionel Sambuc 
29*1230fdc1SLionel Sambuc static const ENCODING * const NS(encodings)[] = {
30*1230fdc1SLionel Sambuc   &ns(latin1_encoding).enc,
31*1230fdc1SLionel Sambuc   &ns(ascii_encoding).enc,
32*1230fdc1SLionel Sambuc   &ns(utf8_encoding).enc,
33*1230fdc1SLionel Sambuc   &ns(big2_encoding).enc,
34*1230fdc1SLionel Sambuc   &ns(big2_encoding).enc,
35*1230fdc1SLionel Sambuc   &ns(little2_encoding).enc,
36*1230fdc1SLionel Sambuc   &ns(utf8_encoding).enc /* NO_ENC */
37*1230fdc1SLionel Sambuc };
38*1230fdc1SLionel Sambuc 
39*1230fdc1SLionel Sambuc static int PTRCALL
NS(initScanProlog)40*1230fdc1SLionel Sambuc NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
41*1230fdc1SLionel Sambuc                    const char **nextTokPtr)
42*1230fdc1SLionel Sambuc {
43*1230fdc1SLionel Sambuc   return initScan(NS(encodings), (const INIT_ENCODING *)enc,
44*1230fdc1SLionel Sambuc                   XML_PROLOG_STATE, ptr, end, nextTokPtr);
45*1230fdc1SLionel Sambuc }
46*1230fdc1SLionel Sambuc 
47*1230fdc1SLionel Sambuc static int PTRCALL
NS(initScanContent)48*1230fdc1SLionel Sambuc NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
49*1230fdc1SLionel Sambuc                     const char **nextTokPtr)
50*1230fdc1SLionel Sambuc {
51*1230fdc1SLionel Sambuc   return initScan(NS(encodings), (const INIT_ENCODING *)enc,
52*1230fdc1SLionel Sambuc                   XML_CONTENT_STATE, ptr, end, nextTokPtr);
53*1230fdc1SLionel Sambuc }
54*1230fdc1SLionel Sambuc 
55*1230fdc1SLionel Sambuc int
NS(XmlInitEncoding)56*1230fdc1SLionel Sambuc NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
57*1230fdc1SLionel Sambuc                     const char *name)
58*1230fdc1SLionel Sambuc {
59*1230fdc1SLionel Sambuc   int i = getEncodingIndex(name);
60*1230fdc1SLionel Sambuc   if (i == UNKNOWN_ENC)
61*1230fdc1SLionel Sambuc     return 0;
62*1230fdc1SLionel Sambuc   SET_INIT_ENC_INDEX(p, i);
63*1230fdc1SLionel Sambuc   p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
64*1230fdc1SLionel Sambuc   p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
65*1230fdc1SLionel Sambuc   p->initEnc.updatePosition = initUpdatePosition;
66*1230fdc1SLionel Sambuc   p->encPtr = encPtr;
67*1230fdc1SLionel Sambuc   *encPtr = &(p->initEnc);
68*1230fdc1SLionel Sambuc   return 1;
69*1230fdc1SLionel Sambuc }
70*1230fdc1SLionel Sambuc 
71*1230fdc1SLionel Sambuc static const ENCODING *
NS(findEncoding)72*1230fdc1SLionel Sambuc NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
73*1230fdc1SLionel Sambuc {
74*1230fdc1SLionel Sambuc #define ENCODING_MAX 128
75*1230fdc1SLionel Sambuc   char buf[ENCODING_MAX];
76*1230fdc1SLionel Sambuc   char *p = buf;
77*1230fdc1SLionel Sambuc   int i;
78*1230fdc1SLionel Sambuc   XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
79*1230fdc1SLionel Sambuc   if (ptr != end)
80*1230fdc1SLionel Sambuc     return 0;
81*1230fdc1SLionel Sambuc   *p = 0;
82*1230fdc1SLionel Sambuc   if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
83*1230fdc1SLionel Sambuc     return enc;
84*1230fdc1SLionel Sambuc   i = getEncodingIndex(buf);
85*1230fdc1SLionel Sambuc   if (i == UNKNOWN_ENC)
86*1230fdc1SLionel Sambuc     return 0;
87*1230fdc1SLionel Sambuc   return NS(encodings)[i];
88*1230fdc1SLionel Sambuc }
89*1230fdc1SLionel Sambuc 
90*1230fdc1SLionel Sambuc int
NS(XmlParseXmlDecl)91*1230fdc1SLionel Sambuc NS(XmlParseXmlDecl)(int isGeneralTextEntity,
92*1230fdc1SLionel Sambuc                     const ENCODING *enc,
93*1230fdc1SLionel Sambuc                     const char *ptr,
94*1230fdc1SLionel Sambuc                     const char *end,
95*1230fdc1SLionel Sambuc                     const char **badPtr,
96*1230fdc1SLionel Sambuc                     const char **versionPtr,
97*1230fdc1SLionel Sambuc                     const char **versionEndPtr,
98*1230fdc1SLionel Sambuc                     const char **encodingName,
99*1230fdc1SLionel Sambuc                     const ENCODING **encoding,
100*1230fdc1SLionel Sambuc                     int *standalone)
101*1230fdc1SLionel Sambuc {
102*1230fdc1SLionel Sambuc   return doParseXmlDecl(NS(findEncoding),
103*1230fdc1SLionel Sambuc                         isGeneralTextEntity,
104*1230fdc1SLionel Sambuc                         enc,
105*1230fdc1SLionel Sambuc                         ptr,
106*1230fdc1SLionel Sambuc                         end,
107*1230fdc1SLionel Sambuc                         badPtr,
108*1230fdc1SLionel Sambuc                         versionPtr,
109*1230fdc1SLionel Sambuc                         versionEndPtr,
110*1230fdc1SLionel Sambuc                         encodingName,
111*1230fdc1SLionel Sambuc                         encoding,
112*1230fdc1SLionel Sambuc                         standalone);
113*1230fdc1SLionel Sambuc }
114*1230fdc1SLionel Sambuc 
115*1230fdc1SLionel Sambuc #endif /* XML_TOK_NS_C */
116