Compare commits

...
61 Commits
Author SHA1 Message Date
James Clark 3b69eb5b92 +C:/home/work/expat/expat.pj 1998.05.14 11:42:18 revision 1.9 by jjc
checkpointed, new revision 1.9
+C:/home/work/expat/expat.pj 1998.05.16 16:18:17  revision 1.9 by jjc
C:/home/work/expat/xmlparse/xmlparse.c new-revision 1.29 was 1.28
+C:/home/work/expat/expat.pj 1998.05.23 14:27:59  revision 1.9 by jjc
C:/home/work/expat/xmltok/xmltok_impl.c new-revision 1.23 was 1.22
+C:/home/work/expat/expat.pj 1998.05.30 17:13:04  revision 1.9 by jjc
C:/home/work/expat/xmlparse/xmlparse.c new-revision 1.30 was 1.29
+C:/home/work/expat/expat.pj 1998.05.30 17:13:06  revision 1.9 by jjc
C:/home/work/expat/xmltok/xmltok.c new-revision 1.25 was 1.24
+C:/home/work/expat/expat.pj 1998.05.30 17:13:07  revision 1.9 by jjc
C:/home/work/expat/xmltok/xmltok.h new-revision 1.17 was 1.16
+C:/home/work/expat/expat.pj 1998.05.30 19:47:06  revision 1.9 by jjc
C:/home/work/expat/xmltok/xmltok.c new-revision 1.26 was 1.25
+C:/home/work/expat/expat.pj 1998.05.30 19:47:07  revision 1.9 by jjc
C:/home/work/expat/xmltok/xmltok.h new-revision 1.18 was 1.17
+C:/home/work/expat/expat.pj 1998.05.31 12:32:40  revision 1.9 by jjc
C:/home/work/expat/xmlparse/hashtable.c new-revision 1.5 was 1.4
+C:/home/work/expat/expat.pj 1998.05.31 12:32:41  revision 1.9 by jjc
C:/home/work/expat/xmlparse/hashtable.h new-revision 1.4 was 1.3
+C:/home/work/expat/expat.pj 1998.05.31 12:32:42  revision 1.9 by jjc
C:/home/work/expat/xmlparse/xmlparse.c new-revision 1.31 was 1.30
+C:/home/work/expat/expat.pj 1998.05.31 12:32:43  revision 1.9 by jjc
C:/home/work/expat/xmlparse/xmlparse.h new-revision 1.7 was 1.6
+C:/home/work/expat/expat.pj 1998.05.31 15:06:00  revision 1.9 by jjc
C:/home/work/expat/xmlparse/xmlparse.c new-revision 1.32 was 1.31
+C:/home/work/expat/expat.pj 1998.05.31 15:06:00  revision 1.9 by jjc
C:/home/work/expat/xmltok/xmltok.c new-revision 1.27 was 1.26
+C:/home/work/expat/expat.pj 1998.05.31 15:06:01  revision 1.9 by jjc
C:/home/work/expat/xmltok/xmltok.h new-revision 1.19 was 1.18
1998-06-21 09:11:40 +00:00
James Clark 22795a8755 Give message about how to run it. 1998-06-21 08:44:14 +00:00
James Clark 7f3efb4802 Fix names of sample files 1998-06-21 08:23:52 +00:00
James Clark 9e81312f63 Initial revision 1998-06-21 08:22:49 +00:00
James Clark fecf35cf44 Add sample files 1998-06-21 08:22:39 +00:00
James Clark 89687a2bfd *** empty log message *** 1998-06-21 08:22:20 +00:00
James Clark 80b4895ce5 *** empty log message *** 1998-06-21 08:10:47 +00:00
James Clark 5700ecb60f Add XML_DefaultCurrent 1998-06-21 06:53:13 +00:00
James Clark 78d38a3fd0 Fix non-Win32 stubs 1998-06-17 11:32:18 +00:00
James Clark 2c080dd19f Avoid dependence on Unicode wchar_t in xmlparse 1998-06-17 11:19:44 +00:00
James Clark d78e5baa21 Improve comment 1998-06-17 10:45:12 +00:00
James Clark 38dc320552 Make locations right for default handler and for character data spread over multiple calls. 1998-06-17 10:18:28 +00:00
James Clark 508f4e99ee Add default handler 1998-06-17 10:04:31 +00:00
James Clark 99eba7a16d Add base address for xmlparse.dll 1998-06-03 13:23:35 +00:00
James Clark 0ee12e8045 Avoid setting eventPtr on error while parsing internal entities. 1998-06-03 13:10:13 +00:00
James Clark 9e2bdba5fb Set the base even if not processing external entities 1998-06-03 11:29:18 +00:00
James Clark 42bd1cb01c Fix typo with -m option 1998-06-03 10:55:52 +00:00
James Clark 5c3919e6bf Fix some bugs in location handling 1998-06-03 10:48:23 +00:00
James Clark 1f49d0a366 Enhance -m option 1998-06-03 10:16:20 +00:00
James Clark e2ae0f492d More comments added. 1998-06-03 09:33:36 +00:00
James Clark b720028b85 Tweak to locations in prolog 1998-06-03 09:28:55 +00:00
James Clark 03f202d614 Change GetErrorCode return type to enum XML_ErrorCode. 1998-06-03 09:24:43 +00:00
James Clark 650ce08322 Add more comments. 1998-06-03 09:23:16 +00:00
James Clark 939ec46566 -1 in unknown encoding lead byte table should use BT_MALFORM 1998-06-03 08:25:08 +00:00
James Clark 0e864d50fb Use ints rather than unsigned shorts in unknown encoding support 1998-06-03 07:52:49 +00:00
James Clark d38e459410 Provide -m option
Set base for external entities
1998-06-03 07:04:44 +00:00
James Clark 069c00e820 Make location information available for all events
Support XML_UseParserAsHandlerArg
1998-06-03 06:35:00 +00:00
James Clark 6b733b9b87 Delete stscanf definition 1998-06-02 09:06:22 +00:00
James Clark 84835ac373 Generalize unknown encoding support 1998-06-02 08:57:14 +00:00
James Clark e8ac3d8f5f Fix typos in CHECK_*_CASES args 1998-06-02 04:20:08 +00:00
James Clark 7ce4d1b852 Mention BYTE_ORDER.
Add codepage.c
1998-06-01 13:02:06 +00:00
James Clark 3e3f6bb7f2 Initial revision 1998-06-01 12:56:04 +00:00
James Clark f310fb4ab9 Ignore encoding decl with protocol specified encoding. Factor out common handling of XML/Text declaration. 1998-06-01 12:54:02 +00:00
James Clark 0fe1372234 Add codepage.c 1998-06-01 12:15:13 +00:00
James Clark 10c3740f1e Initial Revision 1998-06-01 12:12:51 +00:00
James Clark 9efc5049a8 Support for arbitrary single byte encodings 1998-06-01 12:12:35 +00:00
James Clark 3a10246912 New approach for handling predefined entities 1998-06-01 07:28:31 +00:00
James Clark 496af54711 Avoid converting data unnecessarily 1998-06-01 05:55:23 +00:00
James Clark 698686457e Add debugging support for unparsed entities 1998-06-01 04:33:10 +00:00
James Clark c83cd08a8e Report notation and unparsed entity declarations. 1998-06-01 04:30:05 +00:00
James Clark 6ff56dc9dc Add XML_ROLE_NOTATION_NO_SYSTEM_ID 1998-06-01 03:59:07 +00:00
James Clark 28bbc4f64f Ifdef for XML_UNICODE 1998-05-31 11:53:28 +00:00
James Clark 0f3e24272f Fix bug with CDATA sections in internal entity where internal encoding is different from external entity encoding. 1998-05-31 10:18:06 +00:00
James Clark 3bddd238db Fix bug with XML_UNICODE support and duplicate attributes. 1998-05-31 10:14:02 +00:00
James Clark 7eadec98df Make encoding name use XML_Char 1998-05-31 09:38:17 +00:00
James Clark 40962ad8af Make XML_ErrorString return XML_Char * 1998-05-31 08:39:35 +00:00
James Clark a2625a0572 Finish UTF16 conversion support 1998-05-31 08:06:01 +00:00
James Clark 5b77f426ee Ifdef for XML_UNICODE 1998-05-31 05:32:43 +00:00
James Clark c230dddef9 Represent UTF16 as char not UTF16_CHAR 1998-05-30 12:47:06 +00:00
James Clark 583f937102 Change handling of internal encodings in xmltok interface. 1998-05-30 10:13:07 +00:00
James Clark 05fd715a12 Require whitespace between attribute name and following attribute value 1998-05-23 07:27:59 +00:00
James Clark 06fb5cebe8 Split externalEntityInitProcessor into 2. 1998-05-16 09:18:16 +00:00
James Clark 11067a403b +C:/home/work/expat/expat.pj 1998.05.11 16:35:12 revision 1.8 by jjc
checkpointed, new revision 1.8
+C:/home/work/expat/expat.pj 1998.05.11 17:16:37  revision 1.8 by jjc
C:/home/work/expat/xmltok/xmltok.c new-revision 1.24 was 1.23
+C:/home/work/expat/expat.pj 1998.05.14 11:41:52  revision 1.8 by jjc
C:/home/work/expat/expat.html new-revision 1.6 was 1.5
1998-05-14 04:42:18 +00:00
James Clark 0505f1cd36 Update date. 1998-05-14 04:41:52 +00:00
James Clark d504c1c894 Add support for US-ASCII encoding 1998-05-11 10:16:36 +00:00
James Clark 59023a9533 +C:/home/work/expat/expat.pj 1998.05.04 16:40:35 revision 1.7 by jjc
checkpointed, new revision 1.7
+C:/home/work/expat/expat.pj 1998.05.10 17:18:14  revision 1.7 by jjc
C:/home/work/expat/xmlparse/xmlparse.c new-revision 1.26 was 1.25
+C:/home/work/expat/expat.pj 1998.05.10 17:18:14  revision 1.7 by jjc
C:/home/work/expat/xmlparse/xmlparse.h new-revision 1.5 was 1.4
+C:/home/work/expat/expat.pj 1998.05.10 17:18:16  revision 1.7 by jjc
C:/home/work/expat/xmlwf/xmlwf.c new-revision 1.18 was 1.17
+C:/home/work/expat/expat.pj 1998.05.10 17:46:35  revision 1.7 by jjc
C:/home/work/expat/xmlparse/xmlparse.c new-revision 1.27 was 1.26
+C:/home/work/expat/expat.pj 1998.05.10 18:26:58  revision 1.7 by jjc
C:/home/work/expat/xmlparse/xmlparse.h new-revision 1.6 was 1.5
+C:/home/work/expat/expat.pj 1998.05.11 07:59:54  revision 1.7 by jjc
C:/home/work/expat/xmlparse/xmlparse.c new-revision 1.28 was 1.27
+C:/home/work/expat/expat.pj 1998.05.11 16:34:27  revision 1.7 by jjc
C:/home/work/expat/expat.html new-revision 1.5 was 1.4
1998-05-11 09:35:11 +00:00
James Clark d54b83991c Mention -x. Update version. 1998-05-11 09:34:26 +00:00
James Clark 0317338f10 When creating an external entity parser, don't set the processor if the encoding was unknown. 1998-05-11 00:59:52 +00:00
James Clark 5d0c27b76c Add some more comments on new interfaces 1998-05-10 11:26:58 +00:00
James Clark 1250e1d136 Fix dtdCopy bug 1998-05-10 10:46:34 +00:00
James Clark 4b8e8545c5 Support for parsing external entities 1998-05-10 10:18:15 +00:00
24 changed files with 2936 additions and 605 deletions
+4
View File
@@ -1,4 +1,7 @@
CC=gcc
# If you know what your system's byte order is, define BYTE_ORDER:
# use -DBYTE_ORDER=12 for little-endian byte order;
# use -DBYTE_ORDER=21 for big-endian (network) byte order.
CFLAGS=-O2 -Ixmltok -Ixmlparse
# Use one of the next two lines; unixfilemap is better if it works.
FILEMAP_OBJ=xmlwf/unixfilemap.o
@@ -6,6 +9,7 @@ FILEMAP_OBJ=xmlwf/unixfilemap.o
OBJS=xmltok/xmltok.o \
xmltok/xmlrole.o \
xmlwf/xmlwf.o \
xmlwf/codepage.o \
xmlparse/xmlparse.o \
xmlparse/hashtable.o \
$(FILEMAP_OBJ)
+46
View File
@@ -0,0 +1,46 @@
/* This is simple demonstration of how to use expat. This program
reads an XML document from standard input and writes a line with the
name of each element to standard output indenting child elements by
one tab stop more than their parent element. */
#include <stdio.h>
#include "xmlparse.h"
void startElement(void *userData, const char *name, const char **atts)
{
int i;
int *depthPtr = userData;
for (i = 0; i < *depthPtr; i++)
putchar('\t');
puts(name);
*depthPtr += 1;
}
void endElement(void *userData, const char *name)
{
int *depthPtr = userData;
*depthPtr -= 1;
}
int main()
{
char buf[BUFSIZ];
XML_Parser parser = XML_ParserCreate(NULL);
int done;
int depth = 0;
XML_SetUserData(parser, &depth);
XML_SetElementHandler(parser, startElement, endElement);
do {
size_t len = fread(buf, 1, sizeof(buf), stdin);
done = len < sizeof(buf);
if (!XML_Parse(parser, buf, len, done)) {
fprintf(stderr,
"%s at line %d\n",
XML_ErrorString(XML_GetErrorCode(parser)),
XML_GetCurrentLineNumber(parser));
return 1;
}
} while (!done);
XML_ParserFree(parser);
return 0;
}
+5
View File
@@ -0,0 +1,5 @@
@echo off
set LIB=..\xmlparse\Release;..\xmltok\Release;..\lib;%LIB%
set INCLUDE=..\xmlparse;..\xmltok;%INCLUDE%
set CL=/nologo /DXMLTOKAPI=__declspec(dllimport) /DXMLPARSEAPI=__declspec(dllimport) xmlparse.lib xmltok.lib
cl /Fe..\bin\demo demo.c
+38 -19
View File
@@ -1,30 +1,39 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<TITLE>expat</TITLE>
<BODY>
<H1>expat - XML Parser Toolkit</H1>
<H3>Version 19980504</H3>
<P>
Copyright (c) 1998 James Clark. Expat is subject to the <A
<H3>Version 19980621</H3>
<P>Copyright (c) 1998 James Clark. Expat is subject to the <A
HREF="MPL-1_0.html">Mozilla Public License Version 1.0</A>. You may
not use expat except in compliance with this license. Please contact
me if you wish to negotiate an alternative license.</P><P>
Expat is an <A HREF="http://www.w3.org/TR/1998/REC-xml-19980210">XML
1.0</A> parser written in C. It aims to be fully conforming. It is
currently not a validating XML processor.
Expat can be downloaded from <A href =
"ftp://ftp.jclark.com/pub/xml/expat.zip">ftp://ftp.jclark.com/pub/xml/expat.zip</A>.
This is a beta-test version.</P>
<P>
The directory <SAMP>xmltok</SAMP> contains a low-level library for
tokenizing XML. The interface is documented in <SAMP>xmltok/xmltok.h</SAMP>.</P>
<P>
The directory <SAMP>xmlparse</SAMP> contains an XML parser library
me if you wish to negotiate an alternative license.</P><P> Expat is an
<A HREF="http://www.w3.org/TR/1998/REC-xml-19980210">XML 1.0</A>
parser written in C. It aims to be fully conforming. It is currently
not a validating XML processor. Expat can be downloaded from <A href
= "ftp://ftp.jclark.com/pub/xml/expat.zip"
>ftp://ftp.jclark.com/pub/xml/expat.zip</A>. This is a beta-test
version.</P>
<P>The directory <SAMP>xmltok</SAMP> contains a low-level library for
tokenizing XML. The interface is documented in
<SAMP>xmltok/xmltok.h</SAMP>.</P>
<P>The directory <SAMP>xmlparse</SAMP> contains an XML parser library
which is built on top of the <SAMP>xmltok</SAMP> library. The
interface is documented in <SAMP>xmlparse/xmlparse.h</SAMP>.</P>
<P>
The directory <SAMP>xmlwf</SAMP> contains the <SAMP>xmlwf</SAMP>
interface is documented in <SAMP>xmlparse/xmlparse.h</SAMP>. The
directory <SAMP>sample</SAMP> contains a simple example program using
this interface; <SAMP>sample/build.bat</SAMP> is a batch file to build
the example using Visual C++.</P>
<P>The directory <SAMP>xmlwf</SAMP> contains the <SAMP>xmlwf</SAMP>
application, which uses the <SAMP>xmlparse</SAMP> library. The
arguments to <SAMP>xmlwf</SAMP> are one or more files which are each
to be checked for well-formedness. An option <SAMP>-d
@@ -33,10 +42,20 @@ file the corresponding <A
href="http://www.jclark.com/xml/canonxml.html">canonical XML</A> will
be written to <SAMP>dir/<VAR>f</VAR></SAMP>, where
<SAMP><VAR>f</VAR></SAMP> is the filename (without any path) of the
input file.</P>
input file. A <CODE>-x</CODE> option will cause references to
external general entities to be processed.</P>
<P>The <SAMP>bin</SAMP> directory contains Win32 executables. The
<SAMP>lib</SAMP> directory contains Win32 import libraries.</P>
<P></P>
<ADDRESS>
<A HREF="mailto:jjc@jclark.com">James Clark</A>
</ADDRESS>
</BODY>
</HTML>
+121 -4
View File
@@ -63,6 +63,7 @@ INTDIR=.\xmlwf\Release
ALL : "xmlparse - Win32 Release" ".\bin\xmlwf.exe"
CLEAN :
-@erase "$(INTDIR)\codepage.obj"
-@erase "$(INTDIR)\win32filemap.obj"
-@erase "$(INTDIR)\xmlwf.obj"
-@erase ".\bin\xmlwf.exe"
@@ -115,6 +116,7 @@ LINK32_FLAGS=setargv.obj kernel32.lib user32.lib gdi32.lib winspool.lib\
odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no\
/pdb:"$(OUTDIR)/xmlwf.pdb" /machine:I386 /out:"bin/xmlwf.exe"
LINK32_OBJS= \
"$(INTDIR)\codepage.obj" \
"$(INTDIR)\win32filemap.obj" \
"$(INTDIR)\xmlwf.obj" \
".\xmlparse\Release\xmlparse.lib"
@@ -142,6 +144,7 @@ INTDIR=.\xmlwf\Debug
ALL : "xmlparse - Win32 Debug" ".\dbgbin\xmlwf.exe"
CLEAN :
-@erase "$(INTDIR)\codepage.obj"
-@erase "$(INTDIR)\vc40.idb"
-@erase "$(INTDIR)\vc40.pdb"
-@erase "$(INTDIR)\win32filemap.obj"
@@ -198,6 +201,7 @@ LINK32_FLAGS=setargv.obj kernel32.lib user32.lib gdi32.lib winspool.lib\
odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes\
/pdb:"$(OUTDIR)/xmlwf.pdb" /debug /machine:I386 /out:"dbgbin/xmlwf.exe"
LINK32_OBJS= \
"$(INTDIR)\codepage.obj" \
"$(INTDIR)\win32filemap.obj" \
"$(INTDIR)\xmlwf.obj" \
".\xmlparse\Debug\xmlparse.lib"
@@ -430,11 +434,11 @@ BSC32_SBRS= \
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /out:"bin/xmlparse.dll"
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:0x20000000 /subsystem:windows /dll /machine:I386 /out:"bin/xmlparse.dll"
# SUBTRACT LINK32 /profile
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\
odbccp32.lib /nologo /subsystem:windows /dll /incremental:no\
odbccp32.lib /nologo /base:0x20000000 /subsystem:windows /dll /incremental:no\
/pdb:"$(OUTDIR)/xmlparse.pdb" /machine:I386 /out:"bin/xmlparse.dll"\
/implib:"$(OUTDIR)/xmlparse.lib"
LINK32_OBJS= \
@@ -521,10 +525,10 @@ BSC32_SBRS= \
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"dbgbin/xmlparse.dll"
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:0x20000000 /subsystem:windows /dll /debug /machine:I386 /out:"dbgbin/xmlparse.dll"
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\
odbccp32.lib /nologo /subsystem:windows /dll /incremental:yes\
odbccp32.lib /nologo /base:0x20000000 /subsystem:windows /dll /incremental:yes\
/pdb:"$(OUTDIR)/xmlparse.pdb" /debug /machine:I386 /out:"dbgbin/xmlparse.dll"\
/implib:"$(OUTDIR)/xmlparse.lib"
LINK32_OBJS= \
@@ -733,6 +737,7 @@ LINK32_OBJS= \
SOURCE=.\xmlwf\xmlwf.c
DEP_CPP_XMLWF=\
".\xmlparse\xmlparse.h"\
".\xmlwf\codepage.h"\
".\xmlwf\filemap.h"\
@@ -793,6 +798,19 @@ DEP_CPP_READF=\
!ENDIF
# End Project Dependency
################################################################################
# Begin Source File
SOURCE=.\xmlwf\codepage.c
DEP_CPP_CODEP=\
".\xmlwf\codepage.h"\
"$(INTDIR)\codepage.obj" : $(SOURCE) $(DEP_CPP_CODEP) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
# End Source File
# End Target
################################################################################
# Begin Target
@@ -833,6 +851,9 @@ SOURCE=.\gennmtab\gennmtab.c
# Begin Source File
SOURCE=.\xmlparse\xmlparse.c
!IF "$(CFG)" == "xmlparse - Win32 Release"
DEP_CPP_XMLPA=\
".\xmlparse\hashtable.h"\
".\xmlparse\xmlparse.h"\
@@ -848,11 +869,33 @@ NODEP_CPP_XMLPA=\
$(CPP) $(CPP_PROJ) $(SOURCE)
!ELSEIF "$(CFG)" == "xmlparse - Win32 Debug"
DEP_CPP_XMLPA=\
".\xmlparse\hashtable.h"\
".\xmlparse\xmlparse.h"\
".\xmltok\xmldef.h"\
".\xmltok\xmlrole.h"\
".\xmltok\xmltok.h"\
NODEP_CPP_XMLPA=\
".\xmltok\nspr.h"\
"$(INTDIR)\xmlparse.obj" : $(SOURCE) $(DEP_CPP_XMLPA) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF
# End Source File
################################################################################
# Begin Source File
SOURCE=.\xmlparse\hashtable.c
!IF "$(CFG)" == "xmlparse - Win32 Release"
DEP_CPP_HASHT=\
".\xmlparse\hashtable.h"\
".\xmltok\xmldef.h"\
@@ -865,6 +908,22 @@ NODEP_CPP_HASHT=\
$(CPP) $(CPP_PROJ) $(SOURCE)
!ELSEIF "$(CFG)" == "xmlparse - Win32 Debug"
DEP_CPP_HASHT=\
".\xmlparse\hashtable.h"\
".\xmltok\xmldef.h"\
NODEP_CPP_HASHT=\
".\xmltok\nspr.h"\
"$(INTDIR)\hashtable.obj" : $(SOURCE) $(DEP_CPP_HASHT) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF
# End Source File
################################################################################
# Begin Project Dependency
@@ -901,6 +960,9 @@ NODEP_CPP_HASHT=\
# Begin Source File
SOURCE=.\xmltok\xmlrole.c
!IF "$(CFG)" == "xmltok - Win32 Release"
DEP_CPP_XMLRO=\
".\xmltok\xmldef.h"\
".\xmltok\xmlrole.h"\
@@ -914,11 +976,31 @@ NODEP_CPP_XMLRO=\
$(CPP) $(CPP_PROJ) $(SOURCE)
!ELSEIF "$(CFG)" == "xmltok - Win32 Debug"
DEP_CPP_XMLRO=\
".\xmltok\xmldef.h"\
".\xmltok\xmlrole.h"\
".\xmltok\xmltok.h"\
NODEP_CPP_XMLRO=\
".\xmltok\nspr.h"\
"$(INTDIR)\xmlrole.obj" : $(SOURCE) $(DEP_CPP_XMLRO) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF
# End Source File
################################################################################
# Begin Source File
SOURCE=.\xmltok\xmltok.c
!IF "$(CFG)" == "xmltok - Win32 Release"
DEP_CPP_XMLTO=\
".\xmltok\asciitab.h"\
".\xmltok\iasciitab.h"\
@@ -938,16 +1020,51 @@ NODEP_CPP_XMLTO=\
$(CPP) $(CPP_PROJ) $(SOURCE)
!ELSEIF "$(CFG)" == "xmltok - Win32 Debug"
DEP_CPP_XMLTO=\
".\xmltok\asciitab.h"\
".\xmltok\iasciitab.h"\
".\xmltok\latin1tab.h"\
".\xmltok\nametab.h"\
".\xmltok\utf8tab.h"\
".\xmltok\xmldef.h"\
".\xmltok\xmltok.h"\
".\xmltok\xmltok_impl.c"\
".\xmltok\xmltok_impl.h"\
NODEP_CPP_XMLTO=\
".\xmltok\nspr.h"\
"$(INTDIR)\xmltok.obj" : $(SOURCE) $(DEP_CPP_XMLTO) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF
# End Source File
################################################################################
# Begin Source File
SOURCE=.\xmltok\dllmain.c
!IF "$(CFG)" == "xmltok - Win32 Release"
"$(INTDIR)\dllmain.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ELSEIF "$(CFG)" == "xmltok - Win32 Debug"
"$(INTDIR)\dllmain.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF
# End Source File
# End Target
# End Project
+21 -15
View File
@@ -2,28 +2,34 @@
$Revision: 1.17 $
EndOptions
$(projectdir)/MPL-1_0.html a 1.1
$(projectdir)/Makefile a 1.5
$(projectdir)/expat.html a 1.4
$(projectdir)/expat.mak a 1.12
$(projectdir)/Makefile a 1.6
$(projectdir)/expat.html a 1.7
$(projectdir)/expat.mak a 1.14
$(projectdir)/files.txt a 1.3
$(projectdir)/makedist.ksh a 1.1
$(projectdir)/gennmtab/gennmtab.c a 1.2
$(projectdir)/xmlparse/hashtable.c a 1.4
$(projectdir)/xmlparse/hashtable.h a 1.3
$(projectdir)/xmlparse/xmlparse.c a 1.25
$(projectdir)/xmlparse/xmlparse.h a 1.4
$(projectdir)/sample/build.bat a 1.2
$(projectdir)/sample/elements.c a 1.1
$(projectdir)/xmlparse/hashtable.c a 1.5
$(projectdir)/xmlparse/hashtable.h a 1.4
$(projectdir)/xmlparse/xmlparse.c a 1.52
$(projectdir)/xmlparse/xmlparse.h a 1.21
$(projectdir)/xmltok/asciitab.h a 1.4
$(projectdir)/xmltok/dllmain.c a 1.2
$(projectdir)/xmltok/iasciitab.h a 1.2
$(projectdir)/xmltok/latin1tab.h a 1.2
$(projectdir)/xmltok/utf8tab.h a 1.4
$(projectdir)/xmltok/xmldef.h a 1.3
$(projectdir)/xmltok/xmlrole.c a 1.8
$(projectdir)/xmltok/xmlrole.h a 1.4
$(projectdir)/xmltok/xmltok.c a 1.23
$(projectdir)/xmltok/xmltok.h a 1.16
$(projectdir)/xmltok/xmltok_impl.c a 1.22
$(projectdir)/xmltok/xmlrole.c a 1.9
$(projectdir)/xmltok/xmlrole.h a 1.5
$(projectdir)/xmltok/xmltok.c a 1.33
$(projectdir)/xmltok/xmltok.h a 1.24
$(projectdir)/xmltok/xmltok_impl.c a 1.26
$(projectdir)/xmltok/xmltok_impl.h a 1.5
$(projectdir)/xmlwf/filemap.h a 1.2
$(projectdir)/xmlwf/codepage.c a 1.4
$(projectdir)/xmlwf/codepage.h a 1.3
$(projectdir)/xmlwf/filemap.h a 1.3
$(projectdir)/xmlwf/readfilemap.c a 1.3
$(projectdir)/xmlwf/unixfilemap.c a 1.2
$(projectdir)/xmlwf/win32filemap.c a 1.3
$(projectdir)/xmlwf/xmlwf.c a 1.17
$(projectdir)/xmlwf/win32filemap.c a 1.4
$(projectdir)/xmlwf/xmlwf.c a 1.31
+31
View File
@@ -0,0 +1,31 @@
expat.html
MPL-1_0.html
xmltok/asciitab.h
xmltok/dllmain.c
gennmtab/gennmtab.c
xmltok/iasciitab.h
xmltok/latin1tab.h
Makefile
xmltok/nametab.h
xmltok/utf8tab.h
xmltok/xmldef.h
xmltok/xmlrole.c
xmltok/xmlrole.h
xmltok/xmltok.c
xmltok/xmltok.h
expat.mak
xmltok/xmltok_impl.c
xmltok/xmltok_impl.h
xmlparse/hashtable.c
xmlparse/hashtable.h
xmlparse/xmlparse.c
xmlparse/xmlparse.h
xmlwf/codepage.c
xmlwf/codepage.h
xmlwf/filemap.h
xmlwf/readfilemap.c
xmlwf/unixfilemap.c
xmlwf/win32filemap.c
xmlwf/xmlwf.c
sample/elements.c
sample/build.bat
+15
View File
@@ -0,0 +1,15 @@
rm -fr expat
mkdir expat
tar cf - `cat files.txt` | (cd expat; tar xf -)
files=`grep -v expat.mak files.txt`
(cd expat; flip -u $files)
mkdir expat/bin
mkdir expat/lib
xcopy bin\\xmltok.dll expat\\bin
xcopy bin\\xmlparse.dll expat\\bin
xcopy xmltok\\Release\\xmltok.lib expat\\lib
xcopy xmlparse\\Release\\xmlparse.lib expat\\lib
xcopy bin\\xmlwf.exe expat\\bin
rm -f expat.zip
zip -qr expat.zip expat
rm -fr expat
+4
View File
@@ -0,0 +1,4 @@
@echo off
set LIB=..\xmlparse\Release;..\lib;%LIB%
cl /nologo /DXMLTOKAPI=__declspec(dllimport) /DXMLPARSEAPI=__declspec(dllimport) /I..\xmlparse /Fe..\bin\elements elements.c xmlparse.lib
@echo Run it using: ..\bin\elements ^<..\expat.html
+46
View File
@@ -0,0 +1,46 @@
/* This is simple demonstration of how to use expat. This program
reads an XML document from standard input and writes a line with the
name of each element to standard output indenting child elements by
one tab stop more than their parent element. */
#include <stdio.h>
#include "xmlparse.h"
void startElement(void *userData, const char *name, const char **atts)
{
int i;
int *depthPtr = userData;
for (i = 0; i < *depthPtr; i++)
putchar('\t');
puts(name);
*depthPtr += 1;
}
void endElement(void *userData, const char *name)
{
int *depthPtr = userData;
*depthPtr -= 1;
}
int main()
{
char buf[BUFSIZ];
XML_Parser parser = XML_ParserCreate(NULL);
int done;
int depth = 0;
XML_SetUserData(parser, &depth);
XML_SetElementHandler(parser, startElement, endElement);
do {
size_t len = fread(buf, 1, sizeof(buf), stdin);
done = len < sizeof(buf);
if (!XML_Parse(parser, buf, len, done)) {
fprintf(stderr,
"%s at line %d\n",
XML_ErrorString(XML_GetErrorCode(parser)),
XML_GetCurrentLineNumber(parser));
return 1;
}
} while (!done);
XML_ParserFree(parser);
return 0;
}
+13 -6
View File
@@ -1,7 +1,7 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
csompliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
@@ -18,15 +18,22 @@ James Clark. All Rights Reserved.
Contributor(s):
*/
#include "xmldef.h"
#include "hashtable.h"
#include <stdlib.h>
#include <string.h>
#include "xmldef.h"
#include "hashtable.h"
#ifdef XML_UNICODE
#define keycmp wcscmp
#else
#define keycmp strcmp
#endif
#define INIT_SIZE 64
static
unsigned long hash(const char *s)
unsigned long hash(KEY s)
{
unsigned long h = 0;
while (*s)
@@ -34,7 +41,7 @@ unsigned long hash(const char *s)
return h;
}
NAMED *lookup(HASH_TABLE *table, const char *name, size_t createSize)
NAMED *lookup(HASH_TABLE *table, KEY name, size_t createSize)
{
size_t i;
if (table->size == 0) {
@@ -52,7 +59,7 @@ NAMED *lookup(HASH_TABLE *table, const char *name, size_t createSize)
for (i = h & (table->size - 1);
table->v[i];
i == 0 ? i = table->size - 1 : --i) {
if (strcmp(name, table->v[i]->name) == 0)
if (keycmp(name, table->v[i]->name) == 0)
return table->v[i];
}
if (!createSize)
+8 -2
View File
@@ -21,8 +21,14 @@ Contributor(s):
#include <stddef.h>
#ifdef XML_UNICODE
typedef const wchar_t *KEY;
#else
typedef const char *KEY;
#endif
typedef struct {
const char *name;
KEY name;
} NAMED;
typedef struct {
@@ -32,7 +38,7 @@ typedef struct {
size_t usedLim;
} HASH_TABLE;
NAMED *lookup(HASH_TABLE *table, const char *name, size_t createSize);
NAMED *lookup(HASH_TABLE *table, KEY name, size_t createSize);
void hashTableInit(HASH_TABLE *);
void hashTableDestroy(HASH_TABLE *);
+1167 -313
View File
File diff suppressed because it is too large Load Diff
+272 -22
View File
@@ -31,32 +31,199 @@ extern "C" {
typedef void *XML_Parser;
/* Constructs a new parser; encoding should be the name of the charset from
the Content-Type header if the Content-Type is text/xml, or null otherwise. */
#ifdef XML_UNICODE_WCHAR_T
XML_Parser XMLPARSEAPI
XML_ParserCreate(const char *encoding);
/* XML_UNICODE_WCHAR_T will work only if sizeof(wchar_t) == 2 and wchar_t
uses Unicode. */
/* Information is UTF-16 encoded as wchar_ts */
#ifndef XML_UNICODE
#define XML_UNICODE
#endif
#include <stddef.h>
typedef wchar_t XML_Char;
typedef wchar_t XML_LChar;
#else /* not XML_UNICODE_WCHAR_T */
#ifdef XML_UNICODE
/* Information is UTF-16 encoded as unsigned shorts */
typedef unsigned short XML_Char;
typedef char XML_LChar;
#else /* not XML_UNICODE */
/* Information is UTF-8 encoded. */
typedef char XML_Char;
typedef char XML_LChar;
/* atts is array of name/value pairs, terminated by NULL;
names and values are '\0' terminated. */
#endif /* not XML_UNICODE */
#endif /* not XML_UNICODE_WCHAR_T */
/* Constructs a new parser; encoding is the encoding specified by the external
protocol or null if there is none specified. */
XML_Parser XMLPARSEAPI
XML_ParserCreate(const XML_Char *encoding);
/* atts is array of name/value pairs, terminated by 0;
names and values are 0 terminated. */
typedef void (*XML_StartElementHandler)(void *userData,
const char *name,
const char **atts);
const XML_Char *name,
const XML_Char **atts);
typedef void (*XML_EndElementHandler)(void *userData,
const char *name);
const XML_Char *name);
/* s is not 0 terminated. */
typedef void (*XML_CharacterDataHandler)(void *userData,
const char *s,
const XML_Char *s,
int len);
/* target and data are '\0' terminated */
/* target and data are 0 terminated */
typedef void (*XML_ProcessingInstructionHandler)(void *userData,
const char *target,
const char *data);
const XML_Char *target,
const XML_Char *data);
/* This is called for any characters in the XML document for
which there is no applicable handler. This includes both
characters that are part of markup which is of a kind that is
not reported (comments, markup declarations), or characters
that are part of a construct which could be reported but
for which no handler has been supplied. The characters are passed
exactly as they were in the XML document except that
they will be encoded in UTF-8. Line boundaries are not normalized.
Note that a byte order mark character is not passed to the default handler.
If a default handler is set, internal entity references
are not expanded. There are no guarantees about
how characters are divided between calls to the default handler:
for example, a comment might be split between multiple calls. */
typedef void (*XML_DefaultHandler)(void *userData,
const XML_Char *s,
int len);
/* This is called for a declaration of an unparsed (NDATA)
entity. The base argument is whatever was set by XML_SetBase.
The entityName, systemId and notationName arguments will never be null.
The other arguments may be. */
typedef void (*XML_UnparsedEntityDeclHandler)(void *userData,
const XML_Char *entityName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId,
const XML_Char *notationName);
/* This is called for a declaration of notation.
The base argument is whatever was set by XML_SetBase.
The notationName will never be null. The other arguments can be. */
typedef void (*XML_NotationDeclHandler)(void *userData,
const XML_Char *notationName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
/* This is called for a reference to an external parsed general entity.
The referenced entity is not automatically parsed.
The application can parse it immediately or later using
XML_ExternalEntityParserCreate.
The parser argument is the parser parsing the entity containing the reference;
it can be passed as the parser argument to XML_ExternalEntityParserCreate.
The systemId argument is the system identifier as specified in the entity declaration;
it will not be null.
The base argument is the system identifier that should be used as the base for
resolving systemId if systemId was relative; this is set by XML_SetBase;
it may be null.
The publicId argument is the public identifier as specified in the entity declaration,
or null if none was specified; the whitespace in the public identifier
will have been normalized as required by the XML spec.
The openEntityNames argument is a space-separated list of the names of the entities
that are open for the parse of this entity (including the name of the referenced
entity); this can be passed as the openEntityNames argument to
XML_ExternalEntityParserCreate; openEntityNames is valid only until the handler
returns, so if the referenced entity is to be parsed later, it must be copied.
The handler should return 0 if processing should not continue because of
a fatal error in the handling of the external entity.
In this case the calling parser will return an XML_ERROR_EXTERNAL_ENTITY_HANDLING
error.
Note that unlike other handlers the first argument is the parser, not userData. */
typedef int (*XML_ExternalEntityRefHandler)(XML_Parser parser,
const XML_Char *openEntityNames,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
/* This structure is filled in by the XML_UnknownEncodingHandler
to provide information to the parser about encodings that are unknown
to the parser.
The map[b] member gives information about byte sequences
whose first byte is b.
If map[b] is c where c is >= 0, then b by itself encodes the Unicode scalar value c.
If map[b] is -1, then the byte sequence is malformed.
If map[b] is -n, where n >= 2, then b is the first byte of an n-byte
sequence that encodes a single Unicode scalar value.
The data member will be passed as the first argument to the convert function.
The convert function is used to convert multibyte sequences;
s will point to a n-byte sequence where map[(unsigned char)*s] == -n.
The convert function must return the Unicode scalar value
represented by this byte sequence or -1 if the byte sequence is malformed.
The convert function may be null if the encoding is a single-byte encoding,
that is if map[b] >= -1 for all bytes b.
When the parser is finished with the encoding, then if release is not null,
it will call release passing it the data member;
once release has been called, the convert function will not be called again.
Expat places certain restrictions on the encodings that are supported
using this mechanism.
1. Every ASCII character that can appear in a well-formed XML document,
other than the characters
$@\^`{}~
must be represented by a single byte, and that byte must be the
same byte that represents that character in ASCII.
2. No character may require more than 4 bytes to encode.
3. All characters encoded must have Unicode scalar values <= 0xFFFF,
(ie characters that would be encoded by surrogates in UTF-16
are not allowed). Note that this restriction doesn't apply to
the built-in support for UTF-8 and UTF-16.
4. No Unicode character may be encoded by more than one distinct sequence
of bytes. */
typedef struct {
int map[256];
void *data;
int (*convert)(void *data, const char *s);
void (*release)(void *data);
} XML_Encoding;
/* This is called for an encoding that is unknown to the parser.
The encodingHandlerData argument is that which was passed as the
second argument to XML_SetUnknownEncodingHandler.
The name argument gives the name of the encoding as specified in
the encoding declaration.
If the callback can provide information about the encoding,
it must fill in the XML_Encoding structure, and return 1.
Otherwise it must return 0.
If info does not describe a suitable encoding,
then the parser will return an XML_UNKNOWN_ENCODING error. */
typedef int (*XML_UnknownEncodingHandler)(void *encodingHandlerData,
const XML_Char *name,
XML_Encoding *info);
void XMLPARSEAPI
XML_SetElementHandler(XML_Parser parser,
@@ -71,10 +238,62 @@ void XMLPARSEAPI
XML_SetProcessingInstructionHandler(XML_Parser parser,
XML_ProcessingInstructionHandler handler);
void XMLPARSEAPI
XML_SetDefaultHandler(XML_Parser parser,
XML_DefaultHandler handler);
void XMLPARSEAPI
XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
XML_UnparsedEntityDeclHandler handler);
void XMLPARSEAPI
XML_SetNotationDeclHandler(XML_Parser parser,
XML_NotationDeclHandler handler);
void XMLPARSEAPI
XML_SetExternalEntityRefHandler(XML_Parser parser,
XML_ExternalEntityRefHandler handler);
void XMLPARSEAPI
XML_SetUnknownEncodingHandler(XML_Parser parser,
XML_UnknownEncodingHandler handler,
void *encodingHandlerData);
/* This can be called within a handler for a start element, end element,
processing instruction or character data. It causes the corresponding
markup to be passed to the default handler.
Within the expansion of an internal entity, nothing will be passed
to the default handler, although this usually will not happen since
setting a default handler inhibits expansion of internal entities. */
void XMLPARSEAPI XML_DefaultCurrent(XML_Parser parser);
/* This value is passed as the userData argument to callbacks. */
void XMLPARSEAPI
XML_SetUserData(XML_Parser parser, void *userData);
/* Returns the last value set by XML_SetUserData or null. */
#define XML_GetUserData(parser) (*(void **)(parser))
/* If this function is called, then the parser will be passed
as the first argument to callbacks instead of userData.
The userData will still be accessible using XML_GetUserData. */
void XMLPARSEAPI
XML_UseParserAsHandlerArg(XML_Parser parser);
/* Sets the base to be used for resolving relative URIs in system identifiers in
declarations. Resolving relative identifiers is left to the application:
this value will be passed through as the base argument to the
XML_ExternalEntityRefHandler, XML_NotationDeclHandler
and XML_UnparsedEntityDeclHandler. The base argument will be copied.
Returns zero if out of memory, non-zero otherwise. */
int XMLPARSEAPI
XML_SetBase(XML_Parser parser, const XML_Char *base);
const XML_Char XMLPARSEAPI *
XML_GetBase(XML_Parser parser);
/* Parses some input. Returns 0 if a fatal error is detected.
The last call to XML_Parse must have isFinal true;
len may be zero for this call (or any other). */
@@ -87,8 +306,20 @@ XML_GetBuffer(XML_Parser parser, int len);
int XMLPARSEAPI
XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
/* If XML_Parser or XML_ParseEnd have returned 0, then XML_GetError*
returns information about the error. */
/* Creates an XML_Parser object that can parse an external general entity;
openEntityNames is a space-separated list of the names of the entities that are open
for the parse of this entity (including the name of this one);
encoding is the externally specified encoding,
or null if there is no externally specified encoding.
This can be called at any point after the first call to an ExternalEntityRefHandler
so longer as the parser has not yet been freed.
The new parser is completely independent and may safely be used in a separate thread.
The handlers and userData are initialized from the parser argument.
Returns 0 if out of memory. Otherwise returns a new XML_Parser object. */
XML_Parser XMLPARSEAPI
XML_ExternalEntityParserCreate(XML_Parser parser,
const XML_Char *openEntityNames,
const XML_Char *encoding);
enum XML_Error {
XML_ERROR_NONE,
@@ -111,19 +342,38 @@ enum XML_Error {
XML_ERROR_MISPLACED_XML_PI,
XML_ERROR_UNKNOWN_ENCODING,
XML_ERROR_INCORRECT_ENCODING,
XML_ERROR_UNCLOSED_CDATA_SECTION
XML_ERROR_UNCLOSED_CDATA_SECTION,
XML_ERROR_EXTERNAL_ENTITY_HANDLING
};
int XMLPARSEAPI XML_GetErrorCode(XML_Parser parser);
int XMLPARSEAPI XML_GetErrorLineNumber(XML_Parser parser);
int XMLPARSEAPI XML_GetErrorColumnNumber(XML_Parser parser);
long XMLPARSEAPI XML_GetErrorByteIndex(XML_Parser parser);
/* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
returns information about the error. */
enum XML_Error XMLPARSEAPI XML_GetErrorCode(XML_Parser parser);
/* These functions return information about the current parse location.
They may be called when XML_Parse or XML_ParseBuffer return 0;
in this case the location is the location of the character at which
the error was detected.
They may also be called from any other callback called to report
some parse event; in this the location is the location of the first
of the sequence of characters that generated the event. */
int XMLPARSEAPI XML_GetCurrentLineNumber(XML_Parser parser);
int XMLPARSEAPI XML_GetCurrentColumnNumber(XML_Parser parser);
long XMLPARSEAPI XML_GetCurrentByteIndex(XML_Parser parser);
/* For backwards compatibility with previous versions. */
#define XML_GetErrorLineNumber XML_GetCurrentLineNumber
#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
#define XML_GetErrorByteIndexNumber XML_GetCurrentByteIndexNumber
/* Frees memory used by the parser. */
void XMLPARSEAPI
XML_ParserFree(XML_Parser parser);
const char XMLPARSEAPI *
XML_ErrorString(int code);
/* Returns a string describing the error. */
const XML_LChar XMLPARSEAPI *XML_ErrorString(int code);
#ifdef __cplusplus
}
+1 -1
View File
@@ -594,7 +594,7 @@ int notation4(PROLOG_STATE *state,
return XML_ROLE_NOTATION_SYSTEM_ID;
case XML_TOK_DECL_CLOSE:
state->handler = internalSubset;
return XML_ROLE_NONE;
return XML_ROLE_NOTATION_NO_SYSTEM_ID;
}
return syntaxError(state);
}
+1
View File
@@ -44,6 +44,7 @@ enum {
XML_ROLE_ENTITY_NOTATION_NAME,
XML_ROLE_NOTATION_NAME,
XML_ROLE_NOTATION_SYSTEM_ID,
XML_ROLE_NOTATION_NO_SYSTEM_ID,
XML_ROLE_NOTATION_PUBLIC_ID,
XML_ROLE_ATTRIBUTE_NAME,
XML_ROLE_ATTRIBUTE_TYPE_CDATA,
+490 -114
View File
@@ -31,14 +31,11 @@ Contributor(s):
PREFIX(skipS), \
PREFIX(getAtts), \
PREFIX(charRefNumber), \
PREFIX(predefinedEntityName), \
PREFIX(updatePosition), \
PREFIX(isPublicId)
#define VTABLE2 \
PREFIX(encode), \
{ PREFIX(toUtf8) }
#define VTABLE VTABLE1, VTABLE2
#define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16)
#define UCS2_GET_NAMING(pages, hi, lo) \
(namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1 << ((lo) & 0x1F)))
@@ -81,11 +78,79 @@ We need 8 bits to index into pages, 3 bits to add to that index and
#define UTF8_INVALID4(p) ((*p) == 0xF4 && ((p)[1] & 0x30) != 0)
static
int isNever(const ENCODING *enc, const char *p)
{
return 0;
}
static
int utf8_isName2(const ENCODING *enc, const char *p)
{
return UTF8_GET_NAMING2(namePages, (const unsigned char *)p);
}
static
int utf8_isName3(const ENCODING *enc, const char *p)
{
return UTF8_GET_NAMING3(namePages, (const unsigned char *)p);
}
#define utf8_isName4 isNever
static
int utf8_isNmstrt2(const ENCODING *enc, const char *p)
{
return UTF8_GET_NAMING2(namePages, (const unsigned char *)p);
}
static
int utf8_isNmstrt3(const ENCODING *enc, const char *p)
{
return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p);
}
#define utf8_isNmstrt4 isNever
#define utf8_isInvalid2 isNever
static
int utf8_isInvalid3(const ENCODING *enc, const char *p)
{
return UTF8_INVALID3((const unsigned char *)p);
}
static
int utf8_isInvalid4(const ENCODING *enc, const char *p)
{
return UTF8_INVALID4((const unsigned char *)p);
}
struct normal_encoding {
ENCODING enc;
unsigned char type[256];
int (*isName2)(const ENCODING *, const char *);
int (*isName3)(const ENCODING *, const char *);
int (*isName4)(const ENCODING *, const char *);
int (*isNmstrt2)(const ENCODING *, const char *);
int (*isNmstrt3)(const ENCODING *, const char *);
int (*isNmstrt4)(const ENCODING *, const char *);
int (*isInvalid2)(const ENCODING *, const char *);
int (*isInvalid3)(const ENCODING *, const char *);
int (*isInvalid4)(const ENCODING *, const char *);
};
#define NORMAL_VTABLE(E) \
E ## isName2, \
E ## isName3, \
E ## isName4, \
E ## isNmstrt2, \
E ## isNmstrt3, \
E ## isNmstrt4, \
E ## isInvalid2, \
E ## isInvalid3, \
E ## isInvalid4
static int checkCharRefNumber(int);
#include "xmltok_impl.h"
@@ -95,12 +160,16 @@ static int checkCharRefNumber(int);
#define BYTE_TYPE(enc, p) \
(((struct normal_encoding *)(enc))->type[(unsigned char)*(p)])
#define BYTE_TO_ASCII(enc, p) (*p)
#define IS_NAME_CHAR(enc, p, n) UTF8_GET_NAMING(namePages, p, n)
#define IS_NMSTRT_CHAR(enc, p, n) UTF8_GET_NAMING(nmstrtPages, p, n)
#define IS_NAME_CHAR(enc, p, n) \
(((const struct normal_encoding *)(enc))->isName ## n(enc, p))
#define IS_NMSTRT_CHAR(enc, p, n) \
(((const struct normal_encoding *)(enc))->isNmstrt ## n(enc, p))
#define IS_INVALID_CHAR(enc, p, n) \
((n) == 3 \
? UTF8_INVALID3((const unsigned char *)(p)) \
: ((n) == 4 ? UTF8_INVALID4((const unsigned char *)(p)) : 0))
(((const struct normal_encoding *)(enc))->isInvalid ## n(enc, p))
#define IS_NAME_CHAR_MINBPC(enc, p) (0)
#define IS_NMSTRT_CHAR_MINBPC(enc, p) (0)
/* c is an ASCII character */
#define CHAR_MATCHES(enc, p, c) (*(p) == c)
@@ -113,51 +182,18 @@ static int checkCharRefNumber(int);
#undef BYTE_TO_ASCII
#undef CHAR_MATCHES
#undef IS_NAME_CHAR
#undef IS_NAME_CHAR_MINBPC
#undef IS_NMSTRT_CHAR
#undef IS_NMSTRT_CHAR_MINBPC
#undef IS_INVALID_CHAR
enum {
/* cvalN is value of masked first byte of N byte sequence */
cval1 = 0x00,
cval2 = 0xc0,
cval3 = 0xe0,
cval4 = 0xf0,
/* minN is minimum legal resulting value for N byte sequence */
min2 = 0x80,
min3 = 0x800,
min4 = 0x10000
enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */
UTF8_cval1 = 0x00,
UTF8_cval2 = 0xc0,
UTF8_cval3 = 0xe0,
UTF8_cval4 = 0xf0
};
static
int utf8_encode(const ENCODING *enc, int c, char *buf)
{
if (c < 0)
return 0;
if (c < min2) {
buf[0] = (c | cval1);
return 1;
}
if (c < min3) {
buf[0] = ((c >> 6) | cval2);
buf[1] = ((c & 0x3f) | 0x80);
return 2;
}
if (c < min4) {
buf[0] = ((c >> 12) | cval3);
buf[1] = (((c >> 6) & 0x3f) | 0x80);
buf[2] = ((c & 0x3f) | 0x80);
return 3;
}
if (c < 0x110000) {
buf[0] = ((c >> 18) | cval4);
buf[1] = (((c >> 12) & 0x3f) | 0x80);
buf[2] = (((c >> 6) & 0x3f) | 0x80);
buf[3] = ((c & 0x3f) | 0x80);
return 4;
}
return 0;
}
static
void utf8_toUtf8(const ENCODING *enc,
const char **fromP, const char *fromLim,
@@ -177,34 +213,63 @@ void utf8_toUtf8(const ENCODING *enc,
*toP = to;
}
static
void utf8_toUtf16(const ENCODING *enc,
const char **fromP, const char *fromLim,
unsigned short **toP, const unsigned short *toLim)
{
unsigned short *to = *toP;
const char *from = *fromP;
while (from != fromLim && to != toLim) {
switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) {
case BT_LEAD2:
*to++ = ((from[0] & 0x1f) << 6) | (from[1] & 0x3f);
from += 2;
break;
case BT_LEAD3:
*to++ = ((from[0] & 0xf) << 12) | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f);
from += 3;
break;
case BT_LEAD4:
{
unsigned long n;
if (to + 1 == toLim)
break;
n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12) | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f);
n -= 0x10000;
to[0] = (unsigned short)((n >> 10) | 0xD800);
to[1] = (unsigned short)((n & 0x3FF) | 0xDC00);
to += 2;
from += 4;
}
break;
default:
*to++ = *from++;
break;
}
}
*fromP = from;
*toP = to;
}
static const struct normal_encoding utf8_encoding = {
{ VTABLE1, utf8_encode, { utf8_toUtf8 }, 1 },
{ VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
{
#include "asciitab.h"
#include "utf8tab.h"
}
},
NORMAL_VTABLE(utf8_)
};
static const struct normal_encoding internal_utf8_encoding = {
{ VTABLE1, utf8_encode, { utf8_toUtf8 }, 1 },
{ VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 },
{
#include "iasciitab.h"
#include "utf8tab.h"
}
},
NORMAL_VTABLE(utf8_)
};
static
int latin1_encode(const ENCODING *enc, int c, char *buf)
{
if (c < 0)
return 0;
if (c <= 0xFF) {
buf[0] = (char)c;
return 1;
}
return 0;
}
static
void latin1_toUtf8(const ENCODING *enc,
const char **fromP, const char *fromLim,
@@ -218,7 +283,7 @@ void latin1_toUtf8(const ENCODING *enc,
if (c & 0x80) {
if (toLim - *toP < 2)
break;
*(*toP)++ = ((c >> 6) | cval2);
*(*toP)++ = ((c >> 6) | UTF8_cval2);
*(*toP)++ = ((c & 0x3f) | 0x80);
(*fromP)++;
}
@@ -230,15 +295,39 @@ void latin1_toUtf8(const ENCODING *enc,
}
}
static
void latin1_toUtf16(const ENCODING *enc,
const char **fromP, const char *fromLim,
unsigned short **toP, const unsigned short *toLim)
{
while (*fromP != fromLim && *toP != toLim)
*(*toP)++ = (unsigned char)*(*fromP)++;
}
static const struct normal_encoding latin1_encoding = {
{ VTABLE1, latin1_encode, { latin1_toUtf8 }, 1 },
{ VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 },
{
#include "asciitab.h"
#include "latin1tab.h"
}
};
#define latin1tab (latin1_encoding.type)
static
void ascii_toUtf8(const ENCODING *enc,
const char **fromP, const char *fromLim,
char **toP, const char *toLim)
{
while (*fromP != fromLim && *toP != toLim)
*(*toP)++ = *(*fromP)++;
}
static const struct normal_encoding ascii_encoding = {
{ VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 },
{
#include "asciitab.h"
/* BT_NONXML == 0 */
}
};
#undef PREFIX
@@ -260,25 +349,6 @@ static int unicode_byte_type(char hi, char lo)
return BT_NONASCII;
}
#define DEFINE_UTF16_ENCODE \
static \
int PREFIX(encode)(const ENCODING *enc, int charNum, char *buf) \
{ \
if (charNum < 0) \
return 0; \
if (charNum < 0x10000) { \
SET2(buf, charNum); \
return 2; \
} \
if (charNum < 0x110000) { \
charNum -= 0x10000; \
SET2(buf, (charNum >> 10) + 0xD800); \
SET2(buf + 2, (charNum & 0x3FF) + 0xDC00); \
return 4; \
} \
return 0; \
}
#define DEFINE_UTF16_TO_UTF8 \
static \
void PREFIX(toUtf8)(const ENCODING *enc, \
@@ -308,7 +378,7 @@ void PREFIX(toUtf8)(const ENCODING *enc, \
*fromP = from; \
return; \
} \
*(*toP)++ = ((lo >> 6) | (hi << 2) | cval2); \
*(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \
*(*toP)++ = ((lo & 0x3f) | 0x80); \
break; \
default: \
@@ -317,7 +387,7 @@ void PREFIX(toUtf8)(const ENCODING *enc, \
return; \
} \
/* 16 bits divided 4, 6, 6 amongst 3 bytes */ \
*(*toP)++ = ((hi >> 4) | cval3); \
*(*toP)++ = ((hi >> 4) | UTF8_cval3); \
*(*toP)++ = (((hi & 0xf) << 2) | (lo >> 6) | 0x80); \
*(*toP)++ = ((lo & 0x3f) | 0x80); \
break; \
@@ -327,7 +397,7 @@ void PREFIX(toUtf8)(const ENCODING *enc, \
return; \
} \
plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \
*(*toP)++ = ((plane >> 2) | cval4); \
*(*toP)++ = ((plane >> 2) | UTF8_cval4); \
*(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \
from += 2; \
lo2 = GET_LO(from); \
@@ -342,15 +412,33 @@ void PREFIX(toUtf8)(const ENCODING *enc, \
*fromP = from; \
}
#define DEFINE_UTF16_TO_UTF16 \
static \
void PREFIX(toUtf16)(const ENCODING *enc, \
const char **fromP, const char *fromLim, \
unsigned short **toP, const unsigned short *toLim) \
{ \
/* Avoid copying first half only of surrogate */ \
if (fromLim - *fromP > ((toLim - *toP) << 1) \
&& (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \
fromLim -= 2; \
for (; *fromP != fromLim && *toP != toLim; *fromP += 2) \
*(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \
}
#define PREFIX(ident) little2_ ## ident
#define MINBPC 2
#define BYTE_TYPE(enc, p) \
((p)[1] == 0 ? latin1tab[(unsigned char)*(p)] : unicode_byte_type((p)[1], (p)[0]))
((p)[1] == 0 \
? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \
: unicode_byte_type((p)[1], (p)[0]))
#define BYTE_TO_ASCII(enc, p) ((p)[1] == 0 ? (p)[0] : -1)
#define CHAR_MATCHES(enc, p, c) ((p)[1] == 0 && (p)[0] == c)
#define IS_NAME_CHAR(enc, p, n) \
#define IS_NAME_CHAR(enc, p, n) (0)
#define IS_NAME_CHAR_MINBPC(enc, p) \
UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0])
#define IS_NMSTRT_CHAR(enc, p, n) \
#define IS_NMSTRT_CHAR(enc, p, n) (0)
#define IS_NMSTRT_CHAR_MINBPC(enc, p) \
UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[1], (unsigned char)p[0])
#include "xmltok_impl.c"
@@ -360,8 +448,8 @@ void PREFIX(toUtf8)(const ENCODING *enc, \
#define GET_LO(ptr) ((unsigned char)(ptr)[0])
#define GET_HI(ptr) ((unsigned char)(ptr)[1])
DEFINE_UTF16_ENCODE
DEFINE_UTF16_TO_UTF8
DEFINE_UTF16_TO_UTF16
#undef SET2
#undef GET_LO
@@ -371,10 +459,32 @@ DEFINE_UTF16_TO_UTF8
#undef BYTE_TO_ASCII
#undef CHAR_MATCHES
#undef IS_NAME_CHAR
#undef IS_NAME_CHAR_MINBPC
#undef IS_NMSTRT_CHAR
#undef IS_NMSTRT_CHAR_MINBPC
#undef IS_INVALID_CHAR
static const struct encoding little2_encoding = { VTABLE, 2 };
static const struct normal_encoding little2_encoding = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 12
1
#else
0
#endif
},
#include "asciitab.h"
#include "latin1tab.h"
};
#if BYTE_ORDER != 21
static const struct normal_encoding internal_little2_encoding = {
{ VTABLE, 2, 0, 1 },
#include "iasciitab.h"
#include "latin1tab.h"
};
#endif
#undef PREFIX
@@ -382,12 +492,16 @@ static const struct encoding little2_encoding = { VTABLE, 2 };
#define MINBPC 2
/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */
#define BYTE_TYPE(enc, p) \
((p)[0] == 0 ? latin1tab[(unsigned char)(p)[1]] : unicode_byte_type((p)[0], (p)[1]))
((p)[0] == 0 \
? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \
: unicode_byte_type((p)[0], (p)[1]))
#define BYTE_TO_ASCII(enc, p) ((p)[0] == 0 ? (p)[1] : -1)
#define CHAR_MATCHES(enc, p, c) ((p)[0] == 0 && (p)[1] == c)
#define IS_NAME_CHAR(enc, p, n) \
#define IS_NAME_CHAR(enc, p, n) 0
#define IS_NAME_CHAR_MINBPC(enc, p) \
UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1])
#define IS_NMSTRT_CHAR(enc, p, n) \
#define IS_NMSTRT_CHAR(enc, p, n) (0)
#define IS_NMSTRT_CHAR_MINBPC(enc, p) \
UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[0], (unsigned char)p[1])
#include "xmltok_impl.c"
@@ -397,8 +511,8 @@ static const struct encoding little2_encoding = { VTABLE, 2 };
#define GET_LO(ptr) ((unsigned char)(ptr)[1])
#define GET_HI(ptr) ((unsigned char)(ptr)[0])
DEFINE_UTF16_ENCODE
DEFINE_UTF16_TO_UTF8
DEFINE_UTF16_TO_UTF16
#undef SET2
#undef GET_LO
@@ -408,10 +522,32 @@ DEFINE_UTF16_TO_UTF8
#undef BYTE_TO_ASCII
#undef CHAR_MATCHES
#undef IS_NAME_CHAR
#undef IS_NAME_CHAR_MINBPC
#undef IS_NMSTRT_CHAR
#undef IS_NMSTRT_CHAR_MINBPC
#undef IS_INVALID_CHAR
static const struct encoding big2_encoding = { VTABLE, 2 };
static const struct normal_encoding big2_encoding = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 21
1
#else
0
#endif
},
#include "asciitab.h"
#include "latin1tab.h"
};
#if BYTE_ORDER != 12
static const struct normal_encoding internal_big2_encoding = {
{ VTABLE, 2, 0, 1 },
#include "iasciitab.h"
#include "latin1tab.h"
};
#endif
#undef PREFIX
@@ -454,18 +590,18 @@ int initScan(const ENCODING *enc, int state, const char *ptr, const char *end,
else {
switch (((unsigned char)ptr[0] << 8) | (unsigned char)ptr[1]) {
case 0x003C:
*encPtr = &big2_encoding;
*encPtr = &big2_encoding.enc;
return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
case 0xFEFF:
*nextTokPtr = ptr + 2;
*encPtr = &big2_encoding;
*encPtr = &big2_encoding.enc;
return XML_TOK_BOM;
case 0x3C00:
*encPtr = &little2_encoding;
*encPtr = &little2_encoding.enc;
return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
case 0xFFFE:
*nextTokPtr = ptr + 2;
*encPtr = &little2_encoding;
*encPtr = &little2_encoding.enc;
return XML_TOK_BOM;
}
}
@@ -494,13 +630,21 @@ void initUpdatePosition(const ENCODING *enc, const char *ptr,
normal_updatePosition(&utf8_encoding.enc, ptr, end, pos);
}
const ENCODING *XmlGetInternalEncoding(int e)
const ENCODING *XmlGetUtf8InternalEncoding()
{
switch (e) {
case XML_UTF8_ENCODING:
return &internal_utf8_encoding.enc;
}
return 0;
return &internal_utf8_encoding.enc;
}
const ENCODING *XmlGetUtf16InternalEncoding()
{
#if BYTE_ORDER == 12
return &internal_little2_encoding.enc;
#elif BYTE_ORDER == 21
return &internal_big2_encoding.enc;
#else
const short n = 1;
return *(const char *)&n ? &internal_little2_encoding.enc : &internal_big2_encoding.enc;
#endif
}
int XmlInitEncoding(INIT_ENCODING *p, const ENCODING **encPtr, const char *name)
@@ -514,6 +658,10 @@ int XmlInitEncoding(INIT_ENCODING *p, const ENCODING **encPtr, const char *name)
*encPtr = &utf8_encoding.enc;
return 1;
}
if (streqci(name, "US-ASCII")) {
*encPtr = &ascii_encoding.enc;
return 1;
}
if (!streqci(name, "UTF-16"))
return 0;
}
@@ -531,7 +679,7 @@ int toAscii(const ENCODING *enc, const char *ptr, const char *end)
{
char buf[1];
char *p = buf;
XmlConvert(enc, XML_UTF8_ENCODING, &ptr, end, &p, p + 1);
XmlUtf8Convert(enc, &ptr, end, &p, p + 1);
if (p == buf)
return -1;
else
@@ -641,7 +789,7 @@ const ENCODING *findEncoding(const ENCODING *enc, const char *ptr, const char *e
char buf[ENCODING_MAX];
char *p = buf;
int i;
XmlConvert(enc, XML_UTF8_ENCODING, &ptr, end, &p, p + ENCODING_MAX - 1);
XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
if (ptr != end)
return 0;
*p = 0;
@@ -653,11 +801,13 @@ const ENCODING *findEncoding(const ENCODING *enc, const char *ptr, const char *e
return &utf8_encoding.enc;
if (streqci(buf, "ISO-8859-1"))
return &latin1_encoding.enc;
if (streqci(buf, "US-ASCII"))
return &ascii_encoding.enc;
if (streqci(buf, "UTF-16")) {
static const unsigned short n = 1;
if (enc->minBytesPerChar == 2)
return enc;
return &big2_encoding;
return &big2_encoding.enc;
}
return 0;
}
@@ -757,3 +907,229 @@ int checkCharRefNumber(int result)
return result;
}
int XmlUtf8Encode(int c, char *buf)
{
enum {
/* minN is minimum legal resulting value for N byte sequence */
min2 = 0x80,
min3 = 0x800,
min4 = 0x10000
};
if (c < 0)
return 0;
if (c < min2) {
buf[0] = (c | UTF8_cval1);
return 1;
}
if (c < min3) {
buf[0] = ((c >> 6) | UTF8_cval2);
buf[1] = ((c & 0x3f) | 0x80);
return 2;
}
if (c < min4) {
buf[0] = ((c >> 12) | UTF8_cval3);
buf[1] = (((c >> 6) & 0x3f) | 0x80);
buf[2] = ((c & 0x3f) | 0x80);
return 3;
}
if (c < 0x110000) {
buf[0] = ((c >> 18) | UTF8_cval4);
buf[1] = (((c >> 12) & 0x3f) | 0x80);
buf[2] = (((c >> 6) & 0x3f) | 0x80);
buf[3] = ((c & 0x3f) | 0x80);
return 4;
}
return 0;
}
int XmlUtf16Encode(int charNum, unsigned short *buf)
{
if (charNum < 0)
return 0;
if (charNum < 0x10000) {
buf[0] = charNum;
return 1;
}
if (charNum < 0x110000) {
charNum -= 0x10000;
buf[0] = (charNum >> 10) + 0xD800;
buf[1] = (charNum & 0x3FF) + 0xDC00;
return 2;
}
return 0;
}
struct unknown_encoding {
struct normal_encoding normal;
int (*convert)(void *userData, const char *p);
void *userData;
unsigned short utf16[256];
unsigned char utf8[256][4];
};
int XmlSizeOfUnknownEncoding()
{
return sizeof(struct unknown_encoding);
}
static
int unknown_isName(const ENCODING *enc, const char *p)
{
int c = ((const struct unknown_encoding *)enc)
->convert(((const struct unknown_encoding *)enc)->userData, p);
if (c & ~0xFFFF)
return 0;
return UCS2_GET_NAMING(namePages, c >> 8, c & 0xFF);
}
static
int unknown_isNmstrt(const ENCODING *enc, const char *p)
{
int c = ((const struct unknown_encoding *)enc)
->convert(((const struct unknown_encoding *)enc)->userData, p);
if (c & ~0xFFFF)
return 0;
return UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xFF);
}
static
int unknown_isInvalid(const ENCODING *enc, const char *p)
{
int c = ((const struct unknown_encoding *)enc)
->convert(((const struct unknown_encoding *)enc)->userData, p);
return (c & ~0xFFFF) || checkCharRefNumber(c) < 0;
}
static
void unknown_toUtf8(const ENCODING *enc,
const char **fromP, const char *fromLim,
char **toP, const char *toLim)
{
char buf[XML_UTF8_ENCODE_MAX];
for (;;) {
const unsigned char *utf8;
int n;
if (*fromP == fromLim)
break;
utf8 = ((const struct unknown_encoding *)enc)->utf8[(unsigned char)**fromP];
n = *utf8++;
if (n == 0) {
int c = ((const struct unknown_encoding *)enc)
->convert(((const struct unknown_encoding *)enc)->userData, *fromP);
n = XmlUtf8Encode(c, buf);
if (n > toLim - *toP)
break;
utf8 = buf;
*fromP += ((const struct normal_encoding *)enc)->type[(unsigned char)**fromP]
- (BT_LEAD2 - 2);
}
else {
if (n > toLim - *toP)
break;
(*fromP)++;
}
do {
*(*toP)++ = *utf8++;
} while (--n != 0);
}
}
static
void unknown_toUtf16(const ENCODING *enc,
const char **fromP, const char *fromLim,
unsigned short **toP, const unsigned short *toLim)
{
while (*fromP != fromLim && *toP != toLim) {
unsigned short c
= ((const struct unknown_encoding *)enc)->utf16[(unsigned char)**fromP];
if (c == 0) {
c = (unsigned short)((const struct unknown_encoding *)enc)
->convert(((const struct unknown_encoding *)enc)->userData, *fromP);
*fromP += ((const struct normal_encoding *)enc)->type[(unsigned char)**fromP]
- (BT_LEAD2 - 2);
}
else
(*fromP)++;
*(*toP)++ = c;
}
}
ENCODING *
XmlInitUnknownEncoding(void *mem,
int *table,
int (*convert)(void *userData, const char *p),
void *userData)
{
int i;
struct unknown_encoding *e = mem;
for (i = 0; i < sizeof(struct normal_encoding); i++)
((char *)mem)[i] = ((char *)&latin1_encoding)[i];
for (i = 0; i < 128; i++)
if (latin1_encoding.type[i] != BT_OTHER
&& latin1_encoding.type[i] != BT_NONXML
&& table[i] != i)
return 0;
for (i = 0; i < 256; i++) {
int c = table[i];
if (c == -1) {
e->normal.type[i] = BT_MALFORM;
/* This shouldn't really get used. */
e->utf16[i] = 0xFFFF;
e->utf8[i][0] = 1;
e->utf8[i][1] = 0;
}
else if (c < 0) {
if (c < -4)
return 0;
e->normal.type[i] = BT_LEAD2 - (c + 2);
e->utf8[i][0] = 0;
e->utf16[i] = 0;
}
else if (c < 0x80) {
if (latin1_encoding.type[c] != BT_OTHER
&& latin1_encoding.type[c] != BT_NONXML
&& c != i)
return 0;
e->normal.type[i] = latin1_encoding.type[c];
e->utf8[i][0] = 1;
e->utf8[i][1] = (char)c;
e->utf16[i] = c == 0 ? 0xFFFF : c;
}
else if (checkCharRefNumber(c) < 0) {
e->normal.type[i] = BT_NONXML;
/* This shouldn't really get used. */
e->utf16[i] = 0xFFFF;
e->utf8[i][0] = 1;
e->utf8[i][1] = 0;
}
else {
if (c > 0xFFFF)
return 0;
if (UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xff))
e->normal.type[i] = BT_NMSTRT;
else if (UCS2_GET_NAMING(namePages, c >> 8, c & 0xff))
e->normal.type[i] = BT_NAME;
else
e->normal.type[i] = BT_OTHER;
e->utf8[i][0] = (char)XmlUtf8Encode(c, e->utf8[i] + 1);
e->utf16[i] = c;
}
}
e->userData = userData;
e->convert = convert;
if (convert) {
e->normal.isName2 = unknown_isName;
e->normal.isName3 = unknown_isName;
e->normal.isName4 = unknown_isName;
e->normal.isNmstrt2 = unknown_isNmstrt;
e->normal.isNmstrt3 = unknown_isNmstrt;
e->normal.isNmstrt4 = unknown_isNmstrt;
e->normal.isInvalid2 = unknown_isInvalid;
e->normal.isInvalid3 = unknown_isInvalid;
e->normal.isInvalid4 = unknown_isInvalid;
}
e->normal.enc.utf8Convert = unknown_toUtf8;
e->normal.enc.utf16Convert = unknown_toUtf16;
return &(e->normal.enc);
}
+35 -21
View File
@@ -103,14 +103,10 @@ extern "C" {
#define XML_ATTRIBUTE_VALUE_LITERAL 0
#define XML_ENTITY_VALUE_LITERAL 1
#define XML_N_INTERNAL_ENCODINGS 1
#define XML_UTF8_ENCODING 0
#if 0
#define XML_UTF16_ENCODING 1
#define XML_UCS4_ENCODING 2
#endif
#define XML_MAX_BYTES_PER_CHAR 4
/* The size of the buffer passed to XmlUtf8Encode must be at least this. */
#define XML_UTF8_ENCODE_MAX 4
/* The size of the buffer passed to XmlUtf16Encode must be at least this. */
#define XML_UTF16_ENCODE_MAX 2
typedef struct position {
/* first line and first column are 0 not 1 */
@@ -146,21 +142,26 @@ struct encoding {
int (*getAtts)(const ENCODING *enc, const char *ptr,
int attsMax, ATTRIBUTE *atts);
int (*charRefNumber)(const ENCODING *enc, const char *ptr);
int (*predefinedEntityName)(const ENCODING *, const char *, const char *);
void (*updatePosition)(const ENCODING *,
const char *ptr,
const char *end,
POSITION *);
int (*isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
const char **badPtr);
int (*encode)(const ENCODING *enc,
int charNum,
char *buf);
void (*convert[XML_N_INTERNAL_ENCODINGS])(const ENCODING *enc,
const char **fromP,
const char *fromLim,
char **toP,
const char *toLim);
void (*utf8Convert)(const ENCODING *enc,
const char **fromP,
const char *fromLim,
char **toP,
const char *toLim);
void (*utf16Convert)(const ENCODING *enc,
const char **fromP,
const char *fromLim,
unsigned short **toP,
const unsigned short *toLim);
int minBytesPerChar;
char isUtf8;
char isUtf16;
};
/*
@@ -225,17 +226,20 @@ the content of a literal that has already been returned by XmlTok. */
#define XmlCharRefNumber(enc, ptr) \
(((enc)->charRefNumber)(enc, ptr))
#define XmlPredefinedEntityName(enc, ptr, end) \
(((enc)->predefinedEntityName)(enc, ptr, end))
#define XmlUpdatePosition(enc, ptr, end, pos) \
(((enc)->updatePosition)(enc, ptr, end, pos))
#define XmlIsPublicId(enc, ptr, end, badPtr) \
(((enc)->isPublicId)(enc, ptr, end, badPtr))
#define XmlEncode(enc, ch, buf) \
(((enc)->encode)(enc, ch, buf))
#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
(((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
#define XmlConvert(enc, targetEnc, fromP, fromLim, toP, toLim) \
(((enc)->convert[targetEnc])(enc, fromP, fromLim, toP, toLim))
#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
(((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
typedef struct {
ENCODING initEnc;
@@ -253,7 +257,17 @@ int XMLTOKAPI XmlParseXmlDecl(int isGeneralTextEntity,
int *standalonePtr);
int XMLTOKAPI XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
const ENCODING XMLTOKAPI *XmlGetInternalEncoding(int);
const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding();
const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding();
int XMLTOKAPI XmlUtf8Encode(int charNumber, char *buf);
int XMLTOKAPI XmlUtf16Encode(int charNumber, unsigned short *buf);
int XMLTOKAPI XmlSizeOfUnknownEncoding();
ENCODING XMLTOKAPI *
XmlInitUnknownEncoding(void *mem,
int *table,
int (*convert)(void *userData, const char *p),
void *userData);
#ifdef __cplusplus
}
+78 -7
View File
@@ -56,7 +56,7 @@ Contributor(s):
#define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) \
case BT_NONASCII: \
if (!IS_NAME_CHAR(enc, ptr, MINBPC)) { \
if (!IS_NAME_CHAR_MINBPC(enc, ptr)) { \
*nextTokPtr = ptr; \
return XML_TOK_INVALID; \
} \
@@ -84,7 +84,7 @@ Contributor(s):
#define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) \
case BT_NONASCII: \
if (!IS_NMSTRT_CHAR(enc, ptr, MINBPC)) { \
if (!IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { \
*nextTokPtr = ptr; \
return XML_TOK_INVALID; \
} \
@@ -505,7 +505,7 @@ int PREFIX(scanRef)(const ENCODING *enc, const char *ptr, const char *end,
if (ptr == end)
return XML_TOK_PARTIAL;
switch (BYTE_TYPE(enc, ptr)) {
CHECK_NMSTRT_CASES(end, ptr, end, nextTokPtr)
CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
case BT_NUM:
return PREFIX(scanCharRef)(enc, ptr + MINBPC, end, nextTokPtr);
default:
@@ -606,6 +606,22 @@ int PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end,
break;
}
}
ptr += MINBPC;
if (ptr == end)
return XML_TOK_PARTIAL;
switch (BYTE_TYPE(enc, ptr)) {
case BT_S:
case BT_CR:
case BT_LF:
break;
case BT_SOL:
goto sol;
case BT_GT:
goto gt;
default:
*nextTokPtr = ptr;
return XML_TOK_INVALID;
}
/* ptr points to closing quote */
for (;;) {
ptr += MINBPC;
@@ -616,9 +632,11 @@ int PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end,
case BT_S: case BT_CR: case BT_LF:
continue;
case BT_GT:
gt:
*nextTokPtr = ptr + MINBPC;
return XML_TOK_START_TAG_WITH_ATTS;
case BT_SOL:
sol:
ptr += MINBPC;
if (ptr == end)
return XML_TOK_PARTIAL;
@@ -829,7 +847,7 @@ int PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end,
if (ptr == end)
return XML_TOK_PARTIAL;
switch (BYTE_TYPE(enc, ptr)) {
CHECK_NMSTRT_CASES(end, ptr, end, nextTokPtr)
CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
case BT_S: case BT_LF: case BT_CR: case BT_PERCNT:
*nextTokPtr = ptr;
return XML_TOK_PERCENT;
@@ -858,7 +876,7 @@ int PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end,
if (ptr == end)
return XML_TOK_PARTIAL;
switch (BYTE_TYPE(enc, ptr)) {
CHECK_NMSTRT_CASES(end, ptr, end, nextTokPtr)
CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr)
default:
*nextTokPtr = ptr;
return XML_TOK_INVALID;
@@ -1064,12 +1082,12 @@ int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
ptr += MINBPC;
break;
case BT_NONASCII:
if (IS_NMSTRT_CHAR(enc, ptr, MINBPC)) {
if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) {
ptr += MINBPC;
tok = XML_TOK_NAME;
break;
}
if (IS_NAME_CHAR(enc, ptr, MINBPC)) {
if (IS_NAME_CHAR_MINBPC(enc, ptr)) {
ptr += MINBPC;
tok = XML_TOK_NMTOKEN;
break;
@@ -1406,6 +1424,59 @@ int PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr)
return checkCharRefNumber(result);
}
static
int PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, const char *end)
{
switch (end - ptr) {
case 2 * MINBPC:
if (CHAR_MATCHES(enc, ptr + MINBPC, 't')) {
switch (BYTE_TO_ASCII(enc, ptr)) {
case 'l':
return '<';
case 'g':
return '>';
}
}
break;
case 3 * MINBPC:
if (CHAR_MATCHES(enc, ptr, 'a')) {
ptr += MINBPC;
if (CHAR_MATCHES(enc, ptr, 'm')) {
ptr += MINBPC;
if (CHAR_MATCHES(enc, ptr, 'p'))
return '&';
}
}
break;
case 4 * MINBPC:
switch (BYTE_TO_ASCII(enc, ptr)) {
case 'q':
ptr += MINBPC;
if (CHAR_MATCHES(enc, ptr, 'u')) {
ptr += MINBPC;
if (CHAR_MATCHES(enc, ptr, 'o')) {
ptr += MINBPC;
if (CHAR_MATCHES(enc, ptr, 't'))
return '"';
}
}
break;
case 'a':
ptr += MINBPC;
if (CHAR_MATCHES(enc, ptr, 'p')) {
ptr += MINBPC;
if (CHAR_MATCHES(enc, ptr, 'o')) {
ptr += MINBPC;
if (CHAR_MATCHES(enc, ptr, 's'))
return '\'';
}
}
break;
}
}
return 0;
}
static
int PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2)
{
+77
View File
@@ -0,0 +1,77 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
James Clark. All Rights Reserved.
Contributor(s):
*/
#include "codepage.h"
#ifdef WIN32
#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++) {
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 = 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 cp, int *map)
{
return 0;
}
int codepageConvert(int cp, const char *p)
{
return -1;
}
#endif /* not WIN32 */
+22
View File
@@ -0,0 +1,22 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
James Clark. All Rights Reserved.
Contributor(s):
*/
int codepageMap(int cp, int *map);
int codepageConvert(int cp, const char *p);
+6
View File
@@ -21,6 +21,12 @@ Contributor(s):
#include <stddef.h>
#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
+12 -7
View File
@@ -19,14 +19,19 @@ Contributor(s):
*/
#define STRICT 1
#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 char *);
static void win32perror(const TCHAR *);
int filemap(const char *name,
void (*processor)(const void *, size_t, const char *, void *arg),
int filemap(const TCHAR *name,
void (*processor)(const void *, size_t, const TCHAR *, void *arg),
void *arg)
{
HANDLE f;
@@ -47,7 +52,7 @@ int filemap(const char *name,
return 0;
}
if (sizeHi) {
fprintf(stderr, "%s: bigger than 2Gb\n", name);
_ftprintf(stderr, _T("%s: bigger than 2Gb\n"), name);
return 0;
}
/* CreateFileMapping barfs on zero length files */
@@ -78,7 +83,7 @@ int filemap(const char *name,
}
static
void win32perror(const char *s)
void win32perror(const TCHAR *s)
{
LPVOID buf;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
@@ -88,10 +93,10 @@ void win32perror(const char *s)
(LPTSTR) &buf,
0,
NULL)) {
fprintf(stderr, "%s: %s", s, buf);
_ftprintf(stderr, _T("%s: %s"), s, buf);
fflush(stderr);
LocalFree(buf);
}
else
fprintf(stderr, "%s: unknown Windows error\n", s);
_ftprintf(stderr, _T("%s: unknown Windows error\n"), s);
}
+423 -74
View File
@@ -20,6 +20,7 @@ Contributor(s):
#include "xmlparse.h"
#include "filemap.h"
#include "codepage.h"
#include <stdio.h>
#include <stdlib.h>
@@ -53,30 +54,67 @@ Contributor(s):
#define READ_SIZE (1024*8)
#endif
static void characterData(void *userData, const char *s, int len)
#ifdef XML_UNICODE
#ifndef XML_UNICODE_WCHAR_T
#error xmlwf requires a 16-bit Unicode-compatible wchar_t
#endif
#define T(x) 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
#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
#endif /* not XML_UNICODE */
static void characterData(void *userData, const XML_Char *s, int len)
{
FILE *fp = userData;
for (; len > 0; --len, ++s) {
switch (*s) {
case '&':
fputs("&amp;", fp);
case T('&'):
fputts(T("&amp;"), fp);
break;
case '<':
fputs("&lt;", fp);
case T('<'):
fputts(T("&lt;"), fp);
break;
case '>':
fputs("&gt;", fp);
case T('>'):
fputts(T("&gt;"), fp);
break;
case '"':
fputs("&quot;", fp);
case T('"'):
fputts(T("&quot;"), fp);
break;
case 9:
case 10:
case 13:
fprintf(fp, "&#%d;", *s);
ftprintf(fp, T("&#%d;"), *s);
break;
default:
putc(*s, fp);
puttc(*s, fp);
break;
}
}
@@ -87,48 +125,184 @@ is equivalent to lexicographically comparing based on the character number. */
static int attcmp(const void *att1, const void *att2)
{
return strcmp(*(const char **)att1, *(const char **)att2);
return tcscmp(*(const XML_Char **)att1, *(const XML_Char **)att2);
}
static void startElement(void *userData, const char *name, const char **atts)
static void startElement(void *userData, const XML_Char *name, const XML_Char **atts)
{
int nAtts;
const char **p;
const XML_Char **p;
FILE *fp = userData;
putc('<', fp);
fputs(name, fp);
puttc(T('<'), fp);
fputts(name, fp);
p = atts;
while (*p)
++p;
nAtts = (p - atts) >> 1;
if (nAtts > 1)
qsort((void *)atts, nAtts, sizeof(char *) * 2, attcmp);
qsort((void *)atts, nAtts, sizeof(XML_Char *) * 2, attcmp);
while (*atts) {
putc(' ', fp);
fputs(*atts++, fp);
putc('=', fp);
putc('"', fp);
characterData(userData, *atts, strlen(*atts));
putc('"', fp);
puttc(T(' '), fp);
fputts(*atts++, fp);
puttc(T('='), fp);
puttc(T('"'), fp);
characterData(userData, *atts, tcslen(*atts));
puttc(T('"'), fp);
atts++;
}
putc('>', fp);
puttc(T('>'), fp);
}
static void endElement(void *userData, const char *name)
static void endElement(void *userData, const XML_Char *name)
{
FILE *fp = userData;
putc('<', fp);
putc('/', fp);
fputs(name, fp);
putc('>', fp);
puttc(T('<'), fp);
puttc(T('/'), fp);
fputts(name, fp);
puttc(T('>'), fp);
}
static void processingInstruction(void *userData, const char *target, const char *data)
static void processingInstruction(void *userData, const XML_Char *target, const XML_Char *data)
{
FILE *fp = userData;
fprintf(fp, "<?%s %s?>", target, data);
puttc(T('<'), fp);
puttc(T('?'), fp);
fputts(target, fp);
puttc(T(' '), fp);
fputts(data, fp);
puttc(T('?'), fp);
puttc(T('>'), fp);
}
static void defaultCharacterData(XML_Parser parser, const XML_Char *s, int len)
{
XML_DefaultCurrent(parser);
}
static void defaultStartElement(XML_Parser parser, const XML_Char *name, const XML_Char **atts)
{
XML_DefaultCurrent(parser);
}
static void defaultEndElement(XML_Parser parser, const XML_Char *name)
{
XML_DefaultCurrent(parser);
}
static void defaultProcessingInstruction(XML_Parser parser, const XML_Char *target, const XML_Char *data)
{
XML_DefaultCurrent(parser);
}
static void markup(XML_Parser parser, const XML_Char *s, int len)
{
FILE *fp = XML_GetUserData(parser);
for (; len > 0; --len, ++s)
puttc(*s, fp);
}
static
void metaLocation(XML_Parser parser)
{
const XML_Char *uri = XML_GetBase(parser);
if (uri)
ftprintf(XML_GetUserData(parser), T(" uri=\"%s\""), uri);
ftprintf(XML_GetUserData(parser),
T(" byte=\"%ld\" line=\"%d\" col=\"%d\""),
XML_GetCurrentByteIndex(parser),
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser));
}
static
void metaStartElement(XML_Parser parser, const XML_Char *name, const XML_Char **atts)
{
FILE *fp = XML_GetUserData(parser);
ftprintf(fp, T("<starttag name=\"%s\""), name);
metaLocation(parser);
if (*atts) {
fputts(T(">\n"), fp);
do {
ftprintf(fp, T("<attribute name=\"%s\" value=\""), atts[0]);
characterData(fp, atts[1], tcslen(atts[1]));
fputts(T("\"/>\n"), fp);
} while (*(atts += 2));
fputts(T("</starttag>\n"), fp);
}
else
fputts(T("/>\n"), fp);
}
static
void metaEndElement(XML_Parser parser, const XML_Char *name)
{
FILE *fp = XML_GetUserData(parser);
ftprintf(fp, T("<endtag name=\"%s\""), name);
metaLocation(parser);
fputts(T("/>\n"), fp);
}
static
void metaProcessingInstruction(XML_Parser parser, const XML_Char *target, const XML_Char *data)
{
FILE *fp = XML_GetUserData(parser);
ftprintf(fp, T("<pi target=\"%s\" data=\""), target);
characterData(fp, data, tcslen(data));
puttc(T('"'), fp);
metaLocation(parser);
fputts(T("/>\n"), fp);
}
static
void metaCharacterData(XML_Parser parser, const XML_Char *s, int len)
{
FILE *fp = XML_GetUserData(parser);
fputts(T("<chars str=\""), fp);
characterData(fp, s, len);
puttc(T('"'), fp);
metaLocation(parser);
fputts(T("/>\n"), fp);
}
static
void metaUnparsedEntityDecl(XML_Parser parser,
const XML_Char *entityName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId,
const XML_Char *notationName)
{
FILE *fp = XML_GetUserData(parser);
ftprintf(fp, T("<entity name=\"%s\""), entityName);
if (publicId)
ftprintf(fp, T(" public=\"%s\""), publicId);
fputts(T(" system=\""), fp);
characterData(fp, systemId, tcslen(systemId));
puttc(T('"'), fp);
ftprintf(fp, T(" notation=\"%s\""), notationName);
metaLocation(parser);
fputts(T("/>\n"), fp);
}
static
void metaNotationDecl(XML_Parser parser,
const XML_Char *notationName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId)
{
FILE *fp = XML_GetUserData(parser);
ftprintf(fp, T("<notation name=\"%s\""), notationName);
if (publicId)
ftprintf(fp, T(" public=\"%s\""), publicId);
if (systemId) {
fputts(T(" system=\""), fp);
characterData(fp, systemId, tcslen(systemId));
puttc(T('"'), fp);
}
metaLocation(parser);
fputts(T("/>\n"), fp);
}
typedef struct {
@@ -137,22 +311,22 @@ typedef struct {
} PROCESS_ARGS;
static
void reportError(XML_Parser parser, const char *filename)
void reportError(XML_Parser parser, const XML_Char *filename)
{
int code = XML_GetErrorCode(parser);
const char *message = XML_ErrorString(code);
const XML_Char *message = XML_ErrorString(code);
if (message)
fprintf(stdout, "%s:%d:%ld: %s\n",
filename,
XML_GetErrorLineNumber(parser),
XML_GetErrorColumnNumber(parser),
message);
ftprintf(stdout, T("%s:%d:%ld: %s\n"),
filename,
XML_GetErrorLineNumber(parser),
XML_GetErrorColumnNumber(parser),
message);
else
fprintf(stderr, "%s: (unknown message %d)\n", filename, code);
ftprintf(stderr, T("%s: (unknown message %d)\n"), filename, code);
}
static
void processFile(const void *data, size_t size, const char *filename, void *args)
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;
@@ -165,11 +339,68 @@ void processFile(const void *data, size_t size, const char *filename, void *args
}
static
int processStream(const char *filename, XML_Parser parser)
int isAsciiLetter(XML_Char c)
{
int fd = open(filename, O_BINARY|O_RDONLY);
return (T('a') <= c && c <= T('z')) || (T('A') <= c && c <= T('Z'));
}
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('/')
#ifdef 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;
#ifdef 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 *openEntityNames,
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, openEntityNames, 0);
PROCESS_ARGS args;
args.retPtr = &result;
args.parser = entParser;
filename = resolveSystemId(base, systemId, &s);
XML_SetBase(entParser, filename);
if (!filemap(filename, processFile, &args))
result = 0;
free(s);
XML_ParserFree(entParser);
return result;
}
static
int processStream(const XML_Char *filename, XML_Parser parser)
{
int fd = topen(filename, O_BINARY|O_RDONLY);
if (fd < 0) {
perror(filename);
tperror(filename);
return 0;
}
for (;;) {
@@ -177,12 +408,12 @@ int processStream(const char *filename, XML_Parser parser)
char *buf = XML_GetBuffer(parser, READ_SIZE);
if (!buf) {
close(fd);
fprintf(stderr, "%s: out of memory\n", filename);
ftprintf(stderr, T("%s: out of memory\n"), filename);
return 0;
}
nread = read(fd, buf, READ_SIZE);
if (nread < 0) {
perror(filename);
tperror(filename);
close(fd);
return 0;
}
@@ -200,37 +431,119 @@ int processStream(const char *filename, XML_Parser parser)
}
static
void usage(const char *prog)
int externalEntityRefStream(XML_Parser parser,
const XML_Char *openEntityNames,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId)
{
fprintf(stderr, "usage: %s [-r] [-d output-dir] [-e encoding] file ...\n", prog);
XML_Char *s;
const XML_Char *filename;
int ret;
XML_Parser entParser = XML_ExternalEntityParserCreate(parser, openEntityNames, 0);
filename = resolveSystemId(base, systemId, &s);
XML_SetBase(entParser, filename);
ret = processStream(filename, entParser);
free(s);
XML_ParserFree(entParser);
return ret;
}
static
int unknownEncodingConvert(void *data, const char *p)
{
return codepageConvert(*(int *)data, p);
}
static
int 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;
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)
return 0;
cp *= 10;
cp += s - digits;
if (cp >= 0x10000)
return 0;
}
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)
return 0;
*(int *)info->data = cp;
return 1;
}
static
void usage(const XML_Char *prog)
{
ftprintf(stderr, T("usage: %s [-r] [-w] [-x] [-d output-dir] [-e encoding] file ...\n"), prog);
exit(1);
}
int main(int argc, char **argv)
int tmain(int argc, XML_Char **argv)
{
int i;
const char *outputDir = 0;
const char *encoding = 0;
const XML_Char *outputDir = 0;
const XML_Char *encoding = 0;
int useFilemap = 1;
int processExternalEntities = 0;
int windowsCodePages = 0;
int outputType = 0;
#ifdef _MSC_VER
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
#endif
i = 1;
while (i < argc && argv[i][0] == '-') {
while (i < argc && argv[i][0] == T('-')) {
int j;
if (argv[i][1] == '-' && argv[i][2] == '\0') {
if (argv[i][1] == T('-') && argv[i][2] == T('\0')) {
i++;
break;
}
j = 1;
if (argv[i][j] == 'r') {
if (argv[i][j] == T('r')) {
useFilemap = 0;
j++;
}
if (argv[i][j] == 'd') {
if (argv[i][j + 1] == '\0') {
if (argv[i][j] == T('x')) {
processExternalEntities = 1;
j++;
}
if (argv[i][j] == T('w')) {
windowsCodePages = 1;
j++;
}
if (argv[i][j] == T('m')) {
outputType = 'm';
j++;
}
if (argv[i][j] == T('c')) {
outputType = 'c';
j++;
}
if (argv[i][j] == T('d')) {
if (argv[i][j + 1] == T('\0')) {
if (++i == argc)
usage(argv[0]);
outputDir = argv[i];
@@ -239,8 +552,8 @@ int main(int argc, char **argv)
outputDir = argv[i] + j + 1;
i++;
}
else if (argv[i][j] == 'e') {
if (argv[i][j + 1] == '\0') {
else if (argv[i][j] == T('e')) {
if (argv[i][j + 1] == T('\0')) {
if (++i == argc)
usage(argv[0]);
encoding = argv[i];
@@ -249,7 +562,7 @@ int main(int argc, char **argv)
encoding = argv[i] + j + 1;
i++;
}
else if (argv[i][j] == '\0' && j > 1)
else if (argv[i][j] == T('\0') && j > 1)
i++;
else
usage(argv[0]);
@@ -258,31 +571,65 @@ int main(int argc, char **argv)
usage(argv[0]);
for (; i < argc; i++) {
FILE *fp = 0;
char *outName = 0;
XML_Char *outName = 0;
int result;
XML_Parser parser = XML_ParserCreate(encoding);
if (outputDir) {
const char *file = argv[i];
if (strrchr(file, '/'))
file = strrchr(file, '/') + 1;
const XML_Char *file = argv[i];
if (tcsrchr(file, T('/')))
file = tcsrchr(file, T('/')) + 1;
#ifdef WIN32
if (strrchr(file, '\\'))
file = strrchr(file, '\\') + 1;
if (tcsrchr(file, T('\\')))
file = tcsrchr(file, T('\\')) + 1;
#endif
outName = malloc(strlen(outputDir) + strlen(file) + 2);
strcpy(outName, outputDir);
strcat(outName, "/");
strcat(outName, file);
fp = fopen(outName, "wb");
outName = malloc((tcslen(outputDir) + tcslen(file) + 2) * sizeof(XML_Char));
tcscpy(outName, outputDir);
tcscat(outName, T("/"));
tcscat(outName, file);
fp = tfopen(outName, T("wb"));
if (!fp) {
perror(outName);
tperror(outName);
exit(1);
}
#ifdef XML_UNICODE
puttc(0xFEFF, fp);
#endif
XML_SetUserData(parser, fp);
XML_SetElementHandler(parser, startElement, endElement);
XML_SetCharacterDataHandler(parser, characterData);
XML_SetProcessingInstructionHandler(parser, processingInstruction);
switch (outputType) {
case 'm':
XML_UseParserAsHandlerArg(parser);
fputts(T("<document>\n"), fp);
XML_SetElementHandler(parser, metaStartElement, metaEndElement);
XML_SetProcessingInstructionHandler(parser, metaProcessingInstruction);
XML_SetCharacterDataHandler(parser, metaCharacterData);
XML_SetUnparsedEntityDeclHandler(parser, metaUnparsedEntityDecl);
XML_SetNotationDeclHandler(parser, metaNotationDecl);
break;
case 'c':
XML_UseParserAsHandlerArg(parser);
XML_SetDefaultHandler(parser, markup);
XML_SetElementHandler(parser, defaultStartElement, defaultEndElement);
XML_SetCharacterDataHandler(parser, defaultCharacterData);
XML_SetProcessingInstructionHandler(parser, defaultProcessingInstruction);
break;
default:
XML_SetElementHandler(parser, startElement, endElement);
XML_SetCharacterDataHandler(parser, characterData);
XML_SetProcessingInstructionHandler(parser, processingInstruction);
break;
}
}
if (windowsCodePages)
XML_SetUnknownEncodingHandler(parser, unknownEncoding, 0);
if (!XML_SetBase(parser, argv[i])) {
ftprintf(stderr, T("%s: out of memory"), argv[0]);
exit(1);
}
if (processExternalEntities)
XML_SetExternalEntityRefHandler(parser,
useFilemap
? externalEntityRefFilemap
: externalEntityRefStream);
if (useFilemap) {
PROCESS_ARGS args;
args.retPtr = &result;
@@ -293,9 +640,11 @@ int main(int argc, char **argv)
else
result = processStream(argv[i], parser);
if (outputDir) {
if (outputType == 'm')
fputts(T("</document>\n"), fp);
fclose(fp);
if (!result)
remove(outName);
tremove(outName);
free(outName);
}
XML_ParserFree(parser);