初始化PHP-Xlswrite扩展

This commit is contained in:
ykxiao
2024-03-05 10:01:08 +08:00
commit 879cf9584d
2483 changed files with 1054962 additions and 0 deletions

6
library/libexpat/expat/xmlwf/.gitignore vendored Executable file
View File

@ -0,0 +1,6 @@
Debug
Release
xmlwf.plg
Makefile
xmlwf
.libs

View File

@ -0,0 +1,61 @@
#
# __ __ _
# ___\ \/ /_ __ __ _| |_
# / _ \\ /| '_ \ / _` | __|
# | __// \| |_) | (_| | |_
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2017 Expat development team
# 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.
bin_PROGRAMS = xmlwf
xmlwf_LDADD = ../lib/libexpat.la
xmlwf_SOURCES = \
xmlwf.c \
xmlfile.c \
codepage.c \
@FILEMAP@.c
xmlwf_CPPFLAGS = -I$(srcdir)/../lib
if MINGW
if UNICODE
xmlwf_CPPFLAGS += -mwindows
xmlwf_LDFLAGS = -municode
endif
endif
EXTRA_DIST = \
codepage.h \
ct.c \
filemap.h \
readfilemap.c \
unixfilemap.c \
win32filemap.c \
xmlfile.h \
xmlmime.c \
xmlmime.h \
xmltchar.h \
xmlurl.h \
xmlwin32url.cxx

View File

@ -0,0 +1,97 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#include "codepage.h"
#include "internal.h" /* for UNUSED_P only */
#if defined(_WIN32)
#define STRICT 1
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
int
codepageMap(int cp, int *map)
{
int i;
CPINFO info;
if (!GetCPInfo(cp, &info) || info.MaxCharSize > 2)
return 0;
for (i = 0; i < 256; i++)
map[i] = -1;
if (info.MaxCharSize > 1) {
for (i = 0; i < MAX_LEADBYTES; i+=2) {
int j, lim;
if (info.LeadByte[i] == 0 && info.LeadByte[i + 1] == 0)
break;
lim = info.LeadByte[i + 1];
for (j = info.LeadByte[i]; j <= lim; j++)
map[j] = -2;
}
}
for (i = 0; i < 256; i++) {
if (map[i] == -1) {
char c = (char)i;
unsigned short n;
if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
&c, 1, &n, 1) == 1)
map[i] = n;
}
}
return 1;
}
int
codepageConvert(int cp, const char *p)
{
unsigned short c;
if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
p, 2, &c, 1) == 1)
return c;
return -1;
}
#else /* not _WIN32 */
int
codepageMap(int UNUSED_P(cp), int *UNUSED_P(map))
{
return 0;
}
int
codepageConvert(int UNUSED_P(cp), const char *UNUSED_P(p))
{
return -1;
}
#endif /* not _WIN32 */

View File

@ -0,0 +1,34 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
int codepageMap(int cp, int *map);
int codepageConvert(int cp, const char *p);

View File

@ -0,0 +1,179 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#define CHARSET_MAX 41
static const char *
getTok(const char **pp)
{
enum { inAtom, inString, init, inComment };
int state = init;
const char *tokStart = 0;
for (;;) {
switch (**pp) {
case '\0':
return 0;
case ' ':
case '\r':
case '\t':
case '\n':
if (state == inAtom)
return tokStart;
break;
case '(':
if (state == inAtom)
return tokStart;
if (state != inString)
state++;
break;
case ')':
if (state > init)
--state;
else if (state != inString)
return 0;
break;
case ';':
case '/':
case '=':
if (state == inAtom)
return tokStart;
if (state == init)
return (*pp)++;
break;
case '\\':
++*pp;
if (**pp == '\0')
return 0;
break;
case '"':
switch (state) {
case inString:
++*pp;
return tokStart;
case inAtom:
return tokStart;
case init:
tokStart = *pp;
state = inString;
break;
}
break;
default:
if (state == init) {
tokStart = *pp;
state = inAtom;
}
break;
}
++*pp;
}
/* not reached */
}
/* key must be lowercase ASCII */
static int
matchkey(const char *start, const char *end, const char *key)
{
if (!start)
return 0;
for (; start != end; start++, key++)
if (*start != *key && *start != 'A' + (*key - 'a'))
return 0;
return *key == '\0';
}
void
getXMLCharset(const char *buf, char *charset)
{
const char *next, *p;
charset[0] = '\0';
next = buf;
p = getTok(&next);
if (matchkey(p, next, "text"))
strcpy(charset, "us-ascii");
else if (!matchkey(p, next, "application"))
return;
p = getTok(&next);
if (!p || *p != '/')
return;
p = getTok(&next);
if (matchkey(p, next, "xml"))
isXml = 1;
p = getTok(&next);
while (p) {
if (*p == ';') {
p = getTok(&next);
if (matchkey(p, next, "charset")) {
p = getTok(&next);
if (p && *p == '=') {
p = getTok(&next);
if (p) {
char *s = charset;
if (*p == '"') {
while (++p != next - 1) {
if (*p == '\\')
++p;
if (s == charset + CHARSET_MAX - 1) {
charset[0] = '\0';
break;
}
*s++ = *p;
}
*s++ = '\0';
}
else {
if (next - p > CHARSET_MAX - 1)
break;
while (p != next)
*s++ = *p++;
*s = 0;
break;
}
}
}
}
}
else
p = getTok(&next);
}
}
int
main(int argc, char **argv)
{
char buf[CHARSET_MAX];
getXMLCharset(argv[1], buf);
printf("charset = \"%s\"\n", buf);
return 0;
}

View File

@ -0,0 +1,57 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#include <limits.h> /* INT_MAX */
#include <stddef.h>
/* The following limit (for XML_Parse's int len) derives from
* this loop in xmparse.c:
*
* do {
* bufferSize = (int) (2U * (unsigned) bufferSize);
* } while (bufferSize < neededSize && bufferSize > 0);
*/
#define XML_MAX_CHUNK_LEN (INT_MAX / 2 + 1)
#ifdef XML_UNICODE
int filemap(const wchar_t *name,
void (*processor)(const void *, size_t,
const wchar_t *, void *arg),
void *arg);
#else
int filemap(const char *name,
void (*processor)(const void *, size_t,
const char *, void *arg),
void *arg);
#endif

View File

@ -0,0 +1,141 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
/* Functions close(2) and read(2) */
#if !defined(_WIN32) && !defined(_WIN64)
# include <unistd.h>
#endif
/* Function "read": */
#if defined(_MSC_VER)
# include <io.h>
/* https://msdn.microsoft.com/en-us/library/wyssk1bs(v=vs.100).aspx */
# define _EXPAT_read _read
# define _EXPAT_read_count_t int
# define _EXPAT_read_req_t unsigned int
#else /* POSIX */
/* http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html */
# define _EXPAT_read read
# define _EXPAT_read_count_t ssize_t
# define _EXPAT_read_req_t size_t
#endif
#ifndef S_ISREG
# ifndef S_IFREG
# define S_IFREG _S_IFREG
# endif
# ifndef S_IFMT
# define S_IFMT _S_IFMT
# endif
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif /* not S_ISREG */
#ifndef O_BINARY
# ifdef _O_BINARY
# define O_BINARY _O_BINARY
# else
# define O_BINARY 0
# endif
#endif
#include "xmltchar.h"
#include "filemap.h"
int
filemap(const tchar *name,
void (*processor)(const void *, size_t, const tchar *, void *arg),
void *arg)
{
size_t nbytes;
int fd;
_EXPAT_read_count_t n;
struct stat sb;
void *p;
fd = topen(name, O_RDONLY|O_BINARY);
if (fd < 0) {
tperror(name);
return 0;
}
if (fstat(fd, &sb) < 0) {
tperror(name);
close(fd);
return 0;
}
if (!S_ISREG(sb.st_mode)) {
ftprintf(stderr, T("%s: not a regular file\n"), name);
close(fd);
return 0;
}
if (sb.st_size > XML_MAX_CHUNK_LEN) {
close(fd);
return 2; /* Cannot be passed to XML_Parse in one go */
}
nbytes = sb.st_size;
/* malloc will return NULL with nbytes == 0, handle files with size 0 */
if (nbytes == 0) {
static const char c = '\0';
processor(&c, 0, name, arg);
close(fd);
return 1;
}
p = malloc(nbytes);
if (!p) {
ftprintf(stderr, T("%s: out of memory\n"), name);
close(fd);
return 0;
}
n = _EXPAT_read(fd, p, (_EXPAT_read_req_t)nbytes);
if (n < 0) {
tperror(name);
free(p);
close(fd);
return 0;
}
if (n != (_EXPAT_read_count_t)nbytes) {
ftprintf(stderr, T("%s: read unexpected number of bytes\n"), name);
free(p);
close(fd);
return 0;
}
processor(p, nbytes, name, arg);
free(p);
close(fd);
return 1;
}

View File

@ -0,0 +1,104 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
#include "xmltchar.h"
#include "filemap.h"
#ifdef XML_UNICODE_WCHAR_T
# define XML_FMT_STR "ls"
#else
# define XML_FMT_STR "s"
#endif
int
filemap(const tchar *name,
void (*processor)(const void *, size_t, const tchar *, void *arg),
void *arg)
{
int fd;
size_t nbytes;
struct stat sb;
void *p;
fd = topen(name, O_RDONLY);
if (fd < 0) {
tperror(name);
return 0;
}
if (fstat(fd, &sb) < 0) {
tperror(name);
close(fd);
return 0;
}
if (!S_ISREG(sb.st_mode)) {
close(fd);
fprintf(stderr, "%" XML_FMT_STR ": not a regular file\n", name);
return 0;
}
if (sb.st_size > XML_MAX_CHUNK_LEN) {
close(fd);
return 2; /* Cannot be passed to XML_Parse in one go */
}
nbytes = sb.st_size;
/* mmap fails for zero length files */
if (nbytes == 0) {
static const char c = '\0';
processor(&c, 0, name, arg);
close(fd);
return 1;
}
p = (void *)mmap((void *)0, (size_t)nbytes, PROT_READ,
MAP_FILE|MAP_PRIVATE, fd, (off_t)0);
if (p == (void *)-1) {
tperror(name);
close(fd);
return 0;
}
processor(p, nbytes, name, arg);
munmap((void *)p, nbytes);
close(fd);
return 1;
}

View File

@ -0,0 +1,125 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#define STRICT 1
#define WIN32_LEAN_AND_MEAN 1
#ifdef XML_UNICODE_WCHAR_T
# ifndef XML_UNICODE
# define XML_UNICODE
# endif
#endif
#ifdef XML_UNICODE
# define UNICODE
# define _UNICODE
#endif /* XML_UNICODE */
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "filemap.h"
static void win32perror(const TCHAR *);
int
filemap(const TCHAR *name,
void (*processor)(const void *, size_t, const TCHAR *, void *arg),
void *arg)
{
HANDLE f;
HANDLE m;
DWORD size;
DWORD sizeHi;
void *p;
f = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (f == INVALID_HANDLE_VALUE) {
win32perror(name);
return 0;
}
size = GetFileSize(f, &sizeHi);
if (size == (DWORD)-1) {
win32perror(name);
CloseHandle(f);
return 0;
}
if (sizeHi || (size > XML_MAX_CHUNK_LEN)) {
CloseHandle(f);
return 2; /* Cannot be passed to XML_Parse in one go */
}
/* CreateFileMapping barfs on zero length files */
if (size == 0) {
static const char c = '\0';
processor(&c, 0, name, arg);
CloseHandle(f);
return 1;
}
m = CreateFileMapping(f, NULL, PAGE_READONLY, 0, 0, NULL);
if (m == NULL) {
win32perror(name);
CloseHandle(f);
return 0;
}
p = MapViewOfFile(m, FILE_MAP_READ, 0, 0, 0);
if (p == NULL) {
win32perror(name);
CloseHandle(m);
CloseHandle(f);
return 0;
}
processor(p, size, name, arg);
UnmapViewOfFile(p);
CloseHandle(m);
CloseHandle(f);
return 1;
}
static void
win32perror(const TCHAR *s)
{
LPVOID buf;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &buf,
0,
NULL)) {
_ftprintf(stderr, _T("%s: %s"), s, buf);
fflush(stderr);
LocalFree(buf);
}
else
_ftprintf(stderr, _T("%s: unknown Windows error\n"), s);
}

View File

@ -0,0 +1,290 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <fcntl.h>
#ifdef _WIN32
#include "winconfig.h"
#elif defined(HAVE_EXPAT_CONFIG_H)
#include <expat_config.h>
#endif /* ndef _WIN32 */
#include "expat.h"
#include "internal.h" /* for UNUSED_P only */
#include "xmlfile.h"
#include "xmltchar.h"
#include "filemap.h"
#if defined(_MSC_VER)
#include <io.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifndef O_BINARY
#ifdef _O_BINARY
#define O_BINARY _O_BINARY
#else
#define O_BINARY 0
#endif
#endif
#ifdef _DEBUG
#define READ_SIZE 16
#else
#define READ_SIZE (1024*8)
#endif
typedef struct {
XML_Parser parser;
int *retPtr;
} PROCESS_ARGS;
static int
processStream(const XML_Char *filename, XML_Parser parser);
static void
reportError(XML_Parser parser, const XML_Char *filename)
{
enum XML_Error code = XML_GetErrorCode(parser);
const XML_Char *message = XML_ErrorString(code);
if (message)
ftprintf(stdout,
T("%s")
T(":%") T(XML_FMT_INT_MOD) T("u")
T(":%") T(XML_FMT_INT_MOD) T("u")
T(": %s\n"),
filename,
XML_GetErrorLineNumber(parser),
XML_GetErrorColumnNumber(parser),
message);
else
ftprintf(stderr, T("%s: (unknown message %d)\n"), filename, code);
}
/* This implementation will give problems on files larger than INT_MAX. */
static void
processFile(const void *data, size_t size,
const XML_Char *filename, void *args)
{
XML_Parser parser = ((PROCESS_ARGS *)args)->parser;
int *retPtr = ((PROCESS_ARGS *)args)->retPtr;
if (XML_Parse(parser, (const char *)data, (int)size, 1) == XML_STATUS_ERROR) {
reportError(parser, filename);
*retPtr = 0;
}
else
*retPtr = 1;
}
#if defined(_WIN32)
static int
isAsciiLetter(XML_Char c)
{
return (T('a') <= c && c <= T('z')) || (T('A') <= c && c <= T('Z'));
}
#endif /* _WIN32 */
static const XML_Char *
resolveSystemId(const XML_Char *base, const XML_Char *systemId,
XML_Char **toFree)
{
XML_Char *s;
*toFree = 0;
if (!base
|| *systemId == T('/')
#if defined(_WIN32)
|| *systemId == T('\\')
|| (isAsciiLetter(systemId[0]) && systemId[1] == T(':'))
#endif
)
return systemId;
*toFree = (XML_Char *)malloc((tcslen(base) + tcslen(systemId) + 2)
* sizeof(XML_Char));
if (!*toFree)
return systemId;
tcscpy(*toFree, base);
s = *toFree;
if (tcsrchr(s, T('/')))
s = tcsrchr(s, T('/')) + 1;
#if defined(_WIN32)
if (tcsrchr(s, T('\\')))
s = tcsrchr(s, T('\\')) + 1;
#endif
tcscpy(s, systemId);
return *toFree;
}
static int
externalEntityRefFilemap(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *UNUSED_P(publicId))
{
int result;
XML_Char *s;
const XML_Char *filename;
XML_Parser entParser = XML_ExternalEntityParserCreate(parser, context, 0);
int filemapRes;
PROCESS_ARGS args;
args.retPtr = &result;
args.parser = entParser;
filename = resolveSystemId(base, systemId, &s);
XML_SetBase(entParser, filename);
filemapRes = filemap(filename, processFile, &args);
switch (filemapRes) {
case 0:
result = 0;
break;
case 2:
ftprintf(stderr, T("%s: file too large for memory-mapping")
T(", switching to streaming\n"), filename);
result = processStream(filename, entParser);
break;
}
free(s);
XML_ParserFree(entParser);
return result;
}
static int
processStream(const XML_Char *filename, XML_Parser parser)
{
/* passing NULL for filename means read intput from stdin */
int fd = 0; /* 0 is the fileno for stdin */
if (filename != NULL) {
fd = topen(filename, O_BINARY|O_RDONLY);
if (fd < 0) {
tperror(filename);
return 0;
}
}
for (;;) {
int nread;
char *buf = (char *)XML_GetBuffer(parser, READ_SIZE);
if (!buf) {
if (filename != NULL)
close(fd);
ftprintf(stderr, T("%s: out of memory\n"),
filename != NULL ? filename : T("xmlwf"));
return 0;
}
nread = read(fd, buf, READ_SIZE);
if (nread < 0) {
tperror(filename != NULL ? filename : T("STDIN"));
if (filename != NULL)
close(fd);
return 0;
}
if (XML_ParseBuffer(parser, nread, nread == 0) == XML_STATUS_ERROR) {
reportError(parser, filename != NULL ? filename : T("STDIN"));
if (filename != NULL)
close(fd);
return 0;
}
if (nread == 0) {
if (filename != NULL)
close(fd);
break;;
}
}
return 1;
}
static int
externalEntityRefStream(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *UNUSED_P(publicId))
{
XML_Char *s;
const XML_Char *filename;
int ret;
XML_Parser entParser = XML_ExternalEntityParserCreate(parser, context, 0);
filename = resolveSystemId(base, systemId, &s);
XML_SetBase(entParser, filename);
ret = processStream(filename, entParser);
free(s);
XML_ParserFree(entParser);
return ret;
}
int
XML_ProcessFile(XML_Parser parser,
const XML_Char *filename,
unsigned flags)
{
int result;
if (!XML_SetBase(parser, filename)) {
ftprintf(stderr, T("%s: out of memory"), filename);
exit(1);
}
if (flags & XML_EXTERNAL_ENTITIES)
XML_SetExternalEntityRefHandler(parser,
(flags & XML_MAP_FILE)
? externalEntityRefFilemap
: externalEntityRefStream);
if (flags & XML_MAP_FILE) {
int filemapRes;
PROCESS_ARGS args;
args.retPtr = &result;
args.parser = parser;
filemapRes = filemap(filename, processFile, &args);
switch (filemapRes) {
case 0:
result = 0;
break;
case 2:
ftprintf(stderr, T("%s: file too large for memory-mapping")
T(", switching to streaming\n"), filename);
result = processStream(filename, parser);
break;
}
}
else
result = processStream(filename, parser);
return result;
}

View File

@ -0,0 +1,48 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#define XML_MAP_FILE 01
#define XML_EXTERNAL_ENTITIES 02
#ifdef XML_LARGE_SIZE
#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
#define XML_FMT_INT_MOD "I64"
#else
#define XML_FMT_INT_MOD "ll"
#endif
#else
#define XML_FMT_INT_MOD "l"
#endif
extern int XML_ProcessFile(XML_Parser parser,
const XML_Char *filename,
unsigned flags);

View File

@ -0,0 +1,197 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#include <string.h>
#include "xmlmime.h"
static const char *
getTok(const char **pp)
{
/* inComment means one level of nesting; inComment+1 means two levels etc */
enum { inAtom, inString, init, inComment };
int state = init;
const char *tokStart = 0;
for (;;) {
switch (**pp) {
case '\0':
if (state == inAtom)
return tokStart;
return 0;
case ' ':
case '\r':
case '\t':
case '\n':
if (state == inAtom)
return tokStart;
break;
case '(':
if (state == inAtom)
return tokStart;
if (state != inString)
state++;
break;
case ')':
if (state > init)
--state;
else if (state != inString)
return 0;
break;
case ';':
case '/':
case '=':
if (state == inAtom)
return tokStart;
if (state == init)
return (*pp)++;
break;
case '\\':
++*pp;
if (**pp == '\0')
return 0;
break;
case '"':
switch (state) {
case inString:
++*pp;
return tokStart;
case inAtom:
return tokStart;
case init:
tokStart = *pp;
state = inString;
break;
}
break;
default:
if (state == init) {
tokStart = *pp;
state = inAtom;
}
break;
}
++*pp;
}
/* not reached */
}
/* key must be lowercase ASCII */
static int
matchkey(const char *start, const char *end, const char *key)
{
if (!start)
return 0;
for (; start != end; start++, key++)
if (*start != *key && *start != 'A' + (*key - 'a'))
return 0;
return *key == '\0';
}
void
getXMLCharset(const char *buf, char *charset)
{
const char *next, *p;
charset[0] = '\0';
next = buf;
p = getTok(&next);
if (matchkey(p, next, "text"))
strcpy(charset, "us-ascii");
else if (!matchkey(p, next, "application"))
return;
p = getTok(&next);
if (!p || *p != '/')
return;
p = getTok(&next);
/* BEGIN disabled code */
if (0) {
if (!matchkey(p, next, "xml") && charset[0] == '\0')
return;
}
/* END disabled code */
p = getTok(&next);
while (p) {
if (*p == ';') {
p = getTok(&next);
if (matchkey(p, next, "charset")) {
p = getTok(&next);
if (p && *p == '=') {
p = getTok(&next);
if (p) {
char *s = charset;
if (*p == '"') {
while (++p != next - 1) {
if (*p == '\\')
++p;
if (s == charset + CHARSET_MAX - 1) {
charset[0] = '\0';
break;
}
*s++ = *p;
}
*s++ = '\0';
}
else {
if (next - p > CHARSET_MAX - 1)
break;
while (p != next)
*s++ = *p++;
*s = 0;
break;
}
}
}
break;
}
}
else
p = getTok(&next);
}
}
#ifdef TEST
#include <stdio.h>
int
main(int argc, char *argv[])
{
char buf[CHARSET_MAX];
if (argc <= 1)
return 1;
printf("%s\n", argv[1]);
getXMLCharset(argv[1], buf);
printf("charset=\"%s\"\n", buf);
return 0;
}
#endif /* TEST */

View File

@ -0,0 +1,51 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#ifdef __cplusplus
extern "C" {
#endif
/* Registered charset names are at most 40 characters long. */
#define CHARSET_MAX 41
/* Figure out the charset to use from the ContentType.
buf contains the body of the header field (the part after "Content-Type:").
charset gets the charset to use. It must be at least CHARSET_MAX chars
long. charset will be empty if the default charset should be used.
*/
void getXMLCharset(const char *buf, char *charset);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,74 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
/* Ensures compile-time constants are consistent */
#include "expat_external.h"
#ifdef XML_UNICODE
# ifndef XML_UNICODE_WCHAR_T
# error xmlwf requires a 16-bit Unicode-compatible wchar_t
# endif
# define _PREPEND_BIG_L(x) L ## x
# define T(x) _PREPEND_BIG_L(x)
# define ftprintf fwprintf
# define tfopen _wfopen
# define fputts fputws
# define puttc putwc
# define tcscmp wcscmp
# define tcscpy wcscpy
# define tcscat wcscat
# define tcschr wcschr
# define tcsrchr wcsrchr
# define tcslen wcslen
# define tperror _wperror
# define topen _wopen
# define tmain wmain
# define tremove _wremove
# define tchar wchar_t
#else /* not XML_UNICODE */
# define T(x) x
# define ftprintf fprintf
# define tfopen fopen
# define fputts fputs
# define puttc putc
# define tcscmp strcmp
# define tcscpy strcpy
# define tcscat strcat
# define tcschr strchr
# define tcsrchr strrchr
# define tcslen strlen
# define tperror perror
# define topen open
# define tmain main
# define tremove remove
# define tchar char
#endif /* not XML_UNICODE */

View File

@ -0,0 +1,45 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#ifdef __cplusplus
extern "C" {
#endif
int XML_URLInit();
void XML_URLUninit();
int XML_ProcessURL(XML_Parser parser,
const XML_Char *url,
unsigned flags);
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Template|Win32">
<Configuration>Template</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<SccProjectName />
<SccLocalPath />
<ProjectGuid>{E3C5991F-5238-4168-A179-275D1AC98D7E}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Template|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v141</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v141</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Template|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>.\..\win32\bin\Release\</OutDir>
<IntDir>.\..\win32\tmp\Release-xmlwf\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\..\win32\bin\Debug\</OutDir>
<IntDir>.\..\win32\tmp\Debug-xmlwf\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<StringPooling>true</StringPooling>
<FunctionLevelLinking>true</FunctionLevelLinking>
<Optimization>MaxSpeed</Optimization>
<SuppressStartupBanner>true</SuppressStartupBanner>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>..\lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>.\..\win32\tmp\Release-xmlwf\</AssemblerListingLocation>
<PrecompiledHeaderOutputFile>.\..\win32\tmp\Release-xmlwf\xmlwf.pch</PrecompiledHeaderOutputFile>
<PrecompiledHeader />
<ObjectFileName>.\..\win32\tmp\Release-xmlwf\</ObjectFileName>
<ProgramDataBaseFileName>.\..\win32\tmp\Release-xmlwf\</ProgramDataBaseFileName>
</ClCompile>
<Midl>
<TypeLibraryName>.\..\win32\bin\Release\xmlwf.tlb</TypeLibraryName>
</Midl>
<ResourceCompile>
<Culture>0x0409</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
<OutputFile>.\..\win32\bin\Release\xmlwf.bsc</OutputFile>
</Bscmake>
<Link>
<SuppressStartupBanner>true</SuppressStartupBanner>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<OutputFile>..\win32\bin\Release\xmlwf.exe</OutputFile>
<AdditionalLibraryDirectories>..\win32\bin\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libexpat.lib;setargv.obj;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<FunctionLevelLinking>true</FunctionLevelLinking>
<Optimization>Disabled</Optimization>
<SuppressStartupBanner>true</SuppressStartupBanner>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<AdditionalIncludeDirectories>..\lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>.\..\win32\tmp\Debug-xmlwf\</AssemblerListingLocation>
<PrecompiledHeaderOutputFile>.\..\win32\tmp\Debug-xmlwf\xmlwf.pch</PrecompiledHeaderOutputFile>
<ObjectFileName>.\..\win32\tmp\Debug-xmlwf\</ObjectFileName>
<ProgramDataBaseFileName>.\..\win32\tmp\Debug-xmlwf\</ProgramDataBaseFileName>
</ClCompile>
<Midl>
<TypeLibraryName>.\..\win32\bin\Debug\xmlwf.tlb</TypeLibraryName>
</Midl>
<ResourceCompile>
<Culture>0x0409</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
<OutputFile>.\..\win32\bin\Debug\xmlwf.bsc</OutputFile>
</Bscmake>
<Link>
<SuppressStartupBanner>true</SuppressStartupBanner>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OutputFile>..\win32\bin\Debug\xmlwf.exe</OutputFile>
<AdditionalLibraryDirectories>..\win32\bin\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libexpat.lib;setargv.obj;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="codepage.c" />
<ClCompile Include="readfilemap.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="unixfilemap.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="win32filemap.c" />
<ClCompile Include="xmlfile.c" />
<ClCompile Include="xmlwf.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="codepage.h" />
<ClInclude Include="xmlfile.h" />
<ClInclude Include="xmltchar.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\lib\expat.vcxproj">
<Project>{45a5074d-66e8-44a4-a03f-018027b528d6}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{843deb01-ec59-4070-9fb7-4de851940fbd}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{41225059-d26f-42fd-9d1b-fda760b7e45d}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;fi;fd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{a722469e-558e-4d77-b8ea-88c9f136e29a}</UniqueIdentifier>
<Extensions>ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="codepage.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="readfilemap.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="unixfilemap.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="win32filemap.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="xmlfile.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="xmlwf.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="codepage.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="xmlfile.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="xmltchar.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,427 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
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.
*/
#include "expat.h"
#ifdef XML_UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <urlmon.h>
#include <wininet.h>
#include <stdio.h>
#include <tchar.h>
#include "xmlurl.h"
#include "xmlmime.h"
static int
processURL(XML_Parser parser, IMoniker *baseMoniker, const XML_Char *url);
typedef void (*StopHandler)(void *, HRESULT);
class Callback : public IBindStatusCallback {
public:
// IUnknown methods
STDMETHODIMP QueryInterface(REFIID,void **);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
// IBindStatusCallback methods
STDMETHODIMP OnStartBinding(DWORD, IBinding *);
STDMETHODIMP GetPriority(LONG *);
STDMETHODIMP OnLowResource(DWORD);
STDMETHODIMP OnProgress(ULONG, ULONG, ULONG, LPCWSTR);
STDMETHODIMP OnStopBinding(HRESULT, LPCWSTR);
STDMETHODIMP GetBindInfo(DWORD *, BINDINFO *);
STDMETHODIMP OnDataAvailable(DWORD, DWORD, FORMATETC *, STGMEDIUM *);
STDMETHODIMP OnObjectAvailable(REFIID, IUnknown *);
Callback(XML_Parser, IMoniker *, StopHandler, void *);
~Callback();
int externalEntityRef(const XML_Char *context,
const XML_Char *systemId, const XML_Char *publicId);
private:
XML_Parser parser_;
IMoniker *baseMoniker_;
DWORD totalRead_;
ULONG ref_;
IBinding *pBinding_;
StopHandler stopHandler_;
void *stopArg_;
};
STDMETHODIMP_(ULONG)
Callback::AddRef()
{
return ref_++;
}
STDMETHODIMP_(ULONG)
Callback::Release()
{
if (--ref_ == 0) {
delete this;
return 0;
}
return ref_;
}
STDMETHODIMP
Callback::QueryInterface(REFIID riid, void** ppv)
{
if (IsEqualGUID(riid, IID_IUnknown))
*ppv = (IUnknown *)this;
else if (IsEqualGUID(riid, IID_IBindStatusCallback))
*ppv = (IBindStatusCallback *)this;
else
return E_NOINTERFACE;
((LPUNKNOWN)*ppv)->AddRef();
return S_OK;
}
STDMETHODIMP
Callback::OnStartBinding(DWORD, IBinding* pBinding)
{
pBinding_ = pBinding;
pBinding->AddRef();
return S_OK;
}
STDMETHODIMP
Callback::GetPriority(LONG *)
{
return E_NOTIMPL;
}
STDMETHODIMP
Callback::OnLowResource(DWORD)
{
return E_NOTIMPL;
}
STDMETHODIMP
Callback::OnProgress(ULONG, ULONG, ULONG, LPCWSTR)
{
return S_OK;
}
STDMETHODIMP
Callback::OnStopBinding(HRESULT hr, LPCWSTR szError)
{
if (pBinding_) {
pBinding_->Release();
pBinding_ = 0;
}
if (baseMoniker_) {
baseMoniker_->Release();
baseMoniker_ = 0;
}
stopHandler_(stopArg_, hr);
return S_OK;
}
STDMETHODIMP
Callback::GetBindInfo(DWORD* pgrfBINDF, BINDINFO* pbindinfo)
{
*pgrfBINDF = BINDF_ASYNCHRONOUS;
return S_OK;
}
static void
reportError(XML_Parser parser)
{
int code = XML_GetErrorCode(parser);
const XML_Char *message = XML_ErrorString(code);
if (message)
_ftprintf(stderr, _T("%s:%d:%ld: %s\n"),
XML_GetBase(parser),
XML_GetErrorLineNumber(parser),
XML_GetErrorColumnNumber(parser),
message);
else
_ftprintf(stderr, _T("%s: (unknown message %d)\n"),
XML_GetBase(parser), code);
}
STDMETHODIMP
Callback::OnDataAvailable(DWORD grfBSCF,
DWORD dwSize,
FORMATETC *pfmtetc,
STGMEDIUM* pstgmed)
{
if (grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
IWinInetHttpInfo *hp;
HRESULT hr = pBinding_->QueryInterface(IID_IWinInetHttpInfo,
(void **)&hp);
if (SUCCEEDED(hr)) {
char contentType[1024];
DWORD bufSize = sizeof(contentType);
DWORD flags = 0;
contentType[0] = 0;
hr = hp->QueryInfo(HTTP_QUERY_CONTENT_TYPE, contentType,
&bufSize, 0, NULL);
if (SUCCEEDED(hr)) {
char charset[CHARSET_MAX];
getXMLCharset(contentType, charset);
if (charset[0]) {
#ifdef XML_UNICODE
XML_Char wcharset[CHARSET_MAX];
XML_Char *p1 = wcharset;
const char *p2 = charset;
while ((*p1++ = (unsigned char)*p2++) != 0)
;
XML_SetEncoding(parser_, wcharset);
#else
XML_SetEncoding(parser_, charset);
#endif
}
}
hp->Release();
}
}
if (!parser_)
return E_ABORT;
if (pstgmed->tymed == TYMED_ISTREAM) {
while (totalRead_ < dwSize) {
#define READ_MAX (64*1024)
DWORD nToRead = dwSize - totalRead_;
if (nToRead > READ_MAX)
nToRead = READ_MAX;
void *buf = XML_GetBuffer(parser_, nToRead);
if (!buf) {
_ftprintf(stderr, _T("out of memory\n"));
return E_ABORT;
}
DWORD nRead;
HRESULT hr = pstgmed->pstm->Read(buf, nToRead, &nRead);
if (SUCCEEDED(hr)) {
totalRead_ += nRead;
if (!XML_ParseBuffer(parser_,
nRead,
(grfBSCF & BSCF_LASTDATANOTIFICATION) != 0
&& totalRead_ == dwSize)) {
reportError(parser_);
return E_ABORT;
}
}
}
}
return S_OK;
}
STDMETHODIMP
Callback::OnObjectAvailable(REFIID, IUnknown *)
{
return S_OK;
}
int
Callback::externalEntityRef(const XML_Char *context,
const XML_Char *systemId,
const XML_Char *publicId)
{
XML_Parser entParser = XML_ExternalEntityParserCreate(parser_, context, 0);
XML_SetBase(entParser, systemId);
int ret = processURL(entParser, baseMoniker_, systemId);
XML_ParserFree(entParser);
return ret;
}
Callback::Callback(XML_Parser parser, IMoniker *baseMoniker,
StopHandler stopHandler, void *stopArg)
: parser_(parser),
baseMoniker_(baseMoniker),
ref_(0),
pBinding_(0),
totalRead_(0),
stopHandler_(stopHandler),
stopArg_(stopArg)
{
if (baseMoniker_)
baseMoniker_->AddRef();
}
Callback::~Callback()
{
if (pBinding_)
pBinding_->Release();
if (baseMoniker_)
baseMoniker_->Release();
}
static int
externalEntityRef(void *arg,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId)
{
return ((Callback *)arg)->externalEntityRef(context, systemId, publicId);
}
static HRESULT
openStream(XML_Parser parser,
IMoniker *baseMoniker,
const XML_Char *uri,
StopHandler stopHandler, void *stopArg)
{
if (!XML_SetBase(parser, uri))
return E_OUTOFMEMORY;
HRESULT hr;
IMoniker *m;
#ifdef XML_UNICODE
hr = CreateURLMoniker(0, uri, &m);
#else
LPWSTR uriw = new wchar_t[strlen(uri) + 1];
for (int i = 0;; i++) {
uriw[i] = uri[i];
if (uriw[i] == 0)
break;
}
hr = CreateURLMoniker(baseMoniker, uriw, &m);
delete [] uriw;
#endif
if (FAILED(hr))
return hr;
IBindStatusCallback *cb = new Callback(parser, m, stopHandler, stopArg);
XML_SetExternalEntityRefHandler(parser, externalEntityRef);
XML_SetExternalEntityRefHandlerArg(parser, cb);
cb->AddRef();
IBindCtx *b;
if (FAILED(hr = CreateAsyncBindCtx(0, cb, 0, &b))) {
cb->Release();
m->Release();
return hr;
}
cb->Release();
IStream *pStream;
hr = m->BindToStorage(b, 0, IID_IStream, (void **)&pStream);
if (SUCCEEDED(hr)) {
if (pStream)
pStream->Release();
}
if (hr == MK_S_ASYNCHRONOUS)
hr = S_OK;
m->Release();
b->Release();
return hr;
}
struct QuitInfo {
const XML_Char *url;
HRESULT hr;
int stop;
};
static void
winPerror(const XML_Char *url, HRESULT hr)
{
LPVOID buf;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE,
GetModuleHandleA("urlmon.dll"),
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &buf,
0,
NULL)
|| FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM,
0,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &buf,
0,
NULL)) {
/* The system error messages seem to end with a newline. */
_ftprintf(stderr, _T("%s: %s"), url, buf);
fflush(stderr);
LocalFree(buf);
}
else
_ftprintf(stderr, _T("%s: error %x\n"), url, hr);
}
static void
threadQuit(void *p, HRESULT hr)
{
QuitInfo *qi = (QuitInfo *)p;
qi->hr = hr;
qi->stop = 1;
}
extern "C"
int
XML_URLInit(void)
{
return SUCCEEDED(CoInitialize(0));
}
extern "C"
void
XML_URLUninit(void)
{
CoUninitialize();
}
static int
processURL(XML_Parser parser, IMoniker *baseMoniker,
const XML_Char *url)
{
QuitInfo qi;
qi.stop = 0;
qi.url = url;
XML_SetBase(parser, url);
HRESULT hr = openStream(parser, baseMoniker, url, threadQuit, &qi);
if (FAILED(hr)) {
winPerror(url, hr);
return 0;
}
else if (FAILED(qi.hr)) {
winPerror(url, qi.hr);
return 0;
}
MSG msg;
while (!qi.stop && GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return 1;
}
extern "C"
int
XML_ProcessURL(XML_Parser parser,
const XML_Char *url,
unsigned flags)
{
return processURL(parser, 0, url);
}