summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2003-04-11 21:06:51 +0000
committerJames Bursa <james@netsurf-browser.org>2003-04-11 21:06:51 +0000
commit02674693069358fc9f59700ea150d3811281f296 (patch)
tree7b51c457a0a3efbdc84fb00509bea02a6413d9ee
parent7c94cf8be972d6853cc15f3971bf36fe64b04d92 (diff)
downloadnetsurf-02674693069358fc9f59700ea150d3811281f296.tar.gz
netsurf-02674693069358fc9f59700ea150d3811281f296.tar.bz2
[project @ 2003-04-11 21:06:51 by bursa]
Memory usage and CSS fixes. svn path=/import/netsurf/; revision=122
-rw-r--r--makefile5
-rw-r--r--render/box.c31
-rw-r--r--render/html.c49
-rw-r--r--riscos/gui.c4
-rw-r--r--utils/utils.c37
-rw-r--r--utils/utils.h5
6 files changed, 82 insertions, 49 deletions
diff --git a/makefile b/makefile
index 3b0ead684..515e485b4 100644
--- a/makefile
+++ b/makefile
@@ -1,4 +1,4 @@
-# $Id: makefile,v 1.17 2003/04/06 18:09:34 bursa Exp $
+# $Id: makefile,v 1.18 2003/04/11 21:06:51 bursa Exp $
all: !NetSurf/!RunImage,ff8
clean:
@@ -38,8 +38,7 @@ HEADERS = \
LIBS = \
/usr/local/riscoslibs/libxml2/libxml2.ro \
/usr/local/riscoslibs/OSLib/OSLib.ro \
- /usr/local/riscoslibs/curl/libcurl.ro \
- /usr/local/riscoslibs/libutf-8/libutf-8.ro
+ /usr/local/riscoslibs/curl/libcurl.ro
!NetSurf/!RunImage,ff8: $(OBJECTS)
$(CC) $(FLAGS) -o !NetSurf/!RunImage,ff8 $(OBJECTS) $(LIBS)
diff --git a/render/box.c b/render/box.c
index ad139f7c2..a94088fa6 100644
--- a/render/box.c
+++ b/render/box.c
@@ -1,5 +1,5 @@
/**
- * $Id: box.c,v 1.39 2003/04/10 21:44:45 bursa Exp $
+ * $Id: box.c,v 1.40 2003/04/11 21:06:51 bursa Exp $
*/
#include <assert.h>
@@ -24,7 +24,6 @@
static void box_add_child(struct box * parent, struct box * child);
static struct box * box_create(box_type type, struct css_style * style,
char *href);
-static char * tolat1(xmlChar * s);
static struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
struct content ** stylesheet, unsigned int stylesheet_count,
struct css_selector ** selector, unsigned int depth,
@@ -105,28 +104,6 @@ struct box * box_create(box_type type, struct css_style * style,
}
-char * tolat1(xmlChar * s)
-{
- char *d = xcalloc(strlen((char*) s) + 1, sizeof(char));
- char *d0 = d;
- unsigned int u, chars;
-
- while (*s != 0) {
- u = sgetu8((unsigned char*) s, (int*) &chars);
- s += chars;
- if (u == 0x09 || u == 0x0a || u == 0x0d)
- *d = ' ';
- else if ((0x20 <= u && u <= 0x7f) || (0xa0 <= u && u <= 0xff))
- *d = u;
- else
- *d = '?';
- d++;
- }
- *d = 0;
-
- return d0;
-}
-
/**
* make a box tree with style data from an xml tree
*
@@ -212,7 +189,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
add_img_element(elements, box->img);*/
if (style->display == CSS_DISPLAY_INLINE) {
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "alt"))) {
- text = squash_whitespace(tolat1(s));
+ text = squash_tolat1(s);
xfree(s);
}
}
@@ -220,7 +197,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
} else if (strcmp((const char *) n->name, "textarea") == 0) {
char * content = xmlNodeGetContent(n);
- char * thistext = squash_whitespace(tolat1(content)); /* squash ? */
+ char * thistext = squash_tolat1(content); /* squash ? */
LOG(("textarea"));
box = box_textarea(n, style, current_form);
current_textarea = box->gadget;
@@ -255,7 +232,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
style->display = CSS_DISPLAY_BLOCK;
} else if (n->type == XML_TEXT_NODE) {
- text = squash_whitespace(tolat1(n->content));
+ text = squash_tolat1(n->content);
}
if (text != 0) {
diff --git a/render/html.c b/render/html.c
index c6b96719a..f3f547e88 100644
--- a/render/html.c
+++ b/render/html.c
@@ -1,5 +1,5 @@
/**
- * $Id: html.c,v 1.12 2003/04/10 21:44:45 bursa Exp $
+ * $Id: html.c,v 1.13 2003/04/11 21:06:51 bursa Exp $
*/
#include <assert.h>
@@ -82,13 +82,13 @@ int html_convert(struct content *c, unsigned int width, unsigned int height)
head != 0 && head->type != XML_ELEMENT_NODE;
head = head->next)
;
- if (head == 0 || strcmp((const char *) head->name, "head") != 0) {
+ if (strcmp((const char *) head->name, "head") != 0) {
+ head = 0;
LOG(("head element not found"));
- xmlFreeDoc(document);
- return 1;
}
- html_title(c, head);
+ if (head != 0)
+ html_title(c, head);
/* get stylesheets */
html_find_stylesheets(c, head);
@@ -137,8 +137,19 @@ int html_convert(struct content *c, unsigned int width, unsigned int height)
&selector, 0, c->data.html.layout, 0, 0, c->data.html.fonts,
0, 0, 0, 0, &c->data.html.elements);
/*box_dump(c->data.html.layout->children, 0);*/
+
+ /* XML tree and stylesheets not required past this point */
xmlFreeDoc(document);
+ cache_free(c->data.html.stylesheet_content[0]);
+ for (i = 1; i != c->data.html.stylesheet_count; i++) {
+ if (c->data.html.stylesheet_content[i] != 0)
+ cache_free(c->data.html.stylesheet_content[i]);
+ xfree(c->data.html.stylesheet_url[i]);
+ }
+ xfree(c->data.html.stylesheet_url);
+ xfree(c->data.html.stylesheet_content);
+
c->status_callback(c->status_p, "Formatting document");
LOG(("Layout document"));
layout_document(c->data.html.layout->children, width);
@@ -185,12 +196,15 @@ void html_convert_css_callback(fetchcache_msg msg, struct content *css,
void html_title(struct content *c, xmlNode *head)
{
xmlNode *node;
+ xmlChar *title;
c->title = 0;
for (node = head->children; node != 0; node = node->next) {
if (strcmp(node->name, "title") == 0) {
- c->title = xmlNodeGetContent(node);
+ title = xmlNodeGetContent(node);
+ c->title = squash_tolat1(title);
+ free(title);
return;
}
}
@@ -207,6 +221,9 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
c->data.html.stylesheet_url[0] = "file:///%3CNetSurf$Dir%3E/Resources/CSS";
c->data.html.stylesheet_count = 1;
+ if (head == 0)
+ return;
+
for (node = head->children; node != 0; node = node->next) {
if (strcmp(node->name, "link") == 0) {
/* rel='stylesheet' */
@@ -218,18 +235,19 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
}
free(rel);
- /* type='text/css' */
- if (!(type = (char *) xmlGetProp(node, (const xmlChar *) "type")))
- continue;
- if (strcmp(type, "text/css") != 0) {
+ /* type='text/css' or not present */
+ if ((type = (char *) xmlGetProp(node, (const xmlChar *) "type"))) {
+ if (strcmp(type, "text/css") != 0) {
+ free(type);
+ continue;
+ }
free(type);
- continue;
}
- free(type);
- /* media='screen' or not present */
+ /* media contains 'screen' or 'all' or not present */
if ((media = (char *) xmlGetProp(node, (const xmlChar *) "media"))) {
- if (strcasecmp(media, "screen") != 0) {
+ if (strstr(media, "screen") == 0 &&
+ strstr(media, "all") == 0) {
free(media);
continue;
}
@@ -255,7 +273,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
void html_revive(struct content *c, unsigned int width, unsigned int height)
{
- /* TODO: reload stylesheets and images and fix any pointers to them */
+ /* TODO: reload images and fix any pointers to them */
layout_document(c->data.html.layout->children, width);
c->width = c->data.html.layout->children->width;
c->height = c->data.html.layout->children->height;
@@ -280,5 +298,4 @@ void html_destroy(struct content *c)
font_free_set(c->data.html.fonts);
if (c->title != 0)
xfree(c->title);
- /* TODO: stylesheets */
}
diff --git a/riscos/gui.c b/riscos/gui.c
index c8f293f51..9ed95d2a2 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -1,5 +1,5 @@
/**
- * $Id: gui.c,v 1.24 2003/04/10 21:44:45 bursa Exp $
+ * $Id: gui.c,v 1.25 2003/04/11 21:06:51 bursa Exp $
*/
#include "netsurf/riscos/font.h"
@@ -20,6 +20,8 @@
#include <time.h>
#include <math.h>
+const char *__dynamic_da_name = "NetSurf";
+
int gadget_subtract_x;
int gadget_subtract_y;
#define browser_menu_flags (wimp_ICON_TEXT | wimp_ICON_FILLED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT))
diff --git a/utils/utils.c b/utils/utils.c
index 47c90a4c0..a2fab4e12 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -1,11 +1,12 @@
/**
- * $Id: utils.c,v 1.7 2003/04/05 21:38:06 bursa Exp $
+ * $Id: utils.c,v 1.8 2003/04/11 21:06:51 bursa Exp $
*/
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include "libxml/encoding.h"
#include "libxml/uri.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
@@ -98,6 +99,40 @@ char * squash_whitespace(const char * s)
return c;
}
+char * tolat1(xmlChar * s)
+{
+ unsigned int length = strlen((char*) s);
+ char *d = xcalloc(length + 1, sizeof(char));
+ char *d0 = d;
+ int u, chars;
+
+ while (*s != 0) {
+ chars = length;
+ u = xmlGetUTF8Char((unsigned char *) s, &chars);
+ s += chars;
+ length -= chars;
+ if (u == 0x09 || u == 0x0a || u == 0x0d)
+ *d = ' ';
+ else if ((0x20 <= u && u <= 0x7f) || (0xa0 <= u && u <= 0xff))
+ *d = u;
+ else
+ *d = '?';
+ d++;
+ }
+ *d = 0;
+
+ return d0;
+}
+
+char *squash_tolat1(xmlChar *s)
+{
+ /* TODO: optimize */
+ char *lat1 = tolat1(s);
+ char *squash = squash_whitespace(lat1);
+ free(lat1);
+ return squash;
+}
+
char *url_join(const char* new, const char* base)
{
char* ret;
diff --git a/utils/utils.h b/utils/utils.h
index c55ab5b69..0a3540938 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -1,11 +1,12 @@
/**
- * $Id: utils.h,v 1.6 2003/04/05 21:38:06 bursa Exp $
+ * $Id: utils.h,v 1.7 2003/04/11 21:06:51 bursa Exp $
*/
#ifndef _NETSURF_UTILS_UTILS_H_
#define _NETSURF_UTILS_UTILS_H_
#include <stdlib.h>
+#include "libxml/encoding.h"
void die(const char * const error);
char * strip(char * const s);
@@ -16,6 +17,8 @@ void xfree(void* p);
char * xstrdup(const char * const s);
char * load(const char * const path);
char * squash_whitespace(const char * s);
+char * tolat1(xmlChar * s);
+char *squash_tolat1(xmlChar *s);
char *url_join(const char* new, const char* base);
#endif