r3648 jmb - in /trunk/dom: bindings/hubbub/parser.c bindings/hubbub/parser.h test/Makefile test/binding.c test/data/binding/Aliases test/data/binding/sample.html test/lib/testobject.c
by netsurf@semichrome.net
Author: jmb
Date: Sun Nov 4 03:40:09 2007
New Revision: 3648
URL: http://source.netsurf-browser.org?rev=3648&view=rev
Log:
Make TestObject support both HTML and XML documents and auto-detect which parser to use.
Make binding testcase attempt to load an HTML document.
Hubbub parser binding constructor takes Aliases file path as a parameter.
Hubbub parser binding's token handler now spews debug at stdout.
Added:
trunk/dom/test/data/binding/Aliases
trunk/dom/test/data/binding/sample.html
Modified:
trunk/dom/bindings/hubbub/parser.c
trunk/dom/bindings/hubbub/parser.h
trunk/dom/test/Makefile
trunk/dom/test/binding.c
trunk/dom/test/lib/testobject.c
Modified: trunk/dom/bindings/hubbub/parser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/hubbub/parser.c?rev=...
==============================================================================
--- trunk/dom/bindings/hubbub/parser.c (original)
+++ trunk/dom/bindings/hubbub/parser.c Sun Nov 4 03:40:09 2007
@@ -5,6 +5,8 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
+#include <stdio.h>
+
#include <hubbub/hubbub.h>
#include <hubbub/parser.h>
@@ -18,6 +20,7 @@
*/
struct dom_hubbub_parser {
hubbub_parser *parser; /**< Hubbub parser instance */
+ const uint8_t *buffer; /**< Parser buffer pointer */
struct dom_document *doc; /**< DOM Document we're building */
@@ -41,6 +44,7 @@
/**
* Create a Hubbub parser instance
*
+ * \param aliases Path to encoding alias mapping file
* \param enc Source charset, or NULL
* \param int_enc Desired charset of document buffer (UTF-8 or UTF-16)
* \param alloc Memory (de)allocation function
@@ -49,9 +53,9 @@
* \param mctx Pointer to client-specific private data
* \return Pointer to instance, or NULL on memory exhaustion
*/
-dom_hubbub_parser *dom_hubbub_parser_create(const char *enc,
- const char *int_enc, dom_alloc alloc, void *pw,
- dom_msg msg, void *mctx)
+dom_hubbub_parser *dom_hubbub_parser_create(const char *aliases,
+ const char *enc, const char *int_enc,
+ dom_alloc alloc, void *pw, dom_msg msg, void *mctx)
{
dom_hubbub_parser *parser;
hubbub_parser_optparams params;
@@ -60,8 +64,7 @@
hubbub_error e;
if (__initialised == false) {
- /** \todo Need path of encoding aliases file */
- e = hubbub_initialise("", (hubbub_alloc) alloc, pw);
+ e = hubbub_initialise(aliases, (hubbub_alloc) alloc, pw);
if (e != HUBBUB_OK) {
msg(DOM_MSG_ERROR, mctx,
"Failed initialising hubbub");
@@ -202,14 +205,71 @@
void __dom_hubbub_buffer_handler(const uint8_t *buffer, size_t len,
void *pw)
{
- UNUSED(buffer);
+ dom_hubbub_parser *parser = (dom_hubbub_parser *) pw;
+
UNUSED(len);
- UNUSED(pw);
+
+ parser->buffer = buffer;
}
void __dom_hubbub_token_handler(const hubbub_token *token, void *pw)
{
- UNUSED(token);
- UNUSED(pw);
-}
-
+ dom_hubbub_parser *parser = (dom_hubbub_parser *) pw;
+ static const char *token_names[] = {
+ "DOCTYPE", "START TAG", "END TAG",
+ "COMMENT", "CHARACTERS", "EOF"
+ };
+ size_t i;
+
+ printf("%s: ", token_names[token->type]);
+
+ switch (token->type) {
+ case HUBBUB_TOKEN_DOCTYPE:
+ printf("'%.*s' (%svalid)\n",
+ (int) token->data.doctype.name.len,
+ parser->buffer +
+ token->data.doctype.name.data_off,
+ token->data.doctype.correct ? "" : "in");
+ break;
+ case HUBBUB_TOKEN_START_TAG:
+ printf("'%.*s' %s\n",
+ (int) token->data.tag.name.len,
+ parser->buffer + token->data.tag.name.data_off,
+ (token->data.tag.n_attributes > 0) ?
+ "attributes:" : "");
+ for (i = 0; i < token->data.tag.n_attributes; i++) {
+ printf("\t'%.*s' = '%.*s'\n",
+ (int) token->data.tag.attributes[i].name.len,
+ parser->buffer + token->data.tag.attributes[i].name.data_off,
+ (int) token->data.tag.attributes[i].value.len,
+ parser->buffer + token->data.tag.attributes[i].value.data_off);
+ }
+ break;
+ case HUBBUB_TOKEN_END_TAG:
+ printf("'%.*s' %s\n",
+ (int) token->data.tag.name.len,
+ parser->buffer + token->data.tag.name.data_off,
+ (token->data.tag.n_attributes > 0) ?
+ "attributes:" : "");
+ for (i = 0; i < token->data.tag.n_attributes; i++) {
+ printf("\t'%.*s' = '%.*s'\n",
+ (int) token->data.tag.attributes[i].name.len,
+ parser->buffer + token->data.tag.attributes[i].name.data_off,
+ (int) token->data.tag.attributes[i].value.len,
+ parser->buffer + token->data.tag.attributes[i].value.data_off);
+ }
+ break;
+ case HUBBUB_TOKEN_COMMENT:
+ printf("'%.*s'\n", (int) token->data.comment.len,
+ parser->buffer + token->data.comment.data_off);
+ break;
+ case HUBBUB_TOKEN_CHARACTER:
+ printf("'%.*s'\n", (int) token->data.character.len,
+ parser->buffer + token->data.character.data_off);
+ break;
+ case HUBBUB_TOKEN_EOF:
+ printf("\n");
+ break;
+ }
+}
+
Modified: trunk/dom/bindings/hubbub/parser.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/hubbub/parser.h?rev=...
==============================================================================
--- trunk/dom/bindings/hubbub/parser.h (original)
+++ trunk/dom/bindings/hubbub/parser.h Sun Nov 4 03:40:09 2007
@@ -20,9 +20,9 @@
typedef struct dom_hubbub_parser dom_hubbub_parser;
/* Create a Hubbub parser instance */
-dom_hubbub_parser *dom_hubbub_parser_create(const char *enc,
- const char *int_enc, dom_alloc alloc, void *pw,
- dom_msg msg, void *mctx);
+dom_hubbub_parser *dom_hubbub_parser_create(const char *aliases,
+ const char *enc, const char *int_enc,
+ dom_alloc alloc, void *pw, dom_msg msg, void *mctx);
/* Destroy a Hubbub parser instance */
void dom_hubbub_parser_destroy(dom_hubbub_parser *parser);
Modified: trunk/dom/test/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/test/Makefile?rev=3648&r1=364...
==============================================================================
--- trunk/dom/test/Makefile (original)
+++ trunk/dom/test/Makefile Sun Nov 4 03:40:09 2007
@@ -19,11 +19,15 @@
# test Execute any test cases
# Extend toolchain settings
-CFLAGS += -I${TOP}/src/ -I${TOP}/bindings/xml/ -I$(CURDIR)
-LDFLAGS += `${PKGCONFIG} ${PKGCONFIGFLAGS} --libs libxml-2.0`
+CFLAGS += -I${TOP}/src/ -I${TOP}/bindings/xml/ -I${TOP}/bindings/hubbub/ \
+ -I$(CURDIR)
+# TODO: fix hubbub library usage -- needs hubbub to use pkgconfig
+LDFLAGS += `${PKGCONFIG} ${PKGCONFIGFLAGS} --libs libxml-2.0` \
+ -L${TOP}/../hubbub/ -lhubbub
# Libraries we link against
-LIBS = -L./lib -ldomtest-debug -ldom-libxml-debug -ldom-debug
+LIBS = -L./lib -ldomtest-debug -ldom-libxml-debug \
+ -ldom-libhubbub-debug -ldom-debug
# Release output
RELEASE =
@@ -89,6 +93,6 @@
%: %.c
@${ECHO} ${ECHOFLAGS} "==> $<"
@${CC} -c -g ${CFLAGS} -o $@.o $<
- @${LD} -g -o $@ $@.o ${LDFLAGS} $(LIBS)
+ @${LD} -g -o $@ $@.o $(LIBS) ${LDFLAGS}
@${RM} ${RMFLAGS} $@.o
Modified: trunk/dom/test/binding.c
URL: http://source.netsurf-browser.org/trunk/dom/test/binding.c?rev=3648&r1=36...
==============================================================================
--- trunk/dom/test/binding.c (original)
+++ trunk/dom/test/binding.c Sun Nov 4 03:40:09 2007
@@ -10,9 +10,13 @@
struct dom_string *elementName;
dom_exception err;
TestObject *staff;
+ TestObject *html;
staff = test_object_create(argc, argv, "staff.xml", false);
assert(staff != NULL);
+
+ html = test_object_create(argc, argv, "sample.html", false);
+ assert(html != NULL);
doc = test_object_get_doc(staff);
assert(doc != NULL);
Added: trunk/dom/test/data/binding/Aliases
URL: http://source.netsurf-browser.org/trunk/dom/test/data/binding/Aliases?rev...
==============================================================================
--- trunk/dom/test/data/binding/Aliases (added)
+++ trunk/dom/test/data/binding/Aliases Sun Nov 4 03:40:09 2007
@@ -1,0 +1,302 @@
+# > Unicode:Files.Aliases
+# Mapping of character set encoding names to their canonical form
+#
+# Lines starting with a '#' are comments, blank lines are ignored.
+#
+# Based on http://www.iana.org/assignments/character-sets and
+# http://www.iana.org/assignments/ianacharset-mib
+#
+# Canonical Form MIBenum Aliases...
+#
+US-ASCII 3 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII ISO646-US ANSI_X3.4-1968 us IBM367 cp367 csASCII
+ISO-10646-UTF-1 27 csISO10646UTF1
+ISO_646.basic:1983 28 ref csISO646basic1983
+INVARIANT 29 csINVARIANT
+ISO_646.irv:1983 30 iso-ir-2 irv csISO2IntlRefVersion
+BS_4730 20 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom
+NATS-SEFI 31 iso-ir-8-1 csNATSSEFI
+NATS-SEFI-ADD 32 iso-ir-8-2 csNATSSEFIADD
+NATS-DANO 33 iso-ir-9-1 csNATSDANO
+NATS-DANO-ADD 34 iso-ir-9-2 csNATSDANOADD
+SEN_850200_B 35 iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish
+SEN_850200_C 21 iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames
+KS_C_5601-1987 36 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987
+ISO-2022-KR 37 csISO2022KR
+EUC-KR 38 csEUCKR EUCKR
+ISO-2022-JP 39 csISO2022JP
+ISO-2022-JP-2 40 csISO2022JP2
+ISO-2022-CN 104
+ISO-2022-CN-EXT 105
+JIS_C6220-1969-jp 41 JIS_C6220-1969 iso-ir-13 katakana x0201-7 csISO13JISC6220jp
+JIS_C6220-1969-ro 42 iso-ir-14 jp ISO646-JP csISO14JISC6220ro
+IT 22 iso-ir-15 ISO646-IT csISO15Italian
+PT 43 iso-ir-16 ISO646-PT csISO16Portuguese
+ES 23 iso-ir-17 ISO646-ES csISO17Spanish
+greek7-old 44 iso-ir-18 csISO18Greek7Old
+latin-greek 45 iso-ir-19 csISO19LatinGreek
+DIN_66003 24 iso-ir-21 de ISO646-DE csISO21German
+NF_Z_62-010_(1973) 46 iso-ir-25 ISO646-FR1 csISO25French
+Latin-greek-1 47 iso-ir-27 csISO27LatinGreek1
+ISO_5427 48 iso-ir-37 csISO5427Cyrillic
+JIS_C6226-1978 49 iso-ir-42 csISO42JISC62261978
+BS_viewdata 50 iso-ir-47 csISO47BSViewdata
+INIS 51 iso-ir-49 csISO49INIS
+INIS-8 52 iso-ir-50 csISO50INIS8
+INIS-cyrillic 53 iso-ir-51 csISO51INISCyrillic
+ISO_5427:1981 54 iso-ir-54 ISO5427Cyrillic1981
+ISO_5428:1980 55 iso-ir-55 csISO5428Greek
+GB_1988-80 56 iso-ir-57 cn ISO646-CN csISO57GB1988
+GB_2312-80 57 iso-ir-58 chinese csISO58GB231280
+NS_4551-1 25 iso-ir-60 ISO646-NO no csISO60DanishNorwegian csISO60Norwegian1
+NS_4551-2 58 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2
+NF_Z_62-010 26 iso-ir-69 ISO646-FR fr csISO69French
+videotex-suppl 59 iso-ir-70 csISO70VideotexSupp1
+PT2 60 iso-ir-84 ISO646-PT2 csISO84Portuguese2
+ES2 61 iso-ir-85 ISO646-ES2 csISO85Spanish2
+MSZ_7795.3 62 iso-ir-86 ISO646-HU hu csISO86Hungarian
+JIS_C6226-1983 63 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208
+greek7 64 iso-ir-88 csISO88Greek7
+ASMO_449 65 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449
+iso-ir-90 66 csISO90
+JIS_C6229-1984-a 67 iso-ir-91 jp-ocr-a csISO91JISC62291984a
+JIS_C6229-1984-b 68 iso-ir-92 ISO646-JP-OCR-B jp-ocr-b csISO92JISC62991984b
+JIS_C6229-1984-b-add 69 iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd
+JIS_C6229-1984-hand 70 iso-ir-94 jp-ocr-hand csISO94JIS62291984hand
+JIS_C6229-1984-hand-add 71 iso-ir-95 jp-ocr-hand-add csISO95JIS62291984handadd
+JIS_C6229-1984-kana 72 iso-ir-96 csISO96JISC62291984kana
+ISO_2033-1983 73 iso-ir-98 e13b csISO2033
+ANSI_X3.110-1983 74 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS
+ISO-8859-1 4 iso-ir-100 ISO_8859-1 ISO_8859-1:1987 latin1 l1 IBM819 CP819 csISOLatin1 8859_1 ISO8859-1
+ISO-8859-2 5 iso-ir-101 ISO_8859-2 ISO_8859-2:1987 latin2 l2 csISOLatin2 8859_2 ISO8859-2
+T.61-7bit 75 iso-ir-102 csISO102T617bit
+T.61-8bit 76 T.61 iso-ir-103 csISO103T618bit
+ISO-8859-3 6 iso-ir-109 ISO_8859-3 ISO_8859-3:1988 latin3 l3 csISOLatin3 8859_3 ISO8859-3
+ISO-8859-4 7 iso-ir-110 ISO_8859-4 ISO_8859-4:1988 latin4 l4 csISOLatin4 8859_4 ISO8859-4
+ECMA-cyrillic 77 iso-ir-111 KOI8-E csISO111ECMACyrillic
+CSA_Z243.4-1985-1 78 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1
+CSA_Z243.4-1985-2 79 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2
+CSA_Z243.4-1985-gr 80 iso-ir-123 csISO123CSAZ24341985gr
+ISO-8859-6 9 iso-ir-127 ISO_8859-6 ISO_8859-6:1987 ECMA-114 ASMO-708 arabic csISOLatinArabic
+ISO-8859-6-E 81 csISO88596E ISO_8859-6-E
+ISO-8859-6-I 82 csISO88596I ISO_8859-6-I
+ISO-8859-7 10 iso-ir-126 ISO_8859-7 ISO_8859-7:1987 ELOT_928 ECMA-118 greek greek8 csISOLatinGreek 8859_7 ISO8859-7
+T.101-G2 83 iso-ir-128 csISO128T101G2
+ISO-8859-8 11 iso-ir-138 ISO_8859-8 ISO_8859-8:1988 hebrew csISOLatinHebrew 8859_8 ISO8859-8
+ISO-8859-8-E 84 csISO88598E ISO_8859-8-E
+ISO-8859-8-I 85 csISO88598I ISO_8859-8-I
+CSN_369103 86 iso-ir-139 csISO139CSN369103
+JUS_I.B1.002 87 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002
+ISO_6937-2-add 14 iso-ir-142 csISOTextComm
+IEC_P27-1 88 iso-ir-143 csISO143IECP271
+ISO-8859-5 8 iso-ir-144 ISO_8859-5 ISO_8859-5:1988 cyrillic csISOLatinCyrillic 8859_5 ISO8859-5
+JUS_I.B1.003-serb 89 iso-ir-146 serbian csISO146Serbian
+JUS_I.B1.003-mac 90 macedonian iso-ir-147 csISO147Macedonian
+ISO-8859-9 12 iso-ir-148 ISO_8859-9 ISO_8859-9:1989 latin5 l5 csISOLatin5 8859_9 ISO8859-9
+greek-ccitt 91 iso-ir-150 csISO150 csISO150GreekCCITT
+NC_NC00-10:81 92 cuba iso-ir-151 ISO646-CU csISO151Cuba
+ISO_6937-2-25 93 iso-ir-152 csISO6937Add
+GOST_19768-74 94 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874
+ISO_8859-supp 95 iso-ir-154 latin1-2-5 csISO8859Supp
+ISO_10367-box 96 iso-ir-155 csISO10367Box
+ISO-8859-10 13 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 8859_10 ISO8859-10
+latin-lap 97 lap iso-ir-158 csISO158Lap
+JIS_X0212-1990 98 x0212 iso-ir-159 csISO159JISX02121990
+DS_2089 99 DS2089 ISO646-DK dk csISO646Danish
+us-dk 100 csUSDK
+dk-us 101 csDKUS
+JIS_X0201 15 X0201 csHalfWidthKatakana
+KSC5636 102 ISO646-KR csKSC5636
+ISO-10646-UCS-2 1000 csUnicode UCS-2 UCS2
+ISO-10646-UCS-4 1001 csUCS4 UCS-4 UCS4
+DEC-MCS 2008 dec csDECMCS
+hp-roman8 2004 roman8 r8 csHPRoman8
+macintosh 2027 mac csMacintosh MACROMAN MAC-ROMAN X-MAC-ROMAN
+IBM037 2028 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl csIBM037
+IBM038 2029 EBCDIC-INT cp038 csIBM038
+IBM273 2030 CP273 csIBM273
+IBM274 2031 EBCDIC-BE CP274 csIBM274
+IBM275 2032 EBCDIC-BR cp275 csIBM275
+IBM277 2033 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277
+IBM278 2034 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278
+IBM280 2035 CP280 ebcdic-cp-it csIBM280
+IBM281 2036 EBCDIC-JP-E cp281 csIBM281
+IBM284 2037 CP284 ebcdic-cp-es csIBM284
+IBM285 2038 CP285 ebcdic-cp-gb csIBM285
+IBM290 2039 cp290 EBCDIC-JP-kana csIBM290
+IBM297 2040 cp297 ebcdic-cp-fr csIBM297
+IBM420 2041 cp420 ebcdic-cp-ar1 csIBM420
+IBM423 2042 cp423 ebcdic-cp-gr csIBM423
+IBM424 2043 cp424 ebcdic-cp-he csIBM424
+IBM437 2011 cp437 437 csPC8CodePage437
+IBM500 2044 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500
+IBM775 2087 cp775 csPC775Baltic
+IBM850 2009 cp850 850 csPC850Multilingual
+IBM851 2045 cp851 851 csIBM851
+IBM852 2010 cp852 852 csPCp852
+IBM855 2046 cp855 855 csIBM855
+IBM857 2047 cp857 857 csIBM857
+IBM860 2048 cp860 860 csIBM860
+IBM861 2049 cp861 861 cp-is csIBM861
+IBM862 2013 cp862 862 csPC862LatinHebrew
+IBM863 2050 cp863 863 csIBM863
+IBM864 2051 cp864 csIBM864
+IBM865 2052 cp865 865 csIBM865
+IBM866 2086 cp866 866 csIBM866
+IBM868 2053 CP868 cp-ar csIBM868
+IBM869 2054 cp869 869 cp-gr csIBM869
+IBM870 2055 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870
+IBM871 2056 CP871 ebcdic-cp-is csIBM871
+IBM880 2057 cp880 EBCDIC-Cyrillic csIBM880
+IBM891 2058 cp891 csIBM891
+IBM903 2059 cp903 csIBM903
+IBM904 2060 cp904 904 csIBBM904
+IBM905 2061 CP905 ebcdic-cp-tr csIBM905
+IBM918 2062 CP918 ebcdic-cp-ar2 csIBM918
+IBM1026 2063 CP1026 csIBM1026
+EBCDIC-AT-DE 2064 csIBMEBCDICATDE
+EBCDIC-AT-DE-A 2065 csEBCDICATDEA
+EBCDIC-CA-FR 2066 csEBCDICCAFR
+EBCDIC-DK-NO 2067 csEBCDICDKNO
+EBCDIC-DK-NO-A 2068 csEBCDICDKNOA
+EBCDIC-FI-SE 2069 csEBCDICFISE
+EBCDIC-FI-SE-A 2070 csEBCDICFISEA
+EBCDIC-FR 2071 csEBCDICFR
+EBCDIC-IT 2072 csEBCDICIT
+EBCDIC-PT 2073 csEBCDICPT
+EBCDIC-ES 2074 csEBCDICES
+EBCDIC-ES-A 2075 csEBCDICESA
+EBCDIC-ES-S 2076 csEBCDICESS
+EBCDIC-UK 2077 csEBCDICUK
+EBCDIC-US 2078 csEBCDICUS
+UNKNOWN-8BIT 2079 csUnknown8BiT
+MNEMONIC 2080 csMnemonic
+MNEM 2081 csMnem
+VISCII 2082 csVISCII
+VIQR 2083 csVIQR
+KOI8-R 2084 csKOI8R
+KOI8-U 2088
+IBM00858 2089 CCSID00858 CP00858 PC-Multilingual-850+euro
+IBM00924 2090 CCSID00924 CP00924 ebcdic-Latin9--euro
+IBM01140 2091 CCSID01140 CP01140 ebcdic-us-37+euro
+IBM01141 2092 CCSID01141 CP01141 ebcdic-de-273+euro
+IBM01142 2093 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro
+IBM01143 2094 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro
+IBM01144 2095 CCSID01144 CP01144 ebcdic-it-280+euro
+IBM01145 2096 CCSID01145 CP01145 ebcdic-es-284+euro
+IBM01146 2097 CCSID01146 CP01146 ebcdic-gb-285+euro
+IBM01147 2098 CCSID01147 CP01147 ebcdic-fr-297+euro
+IBM01148 2099 CCSID01148 CP01148 ebcdic-international-500+euro
+IBM01149 2100 CCSID01149 CP01149 ebcdic-is-871+euro
+Big5-HKSCS 2101
+IBM1047 2102 IBM-1047
+PTCP154 2103 csPTCP154 PT154 CP154 Cyrillic-Asian
+Amiga-1251 2104 Ami1251 Amiga1251 Ami-1251
+KOI7-switched 2105
+UNICODE-1-1 1010 csUnicode11
+SCSU 1011
+UTF-7 1012
+UTF-16BE 1013
+UTF-16LE 1014
+UTF-16 1015
+CESU-8 1016 csCESU-8
+UTF-32 1017
+UTF-32BE 1018
+UTF-32LE 1019
+BOCU-1 1020 csBOCU-1
+UNICODE-1-1-UTF-7 103 csUnicode11UTF7
+UTF-8 106 UNICODE-1-1-UTF-8 UNICODE-2-0-UTF-8 utf8
+ISO-8859-13 109 8859_13 ISO8859-13
+ISO-8859-14 110 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic l8 8859_14 ISO8859-14
+ISO-8859-15 111 ISO_8859-15 Latin-9 8859_15 ISO8859-15
+ISO-8859-16 112 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10
+GBK 113 CP936 MS936 windows-936
+GB18030 114
+OSD_EBCDIC_DF04_15 115
+OSD_EBCDIC_DF03_IRV 116
+OSD_EBCDIC_DF04_1 117
+JIS_Encoding 16 csJISEncoding
+Shift_JIS 17 MS_Kanji csShiftJIS X-SJIS Shift-JIS
+EUC-JP 18 csEUCPkdFmtJapanese Extended_UNIX_Code_Packed_Format_for_Japanese EUCJP
+Extended_UNIX_Code_Fixed_Width_for_Japanese 19 csEUCFixWidJapanese
+ISO-10646-UCS-Basic 1002 csUnicodeASCII
+ISO-10646-Unicode-Latin1 1003 csUnicodeLatin1 ISO-10646
+ISO-Unicode-IBM-1261 1005 csUnicodeIBM1261
+ISO-Unicode-IBM-1268 1006 csUnicodeIBM1268
+ISO-Unicode-IBM-1276 1007 csUnicodeIBM1276
+ISO-Unicode-IBM-1264 1008 csUnicodeIBM1264
+ISO-Unicode-IBM-1265 1009 csUnicodeIBM1265
+ISO-8859-1-Windows-3.0-Latin-1 2000 csWindows30Latin1
+ISO-8859-1-Windows-3.1-Latin-1 2001 csWindows31Latin1
+ISO-8859-2-Windows-Latin-2 2002 csWindows31Latin2
+ISO-8859-9-Windows-Latin-5 2003 csWindows31Latin5
+Adobe-Standard-Encoding 2005 csAdobeStandardEncoding
+Ventura-US 2006 csVenturaUS
+Ventura-International 2007 csVenturaInternational
+PC8-Danish-Norwegian 2012 csPC8DanishNorwegian
+PC8-Turkish 2014 csPC8Turkish
+IBM-Symbols 2015 csIBMSymbols
+IBM-Thai 2016 csIBMThai
+HP-Legal 2017 csHPLegal
+HP-Pi-font 2018 csHPPiFont
+HP-Math8 2019 csHPMath8
+Adobe-Symbol-Encoding 2020 csHPPSMath
+HP-DeskTop 2021 csHPDesktop
+Ventura-Math 2022 csVenturaMath
+Microsoft-Publishing 2023 csMicrosoftPublishing
+Windows-31J 2024 csWindows31J
+GB2312 2025 csGB2312 EUC-CN EUCCN CN-GB
+Big5 2026 csBig5 BIG-FIVE BIG-5 CN-BIG5 BIG_FIVE
+windows-1250 2250 CP1250 MS-EE
+windows-1251 2251 CP1251 MS-CYRL
+windows-1252 2252 CP1252 MS-ANSI
+windows-1253 2253 CP1253 MS-GREEK
+windows-1254 2254 CP1254 MS-TURK
+windows-1255 2255
+windows-1256 2256 CP1256 MS-ARAB
+windows-1257 2257 CP1257 WINBALTRIM
+windows-1258 2258
+TIS-620 2259
+HZ-GB-2312 2085
+
+# Additional encodings not defined by IANA
+
+# Arbitrary allocations
+#CP737 3001
+#CP853 3002
+#CP856 3003
+CP874 3004 WINDOWS-874
+#CP922 3005
+#CP1046 3006
+#CP1124 3007
+#CP1125 3008 WINDOWS-1125
+#CP1129 3009
+#CP1133 3010 IBM-CP1133
+#CP1161 3011 IBM-1161 IBM1161 CSIBM1161
+#CP1162 3012 IBM-1162 IBM1162 CSIBM1162
+#CP1163 3013 IBM-1163 IBM1163 CSIBM1163
+#GEORGIAN-ACADEMY 3014
+#GEORGIAN-PS 3015
+#KOI8-RU 3016
+#KOI8-T 3017
+#MACARABIC 3018 X-MAC-ARABIC MAC-ARABIC
+#MACCROATIAN 3019 X-MAC-CROATIAN MAC-CROATIAN
+#MACGREEK 3020 X-MAC-GREEK MAC-GREEK
+#MACHEBREW 3021 X-MAC-HEBREW MAC-HEBREW
+#MACICELAND 3022 X-MAC-ICELAND MAC-ICELAND
+#MACROMANIA 3023 X-MAC-ROMANIA MAC-ROMANIA
+#MACTHAI 3024 X-MAC-THAI MAC-THAI
+#MACTURKISH 3025 X-MAC-TURKISH MAC-TURKISH
+#MULELAO-1 3026
+
+# From Unicode Lib
+ISO-IR-182 4000
+ISO-IR-197 4002
+ISO-2022-JP-1 4008
+MACCYRILLIC 4009 X-MAC-CYRILLIC MAC-CYRILLIC
+MACUKRAINE 4010 X-MAC-UKRAINIAN MAC-UKRAINIAN
+MACCENTRALEUROPE 4011 X-MAC-CENTRALEURROMAN MAC-CENTRALEURROMAN
+JOHAB 4012
+ISO-8859-11 4014 iso-ir-166 ISO_8859-11 ISO8859-11 8859_11
+X-CURRENT 4999 X-SYSTEM
+X-ACORN-LATIN1 5001
+X-ACORN-FUZZY 5002
Added: trunk/dom/test/data/binding/sample.html
URL: http://source.netsurf-browser.org/trunk/dom/test/data/binding/sample.html...
==============================================================================
--- trunk/dom/test/data/binding/sample.html (added)
+++ trunk/dom/test/data/binding/sample.html Sun Nov 4 03:40:09 2007
@@ -1,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>This is a title</title>
+</head>
+<body>
+<p>Here is some text with mismatched <b>bold <i>and italic </b>tags</i>. Here's some more text.</p>
+</body>
+</html>
+
Modified: trunk/dom/test/lib/testobject.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testobject.c?rev=364...
==============================================================================
--- trunk/dom/test/lib/testobject.c (original)
+++ trunk/dom/test/lib/testobject.c Sun Nov 4 03:40:09 2007
@@ -5,10 +5,14 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <dom/bootstrap/init_fini.h>
+
+#include "bindings/hubbub/parser.h"
#include "bindings/xml/xmlbinding.h"
#include "bindings/xml/xmlparser.h"
@@ -17,10 +21,14 @@
#include "testobject.h"
#include "utils.h"
-static bool xml_parser_initialised;
+static bool parser_initialised;
struct TestObject {
- dom_xml_parser *parser;
+ enum { OBJECT_XML, OBJECT_HTML } type;
+ union {
+ dom_xml_parser *xml;
+ dom_hubbub_parser *html;
+ } parser;
struct dom_document *doc;
};
@@ -33,6 +41,7 @@
#define CHUNK_SIZE 4096
uint8_t buf[CHUNK_SIZE];
FILE *fp;
+ char *dot;
size_t len;
TestObject *ret;
@@ -43,15 +52,18 @@
exit(EXIT_FAILURE);
}
- if (xml_parser_initialised == false) {
+ if (parser_initialised == false) {
assert(dom_initialise(myrealloc, NULL) == DOM_NO_ERR);
assert(dom_xml_binding_initialise(myrealloc, NULL) ==
DOM_XML_OK);
+// assert(dom_hubbub_binding_initialise(myrealloc, NULL) ==
+// DOM_HUBBUB_OK);
+
atexit(test_object_cleanup);
- xml_parser_initialised = true;
+ parser_initialised = true;
}
snprintf(fnbuf, sizeof fnbuf, "%s/%s", argv[1], uri);
@@ -60,16 +72,67 @@
if (ret == NULL)
return NULL;
- ret->parser = dom_xml_parser_create(NULL, "UTF-8", myrealloc, NULL,
- mymsg, NULL);
- if (ret->parser == NULL) {
- free(ret);
- return NULL;
+ /* Detect the parser type (this is mildly hacky) */
+ dot = strrchr(uri, '.');
+ len = strlen(uri);
+
+ if (dot == NULL) {
+ printf("No file extension, assuming XML\n");
+
+ ret->type = OBJECT_XML;
+ } else if (len - ((dot + 1) - uri) == 3) {
+ if (tolower(dot[1]) == 'x' && tolower(dot[2]) == 'm'
+ && tolower(dot[3]) == 'l') {
+ ret->type = OBJECT_XML;
+ } else if (tolower(dot[1]) == 'h' && tolower(dot[2]) == 't' &&
+ tolower(dot[3]) == 'm') {
+ ret->type = OBJECT_HTML;
+ }
+ } else if (len - ((dot + 1) - uri) == 4) {
+ if (tolower(dot[1]) == 'h' && tolower(dot[2]) == 't' &&
+ tolower(dot[3]) == 'm' &&
+ tolower(dot[4]) == 'l') {
+ ret->type = OBJECT_HTML;
+ }
+ } else {
+ /* Assume XML */
+ ret->type = OBJECT_XML;
+ }
+
+ switch (ret->type) {
+ case OBJECT_XML:
+ ret->parser.xml = dom_xml_parser_create(NULL, "UTF-8",
+ myrealloc, NULL, mymsg, NULL);
+ if (ret->parser.xml == NULL) {
+ free(ret);
+ return NULL;
+ }
+ break;
+ case OBJECT_HTML:
+ {
+ char abuf[1024];
+ snprintf(abuf, sizeof abuf, "%s/Aliases", argv[1]);
+
+ ret->parser.html = dom_hubbub_parser_create(abuf,
+ NULL, "UTF-8", myrealloc, NULL, mymsg, NULL);
+ if (ret->parser.html == NULL) {
+ free(ret);
+ return NULL;
+ }
+ break;
+ }
}
fp = fopen(fnbuf, "r");
if (fp == NULL) {
- dom_xml_parser_destroy(ret->parser);
+ switch (ret->type) {
+ case OBJECT_XML:
+ dom_xml_parser_destroy(ret->parser.xml);
+ break;
+ case OBJECT_HTML:
+ dom_hubbub_parser_destroy(ret->parser.html);
+ break;
+ }
free(ret);
return NULL;
}
@@ -81,8 +144,16 @@
while (len > CHUNK_SIZE) {
fread(buf, 1, CHUNK_SIZE, fp);
- assert(dom_xml_parser_parse_chunk(ret->parser, buf,
- CHUNK_SIZE) == DOM_XML_OK);
+ switch (ret->type) {
+ case OBJECT_XML:
+ assert(dom_xml_parser_parse_chunk(ret->parser.xml,
+ buf, CHUNK_SIZE) == DOM_XML_OK);
+ break;
+ case OBJECT_HTML:
+ assert(dom_hubbub_parser_parse_chunk(ret->parser.html,
+ buf, CHUNK_SIZE) == DOM_HUBBUB_OK);
+ break;
+ }
len -= CHUNK_SIZE;
}
@@ -90,20 +161,51 @@
if (len > 0) {
fread(buf, 1, len, fp);
- assert(dom_xml_parser_parse_chunk(ret->parser, buf,
- len) == DOM_XML_OK);
+ switch (ret->type) {
+ case OBJECT_XML:
+ assert(dom_xml_parser_parse_chunk(ret->parser.xml,
+ buf, len) == DOM_XML_OK);
+ break;
+ case OBJECT_HTML:
+ assert(dom_hubbub_parser_parse_chunk(ret->parser.html,
+ buf, len) == DOM_HUBBUB_OK);
+ break;
+ }
len = 0;
}
- assert(dom_xml_parser_completed(ret->parser) == DOM_XML_OK);
+ switch (ret->type) {
+ case OBJECT_XML:
+ assert(dom_xml_parser_completed(ret->parser.xml) == DOM_XML_OK);
+ break;
+ case OBJECT_HTML:
+ assert(dom_hubbub_parser_completed(ret->parser.html) ==
+ DOM_HUBBUB_OK);
+ break;
+ }
fclose(fp);
- ret->doc = dom_xml_parser_get_document(ret->parser);
-
- dom_xml_parser_destroy(ret->parser);
- ret->parser = NULL;
+ switch (ret->type) {
+ case OBJECT_XML:
+ ret->doc = dom_xml_parser_get_document(ret->parser.xml);
+ break;
+ case OBJECT_HTML:
+ ret->doc = dom_hubbub_parser_get_document(ret->parser.html);
+ break;
+ }
+
+ switch (ret->type) {
+ case OBJECT_XML:
+ dom_xml_parser_destroy(ret->parser.xml);
+ ret->parser.xml = NULL;
+ break;
+ case OBJECT_HTML:
+ dom_hubbub_parser_destroy(ret->parser.html);
+ ret->parser.html = NULL;
+ break;
+ }
return ret;
@@ -117,14 +219,13 @@
const char *test_object_get_mimetype(TestObject *obj)
{
- UNUSED(obj);
-
- return "text/xml";
+ return (obj->type == OBJECT_XML ? "text/xml" : "text/html");
}
void test_object_cleanup(void)
{
- if (xml_parser_initialised) {
+ if (parser_initialised) {
+// dom_hubbub_binding_finalise();
dom_xml_binding_finalise();
dom_finalise();
}
15 years, 6 months
r3647 jmb - /trunk/dom/test/lib/testobject.c
by netsurf@semichrome.net
Author: jmb
Date: Sun Nov 4 02:13:32 2007
New Revision: 3647
URL: http://source.netsurf-browser.org?rev=3647&view=rev
Log:
Fix TestObject after xml binding error changes
Modified:
trunk/dom/test/lib/testobject.c
Modified: trunk/dom/test/lib/testobject.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testobject.c?rev=364...
==============================================================================
--- trunk/dom/test/lib/testobject.c (original)
+++ trunk/dom/test/lib/testobject.c Sun Nov 4 02:13:32 2007
@@ -46,7 +46,8 @@
if (xml_parser_initialised == false) {
assert(dom_initialise(myrealloc, NULL) == DOM_NO_ERR);
- assert(dom_xml_binding_initialise(myrealloc, NULL) == XML_OK);
+ assert(dom_xml_binding_initialise(myrealloc, NULL) ==
+ DOM_XML_OK);
atexit(test_object_cleanup);
@@ -81,7 +82,7 @@
fread(buf, 1, CHUNK_SIZE, fp);
assert(dom_xml_parser_parse_chunk(ret->parser, buf,
- CHUNK_SIZE) == XML_OK);
+ CHUNK_SIZE) == DOM_XML_OK);
len -= CHUNK_SIZE;
}
@@ -90,12 +91,12 @@
fread(buf, 1, len, fp);
assert(dom_xml_parser_parse_chunk(ret->parser, buf,
- len) == XML_OK);
+ len) == DOM_XML_OK);
len = 0;
}
- assert(dom_xml_parser_completed(ret->parser) == XML_OK);
+ assert(dom_xml_parser_completed(ret->parser) == DOM_XML_OK);
fclose(fp);
15 years, 6 months
r3646 jmb - in /trunk/dom/bindings: Makefile hubbub/ hubbub/Makefile hubbub/README hubbub/errors.h hubbub/parser.c hubbub/parser.h hubbub/utils.h
by netsurf@semichrome.net
Author: jmb
Date: Sun Nov 4 02:08:05 2007
New Revision: 3646
URL: http://source.netsurf-browser.org?rev=3646&view=rev
Log:
Beginnings of a hubbub binding to libdom
Currently comprises a stubbed-out parser wrapper
Todo:
1) Complete parser wrapper, such that it actually creates a DOM tree
2) Provide a hubbub-backed DOMImplementationSource
Added:
trunk/dom/bindings/hubbub/
trunk/dom/bindings/hubbub/Makefile
trunk/dom/bindings/hubbub/README
trunk/dom/bindings/hubbub/errors.h
trunk/dom/bindings/hubbub/parser.c
trunk/dom/bindings/hubbub/parser.h
trunk/dom/bindings/hubbub/utils.h
Modified:
trunk/dom/bindings/Makefile
Modified: trunk/dom/bindings/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/bindings/Makefile?rev=3646&r1...
==============================================================================
--- trunk/dom/bindings/Makefile (original)
+++ trunk/dom/bindings/Makefile Sun Nov 4 02:08:05 2007
@@ -23,22 +23,29 @@
# Targets
release:
@${MAKE} -C xml release
+ @${MAKE} -C hubbub release
debug:
@${MAKE} -C xml debug
+ @${MAKE} -C hubbub debug
clean:
@${MAKE} -C xml clean
+ @${MAKE} -C hubbub clean
distclean:
@${MAKE} -C xml distclean
+ @${MAKE} -C hubbub distclean
setup:
@${MAKE} -C xml setup
+ @${MAKE} -C hubbub setup
export:
@${MAKE} -C xml export
+ @${MAKE} -C hubbub export
test:
@${MAKE} -C xml test
+ @${MAKE} -C hubbub test
Added: trunk/dom/bindings/hubbub/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/bindings/hubbub/Makefile?rev=...
==============================================================================
--- trunk/dom/bindings/hubbub/Makefile (added)
+++ trunk/dom/bindings/hubbub/Makefile Sun Nov 4 02:08:05 2007
@@ -1,0 +1,70 @@
+# Makefile for libdom
+#
+# Toolchain is exported by top-level makefile
+#
+# Top-level makefile also exports the following variables:
+#
+# COMPONENT Name of component
+# EXPORT Absolute path of export directory
+# TOP Absolute path of source tree root
+#
+# The top-level makefile requires the following targets to exist:
+#
+# clean Clean source tree
+# debug Create a debug binary
+# distclean Fully clean source tree, back to pristine condition
+# export Export distributable components to ${EXPORT}
+# release Create a release binary
+# setup Perform any setup required prior to compilation
+# test Execute any test cases
+
+# Manipulate include paths
+# TODO: fix hubbub include path finding -- needs hubbub to use pkgconfig
+CFLAGS += -I$(CURDIR) \
+ -I../../../hubbub/include
+
+# Release output
+RELEASE = ${TOP}/${COMPONENT}-libhubbub.a
+
+# Debug output
+DEBUG = ${TOP}/${COMPONENT}-libhubbub-debug.a
+
+# Objects
+OBJS = parser
+
+.PHONY: clean debug distclean export release setup test
+
+# Targets
+release: $(addprefix Release/, $(addsuffix .o, $(OBJS)))
+ @${AR} ${ARFLAGS} $(RELEASE) Release/*
+
+debug: $(addprefix Debug/, $(addsuffix .o, $(OBJS)))
+ @${AR} ${ARFLAGS} $(DEBUG) Debug/*
+
+clean:
+ -@${RM} ${RMFLAGS} $(addprefix Release/, $(addsuffix .o, ${OBJS}))
+ -@${RM} ${RMFLAGS} $(addprefix Debug/, $(addsuffix .o, ${OBJS}))
+ -@${RM} ${RMFLAGS} $(RELEASE) $(DEBUG)
+
+distclean:
+ -@${RM} ${RMFLAGS} -r Release
+ -@${RM} ${RMFLAGS} -r Debug
+
+setup:
+ @${MKDIR} ${MKDIRFLAGS} Release
+ @${MKDIR} ${MKDIRFLAGS} Debug
+
+export:
+ @${CP} ${CPFLAGS} $(RELEASE) ${EXPORT}/lib/
+
+test:
+
+# Pattern rules
+Release/%.o: %.c
+ @${ECHO} ${ECHOFLAGS} "==> $<"
+ @${CC} -c ${CFLAGS} -DNDEBUG -o $@ $<
+
+Debug/%.o: %.c
+ @${ECHO} ${ECHOFLAGS} "==> $<"
+ @${CC} -c -g ${CFLAGS} -o $@ $<
+
Added: trunk/dom/bindings/hubbub/README
URL: http://source.netsurf-browser.org/trunk/dom/bindings/hubbub/README?rev=36...
==============================================================================
--- trunk/dom/bindings/hubbub/README (added)
+++ trunk/dom/bindings/hubbub/README Sun Nov 4 02:08:05 2007
@@ -1,0 +1,29 @@
+Hubbub binding for libdom
+=========================
+
+Overview
+--------
+
+ This is an example binding of hubbub to libdom. It consists of two,
+ orthogonal, parts:
+
+ 1) hubbub parser wrapper
+ 2) hubbub-specific DOMImplementationSource for libdom
+
+Push parser wrapper
+-------------------
+
+ This is a wrapper around hubbub's parser API, to facilitate
+ construction of a libdom DOM tree. The basic premise is that the wrapper
+ intercepts the SAX-like events emitted by hubbub's tokeniser then builds
+ a libdom DOM tree from them.
+
+DOMImplementationSource
+-----------------------
+
+ The DOMImplementationSource exposes the APIs needed to create a new
+ document based upon the hubbub binding. It also provides the utility
+ functions that libdom uses when performing some operations (such as
+ document normalization). This is needed as libdom is document language
+ agnostic; therefore, it requires support from the binding to perform
+ some operations.
Added: trunk/dom/bindings/hubbub/errors.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/hubbub/errors.h?rev=...
==============================================================================
--- trunk/dom/bindings/hubbub/errors.h (added)
+++ trunk/dom/bindings/hubbub/errors.h Sun Nov 4 02:08:05 2007
@@ -1,0 +1,19 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_hubbub_errors_h_
+#define dom_hubbub_errors_h_
+
+typedef enum {
+ DOM_HUBBUB_OK = 0,
+
+ DOM_HUBBUB_NOMEM = 1,
+
+ DOM_HUBBUB_HUBBUB_ERR = (1<<16),
+} dom_hubbub_error;
+
+#endif
Added: trunk/dom/bindings/hubbub/parser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/hubbub/parser.c?rev=...
==============================================================================
--- trunk/dom/bindings/hubbub/parser.c (added)
+++ trunk/dom/bindings/hubbub/parser.c Sun Nov 4 02:08:05 2007
@@ -1,0 +1,215 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#include <hubbub/hubbub.h>
+#include <hubbub/parser.h>
+
+#include <dom/dom.h>
+
+#include "parser.h"
+#include "utils.h"
+
+/**
+ * libdom Hubbub parser object
+ */
+struct dom_hubbub_parser {
+ hubbub_parser *parser; /**< Hubbub parser instance */
+
+ struct dom_document *doc; /**< DOM Document we're building */
+
+ bool complete; /**< Indicate stream completion */
+
+ struct dom_implementation *impl;/**< DOM implementation */
+
+ dom_alloc alloc; /**< Memory (de)allocation function */
+ void *pw; /**< Pointer to client data */
+
+ dom_msg msg; /**< Informational messaging function */
+ void *mctx; /**< Pointer to client data */
+};
+
+static void __dom_hubbub_buffer_handler(const uint8_t *buffer, size_t len,
+ void *pw);
+static void __dom_hubbub_token_handler(const hubbub_token *token, void *pw);
+
+static bool __initialised;
+
+/**
+ * Create a Hubbub parser instance
+ *
+ * \param enc Source charset, or NULL
+ * \param int_enc Desired charset of document buffer (UTF-8 or UTF-16)
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \param msg Informational message function
+ * \param mctx Pointer to client-specific private data
+ * \return Pointer to instance, or NULL on memory exhaustion
+ */
+dom_hubbub_parser *dom_hubbub_parser_create(const char *enc,
+ const char *int_enc, dom_alloc alloc, void *pw,
+ dom_msg msg, void *mctx)
+{
+ dom_hubbub_parser *parser;
+ hubbub_parser_optparams params;
+ struct dom_string *features;
+ dom_exception err;
+ hubbub_error e;
+
+ if (__initialised == false) {
+ /** \todo Need path of encoding aliases file */
+ e = hubbub_initialise("", (hubbub_alloc) alloc, pw);
+ if (e != HUBBUB_OK) {
+ msg(DOM_MSG_ERROR, mctx,
+ "Failed initialising hubbub");
+ return NULL;
+ }
+
+ __initialised = true;
+ }
+
+ parser = alloc(NULL, sizeof(dom_hubbub_parser), pw);
+ if (parser == NULL) {
+ msg(DOM_MSG_CRITICAL, mctx, "No memory for parser");
+ return NULL;
+ }
+
+ parser->parser = hubbub_parser_create(enc, int_enc,
+ (hubbub_alloc) alloc, pw);
+ if (parser->parser == NULL) {
+ alloc(parser, 0, pw);
+ msg(DOM_MSG_CRITICAL, mctx, "Failed to create hubbub parser");
+ return NULL;
+ }
+
+ params.buffer_handler.handler = __dom_hubbub_buffer_handler;
+ params.buffer_handler.pw = parser;
+ e = hubbub_parser_setopt(parser->parser, HUBBUB_PARSER_BUFFER_HANDLER,
+ ¶ms);
+ if (e != HUBBUB_OK) {
+ hubbub_parser_destroy(parser->parser);
+ alloc(parser, 0, pw);
+ msg(DOM_MSG_CRITICAL, mctx,
+ "Failed registering hubbub buffer handler");
+ return NULL;
+ }
+
+ params.token_handler.handler = __dom_hubbub_token_handler;
+ params.token_handler.pw = parser;
+ e = hubbub_parser_setopt(parser->parser, HUBBUB_PARSER_TOKEN_HANDLER,
+ ¶ms);
+ if (e != HUBBUB_OK) {
+ hubbub_parser_destroy(parser->parser);
+ alloc(parser, 0, pw);
+ msg(DOM_MSG_CRITICAL, mctx,
+ "Failed registering hubbub token handler");
+ return NULL;
+ }
+
+ parser->doc = NULL;
+
+ parser->complete = false;
+
+ /* Get DOM implementation */
+ /* Create string representation of the features we want */
+ err = dom_string_create_from_ptr_no_doc(alloc, pw,
+ DOM_STRING_UTF8,
+ (const uint8_t *) "HTML", SLEN("HTML"), &features);
+ if (err != DOM_NO_ERR) {
+ hubbub_parser_destroy(parser->parser);
+ alloc(parser, 0, pw);
+ msg(DOM_MSG_CRITICAL, mctx, "No memory for feature string");
+ return NULL;
+ }
+
+ /* Now, try to get an appropriate implementation from the registry */
+ err = dom_implregistry_get_dom_implementation(features,
+ &parser->impl, alloc, pw);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(features);
+ hubbub_parser_destroy(parser->parser);
+ alloc(parser, 0, pw);
+ msg(DOM_MSG_ERROR, mctx, "No suitable DOMImplementation");
+ return NULL;
+ }
+
+ /* no longer need the features string */
+ dom_string_unref(features);
+
+ parser->alloc = alloc;
+ parser->pw = pw;
+
+ parser->msg = msg;
+ parser->mctx = mctx;
+
+ return parser;
+}
+
+/* Destroy a Hubbub parser instance */
+void dom_hubbub_parser_destroy(dom_hubbub_parser *parser)
+{
+ dom_implementation_unref(parser->impl);
+
+ hubbub_parser_destroy(parser->parser);
+
+ /** \todo do we want to clean up the document here too? */
+
+ parser->alloc(parser, 0, parser->pw);
+}
+
+/* Parse a chunk of data */
+dom_hubbub_error dom_hubbub_parser_parse_chunk(dom_hubbub_parser *parser,
+ uint8_t *data, size_t len)
+{
+ hubbub_error err;
+
+ err = hubbub_parser_parse_chunk(parser->parser, data, len);
+ if (err != HUBBUB_OK) {
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
+ "hubbub_parser_parse_chunk failed: %d", err);
+ return DOM_HUBBUB_HUBBUB_ERR | err;
+ }
+
+ return DOM_HUBBUB_OK;
+}
+
+/* Notify parser that datastream is empty */
+dom_hubbub_error dom_hubbub_parser_completed(dom_hubbub_parser *parser)
+{
+ hubbub_error err;
+
+ err = hubbub_parser_completed(parser->parser);
+ if (err != DOM_HUBBUB_OK) {
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
+ "hubbub_parser_completed failed: %d", err);
+ return DOM_HUBBUB_HUBBUB_ERR | err;
+ }
+
+ parser->complete = true;
+
+ return DOM_HUBBUB_OK;
+}
+
+/* Retrieve the created DOM Document */
+struct dom_document *dom_hubbub_parser_get_document(dom_hubbub_parser *parser)
+{
+ return (parser->complete ? parser->doc : NULL);
+}
+
+void __dom_hubbub_buffer_handler(const uint8_t *buffer, size_t len,
+ void *pw)
+{
+ UNUSED(buffer);
+ UNUSED(len);
+ UNUSED(pw);
+}
+
+void __dom_hubbub_token_handler(const hubbub_token *token, void *pw)
+{
+ UNUSED(token);
+ UNUSED(pw);
+}
+
Added: trunk/dom/bindings/hubbub/parser.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/hubbub/parser.h?rev=...
==============================================================================
--- trunk/dom/bindings/hubbub/parser.h (added)
+++ trunk/dom/bindings/hubbub/parser.h Sun Nov 4 02:08:05 2007
@@ -1,0 +1,40 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_hubbub_parser_h_
+#define dom_hubbub_parser_h_
+
+#include <stddef.h>
+#include <inttypes.h>
+
+#include <dom/dom.h>
+
+#include "errors.h"
+
+struct dom_document;
+
+typedef struct dom_hubbub_parser dom_hubbub_parser;
+
+/* Create a Hubbub parser instance */
+dom_hubbub_parser *dom_hubbub_parser_create(const char *enc,
+ const char *int_enc, dom_alloc alloc, void *pw,
+ dom_msg msg, void *mctx);
+
+/* Destroy a Hubbub parser instance */
+void dom_hubbub_parser_destroy(dom_hubbub_parser *parser);
+
+/* Parse a chunk of data */
+dom_hubbub_error dom_hubbub_parser_parse_chunk(dom_hubbub_parser *parser,
+ uint8_t *data, size_t len);
+
+/* Notify parser that datastream is empty */
+dom_hubbub_error dom_hubbub_parser_completed(dom_hubbub_parser *parser);
+
+/* Retrieve the created DOM Document */
+struct dom_document *dom_hubbub_parser_get_document(dom_hubbub_parser *parser);
+
+#endif
Added: trunk/dom/bindings/hubbub/utils.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/hubbub/utils.h?rev=3...
==============================================================================
--- trunk/dom/bindings/hubbub/utils.h (added)
+++ trunk/dom/bindings/hubbub/utils.h Sun Nov 4 02:08:05 2007
@@ -1,0 +1,28 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_hubbub_utils_h_
+#define dom_hubbub_utils_h_
+
+#ifndef max
+#define max(a,b) ((a)>(b)?(a):(b))
+#endif
+
+#ifndef min
+#define min(a,b) ((a)<(b)?(a):(b))
+#endif
+
+#ifndef SLEN
+/* Calculate length of a string constant */
+#define SLEN(s) (sizeof((s)) - 1) /* -1 for '\0' */
+#endif
+
+#ifndef UNUSED
+#define UNUSED(x) ((x)=(x))
+#endif
+
+#endif
15 years, 6 months
r3645 jmb - in /trunk/dom/bindings/xml: xmlbinding.c xmlerror.h xmlparser.c
by netsurf@semichrome.net
Author: jmb
Date: Sun Nov 4 02:01:00 2007
New Revision: 3645
URL: http://source.netsurf-browser.org?rev=3645&view=rev
Log:
Fix up names of xml binding error enum values
Modified:
trunk/dom/bindings/xml/xmlbinding.c
trunk/dom/bindings/xml/xmlerror.h
trunk/dom/bindings/xml/xmlparser.c
Modified: trunk/dom/bindings/xml/xmlbinding.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.c?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.c (original)
+++ trunk/dom/bindings/xml/xmlbinding.c Sun Nov 4 02:01:00 2007
@@ -381,7 +381,7 @@
*
* \param alloc Pointer to memory (de)allocation function
* \param pw Pointer to client-specific private data
- * \return XML_OK on success, XML_NOMEM on memory exhaustion
+ * \return DOM_XML_OK on success, DOM_XML_NOMEM on memory exhaustion
*/
dom_xml_error dom_xml_binding_initialise(dom_alloc alloc, void *pw)
{
@@ -389,19 +389,19 @@
err = dom_register_source(&xml_dom_impl_src, alloc, pw);
if (err != DOM_NO_ERR)
- return XML_NOMEM;
-
- return XML_OK;
+ return DOM_XML_NOMEM;
+
+ return DOM_XML_OK;
}
/**
* Finalise the XML DOM binding
*
- * \return XML_OK on success.
+ * \return DOM_XML_OK on success.
*/
dom_xml_error dom_xml_binding_finalise(void)
{
- return XML_OK;
-}
-
-
+ return DOM_XML_OK;
+}
+
+
Modified: trunk/dom/bindings/xml/xmlerror.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlerror.h?rev=3...
==============================================================================
--- trunk/dom/bindings/xml/xmlerror.h (original)
+++ trunk/dom/bindings/xml/xmlerror.h Sun Nov 4 02:01:00 2007
@@ -9,11 +9,11 @@
#define xml_xmlerror_h_
typedef enum {
- XML_OK = 0,
+ DOM_XML_OK = 0,
- XML_NOMEM = 1,
+ DOM_XML_NOMEM = 1,
- XML_LIBXML_ERR = (1<<16),
+ DOM_XML_LIBXML_ERR = (1<<16),
} dom_xml_error;
#endif
Modified: trunk/dom/bindings/xml/xmlparser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.c?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.c (original)
+++ trunk/dom/bindings/xml/xmlparser.c Sun Nov 4 02:01:00 2007
@@ -255,7 +255,7 @@
* \param parser The XML parser instance to use for parsing
* \param data Pointer to data chunk
* \param len Byte length of data chunk
- * \return XML_OK on success, XML_LIBXML_ERR | <libxml error> on failure
+ * \return DOM_XML_OK on success, DOM_XML_LIBXML_ERR | <libxml error> on failure
*/
dom_xml_error dom_xml_parser_parse_chunk(dom_xml_parser *parser,
uint8_t *data, size_t len)
@@ -266,17 +266,17 @@
if (err != XML_ERR_OK) {
parser->msg(DOM_MSG_ERROR, parser->mctx,
"xmlParseChunk failed: %d", err);
- return XML_LIBXML_ERR | err;
- }
-
- return XML_OK;
+ return DOM_XML_LIBXML_ERR | err;
+ }
+
+ return DOM_XML_OK;
}
/**
* Notify parser that datastream is empty
*
* \param parser The XML parser instance to notify
- * \return XML_OK on success, XML_LIBXML_ERR | <libxml error> on failure
+ * \return DOM_XML_OK on success, DOM_XML_LIBXML_ERR | <libxml error> on failure
*
* This will force any remaining data through the parser
*/
@@ -288,12 +288,12 @@
if (err != XML_ERR_OK) {
parser->msg(DOM_MSG_ERROR, parser->mctx,
"xmlParseChunk failed: %d", err);
- return XML_LIBXML_ERR | err;
+ return DOM_XML_LIBXML_ERR | err;
}
parser->complete = true;
- return XML_OK;
+ return DOM_XML_OK;
}
/**
15 years, 6 months
r3644 adrianl - /trunk/netsurf/desktop/browser.c
by netsurf@semichrome.net
Author: adrianl
Date: Sun Nov 4 01:16:50 2007
New Revision: 3644
URL: http://source.netsurf-browser.org?rev=3644&view=rev
Log:
Fix frame-related crash (images.google) caused by destruction of current window when clicking URL/submitting form
Modified:
trunk/netsurf/desktop/browser.c
Modified: trunk/netsurf/desktop/browser.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/browser.c?rev=364...
==============================================================================
--- trunk/netsurf/desktop/browser.c (original)
+++ trunk/netsurf/desktop/browser.c Sun Nov 4 01:16:50 2007
@@ -1256,6 +1256,7 @@
void browser_window_mouse_action_html(struct browser_window *bw,
browser_mouse_state mouse, int x, int y)
{
+ enum { ACTION_NONE, ACTION_SUBMIT, ACTION_GO } action = ACTION_NONE;
char *base_url = 0;
char *title = 0;
const char *url = 0;
@@ -1393,12 +1394,8 @@
gadget->form->action);
status = status_buffer;
pointer = GUI_POINTER_POINT;
- if (mouse & (BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2)) {
- browser_form_submit(bw,
- browser_window_find_target(bw, target,
- (mouse & BROWSER_MOUSE_CLICK_2)),
- gadget->form, gadget);
- }
+ if (mouse & (BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2))
+ action = ACTION_SUBMIT;
} else {
status = messages_get("FormBadSubmit");
}
@@ -1523,11 +1520,8 @@
gui_window_save_as_link(bw->window,
&browser_window_href_content);
- } else if (mouse & (BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2)) {
- browser_window_go(browser_window_find_target(bw, target,
- (mouse & BROWSER_MOUSE_CLICK_2)),
- url, c->url, true);
- }
+ } else if (mouse & (BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2))
+ action = ACTION_GO;
} else {
bool done = false;
@@ -1609,6 +1603,23 @@
browser_window_set_status(bw, status);
browser_window_set_pointer(bw->window, pointer);
+
+ /* deferred actions that can cause this browser_window to be destroyed
+ and must therefore be done after set_status/pointer
+ */
+ switch (action) {
+ case ACTION_SUBMIT:
+ browser_form_submit(bw,
+ browser_window_find_target(bw, target,
+ (mouse & BROWSER_MOUSE_CLICK_2)),
+ gadget->form, gadget);
+
+ case ACTION_GO:
+ browser_window_go(browser_window_find_target(bw, target,
+ (mouse & BROWSER_MOUSE_CLICK_2)),
+ url, c->url, true);
+ break;
+ }
}
15 years, 6 months
r3643 jmb - in /trunk/dom: bindings/ bindings/xml/ include/dom/ test/lib/
by netsurf@semichrome.net
Author: jmb
Date: Sun Nov 4 01:06:53 2007
New Revision: 3643
URL: http://source.netsurf-browser.org?rev=3643&view=rev
Log:
Fix up bindings buildsystem to permit multiple bindings to be built -- quite why this wasn't done in the first place is currently beyond me.
Tidy up XML binding -- ensure all public API is prefixed dom_xml_ to avoid confusion, remove xml_alloc (it's pointless), and move xml_msg to <dom/functypes.h> (as dom_msg, as it's more useful there)
Fix up testobject to compile once more
Removed:
trunk/dom/bindings/xml/functypes.h
Modified:
trunk/dom/bindings/Makefile
trunk/dom/bindings/xml/Makefile
trunk/dom/bindings/xml/xmlbinding.c
trunk/dom/bindings/xml/xmlbinding.h
trunk/dom/bindings/xml/xmlerror.h
trunk/dom/bindings/xml/xmlparser.c
trunk/dom/bindings/xml/xmlparser.h
trunk/dom/include/dom/functypes.h
trunk/dom/test/lib/testobject.c
Modified: trunk/dom/bindings/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/bindings/Makefile?rev=3643&r1...
==============================================================================
--- trunk/dom/bindings/Makefile (original)
+++ trunk/dom/bindings/Makefile Sun Nov 4 01:06:53 2007
@@ -18,55 +18,27 @@
# setup Perform any setup required prior to compilation
# test Execute any test cases
-# Manipulate include paths
-CFLAGS += -I$(CURDIR)
-
-# Release output
-RELEASE = ${TOP}/${COMPONENT}-libxml.a
-
-# Debug output
-DEBUG = ${TOP}/${COMPONENT}-libxml-debug.a
-
-# Objects
-OBJS =
-
.PHONY: clean debug distclean export release setup test
# Targets
-release: $(addprefix Release/, $(addsuffix .o, $(OBJS)))
+release:
@${MAKE} -C xml release
- @${AR} ${ARFLAGS} $(RELEASE) Release/*
-debug: $(addprefix Debug/, $(addsuffix .o, $(OBJS)))
+debug:
@${MAKE} -C xml debug
- @${AR} ${ARFLAGS} $(DEBUG) Debug/*
clean:
@${MAKE} -C xml clean
-ifneq (${OBJS}, )
- -@${RM} ${RMFLAGS} $(addprefix Release/, $(addsuffix .o, ${OBJS}))
- -@${RM} ${RMFLAGS} $(addprefix Debug/, $(addsuffix .o, ${OBJS}))
-endif
- -@${RM} ${RMFLAGS} $(RELEASE) $(DEBUG)
-
+
distclean:
- -@${RM} ${RMFLAGS} -r Release
- -@${RM} ${RMFLAGS} -r Debug
+ @${MAKE} -C xml distclean
setup:
- @${MKDIR} ${MKDIRFLAGS} Release
- @${MKDIR} ${MKDIRFLAGS} Debug
+ @${MAKE} -C xml setup
export:
- @${CP} ${CPFLAGS} $(RELEASE) ${EXPORT}/lib/
+ @${MAKE} -C xml export
test:
+ @${MAKE} -C xml test
-# Pattern rules
-Release/%.o: %.c
- @${ECHO} ${ECHOFLAGS} "==> $<"
- @${CC} -c ${CFLAGS} -DNDEBUG -o $@ $<
-
-Debug/%.o: %.c
- @${ECHO} ${ECHOFLAGS} "==> $<"
- @${CC} -c -g ${CFLAGS} -o $@ $<
Modified: trunk/dom/bindings/xml/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/Makefile?rev=364...
==============================================================================
--- trunk/dom/bindings/xml/Makefile (original)
+++ trunk/dom/bindings/xml/Makefile Sun Nov 4 01:06:53 2007
@@ -23,33 +23,47 @@
`${PKGCONFIG} ${PKGCONFIGFLAGS} --cflags libxml-2.0` \
-D_POSIX_C_SOURCE
+# Release output
+RELEASE = ${TOP}/${COMPONENT}-libxml.a
+
+# Debug output
+DEBUG = ${TOP}/${COMPONENT}-libxml-debug.a
+
# Objects
OBJS = xmlbinding xmlparser
.PHONY: clean debug distclean export release setup test
# Targets
-release: $(addprefix ../Release/, $(addsuffix .o, $(OBJS)))
+release: $(addprefix Release/, $(addsuffix .o, $(OBJS)))
+ @${AR} ${ARFLAGS} $(RELEASE) Release/*
-debug: $(addprefix ../Debug/, $(addsuffix .o, $(OBJS)))
+debug: $(addprefix Debug/, $(addsuffix .o, $(OBJS)))
+ @${AR} ${ARFLAGS} $(DEBUG) Debug/*
clean:
- -@${RM} ${RMFLAGS} $(addprefix ../Release/, $(addsuffix .o, ${OBJS}))
- -@${RM} ${RMFLAGS} $(addprefix ../Debug/, $(addsuffix .o, ${OBJS}))
+ -@${RM} ${RMFLAGS} $(addprefix Release/, $(addsuffix .o, ${OBJS}))
+ -@${RM} ${RMFLAGS} $(addprefix Debug/, $(addsuffix .o, ${OBJS}))
+ -@${RM} ${RMFLAGS} $(RELEASE) $(DEBUG)
distclean:
+ -@${RM} ${RMFLAGS} -r Release
+ -@${RM} ${RMFLAGS} -r Debug
setup:
+ @${MKDIR} ${MKDIRFLAGS} Release
+ @${MKDIR} ${MKDIRFLAGS} Debug
export:
+ @${CP} ${CPFLAGS} $(RELEASE) ${EXPORT}/lib/
test:
# Pattern rules
-../Release/%.o: %.c
+Release/%.o: %.c
@${ECHO} ${ECHOFLAGS} "==> $<"
@${CC} -c ${CFLAGS} -DNDEBUG -o $@ $<
-../Debug/%.o: %.c
+Debug/%.o: %.c
@${ECHO} ${ECHOFLAGS} "==> $<"
@${CC} -c -g ${CFLAGS} -o $@ $<
Removed: trunk/dom/bindings/xml/functypes.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/functypes.h?rev=...
==============================================================================
--- trunk/dom/bindings/xml/functypes.h (original)
+++ trunk/dom/bindings/xml/functypes.h (removed)
@@ -1,39 +1,0 @@
-/*
- * This file is part of libdom.
- * Licensed under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
- */
-
-#ifndef xml_functypes_h_
-#define xml_functypes_h_
-
-#include <stddef.h>
-#include <inttypes.h>
-
-/**
- * Type of XML parser allocation function
- */
-typedef void *(*xml_alloc)(void *ptr, size_t len, void *pw);
-
-/**
- * Severity levels for xml_msg function, based on syslog(3)
- */
-enum {
- XML_MSG_DEBUG,
- XML_MSG_INFO,
- XML_MSG_NOTICE,
- XML_MSG_WARNING,
- XML_MSG_ERROR,
- XML_MSG_CRITICAL,
- XML_MSG_ALERT,
- XML_MSG_EMERGENCY
-};
-
-/**
- * Type of XML parser message function
- */
-typedef void (*xml_msg)(uint32_t severity, void *ctx, const char *msg, ...);
-
-#endif
-
Modified: trunk/dom/bindings/xml/xmlbinding.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.c?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.c (original)
+++ trunk/dom/bindings/xml/xmlbinding.c Sun Nov 4 01:06:53 2007
@@ -9,7 +9,6 @@
#include <dom/bootstrap/implregistry.h>
#include <dom/dom.h>
-#include "functypes.h"
#include "xmlbinding.h"
#include "utils.h"
@@ -384,11 +383,11 @@
* \param pw Pointer to client-specific private data
* \return XML_OK on success, XML_NOMEM on memory exhaustion
*/
-xml_error xml_dom_binding_initialise(xml_alloc alloc, void *pw)
+dom_xml_error dom_xml_binding_initialise(dom_alloc alloc, void *pw)
{
dom_exception err;
- err = dom_register_source(&xml_dom_impl_src, (dom_alloc) alloc, pw);
+ err = dom_register_source(&xml_dom_impl_src, alloc, pw);
if (err != DOM_NO_ERR)
return XML_NOMEM;
@@ -400,7 +399,7 @@
*
* \return XML_OK on success.
*/
-xml_error xml_dom_binding_finalise(void)
+dom_xml_error dom_xml_binding_finalise(void)
{
return XML_OK;
}
Modified: trunk/dom/bindings/xml/xmlbinding.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.h?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.h (original)
+++ trunk/dom/bindings/xml/xmlbinding.h Sun Nov 4 01:06:53 2007
@@ -9,12 +9,11 @@
#define xml_xmlbinding_h_
#include "xmlerror.h"
-#include "functypes.h"
/* Initialise the XML DOM binding */
-xml_error xml_dom_binding_initialise(xml_alloc alloc, void *pw);
+dom_xml_error dom_xml_binding_initialise(dom_alloc alloc, void *pw);
/* Finalise the XML DOM binding */
-xml_error xml_dom_binding_finalise(void);
+dom_xml_error dom_xml_binding_finalise(void);
#endif
Modified: trunk/dom/bindings/xml/xmlerror.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlerror.h?rev=3...
==============================================================================
--- trunk/dom/bindings/xml/xmlerror.h (original)
+++ trunk/dom/bindings/xml/xmlerror.h Sun Nov 4 01:06:53 2007
@@ -14,6 +14,6 @@
XML_NOMEM = 1,
XML_LIBXML_ERR = (1<<16),
-} xml_error;
+} dom_xml_error;
#endif
Modified: trunk/dom/bindings/xml/xmlparser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.c?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.c (original)
+++ trunk/dom/bindings/xml/xmlparser.c Sun Nov 4 01:06:53 2007
@@ -29,22 +29,22 @@
static void xml_parser_end_element_ns(void *ctx, const xmlChar *localname,
const xmlChar *prefix, const xmlChar *URI);
-static dom_exception xml_parser_link_nodes(xml_parser *parser,
+static dom_exception xml_parser_link_nodes(dom_xml_parser *parser,
struct dom_node *dom, xmlNodePtr xml);
-static void xml_parser_add_node(xml_parser *parser, struct dom_node *parent,
+static void xml_parser_add_node(dom_xml_parser *parser, struct dom_node *parent,
xmlNodePtr child);
-static void xml_parser_add_element_node(xml_parser *parser,
+static void xml_parser_add_element_node(dom_xml_parser *parser,
struct dom_node *parent, xmlNodePtr child);
-static void xml_parser_add_text_node(xml_parser *parser,
+static void xml_parser_add_text_node(dom_xml_parser *parser,
struct dom_node *parent, xmlNodePtr child);
-static void xml_parser_add_cdata_section(xml_parser *parser,
+static void xml_parser_add_cdata_section(dom_xml_parser *parser,
struct dom_node *parent, xmlNodePtr child);
-static void xml_parser_add_entity_reference(xml_parser *parser,
+static void xml_parser_add_entity_reference(dom_xml_parser *parser,
struct dom_node *parent, xmlNodePtr child);
-static void xml_parser_add_comment(xml_parser *parser,
+static void xml_parser_add_comment(dom_xml_parser *parser,
struct dom_node *parent, xmlNodePtr child);
-static void xml_parser_add_document_type(xml_parser *parser,
+static void xml_parser_add_document_type(dom_xml_parser *parser,
struct dom_node *parent, xmlNodePtr child);
static void xml_parser_internal_subset(void *ctx, const xmlChar *name,
@@ -79,9 +79,9 @@
const xmlChar *ExternalID, const xmlChar *SystemID);
/**
- * XML parser object
- */
-struct xml_parser {
+ * libdom XML parser object
+ */
+struct dom_xml_parser {
xmlParserCtxtPtr xml_ctx; /**< libxml parser context */
struct dom_document *doc; /**< DOM Document we're building */
@@ -92,10 +92,10 @@
struct dom_implementation *impl;/**< DOM implementation */
- xml_alloc alloc; /**< Memory (de)allocation function */
+ dom_alloc alloc; /**< Memory (de)allocation function */
void *pw; /**< Pointer to client data */
- xml_msg msg; /**< Informational message function */
+ dom_msg msg; /**< Informational message function */
void *mctx; /**< Pointer to client data */
};
@@ -152,19 +152,19 @@
* libxml only supports a UTF-8 document buffer and forcibly setting the
* parser encoding is not yet implemented
*/
-xml_parser *xml_parser_create(const char *enc, const char *int_enc,
- xml_alloc alloc, void *pw, xml_msg msg, void *mctx)
-{
- xml_parser *parser;
+dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc,
+ dom_alloc alloc, void *pw, dom_msg msg, void *mctx)
+{
+ dom_xml_parser *parser;
struct dom_string *features;
dom_exception err;
UNUSED(enc);
UNUSED(int_enc);
- parser = alloc(NULL, sizeof(xml_parser), pw);
+ parser = alloc(NULL, sizeof(dom_xml_parser), pw);
if (parser == NULL) {
- msg(XML_MSG_CRITICAL, mctx, "No memory for parser");
+ msg(DOM_MSG_CRITICAL, mctx, "No memory for parser");
return NULL;
}
@@ -172,7 +172,7 @@
xmlCreatePushParserCtxt(&sax_handler, parser, "", 0, NULL);
if (parser->xml_ctx == NULL) {
alloc(parser, 0, pw);
- msg(XML_MSG_CRITICAL, mctx, "Failed to create XML parser");
+ msg(DOM_MSG_CRITICAL, mctx, "Failed to create XML parser");
return NULL;
}
@@ -188,7 +188,7 @@
if (err != DOM_NO_ERR) {
xmlFreeParserCtxt(parser->xml_ctx);
alloc(parser, 0, pw);
- msg(XML_MSG_CRITICAL, mctx, "No memory for userdata key");
+ msg(DOM_MSG_CRITICAL, mctx, "No memory for userdata key");
return NULL;
}
@@ -201,7 +201,7 @@
dom_string_unref(parser->udkey);
xmlFreeParserCtxt(parser->xml_ctx);
alloc(parser, 0, pw);
- msg(XML_MSG_CRITICAL, mctx, "No memory for feature string");
+ msg(DOM_MSG_CRITICAL, mctx, "No memory for feature string");
return NULL;
}
@@ -213,7 +213,7 @@
dom_string_unref(parser->udkey);
xmlFreeParserCtxt(parser->xml_ctx);
alloc(parser, 0, pw);
- msg(XML_MSG_ERROR, mctx, "No suitable DOMImplementation");
+ msg(DOM_MSG_ERROR, mctx, "No suitable DOMImplementation");
return NULL;
}
@@ -234,7 +234,7 @@
*
* \param parser The parser instance to destroy
*/
-void xml_parser_destroy(xml_parser *parser)
+void dom_xml_parser_destroy(dom_xml_parser *parser)
{
dom_implementation_unref(parser->impl);
@@ -257,14 +257,14 @@
* \param len Byte length of data chunk
* \return XML_OK on success, XML_LIBXML_ERR | <libxml error> on failure
*/
-xml_error xml_parser_parse_chunk(xml_parser *parser,
+dom_xml_error dom_xml_parser_parse_chunk(dom_xml_parser *parser,
uint8_t *data, size_t len)
{
xmlParserErrors err;
err = xmlParseChunk(parser->xml_ctx, (char *) data, len, 0);
if (err != XML_ERR_OK) {
- parser->msg(XML_MSG_ERROR, parser->mctx,
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
"xmlParseChunk failed: %d", err);
return XML_LIBXML_ERR | err;
}
@@ -280,13 +280,13 @@
*
* This will force any remaining data through the parser
*/
-xml_error xml_parser_completed(xml_parser *parser)
+dom_xml_error dom_xml_parser_completed(dom_xml_parser *parser)
{
xmlParserErrors err;
err = xmlParseChunk(parser->xml_ctx, "", 0, 1);
if (err != XML_ERR_OK) {
- parser->msg(XML_MSG_ERROR, parser->mctx,
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
"xmlParseChunk failed: %d", err);
return XML_LIBXML_ERR | err;
}
@@ -304,7 +304,7 @@
*
* This may only be called after xml_parser_completed().
*/
-struct dom_document *xml_parser_get_document(xml_parser *parser)
+struct dom_document *dom_xml_parser_get_document(dom_xml_parser *parser)
{
return (parser->complete ? parser->doc : NULL);
}
@@ -316,7 +316,7 @@
*/
void xml_parser_start_document(void *ctx)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
struct dom_document *doc;
dom_exception err;
@@ -333,7 +333,7 @@
(dom_alloc) parser->alloc,
parser->pw);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"Failed creating document");
return;
}
@@ -357,7 +357,7 @@
*/
void xml_parser_end_document(void *ctx)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlNodePtr node;
xmlNodePtr n;
dom_exception err;
@@ -367,7 +367,7 @@
/* If there is no document, we can't do anything */
if (parser->doc == NULL) {
- parser->msg(XML_MSG_WARNING, parser->mctx,
+ parser->msg(DOM_MSG_WARNING, parser->mctx,
"No document in end_document");
return;
}
@@ -379,7 +379,7 @@
err = dom_node_get_user_data((struct dom_node *) parser->doc,
parser->udkey, (void **) &node);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_WARNING, parser->mctx,
+ parser->msg(DOM_MSG_WARNING, parser->mctx,
"Failed finding XML node");
return;
}
@@ -427,7 +427,7 @@
int nb_attributes, int nb_defaulted,
const xmlChar **attributes)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlNodePtr parent = parser->xml_ctx->node;
/* Invoke libxml2's default behaviour */
@@ -437,7 +437,7 @@
/* If there is no document, we can't do anything */
if (parser->doc == NULL) {
- parser->msg(XML_MSG_WARNING, parser->mctx,
+ parser->msg(DOM_MSG_WARNING, parser->mctx,
"No document in start_element_ns");
return;
}
@@ -495,7 +495,7 @@
void xml_parser_end_element_ns(void *ctx, const xmlChar *localname,
const xmlChar *prefix, const xmlChar *URI)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlNodePtr node = parser->xml_ctx->node;
xmlNodePtr n;
@@ -504,14 +504,14 @@
/* If there is no document, we can't do anything */
if (parser->doc == NULL) {
- parser->msg(XML_MSG_WARNING, parser->mctx,
+ parser->msg(DOM_MSG_WARNING, parser->mctx,
"No document in end_element_ns");
return;
}
/* If node wasn't linked, we can't do anything */
if (node->_private == NULL) {
- parser->msg(XML_MSG_WARNING, parser->mctx,
+ parser->msg(DOM_MSG_WARNING, parser->mctx,
"Node '%s' not linked", node->name);
return;
}
@@ -548,8 +548,8 @@
* \param xml The XML node
* \return DOM_NO_ERR on success, appropriate error otherwise
*/
-dom_exception xml_parser_link_nodes(xml_parser *parser, struct dom_node *dom,
- xmlNodePtr xml)
+dom_exception xml_parser_link_nodes(dom_xml_parser *parser,
+ struct dom_node *dom, xmlNodePtr xml)
{
void *prev_data;
dom_exception err;
@@ -558,7 +558,7 @@
err = dom_node_set_user_data(dom, parser->udkey, xml, NULL,
&prev_data);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_ERROR, parser->mctx,
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
"Failed setting user data: %d", err);
return err;
}
@@ -576,7 +576,7 @@
* \param parent The parent DOM node
* \param child The xmlNode to mirror in the DOM as a child of parent
*/
-void xml_parser_add_node(xml_parser *parser, struct dom_node *parent,
+void xml_parser_add_node(dom_xml_parser *parser, struct dom_node *parent,
xmlNodePtr child)
{
static const char *node_types[] = {
@@ -624,7 +624,7 @@
xml_parser_add_document_type(parser, parent, child);
break;
default:
- parser->msg(XML_MSG_NOTICE, parser->mctx,
+ parser->msg(DOM_MSG_NOTICE, parser->mctx,
"Unsupported node type: %s",
node_types[child->type]);
}
@@ -637,8 +637,8 @@
* \param parent The parent DOM node
* \param child The xmlNode to mirror in the DOM as a child of parent
*/
-void xml_parser_add_element_node(xml_parser *parser, struct dom_node *parent,
- xmlNodePtr child)
+void xml_parser_add_element_node(dom_xml_parser *parser,
+ struct dom_node *parent, xmlNodePtr child)
{
struct dom_element *el, *ins_el = NULL;
xmlAttrPtr a;
@@ -655,7 +655,7 @@
strlen((const char *) child->name),
&tag_name);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for tag name");
return;
}
@@ -665,7 +665,7 @@
tag_name, &el);
if (err != DOM_NO_ERR) {
dom_string_unref(tag_name);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"Failed creating element '%s'",
child->name);
return;
@@ -689,7 +689,7 @@
strlen((const char *) child->ns->href),
&namespace);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for namespace");
return;
}
@@ -709,7 +709,7 @@
&qname);
if (err != DOM_NO_ERR) {
dom_string_unref(namespace);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for qname");
return;
}
@@ -720,7 +720,7 @@
if (err != DOM_NO_ERR) {
dom_string_unref(namespace);
dom_string_unref(qname);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"Failed creating element '%s'",
qnamebuf);
return;
@@ -747,7 +747,7 @@
strlen((const char *) a->name),
&name);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for attribute name");
goto cleanup;
}
@@ -757,7 +757,7 @@
name, &attr);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"Failed creating attribute '%s'",
a->name);
goto cleanup;
@@ -781,7 +781,7 @@
strlen((const char *) a->ns->href),
&namespace);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for namespace");
return;
}
@@ -801,7 +801,7 @@
&qname);
if (err != DOM_NO_ERR) {
dom_string_unref(namespace);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for qname");
return;
}
@@ -812,7 +812,7 @@
if (err != DOM_NO_ERR) {
dom_string_unref(namespace);
dom_string_unref(qname);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"Failed creating attribute '%s'",
qnamebuf);
return;
@@ -841,7 +841,7 @@
err = dom_element_set_attribute_node(el, attr, &prev_attr);
if (err != DOM_NO_ERR) {
dom_node_unref((struct dom_node *) attr);
- parser->msg(XML_MSG_ERROR, parser->mctx,
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
"Failed attaching attribute '%s'",
a->name);
goto cleanup;
@@ -859,7 +859,7 @@
err = dom_node_append_child(parent, (struct dom_node *) el,
(struct dom_node **) &ins_el);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_ERROR, parser->mctx,
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
"Failed attaching element '%s'",
child->name);
goto cleanup;
@@ -896,7 +896,7 @@
* \param parent The parent DOM node
* \param child The xmlNode to mirror in the DOM as a child of parent
*/
-void xml_parser_add_text_node(xml_parser *parser, struct dom_node *parent,
+void xml_parser_add_text_node(dom_xml_parser *parser, struct dom_node *parent,
xmlNodePtr child)
{
struct dom_text *text, *ins_text = NULL;
@@ -907,7 +907,7 @@
err = dom_string_create_from_const_ptr(parser->doc, child->content,
strlen((const char *) child->content), &data);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for text node contents ");
return;
}
@@ -916,7 +916,7 @@
err = dom_document_create_text_node(parser->doc, data, &text);
if (err != DOM_NO_ERR) {
dom_string_unref(data);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for text node");
return;
}
@@ -929,7 +929,7 @@
(struct dom_node **) &ins_text);
if (err != DOM_NO_ERR) {
dom_node_unref((struct dom_node *) text);
- parser->msg(XML_MSG_ERROR, parser->mctx,
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
"Failed attaching text node");
return;
}
@@ -957,7 +957,7 @@
* \param parent The parent DOM node
* \param child The xmlNode to mirror in the DOM as a child of parent
*/
-void xml_parser_add_cdata_section(xml_parser *parser,
+void xml_parser_add_cdata_section(dom_xml_parser *parser,
struct dom_node *parent, xmlNodePtr child)
{
struct dom_cdata_section *cdata, *ins_cdata = NULL;
@@ -968,7 +968,7 @@
err = dom_string_create_from_const_ptr(parser->doc, child->content,
strlen((const char *) child->content), &data);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for cdata section contents");
return;
}
@@ -977,7 +977,7 @@
err = dom_document_create_cdata_section(parser->doc, data, &cdata);
if (err != DOM_NO_ERR) {
dom_string_unref(data);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for cdata section");
return;
}
@@ -990,7 +990,7 @@
(struct dom_node **) &ins_cdata);
if (err != DOM_NO_ERR) {
dom_node_unref((struct dom_node *) cdata);
- parser->msg(XML_MSG_ERROR, parser->mctx,
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
"Failed attaching cdata section");
return;
}
@@ -1018,7 +1018,7 @@
* \param parent The parent DOM node
* \param child The xmlNode to mirror in the DOM as a child of parent
*/
-void xml_parser_add_entity_reference(xml_parser *parser,
+void xml_parser_add_entity_reference(dom_xml_parser *parser,
struct dom_node *parent, xmlNodePtr child)
{
struct dom_entity_reference *entity, *ins_entity = NULL;
@@ -1030,7 +1030,7 @@
err = dom_string_create_from_const_ptr(parser->doc, child->name,
strlen((const char *) child->name), &name);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for entity reference name");
return;
}
@@ -1040,7 +1040,7 @@
&entity);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for entity reference");
return;
}
@@ -1058,7 +1058,7 @@
(struct dom_node **) &ins_entity);
if (err != DOM_NO_ERR) {
dom_node_unref((struct dom_node *) entity);
- parser->msg(XML_MSG_ERROR, parser->mctx,
+ parser->msg(DOM_MSG_ERROR, parser->mctx,
"Failed attaching entity reference");
return;
}
@@ -1086,7 +1086,7 @@
* \param parent The parent DOM node
* \param child The xmlNode to mirror in the DOM as a child of parent
*/
-void xml_parser_add_comment(xml_parser *parser, struct dom_node *parent,
+void xml_parser_add_comment(dom_xml_parser *parser, struct dom_node *parent,
xmlNodePtr child)
{
struct dom_comment *comment, *ins_comment = NULL;
@@ -1097,7 +1097,7 @@
err = dom_string_create_from_const_ptr(parser->doc, child->content,
strlen((const char *) child->content), &data);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for comment data");
return;
}
@@ -1106,7 +1106,7 @@
err = dom_document_create_comment(parser->doc, data, &comment);
if (err != DOM_NO_ERR) {
dom_string_unref(data);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for comment node");
return;
}
@@ -1119,7 +1119,7 @@
(struct dom_node **) &ins_comment);
if (err != DOM_NO_ERR) {
dom_node_unref((struct dom_node *) comment);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"Failed attaching comment node");
return;
}
@@ -1147,7 +1147,7 @@
* \param parent The parent DOM node
* \param child The xmlNode to mirror in the DOM as a child of parent
*/
-void xml_parser_add_document_type(xml_parser *parser,
+void xml_parser_add_document_type(dom_xml_parser *parser,
struct dom_node *parent, xmlNodePtr child)
{
xmlDtdPtr dtd = (xmlDtdPtr) child;
@@ -1159,7 +1159,7 @@
err = dom_string_create_from_const_ptr(parser->doc, dtd->name,
strlen((const char *) dtd->name), &qname);
if (err != DOM_NO_ERR) {
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for doctype name");
return;
}
@@ -1172,7 +1172,7 @@
&public_id);
if (err != DOM_NO_ERR) {
dom_string_unref(qname);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for doctype public id");
return;
}
@@ -1186,7 +1186,7 @@
if (err != DOM_NO_ERR) {
dom_string_unref(public_id);
dom_string_unref(qname);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"No memory for doctype system id");
return;
}
@@ -1199,7 +1199,7 @@
dom_string_unref(system_id);
dom_string_unref(public_id);
dom_string_unref(qname);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"Failed to create document type");
return;
}
@@ -1214,7 +1214,7 @@
(struct dom_node **) &ins_doctype);
if (err != DOM_NO_ERR) {
dom_node_unref((struct dom_node *) doctype);
- parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"Failed attaching doctype");
return;
}
@@ -1241,28 +1241,28 @@
void xml_parser_internal_subset(void *ctx, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2InternalSubset(parser->xml_ctx, name, ExternalID, SystemID);
}
int xml_parser_is_standalone(void *ctx)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
return xmlSAX2IsStandalone(parser->xml_ctx);
}
int xml_parser_has_internal_subset(void *ctx)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
return xmlSAX2HasInternalSubset(parser->xml_ctx);
}
int xml_parser_has_external_subset(void *ctx)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
return xmlSAX2HasExternalSubset(parser->xml_ctx);
}
@@ -1270,14 +1270,14 @@
xmlParserInputPtr xml_parser_resolve_entity(void *ctx,
const xmlChar *publicId, const xmlChar *systemId)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
return xmlSAX2ResolveEntity(parser->xml_ctx, publicId, systemId);
}
xmlEntityPtr xml_parser_get_entity(void *ctx, const xmlChar *name)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
return xmlSAX2GetEntity(parser->xml_ctx, name);
}
@@ -1286,7 +1286,7 @@
int type, const xmlChar *publicId, const xmlChar *systemId,
xmlChar *content)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2EntityDecl(parser->xml_ctx, name, type, publicId, systemId,
content);
@@ -1295,7 +1295,7 @@
void xml_parser_notation_decl(void *ctx, const xmlChar *name,
const xmlChar *publicId, const xmlChar *systemId)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2NotationDecl(parser->xml_ctx, name, publicId, systemId);
}
@@ -1304,7 +1304,7 @@
const xmlChar *fullname, int type, int def,
const xmlChar *defaultValue, xmlEnumerationPtr tree)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2AttributeDecl(parser->xml_ctx, elem, fullname, type, def,
defaultValue, tree);
@@ -1313,7 +1313,7 @@
void xml_parser_element_decl(void *ctx, const xmlChar *name,
int type, xmlElementContentPtr content)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2ElementDecl(parser->xml_ctx, name, type, content);
}
@@ -1322,7 +1322,7 @@
const xmlChar *publicId, const xmlChar *systemId,
const xmlChar *notationName)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2UnparsedEntityDecl(parser->xml_ctx, name, publicId,
systemId, notationName);
@@ -1330,42 +1330,42 @@
void xml_parser_set_document_locator(void *ctx, xmlSAXLocatorPtr loc)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2SetDocumentLocator(parser->xml_ctx, loc);
}
void xml_parser_reference(void *ctx, const xmlChar *name)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2Reference(parser->xml_ctx, name);
}
void xml_parser_characters(void *ctx, const xmlChar *ch, int len)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2Characters(parser->xml_ctx, ch, len);
}
void xml_parser_comment(void *ctx, const xmlChar *value)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2Comment(parser->xml_ctx, value);
}
xmlEntityPtr xml_parser_get_parameter_entity(void *ctx, const xmlChar *name)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
return xmlSAX2GetParameterEntity(parser->xml_ctx, name);
}
void xml_parser_cdata_block(void *ctx, const xmlChar *value, int len)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2CDataBlock(parser->xml_ctx, value, len);
}
@@ -1373,7 +1373,7 @@
void xml_parser_external_subset(void *ctx, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID)
{
- xml_parser *parser = (xml_parser *) ctx;
+ dom_xml_parser *parser = (dom_xml_parser *) ctx;
xmlSAX2ExternalSubset(parser->xml_ctx, name, ExternalID, SystemID);
}
Modified: trunk/dom/bindings/xml/xmlparser.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.h?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.h (original)
+++ trunk/dom/bindings/xml/xmlparser.h Sun Nov 4 01:06:53 2007
@@ -11,28 +11,29 @@
#include <stddef.h>
#include <inttypes.h>
+#include <dom/dom.h>
+
#include "xmlerror.h"
-#include "functypes.h"
struct dom_document;
-typedef struct xml_parser xml_parser;
+typedef struct dom_xml_parser dom_xml_parser;
/* Create an XML parser instance */
-xml_parser *xml_parser_create(const char *enc, const char *int_enc,
- xml_alloc alloc, void *pw, xml_msg msg, void *mctx);
+dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc,
+ dom_alloc alloc, void *pw, dom_msg msg, void *mctx);
/* Destroy an XML parser instance */
-void xml_parser_destroy(xml_parser *parser);
+void dom_xml_parser_destroy(dom_xml_parser *parser);
/* Parse a chunk of data */
-xml_error xml_parser_parse_chunk(xml_parser *parser,
+dom_xml_error dom_xml_parser_parse_chunk(dom_xml_parser *parser,
uint8_t *data, size_t len);
/* Notify parser that datastream is empty */
-xml_error xml_parser_completed(xml_parser *parser);
+dom_xml_error dom_xml_parser_completed(dom_xml_parser *parser);
/* Retrieve the created DOM Document */
-struct dom_document *xml_parser_get_document(xml_parser *parser);
+struct dom_document *dom_xml_parser_get_document(dom_xml_parser *parser);
#endif
Modified: trunk/dom/include/dom/functypes.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/functypes.h?rev=3...
==============================================================================
--- trunk/dom/include/dom/functypes.h (original)
+++ trunk/dom/include/dom/functypes.h Sun Nov 4 01:06:53 2007
@@ -9,10 +9,30 @@
#define dom_functypes_h_
#include <stddef.h>
+#include <inttypes.h>
/**
* Type of allocation function for DOM implementation
*/
typedef void *(*dom_alloc)(void *ptr, size_t size, void *pw);
+/**
+ * Severity levels for dom_msg function, based on syslog(3)
+ */
+enum {
+ DOM_MSG_DEBUG,
+ DOM_MSG_INFO,
+ DOM_MSG_NOTICE,
+ DOM_MSG_WARNING,
+ DOM_MSG_ERROR,
+ DOM_MSG_CRITICAL,
+ DOM_MSG_ALERT,
+ DOM_MSG_EMERGENCY
+};
+
+/**
+ * Type of DOM message function
+ */
+typedef void (*dom_msg)(uint32_t severity, void *ctx, const char *msg, ...);
+
#endif
Modified: trunk/dom/test/lib/testobject.c
URL: http://source.netsurf-browser.org/trunk/dom/test/lib/testobject.c?rev=364...
==============================================================================
--- trunk/dom/test/lib/testobject.c (original)
+++ trunk/dom/test/lib/testobject.c Sun Nov 4 01:06:53 2007
@@ -20,7 +20,7 @@
static bool xml_parser_initialised;
struct TestObject {
- xml_parser *parser;
+ dom_xml_parser *parser;
struct dom_document *doc;
};
@@ -46,7 +46,7 @@
if (xml_parser_initialised == false) {
assert(dom_initialise(myrealloc, NULL) == DOM_NO_ERR);
- assert(xml_dom_binding_initialise(myrealloc, NULL) == XML_OK);
+ assert(dom_xml_binding_initialise(myrealloc, NULL) == XML_OK);
atexit(test_object_cleanup);
@@ -59,7 +59,7 @@
if (ret == NULL)
return NULL;
- ret->parser = xml_parser_create(NULL, "UTF-8", myrealloc, NULL,
+ ret->parser = dom_xml_parser_create(NULL, "UTF-8", myrealloc, NULL,
mymsg, NULL);
if (ret->parser == NULL) {
free(ret);
@@ -68,7 +68,7 @@
fp = fopen(fnbuf, "r");
if (fp == NULL) {
- xml_parser_destroy(ret->parser);
+ dom_xml_parser_destroy(ret->parser);
free(ret);
return NULL;
}
@@ -80,7 +80,7 @@
while (len > CHUNK_SIZE) {
fread(buf, 1, CHUNK_SIZE, fp);
- assert(xml_parser_parse_chunk(ret->parser, buf,
+ assert(dom_xml_parser_parse_chunk(ret->parser, buf,
CHUNK_SIZE) == XML_OK);
len -= CHUNK_SIZE;
@@ -89,19 +89,19 @@
if (len > 0) {
fread(buf, 1, len, fp);
- assert(xml_parser_parse_chunk(ret->parser, buf,
+ assert(dom_xml_parser_parse_chunk(ret->parser, buf,
len) == XML_OK);
len = 0;
}
- assert(xml_parser_completed(ret->parser) == XML_OK);
+ assert(dom_xml_parser_completed(ret->parser) == XML_OK);
fclose(fp);
- ret->doc = xml_parser_get_document(ret->parser);
+ ret->doc = dom_xml_parser_get_document(ret->parser);
- xml_parser_destroy(ret->parser);
+ dom_xml_parser_destroy(ret->parser);
ret->parser = NULL;
return ret;
@@ -124,7 +124,7 @@
void test_object_cleanup(void)
{
if (xml_parser_initialised) {
- xml_dom_binding_finalise();
+ dom_xml_binding_finalise();
dom_finalise();
}
}
15 years, 6 months
r3642 jmb - in /trunk/dom/src/core: characterdata.h text.c
by netsurf@semichrome.net
Author: jmb
Date: Sat Nov 3 21:38:53 2007
New Revision: 3642
URL: http://source.netsurf-browser.org?rev=3642&view=rev
Log:
Implement dom_text_split_text()
Modified:
trunk/dom/src/core/characterdata.h
trunk/dom/src/core/text.c
Modified: trunk/dom/src/core/characterdata.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.h?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.h (original)
+++ trunk/dom/src/core/characterdata.h Sat Nov 3 21:38:53 2007
@@ -7,6 +7,8 @@
#ifndef dom_internal_core_characterdata_h_
#define dom_internal_core_characterdata_h_
+
+#include <dom/core/characterdata.h>
#include "core/node.h"
Modified: trunk/dom/src/core/text.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/text.c?rev=3642&r1=3...
==============================================================================
--- trunk/dom/src/core/text.c (original)
+++ trunk/dom/src/core/text.c Sat Nov 3 21:38:53 2007
@@ -128,11 +128,53 @@
dom_exception dom_text_split_text(struct dom_text *text,
unsigned long offset, struct dom_text **result)
{
- UNUSED(text);
- UNUSED(offset);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *t = (struct dom_node *) text;
+ struct dom_string *value;
+ struct dom_text *res;
+ unsigned long len;
+ dom_exception err;
+
+ if (_dom_node_readonly(t)) {
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ err = dom_characterdata_get_length(&text->base, &len);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ if (offset >= len) {
+ return DOM_INDEX_SIZE_ERR;
+ }
+
+ /* Retrieve the data after the split point --
+ * this will be the new node's value. */
+ err = dom_characterdata_substring_data(&text->base, offset,
+ len - offset, &value);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ /* Create new node */
+ err = dom_text_create(t->owner, t->name, value, &res);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(value);
+ return err;
+ }
+
+ /* Release our reference on the value (the new node has its own) */
+ dom_string_unref(value);
+
+ /* Delete the data after the split point */
+ err = dom_characterdata_delete_data(&text->base, offset, len - offset);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) res);
+ return err;
+ }
+
+ *result = res;
+
+ return DOM_NO_ERR;
}
/**
15 years, 6 months
r3641 jmb - in /trunk/dom: include/dom/core/string.h src/core/characterdata.c src/core/string.c
by netsurf@semichrome.net
Author: jmb
Date: Sat Nov 3 21:18:02 2007
New Revision: 3641
URL: http://source.netsurf-browser.org?rev=3641&view=rev
Log:
Add, and implement, dom_string_insert() and dom_string_replace() API
Fix dom_string_substr() to have correct length limits when calling _dom_utf{8,16}_next()
Fix dom_string_substr() to calculate correct length of output string when creating from ptr
Implement dom_characterdata_get_length()
Implement dom_characterdata_substring_data()
Implement dom_characterdata_append_data()
Implement dom_characterdata_insert_data()
Implement dom_characterdata_delete_data()
Implement dom_characterdata_replace_data()
Modified:
trunk/dom/include/dom/core/string.h
trunk/dom/src/core/characterdata.c
trunk/dom/src/core/string.c
Modified: trunk/dom/include/dom/core/string.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/string.h?rev...
==============================================================================
--- trunk/dom/include/dom/core/string.h (original)
+++ trunk/dom/include/dom/core/string.h Sat Nov 3 21:18:02 2007
@@ -63,6 +63,16 @@
dom_exception dom_string_substr(struct dom_string *str,
uint32_t i1, uint32_t i2, struct dom_string **result);
+/* Insert data into a dom string at the given location */
+dom_exception dom_string_insert(struct dom_string *target,
+ struct dom_string *source, uint32_t offset,
+ struct dom_string **result);
+
+/* Replace a section of a dom string */
+dom_exception dom_string_replace(struct dom_string *target,
+ struct dom_string *source, uint32_t i1, uint32_t i2,
+ struct dom_string **result);
+
/* Duplicate a dom string */
dom_exception dom_string_dup(struct dom_string *str,
struct dom_string **result);
Modified: trunk/dom/src/core/characterdata.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/characterdata.c?rev=...
==============================================================================
--- trunk/dom/src/core/characterdata.c (original)
+++ trunk/dom/src/core/characterdata.c Sat Nov 3 21:18:02 2007
@@ -115,10 +115,15 @@
dom_exception dom_characterdata_get_length(struct dom_characterdata *cdata,
unsigned long *length)
{
- UNUSED(cdata);
- UNUSED(length);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *c = (struct dom_node *) cdata;
+
+ if (c->value != NULL) {
+ *length = dom_string_length(c->value);
+ } else {
+ *length = 0;
+ }
+
+ return DOM_NO_ERR;
}
/**
@@ -143,12 +148,22 @@
struct dom_characterdata *cdata, unsigned long offset,
unsigned long count, struct dom_string **data)
{
- UNUSED(cdata);
- UNUSED(offset);
- UNUSED(count);
- UNUSED(data);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *c = (struct dom_node *) cdata;
+ uint32_t len, end;
+
+ if (c->value != NULL) {
+ len = dom_string_length(c->value);
+ } else {
+ len = 0;
+ }
+
+ if (offset >= len) {
+ return DOM_INDEX_SIZE_ERR;
+ }
+
+ end = (offset + count) >= len ? len : offset + count;
+
+ return dom_string_substr(c->value, offset, end, data);
}
/**
@@ -162,10 +177,28 @@
dom_exception dom_characterdata_append_data(struct dom_characterdata *cdata,
struct dom_string *data)
{
- UNUSED(cdata);
- UNUSED(data);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_string *temp;
+ dom_exception err;
+
+ if (_dom_node_readonly(c)) {
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ err = dom_string_insert(c->value, data,
+ c->value != NULL ? dom_string_length(c->value) : 0,
+ &temp);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ if (c->value != NULL) {
+ dom_string_unref(c->value);
+ }
+
+ c->value = temp;
+
+ return DOM_NO_ERR;
}
/**
@@ -182,11 +215,37 @@
dom_exception dom_characterdata_insert_data(struct dom_characterdata *cdata,
unsigned long offset, struct dom_string *data)
{
- UNUSED(cdata);
- UNUSED(offset);
- UNUSED(data);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_string *temp;
+ uint32_t len;
+ dom_exception err;
+
+ if (_dom_node_readonly(c)) {
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ if (c->value != NULL) {
+ len = dom_string_length(c->value);
+ } else {
+ len = 0;
+ }
+
+ if (offset >= len) {
+ return DOM_INDEX_SIZE_ERR;
+ }
+
+ err = dom_string_insert(c->value, data, offset, &temp);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ if (c->value != NULL) {
+ dom_string_unref(c->value);
+ }
+
+ c->value = temp;
+
+ return DOM_NO_ERR;
}
/**
@@ -203,11 +262,39 @@
dom_exception dom_characterdata_delete_data(struct dom_characterdata *cdata,
unsigned long offset, unsigned long count)
{
- UNUSED(cdata);
- UNUSED(offset);
- UNUSED(count);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_string *temp;
+ uint32_t len, end;
+ dom_exception err;
+
+ if (_dom_node_readonly(c)) {
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ if (c->value != NULL) {
+ len = dom_string_length(c->value);
+ } else {
+ len = 0;
+ }
+
+ if (offset >= len) {
+ return DOM_INDEX_SIZE_ERR;
+ }
+
+ end = (offset + count) >= len ? len : offset + count;
+
+ err = dom_string_replace(c->value, NULL, offset, end, &temp);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ if (c->value != NULL) {
+ dom_string_unref(c->value);
+ }
+
+ c->value = temp;
+
+ return DOM_NO_ERR;
}
/**
@@ -226,11 +313,38 @@
unsigned long offset, unsigned long count,
struct dom_string *data)
{
- UNUSED(cdata);
- UNUSED(offset);
- UNUSED(count);
- UNUSED(data);
-
- return DOM_NOT_SUPPORTED_ERR;
-}
-
+ struct dom_node *c = (struct dom_node *) cdata;
+ struct dom_string *temp;
+ uint32_t len, end;
+ dom_exception err;
+
+ if (_dom_node_readonly(c)) {
+ return DOM_NO_MODIFICATION_ALLOWED_ERR;
+ }
+
+ if (c->value != NULL) {
+ len = dom_string_length(c->value);
+ } else {
+ len = 0;
+ }
+
+ if (offset >= len) {
+ return DOM_INDEX_SIZE_ERR;
+ }
+
+ end = (offset + count) >= len ? len : offset + count;
+
+ err = dom_string_replace(c->value, data, offset, end, &temp);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ if (c->value != NULL) {
+ dom_string_unref(c->value);
+ }
+
+ c->value = temp;
+
+ return DOM_NO_ERR;
+}
+
Modified: trunk/dom/src/core/string.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/string.c?rev=3641&r1...
==============================================================================
--- trunk/dom/src/core/string.c (original)
+++ trunk/dom/src/core/string.c Sat Nov 3 21:18:02 2007
@@ -622,9 +622,9 @@
/* Calculate the byte index of the start */
while (i1 > 0) {
if (str->charset == DOM_STRING_UTF8) {
- err = _dom_utf8_next(s, slen, b1, &b1);
+ err = _dom_utf8_next(s, slen - b1, b1, &b1);
} else {
- err = _dom_utf16_next(s, slen, b1, &b1);
+ err = _dom_utf16_next(s, slen - b1, b1, &b1);
}
if (err != CHARSET_OK) {
@@ -640,9 +640,9 @@
/* Calculate the byte index of the end */
while (i2 > 0) {
if (str->charset == DOM_STRING_UTF8) {
- err = _dom_utf8_next(s, slen, b2, &b2);
+ err = _dom_utf8_next(s, slen - b2, b2, &b2);
} else {
- err = _dom_utf16_next(s, slen, b2, &b2);
+ err = _dom_utf16_next(s, slen - b2, b2, &b2);
}
if (err != CHARSET_OK) {
@@ -660,7 +660,268 @@
str->charset,
s + b1, b2 - b1, result)
: dom_string_create_from_ptr(str->ctx.doc,
- s + b1, b2 - b2, result);
+ s + b1, b2 - b1, result);
+}
+
+/**
+ * Insert data into a dom string at the given location
+ *
+ * \param target Pointer to string to insert into
+ * \param source Pointer to string to insert
+ * \param offset Character offset of location to insert at
+ * \param result Pointer to location to receive result
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion,
+ * DOM_INDEX_SIZE_ERR if ::offset > len(::target).
+ *
+ * The returned string will be allocated using the allocation details
+ * stored in ::target.
+ *
+ * The returned string will have its reference count increased. The client
+ * should dereference it once it has finished with it.
+ */
+dom_exception dom_string_insert(struct dom_string *target,
+ struct dom_string *source, uint32_t offset,
+ struct dom_string **result)
+{
+ struct dom_string *res;
+ const uint8_t *t, *s;
+ uint32_t tlen, slen, clen;
+ uint32_t ins = 0;
+ charset_error err;
+
+ __dom_string_get_data(target, &t, &tlen);
+
+ __dom_string_get_data(source, &s, &slen);
+
+ clen = dom_string_length(target);
+
+ if (offset > clen)
+ return DOM_INDEX_SIZE_ERR;
+
+ /* Calculate the byte index of the insertion point */
+ if (offset == clen) {
+ /* Optimisation for append */
+ offset = 0;
+ ins = tlen;
+ } else {
+ while (offset > 0) {
+ if (target->charset == DOM_STRING_UTF8) {
+ err = _dom_utf8_next(t, tlen - ins, ins, &ins);
+ } else {
+ err = _dom_utf16_next(t, tlen - ins, ins, &ins);
+ }
+
+ if (err != CHARSET_OK) {
+ return DOM_NO_MEM_ERR;
+ }
+
+ offset--;
+ }
+ }
+
+ /* Allocate result string */
+ if (target->type == DOM_STRING_PTR_NODOC) {
+ res = target->ctx.nodoc.alloc(NULL, sizeof(struct dom_string),
+ target->ctx.nodoc.pw);
+ } else {
+ res = dom_document_alloc(target->ctx.doc,
+ NULL, sizeof(struct dom_string));
+ }
+
+ if (res == NULL) {
+ return DOM_NO_MEM_ERR;
+ }
+
+ /** \todo support insertion of a string from a different charset */
+
+ /* Allocate data buffer for result contents */
+ if (target->type == DOM_STRING_PTR_NODOC) {
+ res->data.ptr = target->ctx.nodoc.alloc(NULL,
+ tlen + slen, target->ctx.nodoc.pw);
+ } else {
+ res->data.ptr = dom_document_alloc(target->ctx.doc,
+ NULL, tlen + slen);
+ }
+ if (res->data.ptr == NULL) {
+ if (target->type == DOM_STRING_PTR_NODOC) {
+ target->ctx.nodoc.alloc(res, 0, target->ctx.nodoc.pw);
+ } else {
+ dom_document_alloc(target->ctx.doc, res, 0);
+ }
+ return DOM_NO_MEM_ERR;
+ }
+
+ /* Populate result members */
+ res->type = (target->type == DOM_STRING_PTR_NODOC)
+ ? DOM_STRING_PTR_NODOC : DOM_STRING_PTR;
+
+ res->charset = target->charset;
+
+ /* Copy initial portion of target, if any, into result */
+ if (ins > 0) {
+ memcpy(res->data.ptr, t, ins);
+ }
+
+ /* Copy inserted data into result */
+ memcpy(res->data.ptr + ins, s, slen);
+
+ /* Copy remainder of target, if any, into result */
+ if (tlen - ins > 0) {
+ memcpy(res->data.ptr + ins + slen, t + ins, tlen - ins);
+ }
+
+ res->len = tlen + slen;
+
+ if (res->type == DOM_STRING_PTR_NODOC) {
+ res->ctx.nodoc.alloc = target->ctx.nodoc.alloc;
+ res->ctx.nodoc.pw = target->ctx.nodoc.pw;
+ } else {
+ res->ctx.doc = target->ctx.doc;
+ }
+
+ res->refcnt = 1;
+
+ *result = res;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Replace a section of a dom string
+ *
+ * \param target Pointer to string of which to replace a section
+ * \param source Pointer to replacement string
+ * \param i1 Character index of start of region to replace
+ * \param i2 Character index of end of region to replace
+ * \param result Pointer to location to receive result
+ * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * The returned string will be allocated using the allocation details
+ * stored in ::target.
+ *
+ * The returned string will have its reference count increased. The client
+ * should dereference it once it has finished with it.
+ */
+dom_exception dom_string_replace(struct dom_string *target,
+ struct dom_string *source, uint32_t i1, uint32_t i2,
+ struct dom_string **result)
+{
+ struct dom_string *res;
+ const uint8_t *t, *s;
+ uint32_t tlen, slen;
+ uint32_t b1, b2;
+ charset_error err;
+
+ __dom_string_get_data(target, &t, &tlen);
+
+ __dom_string_get_data(source, &s, &slen);
+
+ /* Initialise the byte index of the start to 0 */
+ b1 = 0;
+ /* Make the end a character offset from the start */
+ i2 -= i1;
+
+ /* Calculate the byte index of the start */
+ while (i1 > 0) {
+ if (target->charset == DOM_STRING_UTF8) {
+ err = _dom_utf8_next(s, slen - b1, b1, &b1);
+ } else {
+ err = _dom_utf16_next(s, slen - b1, b1, &b1);
+ }
+
+ if (err != CHARSET_OK) {
+ return DOM_NO_MEM_ERR;
+ }
+
+ i1--;
+ }
+
+ /* Initialise the byte index of the end to that of the start */
+ b2 = b1;
+
+ /* Calculate the byte index of the end */
+ while (i2 > 0) {
+ if (target->charset == DOM_STRING_UTF8) {
+ err = _dom_utf8_next(s, slen - b2, b2, &b2);
+ } else {
+ err = _dom_utf16_next(s, slen - b2, b2, &b2);
+ }
+
+ if (err != CHARSET_OK) {
+ return DOM_NO_MEM_ERR;
+ }
+
+ i2--;
+ }
+
+ /* Allocate result string */
+ if (target->type == DOM_STRING_PTR_NODOC) {
+ res = target->ctx.nodoc.alloc(NULL, sizeof(struct dom_string),
+ target->ctx.nodoc.pw);
+ } else {
+ res = dom_document_alloc(target->ctx.doc,
+ NULL, sizeof(struct dom_string));
+ }
+
+ if (res == NULL) {
+ return DOM_NO_MEM_ERR;
+ }
+
+ /** \todo support insertion of a string from a different charset */
+
+ /* Allocate data buffer for result contents */
+ if (target->type == DOM_STRING_PTR_NODOC) {
+ res->data.ptr = target->ctx.nodoc.alloc(NULL,
+ tlen + slen - (b2 - b1), target->ctx.nodoc.pw);
+ } else {
+ res->data.ptr = dom_document_alloc(target->ctx.doc,
+ NULL, tlen + slen - (b2 - b1));
+ }
+ if (res->data.ptr == NULL) {
+ if (target->type == DOM_STRING_PTR_NODOC) {
+ target->ctx.nodoc.alloc(res, 0, target->ctx.nodoc.pw);
+ } else {
+ dom_document_alloc(target->ctx.doc, res, 0);
+ }
+ return DOM_NO_MEM_ERR;
+ }
+
+ /* Populate result members */
+ res->type = (target->type == DOM_STRING_PTR_NODOC)
+ ? DOM_STRING_PTR_NODOC : DOM_STRING_PTR;
+
+ res->charset = target->charset;
+
+ /* Copy initial portion of target, if any, into result */
+ if (b1 > 0) {
+ memcpy(res->data.ptr, t, b1);
+ }
+
+ /* Copy replacement data into result */
+ if (slen > 0) {
+ memcpy(res->data.ptr + b1, s, slen);
+ }
+
+ /* Copy remainder of target, if any, into result */
+ if (tlen - b2 > 0) {
+ memcpy(res->data.ptr + b1 + slen, t + b2, tlen - b2);
+ }
+
+ res->len = tlen + slen - (b2 - b1);
+
+ if (res->type == DOM_STRING_PTR_NODOC) {
+ res->ctx.nodoc.alloc = target->ctx.nodoc.alloc;
+ res->ctx.nodoc.pw = target->ctx.nodoc.pw;
+ } else {
+ res->ctx.doc = target->ctx.doc;
+ }
+
+ res->refcnt = 1;
+
+ *result = res;
+
+ return DOM_NO_ERR;
}
/**
15 years, 6 months
r3640 tlsa - /trunk/netsurf/!NetSurf/Resources/CSS,f79
by netsurf@semichrome.net
Author: tlsa
Date: Thu Nov 1 21:59:35 2007
New Revision: 3640
URL: http://source.netsurf-browser.org?rev=3640&view=rev
Log:
Update alignment rules again.
Modified:
trunk/netsurf/!NetSurf/Resources/CSS,f79
Modified: trunk/netsurf/!NetSurf/Resources/CSS,f79
URL: http://source.netsurf-browser.org/trunk/netsurf/%21NetSurf/Resources/CSS%...
==============================================================================
--- trunk/netsurf/!NetSurf/Resources/CSS,f79 (original)
+++ trunk/netsurf/!NetSurf/Resources/CSS,f79 Thu Nov 1 21:59:35 2007
@@ -11,6 +11,9 @@
body { display: block; padding: 8px; }
div { display: block; }
+div[align=left] { text-align: left; }
+div[align=center] { text-align: center; }
+div[align=right] { text-align: right; }
div[align=left] * { margin-right: auto; text-align: left; }
div[align=center] * { margin-left: auto; margin-right: auto; text-align: center; }
div[align=right] * { margin-left: auto; text-align: right; }
@@ -49,9 +52,9 @@
sup { vertical-align: super; font-size: .83em; }
p { display: block; margin: 1.12em 0; }
-p[align=left] * { text-align: left; }
-p[align=center] * { text-align: center; }
-p[align=right] * { text-align: right; }
+p[align=left] { text-align: left; }
+p[align=center] { text-align: center; }
+p[align=right] { text-align: right; }
br[clear=left] { clear: left; }
br[clear=right] { clear: right; }
@@ -101,6 +104,9 @@
td[nowrap], th[nowrap] { white-space: nowrap; }
+td[align=left], th[align=left] { text-align: left; }
+td[align=center], th[align=center] { text-align: center; }
+td[align=right], th[align=right] { text-align: right; }
tr[align=left] *, td[align=left] *, th[align=left] * { text-align: left; margin-right: auto; }
tr[align=center] *, td[align=center] *, th[align=center] * { text-align: center; margin-left: auto; margin-right: auto; }
tr[align=right] *, td[align=right] *, th[align=right] * { text-align: right; margin-left: auto; }
15 years, 7 months
r3639 tlsa - /trunk/netsurf/!NetSurf/Resources/CSS,f79
by netsurf@semichrome.net
Author: tlsa
Date: Thu Nov 1 21:44:44 2007
New Revision: 3639
URL: http://source.netsurf-browser.org?rev=3639&view=rev
Log:
Update alignment rules.
Modified:
trunk/netsurf/!NetSurf/Resources/CSS,f79
Modified: trunk/netsurf/!NetSurf/Resources/CSS,f79
URL: http://source.netsurf-browser.org/trunk/netsurf/%21NetSurf/Resources/CSS%...
==============================================================================
--- trunk/netsurf/!NetSurf/Resources/CSS,f79 (original)
+++ trunk/netsurf/!NetSurf/Resources/CSS,f79 Thu Nov 1 21:44:44 2007
@@ -11,9 +11,9 @@
body { display: block; padding: 8px; }
div { display: block; }
-div[align=left] > * { margin-right: auto; }
-div[align=center] > * { margin-left: auto; margin-right: auto; }
-div[align=right] > * { margin-left: auto; }
+div[align=left] * { margin-right: auto; text-align: left; }
+div[align=center] * { margin-left: auto; margin-right: auto; text-align: center; }
+div[align=right] * { margin-left: auto; text-align: right; }
h1 { display: block; font-size: 2em; font-weight: bold; margin: .67em 0; }
h2 { display: block; font-size: 1.5em; font-weight: bold; margin: .69em 0; }
@@ -21,6 +21,12 @@
h4 { display: block; font-weight: bold; margin: 1.12em 0; }
h5 { display: block; font-size: .83em; font-weight: bold; margin: 1.5em 0; }
h6 { display: block; font-size: .75em; font-weight: bold; margin: 1.67em 0; }
+h1[align=left], h2[align=left], h3[align=left],
+h4[align=left], h5[align=left], h6[align=left] { text-align: left; }
+h1[align=center], h2[align=center], h3[align=center],
+h4[align=center], h5[align=center], h6[align=center] { text-align: center; }
+h1[align=right], h2[align=right], h3[align=right],
+h4[align=right], h5[align=right], h6[align=right] { text-align: right; }
address { display: block; font-style: italic; }
@@ -43,6 +49,9 @@
sup { vertical-align: super; font-size: .83em; }
p { display: block; margin: 1.12em 0; }
+p[align=left] * { text-align: left; }
+p[align=center] * { text-align: center; }
+p[align=right] * { text-align: right; }
br[clear=left] { clear: left; }
br[clear=right] { clear: right; }
@@ -92,9 +101,9 @@
td[nowrap], th[nowrap] { white-space: nowrap; }
-tr[align=left] > td, tr[align=left] > th { text-align: left; margin-right: auto; }
-tr[align=center] > td, tr[align=center] > th { text-align: center; margin-left: auto; margin-right: auto; }
-tr[align=right] > td, tr[align=right] > th { text-align: right; margin-left: auto; }
+tr[align=left] *, td[align=left] *, th[align=left] * { text-align: left; margin-right: auto; }
+tr[align=center] *, td[align=center] *, th[align=center] * { text-align: center; margin-left: auto; margin-right: auto; }
+tr[align=right] *, td[align=right] *, th[align=right] * { text-align: right; margin-left: auto; }
col[valign=top], colgroup[valign=top], tbody[valign=top], td[valign=top], tfoot[valign=top], th[valign=top], thead[valign=top], tr[valign=top] { vertical-align: top; }
col[valign=middle], colgroup[valign=middle], tbody[valign=middle], td[valign=middle], tfoot[valign=middle], th[valign=middle], thead[valign=middle], tr[valign=middle] { vertical-align: middle; }
@@ -113,7 +122,7 @@
applet[align=right] { float: right; }
center { display: block; text-align: center; }
-center * { margin-left: auto; margin-right: auto; }
+center * { margin-left: auto; margin-right: auto; text-align: center; }
tt { font-family: monospace; }
i { font-style: italic; }
@@ -177,11 +186,3 @@
overflow: scroll; padding: 0 2px; }
fieldset { display: block; border: thin solid #888; margin: 1.12em 0; }
-
-[align=left] { text-align: left; }
-[align=center] { text-align: center; }
-[align=right] { text-align: right; }
-
-[align=left] * { margin-left: 0; margin-right: auto; }
-[align=center] * { margin-left: auto; margin-right: auto; }
-[align=right] * { margin-left: auto; margin-right: 0; }
15 years, 7 months