[project @ 2003-06-08 04:00:05 by jmb]

Cope with broken Choices file.

svn path=/import/netsurf/; revision=178
This commit is contained in:
John Mark Bell 2003-06-08 04:00:05 +00:00
parent dfdf69fc91
commit bdad21d51c
2 changed files with 44 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/**
* $Id: gui.c,v 1.30 2003/06/04 18:42:13 jmb Exp $
* $Id: gui.c,v 1.31 2003/06/08 04:00:05 jmb Exp $
*/
#include "netsurf/desktop/options.h"
@ -1104,6 +1104,10 @@ void gui_init(int argc, char** argv)
wimp_icon_create iconbar;
wimp_version_no version;
char theme_fname[256];
int *varsize;
char *var;
os_error *e;
fileswitch_object_type *ot;
/* __riscosify_control = __RISCOSIFY_NO_PROCESS; */
@ -1119,10 +1123,35 @@ void gui_init(int argc, char** argv)
strcpy(iconbar.icon.data.sprite, "!netsurf");
ro_gui_iconbar_i = wimp_create_icon(&iconbar);
if (OPTIONS.theme != NULL)
sprintf(theme_fname, "<NetSurf$Dir>.Themes.%s", OPTIONS.theme);
else
if (OPTIONS.theme != NULL) {
/* get size of <netsurf$dir> */
e = xos_read_var_val_size ("NetSurf$Dir",0,os_VARTYPE_STRING,
&varsize, NULL, NULL);
var = xcalloc((~((int)varsize) + 10),sizeof(char));
/* get real value of <netsurf$dir> */
e = xos_read_var_val ("NetSurf$Dir", var, (~(int)varsize), 0,
os_VARTYPE_STRING, NULL, NULL, NULL);
strcat(var, ".Themes.");
/* check if theme directory exists */
e = xosfile_read_stamped_path ((const char*)OPTIONS.theme,
(const char*)var,
&ot, NULL, NULL, NULL, NULL, NULL);
xfree(var);
/* yes -> use this theme */
if (ot != fileswitch_NOT_FOUND && ot == fileswitch_IS_DIR) {
sprintf(theme_fname, "<NetSurf$Dir>.Themes.%s", OPTIONS.theme);
}
/* no -> use default theme */
else {
OPTIONS.theme = strdup("Default");
sprintf(theme_fname, "<NetSurf$Dir>.Themes.Default");
}
}
else {
sprintf(theme_fname, "<NetSurf$Dir>.Themes.Default");
OPTIONS.theme = strdup("Default");
}
LOG(("Using theme '%s' - from '%s'",theme_fname, OPTIONS.theme));
current_theme = ro_theme_create(theme_fname);

View File

@ -1,5 +1,5 @@
/**
* $Id: options.c,v 1.3 2003/06/06 02:14:28 jmb Exp $
* $Id: options.c,v 1.4 2003/06/08 04:00:05 jmb Exp $
*/
#include "netsurf/desktop/options.h"
@ -98,7 +98,7 @@ void options_write(struct options* opt, char* filename)
void options_init(struct options* opt)
{
opt->http = 0;
opt->http_proxy = strdup("http://www-cache.freeserve.co.uk");
opt->http_proxy = strdup("");
opt->http_port = 8080;
opt->use_mouse_gestures = 0;
opt->allow_text_selection = 1;
@ -120,7 +120,7 @@ void options_read(struct options* opt, char* filename)
LOG(("Testing filename"));
if (filename == NULL)
fn = "Choices:NetSurf.Choices";
strcat(fn, "Choices");
else
strcat(fn, filename);
@ -128,6 +128,14 @@ void options_read(struct options* opt, char* filename)
if (xmessagetrans_file_info(fn, &flags, &size) != NULL)
return;
/* catch empty choices file - this is a kludge but should work */
if (size <= 10) {
LOG(("Empty Choices file - using defaults"));
options_init(opt);
return;
}
LOG(("Allocating %d bytes", size));
data = xcalloc(size, sizeof(char));
messagetrans_open_file(&cb, fn, data);