netsurf/desktop/netsurf.c
John Mark Bell f3e6ad3e90 Attempt to perform content cleaning far less frequently.
svn path=/trunk/netsurf/; revision=3156
2007-01-30 00:44:53 +00:00

147 lines
3.0 KiB
C

/*
* This file is part of NetSurf, http://netsurf-browser.org/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk>
*/
#include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
#include "netsurf/utils/config.h"
#include "netsurf/content/fetch.h"
#include "netsurf/content/fetchcache.h"
#include "netsurf/content/urldb.h"
#include "netsurf/desktop/netsurf.h"
#include "netsurf/desktop/browser.h"
#include "netsurf/desktop/gui.h"
#ifdef riscos
#include "netsurf/riscos/buffer.h"
#endif
#include "netsurf/utils/log.h"
#include "netsurf/utils/url.h"
#include "netsurf/utils/utf8.h"
#include "netsurf/utils/utils.h"
bool netsurf_quit = false;
static void netsurf_init(int argc, char** argv);
static void netsurf_poll(void);
static void netsurf_exit(void);
static void lib_init(void);
static void content_clean_wrapper(void *p);
#define CONTENT_CLEAN_FREQ (500) /* cs */
/**
* Gui NetSurf main().
*/
int main(int argc, char** argv)
{
setbuf(stderr, NULL);
netsurf_init(argc, argv);
while (!netsurf_quit)
netsurf_poll();
netsurf_exit();
return EXIT_SUCCESS;
}
/**
* Initialise components used by gui NetSurf.
*/
void netsurf_init(int argc, char** argv)
{
struct utsname utsname;
stdout = stderr;
#ifdef _MEMDEBUG_H_
memdebug_memdebug("memdump");
#endif
LOG(("version '%s'", netsurf_version));
if (uname(&utsname) != 0)
LOG(("Failed to extract machine information"));
else
LOG(("NetSurf on <%s>, node <%s>, release <%s>, version <%s>, "
"machine <%s>", utsname.sysname,
utsname.nodename, utsname.release,
utsname.version, utsname.machine));
lib_init();
url_init();
gui_init(argc, argv);
setlocale(LC_ALL, "");
fetch_init();
fetchcache_init();
gui_init2(argc, argv);
schedule(CONTENT_CLEAN_FREQ, content_clean_wrapper, NULL);
}
/**
* Poll components which require it.
*/
void netsurf_poll(void)
{
gui_poll(fetch_active);
fetch_poll();
}
/**
* Clean up components used by gui NetSurf.
*/
void netsurf_exit(void)
{
schedule_remove(content_clean_wrapper, NULL);
LOG(("Closing GUI"));
gui_quit();
LOG(("Closing content"));
content_quit();
LOG(("Closing fetches"));
fetch_quit();
LOG(("Closing utf8"));
utf8_finalise();
LOG(("Destroying URLdb"));
urldb_destroy();
LOG(("Exited successfully"));
}
/**
* Initialises the libraries used in NetSurf.
*/
static void lib_init(void)
{
/* Using encoding "X-SJIS" (unknown to libxmp2/iconv) instead as
* "Shift-JIS" is rather popular.
*/
if (xmlAddEncodingAlias(xmlGetCharEncodingName(XML_CHAR_ENCODING_SHIFT_JIS), "X-SJIS") != 0)
die("Failed to add encoding alias");
}
/**
* Wrapper for content cleaner callback
*/
static void content_clean_wrapper(void *p)
{
content_clean();
schedule(CONTENT_CLEAN_FREQ, content_clean_wrapper, NULL);
}