summaryrefslogtreecommitdiff
path: root/debug/netsurfd.c
blob: 4a7f978bd33536c277e615a6a0a4711e1c11a2f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * 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 James Bursa <bursa@users.sourceforge.net>
 */

#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include "netsurf/utils/config.h"
#include "netsurf/content/fetch.h"
#include "netsurf/content/content.h"
#include "netsurf/content/fetchcache.h"
#include "netsurf/desktop/gui.h"
#include "netsurf/desktop/options.h"
#include "netsurf/desktop/textinput.h"
#include "netsurf/image/bitmap.h"
#include "netsurf/render/box.h"
#include "netsurf/riscos/save_complete.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/messages.h"
#include "netsurf/utils/url.h"
#include "netsurf/utils/utils.h"

int done, destroyed;
bool print_active = false;
void *hotlist_toolbar = NULL;
void *hotlist_window = NULL;
struct browser_window *current_redraw_browser = NULL;
struct gui_window *search_current_window = NULL;

#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>";
char *default_stylesheet_url = "file:/<NetSurf$Dir>/Resources/CSS";
char *adblock_stylesheet_url = "file:/<NetSurf$Dir>/Resources/AdBlock";
#endif

static void callback(content_msg msg, struct content *c, void *p1,
		void *p2,  union content_msg_data data);


int main(int argc, char *argv[])
{
	char url[1000];
	struct content *c;

#ifndef riscos
	default_stylesheet_url = malloc(200);
	adblock_stylesheet_url = malloc(200);
	getcwd(url, sizeof url);
	snprintf(default_stylesheet_url, 200, "file:%s/ns.css", url);
	snprintf(adblock_stylesheet_url, 200, "file:%s/AdBlock", url);
#endif

	fetch_init();
	fetchcache_init();
	url_init();
	options_read("options");
	messages_load("messages");

	while (1) {
		puts("=== URL:");
		if (!fgets(url, 1000, stdin))
			break;
		url[strlen(url) - 1] = 0;
		destroyed = 0;
		c = fetchcache(url, callback, 0, 0, 1000, 1000, false,
				0, 0, true, false);
		if (c) {
			fetchcache_go(c, 0, callback, 0, 0, 1000, 1000,
					0, 0, true);
			done = c->status == CONTENT_STATUS_DONE;
			while (!done)
				fetch_poll();
			puts("=== SUCCESS, dumping cache");
		} else {
			destroyed = 1;
			puts("=== FAILURE, dumping cache");
		}
		if (!destroyed) {
			/*while (1)
				schedule_run();*/
/* 			content_reformat(c, 1, 1000); */
/*			save_complete(c, "save_complete");*/
			if (c->type == CONTENT_HTML)
				box_dump(c->data.html.layout, 0);
			else if (c->type == CONTENT_CSS)
				css_dump_stylesheet(c->data.css.css);
			else if (c->type == CONTENT_GIF)
				gif_decode_frame(c->data.gif.gif, 0);
			/*else if (c->type == CONTENT_MNG)
				nsmng_animate(c);*/
			content_remove_user(c, callback, 0, 0);
			c = 0;
		}
		content_clean();
	}

/* 	options_write("options"); */
	fetch_quit();

	return 0;
}


void callback(content_msg msg, struct content *c, void *p1,
	      void *p2,  union content_msg_data data)
{
	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);
		else if (msg == CONTENT_MSG_REDIRECT) {
			printf("=== REDIRECT to '%s'\n", data.redirect);
			done = destroyed = 1;
		}
}


void gui_multitask(void)
{
/* 	putchar('-'); */
}


void die(const char *error)
{
	printf("die: %s\n", error);
	exit(1);
}


void warn_user(const char *warning, const char *detail)
{
	printf("WARNING: %s %s\n", warning, detail);
}


#ifdef WITH_PLUGIN
void plugin_msg_parse(wimp_message *message, int ack) {}
bool plugin_create(struct content *c, const char *params[]) {return true;}
bool plugin_convert(struct content *c, int width, int height) {return true;}
void plugin_reformat(struct content *c, int width, int height) {}
void plugin_destroy(struct content *c) {}
bool plugin_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) {return true;}
void plugin_open(struct content *c, struct browser_window *bw,
		struct content *page, struct box *box,
		struct object_params *params) {}
void plugin_close(struct content *c) {}
bool plugin_handleable(const char *mime_type) {return false;}
#endif

#ifndef riscos
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) {}
#endif

void tree_initialise_redraw(struct tree *tree) {}
void tree_redraw_area(struct tree *tree, int x, int y, int width, int height) {}
void tree_draw_line(int x, int y, int width, int height) {}
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) {}
void tree_update_URL_node(struct node *node, struct url_content *data) {}
void tree_resized(struct tree *tree) {}
void tree_set_node_sprite_folder(struct node *node) {}

#ifndef riscos
void schedule(int t, void (*callback)(void *p), void *p) {}
void schedule_remove(void (*callback)(void *p), void *p) {}
void schedule_run(void) {}
#endif

bool selection_highlighted(struct selection *s, struct box *box,
		unsigned *start_idx, unsigned *end_idx) { return false; }
bool gui_search_term_highlighted(struct gui_window *g,
		unsigned start_offset, unsigned end_offset,
		unsigned *start_idx, unsigned *end_idx) { return false; }

const char *local_encoding_name(void) { return "ISO-8859-1"; }

struct caret ghost_caret;