NetSurf
|
Option reading and saving (implementation). More...
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "netsurf/inttypes.h"
#include "netsurf/plot_style.h"
#include "utils/errors.h"
#include "utils/log.h"
#include "utils/utils.h"
#include "utils/nsoption.h"
#include "desktop/options.h"
Go to the source code of this file.
Macros | |
#define | NSOPTION_MAX_LINE_LEN 1024 |
Length of buffer used to read lines from input file. More... | |
#define | NSOPTION_BOOL(NAME, DEFAULT) { #NAME, sizeof(#NAME) - 1, OPTION_BOOL, { .b = DEFAULT } }, |
#define | NSOPTION_STRING(NAME, DEFAULT) { #NAME, sizeof(#NAME) - 1, OPTION_STRING, { .cs = DEFAULT } }, |
#define | NSOPTION_INTEGER(NAME, DEFAULT) { #NAME, sizeof(#NAME) - 1, OPTION_INTEGER, { .i = DEFAULT } }, |
#define | NSOPTION_UINT(NAME, DEFAULT) { #NAME, sizeof(#NAME) - 1, OPTION_UINT, { .u = DEFAULT } }, |
#define | NSOPTION_COLOUR(NAME, DEFAULT) { #NAME, sizeof(#NAME) - 1, OPTION_COLOUR, { .c = DEFAULT } }, |
Functions | |
static bool | strtooption (const char *value, struct nsoption_s *option) |
Set an option value based on a string. More... | |
static void | nsoption_validate (struct nsoption_s *opts, struct nsoption_s *defs) |
static bool | nsoption_is_set (const struct nsoption_s *opts, const struct nsoption_s *defs, const enum nsoption_e entry) |
Determines if an option is different between two option tables. More... | |
static size_t | nsoption_output_value_file (struct nsoption_s *option, void *ctx) |
Output an option value into a file stream, in plain text format. More... | |
static size_t | nsoption_output_value_html (struct nsoption_s *option, size_t size, size_t pos, char *string) |
Output an option value into a string, in HTML format. More... | |
static size_t | nsoption_output_value_text (struct nsoption_s *option, size_t size, size_t pos, char *string) |
Output an option value into a string, in plain text format. More... | |
static nserror | nsoption_dup (struct nsoption_s *src, struct nsoption_s **pdst) |
Duplicates an option table. More... | |
static nserror | nsoption_free (struct nsoption_s *opts) |
frees an option table. More... | |
static nserror | get_key_value (char *line, int linelen, char **key_out, char **value_out) |
extract key/value from a line of input More... | |
static nserror | optionline (struct nsoption_s *opts, char *line, int linelen) |
Process a line from a user option file. More... | |
nserror | nsoption_init (nsoption_set_default_t *set_defaults, 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 *generate_cb, void *generate_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_idx, 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 = NULL |
global active option table. More... | |
struct nsoption_s * | nsoptions_default = NULL |
global default option table. More... | |
static struct nsoption_s | defaults [] |
The table of compiled in default options. More... | |
Option reading and saving (implementation).
Options are stored in the format key:value, one per line.
For bool options, value is "0" or "1".
Definition in file nsoption.c.
#define NSOPTION_BOOL | ( | NAME, | |
DEFAULT | |||
) | { #NAME, sizeof(#NAME) - 1, OPTION_BOOL, { .b = DEFAULT } }, |
Definition at line 48 of file nsoption.c.
#define NSOPTION_COLOUR | ( | NAME, | |
DEFAULT | |||
) | { #NAME, sizeof(#NAME) - 1, OPTION_COLOUR, { .c = DEFAULT } }, |
Definition at line 60 of file nsoption.c.
#define NSOPTION_INTEGER | ( | NAME, | |
DEFAULT | |||
) | { #NAME, sizeof(#NAME) - 1, OPTION_INTEGER, { .i = DEFAULT } }, |
Definition at line 54 of file nsoption.c.
#define NSOPTION_MAX_LINE_LEN 1024 |
Length of buffer used to read lines from input file.
Definition at line 43 of file nsoption.c.
#define NSOPTION_STRING | ( | NAME, | |
DEFAULT | |||
) | { #NAME, sizeof(#NAME) - 1, OPTION_STRING, { .cs = DEFAULT } }, |
Definition at line 51 of file nsoption.c.
#define NSOPTION_UINT | ( | NAME, | |
DEFAULT | |||
) | { #NAME, sizeof(#NAME) - 1, OPTION_UINT, { .u = DEFAULT } }, |
Definition at line 57 of file nsoption.c.
|
static |
extract key/value from a line of input
\retun NSERROR_OK and key_out and value_out updated NSERROR_NOT_FOUND if not a key/value input line NSERROR_INVALID if the line is and invalid format (missing colon)
Definition at line 531 of file nsoption.c.
References nsoption_s::key, line(), NSERROR_INVALID, NSERROR_NOT_FOUND, NSERROR_OK, and nsoption_s::value.
Referenced by optionline().
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().
|
static |
Duplicates an option table.
Allocates a new option table and copies an existing one into it.
[in] | src | The source table to copy |
[out] | pdst | The output table |
Definition at line 468 of file nsoption.c.
References defaults, nsoption_s::key, NSERROR_NOMEM, NSERROR_OK, OPTION_STRING, nsoption_s::s, nsoption_s::type, and nsoption_s::value.
Referenced by nsoption_init().
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().
|
static |
frees an option table.
Iterates through an option table a freeing resources as required finally freeing the option table itself.
opts | The option table to free. |
Definition at line 501 of file nsoption.c.
References nsoption_s::key, NSERROR_BAD_PARAMETER, NSERROR_OK, OPTION_STRING, nsoption_s::s, nsoption_s::type, and nsoption_s::value.
Referenced by nsoption_finalise(), and nsoption_init().
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().
|
static |
Determines if an option is different between two option tables.
opts | The first table to compare. |
defs | The second table to compare. |
entry | The option to compare. |
Definition at line 227 of file nsoption.c.
References nsoption_s::b, nsoption_s::c, nsoption_s::i, OPTION_BOOL, OPTION_COLOUR, OPTION_INTEGER, OPTION_STRING, OPTION_UINT, nsoption_s::s, type, nsoption_s::u, and nsoption_s::value.
Referenced by nsoption_generate(), and nsoption_snoptionf().
|
static |
Output an option value into a file stream, in plain text format.
option | The option to output the value of. |
fp | The file stream to write to. |
Definition at line 287 of file nsoption.c.
References nsoption_s::b, nsoption_s::c, nsoption_s::i, nsoption_s::key, OPTION_BOOL, OPTION_COLOUR, OPTION_INTEGER, OPTION_STRING, OPTION_UINT, nsoption_s::s, nsoption_s::type, nsoption_s::u, and nsoption_s::value.
Referenced by nsoption_dump(), and nsoption_write().
|
static |
Output an option value into a string, in HTML format.
option | The option to output the value of. |
size | The size of the string buffer. |
pos | The current position in string |
string | The string in which to output the value. |
Definition at line 335 of file nsoption.c.
References nsoption_s::b, nsoption_s::c, colour_rb_swap, colour_to_bw_furthest, nsoption_s::i, OPTION_BOOL, OPTION_COLOUR, OPTION_INTEGER, OPTION_STRING, OPTION_UINT, nsoption_s::s, nsoption_s::type, nsoption_s::u, and nsoption_s::value.
Referenced by nsoption_snoptionf().
|
static |
Output an option value into a string, in plain text format.
option | The option to output the value of. |
size | The size of the string buffer. |
pos | The current position in string |
string | The string in which to output the value. |
Definition at line 408 of file nsoption.c.
References nsoption_s::b, nsoption_s::c, nsoption_s::i, OPTION_BOOL, OPTION_COLOUR, OPTION_INTEGER, OPTION_STRING, OPTION_UINT, nsoption_s::s, nsoption_s::type, nsoption_s::u, and nsoption_s::value.
Referenced by nsoption_snoptionf().
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.
|
static |
Definition at line 145 of file nsoption.c.
References nsoption_s::c, nsoption_s::i, nslog_set_filter_by_options(), NSOPTION_SYS_COLOUR_END, NSOPTION_SYS_COLOUR_START, nsoption_s::u, and nsoption_s::value.
Referenced by nsoption_commandline(), and nsoption_read().
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().
|
static |
Process a line from a user option file.
Definition at line 582 of file nsoption.c.
References get_key_value(), nsoption_s::key, line(), NSERROR_OK, strtooption(), and nsoption_s::value.
Referenced by nsoption_read().
|
static |
Set an option value based on a string.
Definition at line 97 of file nsoption.c.
References nsoption_s::b, nsoption_s::c, nsoption_s::i, OPTION_BOOL, OPTION_COLOUR, OPTION_INTEGER, OPTION_STRING, OPTION_UINT, nsoption_s::s, nsoption_s::type, nsoption_s::u, and nsoption_s::value.
Referenced by nsoption_commandline(), and optionline().
|
static |
The table of compiled in default options.
Definition at line 64 of file nsoption.c.
Referenced by nsoption_dup(), nsoption_init(), and set_defaults().
struct nsoption_s* nsoptions = NULL |
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().
struct nsoption_s* nsoptions_default = NULL |
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().