xmlfile.c (104349) | xmlfile.c (178848) |
---|---|
1/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd 2 See the file COPYING for copying permission. 3*/ 4 5#include <stdio.h> 6#include <stdlib.h> 7#include <stddef.h> 8#include <string.h> 9#include <fcntl.h> | 1/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd 2 See the file COPYING for copying permission. 3*/ 4 5#include <stdio.h> 6#include <stdlib.h> 7#include <stddef.h> 8#include <string.h> 9#include <fcntl.h> |
10 |
|
10#ifdef COMPILED_FROM_DSP 11#include "winconfig.h" | 11#ifdef COMPILED_FROM_DSP 12#include "winconfig.h" |
12#else 13#include "expat_config.h" 14#endif | 13#elif defined(MACOS_CLASSIC) 14#include "macconfig.h" 15#elif defined(__amigaos__) 16#include "amigaconfig.h" 17#elif defined(__WATCOMC__) 18#include "watcomconfig.h" 19#elif defined(HAVE_EXPAT_CONFIG_H) 20#include <expat_config.h> 21#endif /* ndef COMPILED_FROM_DSP */ 22 |
15#include "expat.h" 16#include "xmlfile.h" 17#include "xmltchar.h" 18#include "filemap.h" 19 | 23#include "expat.h" 24#include "xmlfile.h" 25#include "xmltchar.h" 26#include "filemap.h" 27 |
20#ifdef _MSC_VER | 28#if (defined(_MSC_VER) || (defined(__WATCOMC__) && !defined(__LINUX__))) |
21#include <io.h> 22#endif 23 | 29#include <io.h> 30#endif 31 |
32#if defined(__amigaos__) && defined(__USE_INLINE__) 33#include <proto/expat.h> 34#endif 35 |
|
24#ifdef HAVE_UNISTD_H 25#include <unistd.h> 26#endif 27 28#ifndef O_BINARY 29#ifdef _O_BINARY 30#define O_BINARY _O_BINARY 31#else --- 11 unchanged lines hidden (view full) --- 43typedef struct { 44 XML_Parser parser; 45 int *retPtr; 46} PROCESS_ARGS; 47 48static void 49reportError(XML_Parser parser, const XML_Char *filename) 50{ | 36#ifdef HAVE_UNISTD_H 37#include <unistd.h> 38#endif 39 40#ifndef O_BINARY 41#ifdef _O_BINARY 42#define O_BINARY _O_BINARY 43#else --- 11 unchanged lines hidden (view full) --- 55typedef struct { 56 XML_Parser parser; 57 int *retPtr; 58} PROCESS_ARGS; 59 60static void 61reportError(XML_Parser parser, const XML_Char *filename) 62{ |
51 int code = XML_GetErrorCode(parser); | 63 enum XML_Error code = XML_GetErrorCode(parser); |
52 const XML_Char *message = XML_ErrorString(code); 53 if (message) | 64 const XML_Char *message = XML_ErrorString(code); 65 if (message) |
54 ftprintf(stdout, T("%s:%d:%d: %s\n"), | 66 ftprintf(stdout, T("%s:%" XML_FMT_INT_MOD "u:%" XML_FMT_INT_MOD "u: %s\n"), |
55 filename, 56 XML_GetErrorLineNumber(parser), 57 XML_GetErrorColumnNumber(parser), 58 message); 59 else 60 ftprintf(stderr, T("%s: (unknown message %d)\n"), filename, code); 61} | 67 filename, 68 XML_GetErrorLineNumber(parser), 69 XML_GetErrorColumnNumber(parser), 70 message); 71 else 72 ftprintf(stderr, T("%s: (unknown message %d)\n"), filename, code); 73} |
62 | 74 75/* This implementation will give problems on files larger than INT_MAX. */ |
63static void 64processFile(const void *data, size_t size, 65 const XML_Char *filename, void *args) 66{ 67 XML_Parser parser = ((PROCESS_ARGS *)args)->parser; 68 int *retPtr = ((PROCESS_ARGS *)args)->retPtr; | 76static void 77processFile(const void *data, size_t size, 78 const XML_Char *filename, void *args) 79{ 80 XML_Parser parser = ((PROCESS_ARGS *)args)->parser; 81 int *retPtr = ((PROCESS_ARGS *)args)->retPtr; |
69 if (XML_Parse(parser, data, size, 1) == XML_STATUS_ERROR) { | 82 if (XML_Parse(parser, (const char *)data, (int)size, 1) == XML_STATUS_ERROR) { |
70 reportError(parser, filename); 71 *retPtr = 0; 72 } 73 else 74 *retPtr = 1; 75} 76 | 83 reportError(parser, filename); 84 *retPtr = 0; 85 } 86 else 87 *retPtr = 1; 88} 89 |
77#ifdef WIN32 | 90#if (defined(WIN32) || defined(__WATCOMC__)) |
78 79static int 80isAsciiLetter(XML_Char c) 81{ 82 return (T('a') <= c && c <= T('z')) || (T('A') <= c && c <= T('Z')); 83} 84 85#endif /* WIN32 */ 86 87static const XML_Char * 88resolveSystemId(const XML_Char *base, const XML_Char *systemId, 89 XML_Char **toFree) 90{ 91 XML_Char *s; 92 *toFree = 0; 93 if (!base 94 || *systemId == T('/') | 91 92static int 93isAsciiLetter(XML_Char c) 94{ 95 return (T('a') <= c && c <= T('z')) || (T('A') <= c && c <= T('Z')); 96} 97 98#endif /* WIN32 */ 99 100static const XML_Char * 101resolveSystemId(const XML_Char *base, const XML_Char *systemId, 102 XML_Char **toFree) 103{ 104 XML_Char *s; 105 *toFree = 0; 106 if (!base 107 || *systemId == T('/') |
95#ifdef WIN32 | 108#if (defined(WIN32) || defined(__WATCOMC__)) |
96 || *systemId == T('\\') 97 || (isAsciiLetter(systemId[0]) && systemId[1] == T(':')) 98#endif 99 ) 100 return systemId; 101 *toFree = (XML_Char *)malloc((tcslen(base) + tcslen(systemId) + 2) 102 * sizeof(XML_Char)); 103 if (!*toFree) 104 return systemId; 105 tcscpy(*toFree, base); 106 s = *toFree; 107 if (tcsrchr(s, T('/'))) 108 s = tcsrchr(s, T('/')) + 1; | 109 || *systemId == T('\\') 110 || (isAsciiLetter(systemId[0]) && systemId[1] == T(':')) 111#endif 112 ) 113 return systemId; 114 *toFree = (XML_Char *)malloc((tcslen(base) + tcslen(systemId) + 2) 115 * sizeof(XML_Char)); 116 if (!*toFree) 117 return systemId; 118 tcscpy(*toFree, base); 119 s = *toFree; 120 if (tcsrchr(s, T('/'))) 121 s = tcsrchr(s, T('/')) + 1; |
109#ifdef WIN32 | 122#if (defined(WIN32) || defined(__WATCOMC__)) |
110 if (tcsrchr(s, T('\\'))) 111 s = tcsrchr(s, T('\\')) + 1; 112#endif 113 tcscpy(s, systemId); 114 return *toFree; 115} 116 117static int --- 29 unchanged lines hidden (view full) --- 147 fd = topen(filename, O_BINARY|O_RDONLY); 148 if (fd < 0) { 149 tperror(filename); 150 return 0; 151 } 152 } 153 for (;;) { 154 int nread; | 123 if (tcsrchr(s, T('\\'))) 124 s = tcsrchr(s, T('\\')) + 1; 125#endif 126 tcscpy(s, systemId); 127 return *toFree; 128} 129 130static int --- 29 unchanged lines hidden (view full) --- 160 fd = topen(filename, O_BINARY|O_RDONLY); 161 if (fd < 0) { 162 tperror(filename); 163 return 0; 164 } 165 } 166 for (;;) { 167 int nread; |
155 char *buf = XML_GetBuffer(parser, READ_SIZE); | 168 char *buf = (char *)XML_GetBuffer(parser, READ_SIZE); |
156 if (!buf) { 157 if (filename != NULL) 158 close(fd); 159 ftprintf(stderr, T("%s: out of memory\n"), 160 filename != NULL ? filename : "xmlwf"); 161 return 0; 162 } 163 nread = read(fd, buf, READ_SIZE); --- 68 unchanged lines hidden --- | 169 if (!buf) { 170 if (filename != NULL) 171 close(fd); 172 ftprintf(stderr, T("%s: out of memory\n"), 173 filename != NULL ? filename : "xmlwf"); 174 return 0; 175 } 176 nread = read(fd, buf, READ_SIZE); --- 68 unchanged lines hidden --- |