diff options
author | Haibo Huang <hhb@google.com> | 2019-10-11 11:13:39 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2019-11-13 10:28:10 -0800 |
commit | 40a7191d8057597978b149621d2882ca507d8cb5 (patch) | |
tree | e8d918e4285a965f916def290385a0614313bde1 /xmlwf | |
parent | 4c60b0d92a62545fa2ff75f7cac070df04a59bdf (diff) | |
download | expat-40a7191d8057597978b149621d2882ca507d8cb5.tar.gz |
Upgrade expat to R_2_2_9
Manual changes to Android.bp and expat_config.h.
Test: treehugger
Change-Id: Iba9d1ed11fadaf15b95a9e94cbc128e77f3aea6d
Diffstat (limited to 'xmlwf')
-rw-r--r-- | xmlwf/Makefile.am | 4 | ||||
-rw-r--r-- | xmlwf/Makefile.in | 4 | ||||
-rw-r--r-- | xmlwf/codepage.c | 48 | ||||
-rw-r--r-- | xmlwf/ct.c | 26 | ||||
-rw-r--r-- | xmlwf/filemap.h | 12 | ||||
-rw-r--r-- | xmlwf/readfilemap.c | 59 | ||||
-rw-r--r-- | xmlwf/unixfilemap.c | 17 | ||||
-rw-r--r-- | xmlwf/win32filemap.c | 35 | ||||
-rw-r--r-- | xmlwf/xmlfile.c | 129 | ||||
-rw-r--r-- | xmlwf/xmlfile.h | 11 | ||||
-rw-r--r-- | xmlwf/xmlmime.c | 34 | ||||
-rw-r--r-- | xmlwf/xmltchar.h | 72 | ||||
-rw-r--r-- | xmlwf/xmlurl.h | 45 | ||||
-rw-r--r-- | xmlwf/xmlwf.c | 404 | ||||
-rw-r--r-- | xmlwf/xmlwf.vcxproj | 164 | ||||
-rw-r--r-- | xmlwf/xmlwf.vcxproj.filters | 48 | ||||
-rwxr-xr-x | xmlwf/xmlwf_helpgen.py | 69 | ||||
-rwxr-xr-x | xmlwf/xmlwf_helpgen.sh | 35 | ||||
-rw-r--r-- | xmlwf/xmlwin32url.cxx | 427 |
19 files changed, 501 insertions, 1142 deletions
diff --git a/xmlwf/Makefile.am b/xmlwf/Makefile.am index ff460902..4b41c2cb 100644 --- a/xmlwf/Makefile.am +++ b/xmlwf/Makefile.am @@ -56,6 +56,4 @@ EXTRA_DIST = \ xmlfile.h \ xmlmime.c \ xmlmime.h \ - xmltchar.h \ - xmlurl.h \ - xmlwin32url.cxx + xmltchar.h diff --git a/xmlwf/Makefile.in b/xmlwf/Makefile.in index 441260d1..368d3777 100644 --- a/xmlwf/Makefile.in +++ b/xmlwf/Makefile.in @@ -365,9 +365,7 @@ EXTRA_DIST = \ xmlfile.h \ xmlmime.c \ xmlmime.h \ - xmltchar.h \ - xmlurl.h \ - xmlwin32url.cxx + xmltchar.h all: all-am diff --git a/xmlwf/codepage.c b/xmlwf/codepage.c index 1a0487ff..1095adf6 100644 --- a/xmlwf/codepage.c +++ b/xmlwf/codepage.c @@ -31,25 +31,24 @@ */ #include "codepage.h" -#include "internal.h" /* for UNUSED_P only */ +#include "internal.h" /* for UNUSED_P only */ #if defined(_WIN32) -#define STRICT 1 -#define WIN32_LEAN_AND_MEAN 1 +# define STRICT 1 +# define WIN32_LEAN_AND_MEAN 1 -#include <windows.h> +# include <windows.h> int -codepageMap(int cp, int *map) -{ +codepageMap(int cp, int *map) { int i; CPINFO info; - if (!GetCPInfo(cp, &info) || info.MaxCharSize > 2) + 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) { + for (i = 0; i < MAX_LEADBYTES; i += 2) { int j, lim; if (info.LeadByte[i] == 0 && info.LeadByte[i + 1] == 0) break; @@ -59,23 +58,24 @@ codepageMap(int cp, int *map) } } 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; - } + 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) -{ +codepageConvert(int cp, const char *p) { unsigned short c; - if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, - p, 2, &c, 1) == 1) + if (MultiByteToWideChar(cp, MB_PRECOMPOSED | MB_ERR_INVALID_CHARS, p, 2, &c, + 1) + == 1) return c; return -1; } @@ -83,14 +83,16 @@ codepageConvert(int cp, const char *p) #else /* not _WIN32 */ int -codepageMap(int UNUSED_P(cp), int *UNUSED_P(map)) -{ +codepageMap(int cp, int *map) { + UNUSED_P(cp); + UNUSED_P(map); return 0; } int -codepageConvert(int UNUSED_P(cp), const char *UNUSED_P(p)) -{ +codepageConvert(int cp, const char *p) { + UNUSED_P(cp); + UNUSED_P(p); return -1; } @@ -33,8 +33,7 @@ #define CHARSET_MAX 41 static const char * -getTok(const char **pp) -{ +getTok(const char **pp) { enum { inAtom, inString, init, inComment }; int state = init; const char *tokStart = 0; @@ -102,9 +101,8 @@ getTok(const char **pp) /* key must be lowercase ASCII */ static int -matchkey(const char *start, const char *end, const char *key) -{ - if (!start) +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')) @@ -113,8 +111,7 @@ matchkey(const char *start, const char *end, const char *key) } void -getXMLCharset(const char *buf, char *charset) -{ +getXMLCharset(const char *buf, char *charset) { const char *next, *p; charset[0] = '\0'; @@ -122,10 +119,10 @@ getXMLCharset(const char *buf, char *charset) p = getTok(&next); if (matchkey(p, next, "text")) strcpy(charset, "us-ascii"); - else if (!matchkey(p, next, "application")) + else if (! matchkey(p, next, "application")) return; p = getTok(&next); - if (!p || *p != '/') + if (! p || *p != '/') return; p = getTok(&next); if (matchkey(p, next, "xml")) @@ -151,8 +148,7 @@ getXMLCharset(const char *buf, char *charset) *s++ = *p; } *s++ = '\0'; - } - else { + } else { if (next - p > CHARSET_MAX - 1) break; while (p != next) @@ -163,15 +159,13 @@ getXMLCharset(const char *buf, char *charset) } } } - } - else - p = getTok(&next); + } else + p = getTok(&next); } } int -main(int argc, char **argv) -{ +main(int argc, char **argv) { char buf[CHARSET_MAX]; getXMLCharset(argv[1], buf); printf("charset = \"%s\"\n", buf); diff --git a/xmlwf/filemap.h b/xmlwf/filemap.h index 5487a4eb..ef661144 100644 --- a/xmlwf/filemap.h +++ b/xmlwf/filemap.h @@ -30,10 +30,9 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include <limits.h> /* INT_MAX */ +#include <limits.h> /* INT_MAX */ #include <stddef.h> - /* The following limit (for XML_Parse's int len) derives from * this loop in xmparse.c: * @@ -41,17 +40,14 @@ * bufferSize = (int) (2U * (unsigned) bufferSize); * } while (bufferSize < neededSize && bufferSize > 0); */ -#define XML_MAX_CHUNK_LEN (INT_MAX / 2 + 1) - +#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 (*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 (*processor)(const void *, size_t, const char *, void *arg), void *arg); #endif diff --git a/xmlwf/readfilemap.c b/xmlwf/readfilemap.c index 4c4780bd..d5b84f99 100644 --- a/xmlwf/readfilemap.c +++ b/xmlwf/readfilemap.c @@ -37,40 +37,40 @@ #include <stdio.h> /* Functions close(2) and read(2) */ -#if !defined(_WIN32) && !defined(_WIN64) -# include <unistd.h> +#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 +# 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) +# 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 +# ifdef _O_BINARY +# define O_BINARY _O_BINARY +# else +# define O_BINARY 0 +# endif #endif #include "xmltchar.h" @@ -79,15 +79,14 @@ int filemap(const tchar *name, void (*processor)(const void *, size_t, const tchar *, void *arg), - 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); + fd = topen(name, O_RDONLY | O_BINARY); if (fd < 0) { tperror(name); return 0; @@ -97,14 +96,14 @@ filemap(const tchar *name, close(fd); return 0; } - if (!S_ISREG(sb.st_mode)) { + 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 */ + return 2; /* Cannot be passed to XML_Parse in one go */ } nbytes = sb.st_size; @@ -116,7 +115,7 @@ filemap(const tchar *name, return 1; } p = malloc(nbytes); - if (!p) { + if (! p) { ftprintf(stderr, T("%s: out of memory\n"), name); close(fd); return 0; diff --git a/xmlwf/unixfilemap.c b/xmlwf/unixfilemap.c index 4ab757c2..0d0dc042 100644 --- a/xmlwf/unixfilemap.c +++ b/xmlwf/unixfilemap.c @@ -40,23 +40,22 @@ #include <unistd.h> #ifndef MAP_FILE -#define MAP_FILE 0 +# define MAP_FILE 0 #endif #include "xmltchar.h" #include "filemap.h" #ifdef XML_UNICODE_WCHAR_T -# define XML_FMT_STR "ls" +# define XML_FMT_STR "ls" #else -# define XML_FMT_STR "s" +# define XML_FMT_STR "s" #endif int filemap(const tchar *name, void (*processor)(const void *, size_t, const tchar *, void *arg), - void *arg) -{ + void *arg) { int fd; size_t nbytes; struct stat sb; @@ -72,14 +71,14 @@ filemap(const tchar *name, close(fd); return 0; } - if (!S_ISREG(sb.st_mode)) { + 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 */ + return 2; /* Cannot be passed to XML_Parse in one go */ } nbytes = sb.st_size; @@ -90,8 +89,8 @@ filemap(const tchar *name, close(fd); return 1; } - p = (void *)mmap((void *)0, (size_t)nbytes, PROT_READ, - MAP_FILE|MAP_PRIVATE, fd, (off_t)0); + 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); diff --git a/xmlwf/win32filemap.c b/xmlwf/win32filemap.c index a040a097..0c9b7ecc 100644 --- a/xmlwf/win32filemap.c +++ b/xmlwf/win32filemap.c @@ -34,14 +34,14 @@ #define WIN32_LEAN_AND_MEAN 1 #ifdef XML_UNICODE_WCHAR_T -# ifndef XML_UNICODE -# define XML_UNICODE -# endif +# ifndef XML_UNICODE +# define XML_UNICODE +# endif #endif #ifdef XML_UNICODE -# define UNICODE -# define _UNICODE +# define UNICODE +# define _UNICODE #endif /* XML_UNICODE */ #include <windows.h> #include <stdio.h> @@ -53,8 +53,7 @@ static void win32perror(const TCHAR *); int filemap(const TCHAR *name, void (*processor)(const void *, size_t, const TCHAR *, void *arg), - void *arg) -{ + void *arg) { HANDLE f; HANDLE m; DWORD size; @@ -62,7 +61,7 @@ filemap(const TCHAR *name, void *p; f = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, - FILE_FLAG_SEQUENTIAL_SCAN, NULL); + FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (f == INVALID_HANDLE_VALUE) { win32perror(name); return 0; @@ -75,7 +74,7 @@ filemap(const TCHAR *name, } if (sizeHi || (size > XML_MAX_CHUNK_LEN)) { CloseHandle(f); - return 2; /* Cannot be passed to XML_Parse in one go */ + return 2; /* Cannot be passed to XML_Parse in one go */ } /* CreateFileMapping barfs on zero length files */ if (size == 0) { @@ -97,7 +96,7 @@ filemap(const TCHAR *name, CloseHandle(f); return 0; } - processor(p, size, name, arg); + processor(p, size, name, arg); UnmapViewOfFile(p); CloseHandle(m); CloseHandle(f); @@ -105,21 +104,15 @@ filemap(const TCHAR *name, } static void -win32perror(const TCHAR *s) -{ +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, + 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 + } else _ftprintf(stderr, _T("%s: unknown Windows error\n"), s); } diff --git a/xmlwf/xmlfile.c b/xmlwf/xmlfile.c index 4075f571..922e18b0 100644 --- a/xmlwf/xmlfile.c +++ b/xmlwf/xmlfile.c @@ -37,87 +37,77 @@ #include <fcntl.h> #ifdef _WIN32 -#include "winconfig.h" +# include "winconfig.h" #elif defined(HAVE_EXPAT_CONFIG_H) -#include <expat_config.h> +# include <expat_config.h> #endif /* ndef _WIN32 */ #include "expat.h" -#include "internal.h" /* for UNUSED_P only */ +#include "internal.h" /* for UNUSED_P only */ #include "xmlfile.h" #include "xmltchar.h" #include "filemap.h" #if defined(_MSC_VER) -#include <io.h> +# include <io.h> #endif #ifdef HAVE_UNISTD_H -#include <unistd.h> +# include <unistd.h> #endif #ifndef O_BINARY -#ifdef _O_BINARY -#define O_BINARY _O_BINARY -#else -#define O_BINARY 0 -#endif +# ifdef _O_BINARY +# define O_BINARY _O_BINARY +# else +# define O_BINARY 0 +# endif #endif #ifdef _DEBUG -#define READ_SIZE 16 +# define READ_SIZE 16 #else -#define READ_SIZE (1024*8) +# 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 int processStream(const XML_Char *filename, XML_Parser parser); static void -reportError(XML_Parser parser, const XML_Char *filename) -{ +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); + 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) -{ +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 + } else *retPtr = 1; } #if defined(_WIN32) static int -isAsciiLetter(XML_Char c) -{ +isAsciiLetter(XML_Char c) { return (T('a') <= c && c <= T('z')) || (T('A') <= c && c <= T('Z')); } @@ -125,21 +115,19 @@ isAsciiLetter(XML_Char c) static const XML_Char * resolveSystemId(const XML_Char *base, const XML_Char *systemId, - XML_Char **toFree) -{ + XML_Char **toFree) { XML_Char *s; *toFree = 0; - if (!base - || *systemId == T('/') + 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) + if (! *toFree) return systemId; tcscpy(*toFree, base); s = *toFree; @@ -154,18 +142,16 @@ resolveSystemId(const XML_Char *base, const XML_Char *systemId, } static int -externalEntityRefFilemap(XML_Parser parser, - const XML_Char *context, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *UNUSED_P(publicId)) -{ +externalEntityRefFilemap(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { int result; XML_Char *s; const XML_Char *filename; XML_Parser entParser = XML_ExternalEntityParserCreate(parser, context, 0); int filemapRes; PROCESS_ARGS args; + UNUSED_P(publicId); args.retPtr = &result; args.parser = entParser; filename = resolveSystemId(base, systemId, &s); @@ -176,8 +162,10 @@ externalEntityRefFilemap(XML_Parser parser, result = 0; break; case 2: - ftprintf(stderr, T("%s: file too large for memory-mapping") - T(", switching to streaming\n"), filename); + ftprintf(stderr, + T("%s: file too large for memory-mapping") + T(", switching to streaming\n"), + filename); result = processStream(filename, entParser); break; } @@ -187,13 +175,12 @@ externalEntityRefFilemap(XML_Parser parser, } static int -processStream(const XML_Char *filename, XML_Parser parser) -{ +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 */ + int fd = 0; /* 0 is the fileno for stdin */ if (filename != NULL) { - fd = topen(filename, O_BINARY|O_RDONLY); + fd = topen(filename, O_BINARY | O_RDONLY); if (fd < 0) { tperror(filename); return 0; @@ -202,7 +189,7 @@ processStream(const XML_Char *filename, XML_Parser parser) for (;;) { int nread; char *buf = (char *)XML_GetBuffer(parser, READ_SIZE); - if (!buf) { + if (! buf) { if (filename != NULL) close(fd); ftprintf(stderr, T("%s: out of memory\n"), @@ -217,7 +204,7 @@ processStream(const XML_Char *filename, XML_Parser parser) return 0; } if (XML_ParseBuffer(parser, nread, nread == 0) == XML_STATUS_ERROR) { - reportError(parser, filename != NULL ? filename : T("STDIN")); + reportError(parser, filename != NULL ? filename : T("STDIN")); if (filename != NULL) close(fd); return 0; @@ -225,23 +212,22 @@ processStream(const XML_Char *filename, XML_Parser parser) if (nread == 0) { if (filename != NULL) close(fd); - break;; + 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)) -{ +externalEntityRefStream(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { XML_Char *s; const XML_Char *filename; int ret; XML_Parser entParser = XML_ExternalEntityParserCreate(parser, context, 0); + UNUSED_P(publicId); filename = resolveSystemId(base, systemId, &s); XML_SetBase(entParser, filename); ret = processStream(filename, entParser); @@ -251,22 +237,18 @@ externalEntityRefStream(XML_Parser parser, } int -XML_ProcessFile(XML_Parser parser, - const XML_Char *filename, - unsigned flags) -{ +XML_ProcessFile(XML_Parser parser, const XML_Char *filename, unsigned flags) { int result; - if (!XML_SetBase(parser, filename)) { + 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); + XML_SetExternalEntityRefHandler(parser, (flags & XML_MAP_FILE) + ? externalEntityRefFilemap + : externalEntityRefStream); if (flags & XML_MAP_FILE) { int filemapRes; PROCESS_ARGS args; @@ -278,13 +260,14 @@ XML_ProcessFile(XML_Parser parser, result = 0; break; case 2: - ftprintf(stderr, T("%s: file too large for memory-mapping") - T(", switching to streaming\n"), filename); + ftprintf(stderr, + T("%s: file too large for memory-mapping") + T(", switching to streaming\n"), + filename); result = processStream(filename, parser); break; } - } - else + } else result = processStream(filename, parser); return result; } diff --git a/xmlwf/xmlfile.h b/xmlwf/xmlfile.h index c47ea2cf..6e5d5b49 100644 --- a/xmlwf/xmlfile.h +++ b/xmlwf/xmlfile.h @@ -34,15 +34,10 @@ #define XML_EXTERNAL_ENTITIES 02 #ifdef XML_LARGE_SIZE -#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400 -#define XML_FMT_INT_MOD "I64" +# define XML_FMT_INT_MOD "ll" #else -#define XML_FMT_INT_MOD "ll" -#endif -#else -#define XML_FMT_INT_MOD "l" +# define XML_FMT_INT_MOD "l" #endif -extern int XML_ProcessFile(XML_Parser parser, - const XML_Char *filename, +extern int XML_ProcessFile(XML_Parser parser, const XML_Char *filename, unsigned flags); diff --git a/xmlwf/xmlmime.c b/xmlwf/xmlmime.c index 26f4f801..39160d71 100644 --- a/xmlwf/xmlmime.c +++ b/xmlwf/xmlmime.c @@ -34,8 +34,7 @@ #include "xmlmime.h" static const char * -getTok(const char **pp) -{ +getTok(const char **pp) { /* inComment means one level of nesting; inComment+1 means two levels etc */ enum { inAtom, inString, init, inComment }; int state = init; @@ -106,9 +105,8 @@ getTok(const char **pp) /* key must be lowercase ASCII */ static int -matchkey(const char *start, const char *end, const char *key) -{ - if (!start) +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')) @@ -117,8 +115,7 @@ matchkey(const char *start, const char *end, const char *key) } void -getXMLCharset(const char *buf, char *charset) -{ +getXMLCharset(const char *buf, char *charset) { const char *next, *p; charset[0] = '\0'; @@ -126,18 +123,18 @@ getXMLCharset(const char *buf, char *charset) p = getTok(&next); if (matchkey(p, next, "text")) strcpy(charset, "us-ascii"); - else if (!matchkey(p, next, "application")) + else if (! matchkey(p, next, "application")) return; p = getTok(&next); - if (!p || *p != '/') + if (! p || *p != '/') return; p = getTok(&next); -/* BEGIN disabled code */ + /* BEGIN disabled code */ if (0) { - if (!matchkey(p, next, "xml") && charset[0] == '\0') + if (! matchkey(p, next, "xml") && charset[0] == '\0') return; } -/* END disabled code */ + /* END disabled code */ p = getTok(&next); while (p) { if (*p == ';') { @@ -159,8 +156,7 @@ getXMLCharset(const char *buf, char *charset) *s++ = *p; } *s++ = '\0'; - } - else { + } else { if (next - p > CHARSET_MAX - 1) break; while (p != next) @@ -172,19 +168,17 @@ getXMLCharset(const char *buf, char *charset) } break; } - } - else - p = getTok(&next); + } else + p = getTok(&next); } } #ifdef TEST -#include <stdio.h> +# include <stdio.h> int -main(int argc, char *argv[]) -{ +main(int argc, char *argv[]) { char buf[CHARSET_MAX]; if (argc <= 1) return 1; diff --git a/xmlwf/xmltchar.h b/xmlwf/xmltchar.h index cdfaea79..d7e7b411 100644 --- a/xmlwf/xmltchar.h +++ b/xmlwf/xmltchar.h @@ -34,41 +34,41 @@ #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 +# 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 +# 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 */ diff --git a/xmlwf/xmlurl.h b/xmlwf/xmlurl.h deleted file mode 100644 index f2cff093..00000000 --- a/xmlwf/xmlurl.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - __ __ _ - ___\ \/ /_ __ __ _| |_ - / _ \\ /| '_ \ / _` | __| - | __// \| |_) | (_| | |_ - \___/_/\_\ .__/ \__,_|\__| - |_| 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 diff --git a/xmlwf/xmlwf.c b/xmlwf/xmlwf.c index 82d028ea..2d5a87e7 100644 --- a/xmlwf/xmlwf.c +++ b/xmlwf/xmlwf.c @@ -38,16 +38,16 @@ #include "expat.h" #include "codepage.h" -#include "internal.h" /* for UNUSED_P only */ +#include "internal.h" /* for UNUSED_P only */ #include "xmlfile.h" #include "xmltchar.h" #ifdef _MSC_VER -# include <crtdbg.h> +# include <crtdbg.h> #endif #ifdef XML_UNICODE -# include <wchar.h> +# include <wchar.h> #endif /* Structures for handler user data */ @@ -64,14 +64,12 @@ typedef struct xmlwfUserData { const XML_Char *currentDoctypeName; } XmlwfUserData; - /* This ensures proper sorting. */ #define NSSEP T('\001') static void XMLCALL -characterData(void *userData, const XML_Char *s, int len) -{ +characterData(void *userData, const XML_Char *s, int len) { FILE *fp = ((XmlwfUserData *)userData)->fp; for (; len > 0; --len, ++s) { switch (*s) { @@ -106,8 +104,7 @@ characterData(void *userData, const XML_Char *s, int len) } static void -attributeValue(FILE *fp, const XML_Char *s) -{ +attributeValue(FILE *fp, const XML_Char *s) { puttc(T('='), fp); puttc(T('"'), fp); assert(s); @@ -158,14 +155,12 @@ attributeValue(FILE *fp, const XML_Char *s) is equivalent to lexicographically comparing based on the character number. */ static int -attcmp(const void *att1, const void *att2) -{ +attcmp(const void *att1, const void *att2) { return tcscmp(*(const XML_Char **)att1, *(const XML_Char **)att2); } static void XMLCALL -startElement(void *userData, const XML_Char *name, const XML_Char **atts) -{ +startElement(void *userData, const XML_Char *name, const XML_Char **atts) { int nAtts; const XML_Char **p; FILE *fp = ((XmlwfUserData *)userData)->fp; @@ -188,8 +183,7 @@ startElement(void *userData, const XML_Char *name, const XML_Char **atts) } static void XMLCALL -endElement(void *userData, const XML_Char *name) -{ +endElement(void *userData, const XML_Char *name) { FILE *fp = ((XmlwfUserData *)userData)->fp; puttc(T('<'), fp); puttc(T('/'), fp); @@ -198,8 +192,7 @@ endElement(void *userData, const XML_Char *name) } static int -nsattcmp(const void *p1, const void *p2) -{ +nsattcmp(const void *p1, const void *p2) { const XML_Char *att1 = *(const XML_Char **)p1; const XML_Char *att2 = *(const XML_Char **)p2; int sep1 = (tcsrchr(att1, NSSEP) != 0); @@ -210,8 +203,7 @@ nsattcmp(const void *p1, const void *p2) } static void XMLCALL -startElementNS(void *userData, const XML_Char *name, const XML_Char **atts) -{ +startElementNS(void *userData, const XML_Char *name, const XML_Char **atts) { int nAtts; int nsi; const XML_Char **p; @@ -226,8 +218,7 @@ startElementNS(void *userData, const XML_Char *name, const XML_Char **atts) fputts(T(" xmlns:n1"), fp); attributeValue(fp, name); nsi = 2; - } - else { + } else { fputts(name, fp); nsi = 1; } @@ -245,8 +236,7 @@ startElementNS(void *userData, const XML_Char *name, const XML_Char **atts) if (sep) { ftprintf(fp, T("n%d:"), nsi); fputts(sep + 1, fp); - } - else + } else fputts(name, fp); attributeValue(fp, *atts); if (sep) { @@ -259,8 +249,7 @@ startElementNS(void *userData, const XML_Char *name, const XML_Char **atts) } static void XMLCALL -endElementNS(void *userData, const XML_Char *name) -{ +endElementNS(void *userData, const XML_Char *name) { FILE *fp = ((XmlwfUserData *)userData)->fp; const XML_Char *sep; puttc(T('<'), fp); @@ -269,8 +258,7 @@ endElementNS(void *userData, const XML_Char *name) if (sep) { fputts(T("n1:"), fp); fputts(sep + 1, fp); - } - else + } else fputts(name, fp); puttc(T('>'), fp); } @@ -279,8 +267,7 @@ endElementNS(void *userData, const XML_Char *name) static void XMLCALL processingInstruction(void *userData, const XML_Char *target, - const XML_Char *data) -{ + const XML_Char *data) { FILE *fp = ((XmlwfUserData *)userData)->fp; puttc(T('<'), fp); puttc(T('?'), fp); @@ -291,9 +278,8 @@ processingInstruction(void *userData, const XML_Char *target, puttc(T('>'), fp); } - -static XML_Char *xcsdup(const XML_Char *s) -{ +static XML_Char * +xcsdup(const XML_Char *s) { XML_Char *result; int count = 0; int numBytes; @@ -311,19 +297,18 @@ static XML_Char *xcsdup(const XML_Char *s) } static void XMLCALL -startDoctypeDecl(void *userData, - const XML_Char *doctypeName, - const XML_Char *UNUSED_P(sysid), - const XML_Char *UNUSED_P(publid), - int UNUSED_P(has_internal_subset)) -{ +startDoctypeDecl(void *userData, const XML_Char *doctypeName, + const XML_Char *sysid, const XML_Char *publid, + int has_internal_subset) { XmlwfUserData *data = (XmlwfUserData *)userData; + UNUSED_P(sysid); + UNUSED_P(publid); + UNUSED_P(has_internal_subset); data->currentDoctypeName = xcsdup(doctypeName); } static void -freeNotations(XmlwfUserData *data) -{ +freeNotations(XmlwfUserData *data) { NotationList *notationListHead = data->notationListHead; while (notationListHead != NULL) { @@ -337,8 +322,8 @@ freeNotations(XmlwfUserData *data) data->notationListHead = NULL; } -static int xcscmp(const XML_Char *xs, const XML_Char *xt) -{ +static int +xcscmp(const XML_Char *xs, const XML_Char *xt) { while (*xs != 0 && *xt != 0) { if (*xs < *xt) return -1; @@ -355,17 +340,15 @@ static int xcscmp(const XML_Char *xs, const XML_Char *xt) } static int -notationCmp(const void *a, const void *b) -{ - const NotationList * const n1 = *(NotationList **)a; - const NotationList * const n2 = *(NotationList **)b; +notationCmp(const void *a, const void *b) { + const NotationList *const n1 = *(NotationList **)a; + const NotationList *const n2 = *(NotationList **)b; return xcscmp(n1->notationName, n2->notationName); } static void XMLCALL -endDoctypeDecl(void *userData) -{ +endDoctypeDecl(void *userData) { XmlwfUserData *data = (XmlwfUserData *)userData; NotationList **notations; int notationCount = 0; @@ -389,9 +372,7 @@ endDoctypeDecl(void *userData) return; } - for (p = data->notationListHead, i = 0; - i < notationCount; - p = p->next, i++) { + for (p = data->notationListHead, i = 0; i < notationCount; p = p->next, i++) { notations[i] = p; } qsort(notations, notationCount, sizeof(NotationList *), notationCmp); @@ -415,8 +396,7 @@ endDoctypeDecl(void *userData) fputts(notations[i]->systemId, data->fp); puttc(T('\''), data->fp); } - } - else if (notations[i]->systemId != NULL) { + } else if (notations[i]->systemId != NULL) { fputts(T(" SYSTEM '"), data->fp); fputts(notations[i]->systemId, data->fp); puttc(T('\''), data->fp); @@ -435,16 +415,13 @@ endDoctypeDecl(void *userData) } static void XMLCALL -notationDecl(void *userData, - const XML_Char *notationName, - const XML_Char *UNUSED_P(base), - const XML_Char *systemId, - const XML_Char *publicId) -{ +notationDecl(void *userData, const XML_Char *notationName, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId) { XmlwfUserData *data = (XmlwfUserData *)userData; NotationList *entry = malloc(sizeof(NotationList)); const char *errorMessage = "Unable to store NOTATION for output\n"; + UNUSED_P(base); if (entry == NULL) { fputs(errorMessage, stderr); return; /* Nothing we can really do about this */ @@ -463,8 +440,7 @@ notationDecl(void *userData, free(entry); return; } - } - else { + } else { entry->systemId = NULL; } if (publicId != NULL) { @@ -476,8 +452,7 @@ notationDecl(void *userData, free(entry); return; } - } - else { + } else { entry->publicId = NULL; } @@ -488,101 +463,103 @@ notationDecl(void *userData, #endif /* not W3C14N */ static void XMLCALL -defaultCharacterData(void *userData, const XML_Char *UNUSED_P(s), int UNUSED_P(len)) -{ - XML_DefaultCurrent((XML_Parser) userData); +defaultCharacterData(void *userData, const XML_Char *s, int len) { + UNUSED_P(s); + UNUSED_P(len); + XML_DefaultCurrent((XML_Parser)userData); } static void XMLCALL -defaultStartElement(void *userData, const XML_Char *UNUSED_P(name), - const XML_Char **UNUSED_P(atts)) -{ - XML_DefaultCurrent((XML_Parser) userData); +defaultStartElement(void *userData, const XML_Char *name, + const XML_Char **atts) { + UNUSED_P(name); + UNUSED_P(atts); + XML_DefaultCurrent((XML_Parser)userData); } static void XMLCALL -defaultEndElement(void *userData, const XML_Char *UNUSED_P(name)) -{ - XML_DefaultCurrent((XML_Parser) userData); +defaultEndElement(void *userData, const XML_Char *name) { + UNUSED_P(name); + XML_DefaultCurrent((XML_Parser)userData); } static void XMLCALL -defaultProcessingInstruction(void *userData, const XML_Char *UNUSED_P(target), - const XML_Char *UNUSED_P(data)) -{ - XML_DefaultCurrent((XML_Parser) userData); +defaultProcessingInstruction(void *userData, const XML_Char *target, + const XML_Char *data) { + UNUSED_P(target); + UNUSED_P(data); + XML_DefaultCurrent((XML_Parser)userData); } static void XMLCALL -nopCharacterData(void *UNUSED_P(userData), const XML_Char *UNUSED_P(s), int UNUSED_P(len)) -{ +nopCharacterData(void *userData, const XML_Char *s, int len) { + UNUSED_P(userData); + UNUSED_P(s); + UNUSED_P(len); } static void XMLCALL -nopStartElement(void *UNUSED_P(userData), const XML_Char *UNUSED_P(name), const XML_Char **UNUSED_P(atts)) -{ +nopStartElement(void *userData, const XML_Char *name, const XML_Char **atts) { + UNUSED_P(userData); + UNUSED_P(name); + UNUSED_P(atts); } static void XMLCALL -nopEndElement(void *UNUSED_P(userData), const XML_Char *UNUSED_P(name)) -{ +nopEndElement(void *userData, const XML_Char *name) { + UNUSED_P(userData); + UNUSED_P(name); } static void XMLCALL -nopProcessingInstruction(void *UNUSED_P(userData), const XML_Char *UNUSED_P(target), - const XML_Char *UNUSED_P(data)) -{ +nopProcessingInstruction(void *userData, const XML_Char *target, + const XML_Char *data) { + UNUSED_P(userData); + UNUSED_P(target); + UNUSED_P(data); } static void XMLCALL -markup(void *userData, const XML_Char *s, int len) -{ - FILE *fp = ((XmlwfUserData *)XML_GetUserData((XML_Parser) userData))->fp; +markup(void *userData, const XML_Char *s, int len) { + FILE *fp = ((XmlwfUserData *)XML_GetUserData((XML_Parser)userData))->fp; for (; len > 0; --len, ++s) puttc(*s, fp); } static void -metaLocation(XML_Parser parser) -{ +metaLocation(XML_Parser parser) { const XML_Char *uri = XML_GetBase(parser); FILE *fp = ((XmlwfUserData *)XML_GetUserData(parser))->fp; if (uri) ftprintf(fp, T(" uri=\"%s\""), uri); ftprintf(fp, - T(" byte=\"%") T(XML_FMT_INT_MOD) T("d\"") - T(" nbytes=\"%d\"") - T(" line=\"%") T(XML_FMT_INT_MOD) T("u\"") - T(" col=\"%") T(XML_FMT_INT_MOD) T("u\""), - XML_GetCurrentByteIndex(parser), - XML_GetCurrentByteCount(parser), + T(" byte=\"%") T(XML_FMT_INT_MOD) T("d\"") T(" nbytes=\"%d\"") + T(" line=\"%") T(XML_FMT_INT_MOD) T("u\"") T(" col=\"%") + T(XML_FMT_INT_MOD) T("u\""), + XML_GetCurrentByteIndex(parser), XML_GetCurrentByteCount(parser), XML_GetCurrentLineNumber(parser), XML_GetCurrentColumnNumber(parser)); } static void -metaStartDocument(void *userData) -{ +metaStartDocument(void *userData) { fputts(T("<document>\n"), - ((XmlwfUserData *)XML_GetUserData((XML_Parser) userData))->fp); + ((XmlwfUserData *)XML_GetUserData((XML_Parser)userData))->fp); } static void -metaEndDocument(void *userData) -{ +metaEndDocument(void *userData) { fputts(T("</document>\n"), - ((XmlwfUserData *)XML_GetUserData((XML_Parser) userData))->fp); + ((XmlwfUserData *)XML_GetUserData((XML_Parser)userData))->fp); } static void XMLCALL -metaStartElement(void *userData, const XML_Char *name, - const XML_Char **atts) -{ - XML_Parser parser = (XML_Parser) userData; +metaStartElement(void *userData, const XML_Char *name, const XML_Char **atts) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; const XML_Char **specifiedAttsEnd - = atts + XML_GetSpecifiedAttributeCount(parser); + = atts + XML_GetSpecifiedAttributeCount(parser); const XML_Char **idAttPtr; int idAttIndex = XML_GetIdAttributeIndex(parser); if (idAttIndex < 0) @@ -605,15 +582,13 @@ metaStartElement(void *userData, const XML_Char *name, fputts(T("\"/>\n"), fp); } while (*(atts += 2)); fputts(T("</starttag>\n"), fp); - } - else + } else fputts(T("/>\n"), fp); } static void XMLCALL -metaEndElement(void *userData, const XML_Char *name) -{ - XML_Parser parser = (XML_Parser) userData; +metaEndElement(void *userData, const XML_Char *name) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; ftprintf(fp, T("<endtag name=\"%s\""), name); @@ -623,9 +598,8 @@ metaEndElement(void *userData, const XML_Char *name) static void XMLCALL metaProcessingInstruction(void *userData, const XML_Char *target, - const XML_Char *data) -{ - XML_Parser parser = (XML_Parser) userData; + const XML_Char *data) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *usrData = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = usrData->fp; ftprintf(fp, T("<pi target=\"%s\" data=\""), target); @@ -636,9 +610,8 @@ metaProcessingInstruction(void *userData, const XML_Char *target, } static void XMLCALL -metaComment(void *userData, const XML_Char *data) -{ - XML_Parser parser = (XML_Parser) userData; +metaComment(void *userData, const XML_Char *data) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *usrData = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = usrData->fp; fputts(T("<comment data=\""), fp); @@ -649,9 +622,8 @@ metaComment(void *userData, const XML_Char *data) } static void XMLCALL -metaStartCdataSection(void *userData) -{ - XML_Parser parser = (XML_Parser) userData; +metaStartCdataSection(void *userData) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; fputts(T("<startcdata"), fp); @@ -660,9 +632,8 @@ metaStartCdataSection(void *userData) } static void XMLCALL -metaEndCdataSection(void *userData) -{ - XML_Parser parser = (XML_Parser) userData; +metaEndCdataSection(void *userData) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; fputts(T("<endcdata"), fp); @@ -671,9 +642,8 @@ metaEndCdataSection(void *userData) } static void XMLCALL -metaCharacterData(void *userData, const XML_Char *s, int len) -{ - XML_Parser parser = (XML_Parser) userData; +metaCharacterData(void *userData, const XML_Char *s, int len) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; fputts(T("<chars str=\""), fp); @@ -684,24 +654,23 @@ metaCharacterData(void *userData, const XML_Char *s, int len) } static void XMLCALL -metaStartDoctypeDecl(void *userData, - const XML_Char *doctypeName, - const XML_Char *UNUSED_P(sysid), - const XML_Char *UNUSED_P(pubid), - int UNUSED_P(has_internal_subset)) -{ - XML_Parser parser = (XML_Parser) userData; +metaStartDoctypeDecl(void *userData, const XML_Char *doctypeName, + const XML_Char *sysid, const XML_Char *pubid, + int has_internal_subset) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; + UNUSED_P(sysid); + UNUSED_P(pubid); + UNUSED_P(has_internal_subset); ftprintf(fp, T("<startdoctype name=\"%s\""), doctypeName); metaLocation(parser); fputts(T("/>\n"), fp); } static void XMLCALL -metaEndDoctypeDecl(void *userData) -{ - XML_Parser parser = (XML_Parser) userData; +metaEndDoctypeDecl(void *userData) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; fputts(T("<enddoctype"), fp); @@ -710,15 +679,13 @@ metaEndDoctypeDecl(void *userData) } static void XMLCALL -metaNotationDecl(void *userData, - const XML_Char *notationName, - const XML_Char *UNUSED_P(base), - const XML_Char *systemId, - const XML_Char *publicId) -{ - XML_Parser parser = (XML_Parser) userData; +metaNotationDecl(void *userData, const XML_Char *notationName, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; + UNUSED_P(base); ftprintf(fp, T("<notation name=\"%s\""), notationName); if (publicId) ftprintf(fp, T(" public=\"%s\""), publicId); @@ -731,30 +698,24 @@ metaNotationDecl(void *userData, fputts(T("/>\n"), fp); } - static void XMLCALL -metaEntityDecl(void *userData, - const XML_Char *entityName, - int UNUSED_P(is_param), - const XML_Char *value, - int value_length, - const XML_Char *UNUSED_P(base), - const XML_Char *systemId, - const XML_Char *publicId, - const XML_Char *notationName) -{ - XML_Parser parser = (XML_Parser) userData; +metaEntityDecl(void *userData, const XML_Char *entityName, int is_param, + const XML_Char *value, int value_length, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; + UNUSED_P(is_param); + UNUSED_P(base); if (value) { ftprintf(fp, T("<entity name=\"%s\""), entityName); metaLocation(parser); puttc(T('>'), fp); characterData(data, value, value_length); fputts(T("</entity/>\n"), fp); - } - else if (notationName) { + } else if (notationName) { ftprintf(fp, T("<entity name=\"%s\""), entityName); if (publicId) ftprintf(fp, T(" public=\"%s\""), publicId); @@ -764,8 +725,7 @@ metaEntityDecl(void *userData, ftprintf(fp, T(" notation=\"%s\""), notationName); metaLocation(parser); fputts(T("/>\n"), fp); - } - else { + } else { ftprintf(fp, T("<entity name=\"%s\""), entityName); if (publicId) ftprintf(fp, T(" public=\"%s\""), publicId); @@ -778,11 +738,9 @@ metaEntityDecl(void *userData, } static void XMLCALL -metaStartNamespaceDecl(void *userData, - const XML_Char *prefix, - const XML_Char *uri) -{ - XML_Parser parser = (XML_Parser) userData; +metaStartNamespaceDecl(void *userData, const XML_Char *prefix, + const XML_Char *uri) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; fputts(T("<startns"), fp); @@ -792,74 +750,70 @@ metaStartNamespaceDecl(void *userData, fputts(T(" ns=\""), fp); characterData(data, uri, (int)tcslen(uri)); fputts(T("\"/>\n"), fp); - } - else + } else fputts(T("/>\n"), fp); } static void XMLCALL -metaEndNamespaceDecl(void *userData, const XML_Char *prefix) -{ - XML_Parser parser = (XML_Parser) userData; +metaEndNamespaceDecl(void *userData, const XML_Char *prefix) { + XML_Parser parser = (XML_Parser)userData; XmlwfUserData *data = (XmlwfUserData *)XML_GetUserData(parser); FILE *fp = data->fp; - if (!prefix) + if (! prefix) fputts(T("<endns/>\n"), fp); else ftprintf(fp, T("<endns prefix=\"%s\"/>\n"), prefix); } static int XMLCALL -unknownEncodingConvert(void *data, const char *p) -{ +unknownEncodingConvert(void *data, const char *p) { return codepageConvert(*(int *)data, p); } static int XMLCALL -unknownEncoding(void *UNUSED_P(userData), const XML_Char *name, XML_Encoding *info) -{ +unknownEncoding(void *userData, const XML_Char *name, XML_Encoding *info) { int cp; static const XML_Char prefixL[] = T("windows-"); static const XML_Char prefixU[] = T("WINDOWS-"); int i; + UNUSED_P(userData); for (i = 0; prefixU[i]; i++) if (name[i] != prefixU[i] && name[i] != prefixL[i]) return 0; - + cp = 0; for (; name[i]; i++) { static const XML_Char digits[] = T("0123456789"); const XML_Char *s = tcschr(digits, name[i]); - if (!s) + if (! s) return 0; cp *= 10; cp += (int)(s - digits); if (cp >= 0x10000) return 0; } - if (!codepageMap(cp, info->map)) + if (! codepageMap(cp, info->map)) return 0; info->convert = unknownEncodingConvert; /* We could just cast the code page integer to a void *, and avoid the use of release. */ info->release = free; info->data = malloc(sizeof(int)); - if (!info->data) + if (! info->data) return 0; *(int *)info->data = cp; return 1; } static int XMLCALL -notStandalone(void *UNUSED_P(userData)) -{ +notStandalone(void *userData) { + UNUSED_P(userData); return 0; } static void -showVersion(XML_Char *prog) -{ +showVersion(XML_Char *prog) { XML_Char *s = prog; XML_Char ch; const XML_Feature *features = XML_GetFeatureList(); @@ -868,7 +822,7 @@ showVersion(XML_Char *prog) #if defined(_WIN32) || ch == '\\' #endif - ) + ) prog = s + 1; ++s; } @@ -889,10 +843,46 @@ showVersion(XML_Char *prog) } static void -usage(const XML_Char *prog, int rc) -{ - ftprintf(stderr, - T("usage: %s [-s] [-n] [-p] [-x] [-e encoding] [-w] [-d output-dir] [-c] [-m] [-r] [-t] [-N] [file ...]\n"), prog); +usage(const XML_Char *prog, int rc) { + ftprintf( + stderr, + /* Generated with: + * $ xmlwf/xmlwf_helpgen.sh + */ + /* clang-format off */ + T("usage: %s [-s] [-n] [-p] [-x] [-e ENCODING] [-w] [-r] [-d DIRECTORY]\n") + T(" [-c | -m | -t] [-N]\n") + T(" [FILE [FILE ...]]\n") + T("\n") + T("xmlwf - Determines if an XML document is well-formed\n") + T("\n") + T("positional arguments:\n") + T(" FILE files to process (default: STDIN)\n") + T("\n") + T("input control arguments:\n") + T(" -s print an error if the document is not [s]tandalone\n") + T(" -n enable [n]amespace processing\n") + T(" -p enable processing external DTDs and [p]arameter entities\n") + T(" -x enable processing of e[x]ternal entities\n") + T(" -e ENCODING override any in-document [e]ncoding declaration\n") + T(" -w enable support for [W]indows code pages\n") + T(" -r disable memory-mapping and use normal file [r]ead IO calls instead\n") + T("\n") + T("output control arguments:\n") + T(" -d DIRECTORY output [d]estination directory\n") + T(" -c write a [c]opy of input XML, not canonical XML\n") + T(" -m write [m]eta XML, not canonical XML\n") + T(" -t write no XML output for [t]iming of plain parsing\n") + T(" -N enable adding doctype and [n]otation declarations\n") + T("\n") + T("info arguments:\n") + T(" -h show this [h]elp message and exit\n") + T(" -v show program's [v]ersion number and exit\n") + T("\n") + T("libexpat is software libre, licensed under the MIT license.\n") + T("Please report bugs at https://github.com/libexpat/libexpat/issues. Thank you!\n") + , /* clang-format on */ + prog); exit(rc); } @@ -902,8 +892,7 @@ int wmain(int argc, XML_Char **argv); #endif int -tmain(int argc, XML_Char **argv) -{ +tmain(int argc, XML_Char **argv) { int i, j; const XML_Char *outputDir = NULL; const XML_Char *encoding = NULL; @@ -913,13 +902,13 @@ tmain(int argc, XML_Char **argv) int useNamespaces = 0; int requireStandalone = 0; int requiresNotations = 0; - enum XML_ParamEntityParsing paramEntityParsing = - XML_PARAM_ENTITY_PARSING_NEVER; + enum XML_ParamEntityParsing paramEntityParsing + = XML_PARAM_ENTITY_PARSING_NEVER; int useStdin = 0; - XmlwfUserData userData = { NULL, NULL, NULL }; + XmlwfUserData userData = {NULL, NULL, NULL}; #ifdef _MSC_VER - _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF); + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif i = 1; @@ -980,8 +969,7 @@ tmain(int argc, XML_Char **argv) if (++i == argc) usage(argv[0], 2); outputDir = argv[i]; - } - else + } else outputDir = argv[i] + j + 1; i++; j = 0; @@ -991,8 +979,7 @@ tmain(int argc, XML_Char **argv) if (++i == argc) usage(argv[0], 2); encoding = argv[i]; - } - else + } else encoding = argv[i] + j + 1; i++; j = 0; @@ -1043,18 +1030,17 @@ tmain(int argc, XML_Char **argv) XML_SetElementHandler(parser, nopStartElement, nopEndElement); XML_SetCharacterDataHandler(parser, nopCharacterData); XML_SetProcessingInstructionHandler(parser, nopProcessingInstruction); - } - else if (outputDir) { - const XML_Char * delim = T("/"); + } else if (outputDir) { + const XML_Char *delim = T("/"); const XML_Char *file = useStdin ? T("STDIN") : argv[i]; - if (!useStdin) { + if (! useStdin) { /* Jump after last (back)slash */ - const XML_Char * lastDelim = tcsrchr(file, delim[0]); + const XML_Char *lastDelim = tcsrchr(file, delim[0]); if (lastDelim) file = lastDelim + 1; #if defined(_WIN32) else { - const XML_Char * winDelim = T("\\"); + const XML_Char *winDelim = T("\\"); lastDelim = tcsrchr(file, winDelim[0]); if (lastDelim) { file = lastDelim + 1; @@ -1064,12 +1050,12 @@ tmain(int argc, XML_Char **argv) #endif } outName = (XML_Char *)malloc((tcslen(outputDir) + tcslen(file) + 2) - * sizeof(XML_Char)); + * sizeof(XML_Char)); tcscpy(outName, outputDir); tcscat(outName, delim); tcscat(outName, file); userData.fp = tfopen(outName, T("wb")); - if (!userData.fp) { + if (! userData.fp) { tperror(outName); exit(1); } @@ -1126,13 +1112,15 @@ tmain(int argc, XML_Char **argv) if (outputType == 'm') metaEndDocument(parser); fclose(userData.fp); - if (!result) { + if (! result) { tremove(outName); - exit(2); } free(outName); } XML_ParserFree(parser); + if (! result) { + exit(2); + } } return 0; } diff --git a/xmlwf/xmlwf.vcxproj b/xmlwf/xmlwf.vcxproj deleted file mode 100644 index 60efd398..00000000 --- a/xmlwf/xmlwf.vcxproj +++ /dev/null @@ -1,164 +0,0 @@ -<?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>
\ No newline at end of file diff --git a/xmlwf/xmlwf.vcxproj.filters b/xmlwf/xmlwf.vcxproj.filters deleted file mode 100644 index 890b9efb..00000000 --- a/xmlwf/xmlwf.vcxproj.filters +++ /dev/null @@ -1,48 +0,0 @@ -<?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>
\ No newline at end of file diff --git a/xmlwf/xmlwf_helpgen.py b/xmlwf/xmlwf_helpgen.py new file mode 100755 index 00000000..0dcb6d34 --- /dev/null +++ b/xmlwf/xmlwf_helpgen.py @@ -0,0 +1,69 @@ +#! /usr/bin/env python3 +# __ __ _ +# ___\ \/ /_ __ __ _| |_ +# / _ \\ /| '_ \ / _` | __| +# | __// \| |_) | (_| | |_ +# \___/_/\_\ .__/ \__,_|\__| +# |_| XML parser +# +# Copyright (c) 2019 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. + +import argparse + +epilog = """ +libexpat is software libre, licensed under the MIT license. +Please report bugs at https://github.com/libexpat/libexpat/issues. Thank you! +""" + +parser = argparse.ArgumentParser(prog='xmlwf', add_help=False, + description='xmlwf - Determines if an XML document is well-formed', + formatter_class=argparse.RawTextHelpFormatter, + epilog=epilog) + +input_related = parser.add_argument_group('input control arguments') +input_related.add_argument('-s', action='store_true', help='print an error if the document is not [s]tandalone') +input_related.add_argument('-n', action='store_true', help='enable [n]amespace processing') +input_related.add_argument('-p', action='store_true', help='enable processing external DTDs and [p]arameter entities') +input_related.add_argument('-x', action='store_true', help='enable processing of e[x]ternal entities') +input_related.add_argument('-e', action='store', metavar='ENCODING', help='override any in-document [e]ncoding declaration') +input_related.add_argument('-w', action='store_true', help='enable support for [W]indows code pages') +input_related.add_argument('-r', action='store_true', help='disable memory-mapping and use normal file [r]ead IO calls instead') + +output_related = parser.add_argument_group('output control arguments') +output_related.add_argument('-d', action='store', metavar='DIRECTORY', help='output [d]estination directory') +output_mode = output_related.add_mutually_exclusive_group() +output_mode.add_argument('-c', action='store_true', help='write a [c]opy of input XML, not canonical XML') +output_mode.add_argument('-m', action='store_true', help='write [m]eta XML, not canonical XML') +output_mode.add_argument('-t', action='store_true', help='write no XML output for [t]iming of plain parsing') +output_related.add_argument('-N', action='store_true', help='enable adding doctype and [n]otation declarations') + +parser.add_argument('files', metavar='FILE', nargs='*', help='files to process (default: STDIN)') + +info = parser.add_argument_group('info arguments') +info = info.add_mutually_exclusive_group() +info.add_argument('-h', action='store_true', help='show this [h]elp message and exit') +info.add_argument('-v', action='store_true', help='show program\'s [v]ersion number and exit') + + +if __name__ == '__main__': + parser.print_help() diff --git a/xmlwf/xmlwf_helpgen.sh b/xmlwf/xmlwf_helpgen.sh new file mode 100755 index 00000000..6b0fbf92 --- /dev/null +++ b/xmlwf/xmlwf_helpgen.sh @@ -0,0 +1,35 @@ +#! /usr/bin/env bash +# __ __ _ +# ___\ \/ /_ __ __ _| |_ +# / _ \\ /| '_ \ / _` | __| +# | __// \| |_) | (_| | |_ +# \___/_/\_\ .__/ \__,_|\__| +# |_| XML parser +# +# Copyright (c) 2019 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. + +./xmlwf/xmlwf_helpgen.py | sed \ + -e 's,usage: xmlwf,usage: %s,' \ + -e 's, \[-h | -v\],,' \ + -e 's,^, T(",' \ + -e 's,$,\\n"),' diff --git a/xmlwf/xmlwin32url.cxx b/xmlwf/xmlwin32url.cxx deleted file mode 100644 index ef2a1374..00000000 --- a/xmlwf/xmlwin32url.cxx +++ /dev/null @@ -1,427 +0,0 @@ -/* - __ __ _ - ___\ \/ /_ __ __ _| |_ - / _ \\ /| '_ \ / _` | __| - | __// \| |_) | (_| | |_ - \___/_/\_\ .__/ \__,_|\__| - |_| 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); -} |