diff --git a/amiga/gui.c b/amiga/gui.c index 01f149c31..ab94e8ca0 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -540,6 +540,13 @@ nsurl *gui_get_resource_url(const char *path) return url; } +/* Documented in desktop/options.h */ +void gui_options_init_defaults(void) +{ + /* Set defaults for absent option strings */ + ami_set_options(); /* check options and set defaults where required */ +} + void gui_init(int argc, char** argv) { BPTR lock = 0; @@ -549,8 +556,6 @@ void gui_init(int argc, char** argv) ami_clipboard_init(); ami_openurl_open(); - ami_set_options(); /* check options and set defaults where required */ - win_destroyed = false; nsscreentitle = ASPrintf("NetSurf %s",netsurf_version); diff --git a/atari/gui.c b/atari/gui.c index a2dac21d3..c2158e05e 100755 --- a/atari/gui.c +++ b/atari/gui.c @@ -553,12 +553,12 @@ gui_window_remove_caret(struct gui_window *w) void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) -{ - struct bitmap *bmp_icon; +{ + struct bitmap *bmp_icon; - bmp_icon = (icon != NULL) ? content_get_bitmap(icon) : NULL; - - window_set_icon(g, bmp_icon); + bmp_icon = (icon != NULL) ? content_get_bitmap(icon) : NULL; + + window_set_icon(g, bmp_icon); } void @@ -911,6 +911,17 @@ nsurl *gui_get_resource_url(const char *path) return url; } +/* Documented in desktop/options.h */ +void gui_options_init_defaults(void) +{ + /* Set defaults for absent option strings */ + nsoption_setnull_charp(cookie_file, strdup("cookies")); + + if (nsoption_charp(cookie_file) == NULL) { + die("Failed initialising string options"); + } +} + static void gui_init(int argc, char** argv) { char buf[PATH_MAX]; @@ -961,9 +972,6 @@ static void gui_init(int argc, char** argv) urldb_load(nsoption_charp(url_file)); } - if (nsoption_charp(cookie_file) == NULL ){ - nsoption_set_charp(cookie_file, (char*)"cookies"); - } LOG(("Loading cookies from: %s", nsoption_charp(cookie_file) )); if( strlen(nsoption_charp(cookie_file)) ){ urldb_load_cookies(nsoption_charp(cookie_file)); diff --git a/beos/gui.cpp b/beos/gui.cpp index dc3c33538..b275616f5 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -475,6 +475,12 @@ int main(int argc, char** argv) return 0; } +/* Documented in desktop/options.h */ +void gui_options_init_defaults(void) +{ + /* Set defaults for absent option strings */ +} + void gui_init(int argc, char** argv) { diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 65c9f8cd1..4c2dfc185 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -164,15 +164,21 @@ void cocoa_autorelease( void ) pool = [[NSAutoreleasePool alloc] init]; } +/* Documented in desktop/options.h */ +void gui_options_init_defaults(void) +{ + /* Set defaults for absent option strings */ + const char * const ca_bundle = [[[NSBundle mainBundle] pathForResource: @"ca-bundle" ofType: @""] UTF8String]; + + nsoption_setnull_charp(ca_bundle, strdup(ca_bundle)); +} + int main( int argc, char **argv ) { cocoa_autorelease(); const char * const messages = [[[NSBundle mainBundle] pathForResource: @"Messages" ofType: @""] UTF8String]; const char * const options = cocoa_get_options_file(); - const char * const ca_bundle = [[[NSBundle mainBundle] pathForResource: @"ca-bundle" ofType: @""] UTF8String]; - - nsoption_setnull_charp(ca_bundle, strdup(ca_bundle)); netsurf_init(&argc, &argv, options, messages); diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 65765fae4..0b1cffe0a 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -166,6 +166,7 @@ nserror netsurf_init(int *pargc, LOG(("Using '%s' for Options file", options)); nsoption_read(options); + gui_options_init_defaults(); messages_load(messages); diff --git a/desktop/options.h b/desktop/options.h index b96aaec52..53c025c18 100644 --- a/desktop/options.h +++ b/desktop/options.h @@ -114,13 +114,16 @@ extern struct ns_options nsoptions; } \ } while (0) -#define nsoption_setnull_charp(OPTION, VALUE) do { \ - if (nsoptions.OPTION == NULL) { \ +#define nsoption_setnull_charp(OPTION, VALUE) \ + do { \ + if (nsoptions.OPTION == NULL) { \ nsoptions.OPTION = VALUE; \ if (*nsoptions.OPTION == 0) { \ free(nsoptions.OPTION); \ nsoptions.OPTION = NULL; \ } \ + } else { \ + free(VALUE); \ } \ } while (0) @@ -175,5 +178,10 @@ int nsoption_snoptionf(char *string, size_t size, unsigned int option, */ void nsoption_commandline(int *pargc, char **argv); +/** + * Set default values for unset front-end specific options + */ +void gui_options_init_defaults(void); + #endif diff --git a/framebuffer/gui.c b/framebuffer/gui.c index b8bb5cede..0f3f7b921 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -476,26 +476,27 @@ process_cmdline(int argc, char** argv) return true; } +/* Documented in desktop/options.h */ +void gui_options_init_defaults(void) +{ + /* Set defaults for absent option strings */ + nsoption_setnull_charp(cookie_file, strdup("~/.netsurf/Cookies")); + nsoption_setnull_charp(cookie_jar, strdup("~/.netsurf/Cookies")); + + if (nsoption_charp(cookie_file) == NULL || + nsoption_charp(cookie_jar == NULL)) { + die("Failed initialising cookie options"); + } +} + static void gui_init(int argc, char** argv) { nsfb_t *nsfb; + /* Override, since we have no support for non-core SELECT menu */ nsoption_set_bool(core_select_menu, true); - if (nsoption_charp(cookie_file) == NULL) { - nsoption_set_charp(cookie_file, strdup("~/.netsurf/Cookies")); - LOG(("Using '%s' as Cookies file", nsoption_charp(cookie_file))); - } - - if (nsoption_charp(cookie_jar) == NULL) { - nsoption_set_charp(cookie_jar, strdup("~/.netsurf/Cookies")); - LOG(("Using '%s' as Cookie Jar file", nsoption_charp(cookie_jar))); - } - - if (nsoption_charp(cookie_file) == NULL || nsoption_charp(cookie_jar == NULL)) - die("Failed initialising cookie options"); - if (process_cmdline(argc,argv) != true) die("unable to process command line.\n"); diff --git a/gtk/gui.c b/gtk/gui.c index b24fecfb8..891910407 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -241,11 +241,49 @@ nsgtk_init_glade(char **respath) widWarning = GTK_WIDGET(gtk_builder_get_object(gladeWarning, "labelWarning")); } -static void check_options(char **respath) +/* Documented in desktop/options.h */ +void gui_options_init_defaults(void) { char *hdir = getenv("HOME"); char buf[PATH_MAX]; + /* Set defaults for absent option strings */ + snprintf(buf, PATH_MAX, "%s/.netsurf/Cookies", hdir); + nsoption_setnull_charp(cookie_file, strdup(buf)); + nsoption_setnull_charp(cookie_jar, strdup(buf)); + if (nsoption_charp(cookie_file) == NULL || + nsoption_charp(cookie_jar) == NULL) + die("Failed initialising cookie options"); + + if (nsoption_charp(downloads_directory) == NULL) { + snprintf(buf, PATH_MAX, "%s/", hdir); + nsoption_set_charp(downloads_directory, strdup(buf)); + } + + if (nsoption_charp(url_file) == NULL) { + snprintf(buf, PATH_MAX, "%s/.netsurf/URLs", hdir); + nsoption_set_charp(url_file, strdup(buf)); + } + + if (nsoption_charp(hotlist_path) == NULL) { + snprintf(buf, PATH_MAX, "%s/.netsurf/Hotlist", hdir); + nsoption_set_charp(hotlist_path, strdup(buf)); + } + + nsoption_setnull_charp(ca_path, strdup("/etc/ssl/certs")); + + if (nsoption_charp(url_file) == NULL || + nsoption_charp(ca_path) == NULL || + nsoption_charp(downloads_directory) == NULL || + nsoption_charp(hotlist_path) == NULL) { + die("Failed initialising string options"); + } +} + +static void check_options(char **respath) +{ + char *hdir = getenv("HOME"); + char buf[PATH_MAX]; nsoption_set_bool(core_select_menu, true); /* Attempt to handle nonsense status bar widths. These may exist @@ -259,57 +297,13 @@ static void check_options(char **respath) } /* user options should be stored in the users home directory */ - snprintf(buf, PATH_MAX, "%s/.netsurf/Choices", hdir); + snprintf(buf, PATH_MAX, "%s/.netsurf/Choices", hdir); options_file_location = strdup(buf); - - /* VRS - I do not beleive these setting should search the - * resource path, they should just be set to the default - * values! - */ - if (nsoption_charp(cookie_file) == NULL) { - filepath_sfinddef(respath, buf, "Cookies", "~/.netsurf/"); - LOG(("Using '%s' as Cookies file", buf)); - nsoption_set_charp(cookie_file, strdup(buf)); - } - if (nsoption_charp(cookie_jar) == NULL) { - filepath_sfinddef(respath, buf, "Cookies", "~/.netsurf/"); - LOG(("Using '%s' as Cookie Jar file", buf)); - nsoption_set_charp(cookie_jar, strdup(buf)); - } - if (nsoption_charp(cookie_file) == NULL || - nsoption_charp(cookie_jar) == NULL) - die("Failed initialising cookie options"); - - if (nsoption_charp(url_file) == NULL) { - filepath_sfinddef(respath, buf, "URLs", "~/.netsurf/"); - LOG(("Using '%s' as URL file", buf)); - nsoption_set_charp(url_file, strdup(buf)); - } - - if (nsoption_charp(ca_path) == NULL) { - filepath_sfinddef(respath, buf, "certs", "/etc/ssl/"); - LOG(("Using '%s' as certificate path", buf)); - nsoption_set_charp(ca_path, strdup(buf)); - } - - if (nsoption_charp(downloads_directory) == NULL) { - LOG(("Using '%s' as download directory", hdir)); - nsoption_set_charp(downloads_directory, strdup(hdir)); - } filepath_sfinddef(respath, buf, "icons/", "~/.netsurf/"); LOG(("Using '%s' as Tree icons dir", buf)); tree_set_icon_dir(strdup(buf)); - if (nsoption_charp(hotlist_path) == NULL) { - filepath_sfinddef(respath, buf, "Hotlist", "~/.netsurf/"); - LOG(("Using '%s' as Hotlist file", buf)); - nsoption_set_charp(hotlist_path, strdup(buf)); - } - if (nsoption_charp(hotlist_path) == NULL) - die("Failed initialising hotlist option"); - - filepath_sfinddef(respath, buf, "Print", "~/.netsurf/"); LOG(("Using '%s' as Print Settings file", buf)); print_options_file_location = strdup(buf); diff --git a/monkey/main.c b/monkey/main.c index 45be754e1..03421ef03 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -91,6 +91,12 @@ static void quit_handler(int argc, char **argv) netsurf_quit = true; } +/* Documented in desktop/options.h */ +void gui_options_init_defaults(void) +{ + /* Set defaults for absent option strings */ +} + int main(int argc, char **argv) { diff --git a/riscos/gui.c b/riscos/gui.c index d689094ab..93fc3db65 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -328,6 +328,47 @@ nsurl *gui_get_resource_url(const char *path) return url; } +/* Documented in desktop/options.h */ +void gui_options_init_defaults(void) +{ + /* Set defaults for absent option strings */ + nsoption_setnull_charp(theme, strdup("Aletheia")); + nsoption_setnull_charp(toolbar_browser, strdup("0123|58|9")); + nsoption_setnull_charp(toolbar_hotlist, strdup("40|12|3")); + nsoption_setnull_charp(toolbar_history, strdup("0|12|3")); + nsoption_setnull_charp(toolbar_cookies, strdup("0|12")); + nsoption_setnull_charp(ca_bundle, strdup("NetSurf:Resources.ca-bundle")); + nsoption_setnull_charp(cookie_file, strdup("NetSurf:Cookies")); + nsoption_setnull_charp(cookie_jar, strdup(CHOICES_PREFIX "Cookies")); + nsoption_setnull_charp(url_path, strdup("NetSurf:URL")); + nsoption_setnull_charp(url_save, strdup(CHOICES_PREFIX "URL")); + nsoption_setnull_charp(hotlist_path, strdup("NetSurf:Hotlist")); + nsoption_setnull_charp(hotlist_save, strdup(CHOICES_PREFIX "Hotlist")); + nsoption_setnull_charp(recent_path, strdup("NetSurf:Recent")); + nsoption_setnull_charp(recent_save, strdup(CHOICES_PREFIX "Recent")); + nsoption_setnull_charp(theme_path, strdup("NetSurf:Themes")); + nsoption_setnull_charp(theme_save, strdup(CHOICES_PREFIX "Themes")); + + if (nsoption_charp(theme) == NULL || + nsoption_charp(toolbar_browser) == NULL || + nsoption_charp(toolbar_hotlist) == NULL || + nsoption_charp(toolbar_history) == NULL || + nsoption_charp(toolbar_cookies) == NULL || + nsoption_charp(ca_bundle) == NULL || + nsoption_charp(cookie_file) == NULL || + nsoption_charp(cookie_jar) == NULL || + nsoption_charp(url_path) == NULL || + nsoption_charp(url_save) == NULL || + nsoption_charp(hotlist_path) == NULL || + nsoption_charp(hotlist_save) == NULL || + nsoption_charp(recent_path) == NULL || + nsoption_charp(recent_save) == NULL || + nsoption_charp(theme_path) == NULL || + nsoption_charp(theme_save) == NULL) { + die("Failed initialising string options"); + } +} + /** * Initialise the gui (RISC OS specific part). */ @@ -347,6 +388,7 @@ static void gui_init(int argc, char** argv) int length; char *nsdir_temp; byte *base; + char *tree_icons_dir; /* re-enable all FPU exceptions/traps except inexact operations, * which we're not interested in, and underflow which is incorrectly @@ -375,42 +417,11 @@ static void gui_init(int argc, char** argv) ro_plot_patterned_lines = false; } - /* Set defaults for absent option strings */ - nsoption_setnull_charp(theme, strdup("Aletheia")); - nsoption_setnull_charp(toolbar_browser, strdup("0123|58|9")); - nsoption_setnull_charp(toolbar_hotlist, strdup("40|12|3")); - nsoption_setnull_charp(toolbar_history, strdup("0|12|3")); - nsoption_setnull_charp(toolbar_cookies, strdup("0|12")); - nsoption_setnull_charp(ca_bundle, strdup("NetSurf:Resources.ca-bundle")); - nsoption_setnull_charp(cookie_file, strdup("NetSurf:Cookies")); - nsoption_setnull_charp(cookie_jar, strdup(CHOICES_PREFIX "Cookies")); - nsoption_setnull_charp(url_path, strdup("NetSurf:URL")); - nsoption_setnull_charp(url_save, strdup(CHOICES_PREFIX "URL")); - nsoption_setnull_charp(hotlist_path, strdup("NetSurf:Hotlist")); - nsoption_setnull_charp(hotlist_save, strdup(CHOICES_PREFIX "Hotlist")); - nsoption_setnull_charp(recent_path, strdup("NetSurf:Recent")); - nsoption_setnull_charp(recent_save, strdup(CHOICES_PREFIX "Recent")); - nsoption_setnull_charp(theme_path, strdup("NetSurf:Themes")); - nsoption_setnull_charp(theme_save, strdup(CHOICES_PREFIX "Themes")); - - tree_set_icon_dir(strdup("NetSurf:Resources.Icons")); - - if (nsoption_charp(theme) == NULL || - nsoption_charp(toolbar_browser) == NULL || - nsoption_charp(toolbar_hotlist) == NULL || - nsoption_charp(toolbar_history) == NULL || - nsoption_charp(ca_bundle) == NULL || - nsoption_charp(cookie_file) == NULL || - nsoption_charp(cookie_jar) == NULL || - nsoption_charp(url_path) == NULL || - nsoption_charp(url_save) == NULL || - nsoption_charp(hotlist_path) == NULL || - nsoption_charp(hotlist_save) == NULL || - nsoption_charp(recent_path) == NULL || - nsoption_charp(recent_save) == NULL || - nsoption_charp(theme_path) == NULL || - nsoption_charp(theme_save) == NULL) + tree_icons_dir = strdup("NetSurf:Resources.Icons"); + if (tree_icons_dir == NULL) die("Failed initialising string options"); + tree_set_icon_dir(tree_icons_dir); + /* Create our choices directories */ ro_gui_create_dirs(); diff --git a/windows/main.c b/windows/main.c index 6fbf40174..7d158660a 100644 --- a/windows/main.c +++ b/windows/main.c @@ -79,6 +79,15 @@ bool nslog_ensure(FILE *fptr) return true; } +/* Documented in desktop/options.h */ +void gui_options_init_defaults(void) +{ + /* Set defaults for absent option strings */ + + /* ensure homepage option has a default */ + nsoption_setnull_charp(homepage_url, strdup(NETSURF_HOMEPAGE)); +} + /** * Entry point from operating system **/ @@ -138,9 +147,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) nsws_window_init_pointers(hInstance); - /* ensure homepage option has a default */ - nsoption_setnull_charp(homepage_url, strdup(NETSURF_HOMEPAGE)); - /* If there is a url specified on the command line use it */ if (argc > 1) { addr = argv[1];