From 6839622183b74914ed0bcb83387fedf6459e2c5c Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 17 Feb 2004 12:41:38 +0000 Subject: [PATCH] [project @ 2004-02-17 12:41:38 by jmb] Begin save complete support. Fix memory leak when using Select PNG renderer. (commented out lines can probably removed) svn path=/import/netsurf/; revision=556 --- Docs/Doxyfile | 2 +- makefile | 2 +- render/html.c | 24 +++--- riscos/png.c | 19 +++-- riscos/save_complete.c | 174 +++++++++++++++++++++++++++++++++++++++++ riscos/save_complete.h | 15 ++++ riscos/window.c | 9 ++- utils/config.h | 1 + 8 files changed, 225 insertions(+), 21 deletions(-) create mode 100644 riscos/save_complete.c create mode 100644 riscos/save_complete.h diff --git a/Docs/Doxyfile b/Docs/Doxyfile index 96fc3466c..80bcc7b9e 100644 --- a/Docs/Doxyfile +++ b/Docs/Doxyfile @@ -889,7 +889,7 @@ INCLUDE_FILE_PATTERNS = # or name=definition (no spaces). If the definition and the = are # omitted =1 is assumed. -PREDEFINED = riscos CSS_INTERNALS WITH_POST WITH_DRAW WITH_GIF WITH_JPEG WITH_PNG WITH_SPRITE WITH_PLUGIN WITH_FRAMES WITH_AUTH WITH_COOKIES WITH_ABOUT WITH_URI WITH_URL WITH_DRAW_EXPORT +PREDEFINED = riscos CSS_INTERNALS WITH_POST WITH_DRAW WITH_GIF WITH_JPEG WITH_PNG WITH_SPRITE WITH_PLUGIN WITH_FRAMES WITH_AUTH WITH_COOKIES WITH_ABOUT WITH_URI WITH_URL WITH_DRAW_EXPORT WITH_SAVE_COMPLETE # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. diff --git a/makefile b/makefile index bf453a19c..ae0f239d6 100644 --- a/makefile +++ b/makefile @@ -18,7 +18,7 @@ OBJECTS = $(OBJECTS_COMMON) \ textselection.o theme.o window.o \ draw.o gif.o jpeg.o plugin.o png.o sprite.o \ about.o filetype.o font.o uri.o url.o history.o \ - version.o save_draw.o + version.o save_draw.o save_complete.o OBJECTS_DEBUG = $(OBJECTS_COMMON) \ netsurfd.o \ options.o filetyped.o fontd.o diff --git a/render/html.c b/render/html.c index 476c8b6f2..a66346806 100644 --- a/render/html.c +++ b/render/html.c @@ -128,19 +128,9 @@ int html_convert(struct content *c, unsigned int width, unsigned int height) xml_to_box(html, c); /*box_dump(c->data.html.layout->children, 0);*/ - /* XML tree and stylesheets not required past this point */ + /* XML tree not required past this point */ xmlFreeDoc(document); - content_remove_user(c->data.html.stylesheet_content[0], - html_convert_css_callback, c, 0); - if (c->data.html.stylesheet_content[1] != 0) - content_destroy(c->data.html.stylesheet_content[1]); - for (i = 2; i != c->data.html.stylesheet_count; i++) - if (c->data.html.stylesheet_content[i] != 0) - content_remove_user(c->data.html.stylesheet_content[i], - html_convert_css_callback, c, (void*)i); - xfree(c->data.html.stylesheet_content); - /* layout the box tree */ sprintf(c->status_message, "Formatting document"); content_broadcast(c, CONTENT_MSG_STATUS, 0); @@ -660,6 +650,18 @@ void html_destroy(struct content *c) unsigned int i; LOG(("content %p", c)); + /* Remove stylesheets */ + content_remove_user(c->data.html.stylesheet_content[0], + html_convert_css_callback, c, 0); + if (c->data.html.stylesheet_content[1] != 0) + content_destroy(c->data.html.stylesheet_content[1]); + for (i = 2; i != c->data.html.stylesheet_count; i++) + if (c->data.html.stylesheet_content[i] != 0) + content_remove_user(c->data.html.stylesheet_content[i], + html_convert_css_callback, c, (void*)i); + xfree(c->data.html.stylesheet_content); + + /* and objects */ for (i = 0; i != c->data.html.object_count; i++) { LOG(("object %i %p", i, c->data.html.object[i].content)); if (c->data.html.object[i].content != 0) diff --git a/riscos/png.c b/riscos/png.c index 8105ebfe7..20597fa57 100644 --- a/riscos/png.c +++ b/riscos/png.c @@ -69,11 +69,11 @@ void nspng_init(void) void nspng_create(struct content *c, const char *params[]) { #ifndef NO_IFC - if (imagefileconvert) { +// if (imagefileconvert) { c->data.other.data = xcalloc(0, 1); c->data.other.length = 0; - return; - } +// return; +// } #endif c->data.png.sprite_area = 0; @@ -97,14 +97,14 @@ void nspng_create(struct content *c, const char *params[]) void nspng_process_data(struct content *c, char *data, unsigned long size) { #ifndef NO_IFC - if (imagefileconvert) { +// if (imagefileconvert) { c->data.png.data = xrealloc(c->data.png.data, c->data.png.length + size); memcpy(c->data.png.data + c->data.png.length, data, size); c->data.png.length += size; - c->size += size; - return; - } +// c->size += size; +// return; +// } #endif if (setjmp(png_jmpbuf(c->data.png.png))) { @@ -366,6 +366,11 @@ void nspng_destroy(struct content *c) { xfree(c->title); xfree(c->data.png.sprite_area); +#ifndef NO_IFC +// if (imagefileconvert) { + xfree(c->data.png.data); +// } +#endif } diff --git a/riscos/save_complete.c b/riscos/save_complete.c new file mode 100644 index 000000000..3b6e3a988 --- /dev/null +++ b/riscos/save_complete.c @@ -0,0 +1,174 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 John M Bell + */ + +#include + +#include /* for __riscosify */ + +#include /* possibly just have accessor methods in utils.c */ + +#include "oslib/osfile.h" + +#include "netsurf/utils/config.h" +#include "netsurf/content/content.h" +#include "netsurf/css/css.h" +#include "netsurf/render/form.h" +#include "netsurf/render/layout.h" +#include "netsurf/riscos/save_complete.h" +#include "netsurf/utils/log.h" +#include "netsurf/utils/utils.h" + +/** \todo Save out CSS. */ + +#ifdef WITH_SAVE_COMPLETE + +char* get_filename(char * url); + +/* this is temporary. */ +const char * const SAVE_PATH = ".savetest."; +const char * const OBJ_DIR = "_files"; + +/** \todo this will probably want to take a filename */ +void save_complete(struct content *c) { + + struct box *box; + char *fname = 0, *spath, *ofname; + unsigned int i; + + if (c->type != CONTENT_HTML) { + return; + } + + fname = get_filename(c->data.html.base_url); + + if (!fname) { /* no path -> exit */ + return; + } + + spath = xcalloc(strlen(SAVE_PATH)+strlen(OBJ_DIR)+strlen(fname)+50, + sizeof(char)); + + sprintf(spath, "%s%s%s", SAVE_PATH, fname, OBJ_DIR); + xosfile_create_dir(spath, 77); + + /* save stylesheets, ignoring the base sheet and