コード例 #1
0
ファイル: gui.c プロジェクト: bkeepers/cheribsd
/** Entry point from OS.
 *
 * /param argc The number of arguments in the string vector.
 * /param argv The argument string vector.
 * /return The return code to the OS
 */
int
main(int argc, char** argv)
{
	struct browser_window *bw;
	char *options;
	char *messages;
	nsurl *url;
	nserror ret;
	nsfb_t *nsfb;
	struct gui_table framebuffer_gui_table = {
		.browser = &framebuffer_browser_table,
		.window = &framebuffer_window_table,
		.clipboard = framebuffer_clipboard_table,
		.fetch = framebuffer_fetch_table,
		.utf8 = framebuffer_utf8_table,
	};

	respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH);

	/* initialise logging. Not fatal if it fails but not much we
	 * can do about it either.
	 */
	nslog_init(nslog_stream_configure, &argc, argv);

	/* user options setup */
	ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
	if (ret != NSERROR_OK) {
		die("Options failed to initialise");
	}
	options = filepath_find(respaths, "Choices");
	nsoption_read(options, nsoptions);
	free(options);
	nsoption_commandline(&argc, argv, nsoptions);

	/* common initialisation */
	messages = filepath_find(respaths, "Messages");
	ret = netsurf_init(messages, &framebuffer_gui_table);
	free(messages);
	if (ret != NSERROR_OK) {
		die("NetSurf failed to initialise");
	}

	/* Override, since we have no support for non-core SELECT menu */
	nsoption_set_bool(core_select_menu, true);

	if (process_cmdline(argc,argv) != true)
		die("unable to process command line.\n");

	nsfb = framebuffer_initialise(fename, fewidth, feheight, febpp);
	if (nsfb == NULL)
		die("Unable to initialise framebuffer");

	framebuffer_set_cursor(&pointer_image);

	if (fb_font_init() == false)
		die("Unable to initialise the font system");

	fbtk = fbtk_init(nsfb);

	fbtk_enable_oskb(fbtk);

	urldb_load_cookies(nsoption_charp(cookie_file));

	/* create an initial browser window */

	LOG(("calling browser_window_create"));

	ret = nsurl_create(feurl, &url);
	if (ret == NSERROR_OK) {
		ret = browser_window_create(BW_CREATE_HISTORY,
					      url,
					      NULL,
					      NULL,
					      &bw);
		nsurl_unref(url);
	}
	if (ret != NSERROR_OK) {
		warn_user(messages_get_errorcode(ret), 0);
	} else {
		netsurf_main_loop();

		browser_window_destroy(bw);
	}

	netsurf_exit();

	if (fb_font_finalise() == false)
		LOG(("Font finalisation failed."));

	/* finalise options */
	nsoption_finalise(nsoptions, nsoptions_default);

	return 0;
}
コード例 #2
0
ファイル: gui.c プロジェクト: mmuman/NetSurf
/**
 * Main entry point from OS.
 */
int main(int argc, char** argv)
{
	char *cache_home = NULL;
	nserror ret;
	struct netsurf_table nsgtk_table = {
		.misc = &nsgtk_misc_table,
		.window = nsgtk_window_table,
		.clipboard = nsgtk_clipboard_table,
		.download = nsgtk_download_table,
		.fetch = nsgtk_fetch_table,
		.llcache = filesystem_llcache_table,
		.search = nsgtk_search_table,
		.search_web = nsgtk_search_web_table,
		.bitmap = nsgtk_bitmap_table,
		.layout = nsgtk_layout_table,
	};

	ret = netsurf_register(&nsgtk_table);
	if (ret != NSERROR_OK) {
		die("NetSurf operation table failed registration\n");
	}

	/* Locate the correct user configuration directory path */
	ret = get_config_home(&nsgtk_config_home);
	if (ret == NSERROR_NOT_FOUND) {
		/* no config directory exists yet so try to create one */
		ret = create_config_home(&nsgtk_config_home);
	}
	if (ret != NSERROR_OK) {
		LOG("Unable to locate a configuration directory.");
		nsgtk_config_home = NULL;
	}

	/* Initialise gtk */
	gtk_init(&argc, &argv);

	/* initialise logging. Not fatal if it fails but not much we
	 * can do about it either.
	 */
	nslog_init(nslog_stream_configure, &argc, argv);

	/* build the common resource path list */
	respaths = nsgtk_init_resource_path(nsgtk_config_home);
	if (respaths == NULL) {
		fprintf(stderr, "Unable to locate resources\n");
		return 1;
	}

	/* initialise the gtk resource handling */
	ret = nsgtk_init_resources(respaths);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "GTK resources failed to initialise (%s)\n",
			messages_get_errorcode(ret));
		return 1;
	}

	/* Initialise user options */
	ret = nsgtk_option_init(&argc, argv);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "Options failed to initialise (%s)\n",
			messages_get_errorcode(ret));
		return 1;
	}

	/* Initialise translated messages */
	ret = nsgtk_messages_init(respaths);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "Unable to load translated messages (%s)\n",
			messages_get_errorcode(ret));
		LOG("Unable to load translated messages");
		/** \todo decide if message load faliure should be fatal */
	}

	/* Locate the correct user cache directory path */
	ret = get_cache_home(&cache_home);
	if (ret == NSERROR_NOT_FOUND) {
		/* no cache directory exists yet so try to create one */
		ret = create_cache_home(&cache_home);
	}
	if (ret != NSERROR_OK) {
		LOG("Unable to locate a cache directory.");
	}

	/* core initialisation */
	ret = netsurf_init(cache_home);
	free(cache_home);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "NetSurf core failed to initialise (%s)\n",
			messages_get_errorcode(ret));
		return 1;
	}

	/* run the browser */
	ret = nsgtk_init(argc, argv, respaths);
	if (ret != NSERROR_OK) {
		fprintf(stderr, "NetSurf gtk initialise failed (%s)\n",
			messages_get_errorcode(ret));
	} else {
		nsgtk_main();
	}

	/* common finalisation */
	netsurf_exit();

	/* finalise options */
	nsoption_finalise(nsoptions, nsoptions_default);

	return 0;
}