2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2004-02-13 19:09:12 +03:00
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-06-30 16:44:03 +04:00
|
|
|
*/
|
|
|
|
|
2004-03-27 03:54:03 +03:00
|
|
|
#include <assert.h>
|
2003-08-29 16:57:14 +04:00
|
|
|
#include <stdbool.h>
|
2003-06-21 17:18:00 +04:00
|
|
|
#include <string.h>
|
2004-07-29 03:13:39 +04:00
|
|
|
#include <time.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
#include "content/fetch.h"
|
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/fetchcache.h"
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/cookies.h"
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/options.h"
|
|
|
|
#include "desktop/selection.h"
|
|
|
|
#include "desktop/textinput.h"
|
|
|
|
#include "desktop/tree.h"
|
|
|
|
#include "image/bitmap.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "riscos/save_complete.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
2003-06-21 17:18:00 +04:00
|
|
|
|
2003-08-25 20:17:11 +04:00
|
|
|
int done, destroyed;
|
2007-08-07 02:17:42 +04:00
|
|
|
bool verbose_log = true;
|
2004-08-15 23:54:24 +04:00
|
|
|
bool print_active = false;
|
|
|
|
void *hotlist_toolbar = NULL;
|
|
|
|
void *hotlist_window = NULL;
|
2005-04-17 20:42:05 +04:00
|
|
|
struct browser_window *current_redraw_browser = NULL;
|
|
|
|
struct gui_window *search_current_window = NULL;
|
2003-06-21 17:18:00 +04:00
|
|
|
|
2005-01-02 14:46:29 +03:00
|
|
|
#ifndef riscos
|
|
|
|
char *default_stylesheet_url;
|
|
|
|
char *adblock_stylesheet_url;
|
|
|
|
bool option_filter_sprites = false;
|
|
|
|
bool option_dither_sprites = false;
|
|
|
|
void *plot = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef riscos
|
|
|
|
void *ro_gui_current_redraw_gui = 0;
|
|
|
|
const char *NETSURF_DIR = "<NetSurf$Dir>";
|
2006-04-12 12:09:27 +04:00
|
|
|
char *default_stylesheet_url = "file:///<NetSurf$Dir>/Resources/CSS";
|
|
|
|
char *adblock_stylesheet_url = "file:///<NetSurf$Dir>/Resources/AdBlock";
|
2005-01-02 14:46:29 +03:00
|
|
|
#endif
|
|
|
|
|
2008-05-26 14:40:00 +04:00
|
|
|
static void callback(content_msg msg, struct content *c, intptr_t p1,
|
|
|
|
intptr_t p2, union content_msg_data data);
|
2005-01-02 14:46:29 +03:00
|
|
|
|
2003-06-21 17:18:00 +04:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char url[1000];
|
|
|
|
struct content *c;
|
|
|
|
|
2005-01-02 14:46:29 +03:00
|
|
|
#ifndef riscos
|
|
|
|
default_stylesheet_url = malloc(200);
|
|
|
|
adblock_stylesheet_url = malloc(200);
|
|
|
|
getcwd(url, sizeof url);
|
2006-03-09 21:55:30 +03:00
|
|
|
snprintf(default_stylesheet_url, 200, "file:%s/ns.css", url);
|
2005-01-02 14:46:29 +03:00
|
|
|
snprintf(adblock_stylesheet_url, 200, "file:%s/AdBlock", url);
|
|
|
|
#endif
|
|
|
|
|
2003-06-21 17:18:00 +04:00
|
|
|
fetch_init();
|
2003-12-27 23:15:23 +03:00
|
|
|
fetchcache_init();
|
2004-03-27 03:54:03 +03:00
|
|
|
url_init();
|
2004-02-13 19:09:12 +03:00
|
|
|
options_read("options");
|
2004-03-27 03:54:03 +03:00
|
|
|
messages_load("messages");
|
2003-06-21 17:18:00 +04:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
puts("=== URL:");
|
2003-10-09 00:50:18 +04:00
|
|
|
if (!fgets(url, 1000, stdin))
|
2004-01-02 15:02:01 +03:00
|
|
|
break;
|
2003-10-09 00:50:18 +04:00
|
|
|
url[strlen(url) - 1] = 0;
|
|
|
|
destroyed = 0;
|
2004-06-11 04:03:11 +04:00
|
|
|
c = fetchcache(url, callback, 0, 0, 1000, 1000, false,
|
2005-01-03 05:09:20 +03:00
|
|
|
0, 0, true, false);
|
2003-07-16 21:38:46 +04:00
|
|
|
if (c) {
|
2005-04-17 20:42:05 +04:00
|
|
|
fetchcache_go(c, 0, callback, 0, 0, 1000, 1000,
|
2007-02-22 00:23:01 +03:00
|
|
|
0, 0, true, 0);
|
2003-07-16 21:38:46 +04:00
|
|
|
done = c->status == CONTENT_STATUS_DONE;
|
2007-08-20 06:39:49 +04:00
|
|
|
while (!done) {
|
2003-07-16 21:38:46 +04:00
|
|
|
fetch_poll();
|
2007-08-20 06:39:49 +04:00
|
|
|
sleep(1);
|
|
|
|
}
|
2003-07-16 21:38:46 +04:00
|
|
|
puts("=== SUCCESS, dumping cache");
|
|
|
|
} else {
|
2003-10-09 00:50:18 +04:00
|
|
|
destroyed = 1;
|
2003-07-16 21:38:46 +04:00
|
|
|
puts("=== FAILURE, dumping cache");
|
|
|
|
}
|
2004-03-27 03:54:03 +03:00
|
|
|
if (!destroyed) {
|
2004-06-03 01:01:52 +04:00
|
|
|
/*while (1)
|
|
|
|
schedule_run();*/
|
2004-03-27 03:54:03 +03:00
|
|
|
/* content_reformat(c, 1, 1000); */
|
2004-04-25 03:42:32 +04:00
|
|
|
/* save_complete(c, "save_complete");*/
|
2004-05-13 18:41:50 +04:00
|
|
|
if (c->type == CONTENT_HTML)
|
2007-08-20 06:39:49 +04:00
|
|
|
box_dump(stderr, c->data.html.layout, 0);
|
2004-05-13 18:41:50 +04:00
|
|
|
else if (c->type == CONTENT_CSS)
|
|
|
|
css_dump_stylesheet(c->data.css.css);
|
2004-06-03 01:01:52 +04:00
|
|
|
else if (c->type == CONTENT_GIF)
|
|
|
|
gif_decode_frame(c->data.gif.gif, 0);
|
2004-07-29 03:13:39 +04:00
|
|
|
/*else if (c->type == CONTENT_MNG)
|
|
|
|
nsmng_animate(c);*/
|
2003-08-25 20:17:11 +04:00
|
|
|
content_remove_user(c, callback, 0, 0);
|
2004-05-13 18:41:50 +04:00
|
|
|
c = 0;
|
2004-03-27 03:54:03 +03:00
|
|
|
}
|
2004-06-21 19:09:59 +04:00
|
|
|
content_clean();
|
2003-06-21 17:18:00 +04:00
|
|
|
}
|
|
|
|
|
2004-05-13 18:41:50 +04:00
|
|
|
/* options_write("options"); */
|
2003-06-21 17:18:00 +04:00
|
|
|
fetch_quit();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-26 14:40:00 +04:00
|
|
|
void callback(content_msg msg, struct content *c, intptr_t p1,
|
|
|
|
intptr_t p2, union content_msg_data data)
|
2003-06-21 17:18:00 +04:00
|
|
|
{
|
2005-01-02 14:46:29 +03:00
|
|
|
LOG(("content %s, message %i", c->url, msg));
|
|
|
|
if (msg == CONTENT_MSG_DONE)
|
|
|
|
done = 1;
|
|
|
|
else if (msg == CONTENT_MSG_ERROR) {
|
|
|
|
printf("=== ERROR: %s\n", data.error);
|
|
|
|
done = destroyed = 1;
|
|
|
|
} else if (msg == CONTENT_MSG_STATUS)
|
|
|
|
printf("=== STATUS: %s\n", c->status_message);
|
2003-06-21 17:18:00 +04:00
|
|
|
}
|
|
|
|
|
2005-01-02 14:46:29 +03:00
|
|
|
|
|
|
|
void gui_multitask(void)
|
2003-06-21 17:18:00 +04:00
|
|
|
{
|
2005-01-02 14:46:29 +03:00
|
|
|
/* putchar('-'); */
|
2003-06-21 17:18:00 +04:00
|
|
|
}
|
|
|
|
|
2005-01-02 14:46:29 +03:00
|
|
|
|
|
|
|
void die(const char *error)
|
2003-11-15 03:15:40 +03:00
|
|
|
{
|
2005-01-02 14:46:29 +03:00
|
|
|
printf("die: %s\n", error);
|
|
|
|
exit(1);
|
2003-11-15 03:15:40 +03:00
|
|
|
}
|
|
|
|
|
2005-01-02 14:46:29 +03:00
|
|
|
|
|
|
|
void warn_user(const char *warning, const char *detail)
|
2004-01-02 15:02:01 +03:00
|
|
|
{
|
2005-01-02 14:46:29 +03:00
|
|
|
printf("WARNING: %s %s\n", warning, detail);
|
2004-01-02 15:02:01 +03:00
|
|
|
}
|
2005-01-02 14:46:29 +03:00
|
|
|
|
2004-01-02 15:02:01 +03:00
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_PLUGIN
|
2004-01-02 15:02:01 +03:00
|
|
|
void plugin_msg_parse(wimp_message *message, int ack) {}
|
2004-08-15 23:54:24 +04:00
|
|
|
bool plugin_create(struct content *c, const char *params[]) {return true;}
|
|
|
|
bool plugin_convert(struct content *c, int width, int height) {return true;}
|
2004-06-11 04:03:11 +04:00
|
|
|
void plugin_reformat(struct content *c, int width, int height) {}
|
2004-01-02 15:02:01 +03:00
|
|
|
void plugin_destroy(struct content *c) {}
|
2004-08-15 23:54:24 +04:00
|
|
|
bool plugin_redraw(struct content *c, int x, int y,
|
2004-06-11 04:03:11 +04:00
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
2004-08-15 23:54:24 +04:00
|
|
|
float scale, unsigned long background_colour) {return true;}
|
|
|
|
void plugin_open(struct content *c, struct browser_window *bw,
|
2006-04-10 03:21:13 +04:00
|
|
|
struct content *page, unsigned int index, struct box *box,
|
2004-08-15 23:54:24 +04:00
|
|
|
struct object_params *params) {}
|
|
|
|
void plugin_close(struct content *c) {}
|
2005-01-02 14:46:29 +03:00
|
|
|
bool plugin_handleable(const char *mime_type) {return false;}
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-01-02 15:02:01 +03:00
|
|
|
|
2004-04-14 16:54:20 +04:00
|
|
|
#ifndef riscos
|
2005-01-02 14:46:29 +03:00
|
|
|
bool bitmap_get_opaque(struct bitmap *bitmap) { return false; }
|
|
|
|
bool bitmap_test_opaque(struct bitmap *bitmap) { return false; }
|
|
|
|
void bitmap_set_opaque(struct bitmap *bitmap, bool opaque) {}
|
2004-04-14 16:54:20 +04:00
|
|
|
#endif
|
2004-03-27 03:54:03 +03:00
|
|
|
|
2005-01-02 14:46:29 +03:00
|
|
|
void tree_initialise_redraw(struct tree *tree) {}
|
|
|
|
void tree_redraw_area(struct tree *tree, int x, int y, int width, int height) {}
|
2006-03-09 21:55:30 +03:00
|
|
|
void tree_draw_line(int x, int y, int width, int height) {}
|
2005-01-02 14:46:29 +03:00
|
|
|
void tree_draw_node_element(struct tree *tree, struct node_element *element) {}
|
|
|
|
void tree_draw_node_expansion(struct tree *tree, struct node *node) {}
|
|
|
|
void tree_recalculate_node_element(struct node_element *element) {}
|
2006-04-10 03:21:13 +04:00
|
|
|
void tree_update_URL_node(struct node *node, const char *url,
|
|
|
|
const struct url_data *data) {}
|
2005-01-02 14:46:29 +03:00
|
|
|
void tree_resized(struct tree *tree) {}
|
|
|
|
void tree_set_node_sprite_folder(struct node *node) {}
|
2004-08-15 23:54:24 +04:00
|
|
|
|
|
|
|
#ifndef riscos
|
2005-01-02 14:46:29 +03:00
|
|
|
void schedule(int t, void (*callback)(void *p), void *p) {}
|
|
|
|
void schedule_remove(void (*callback)(void *p), void *p) {}
|
|
|
|
void schedule_run(void) {}
|
2004-08-15 23:54:24 +04:00
|
|
|
#endif
|
2005-04-17 20:42:05 +04:00
|
|
|
|
2007-02-22 00:23:01 +03:00
|
|
|
bool selection_highlighted(struct selection *s, unsigned start, unsigned end,
|
2005-04-17 20:42:05 +04:00
|
|
|
unsigned *start_idx, unsigned *end_idx) { return false; }
|
2006-03-09 21:55:30 +03:00
|
|
|
bool gui_search_term_highlighted(struct gui_window *g,
|
|
|
|
unsigned start_offset, unsigned end_offset,
|
2005-04-17 20:42:05 +04:00
|
|
|
unsigned *start_idx, unsigned *end_idx) { return false; }
|
|
|
|
|
2006-03-10 11:08:45 +03:00
|
|
|
struct caret ghost_caret;
|
2006-07-16 05:07:29 +04:00
|
|
|
|
2006-07-23 20:49:19 +04:00
|
|
|
bool cookies_update(const char *domain, const struct cookie_data *data)
|
|
|
|
{ return true; }
|
2006-07-16 05:07:29 +04:00
|
|
|
|
|
|
|
char *url_to_path(const char *url)
|
|
|
|
{
|
|
|
|
return strdup(url + 5);
|
|
|
|
}
|
|
|
|
|
2006-11-27 00:06:14 +03:00
|
|
|
char *path_to_url(const char *path)
|
|
|
|
{
|
|
|
|
char *r = malloc(strlen(path) + 7 + 1);
|
|
|
|
|
|
|
|
strcpy(r, "file://");
|
|
|
|
strcat(r, path);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-07-16 05:07:29 +04:00
|
|
|
void tree_set_node_sprite(struct node *node, const char *sprite,
|
|
|
|
const char *expanded) { }
|