r13329 jmb - /trunk/netsurf/content/mimesniff.c
by netsurf@semichrome.net
Author: jmb
Date: Thu Dec 22 18:21:47 2011
New Revision: 13329
URL: http://source.netsurf-browser.org?rev=13329&view=rev
Log:
Sync with spec
Modified:
trunk/netsurf/content/mimesniff.c
Modified: trunk/netsurf/content/mimesniff.c
URL: http://source.netsurf-browser.org/trunk/netsurf/content/mimesniff.c?rev=1...
==============================================================================
--- trunk/netsurf/content/mimesniff.c (original)
+++ trunk/netsurf/content/mimesniff.c Thu Dec 22 18:21:47 2011
@@ -19,7 +19,7 @@
/** \file
* MIME type sniffer (implementation)
*
- * Spec version: 2011-09-26
+ * Spec version: 2011-11-27
*/
#include<string.h>
@@ -175,9 +175,9 @@
* which is decidely unlikely.
*/
- /* Sniffing spec says 4; we use 12, as this is the minimum number of
- * octets needed to sniff useful information out of an 'ftyp' box
- * (i.e. the size, type, and major_brand words). */
+ /* 12 reflects the minimum number of octets needed to sniff useful
+ * information out of an 'ftyp' box (i.e. the size, type,
+ * and major_brand words). */
if (len < 12)
return NSERROR_NOT_FOUND;
@@ -189,12 +189,12 @@
return NSERROR_NOT_FOUND;
/* Ensure this is an 'ftyp' box */
- if (data[5] != 'f' || data[6] != 't' ||
- data[7] != 'y' || data[8] != 'p')
+ if (data[4] != 'f' || data[5] != 't' ||
+ data[6] != 'y' || data[7] != 'p')
return NSERROR_NOT_FOUND;
/* Check if major brand begins with 'mp4' */
- if (data[9] == 'm' && data[10] == 'p' && data[11] == '4') {
+ if (data[8] == 'm' && data[9] == 'p' && data[10] == '4') {
*effective_type = lwc_string_ref(video_mp4);
return NSERROR_OK;
}
11 years, 5 months
r13328 vince - in /branches/vince/netsurf-cairo: Docs/BUILDING-GTK content/content.h desktop/plot_style.h image/gif.c image/image.c image/image.h image/image_cache.c render/html_redraw.c
by netsurf@semichrome.net
Author: vince
Date: Thu Dec 22 17:53:15 2011
New Revision: 13328
URL: http://source.netsurf-browser.org?rev=13328&view=rev
Log:
Move short circuit of 1x1 bitmap plotting to common image content hander helper
Modified:
branches/vince/netsurf-cairo/Docs/BUILDING-GTK
branches/vince/netsurf-cairo/content/content.h
branches/vince/netsurf-cairo/desktop/plot_style.h
branches/vince/netsurf-cairo/image/gif.c
branches/vince/netsurf-cairo/image/image.c
branches/vince/netsurf-cairo/image/image.h
branches/vince/netsurf-cairo/image/image_cache.c
branches/vince/netsurf-cairo/render/html_redraw.c
Modified: branches/vince/netsurf-cairo/Docs/BUILDING-GTK
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/Docs/BUILD...
==============================================================================
--- branches/vince/netsurf-cairo/Docs/BUILDING-GTK (original)
+++ branches/vince/netsurf-cairo/Docs/BUILDING-GTK Thu Dec 22 17:53:15 2011
@@ -67,7 +67,7 @@
Debian-like OS:
$ apt-get install libglade2-dev libcurl3-dev libxml2-dev libmng-dev
- $ apt-get install librsvg2-dev liblcms1-dev
+ $ apt-get install librsvg2-dev liblcms1-dev libjpeg-dev
Recent OS versions might need libcurl4-dev instead of libcurl3-dev but
note that when it has not been built with OpenSSL, the SSL_CTX is not
Modified: branches/vince/netsurf-cairo/content/content.h
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/content/co...
==============================================================================
--- branches/vince/netsurf-cairo/content/content.h (original)
+++ branches/vince/netsurf-cairo/content/content.h Thu Dec 22 17:53:15 2011
@@ -112,25 +112,25 @@
struct content_rfc5988_link *rfc5988_link;
};
-
+/** parameters to content redraw */
struct content_redraw_data {
- int x; /** coordinate for top-left of redraw */
- int y; /** coordinate for top-left of redraw */
+ int x; /**< coordinate for top-left of redraw */
+ int y; /**< coordinate for top-left of redraw */
/** dimensions to render content at
* (for scaling contents with intrinsic dimensions) */
- int width; /* horizontal */
- int height; /* vertical */
-
- /** the background colour */
+ int width; /**< horizontal dimension */
+ int height; /**< vertical dimension */
+
+ /** The background colour */
colour background_colour;
/** Scale for redraw
* (for scaling contents without intrinsic dimensions) */
- float scale; /* scale factor */
-
- bool repeat_x; /* whether content is tiled in x direction */
- bool repeat_y; /* whether content is tiled in y direction */
+ float scale; /**< Scale factor for redraw */
+
+ bool repeat_x; /**< whether content is tiled in x direction */
+ bool repeat_y; /**< whether content is tiled in y direction */
};
/* The following are for hlcache */
Modified: branches/vince/netsurf-cairo/desktop/plot_style.h
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/desktop/pl...
==============================================================================
--- branches/vince/netsurf-cairo/desktop/plot_style.h (original)
+++ branches/vince/netsurf-cairo/desktop/plot_style.h Thu Dec 22 17:53:15 2011
@@ -64,10 +64,15 @@
(((((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff)) >> 1) << 8) | \
((((c0 & 0xff) + (c1 & 0xff)) >> 1) << 0)
+/* get a bitmap pixel (image/bitmap.h) into a plot colour */
+#define pixel_to_colour(b) \
+ b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)
+
/**
* Colour type: XBGR
*/
typedef uint32_t colour;
+
/**
* Magical transparent value
*/
Modified: branches/vince/netsurf-cairo/image/gif.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/image/gif....
==============================================================================
--- branches/vince/netsurf-cairo/image/gif.c (original)
+++ branches/vince/netsurf-cairo/image/gif.c Thu Dec 22 17:53:15 2011
@@ -39,6 +39,7 @@
#include "content/hlcache.h"
#include "desktop/options.h"
#include "desktop/plotters.h"
+#include "image/image.h"
#include "image/bitmap.h"
#include "image/gif.h"
#include "utils/log.h"
@@ -337,7 +338,6 @@
const struct rect *clip, const struct redraw_context *ctx)
{
nsgif_content *gif = (nsgif_content *) c;
- bitmap_flags_t flags = BITMAPF_NONE;
if (gif->current_frame != gif->gif->decoded_frame) {
if (nsgif_get_frame(gif) != GIF_OK) {
@@ -345,16 +345,7 @@
}
}
- if ((data->width == -1) && (data->height == -1))
- return true;
-
- if (data->repeat_x)
- flags |= BITMAPF_REPEAT_X;
- if (data->repeat_y)
- flags |= BITMAPF_REPEAT_Y;
-
- return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
- gif->gif->frame_image, data->background_colour, flags);
+ return image_bitmap_plot(gif->gif->frame_image, data, clip, ctx);
}
Modified: branches/vince/netsurf-cairo/image/image.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/image/imag...
==============================================================================
--- branches/vince/netsurf-cairo/image/image.c (original)
+++ branches/vince/netsurf-cairo/image/image.c Thu Dec 22 17:53:15 2011
@@ -22,8 +22,11 @@
#include <string.h>
#include "utils/errors.h"
+#include "utils/config.h"
+#include "utils/log.h"
+#include "desktop/plotters.h"
+#include "image/bitmap.h"
-#include "image/image.h"
#include "image/bmp.h"
#include "image/gif.h"
#include "image/ico.h"
@@ -35,7 +38,7 @@
#include "image/svg.h"
#include "image/webp.h"
-#include "utils/config.h"
+#include "image/image.h"
/**
* Initialise image content handlers
@@ -114,3 +117,60 @@
return NSERROR_OK;
}
+
+bool image_bitmap_plot(struct bitmap *bitmap,
+ struct content_redraw_data *data,
+ const struct rect *clip,
+ const struct redraw_context *ctx)
+{
+ bitmap_flags_t flags = BITMAPF_NONE;
+
+ int width;
+ int height;
+ unsigned char *pixel;
+ plot_style_t fill_style;
+ struct rect area;
+
+ if (bitmap_get_opaque(bitmap)) {
+ width = bitmap_get_width(bitmap);
+ if (width == 1) {
+ height = bitmap_get_height(bitmap);
+ if (height == 1) {
+ /* optimise 1x1 bitmap plot */
+ pixel = bitmap_get_buffer(bitmap);
+ fill_style.fill_colour = pixel_to_colour(pixel);
+
+ area = *clip;
+
+ if (data->repeat_x != true) {
+ area.x0 = data->x;
+ area.x1 = data->x + data->width;
+ }
+
+ if (data->repeat_y != true) {
+ area.y0 = data->y;
+ area.y1 = data->y + data->height;
+ }
+
+ fill_style.stroke_type = PLOT_OP_TYPE_NONE;
+ fill_style.fill_type = PLOT_OP_TYPE_SOLID;
+ LOG(("area %d,%d -> %d,%d", area.x0, area.y0, area.x1, area.y1));
+ return ctx->plot->rectangle(area.x0, area.y0,
+ area.x1, area.y1,
+ &fill_style);
+
+ }
+ }
+ }
+
+ /* do the plot */
+ if (data->repeat_x)
+ flags |= BITMAPF_REPEAT_X;
+ if (data->repeat_y)
+ flags |= BITMAPF_REPEAT_Y;
+
+ return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
+ bitmap, data->background_colour, flags);
+
+
+}
Modified: branches/vince/netsurf-cairo/image/image.h
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/image/imag...
==============================================================================
--- branches/vince/netsurf-cairo/image/image.h (original)
+++ branches/vince/netsurf-cairo/image/image.h Thu Dec 22 17:53:15 2011
@@ -25,6 +25,19 @@
#include "utils/errors.h"
+/** Initialise the content handlers for image types.
+ */
nserror image_init(void);
+/** Common image content handler bitmap plot call.
+ *
+ * This plots the specified bitmap controlled by the redraw context
+ * and specific content redraw data. It is a helper specifically
+ * provided for image content handlers redraw callback.
+ */
+bool image_bitmap_plot(struct bitmap *bitmap,
+ struct content_redraw_data *data,
+ const struct rect *clip,
+ const struct redraw_context *ctx);
+
#endif
Modified: branches/vince/netsurf-cairo/image/image_cache.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/image/imag...
==============================================================================
--- branches/vince/netsurf-cairo/image/image_cache.c (original)
+++ branches/vince/netsurf-cairo/image/image_cache.c Thu Dec 22 17:53:15 2011
@@ -22,13 +22,12 @@
#include <stdbool.h>
#include <string.h>
-#include "utils/errors.h"
-#include "utils/utils.h"
+#include "utils/schedule.h"
#include "utils/log.h"
-#include "utils/config.h"
-#include "utils/schedule.h"
#include "content/content_protected.h"
+
#include "image/image_cache.h"
+#include "image/image.h"
/** Age of an entry within the cache
*
@@ -712,7 +711,6 @@
const struct rect *clip,
const struct redraw_context *ctx)
{
- bitmap_flags_t flags = BITMAPF_NONE;
struct image_cache_entry_s *centry;
/* get the cache entry */
@@ -746,14 +744,7 @@
centry->redraw_count++;
centry->redraw_age = image_cache->current_age;
- /* do the plot */
- if (data->repeat_x)
- flags |= BITMAPF_REPEAT_X;
- if (data->repeat_y)
- flags |= BITMAPF_REPEAT_Y;
-
- return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
- centry->bitmap, data->background_colour, flags);
+ return image_bitmap_plot(centry->bitmap, data, clip, ctx);
}
void image_cache_destroy(struct content *content)
Modified: branches/vince/netsurf-cairo/render/html_redraw.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-cairo/render/htm...
==============================================================================
--- branches/vince/netsurf-cairo/render/html_redraw.c (original)
+++ branches/vince/netsurf-cairo/render/html_redraw.c Thu Dec 22 17:53:15 2011
@@ -2173,6 +2173,7 @@
width = content_get_width(background->background);
height = content_get_height(background->background);
+ /* ensure clip area only as large as required */
if (!repeat_x) {
if (r.x0 < x)
r.x0 = x;
11 years, 5 months
r13327 tlsa - in /trunk/libdom: examples/dom-structure-dump.c include/dom/core/string.h src/core/string.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 22 08:16:52 2011
New Revision: 13327
URL: http://source.netsurf-browser.org?rev=13327&view=rev
Log:
Fix comparison of interned and non-interned dom strings. Constify dom string data accessers.
Modified:
trunk/libdom/examples/dom-structure-dump.c
trunk/libdom/include/dom/core/string.h
trunk/libdom/src/core/string.c
Modified: trunk/libdom/examples/dom-structure-dump.c
URL: http://source.netsurf-browser.org/trunk/libdom/examples/dom-structure-dum...
==============================================================================
--- trunk/libdom/examples/dom-structure-dump.c (original)
+++ trunk/libdom/examples/dom-structure-dump.c Thu Dec 22 08:16:52 2011
@@ -133,7 +133,8 @@
/**
* Dump attribute/value for an element node
*
- * \param node The element node to dump attribute details for
+ * \param node The element node to dump attribute details for
+ * \param attribute The attribute to dump
* \return true on success, or false on error
*/
bool dump_dom_element_attribute(dom_node_internal *node, char *attribute)
Modified: trunk/libdom/include/dom/core/string.h
URL: http://source.netsurf-browser.org/trunk/libdom/include/dom/core/string.h?...
==============================================================================
--- trunk/libdom/include/dom/core/string.h (original)
+++ trunk/libdom/include/dom/core/string.h Thu Dec 22 08:16:52 2011
@@ -49,10 +49,10 @@
* @note: This function is just provided for the convenience of accessing the
* raw C string character, no change on the result string is allowed.
*/
-const char *dom_string_data(dom_string *str);
+const char *dom_string_data(const dom_string *str);
/* Get the byte length of this dom_string */
-size_t dom_string_byte_length(dom_string *str);
+size_t dom_string_byte_length(const dom_string *str);
/* Get the UCS-4 character at position index, the index should be in
* [0, length), and length can be get by calling dom_string_length
Modified: trunk/libdom/src/core/string.c
URL: http://source.netsurf-browser.org/trunk/libdom/src/core/string.c?rev=1332...
==============================================================================
--- trunk/libdom/src/core/string.c (original)
+++ trunk/libdom/src/core/string.c Thu Dec 22 08:16:52 2011
@@ -214,6 +214,8 @@
*/
bool dom_string_isequal(const dom_string *s1, const dom_string *s2)
{
+ size_t len;
+
if (s1 == NULL)
s1 = &empty_string;
@@ -229,11 +231,12 @@
return match;
}
- if (s1->data.cdata.len != s2->data.cdata.len)
+ len = dom_string_byte_length(s1);
+
+ if (len != dom_string_byte_length(s2))
return false;
- return 0 == memcmp(s1->data.cdata.ptr, s2->data.cdata.ptr,
- s1->data.cdata.len);
+ return 0 == memcmp(dom_string_data(s1), dom_string_data(s2), len);
}
/**
@@ -275,12 +278,13 @@
return match;
}
- if (s1->data.cdata.len != s2->data.cdata.len)
+ len = dom_string_byte_length(s1);
+
+ if (len != dom_string_byte_length(s2))
return false;
- d1 = s1->data.cdata.ptr;
- d2 = s2->data.cdata.ptr;
- len = s1->data.cdata.len;
+ d1 = (const uint8_t *) dom_string_data(s1);
+ d2 = (const uint8_t *) dom_string_data(s2);
while (len > 0) {
if (dolower(*d1) != dolower(*d2))
@@ -787,7 +791,7 @@
* @note: This function is just provided for the convenience of accessing the
* raw C string character, no change on the result string is allowed.
*/
-const char *dom_string_data(dom_string *str)
+const char *dom_string_data(const dom_string *str)
{
if (str->type == DOM_STRING_CDATA) {
return (const char *) str->data.cdata.ptr;
@@ -800,7 +804,7 @@
*
* \param str The dom_string object
*/
-size_t dom_string_byte_length(dom_string *str)
+size_t dom_string_byte_length(const dom_string *str)
{
if (str->type == DOM_STRING_CDATA) {
return str->data.cdata.len;
11 years, 5 months
r13326 tlsa - /trunk/libdom/examples/dom-structure-dump.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 22 05:59:57 2011
New Revision: 13326
URL: http://source.netsurf-browser.org?rev=13326&view=rev
Log:
Fix length for dom_string creation. Dump id attribute too.
Modified:
trunk/libdom/examples/dom-structure-dump.c
Modified: trunk/libdom/examples/dom-structure-dump.c
URL: http://source.netsurf-browser.org/trunk/libdom/examples/dom-structure-dum...
==============================================================================
--- trunk/libdom/examples/dom-structure-dump.c (original)
+++ trunk/libdom/examples/dom-structure-dump.c Thu Dec 22 05:59:57 2011
@@ -41,6 +41,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
@@ -153,7 +154,7 @@
assert(type == DOM_ELEMENT_NODE);
/* Create a dom_string containing required attribute name. */
- exc = dom_string_create((uint8_t *)attribute, 5, &attr);
+ exc = dom_string_create((uint8_t *)attribute, strlen(attribute), &attr);
if (exc != DOM_NO_ERR) {
printf(" Exception raised for dom_string_create\n");
return false;
@@ -238,8 +239,10 @@
/* Finished with the node_name dom_string */
dom_string_unref(node_name);
- /* Print the element's class, if it has one */
- if (dump_dom_element_attribute(node, "class") == false) {
+ /* Print the element's id & class, if it has them */
+ if (dump_dom_element_attribute(node, "id") == false ||
+ dump_dom_element_attribute(node, "class") == false) {
+ /* Error occured */
printf("\n");
return false;
}
11 years, 5 months
r13325 tlsa - /trunk/libdom/examples/dom-structure-dump.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 22 05:34:47 2011
New Revision: 13325
URL: http://source.netsurf-browser.org?rev=13325&view=rev
Log:
Fix length of string prints.
Modified:
trunk/libdom/examples/dom-structure-dump.c
Modified: trunk/libdom/examples/dom-structure-dump.c
URL: http://source.netsurf-browser.org/trunk/libdom/examples/dom-structure-dum...
==============================================================================
--- trunk/libdom/examples/dom-structure-dump.c (original)
+++ trunk/libdom/examples/dom-structure-dump.c Thu Dec 22 05:34:47 2011
@@ -177,7 +177,7 @@
length = dom_string_byte_length(attr_value);
/* Print attribute info */
- printf(" %s=\"%*s\"", attribute, (int)length, string);
+ printf(" %s=\"%.*s\"", attribute, (int)length, string);
/* Finished with the attr_value dom_string */
dom_string_unref(attr_value);
@@ -233,7 +233,7 @@
/* Get string data and print element name */
string = dom_string_data(node_name);
length = dom_string_byte_length(node_name);
- printf("%*s", (int)length, string);
+ printf("%.*s", (int)length, string);
/* Finished with the node_name dom_string */
dom_string_unref(node_name);
11 years, 5 months
r13324 tlsa - /trunk/libdom/examples/dom-structure-dump.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 22 05:05:48 2011
New Revision: 13324
URL: http://source.netsurf-browser.org?rev=13324&view=rev
Log:
Make example a smidgen more generic. Free the dom_string created for attribute acquisition.
Modified:
trunk/libdom/examples/dom-structure-dump.c
Modified: trunk/libdom/examples/dom-structure-dump.c
URL: http://source.netsurf-browser.org/trunk/libdom/examples/dom-structure-dum...
==============================================================================
--- trunk/libdom/examples/dom-structure-dump.c (original)
+++ trunk/libdom/examples/dom-structure-dump.c Thu Dec 22 05:05:48 2011
@@ -130,16 +130,16 @@
/**
- * Dump class attribute/value for an element node
- *
- * \param node The element node to dump class for
+ * Dump attribute/value for an element node
+ *
+ * \param node The element node to dump attribute details for
* \return true on success, or false on error
*/
-bool dump_dom_element_class(dom_node_internal *node)
+bool dump_dom_element_attribute(dom_node_internal *node, char *attribute)
{
dom_exception exc;
- dom_string *class = NULL;
- dom_string *classvalue = NULL;
+ dom_string *attr = NULL;
+ dom_string *attr_value = NULL;
dom_node_type type;
const char *string;
size_t length;
@@ -152,32 +152,35 @@
}
assert(type == DOM_ELEMENT_NODE);
- /* Create a dom_string containing "class". */
- exc = dom_string_create((uint8_t *)"class", 5, &class);
+ /* Create a dom_string containing required attribute name. */
+ exc = dom_string_create((uint8_t *)attribute, 5, &attr);
if (exc != DOM_NO_ERR) {
printf(" Exception raised for dom_string_create\n");
return false;
}
/* Get class attribute's value */
- exc = dom_element_get_attribute(node, class, &classvalue);
+ exc = dom_element_get_attribute(node, attr, &attr_value);
if (exc != DOM_NO_ERR) {
printf(" Exception raised for element_get_attribute\n");
return false;
- } else if (classvalue == NULL) {
- /* Element has no class attribute */
+ } else if (attr_value == NULL) {
+ /* Element lacks required attribute */
return true;
}
- /* Get attributes's string data */
- string = dom_string_data(classvalue);
- length = dom_string_byte_length(classvalue);
-
- /* Print class info */
- printf(" class=\"%*s\"", (int)length, string);
-
- /* Finished with the classvalue dom_string */
- dom_string_unref(classvalue);
+ /* Finished with the attr dom_string */
+ dom_string_unref(attr);
+
+ /* Get attribute value's string data */
+ string = dom_string_data(attr_value);
+ length = dom_string_byte_length(attr_value);
+
+ /* Print attribute info */
+ printf(" %s=\"%*s\"", attribute, (int)length, string);
+
+ /* Finished with the attr_value dom_string */
+ dom_string_unref(attr_value);
return true;
}
@@ -236,7 +239,7 @@
dom_string_unref(node_name);
/* Print the element's class, if it has one */
- if (dump_dom_element_class(node) == false) {
+ if (dump_dom_element_attribute(node, "class") == false) {
printf("\n");
return false;
}
11 years, 5 months
r13323 tlsa - /trunk/libdom/examples/dom-structure-dump.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 22 04:49:34 2011
New Revision: 13323
URL: http://source.netsurf-browser.org?rev=13323&view=rev
Log:
Use ANSI functions for file handling.
Modified:
trunk/libdom/examples/dom-structure-dump.c
Modified: trunk/libdom/examples/dom-structure-dump.c
URL: http://source.netsurf-browser.org/trunk/libdom/examples/dom-structure-dum...
==============================================================================
--- trunk/libdom/examples/dom-structure-dump.c (original)
+++ trunk/libdom/examples/dom-structure-dump.c Thu Dec 22 04:49:34 2011
@@ -35,14 +35,12 @@
*
*/
-#define _GNU_SOURCE /* for strndup */
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <fcntl.h>
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
@@ -71,9 +69,9 @@
*/
dom_document *create_doc_dom_from_file(char *file)
{
- const unsigned int buffer_size = 1024;
+ size_t buffer_size = 1024;
dom_hubbub_parser *parser = NULL;
- int handle;
+ FILE *handle;
int chunk_length;
dom_hubbub_error error;
dom_document *doc;
@@ -87,8 +85,8 @@
}
/* Open input file */
- handle = open(file, O_RDONLY);
- if (handle == -1) {
+ handle = fopen(file, "rb");
+ if (handle == NULL) {
dom_hubbub_parser_destroy(parser);
printf("Can't open test input file: %s\n", file);
return NULL;
@@ -97,7 +95,7 @@
/* Parse input file in chunks */
chunk_length = buffer_size;
while(chunk_length == buffer_size) {
- chunk_length = read(handle, buffer, buffer_size);
+ chunk_length = fread(buffer, 1, buffer_size, handle);
error = dom_hubbub_parser_parse_chunk(parser, buffer,
chunk_length);
if (error != DOM_HUBBUB_OK) {
@@ -122,7 +120,7 @@
dom_hubbub_parser_destroy(parser);
/* Close input file */
- if (close(handle) == -1) {
+ if (fclose(handle) != 0) {
printf("Can't close test input file: %s\n", file);
return NULL;
}
11 years, 5 months
r13322 tlsa - in /trunk/libdom: include/dom/core/string.h src/core/node.c src/core/nodelist.c src/core/string.c src/core/string.h src/events/keyboard_event.c src/events/mouse_event.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 22 04:24:04 2011
New Revision: 13322
URL: http://source.netsurf-browser.org?rev=13322&view=rev
Log:
Move dom_string data accessing functions to public header.
Modified:
trunk/libdom/include/dom/core/string.h
trunk/libdom/src/core/node.c
trunk/libdom/src/core/nodelist.c
trunk/libdom/src/core/string.c
trunk/libdom/src/core/string.h
trunk/libdom/src/events/keyboard_event.c
trunk/libdom/src/events/mouse_event.c
Modified: trunk/libdom/include/dom/core/string.h
URL: http://source.netsurf-browser.org/trunk/libdom/include/dom/core/string.h?...
==============================================================================
--- trunk/libdom/include/dom/core/string.h (original)
+++ trunk/libdom/include/dom/core/string.h Thu Dec 22 04:24:04 2011
@@ -44,6 +44,16 @@
/* Get the length, in characters, of a dom string */
uint32_t dom_string_length(dom_string *str);
+/**
+ * Get the raw character data of the dom_string.
+ * @note: This function is just provided for the convenience of accessing the
+ * raw C string character, no change on the result string is allowed.
+ */
+const char *dom_string_data(dom_string *str);
+
+/* Get the byte length of this dom_string */
+size_t dom_string_byte_length(dom_string *str);
+
/* Get the UCS-4 character at position index, the index should be in
* [0, length), and length can be get by calling dom_string_length
*/
Modified: trunk/libdom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/libdom/src/core/node.c?rev=13322&...
==============================================================================
--- trunk/libdom/src/core/node.c (original)
+++ trunk/libdom/src/core/node.c Thu Dec 22 04:24:04 2011
@@ -1197,8 +1197,8 @@
UNUSED(node);
- dom_implementation_has_feature(_dom_string_data(feature),
- _dom_string_data(version), &has);
+ dom_implementation_has_feature(dom_string_data(feature),
+ dom_string_data(version), &has);
*result = has;
@@ -1685,8 +1685,8 @@
UNUSED(node);
- dom_implementation_has_feature(_dom_string_data(feature),
- _dom_string_data(version), &has);
+ dom_implementation_has_feature(dom_string_data(feature),
+ dom_string_data(version), &has);
if (has) {
*result = node;
Modified: trunk/libdom/src/core/nodelist.c
URL: http://source.netsurf-browser.org/trunk/libdom/src/core/nodelist.c?rev=13...
==============================================================================
--- trunk/libdom/src/core/nodelist.c (original)
+++ trunk/libdom/src/core/nodelist.c Thu Dec 22 04:24:04 2011
@@ -87,8 +87,8 @@
if (type == DOM_NODELIST_BY_NAME) {
assert(tagname != NULL);
l->data.n.any_name = false;
- if (_dom_string_byte_length(tagname) == 1) {
- const char *ch = _dom_string_data(tagname);
+ if (dom_string_byte_length(tagname) == 1) {
+ const char *ch = dom_string_data(tagname);
if (*ch == '*') {
l->data.n.any_name = true;
}
@@ -99,8 +99,8 @@
l->data.ns.any_localname = false;
l->data.ns.any_namespace = false;
if (localname != NULL) {
- if (_dom_string_byte_length(localname) == 1) {
- const char *ch = _dom_string_data(localname);
+ if (dom_string_byte_length(localname) == 1) {
+ const char *ch = dom_string_data(localname);
if (*ch == '*') {
l->data.ns.any_localname = true;
}
@@ -108,8 +108,8 @@
dom_string_ref(localname);
}
if (namespace != NULL) {
- if (_dom_string_byte_length(namespace) == 1) {
- const char *ch = _dom_string_data(namespace);
+ if (dom_string_byte_length(namespace) == 1) {
+ const char *ch = dom_string_data(namespace);
if (*ch == '*') {
l->data.ns.any_namespace = true;
}
Modified: trunk/libdom/src/core/string.c
URL: http://source.netsurf-browser.org/trunk/libdom/src/core/string.c?rev=1332...
==============================================================================
--- trunk/libdom/src/core/string.c (original)
+++ trunk/libdom/src/core/string.c Thu Dec 22 04:24:04 2011
@@ -308,8 +308,8 @@
uint32_t c, index;
parserutils_error err;
- s = (const uint8_t *) _dom_string_data(str);
- slen = _dom_string_byte_length(str);
+ s = (const uint8_t *) dom_string_data(str);
+ slen = dom_string_byte_length(str);
index = 0;
@@ -345,8 +345,8 @@
uint32_t c, coff, index;
parserutils_error err;
- s = (const uint8_t *) _dom_string_data(str);
- slen = _dom_string_byte_length(str);
+ s = (const uint8_t *) dom_string_data(str);
+ slen = dom_string_byte_length(str);
index = dom_string_length(str);
@@ -385,8 +385,8 @@
size_t slen, clen;
parserutils_error err;
- s = (const uint8_t *) _dom_string_data(str);
- slen = _dom_string_byte_length(str);
+ s = (const uint8_t *) dom_string_data(str);
+ slen = dom_string_byte_length(str);
err = parserutils_charset_utf8_length(s, slen, &clen);
if (err != PARSERUTILS_OK) {
@@ -411,8 +411,8 @@
uint32_t c, i;
parserutils_error err;
- s = (const uint8_t *) _dom_string_data(str);
- slen = _dom_string_byte_length(str);
+ s = (const uint8_t *) dom_string_data(str);
+ slen = dom_string_byte_length(str);
i = 0;
@@ -464,10 +464,10 @@
assert(s1 != NULL);
assert(s2 != NULL);
- s1ptr = (const uint8_t *) _dom_string_data(s1);
- s2ptr = (const uint8_t *) _dom_string_data(s2);
- s1len = _dom_string_byte_length(s1);
- s2len = _dom_string_byte_length(s2);
+ s1ptr = (const uint8_t *) dom_string_data(s1);
+ s2ptr = (const uint8_t *) dom_string_data(s2);
+ s1len = dom_string_byte_length(s1);
+ s2len = dom_string_byte_length(s2);
concat = malloc(sizeof(dom_string));
@@ -512,8 +512,8 @@
dom_exception dom_string_substr(dom_string *str,
uint32_t i1, uint32_t i2, dom_string **result)
{
- const uint8_t *s = (const uint8_t *) _dom_string_data(str);
- size_t slen = _dom_string_byte_length(str);
+ const uint8_t *s = (const uint8_t *) dom_string_data(str);
+ size_t slen = dom_string_byte_length(str);
uint32_t b1, b2;
parserutils_error err;
@@ -573,10 +573,10 @@
uint32_t ins = 0;
parserutils_error err;
- t = (const uint8_t *) _dom_string_data(target);
- tlen = _dom_string_byte_length(target);
- s = (const uint8_t *) _dom_string_data(source);
- slen = _dom_string_byte_length(source);
+ t = (const uint8_t *) dom_string_data(target);
+ tlen = dom_string_byte_length(target);
+ s = (const uint8_t *) dom_string_data(source);
+ slen = dom_string_byte_length(source);
clen = dom_string_length(target);
@@ -661,10 +661,10 @@
uint32_t b1, b2;
parserutils_error err;
- t = (const uint8_t *) _dom_string_data(target);
- tlen = _dom_string_byte_length(target);
- s = (const uint8_t *) _dom_string_data(source);
- slen = _dom_string_byte_length(source);
+ t = (const uint8_t *) dom_string_data(target);
+ tlen = dom_string_byte_length(target);
+ s = (const uint8_t *) dom_string_data(source);
+ slen = dom_string_byte_length(source);
/* Initialise the byte index of the start to 0 */
b1 = 0;
@@ -743,8 +743,8 @@
*/
uint32_t dom_string_hash(dom_string *str)
{
- const uint8_t *s = (const uint8_t *) _dom_string_data(str);
- size_t slen = _dom_string_byte_length(str);
+ const uint8_t *s = (const uint8_t *) dom_string_data(str);
+ size_t slen = dom_string_byte_length(str);
uint32_t hash = 0x811c9dc5;
while (slen > 0) {
@@ -787,7 +787,7 @@
* @note: This function is just provided for the convenience of accessing the
* raw C string character, no change on the result string is allowed.
*/
-const char *_dom_string_data(dom_string *str)
+const char *dom_string_data(dom_string *str)
{
if (str->type == DOM_STRING_CDATA) {
return (const char *) str->data.cdata.ptr;
@@ -800,7 +800,7 @@
*
* \param str The dom_string object
*/
-size_t _dom_string_byte_length(dom_string *str)
+size_t dom_string_byte_length(dom_string *str)
{
if (str->type == DOM_STRING_CDATA) {
return str->data.cdata.len;
Modified: trunk/libdom/src/core/string.h
URL: http://source.netsurf-browser.org/trunk/libdom/src/core/string.h?rev=1332...
==============================================================================
--- trunk/libdom/src/core/string.h (original)
+++ trunk/libdom/src/core/string.h Thu Dec 22 04:24:04 2011
@@ -18,15 +18,5 @@
/* Map the lwc_error to dom_exception */
dom_exception _dom_exception_from_lwc_error(lwc_error err);
-/**
- * Get the raw character data of the dom_string.
- * @note: This function is just provided for the convenience of accessing the
- * raw C string character, no change on the result string is allowed.
- */
-const char *_dom_string_data(dom_string *str);
-
-/* Get the byte length of this dom_string */
-size_t _dom_string_byte_length(dom_string *str);
-
#endif
Modified: trunk/libdom/src/events/keyboard_event.c
URL: http://source.netsurf-browser.org/trunk/libdom/src/events/keyboard_event....
==============================================================================
--- trunk/libdom/src/events/keyboard_event.c (original)
+++ trunk/libdom/src/events/keyboard_event.c Thu Dec 22 04:24:04 2011
@@ -177,8 +177,8 @@
return DOM_NO_ERR;
}
- const char *data = _dom_string_data(m);
- size_t len = _dom_string_byte_length(m);
+ const char *data = dom_string_data(m);
+ size_t len = dom_string_byte_length(m);
if (len == SLEN("AltGraph") && strncmp(data, "AltGraph", len) == 0) {
*state = ((evt->modifier_state & DOM_MOD_ALT_GRAPH) != 0);
@@ -291,7 +291,7 @@
if (modifier_list == NULL)
return DOM_NO_ERR;
- const char *data = _dom_string_data(modifier_list);
+ const char *data = dom_string_data(modifier_list);
const char *m = data;
size_t len = 0;
Modified: trunk/libdom/src/events/mouse_event.c
URL: http://source.netsurf-browser.org/trunk/libdom/src/events/mouse_event.c?r...
==============================================================================
--- trunk/libdom/src/events/mouse_event.c (original)
+++ trunk/libdom/src/events/mouse_event.c Thu Dec 22 04:24:04 2011
@@ -229,8 +229,8 @@
return DOM_NO_ERR;
}
- const char *data = _dom_string_data(m);
- size_t len = _dom_string_byte_length(m);
+ const char *data = dom_string_data(m);
+ size_t len = dom_string_byte_length(m);
if (len == SLEN("AltGraph") && strncmp(data, "AltGraph", len) == 0) {
*state = ((evt->modifier_state & DOM_MOD_ALT_GRAPH) != 0);
11 years, 5 months
r13321 tlsa - in /trunk/libdom/examples: dom-structure-dump.c makefile
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 22 04:22:51 2011
New Revision: 13321
URL: http://source.netsurf-browser.org?rev=13321&view=rev
Log:
Update for current libdom. Has issues.
Modified:
trunk/libdom/examples/dom-structure-dump.c
trunk/libdom/examples/makefile
Modified: trunk/libdom/examples/dom-structure-dump.c
URL: http://source.netsurf-browser.org/trunk/libdom/examples/dom-structure-dum...
==============================================================================
--- trunk/libdom/examples/dom-structure-dump.c (original)
+++ trunk/libdom/examples/dom-structure-dump.c Thu Dec 22 04:22:51 2011
@@ -3,7 +3,7 @@
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*
- * Copyright 2010 Michael Drake <tlsa(a)netsurf-browser.org>
+ * Copyright 2010 - 2011 Michael Drake <tlsa(a)netsurf-browser.org>
*/
/*
@@ -39,6 +39,7 @@
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -47,13 +48,6 @@
#include <dom/bindings/hubbub/parser.h>
#define UNUSED(x) ((x)=(x))
-
-void *test_realloc(void *ptr, size_t len, void *pw)
-{
- UNUSED(pw);
-
- return realloc(ptr, len);
-}
void test_msg(uint32_t severity, void *ctx, const char *msg, ...)
{
@@ -83,11 +77,10 @@
int chunk_length;
dom_hubbub_error error;
dom_document *doc;
- char buffer[buffer_size];
+ unsigned char buffer[buffer_size];
/* Create Hubbub parser */
- parser = dom_hubbub_parser_create(NULL, true, test_realloc, NULL,
- test_msg, NULL);
+ parser = dom_hubbub_parser_create(NULL, true, test_msg, NULL);
if (parser == NULL) {
printf("Can't create Hubbub Parser\n");
return NULL;
@@ -147,82 +140,67 @@
bool dump_dom_element_class(dom_node_internal *node)
{
dom_exception exc;
- lwc_error err;
dom_string *class = NULL;
dom_string *classvalue = NULL;
- lwc_string *lwcstr = NULL;
+ dom_node_type type;
+ const char *string;
+ size_t length;
+
+ /* Should only have element nodes here */
+ exc = dom_node_get_node_type(node, &type);
+ if (exc != DOM_NO_ERR) {
+ printf(" Exception raised for node_get_node_type\n");
+ return false;
+ }
+ assert(type == DOM_ELEMENT_NODE);
+
+ /* Create a dom_string containing "class". */
+ exc = dom_string_create((uint8_t *)"class", 5, &class);
+ if (exc != DOM_NO_ERR) {
+ printf(" Exception raised for dom_string_create\n");
+ return false;
+ }
+
+ /* Get class attribute's value */
+ exc = dom_element_get_attribute(node, class, &classvalue);
+ if (exc != DOM_NO_ERR) {
+ printf(" Exception raised for element_get_attribute\n");
+ return false;
+ } else if (classvalue == NULL) {
+ /* Element has no class attribute */
+ return true;
+ }
+
+ /* Get attributes's string data */
+ string = dom_string_data(classvalue);
+ length = dom_string_byte_length(classvalue);
+
+ /* Print class info */
+ printf(" class=\"%*s\"", (int)length, string);
+
+ /* Finished with the classvalue dom_string */
+ dom_string_unref(classvalue);
+
+ return true;
+}
+
+
+/**
+ * Print a line in a DOM structure dump for an element
+ *
+ * \param node The node to dump
+ * \param depth The node's depth
+ * \return true on success, or false on error
+ */
+bool dump_dom_element(dom_node_internal *node, int depth)
+{
+ dom_exception exc;
+ dom_string *node_name = NULL;
dom_node_type type;
int i;
const char *string;
size_t length;
- /* Should only have element nodes here */
- exc = dom_node_get_node_type(node, &type);
- if (exc != DOM_NO_ERR) {
- printf(" Exception raised for node_get_node_type\n");
- return false;
- }
- assert(type == DOM_ELEMENT_NODE);
-
- /* Create a dom_string constaining "class". */
- exc = dom_string_create(test_realloc, NULL, "class", 5, &class);
- if (exc != DOM_NO_ERR) {
- printf(" Exception raised for dom_string_create\n");
- return false;
- }
-
- /* Get class attribute's value */
- exc = dom_element_get_attribute(node, class, &classvalue);
- if (exc != DOM_NO_ERR) {
- printf(" Exception raised for element_get_attribute\n");
- return false;
- } else if (classvalue == NULL) {
- /* Element has no class attribute */
- return true;
- }
-
- /* Get attributes's lwc_string */
- exc = dom_string_get_intern(classvalue, &lwcstr);
- if (exc != DOM_NO_ERR) {
- printf(" Exception raised for string_get_intern\n");
- return false;
- } else if (lwcstr == NULL) {
- printf(" Broken: lwcstr == NULL\n");
- return false;
- }
-
- /* Finished with the classvalue dom_string */
- dom_string_unref(classvalue);
-
- /* Get string data and print class info */
- string = lwc_string_data(lwcstr);
- length = lwc_string_length(lwcstr);
- printf(" class=\"%*s\"", length, string);
-
- /* Print the element's class, if it has one */
- dump_dom_element_class(node);
- return true;
-}
-
-
-/**
- * Print a line in a DOM structure dump for an element
- *
- * \param node The node to dump
- * \param depth The node's depth
- * \return true on success, or false on error
- */
-bool dump_dom_element(dom_node_internal *node, int depth)
-{
- dom_exception exc;
- lwc_error err;
- dom_string *node_name = NULL;
- lwc_string *lwcstr = NULL;
- dom_node_type type;
- int i;
- const char *string;
- size_t length;
-
/* Only interested in element nodes */
exc = dom_node_get_node_type(node, &type);
if (exc != DOM_NO_ERR) {
@@ -242,16 +220,6 @@
printf("Broken: root_name == NULL\n");
return false;
}
-
- /* Get element name's lwc_string */
- exc = dom_string_get_intern(node_name, &lwcstr);
- if (exc != DOM_NO_ERR) {
- printf("Exception raised for string_get_intern\n");
- return false;
- }
-
- /* Finished with the node_name dom_string */
- dom_string_unref(node_name);
/* Print ASCII tree structure for current node */
if (depth > 0) {
@@ -262,12 +230,16 @@
}
/* Get string data and print element name */
- string = lwc_string_data(lwcstr);
- length = lwc_string_length(lwcstr);
- printf("%*s", length, string);
-
- /* PENDING FIX: Print the element's class, if it has one */
+ string = dom_string_data(node_name);
+ length = dom_string_byte_length(node_name);
+ printf("%*s", (int)length, string);
+
+ /* Finished with the node_name dom_string */
+ dom_string_unref(node_name);
+
+ /* Print the element's class, if it has one */
if (dump_dom_element_class(node) == false) {
+ printf("\n");
return false;
}
@@ -329,16 +301,8 @@
int main(int argc, char **argv)
{
dom_exception exc; /* returned by libdom functions */
- lwc_error err; /* returned by libwapacplet functions */
dom_document *doc = NULL; /* document, loaded into libdom */
dom_node_internal *root = NULL; /* root element of document */
-
- /* Initialise the DOM library */
- exc = dom_initialise(test_realloc, NULL);
- if (exc != DOM_NO_ERR) {
- printf("Failed to initialise DOM library.\n");
- return EXIT_FAILURE;
- }
/* Load up the input HTML file */
doc = create_doc_dom_from_file("files/test.html");
@@ -363,13 +327,6 @@
return EXIT_FAILURE;
}
- /* Finalise the DOM library */
- exc = dom_finalise();
- if (exc != DOM_NO_ERR) {
- printf("Failed to finalise DOM library.\n");
- return EXIT_FAILURE;
- }
-
/* Finished with the dom_document */
dom_node_unref(doc);
Modified: trunk/libdom/examples/makefile
URL: http://source.netsurf-browser.org/trunk/libdom/examples/makefile?rev=1332...
==============================================================================
--- trunk/libdom/examples/makefile (original)
+++ trunk/libdom/examples/makefile Thu Dec 22 04:22:51 2011
@@ -1,7 +1,7 @@
CC := gcc
LD := gcc
-CFLAGS := `pkg-config --cflags libdom` `pkg-config --cflags libwapcaplet`
+CFLAGS := `pkg-config --cflags libdom` `pkg-config --cflags libwapcaplet` -Wall
LDFLAGS := `pkg-config --libs libdom` `pkg-config --libs libwapcaplet`
SRC := dom-structure-dump.c
11 years, 5 months
r13320 mono - /trunk/netsurf/atari/gui.c
by netsurf@semichrome.net
Author: mono
Date: Wed Dec 21 16:51:17 2011
New Revision: 13320
URL: http://source.netsurf-browser.org?rev=13320&view=rev
Log:
Removed unused variable.
Modified:
trunk/netsurf/atari/gui.c
Modified: trunk/netsurf/atari/gui.c
URL: http://source.netsurf-browser.org/trunk/netsurf/atari/gui.c?rev=13320&r1=...
==============================================================================
--- trunk/netsurf/atari/gui.c (original)
+++ trunk/netsurf/atari/gui.c Wed Dec 21 16:51:17 2011
@@ -97,9 +97,7 @@
const char * cfg_homepage_url;
/* path to choices file: */
-char options[PATH_MAX];
-
-extern GEM_PLOTTER plotter;
+char options[PATH_MAX];
void gui_poll(bool active)
@@ -1011,8 +1009,7 @@
browser_window_create(cfg_homepage_url, 0, 0, true, false);
graf_mouse( ARROW , NULL);
netsurf_main_loop();
- netsurf_exit();
-
+ netsurf_exit();
LOG(("ApplExit"));
ApplExit();
#ifdef WITH_DBG_LOGFILE
11 years, 5 months