NetSurf
|
Option reading and saving interface. More...
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "utils/errors.h"
#include "desktop/options.h"
Go to the source code of this file.
Data Structures | |
struct | nsoption_s |
Macros | |
#define | NSOPTION_BOOL(NAME, DEFAULT) |
#define | NSOPTION_STRING(NAME, DEFAULT) |
#define | NSOPTION_INTEGER(NAME, DEFAULT) |
#define | NSOPTION_UINT(NAME, DEFAULT) |
#define | NSOPTION_COLOUR(NAME, DEFAULT) |
#define | DEFAULT_MARGIN_TOP_MM 10 |
#define | DEFAULT_MARGIN_BOTTOM_MM 10 |
#define | DEFAULT_MARGIN_LEFT_MM 10 |
#define | DEFAULT_MARGIN_RIGHT_MM 10 |
#define | DEFAULT_EXPORT_SCALE 0.7 |
#define | DEFAULT_REFLOW_PERIOD 25 |
Default reflow time in cs. More... | |
#define | NSOPTION_BOOL(NAME, DEFAULT) NSOPTION_##NAME, |
#define | NSOPTION_STRING(NAME, DEFAULT) NSOPTION_##NAME, |
#define | NSOPTION_INTEGER(NAME, DEFAULT) NSOPTION_##NAME, |
#define | NSOPTION_UINT(NAME, DEFAULT) NSOPTION_##NAME, |
#define | NSOPTION_COLOUR(NAME, DEFAULT) NSOPTION_##NAME, |
#define | nsoption_bool(OPTION) (nsoptions[NSOPTION_##OPTION].value.b) |
Get the value of a boolean option. More... | |
#define | nsoption_int(OPTION) (nsoptions[NSOPTION_##OPTION].value.i) |
Get the value of an integer option. More... | |
#define | nsoption_uint(OPTION) (nsoptions[NSOPTION_##OPTION].value.u) |
Get the value of an unsigned integer option. More... | |
#define | nsoption_charp(OPTION) (nsoptions[NSOPTION_##OPTION].value.s) |
Get the value of a string option. More... | |
#define | nsoption_colour(OPTION) (nsoptions[NSOPTION_##OPTION].value.c) |
Get the value of a netsurf colour option. More... | |
#define | nsoption_set_bool(OPTION, VALUE) nsoptions[NSOPTION_##OPTION].value.b = VALUE |
set a boolean option in the default table More... | |
#define | nsoption_set_int(OPTION, VALUE) nsoptions[NSOPTION_##OPTION].value.i = VALUE |
set an integer option in the default table More... | |
#define | nsoption_set_uint(OPTION, VALUE) nsoptions[NSOPTION_##OPTION].value.u = VALUE |
set an unsigned integer option in the default table More... | |
#define | nsoption_set_colour(OPTION, VALUE) nsoptions[NSOPTION_##OPTION].value.c = VALUE |
set a colour option in the default table More... | |
#define | nsoption_set_charp(OPTION, VALUE) nsoption_set_tbl_charp(nsoptions, NSOPTION_##OPTION, VALUE) |
set string option in default table More... | |
#define | nsoption_setnull_charp(OPTION, VALUE) |
set string option in default table if currently unset More... | |
Typedefs | |
typedef nserror() | nsoption_set_default_t(struct nsoption_s *defaults) |
default setting callback. More... | |
typedef size_t() | nsoption_generate_cb(struct nsoption_s *option, void *ctx) |
option generate callback More... | |
Enumerations | |
enum | { OPTION_HTTP_PROXY_AUTH_NONE = 0 , OPTION_HTTP_PROXY_AUTH_BASIC = 1 , OPTION_HTTP_PROXY_AUTH_NTLM = 2 } |
enum | nsoption_type_e { OPTION_BOOL , OPTION_INTEGER , OPTION_UINT , OPTION_STRING , OPTION_COLOUR } |
The options type. More... | |
enum | nsoption_e { NSOPTION_LISTEND } |
enum | nsoption_generate_flags { NSOPTION_GENERATE_ALL = 0 , NSOPTION_GENERATE_CHANGED = 1 } |
flags to control option output in the generate call More... | |
Functions | |
nserror | nsoption_init (nsoption_set_default_t *set_default, struct nsoption_s **popts, struct nsoption_s **pdefs) |
Initialise option system. More... | |
nserror | nsoption_finalise (struct nsoption_s *opts, struct nsoption_s *defs) |
Finalise option system. More... | |
nserror | nsoption_read (const char *path, struct nsoption_s *opts) |
Read choices file and set them in the passed table. More... | |
nserror | nsoption_generate (nsoption_generate_cb *cb, void *ctx, enum nsoption_generate_flags flags, struct nsoption_s *opts, struct nsoption_s *defs) |
Generate options via acallback. More... | |
nserror | nsoption_write (const char *path, struct nsoption_s *opts, struct nsoption_s *defs) |
Write options that have changed from the defaults to a file. More... | |
nserror | nsoption_dump (FILE *outf, struct nsoption_s *opts) |
Write all options to a stream. More... | |
nserror | nsoption_commandline (int *pargc, char **argv, struct nsoption_s *opts) |
Process commandline and set options approriately. More... | |
int | nsoption_snoptionf (char *string, size_t size, enum nsoption_e option, const char *fmt) |
Fill a buffer with an option using a format. More... | |
nserror | nsoption_set_tbl_charp (struct nsoption_s *opts, enum nsoption_e option_idx, char *s) |
Set string option in specified table. More... | |
Variables | |
struct nsoption_s * | nsoptions |
global active option table. More... | |
struct nsoption_s * | nsoptions_default |
global default option table. More... | |
Option reading and saving interface.
Global options are defined in desktop/options.h Distinct target options are defined in ${TARGET}/options.h
The implementation API is slightly compromised because it still has "global" tables for both the default and current option tables.
The initialisation and read/write interfaces take pointers to an option table which would let us to make the option structure opaque.
All the actual acessors assume direct access to a global option table (nsoptions). To avoid this the acessors would have to take a pointer to the active options table and be implemented as functions within nsoptions.c
Indirect access would have an impact on performance of NetSurf as the expected option lookup cost is currently that of a simple dereference (which this current implementation keeps).
Definition in file nsoption.h.
#define DEFAULT_EXPORT_SCALE 0.7 |
Definition at line 94 of file nsoption.h.
#define DEFAULT_MARGIN_BOTTOM_MM 10 |
Definition at line 91 of file nsoption.h.
#define DEFAULT_MARGIN_LEFT_MM 10 |
Definition at line 92 of file nsoption.h.
#define DEFAULT_MARGIN_RIGHT_MM 10 |
Definition at line 93 of file nsoption.h.
#define DEFAULT_MARGIN_TOP_MM 10 |
Definition at line 90 of file nsoption.h.
#define DEFAULT_REFLOW_PERIOD 25 |
Default reflow time in cs.
Definition at line 98 of file nsoption.h.
#define NSOPTION_BOOL | ( | NAME, | |
DEFAULT | |||
) |
Definition at line 125 of file nsoption.h.
#define NSOPTION_BOOL | ( | NAME, | |
DEFAULT | |||
) | NSOPTION_##NAME, |
Definition at line 125 of file nsoption.h.
#define nsoption_bool | ( | OPTION | ) | (nsoptions[NSOPTION_##OPTION].value.b) |
Get the value of a boolean option.
Gets the value of an option assuming it is a boolean type.
Definition at line 304 of file nsoption.h.
#define nsoption_charp | ( | OPTION | ) | (nsoptions[NSOPTION_##OPTION].value.s) |
Get the value of a string option.
Gets the value of an option assuming it is a string type.
Definition at line 331 of file nsoption.h.
#define NSOPTION_COLOUR | ( | NAME, | |
DEFAULT | |||
) |
Definition at line 129 of file nsoption.h.
#define NSOPTION_COLOUR | ( | NAME, | |
DEFAULT | |||
) | NSOPTION_##NAME, |
Definition at line 129 of file nsoption.h.
#define nsoption_colour | ( | OPTION | ) | (nsoptions[NSOPTION_##OPTION].value.c) |
Get the value of a netsurf colour option.
Gets the value of an option assuming it is a colour type.
Definition at line 340 of file nsoption.h.
#define nsoption_int | ( | OPTION | ) | (nsoptions[NSOPTION_##OPTION].value.i) |
Get the value of an integer option.
Gets the value of an option assuming it is a integer type.
Definition at line 313 of file nsoption.h.
#define NSOPTION_INTEGER | ( | NAME, | |
DEFAULT | |||
) |
Definition at line 127 of file nsoption.h.
#define NSOPTION_INTEGER | ( | NAME, | |
DEFAULT | |||
) | NSOPTION_##NAME, |
Definition at line 127 of file nsoption.h.
#define nsoption_set_bool | ( | OPTION, | |
VALUE | |||
) | nsoptions[NSOPTION_##OPTION].value.b = VALUE |
set a boolean option in the default table
Definition at line 344 of file nsoption.h.
#define nsoption_set_charp | ( | OPTION, | |
VALUE | |||
) | nsoption_set_tbl_charp(nsoptions, NSOPTION_##OPTION, VALUE) |
set string option in default table
Definition at line 372 of file nsoption.h.
#define nsoption_set_colour | ( | OPTION, | |
VALUE | |||
) | nsoptions[NSOPTION_##OPTION].value.c = VALUE |
set a colour option in the default table
Definition at line 355 of file nsoption.h.
#define nsoption_set_int | ( | OPTION, | |
VALUE | |||
) | nsoptions[NSOPTION_##OPTION].value.i = VALUE |
set an integer option in the default table
Definition at line 348 of file nsoption.h.
#define nsoption_set_uint | ( | OPTION, | |
VALUE | |||
) | nsoptions[NSOPTION_##OPTION].value.u = VALUE |
set an unsigned integer option in the default table
Definition at line 351 of file nsoption.h.
#define nsoption_setnull_charp | ( | OPTION, | |
VALUE | |||
) |
set string option in default table if currently unset
Definition at line 376 of file nsoption.h.
#define NSOPTION_STRING | ( | NAME, | |
DEFAULT | |||
) |
Definition at line 126 of file nsoption.h.
#define NSOPTION_STRING | ( | NAME, | |
DEFAULT | |||
) | NSOPTION_##NAME, |
Definition at line 126 of file nsoption.h.
#define NSOPTION_UINT | ( | NAME, | |
DEFAULT | |||
) |
Definition at line 128 of file nsoption.h.
#define NSOPTION_UINT | ( | NAME, | |
DEFAULT | |||
) | NSOPTION_##NAME, |
Definition at line 128 of file nsoption.h.
#define nsoption_uint | ( | OPTION | ) | (nsoptions[NSOPTION_##OPTION].value.u) |
Get the value of an unsigned integer option.
Gets the value of an option assuming it is a integer type.
Definition at line 322 of file nsoption.h.
typedef size_t() nsoption_generate_cb(struct nsoption_s *option, void *ctx) |
option generate callback
Definition at line 180 of file nsoption.h.
typedef nserror() nsoption_set_default_t(struct nsoption_s *defaults) |
default setting callback.
Definition at line 174 of file nsoption.h.
anonymous enum |
Enumerator | |
---|---|
OPTION_HTTP_PROXY_AUTH_NONE | |
OPTION_HTTP_PROXY_AUTH_BASIC | |
OPTION_HTTP_PROXY_AUTH_NTLM |
Definition at line 86 of file nsoption.h.
enum nsoption_e |
Enumerator | |
---|---|
NSOPTION_LISTEND |
Definition at line 131 of file nsoption.h.
flags to control option output in the generate call
Enumerator | |
---|---|
NSOPTION_GENERATE_ALL | Generate output for all options. |
NSOPTION_GENERATE_CHANGED | Generate output for options which differ from the default. |
Definition at line 186 of file nsoption.h.
enum nsoption_type_e |
The options type.
Definition at line 102 of file nsoption.h.
nserror nsoption_commandline | ( | int * | pargc, |
char ** | argv, | ||
struct nsoption_s * | opts | ||
) |
Process commandline and set options approriately.
pargc | Pointer to the size of the argument vector. |
argv | The argument vector. |
opts | The options table to enerate values from or NULL to use global |
Definition at line 856 of file nsoption.c.
References nsoption_s::key, NSERROR_BAD_PARAMETER, NSERROR_OK, NSLOG, NSOPTION_LISTEND, nsoption_validate(), nsoptions, nsoptions_default, and strtooption().
Referenced by gui_init_replicant(), main(), monkey_options_handle_command(), nsgtk_option_init(), and nsw32_option_init().
nserror nsoption_dump | ( | FILE * | outf, |
struct nsoption_s * | opts | ||
) |
Write all options to a stream.
outf | The stream to write to |
opts | The options table to enerate values from or NULL to use global |
Definition at line 832 of file nsoption.c.
References NSERROR_BAD_PARAMETER, nsoption_generate(), NSOPTION_GENERATE_ALL, nsoption_output_value_file(), nsoptions, and nsoptions_default.
Referenced by ro_gui_signal().
nserror nsoption_finalise | ( | struct nsoption_s * | opts, |
struct nsoption_s * | defs | ||
) |
Finalise option system.
Releases all resources allocated in the initialisation.
opts | the options table or NULL to use global table. |
defs | the default options table to use or NULL to use global table return The error status |
Definition at line 663 of file nsoption.c.
References NSERROR_OK, nsoption_free(), nsoptions, and nsoptions_default.
Referenced by main(), nsgtk_finalise(), and WinMain().
nserror nsoption_generate | ( | nsoption_generate_cb * | cb, |
void * | ctx, | ||
enum nsoption_generate_flags | flags, | ||
struct nsoption_s * | opts, | ||
struct nsoption_s * | defs | ||
) |
Generate options via acallback.
iterates options controlled by flags calling a method for each matched option.
cb | Function called for each option to be output. |
ctx | The context for the callback. |
flags | Flags controlling option matching. |
opts | The options table to enerate values from or NULL to use global. |
defs | The default table to use or NULL to use global. |
Definition at line 746 of file nsoption.c.
References NSERROR_BAD_PARAMETER, NSERROR_OK, NSOPTION_GENERATE_CHANGED, nsoption_is_set(), NSOPTION_LISTEND, nsoptions, and nsoptions_default.
Referenced by nsoption_dump(), and nsoption_write().
nserror nsoption_init | ( | nsoption_set_default_t * | set_default, |
struct nsoption_s ** | popts, | ||
struct nsoption_s ** | pdefs | ||
) |
Initialise option system.
set_default | callback to allow the customisation of the default options. |
popts | pointer to update to get options table or NULL. |
pdefs | pointer to update to get default options table or NULL. |
Definition at line 608 of file nsoption.c.
References defaults, NSERROR_OK, nsoption_dup(), nsoption_free(), nsoptions, nsoptions_default, and set_defaults().
Referenced by gui_init_replicant(), main(), nsgtk_option_init(), and nsw32_option_init().
nserror nsoption_read | ( | const char * | path, |
struct nsoption_s * | opts | ||
) |
Read choices file and set them in the passed table.
path | The path to read the file from |
opts | The options table to enerate values from or NULL to use global |
Definition at line 696 of file nsoption.c.
References NSERROR_BAD_PARAMETER, NSERROR_NOT_FOUND, NSERROR_OK, NSLOG, NSOPTION_MAX_LINE_LEN, nsoption_validate(), nsoptions, nsoptions_default, optionline(), path(), and nsoption_s::s.
Referenced by ami_nsoption_read(), gui_init(), gui_init_replicant(), main(), nsgtk_option_init(), nsw32_option_init(), and save_settings().
nserror nsoption_set_tbl_charp | ( | struct nsoption_s * | opts, |
enum nsoption_e | option_idx, | ||
char * | s | ||
) |
Set string option in specified table.
Sets the string option to the value given freeing any resources currently allocated to the option. If the passed string is empty it is converted to the NULL value.
opts | The table to set option in |
option_idx | The option |
s | The string to set. This is used directly and not copied. |
Definition at line 1046 of file nsoption.c.
References NSERROR_BAD_PARAMETER, NSERROR_OK, OPTION_STRING, nsoption_s::s, nsoption_s::type, and nsoption_s::value.
int nsoption_snoptionf | ( | char * | string, |
size_t | size, | ||
enum nsoption_e | option, | ||
const char * | fmt | ||
) |
Fill a buffer with an option using a format.
The format string is copied into the output buffer with the following replaced: k - The options key t - The options type V - value (HTML formatting) v - value (plain formatting) p - provenance either "user" or "default"
string | The buffer in which to place the results. |
size | The size of the string buffer. |
option | The option . |
fmt | The format string. |
Definition at line 930 of file nsoption.c.
References nsoption_s::key, min, nsoption_is_set(), NSOPTION_LISTEND, nsoption_output_value_html(), nsoption_output_value_text(), nsoptions, nsoptions_default, OPTION_BOOL, OPTION_COLOUR, OPTION_INTEGER, OPTION_STRING, OPTION_UINT, and nsoption_s::type.
nserror nsoption_write | ( | const char * | path, |
struct nsoption_s * | opts, | ||
struct nsoption_s * | defs | ||
) |
Write options that have changed from the defaults to a file.
The nsoption_dump can be used to output all entries not just changed ones.
path | The path to read the file from |
opts | The options table to enerate values from or NULL to use global |
defs | The default table to use or NULL to use global |
Definition at line 786 of file nsoption.c.
References NSERROR_BAD_PARAMETER, NSERROR_NOT_FOUND, NSLOG, nsoption_generate(), NSOPTION_GENERATE_CHANGED, nsoption_output_value_file(), nsoptions, nsoptions_default, and path().
Referenced by ami_nsoption_write(), menu_savewin(), nsgtk_preferences_dialogPreferences_deleteevent(), nsgtk_preferences_dialogPreferences_destroy(), nsgtk_preferences_dialogPreferences_response(), nsgtk_toolbar_customisation_save(), nsws_prefs_save(), ro_gui_save_options(), save_settings(), and savewindowsize_button_clicked_cb().
|
extern |
global active option table.
Definition at line 45 of file nsoption.c.
Referenced by colour_option_from_pen(), gui_init_replicant(), main(), monkey_options_handle_command(), ns_system_colour(), ns_system_colour_char(), ns_system_colour_init(), nsbeos_update_system_ui_colors(), nsgtk_finalise(), nsgtk_option_init(), nsoption_commandline(), nsoption_dump(), nsoption_finalise(), nsoption_generate(), nsoption_init(), nsoption_read(), nsoption_snoptionf(), nsoption_write(), nsw32_option_init(), and WinMain().
|
extern |
global default option table.
Definition at line 46 of file nsoption.c.
Referenced by colour_option_from_pen(), gui_init_replicant(), main(), nsgtk_finalise(), nsgtk_option_init(), nsoption_commandline(), nsoption_dump(), nsoption_finalise(), nsoption_generate(), nsoption_init(), nsoption_read(), nsoption_snoptionf(), nsoption_write(), nsw32_option_init(), and WinMain().