2017-08-12 14:56:14 -04:00
|
|
|
/* This file is included!
|
|
|
|
__ __ _
|
|
|
|
___\ \/ /_ __ __ _| |_
|
|
|
|
/ _ \\ /| '_ \ / _` | __|
|
|
|
|
| __// \| |_) | (_| | |_
|
|
|
|
\___/_/\_\ .__/ \__,_|\__|
|
|
|
|
|_| XML parser
|
|
|
|
|
|
|
|
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
|
2021-05-01 19:49:02 -04:00
|
|
|
Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net>
|
|
|
|
Copyright (c) 2002 Greg Stein <gstein@users.sourceforge.net>
|
|
|
|
Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
|
|
|
|
Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net>
|
|
|
|
Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org>
|
2017-08-12 14:56:14 -04:00
|
|
|
Licensed under the MIT license:
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
persons to whom the Software is furnished to do so, subject to the
|
|
|
|
following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2006-11-26 12:34:46 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef XML_TOK_NS_C
|
|
|
|
|
2002-07-01 12:46:08 -04:00
|
|
|
const ENCODING *
|
2019-08-03 14:34:54 -04:00
|
|
|
NS(XmlGetUtf8InternalEncoding)(void) {
|
1998-11-17 04:45:10 -05:00
|
|
|
return &ns(internal_utf8_encoding).enc;
|
|
|
|
}
|
|
|
|
|
2002-07-01 12:46:08 -04:00
|
|
|
const ENCODING *
|
2019-08-03 14:34:54 -04:00
|
|
|
NS(XmlGetUtf16InternalEncoding)(void) {
|
|
|
|
# if BYTEORDER == 1234
|
1998-11-17 04:45:10 -05:00
|
|
|
return &ns(internal_little2_encoding).enc;
|
2019-08-03 14:34:54 -04:00
|
|
|
# elif BYTEORDER == 4321
|
1998-11-17 04:45:10 -05:00
|
|
|
return &ns(internal_big2_encoding).enc;
|
2019-08-03 14:34:54 -04:00
|
|
|
# else
|
1998-11-17 04:45:10 -05:00
|
|
|
const short n = 1;
|
2019-08-03 14:34:54 -04:00
|
|
|
return (*(const char *)&n ? &ns(internal_little2_encoding).enc
|
|
|
|
: &ns(internal_big2_encoding).enc);
|
|
|
|
# endif
|
1998-11-17 04:45:10 -05:00
|
|
|
}
|
|
|
|
|
2019-08-03 14:34:54 -04:00
|
|
|
static const ENCODING *const NS(encodings)[] = {
|
|
|
|
&ns(latin1_encoding).enc, &ns(ascii_encoding).enc,
|
|
|
|
&ns(utf8_encoding).enc, &ns(big2_encoding).enc,
|
|
|
|
&ns(big2_encoding).enc, &ns(little2_encoding).enc,
|
|
|
|
&ns(utf8_encoding).enc /* NO_ENC */
|
1998-11-17 07:42:16 -05:00
|
|
|
};
|
1998-11-17 04:45:10 -05:00
|
|
|
|
2002-09-19 23:42:43 -04:00
|
|
|
static int PTRCALL
|
2002-07-01 12:46:08 -04:00
|
|
|
NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
|
2019-08-03 14:34:54 -04:00
|
|
|
const char **nextTokPtr) {
|
|
|
|
return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE,
|
|
|
|
ptr, end, nextTokPtr);
|
1998-11-17 04:45:10 -05:00
|
|
|
}
|
|
|
|
|
2002-09-19 23:42:43 -04:00
|
|
|
static int PTRCALL
|
2002-07-01 12:46:08 -04:00
|
|
|
NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
|
2019-08-03 14:34:54 -04:00
|
|
|
const char **nextTokPtr) {
|
|
|
|
return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE,
|
|
|
|
ptr, end, nextTokPtr);
|
1998-11-17 04:45:10 -05:00
|
|
|
}
|
|
|
|
|
2002-07-01 12:46:08 -04:00
|
|
|
int
|
|
|
|
NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr,
|
2019-08-03 14:34:54 -04:00
|
|
|
const char *name) {
|
1998-11-17 07:42:16 -05:00
|
|
|
int i = getEncodingIndex(name);
|
|
|
|
if (i == UNKNOWN_ENC)
|
|
|
|
return 0;
|
1999-06-02 07:20:06 -04:00
|
|
|
SET_INIT_ENC_INDEX(p, i);
|
1998-11-17 04:45:10 -05:00
|
|
|
p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
|
|
|
|
p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
|
|
|
|
p->initEnc.updatePosition = initUpdatePosition;
|
|
|
|
p->encPtr = encPtr;
|
|
|
|
*encPtr = &(p->initEnc);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-07-01 12:46:08 -04:00
|
|
|
static const ENCODING *
|
2019-08-03 14:34:54 -04:00
|
|
|
NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) {
|
|
|
|
# define ENCODING_MAX 128
|
lib: Address GCC 11.2.1 compiler warning
Symptom was:
In file included from xmltok.c:58:
xmltok_ns.c: In function ‘findEncodingNS’:
xmltok.h:276:10: warning: ‘buf’ may be used uninitialized [-Wmaybe-uninitialized]
276 | (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xmltok_ns.c:99:3: note: in expansion of macro ‘XmlUtf8Convert’
99 | XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
| ^~~~~~~~~~~~~~
xmltok.h:276:10: note: by argument 5 of type ‘const char *’ to ‘enum XML_Convert_Result(const ENCODING *, const char **, const char *, char **, const char *)’ {aka ‘enum XML_Convert_Result(const struct encoding *, const char **, const char *, char **, const char *)’}
276 | (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xmltok_ns.c:99:3: note: in expansion of macro ‘XmlUtf8Convert’
99 | XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
| ^~~~~~~~~~~~~~
In file included from xmltok.c:1666:
xmltok_ns.c:96:8: note: ‘buf’ declared here
96 | char buf[ENCODING_MAX];
| ^~~
2021-12-25 12:13:12 -05:00
|
|
|
char buf[ENCODING_MAX] = "";
|
1998-11-17 04:45:10 -05:00
|
|
|
char *p = buf;
|
|
|
|
int i;
|
|
|
|
XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
|
|
|
|
if (ptr != end)
|
|
|
|
return 0;
|
|
|
|
*p = 0;
|
1999-10-12 23:58:17 -04:00
|
|
|
if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
|
1998-11-17 07:42:16 -05:00
|
|
|
return enc;
|
|
|
|
i = getEncodingIndex(buf);
|
|
|
|
if (i == UNKNOWN_ENC)
|
|
|
|
return 0;
|
|
|
|
return NS(encodings)[i];
|
1998-11-17 04:45:10 -05:00
|
|
|
}
|
|
|
|
|
2002-07-01 12:46:08 -04:00
|
|
|
int
|
2019-08-03 14:34:54 -04:00
|
|
|
NS(XmlParseXmlDecl)(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) {
|
|
|
|
return doParseXmlDecl(NS(findEncoding), isGeneralTextEntity, enc, ptr, end,
|
|
|
|
badPtr, versionPtr, versionEndPtr, encodingName,
|
|
|
|
encoding, standalone);
|
1998-11-17 04:45:10 -05:00
|
|
|
}
|
2006-11-26 12:34:46 -05:00
|
|
|
|
|
|
|
#endif /* XML_TOK_NS_C */
|