r3410 jshaw - /trunk/dom/test/test-to-c.xsl
by netsurf@semichrome.net
Author: jshaw
Date: Sat Jul 14 12:14:05 2007
New Revision: 3410
URL: http://source.netsurf-browser.org?rev=3410&view=rev
Log:
Implement metadata function comment. Partially implement <assertEquals>
on DOMStrings. dom_string_create_from_const_ptr lookup is currently
hardwired.
Modified:
trunk/dom/test/test-to-c.xsl
Modified: trunk/dom/test/test-to-c.xsl
URL: http://source.netsurf-browser.org/trunk/dom/test/test-to-c.xsl?rev=3410&r...
==============================================================================
--- trunk/dom/test/test-to-c.xsl (original)
+++ trunk/dom/test/test-to-c.xsl Sat Jul 14 12:14:05 2007
@@ -7,14 +7,14 @@
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"><!-- TODO: exslt not currently used -->
- <!-- relative to transform -->
- <xsl:param name="interfaces-docname">dom1-interfaces.xml</xsl:param>
- <xsl:param name="target-uri-base">http://www.w3.org/2001/DOM-Test-Suite/tests/Level-1/</xsl:param>
-<xsl:output method="text" encoding="UTF-8"/>
-<xsl:variable name="domspec" select="document($interfaces-docname)"/>
+ <xsl:param name="interfaces-docname">dom1-interfaces.xml</xsl:param>
+ <xsl:param name="target-uri-base">http://www.w3.org/2001/DOM-Test-Suite/tests/Level-1/</xsl:param>
+ <xsl:output method="text" encoding="UTF-8"/>
+ <xsl:variable name="domspec" select="document($interfaces-docname)"/>
+
<!-- swallow any text which we don't understand -->
-<xsl:template match="text()"/>
+<xsl:template match="text()" mode="body"/>
<!--
for anything that doesn't match another template,
@@ -24,7 +24,7 @@
This should either be a <method> or <attribute>. If it is neither,
we generate an <xsl:message> reporting that the element is not known.
-->
-<xsl:template match="*">
+<xsl:template match="*" mode="body">
<!-- the element name matches by this template -->
<xsl:variable name="feature" select="local-name(.)"/>
<xsl:variable name="interface" select="@interface"/>
@@ -69,37 +69,52 @@
</xsl:template>
<xsl:template match="*[local-name() = 'test']">
-<xsl:text>
-int main(int argc, char **argv) {
-</xsl:text>
-<xsl:apply-templates/>
+ <xsl:apply-templates select="*[local-name() = 'metadata']"/>
+<xsl:text>
+int main(int argc, char **argv)
+{
+ dom_exception err;
+</xsl:text>
+<xsl:apply-templates mode="body"/>
<xsl:text>
return 0;
}
</xsl:text>
</xsl:template>
+<xsl:template match="*[local-name() = 'metadata']">
+ <xsl:text>/**
+</xsl:text>
+ <xsl:call-template name="emit-description">
+ <xsl:with-param name="description" select="translate(*[local-name() = 'description'], '	', ' ')"/>
+ </xsl:call-template>
+ <xsl:text> */</xsl:text>
+</xsl:template>
+
+<!-- swallowing templates in body mode -->
+<xsl:template match="*[local-name()='metadata']" mode="body"/>
+
<!--
================================
Language construct templates
================================
-->
-<xsl:template match="*[local-name() = 'var']">
+<xsl:template match="*[local-name() = 'var']" mode="body">
<xsl:text> struct </xsl:text><xsl:call-template name="convert_var_type"> <xsl:with-param name="var_type" select="@type"/>
</xsl:call-template> *<xsl:value-of select="@name"/>;
</xsl:template>
-<xsl:template match="*[local-name() = 'if']">
-<xsl:text> if (</xsl:text><!-- TODO: condition --><xsl:text>) {
-</xsl:text>
-<!-- TODO: statement(s) -->
-<xsl:text>
- }</xsl:text>
+<xsl:template match="*[local-name() = 'if']" mode="body">
+<xsl:text>
+ if (</xsl:text><xsl:apply-templates select="*[1]" mode="body"/><xsl:text>) {
+</xsl:text>
+<xsl:apply-templates select="*[position() > 1 and local-name() != 'else']" mode="body"/>
+<xsl:text> }</xsl:text>
<xsl:for-each select="*[local-name() = 'else']">
<xsl:text> else {
</xsl:text>
- <xsl:apply-templates/>
+ <xsl:apply-templates mode="body"/>
<xsl:text>}</xsl:text>
</xsl:for-each>
<xsl:text>
@@ -111,6 +126,10 @@
DOM templates
================================
-->
+
+<xsl:template match="*[local-name() = 'contentType']" mode="body">
+ <xsl:text>strcmp(TODO, "</xsl:text><xsl:value-of select="@type"/><xsl:text>") == 0</xsl:text>
+</xsl:template>
<xsl:template name="produce-method">
<!-- TODO: implement me -->
@@ -146,9 +165,21 @@
<xsl:if test="@value">
<!-- TODO: set attribute to a value -->
</xsl:if>
+ <!--
+ call an attribute accessor. this takes the form
+ err = dom_<objecttype>_get_<attributename>(<objectstruct>, &<targetattributestruct>);
+ -->
<xsl:if test="@var">
<xsl:text>
- err</xsl:text><xsl:text> = TODO_function_call(</xsl:text><xsl:value-of select="@obj"/><xsl:text>, &</xsl:text><xsl:value-of select="@var"/><xsl:text>);
+ err = </xsl:text>
+ <xsl:call-template name="convert_var_type">
+ <xsl:with-param name="var_type"><xsl:value-of select="//*[local-name() = 'var' and @name = $obj]/@type"/></xsl:with-param>
+ </xsl:call-template>
+ <xsl:text>_get_</xsl:text>
+ <xsl:call-template name="convert_attribute_name">
+ <xsl:with-param name="attribute_name"><xsl:value-of select="$attribute/@name"/></xsl:with-param>
+ </xsl:call-template>
+ <xsl:text>(</xsl:text><xsl:value-of select="@obj"/><xsl:text>, &</xsl:text><xsl:value-of select="@var"/><xsl:text>);
assert(err == DOM_NO_ERR);
</xsl:text>
@@ -161,40 +192,109 @@
================================
-->
-<xsl:template match="*[local-name() = 'assertNotNull']">
+<xsl:template match="*[local-name() = 'assertNotNull']" mode="body">
<!-- TODO: what does the @id string do, and do we need it here? -->
<xsl:text>
assert(</xsl:text><xsl:value-of select="@actual"/><xsl:text> != NULL);
</xsl:text>
</xsl:template>
-<xsl:template match="*[local-name() = 'assertNull']">
+<xsl:template match="*[local-name() = 'assertNull']" mode="body">
<!-- TODO: what does the @id string do, and do we need it here? -->
<xsl:text>
assert(</xsl:text><xsl:value-of select="@actual"/><xsl:text> == NULL);
</xsl:text>
</xsl:template>
+<xsl:template match="*[local-name() = 'assertEquals']" mode="body">
+ <!--
+ TODO: this is hard, because we need to know what the types of the objects are
+ that we're comparing
+ -->
+ <xsl:variable name="actual" select="@actual"/>
+ <xsl:variable name="var_type" select="//*[local-name() = 'var' and @name = $actual]/@type"/>
+
+ <xsl:choose>
+ <xsl:when test="$var_type = 'DOMString'">
+ <xsl:text> struct dom_string *match;
+ err = dom_string_create_from_const_ptr(doc <!-- TODO: how do we obtain a handle to doc? We could lookup //var[@type = 'Document', but what if there's more than one? -->, </xsl:text><xsl:value-of select="@expected"/><xsl:text>,
+ SLEN(</xsl:text><xsl:value-of select="@expected"/><xsl:text>), &match);
+ assert(err == DOM_NO_ERR); <!-- TODO: pull this line out, since it's reused everywhere -->
+ assert(dom_string_cmp(</xsl:text><xsl:value-of select="@actual"/><xsl:text>, match) == 0); <!-- TODO: handle case insensitivity if @insensitive is set-->
+</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message terminate="no">Warning in assertEquals template: don't know how to compare variable type '<xsl:value-of select="$var_type"/>'</xsl:message>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
<!-- helper templates -->
<xsl:template name="convert_var_type">
<!-- TODO: convert certain types, e.g. from DocumentType to dom_document_type -->
-<xsl:param name="var_type"/>
-<xsl:text>dom_</xsl:text><xsl:choose>
- <xsl:when test="$var_type = 'Document'">
- <xsl:text>document</xsl:text>
- </xsl:when>
- <xsl:when test="$var_type = 'DocumentType'">
- <xsl:text>document_type</xsl:text>
- </xsl:when>
- <xsl:when test="$var_type = 'DOMString'">
- <xsl:text>string</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:message terminate="no">Warning in convert_var_type template: unrecognised variable type '<xsl:value-of select="$var_type"/>'</xsl:message>
- <xsl:value-of select="$var_type"/>
- </xsl:otherwise>
-</xsl:choose>
+ <xsl:param name="var_type"/>
+ <xsl:text>dom_</xsl:text>
+ <xsl:choose>
+ <xsl:when test="$var_type = 'Document'">
+ <xsl:text>document</xsl:text>
+ </xsl:when>
+ <xsl:when test="$var_type = 'DocumentType'">
+ <xsl:text>document_type</xsl:text>
+ </xsl:when>
+ <xsl:when test="$var_type = 'DOMString'">
+ <xsl:text>string</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message terminate="no">Warning in convert_var_type template: unrecognised variable type '<xsl:value-of select="$var_type"/>'</xsl:message>
+ <xsl:value-of select="$var_type"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="convert_attribute_name">
+ <xsl:param name="attribute_name"/>
+ <xsl:message><xsl:value-of select="$attribute_name"/></xsl:message>
+ <xsl:choose>
+ <xsl:when test="$attribute_name = 'nodeValue'">
+ <xsl:text>node_value</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- assume no conversion is needed -->
+ <xsl:text><xsl:value-of select="$attribute_name"/></xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!--
+stolen from test-to-java.xsl
+Prepends every line with asterisks, suitable for use in a block comment
+-->
+<xsl:template name="emit-description">
+ <xsl:param name="description"/>
+ <xsl:choose>
+ <xsl:when test="contains($description, '
')">
+ <xsl:variable name="preceding" select="substring-before($description, '
')"/>
+ <xsl:if test="string-length($preceding) > 0">
+ <xsl:text> * </xsl:text>
+ <xsl:value-of select="substring-before($description, '
')"/>
+<xsl:text>
+</xsl:text>
+ </xsl:if>
+ <xsl:variable name="following" select="substring-after($description, '
')"/>
+ <xsl:if test="string-length($following) > 0">
+ <xsl:call-template name="emit-description">
+ <xsl:with-param name="description" select="substring-after($description, '
')"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text> * </xsl:text>
+ <xsl:value-of select="$description"/>
+ <xsl:text>
+ </xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
</xsl:stylesheet>
16 years, 2 months
r3409 jshaw - in /trunk/dom: include/dom/core/node.h src/core/node.c
by netsurf@semichrome.net
Author: jshaw
Date: Sat Jul 14 11:31:00 2007
New Revision: 3409
URL: http://source.netsurf-browser.org?rev=3409&view=rev
Log:
Modify node value, type and name functions to match w3c spec
Modified:
trunk/dom/include/dom/core/node.h
trunk/dom/src/core/node.c
Modified: trunk/dom/include/dom/core/node.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/node.h?rev=3...
==============================================================================
--- trunk/dom/include/dom/core/node.h (original)
+++ trunk/dom/include/dom/core/node.h Sat Jul 14 11:31:00 2007
@@ -71,13 +71,13 @@
void dom_node_ref(struct dom_node *node);
void dom_node_unref(struct dom_node *node);
-dom_exception dom_node_get_name(struct dom_node *node,
+dom_exception dom_node_get_node_name(struct dom_node *node,
struct dom_string **result);
-dom_exception dom_node_get_value(struct dom_node *node,
+dom_exception dom_node_get_node_value(struct dom_node *node,
struct dom_string **result);
-dom_exception dom_node_set_value(struct dom_node *node,
+dom_exception dom_node_set_node_value(struct dom_node *node,
struct dom_string *value);
-dom_exception dom_node_get_type(struct dom_node *node,
+dom_exception dom_node_get_node_type(struct dom_node *node,
dom_node_type *result);
dom_exception dom_node_get_parent(struct dom_node *node,
struct dom_node **result);
Modified: trunk/dom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.c?rev=3409&r1=3...
==============================================================================
--- trunk/dom/src/core/node.c (original)
+++ trunk/dom/src/core/node.c Sat Jul 14 11:31:00 2007
@@ -104,7 +104,7 @@
* the responsibility of the caller to unref the string once it has
* finished with it.
*/
-dom_exception dom_node_get_name(struct dom_node *node,
+dom_exception dom_node_get_node_name(struct dom_node *node,
struct dom_string **result)
{
UNUSED(node);
@@ -127,7 +127,7 @@
* DOM3Core states that this can raise DOMSTRING_SIZE_ERR. It will not in
* this implementation; dom_strings are unbounded.
*/
-dom_exception dom_node_get_value(struct dom_node *node,
+dom_exception dom_node_get_node_value(struct dom_node *node,
struct dom_string **result)
{
UNUSED(node);
@@ -149,7 +149,7 @@
* should unref it after the call (as the caller should have already claimed
* a reference on the string). The node's existing value will be unrefed.
*/
-dom_exception dom_node_set_value(struct dom_node *node,
+dom_exception dom_node_set_node_value(struct dom_node *node,
struct dom_string *value)
{
UNUSED(node);
@@ -165,7 +165,7 @@
* \param result Pointer to location to receive node type
* \return DOM_NO_ERR.
*/
-dom_exception dom_node_get_type(struct dom_node *node, dom_node_type *result)
+dom_exception dom_node_get_node_type(struct dom_node *node, dom_node_type *result)
{
*result = node->type;
16 years, 2 months
r3408 tlsa - in /trunk/netsurf/!NetSurf/Docs: intro_de, faf intro_en, faf intro_fr, faf intro_nl, faf
by netsurf@semichrome.net
Author: tlsa
Date: Sat Jul 14 11:06:00 2007
New Revision: 3408
URL: http://source.netsurf-browser.org?rev=3408&view=rev
Log:
Update year.
Modified:
trunk/netsurf/!NetSurf/Docs/intro_de,faf
trunk/netsurf/!NetSurf/Docs/intro_en,faf
trunk/netsurf/!NetSurf/Docs/intro_fr,faf
trunk/netsurf/!NetSurf/Docs/intro_nl,faf
Modified: trunk/netsurf/!NetSurf/Docs/intro_de,faf
URL: http://source.netsurf-browser.org/trunk/netsurf/%21NetSurf/Docs/intro_de%...
==============================================================================
--- trunk/netsurf/!NetSurf/Docs/intro_de,faf (original)
+++ trunk/netsurf/!NetSurf/Docs/intro_de,faf Sat Jul 14 11:06:00 2007
@@ -68,7 +68,7 @@
</div>
-<p class="footer">NetSurf is copyright 2003 - 2006 The NetSurf
+<p class="footer">NetSurf is copyright 2003 - 2007 The NetSurf
Developers</p>
</body>
Modified: trunk/netsurf/!NetSurf/Docs/intro_en,faf
URL: http://source.netsurf-browser.org/trunk/netsurf/%21NetSurf/Docs/intro_en%...
==============================================================================
--- trunk/netsurf/!NetSurf/Docs/intro_en,faf (original)
+++ trunk/netsurf/!NetSurf/Docs/intro_en,faf Sat Jul 14 11:06:00 2007
@@ -83,7 +83,7 @@
</div>
-<p class="footer">NetSurf is copyright 2003 - 2006 The NetSurf
+<p class="footer">NetSurf is copyright 2003 - 2007 The NetSurf
Developers</p>
</body>
Modified: trunk/netsurf/!NetSurf/Docs/intro_fr,faf
URL: http://source.netsurf-browser.org/trunk/netsurf/%21NetSurf/Docs/intro_fr%...
==============================================================================
--- trunk/netsurf/!NetSurf/Docs/intro_fr,faf (original)
+++ trunk/netsurf/!NetSurf/Docs/intro_fr,faf Sat Jul 14 11:06:00 2007
@@ -70,7 +70,7 @@
</div>
-<p class="footer">NetSurf tout droit réservé 2003 - 2006 Les
+<p class="footer">NetSurf tout droit réservé 2003 - 2007 Les
développeurs de NetSurf</p>
</body>
Modified: trunk/netsurf/!NetSurf/Docs/intro_nl,faf
URL: http://source.netsurf-browser.org/trunk/netsurf/%21NetSurf/Docs/intro_nl%...
==============================================================================
--- trunk/netsurf/!NetSurf/Docs/intro_nl,faf (original)
+++ trunk/netsurf/!NetSurf/Docs/intro_nl,faf Sat Jul 14 11:06:00 2007
@@ -73,7 +73,7 @@
</div>
-<p class="footer"><em>NetSurf</em> valt onder copyrecht 2003 - 2006. De NetSurf-ontwikkelaars.</p>
+<p class="footer"><em>NetSurf</em> valt onder copyrecht 2003 - 2007. De NetSurf-ontwikkelaars.</p>
</body>
</html>
16 years, 2 months
r3407 jmb - in /trunk/netsurf/riscos: filetype.c gui.c
by netsurf@semichrome.net
Author: jmb
Date: Fri Jul 13 09:25:34 2007
New Revision: 3407
URL: http://source.netsurf-browser.org?rev=3407&view=rev
Log:
Support dataloading of SVG files
Add internal filetype<->mimetype mapping for SVG files
Modified:
trunk/netsurf/riscos/filetype.c
trunk/netsurf/riscos/gui.c
Modified: trunk/netsurf/riscos/filetype.c
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/filetype.c?rev=340...
==============================================================================
--- trunk/netsurf/riscos/filetype.c (original)
+++ trunk/netsurf/riscos/filetype.c Fri Jul 13 09:25:34 2007
@@ -27,6 +27,7 @@
{0x188, "application/x-shockwave-flash"},
{0x695, "image/gif"},
{0x69c, "image/x-ms-bmp"},
+ {0xaad, "image/svg+xml"},
{0xaff, "image/x-drawfile"},
{0xb60, "image/png"},
{0xc85, "image/jpeg"},
@@ -289,6 +290,8 @@
#ifdef WITH_ARTWORKS
case CONTENT_ARTWORKS: return 0xd94;
#endif
+ case CONTENT_SVG: return 0xaad;
+
default: break;
}
return 0;
Modified: trunk/netsurf/riscos/gui.c
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/gui.c?rev=3407&r1=...
==============================================================================
--- trunk/netsurf/riscos/gui.c (original)
+++ trunk/netsurf/riscos/gui.c Fri Jul 13 09:25:34 2007
@@ -126,6 +126,9 @@
#ifndef FILETYPE_ARTWORKS
#define FILETYPE_ARTWORKS 0xd94
#endif
+#ifndef FILETYPE_SVG
+#define FILETYPE_SVG 0xaad
+#endif
extern bool ro_plot_patterned_lines;
@@ -1467,6 +1470,7 @@
case osfile_TYPE_SPRITE:
case osfile_TYPE_TEXT:
case FILETYPE_ARTWORKS:
+ case FILETYPE_SVG:
/* display the actual file */
url = path_to_url(message->data.data_xfer.file_name);
break;
@@ -1760,7 +1764,8 @@
case FILETYPE_JPEG:
case osfile_TYPE_SPRITE:
case osfile_TYPE_TEXT:
- case FILETYPE_ARTWORKS: {
+ case FILETYPE_ARTWORKS:
+ case FILETYPE_SVG: {
os_error *error;
dataxfer->your_ref = dataxfer->my_ref;
16 years, 2 months
r3406 bursa - in /trunk/netsurf: content/content.c content/content.h content/content_type.h makefile
by netsurf@semichrome.net
Author: bursa
Date: Fri Jul 13 04:54:47 2007
New Revision: 3406
URL: http://source.netsurf-browser.org?rev=3406&view=rev
Log:
Add CONTENT_SVG to content handling.
Modified:
trunk/netsurf/content/content.c
trunk/netsurf/content/content.h
trunk/netsurf/content/content_type.h
trunk/netsurf/makefile
Modified: trunk/netsurf/content/content.c
URL: http://source.netsurf-browser.org/trunk/netsurf/content/content.c?rev=340...
==============================================================================
--- trunk/netsurf/content/content.c (original)
+++ trunk/netsurf/content/content.c Fri Jul 13 04:54:47 2007
@@ -43,6 +43,7 @@
#include "image/bmp.h"
#include "image/ico.h"
#endif
+#include "image/svg.h"
#ifdef WITH_SPRITE
#include "riscos/sprite.h"
#endif
@@ -133,6 +134,8 @@
#ifdef WITH_MNG
{"image/png", CONTENT_PNG},
#endif
+ {"image/svg", CONTENT_SVG},
+ {"image/svg+xml", CONTENT_SVG},
#ifdef WITH_BMP
{"image/x-bitmap", CONTENT_BMP},
{"image/x-bmp", CONTENT_BMP},
@@ -299,6 +302,8 @@
{0, 0, artworks_convert,
0, artworks_destroy, 0, artworks_redraw, 0, 0, 0, false},
#endif
+ {svg_create, 0, svg_convert,
+ 0, svg_destroy, 0, svg_redraw, 0, 0, 0, false},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false}
};
#define HANDLER_MAP_COUNT (sizeof(handler_map) / sizeof(handler_map[0]))
Modified: trunk/netsurf/content/content.h
URL: http://source.netsurf-browser.org/trunk/netsurf/content/content.h?rev=340...
==============================================================================
--- trunk/netsurf/content/content.h (original)
+++ trunk/netsurf/content/content.h Fri Jul 13 04:54:47 2007
@@ -46,6 +46,7 @@
#ifdef WITH_ARTWORKS
#include "riscos/artworks.h"
#endif
+#include "image/svg.h"
struct bitmap;
@@ -165,6 +166,7 @@
#ifdef WITH_ARTWORKS
struct content_artworks_data artworks;
#endif
+ struct content_svg_data svg;
} data;
/**< URL for refresh request, in standard form as from url_join. */
Modified: trunk/netsurf/content/content_type.h
URL: http://source.netsurf-browser.org/trunk/netsurf/content/content_type.h?re...
==============================================================================
--- trunk/netsurf/content/content_type.h (original)
+++ trunk/netsurf/content/content_type.h Fri Jul 13 04:54:47 2007
@@ -53,6 +53,7 @@
#ifdef WITH_ARTWORKS
CONTENT_ARTWORKS,
#endif
+ CONTENT_SVG,
/* these must be the last two */
CONTENT_OTHER,
CONTENT_UNKNOWN /**< content-type not received yet */
Modified: trunk/netsurf/makefile
URL: http://source.netsurf-browser.org/trunk/netsurf/makefile?rev=3406&r1=3405...
==============================================================================
--- trunk/netsurf/makefile (original)
+++ trunk/netsurf/makefile Fri Jul 13 04:54:47 2007
@@ -30,7 +30,7 @@
OBJECTS_COMMON += knockout.o options.o tree.o version.o # desktop/
OBJECTS_IMAGE = bmp.o bmpread.o gif.o gifread.o ico.o jpeg.o \
- mng.o # image/
+ mng.o svg.o # image/
OBJECTS_RISCOS = $(OBJECTS_COMMON) $(OBJECTS_IMAGE)
OBJECTS_RISCOS += browser.o frames.o history_core.o netsurf.o \
16 years, 2 months
r3405 bursa - in /trunk/netsurf/image: svg.c svg.h
by netsurf@semichrome.net
Author: bursa
Date: Fri Jul 13 04:53:14 2007
New Revision: 3405
URL: http://source.netsurf-browser.org?rev=3405&view=rev
Log:
Primitive SVG render (rect, text).
Added:
trunk/netsurf/image/svg.c
trunk/netsurf/image/svg.h
Added: trunk/netsurf/image/svg.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/svg.c?rev=3405&view...
==============================================================================
--- trunk/netsurf/image/svg.c (added)
+++ trunk/netsurf/image/svg.c Fri Jul 13 04:53:14 2007
@@ -1,0 +1,222 @@
+/*
+ * This file is part of NetSurf, http://netsurf-browser.org/
+ * Licensed under the GNU General Public License,
+ * http://www.opensource.org/licenses/gpl-license
+ * Copyright 2007 James Bursa <bursa(a)users.sourceforge.net>
+ */
+
+/** \file
+ * Content for image/svg (implementation).
+ */
+
+#include <assert.h>
+#include <setjmp.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxml/parser.h>
+#include <libxml/debugXML.h>
+#include "utils/config.h"
+#include "content/content.h"
+#include "desktop/plotters.h"
+#include "image/svg.h"
+#include "utils/log.h"
+#include "utils/messages.h"
+#include "utils/utils.h"
+
+
+static bool svg_redraw_svg(xmlNode *svg, int x, int y);
+static bool svg_redraw_rect(xmlNode *rect, int x, int y);
+static bool svg_redraw_text(xmlNode *text, int x, int y);
+
+
+/**
+ * Create a CONTENT_SVG.
+ */
+
+bool svg_create(struct content *c, const char *params[])
+{
+ c->data.svg.doc = 0;
+ c->data.svg.svg = 0;
+
+ return true;
+}
+
+
+/**
+ * Convert a CONTENT_SVG for display.
+ */
+
+bool svg_convert(struct content *c, int w, int h)
+{
+ xmlDoc *document;
+ xmlNode *svg;
+ union content_msg_data msg_data;
+
+ /* parse XML to tree */
+ document = xmlReadMemory(c->source_data, c->source_size,
+ c->url, 0, XML_PARSE_NONET | XML_PARSE_COMPACT);
+ if (!document) {
+ LOG(("xmlReadMemory failed"));
+ msg_data.error = messages_get("ParsingFail");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ }
+ c->data.svg.doc = document;
+
+ xmlDebugDumpDocument(stderr, document);
+
+ /* find root <svg> element */
+ for (svg = document->children;
+ svg && svg->type != XML_ELEMENT_NODE;
+ svg = svg->next)
+ continue;
+ if (!svg) {
+ LOG(("no element in svg"));
+ msg_data.error = "no element in svg";
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ }
+ if (strcmp(svg->name, "svg") != 0) {
+ LOG(("root element is not svg"));
+ msg_data.error = "root element is not svg";
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ }
+ c->data.svg.svg = svg;
+
+ /* get graphic dimensions */
+ xmlChar *width = xmlGetProp(svg, "width");
+ if (width) {
+ c->width = atoi(width);
+ xmlFree(width);
+ } else {
+ c->width = 100;
+ }
+
+ xmlChar *height = xmlGetProp(svg, "height");
+ if (height) {
+ c->height = atoi(height);
+ xmlFree(height);
+ } else {
+ c->height = 100;
+ }
+
+ /*c->title = malloc(100);
+ if (c->title)
+ snprintf(c->title, 100, messages_get("svgTitle"),
+ width, height, c->source_size);*/
+ //c->size += ?;
+ c->status = CONTENT_STATUS_DONE;
+ return true;
+}
+
+
+/**
+ * Redraw a CONTENT_SVG.
+ */
+
+bool svg_redraw(struct content *c, int x, int y,
+ int width, int height,
+ int clip_x0, int clip_y0, int clip_x1, int clip_y1,
+ float scale, unsigned long background_colour)
+{
+ assert(c->data.svg.svg);
+
+ return svg_redraw_svg(c->data.svg.svg, x, y);
+}
+
+
+/**
+ * Redraw a <svg> element node.
+ */
+
+bool svg_redraw_svg(xmlNode *svg, int x, int y)
+{
+ for (xmlNode *child = svg->children; child; child = child->next) {
+ bool ok = true;
+
+ if (child->type == XML_ELEMENT_NODE) {
+ if (strcmp(child->name, "svg") == 0)
+ ok = svg_redraw_svg(child, x, y);
+ else if (strcmp(child->name, "g") == 0)
+ ok = svg_redraw_svg(child, x, y);
+ else if (strcmp(child->name, "rect") == 0)
+ ok = svg_redraw_rect(child, x, y);
+ else if (strcmp(child->name, "text") == 0)
+ ok = svg_redraw_text(child, x, y);
+ }
+
+ if (!ok)
+ return false;
+ }
+
+ return true;
+}
+
+
+/**
+ * Redraw a <rect> element node.
+ */
+
+bool svg_redraw_rect(xmlNode *rect, int x, int y)
+{
+ int width = 0, height = 0;
+
+ for (xmlAttr *attr = rect->properties; attr; attr = attr->next) {
+ if (strcmp(attr->name, "x") == 0)
+ x += atoi(attr->children->content);
+ else if (strcmp(attr->name, "y") == 0)
+ y += atoi(attr->children->content);
+ else if (strcmp(attr->name, "width") == 0)
+ width = atoi(attr->children->content);
+ else if (strcmp(attr->name, "height") == 0)
+ height = atoi(attr->children->content);
+ }
+
+ return plot.rectangle(x, y, width, height, 5, 0x000000, false, false);
+}
+
+
+/**
+ * Redraw a <text> or <tspan> element node.
+ */
+
+bool svg_redraw_text(xmlNode *text, int x, int y)
+{
+ for (xmlAttr *attr = text->properties; attr; attr = attr->next) {
+ if (strcmp(attr->name, "x") == 0)
+ x += atoi(attr->children->content);
+ else if (strcmp(attr->name, "y") == 0)
+ y += atoi(attr->children->content);
+ }
+
+ for (xmlNode *child = text->children; child; child = child->next) {
+ bool ok = true;
+
+ if (child->type == XML_TEXT_NODE) {
+ ok = plot.text(x, y, &css_base_style,
+ child->content, strlen(child->content),
+ 0xffffff, 0x000000);
+ } else if (child->type == XML_ELEMENT_NODE &&
+ strcmp(child->name, "tspan") == 0) {
+ ok = svg_redraw_text(child, x, y);
+ }
+
+ if (!ok)
+ return false;
+ }
+
+ return true;
+}
+
+
+/**
+ * Destroy a CONTENT_SVG and free all resources it owns.
+ */
+
+void svg_destroy(struct content *c)
+{
+ if (c->data.svg.doc)
+ xmlFreeDoc(c->data.svg.doc);
+}
Added: trunk/netsurf/image/svg.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/svg.h?rev=3405&view...
==============================================================================
--- trunk/netsurf/image/svg.h (added)
+++ trunk/netsurf/image/svg.h Fri Jul 13 04:53:14 2007
@@ -1,0 +1,33 @@
+/*
+ * This file is part of NetSurf, http://netsurf-browser.org/
+ * Licensed under the GNU General Public License,
+ * http://www.opensource.org/licenses/gpl-license
+ * Copyright 2007 James Bursa <bursa(a)users.sourceforge.net>
+ */
+
+/** \file
+ * Content for image/svg (interface).
+ */
+
+#ifndef _NETSURF_IMAGE_SVG_H_
+#define _NETSURF_IMAGE_SVG_H_
+
+#include <stdbool.h>
+#include <libxml/parser.h>
+
+struct content;
+
+struct content_svg_data {
+ xmlDoc *doc;
+ xmlNode *svg;
+};
+
+bool svg_create(struct content *c, const char *params[]);
+bool svg_convert(struct content *c, int width, int height);
+void svg_destroy(struct content *c);
+bool svg_redraw(struct content *c, int x, int y,
+ int width, int height,
+ int clip_x0, int clip_y0, int clip_x1, int clip_y1,
+ float scale, unsigned long background_colour);
+
+#endif
16 years, 2 months
r3404 jmb - in /trunk/dom/src/core: document.c document.h namednodemap.c namednodemap.h
by netsurf@semichrome.net
Author: jmb
Date: Fri Jul 13 00:45:43 2007
New Revision: 3404
URL: http://source.netsurf-browser.org?rev=3404&view=rev
Log:
Make NamedNodeMap more generic
Modified:
trunk/dom/src/core/document.c
trunk/dom/src/core/document.h
trunk/dom/src/core/namednodemap.c
trunk/dom/src/core/namednodemap.h
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3404&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Fri Jul 13 00:45:43 2007
@@ -9,6 +9,7 @@
#include <dom/core/document.h>
#include "core/document.h"
+#include "core/namednodemap.h"
#include "core/node.h"
#include "core/nodelist.h"
#include "utils/utils.h"
@@ -866,8 +867,8 @@
* Get a namednodemap, creating one if necessary
*
* \param doc The document to get a namednodemap for
- * \param root Node containing items in map
- * \param type The type of map
+ * \param head Start of list containing items in map
+ * \param type The type of items in map
* \param map Pointer to location to receive map
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.
*
@@ -876,14 +877,14 @@
* finished with it.
*/
dom_exception dom_document_get_namednodemap(struct dom_document *doc,
- struct dom_node *root, dom_namednodemap_type type,
+ struct dom_node *head, dom_node_type type,
struct dom_namednodemap **map)
{
struct dom_doc_nnm *m;
dom_exception err;
for (m = doc->maps; m; m = m->next) {
- if (dom_namednodemap_match(m->map, root, type))
+ if (dom_namednodemap_match(m->map, head, type))
break;
}
@@ -899,7 +900,7 @@
return DOM_NO_MEM_ERR;
/* Create namednodemap */
- err = dom_namednodemap_create(doc, root, type, &m->map);
+ err = dom_namednodemap_create(doc, head, type, &m->map);
if (err != DOM_NO_ERR) {
doc->alloc(m, 0, doc->pw);
return err;
Modified: trunk/dom/src/core/document.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.h?rev=3404&...
==============================================================================
--- trunk/dom/src/core/document.h (original)
+++ trunk/dom/src/core/document.h Fri Jul 13 00:45:43 2007
@@ -11,7 +11,7 @@
#include <inttypes.h>
#include <stddef.h>
-#include "core/namednodemap.h"
+#include <dom/core/node.h>
struct dom_document;
struct dom_namednodemap;
@@ -36,7 +36,7 @@
/* Get a namednodemap, creating one if necessary */
dom_exception dom_document_get_namednodemap(struct dom_document *doc,
- struct dom_node *root, dom_namednodemap_type type,
+ struct dom_node *head, dom_node_type type,
struct dom_namednodemap **map);
/* Remove a namednodemap */
void dom_document_remove_namednodemap(struct dom_document *doc,
Modified: trunk/dom/src/core/namednodemap.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/namednodemap.c?rev=3...
==============================================================================
--- trunk/dom/src/core/namednodemap.c (original)
+++ trunk/dom/src/core/namednodemap.c Fri Jul 13 00:45:43 2007
@@ -18,9 +18,9 @@
struct dom_namednodemap {
struct dom_document *owner; /**< Owning document */
- struct dom_node *root; /**< Node containing items in map */
-
- dom_namednodemap_type type; /**< Type of map */
+ struct dom_node *head; /**< Start of item list */
+
+ dom_node_type type; /**< Type of items in map */
uint32_t refcnt; /**< Reference count */
};
@@ -29,24 +29,24 @@
* Create a namednodemap
*
* \param doc The owning document
- * \param root Node containing items in map
- * \param type The type of map
+ * \param head Start of list containing items in map
+ * \param type The type of items in the map
* \param map Pointer to location to receive created map
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
*
- * ::root must be a node owned by ::doc and must be either an Element or
+ * ::head must be a node owned by ::doc and must be either an Element or
* DocumentType node.
*
- * If ::root is of type Element, ::type must be DOM_NAMEDNODEMAP_ATTRIBUTES
- * If ::root is of type DocumentType, ::type may be either
- * DOM_NAMEDNODEMAP_ENTITIES or DOM_NAMEDNODEMAP_NOTATIONS.
+ * If ::head is of type Element, ::type must be DOM_ATTRIBUTE_NODE
+ * If ::head is of type DocumentType, ::type may be either
+ * DOM_ENTITY_NODE or DOM_NOTATION_NODE.
*
* The returned map will already be referenced, so the client need not
* explicitly reference it. The client must unref the map once it is
* finished with it.
*/
dom_exception dom_namednodemap_create(struct dom_document *doc,
- struct dom_node *root, dom_namednodemap_type type,
+ struct dom_node *head, dom_node_type type,
struct dom_namednodemap **map)
{
struct dom_namednodemap *m;
@@ -58,8 +58,8 @@
dom_node_ref((struct dom_node *) doc);
m->owner = doc;
- dom_node_ref(root);
- m->root = root;
+ dom_node_ref(head);
+ m->head = head;
m->type = type;
@@ -93,7 +93,7 @@
if (--map->refcnt == 0) {
struct dom_node *owner = (struct dom_node *) map->owner;
- dom_node_unref(map->root);
+ dom_node_unref(map->head);
/* Remove map from document */
dom_document_remove_namednodemap(map->owner, map);
@@ -330,15 +330,15 @@
/**
* Match a namednodemap instance against a set of creation parameters
*
- * \param map The map to match
- * \param root Node containing items in map
- * \param type The type of map
+ * \param map The map to match
+ * \param head Start of list containing items in map
+ * \param type The type of items in the map
* \return true if list matches, false otherwise
*/
bool dom_namednodemap_match(struct dom_namednodemap *map,
- struct dom_node *root, dom_namednodemap_type type)
-{
- if (map->root == root && map->type == type)
+ struct dom_node *head, dom_node_type type)
+{
+ if (map->head == head && map->type == type)
return true;
return false;
Modified: trunk/dom/src/core/namednodemap.h
URL: http://source.netsurf-browser.org/trunk/dom/src/core/namednodemap.h?rev=3...
==============================================================================
--- trunk/dom/src/core/namednodemap.h (original)
+++ trunk/dom/src/core/namednodemap.h Fri Jul 13 00:45:43 2007
@@ -11,29 +11,21 @@
#include <stdbool.h>
#include <dom/core/namednodemap.h>
+#include <dom/core/node.h>
struct dom_document;
struct dom_node;
struct dom_namednodemap;
struct dom_string;
-/**
- * Type of a named node map
- */
-typedef enum {
- DOM_NAMEDNODEMAP_ATTRIBUTES,
- DOM_NAMEDNODEMAP_ENTITIES,
- DOM_NAMEDNODEMAP_NOTATIONS
-} dom_namednodemap_type;
-
/* Create a namednodemap */
dom_exception dom_namednodemap_create(struct dom_document *doc,
- struct dom_node *root, dom_namednodemap_type type,
+ struct dom_node *head, dom_node_type type,
struct dom_namednodemap **map);
/* Match a namednodemap instance against a set of creation parameters */
bool dom_namednodemap_match(struct dom_namednodemap *map,
- struct dom_node *root, dom_namednodemap_type type);
+ struct dom_node *head, dom_node_type type);
#endif
16 years, 2 months
r3403 jmb - in /trunk/dom: include/dom/bootstrap/ include/dom/core/ src/ src/bootstrap/ src/core/
by netsurf@semichrome.net
Author: jmb
Date: Thu Jul 12 22:24:08 2007
New Revision: 3403
URL: http://source.netsurf-browser.org?rev=3403&view=rev
Log:
Add DOMImplementation, DOMImplementationList
Add DOMImplementationRegistry
Define DOMImplementationSource and provide API to allow their registration
This little lot should permit some kind of sensible DOM bootstrapping.
Added:
trunk/dom/include/dom/bootstrap/
trunk/dom/include/dom/bootstrap/implpriv.h
trunk/dom/include/dom/bootstrap/implregistry.h
trunk/dom/include/dom/core/implementation.h
trunk/dom/include/dom/core/impllist.h
trunk/dom/src/bootstrap/
trunk/dom/src/bootstrap/Makefile
trunk/dom/src/bootstrap/implregistry.c
trunk/dom/src/core/implementation.c
trunk/dom/src/core/impllist.c
Modified:
trunk/dom/src/Makefile
trunk/dom/src/core/Makefile
Added: trunk/dom/include/dom/bootstrap/implpriv.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/implpri...
==============================================================================
--- trunk/dom/include/dom/bootstrap/implpriv.h (added)
+++ trunk/dom/include/dom/bootstrap/implpriv.h Thu Jul 12 22:24:08 2007
@@ -1,0 +1,244 @@
+/*
+ * 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>
+ */
+
+/** \file
+ * This file defines all the grubby details that implementation backends
+ * need to know in order to permit themselves to be bootstrapped.
+ *
+ * The DOMImplementation and DOMImplementationList implementations also
+ * include this, as those types are defined here.
+ *
+ * No other client should be including this.
+ */
+
+#ifndef dom_bootstrap_implpriv_h_
+#define dom_bootstrap_implpriv_h_
+
+#include <inttypes.h>
+#include <stdbool.h>
+
+#include <dom/core/exceptions.h>
+#include <dom/functypes.h>
+
+struct dom_document;
+struct dom_document_type;
+struct dom_string;
+
+/**
+ * DOM Implementation
+ */
+struct dom_implementation {
+ /**
+ * Test whether a DOM implementation implements a specific feature
+ * and version
+ *
+ * \param impl The DOM implementation to query
+ * \param feature The feature to test for
+ * \param version The version number of the feature to test for
+ * \param result Pointer to location to receive result
+ * \return DOM_NO_ERR.
+ */
+ dom_exception (*has_feature)(struct dom_implementation *impl,
+ struct dom_string *feature,
+ struct dom_string *version,
+ bool *result);
+
+ /**
+ * Create a document type node
+ *
+ * \param impl The implementation to create the node
+ * \param qname The qualified name of the document type
+ * \param public_id The external subset public identifier
+ * \param system_id The external subset system identifier
+ * \param doctype Pointer to location to receive result
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR on success,
+ * DOM_INVALID_CHARACTER_ERR if ::qname is invalid,
+ * DOM_NAMESPACE_ERR if ::qname is malformed,
+ * DOM_NOT_SUPPORTED_ERR if ::impl does not support the
+ * feature "XML" and the language
+ * exposed through Document does
+ * not support XML namespaces.
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function.
+ *
+ * The doctype will be referenced, so the client need not do this
+ * explicitly. The client must unref the doctype once it has
+ * finished with it.
+ */
+ dom_exception (*create_document_type)(
+ struct dom_implementation *impl,
+ struct dom_string *qname,
+ struct dom_string *public_id,
+ struct dom_string *system_id,
+ struct dom_document_type **doctype,
+ dom_alloc alloc, void *pw);
+
+ /**
+ * Create a document node
+ *
+ * \param impl The implementation to create the node
+ * \param namespace The namespace URI of the document element
+ * \param qname The qualified name of the document element
+ * \param doctype The type of document to create
+ * \param doc Pointer to location to receive result
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR on success,
+ * DOM_INVALID_CHARACTER_ERR if ::qname is invalid,
+ * DOM_NAMESPACE_ERR if ::qname is malformed, or if
+ * ::qname has a prefix and
+ * ::namespace is NULL, or if
+ * ::qname is NULL and ::namespace
+ * is non-NULL, or if ::qname has
+ * a prefix "xml" and ::namespace
+ * is not
+ * "http://www.w3.org/XML/1998/namespace",
+ * or if ::impl does not support
+ * the "XML" feature and
+ * ::namespace is non-NULL,
+ * DOM_WRONG_DOCUMENT_ERR if ::doctype is already being
+ * used by a document, or if it
+ * was not created by ::impl,
+ * DOM_NOT_SUPPORTED_ERR if ::impl does not support the
+ * feature "XML" and the language
+ * exposed through Document does
+ * not support XML namespaces.
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function.
+ *
+ * The doctype will be referenced, so the client need not do this
+ * explicitly. The client must unref the doctype once it has
+ * finished with it.
+ */
+ dom_exception (*create_document)(struct dom_implementation *impl,
+ struct dom_string *namespace,
+ struct dom_string *qname,
+ struct dom_document_type *doctype,
+ struct dom_document **doc,
+ dom_alloc alloc, void *pw);
+
+ /**
+ * Retrieve a specialized object which implements the specified
+ * feature and version
+ *
+ * \param impl The implementation to create the object
+ * \param feature The requested feature
+ * \param version The version number of the feature
+ * \param object Pointer to location to receive object
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR.
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function.
+ */
+ dom_exception (*get_feature)(struct dom_implementation *impl,
+ struct dom_string *feature,
+ struct dom_string *version,
+ void **object,
+ dom_alloc alloc, void *pw);
+
+ /**
+ * Destroy a DOM implementation instance
+ *
+ * \param impl The instance to destroy
+ */
+ void (*destroy)(struct dom_implementation *impl);
+
+ uint32_t refcnt; /**< Reference count */
+};
+
+
+/**
+ * An item in a DOM Implementation List
+ */
+struct dom_implementation_list_item {
+ struct dom_implementation *impl; /**< Implementation */
+
+ struct dom_implementation_list_item *next; /**< Next in list */
+ struct dom_implementation_list_item *prev; /**< Prev in list */
+};
+
+/**
+ * DOM Implementation List
+ */
+struct dom_implementation_list {
+ struct dom_implementation_list_item *head; /**< Head of list */
+
+ dom_alloc alloc; /**< Memory (de)allocation function */
+ void *pw; /**< Pointer to client data */
+
+ uint32_t refcnt; /**< Reference count */
+};
+
+
+/**
+ * DOM Implementation Source
+ *
+ * This is simply a pair of function pointers in a struct.
+ *
+ * This is assumed to be statically allocated within the backend.
+ */
+struct dom_implementation_source {
+ /**
+ * Get a DOM implementation that supports the requested features
+ *
+ * \param features String containing required features
+ * \param impl Pointer to location to receive implementation
+ * \param alloc Function to (de)allocate memory
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function. The implementation's
+ * destroy() method will be called once it is no longer used.
+ *
+ * The implementation will be referenced, so the client need not
+ * do this explicitly. The client must unref the implementation
+ * once it has finished with it.
+ */
+ dom_exception (*get_dom_implementation)(
+ struct dom_string *features,
+ struct dom_implementation **impl,
+ dom_alloc alloc, void *pw);
+
+ /**
+ * Get a list of DOM implementations that support the requested
+ * features
+ *
+ * \param features String containing required features
+ * \param list Pointer to location to receive list
+ * \param alloc Function to (de)allocate memory
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function. The ::alloc/::pw
+ * pair must be stored on the list object, such that the list
+ * and its contents may be freed once they are no longer needed.
+ *
+ * List nodes reference the implementation objects they point to.
+ *
+ * The list will be referenced, so the client need not do this
+ * explicitly. The client must unref the list once it has finished
+ * with it.
+ */
+ dom_exception (*get_dom_implementation_list)(
+ struct dom_string *features,
+ struct dom_implementation_list **list,
+ dom_alloc alloc, void *pw);
+};
+
+/* Register a source with the DOM library */
+dom_exception dom_register_source(struct dom_implementation_source *source,
+ dom_alloc alloc, void *pw);
+
+#endif
Added: trunk/dom/include/dom/bootstrap/implregistry.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/implreg...
==============================================================================
--- trunk/dom/include/dom/bootstrap/implregistry.h (added)
+++ trunk/dom/include/dom/bootstrap/implregistry.h Thu Jul 12 22:24:08 2007
@@ -1,0 +1,30 @@
+/*
+ * 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_bootstrap_implregistry_h_
+#define dom_bootstrap_implregistry_h_
+
+#include <dom/core/exceptions.h>
+#include <dom/functypes.h>
+
+struct dom_implementation;
+struct dom_implementation_list;
+struct dom_string;
+
+/* Retrieve a DOM implementation from the registry */
+dom_exception dom_implregistry_get_dom_implementation(
+ struct dom_string *features,
+ struct dom_implementation **impl,
+ dom_alloc alloc, void *pw);
+
+/* Get a list of DOM implementations that support the requested features */
+dom_exception dom_implregistry_get_dom_implementation_list(
+ struct dom_string *features,
+ struct dom_implementation_list **list,
+ dom_alloc alloc, void *pw);
+
+#endif
Added: trunk/dom/include/dom/core/implementation.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/implementati...
==============================================================================
--- trunk/dom/include/dom/core/implementation.h (added)
+++ trunk/dom/include/dom/core/implementation.h Thu Jul 12 22:24:08 2007
@@ -1,0 +1,48 @@
+/*
+ * 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_core_implementation_h_
+#define dom_core_implementation_h_
+
+#include <stdbool.h>
+
+#include <dom/core/exceptions.h>
+#include <dom/functypes.h>
+
+struct dom_document;
+struct dom_document_type;
+struct dom_implementation;
+struct dom_string;
+
+void dom_implementation_ref(struct dom_implementation *impl);
+void dom_implementation_unref(struct dom_implementation *impl);
+
+dom_exception dom_implementation_has_feature(
+ struct dom_implementation *impl,
+ struct dom_string *feature, struct dom_string *version,
+ bool *result);
+
+dom_exception dom_implementation_create_document_type(
+ struct dom_implementation *impl, struct dom_string *qname,
+ struct dom_string *public_id, struct dom_string *system_id,
+ struct dom_document_type **doctype,
+ dom_alloc alloc, void *pw);
+
+dom_exception dom_implementation_create_document(
+ struct dom_implementation *impl,
+ struct dom_string *namespace, struct dom_string *qname,
+ struct dom_document_type *doctype,
+ struct dom_document **doc,
+ dom_alloc alloc, void *pw);
+
+dom_exception dom_implementation_get_feature(
+ struct dom_implementation *impl,
+ struct dom_string *feature, struct dom_string *version,
+ void **object,
+ dom_alloc alloc, void *pw);
+
+#endif
Added: trunk/dom/include/dom/core/impllist.h
URL: http://source.netsurf-browser.org/trunk/dom/include/dom/core/impllist.h?r...
==============================================================================
--- trunk/dom/include/dom/core/impllist.h (added)
+++ trunk/dom/include/dom/core/impllist.h Thu Jul 12 22:24:08 2007
@@ -1,0 +1,26 @@
+/*
+ * 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_core_impllist_h_
+#define dom_core_impllist_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_implementation;
+struct dom_implementation_list;
+
+void dom_implementation_list_ref(struct dom_implementation_list *list);
+void dom_implementation_list_unref(struct dom_implementation_list *list);
+
+dom_exception dom_implementation_list_get_length(
+ struct dom_implementation_list *list, unsigned long *length);
+
+dom_exception dom_implementation_list_item(
+ struct dom_implementation_list *list, unsigned long index,
+ struct dom_implementation **impl);
+
+#endif
Modified: trunk/dom/src/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/src/Makefile?rev=3403&r1=3402...
==============================================================================
--- trunk/dom/src/Makefile (original)
+++ trunk/dom/src/Makefile Thu Jul 12 22:24:08 2007
@@ -34,14 +34,17 @@
# Targets
release: $(addprefix Release/, $(addsuffix .o, $(OBJS)))
+ @${MAKE} -C bootstrap release
@${MAKE} -C core release
@${AR} ${ARFLAGS} $(RELEASE) Release/*
debug: $(addprefix Debug/, $(addsuffix .o, $(OBJS)))
+ @${MAKE} -C bootstrap debug
@${MAKE} -C core debug
@${AR} ${ARFLAGS} $(DEBUG) Debug/*
clean:
+ @${MAKE} -C bootstrap clean
@${MAKE} -C core clean
ifneq (${OBJS}, )
-@${RM} ${RMFLAGS} $(addprefix Release/, $(addsuffix .o, ${OBJS}))
Added: trunk/dom/src/bootstrap/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/src/bootstrap/Makefile?rev=34...
==============================================================================
--- trunk/dom/src/bootstrap/Makefile (added)
+++ trunk/dom/src/bootstrap/Makefile Thu Jul 12 22:24:08 2007
@@ -1,0 +1,53 @@
+# 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
+CFLAGS += -I$(CURDIR)
+
+# Objects
+OBJS = implregistry
+
+.PHONY: clean debug distclean export release setup test
+
+# Targets
+release: $(addprefix ../Release/, $(addsuffix .o, $(OBJS)))
+
+debug: $(addprefix ../Debug/, $(addsuffix .o, $(OBJS)))
+
+clean:
+ -@${RM} ${RMFLAGS} $(addprefix ../Release/, $(addsuffix .o, ${OBJS}))
+ -@${RM} ${RMFLAGS} $(addprefix ../Debug/, $(addsuffix .o, ${OBJS}))
+
+distclean:
+
+setup:
+
+export:
+
+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/src/bootstrap/implregistry.c
URL: http://source.netsurf-browser.org/trunk/dom/src/bootstrap/implregistry.c?...
==============================================================================
--- trunk/dom/src/bootstrap/implregistry.c (added)
+++ trunk/dom/src/bootstrap/implregistry.c Thu Jul 12 22:24:08 2007
@@ -1,0 +1,184 @@
+/*
+ * 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 <stddef.h>
+
+#include <dom/bootstrap/implpriv.h>
+#include <dom/bootstrap/implregistry.h>
+
+#include <dom/core/impllist.h>
+
+/**
+ * Item in list of registered DOM implementation sources
+ */
+struct dom_impl_src_item {
+ struct dom_implementation_source *source; /**< Source */
+
+ struct dom_impl_src_item *next; /**< Next in list */
+ struct dom_impl_src_item *prev; /**< Previous in list */
+};
+
+static struct dom_impl_src_item *sources; /**< List of registered sources */
+
+/**
+ * Retrieve a DOM implementation from the registry
+ *
+ * \param features String containing required features
+ * \param impl Pointer to location to receive implementation
+ * \param alloc Function to (de)allocate memory
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function. The implementation's
+ * destroy() method will be called once it is no longer used.
+ *
+ * The implementation will be referenced, so the client need not
+ * do this explicitly. The client must unref the implementation
+ * once it has finished with it.
+ */
+dom_exception dom_implregistry_get_dom_implementation(
+ struct dom_string *features,
+ struct dom_implementation **impl,
+ dom_alloc alloc, void *pw)
+{
+ struct dom_impl_src_item *item;
+ struct dom_implementation *found = NULL;
+ dom_exception err;
+
+ for (item = sources; item; item = item->next) {
+ err = item->source->get_dom_implementation(features, &found,
+ alloc, pw);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ if (found != NULL)
+ break;
+ }
+
+ *impl = found;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get a list of DOM implementations that support the requested
+ * features
+ *
+ * \param features String containing required features
+ * \param list Pointer to location to receive list
+ * \param alloc Function to (de)allocate memory
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function. The ::alloc/::pw
+ * pair must be stored on the list object, such that the list
+ * and its contents may be freed once they are no longer needed.
+ *
+ * List nodes reference the implementation objects they point to.
+ *
+ * The list will be referenced, so the client need not do this
+ * explicitly. The client must unref the list once it has finished
+ * with it.
+ */
+dom_exception dom_implregistry_get_dom_implementation_list(
+ struct dom_string *features,
+ struct dom_implementation_list **list,
+ dom_alloc alloc, void *pw)
+{
+ struct dom_implementation_list *l;
+ struct dom_impl_src_item *item;
+ dom_exception err;
+
+ l = alloc(NULL, sizeof(struct dom_implementation_list), pw);
+ if (l == NULL)
+ return DOM_NO_MEM_ERR;
+
+ l->head = NULL;
+ l->alloc = alloc;
+ l->pw = pw;
+ l->refcnt = 1;
+
+ for (item = sources; item; item = item->next) {
+ struct dom_implementation_list *plist = NULL;
+ struct dom_implementation_list_item *plast = NULL;
+
+ err = item->source->get_dom_implementation_list(features,
+ &plist, alloc, pw);
+ if (err != DOM_NO_ERR) {
+ dom_implementation_list_unref(l);
+ return err;
+ }
+
+ if (plist == NULL)
+ continue;
+
+ if (plist->head == NULL) {
+ dom_implementation_list_unref(plist);
+ continue;
+ }
+
+ /* Get last item in list for this source */
+ for (plast = plist->head; plast; plast = plast->next) {
+ if (plast->next == NULL)
+ break;
+ }
+
+ /* Prepend list for this source onto result list */
+ plast->next = l->head;
+ if (l->head != NULL)
+ l->head->prev = plast;
+ l->head = plist->head;
+
+ /* Invalidate entire content of list for this source */
+ plist->head = NULL;
+
+ /* And unref it */
+ dom_implementation_list_unref(plist);
+ }
+
+ if (l->head == NULL) {
+ *list = NULL;
+ dom_implementation_list_unref(l);
+ } else {
+ *list = l;
+ }
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Register a DOM implementation source with the DOM library
+ *
+ * \param source The implementation source to register
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.
+ */
+dom_exception dom_register_source(struct dom_implementation_source *source,
+ dom_alloc alloc, void *pw)
+{
+ struct dom_impl_src_item *item;
+
+ item = alloc(NULL, sizeof(struct dom_impl_src_item), pw);
+ if (item == NULL)
+ return DOM_NO_MEM_ERR;
+
+ item->source = source;
+
+ item->next = sources;
+ item->prev = NULL;
+
+ if (sources != NULL)
+ sources->prev = item;
+
+ sources = item;
+
+ return DOM_NO_ERR;
+}
+
Modified: trunk/dom/src/core/Makefile
URL: http://source.netsurf-browser.org/trunk/dom/src/core/Makefile?rev=3403&r1...
==============================================================================
--- trunk/dom/src/core/Makefile (original)
+++ trunk/dom/src/core/Makefile Thu Jul 12 22:24:08 2007
@@ -22,8 +22,8 @@
CFLAGS += -I$(CURDIR)
# Objects
-OBJS = attr characterdata document element namednodemap node nodelist \
- string text
+OBJS = attr characterdata document element implementation impllist \
+ namednodemap node nodelist string text
.PHONY: clean debug distclean export release setup test
Added: trunk/dom/src/core/implementation.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/implementation.c?rev...
==============================================================================
--- trunk/dom/src/core/implementation.c (added)
+++ trunk/dom/src/core/implementation.c Thu Jul 12 22:24:08 2007
@@ -1,0 +1,157 @@
+/*
+ * 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 <dom/bootstrap/implpriv.h>
+#include <dom/core/implementation.h>
+
+/**
+ * Claim a reference on a DOM implementation
+ *
+ * \param impl The implementation to claim a reference on
+ */
+void dom_implementation_ref(struct dom_implementation *impl)
+{
+ impl->refcnt++;
+}
+
+/**
+ * Release a reference from a DOM implementation
+ *
+ * \param impl The implementation to release the reference from
+ *
+ * If the reference count reaches zero, any memory claimed by the
+ * implementation will be released
+ */
+void dom_implementation_unref(struct dom_implementation *impl)
+{
+ if (--impl->refcnt == 0) {
+ impl->destroy(impl);
+ }
+}
+
+/**
+ * Test whether a DOM implementation implements a specific feature
+ * and version
+ *
+ * \param impl The DOM implementation to query
+ * \param feature The feature to test for
+ * \param version The version number of the feature to test for
+ * \param result Pointer to location to receive result
+ * \return DOM_NO_ERR.
+ */
+dom_exception dom_implementation_has_feature(
+ struct dom_implementation *impl,
+ struct dom_string *feature, struct dom_string *version,
+ bool *result)
+{
+ return impl->has_feature(impl, feature, version, result);
+}
+
+/**
+ * Create a document type node
+ *
+ * \param impl The implementation to create the node
+ * \param qname The qualified name of the document type
+ * \param public_id The external subset public identifier
+ * \param system_id The external subset system identifier
+ * \param doctype Pointer to location to receive result
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR on success,
+ * DOM_INVALID_CHARACTER_ERR if ::qname is invalid,
+ * DOM_NAMESPACE_ERR if ::qname is malformed,
+ * DOM_NOT_SUPPORTED_ERR if ::impl does not support the feature
+ * "XML" and the language exposed through
+ * Document does not support XML
+ * namespaces.
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function.
+ *
+ * The doctype will be referenced, so the client need not do this
+ * explicitly. The client must unref the doctype once it has
+ * finished with it.
+ */
+dom_exception dom_implementation_create_document_type(
+ struct dom_implementation *impl, struct dom_string *qname,
+ struct dom_string *public_id, struct dom_string *system_id,
+ struct dom_document_type **doctype,
+ dom_alloc alloc, void *pw)
+{
+ return impl->create_document_type(impl, qname, public_id, system_id,
+ doctype, alloc, pw);
+}
+
+/**
+ * Create a document node
+ *
+ * \param impl The implementation to create the node
+ * \param namespace The namespace URI of the document element
+ * \param qname The qualified name of the document element
+ * \param doctype The type of document to create
+ * \param doc Pointer to location to receive result
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR on success,
+ * DOM_INVALID_CHARACTER_ERR if ::qname is invalid,
+ * DOM_NAMESPACE_ERR if ::qname is malformed, or if ::qname
+ * has a prefix and ::namespace is NULL,
+ * or if ::qname is NULL and ::namespace
+ * is non-NULL, or if ::qname has a prefix
+ * "xml" and ::namespace is not
+ * "http://www.w3.org/XML/1998/namespace",
+ * or if ::impl does not support the "XML"
+ * feature and ::namespace is non-NULL,
+ * DOM_WRONG_DOCUMENT_ERR if ::doctype is already being used by a
+ * document, or if it was not created by
+ * ::impl,
+ * DOM_NOT_SUPPORTED_ERR if ::impl does not support the feature
+ * "XML" and the language exposed through
+ * Document does not support XML
+ * namespaces.
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function.
+ *
+ * The doctype will be referenced, so the client need not do this
+ * explicitly. The client must unref the doctype once it has
+ * finished with it.
+ */
+dom_exception dom_implementation_create_document(
+ struct dom_implementation *impl,
+ struct dom_string *namespace, struct dom_string *qname,
+ struct dom_document_type *doctype,
+ struct dom_document **doc,
+ dom_alloc alloc, void *pw)
+{
+ return impl->create_document(impl, namespace, qname, doctype, doc,
+ alloc, pw);
+}
+
+/**
+ * Retrieve a specialized object which implements the specified
+ * feature and version
+ *
+ * \param impl The implementation to create the object
+ * \param feature The requested feature
+ * \param version The version number of the feature
+ * \param object Pointer to location to receive object
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \return DOM_NO_ERR.
+ *
+ * Any memory allocated by this call should be allocated using
+ * the provided memory (de)allocation function.
+ */
+dom_exception dom_implementation_get_feature(
+ struct dom_implementation *impl,
+ struct dom_string *feature, struct dom_string *version,
+ void **object,
+ dom_alloc alloc, void *pw)
+{
+ return impl->get_feature(impl, feature, version, object, alloc, pw);
+}
Added: trunk/dom/src/core/impllist.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/impllist.c?rev=3403&...
==============================================================================
--- trunk/dom/src/core/impllist.c (added)
+++ trunk/dom/src/core/impllist.c Thu Jul 12 22:24:08 2007
@@ -1,0 +1,108 @@
+/*
+ * 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 <dom/bootstrap/implpriv.h>
+#include <dom/core/implementation.h>
+#include <dom/core/impllist.h>
+
+/**
+ * Claim a reference on a DOM implementation list
+ *
+ * \param list The list to claim a reference on
+ */
+void dom_implementation_list_ref(struct dom_implementation_list *list)
+{
+ list->refcnt++;
+}
+
+/**
+ * Release a reference from a DOM implementation list
+ *
+ * \param list The list to release the reference from
+ *
+ * If the reference count reaches zero, any memory claimed by the
+ * list will be released
+ */
+void dom_implementation_list_unref(struct dom_implementation_list *list)
+{
+ struct dom_implementation_list_item *i, *j;
+
+ if (--list->refcnt == 0) {
+ /* Destroy all list entries */
+ for (i = list->head; i; i = j) {
+ j = i->next;
+
+ /* Unreference the implementation */
+ dom_implementation_unref(i->impl);
+
+ /* And free the entry */
+ list->alloc(i, 0, list->pw);
+ }
+
+ /* Free the list object */
+ list->alloc(list, 0, list->pw);
+ }
+}
+
+/**
+ * Retrieve the length of a DOM implementation list
+ *
+ * \param list The list to retrieve the length of
+ * \param length Pointer to location to receive result
+ * \return DOM_NO_ERR.
+ */
+dom_exception dom_implementation_list_get_length(
+ struct dom_implementation_list *list, unsigned long *length)
+{
+ unsigned long count = 0;
+ struct dom_implementation_list_item *i;
+
+ for (i = list->head; i; i = i->next)
+ count++;
+
+ *length = count;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Retrieve an item by index from a DOM implementation list
+ *
+ * \param list The list to retrieve the item from
+ * \param index The list index to retrieve
+ * \param impl Pointer to location to receive result
+ * \return DOM_NO_ERR.
+ *
+ * ::index is a zero-based index into ::list.
+ * ::index lies in the range [0, length-1]
+ *
+ * The returned implementation will have had its reference count increased.
+ * The client should unref the implementation once it has finished with it.
+ */
+dom_exception dom_implementation_list_item(
+ struct dom_implementation_list *list, unsigned long index,
+ struct dom_implementation **impl)
+{
+ unsigned long idx = 0;
+ struct dom_implementation_list_item *i;
+
+ for (i = list->head; i; i = i->next) {
+ if (idx == index)
+ break;
+
+ idx++;
+ }
+
+ if (i == NULL) {
+ *impl = NULL;
+ } else {
+ dom_implementation_ref(i->impl);
+ *impl = i->impl;
+ }
+
+ return DOM_NO_ERR;
+}
16 years, 2 months
r3401 jshaw - /trunk/dom/test/test-to-c.xsl
by netsurf@semichrome.net
Author: jshaw
Date: Wed Jul 11 21:48:49 2007
New Revision: 3401
URL: http://source.netsurf-browser.org?rev=3401&view=rev
Log:
Initial revision of test-to-c transformer
Added:
trunk/dom/test/test-to-c.xsl
Added: trunk/dom/test/test-to-c.xsl
URL: http://source.netsurf-browser.org/trunk/dom/test/test-to-c.xsl?rev=3401&v...
==============================================================================
--- trunk/dom/test/test-to-c.xsl (added)
+++ trunk/dom/test/test-to-c.xsl Wed Jul 11 21:48:49 2007
@@ -1,0 +1,95 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+This transform generates C source code from a language independent
+test representation.
+-->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:str="http://exslt.org/strings"><!-- TODO: exslt not currently used -->
+ <!-- relative to transform -->
+ <xsl:param name="interfaces-docname">../build/dom1-interfaces.xml</xsl:param>
+ <xsl:param name="target-uri-base">http://www.w3.org/2001/DOM-Test-Suite/tests/Level-1/</xsl:param>
+<xsl:output method="text" encoding="UTF-8"/>
+<xsl:variable name="domspec" select="document($interfaces-docname)"/>
+
+<!-- swallow any text which we don't understand -->
+<xsl:template match="text()"/>
+
+<xsl:template match="/">
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="*[local-name() = 'test']">
+<xsl:text>
+int main(int argc, char **argv) {
+</xsl:text>
+<xsl:apply-templates/>
+<xsl:text>
+ return 0;
+}
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="*[local-name() = 'var']">
+<xsl:text> struct </xsl:text><xsl:call-template name="convert_var_type"> <xsl:with-param name="var_type" select="@type"/>
+</xsl:call-template> *<xsl:value-of select="@name"/>;
+</xsl:template>
+
+<xsl:template match="*[local-name() = 'if']">
+<xsl:text> if (</xsl:text><!-- TODO: condition --><xsl:text>) {
+</xsl:text>
+<!-- TODO: statement(s) -->
+<xsl:text>
+ }</xsl:text>
+<xsl:for-each select="*[local-name() = 'else']">
+ <xsl:text> else {
+ </xsl:text>
+ <xsl:apply-templates/>
+ <xsl:text>}</xsl:text>
+</xsl:for-each>
+<xsl:text>
+</xsl:text>
+</xsl:template>
+
+<!--
+================================
+Assert templates
+================================
+-->
+
+<xsl:template match="*[local-name() = 'assertNotNull']">
+ <!-- TODO: what does the @id string do, and do we need it here? -->
+ <xsl:text> assert(</xsl:text><xsl:value-of select="@actual"/><xsl:text> != NULL);
+</xsl:text>
+</xsl:template>
+
+<xsl:template match="*[local-name() = 'assertNull']">
+ <!-- TODO: what does the @id string do, and do we need it here? -->
+ <xsl:text> assert(</xsl:text><xsl:value-of select="@actual"/><xsl:text> == NULL);
+ </xsl:text>
+</xsl:template>
+
+<!-- helper templates -->
+
+<xsl:template name="convert_var_type">
+<!-- TODO: convert certain types, e.g. from DocumentType to dom_document_type -->
+<xsl:param name="var_type"/>
+<xsl:text>dom_</xsl:text><xsl:choose>
+ <xsl:when test="$var_type = 'Document'">
+ <xsl:text>document</xsl:text>
+ </xsl:when>
+ <xsl:when test="$var_type = 'DocumentType'">
+ <xsl:text>document_type</xsl:text>
+ </xsl:when>
+ <xsl:when test="$var_type = 'DOMString'">
+ <xsl:text>string</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message terminate="no">Warning in convert_var_type template: unrecognised variable type '<xsl:value-of select="$var_type"/>'</xsl:message>
+ <xsl:value-of select="$var_type"/>
+ </xsl:otherwise>
+</xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
16 years, 2 months