From 5e41fb8a121c441a8765a1962a892e93906cde83 Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Sun, 7 Nov 2004 19:19:11 +0000 Subject: [project @ 2004-11-07 19:19:11 by rjw] Initial import. svn path=/import/nstheme/; revision=2436 --- desktop/gui.h | 22 ++++++++ desktop/nstheme.c | 44 ++++++++++++++++ desktop/nstheme.h | 16 ++++++ desktop/options.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ desktop/options.h | 46 +++++++++++++++++ 5 files changed, 277 insertions(+) create mode 100644 desktop/gui.h create mode 100644 desktop/nstheme.c create mode 100644 desktop/nstheme.h create mode 100644 desktop/options.c create mode 100644 desktop/options.h (limited to 'desktop') diff --git a/desktop/gui.h b/desktop/gui.h new file mode 100644 index 0000000..f4069c1 --- /dev/null +++ b/desktop/gui.h @@ -0,0 +1,22 @@ +/* + * 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 Richard Wilson + */ + +/** \file + * Interface to platform-specific gui functions. + */ + +#ifndef _NSTHEME_DESKTOP_GUI_H_ +#define _NSTHEME_DESKTOP_GUI_H_ + +#include + +void gui_init(void); +void gui_multitask(void); +void gui_poll(void); +void gui_exit(void); + +#endif diff --git a/desktop/nstheme.c b/desktop/nstheme.c new file mode 100644 index 0000000..d4e5a19 --- /dev/null +++ b/desktop/nstheme.c @@ -0,0 +1,44 @@ +/* + * 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 Richard Wilson + */ + +#include +#include "nstheme/desktop/gui.h" +#include "nstheme/desktop/nstheme.h" +#include "nstheme/utils/utils.h" + +bool application_quit = false; + +static void application_init(void); +static void application_exit(void); + + +/** + * NSTheme main(). + */ +int main(int argc, char** argv) { + application_init(); + while (!application_quit) gui_poll(); + application_exit(); + return EXIT_SUCCESS; +} + + +/** + * Initialise application. + */ +void application_init(void) { + stdout = stderr; + gui_init(); +} + + +/** + * Finalise application. + */ +void application_exit(void) { + gui_exit(); +} diff --git a/desktop/nstheme.h b/desktop/nstheme.h new file mode 100644 index 0000000..fab28d3 --- /dev/null +++ b/desktop/nstheme.h @@ -0,0 +1,16 @@ +/* + * 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 Richard Wilson + */ + +#ifndef _NSTHEME_DESKTOP_NSTHEME_H_ +#define _NSTHEME_DESKTOP_NSTHEME_H_ + +#include + +extern bool application_quit; + +#endif + diff --git a/desktop/options.c b/desktop/options.c new file mode 100644 index 0000000..b43291b --- /dev/null +++ b/desktop/options.c @@ -0,0 +1,149 @@ +/* + * 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 2003 Phil Mellor + * Copyright 2003 John M Bell + * Copyright 2004 James Bursa + * Copyright 2004 Richard Wilson + */ + +/** \file + * Option reading and saving (implementation). + * + * Options are stored in the format key:value, one per line. For bool options, + * value is "0" or "1". + */ + +#include +#include +#include +#include "nstheme/desktop/options.h" +#include "nstheme/utils/log.h" +#include "nstheme/utils/utils.h" + +#ifdef riscos +#include "nstheme/riscos/options.h" +#else +#define EXTRA_OPTION_DEFINE +#define EXTRA_OPTION_TABLE +#endif + + +EXTRA_OPTION_DEFINE + + +struct { + const char *key; + enum { OPTION_BOOL, OPTION_INTEGER, OPTION_STRING } type; + void *p; +} option_table[] = { + EXTRA_OPTION_TABLE +}; + +#define option_table_entries (sizeof option_table / sizeof option_table[0]) + + +/** + * Read options from a file. + * + * \param path name of file to read options from + * + * Option variables corresponding to lines in the file are updated. Missing + * options are unchanged. If the file fails to open, options are unchanged. + */ + +void options_read(const char *path) +{ + char s[100]; + FILE *fp; + + fp = fopen(path, "r"); + if (!fp) { + LOG(("failed to open file '%s'", path)); + return; + } + + while (fgets(s, 100, fp)) { + char *colon, *value; + unsigned int i; + + if (s[0] == 0 || s[0] == '#') + continue; + colon = strchr(s, ':'); + if (colon == 0) + continue; + s[strlen(s) - 1] = 0; /* remove \n at end */ + *colon = 0; /* terminate key */ + value = colon + 1; + + for (i = 0; i != option_table_entries; i++) { + if (strcasecmp(s, option_table[i].key) != 0) + continue; + + switch (option_table[i].type) { + case OPTION_BOOL: + *((bool *) option_table[i].p) = + value[0] == '1'; + break; + + case OPTION_INTEGER: + *((int *) option_table[i].p) = + atoi(value); + break; + + case OPTION_STRING: + free(*((char **) option_table[i].p)); + *((char **) option_table[i].p) = + strdup(value); + break; + } + break; + } + } + + fclose(fp); +} + + +/** + * Save options to a file. + * + * \param path name of file to write options to + * + * Errors are ignored. + */ + +void options_write(const char *path) +{ + unsigned int i; + FILE *fp; + + fp = fopen(path, "w"); + if (!fp) { + LOG(("failed to open file '%s' for writing", path)); + return; + } + + for (i = 0; i != option_table_entries; i++) { + fprintf(fp, "%s:", option_table[i].key); + switch (option_table[i].type) { + case OPTION_BOOL: + fprintf(fp, "%c", *((bool *) option_table[i].p) ? + '1' : '0'); + break; + + case OPTION_INTEGER: + fprintf(fp, "%i", *((int *) option_table[i].p)); + break; + + case OPTION_STRING: + if (*((char **) option_table[i].p)) + fprintf(fp, "%s", *((char **) option_table[i].p)); + break; + } + fprintf(fp, "\n"); + } + + fclose(fp); +} diff --git a/desktop/options.h b/desktop/options.h new file mode 100644 index 0000000..ae35cda --- /dev/null +++ b/desktop/options.h @@ -0,0 +1,46 @@ +/* + * 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 2003 Phil Mellor + * Copyright 2004 James Bursa + */ + +/** \file + * Option reading and saving (interface). + * + * Non-platform specific options can be added by editing this file and + * netsurf/desktop/options.c + * + * Platform specific options should be added in the platform options.h. + * + * The following types of options are supported: + * - bool (OPTION_BOOL) + * - int (OPTION_INTEGER) + * - char* (OPTION_STRING) (must be allocated on heap, may be 0, free before + * assigning a new value) + */ + +#ifndef _NETSURF_DESKTOP_OPTIONS_H_ +#define _NETSURF_DESKTOP_OPTIONS_H_ + +enum { OPTION_HTTP_PROXY_AUTH_NONE = 0, OPTION_HTTP_PROXY_AUTH_BASIC = 1, + OPTION_HTTP_PROXY_AUTH_NTLM = 2 }; + +extern bool option_http_proxy; +extern char *option_http_proxy_host; +extern int option_http_proxy_port; +extern int option_http_proxy_auth; +extern char *option_http_proxy_auth_user; +extern char *option_http_proxy_auth_pass; +extern int option_font_size; +extern int option_font_min_size; +extern char *option_accept_language; +extern bool option_ssl_verify_certificates; +extern int option_memory_cache_size; +extern bool option_block_ads; + +void options_read(const char *path); +void options_write(const char *path); + +#endif -- cgit v1.2.3