NetSurf
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
nsoption.h File Reference

Option reading and saving interface. More...

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "utils/errors.h"
#include "desktop/options.h"
Include dependency graph for nsoption.h:
This graph shows which files directly or indirectly include this file:

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_snsoptions
 global active option table. More...
 
struct nsoption_snsoptions_default
 global default option table. More...
 

Detailed Description

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.

Macro Definition Documentation

◆ DEFAULT_EXPORT_SCALE

#define DEFAULT_EXPORT_SCALE   0.7

Definition at line 94 of file nsoption.h.

◆ DEFAULT_MARGIN_BOTTOM_MM

#define DEFAULT_MARGIN_BOTTOM_MM   10

Definition at line 91 of file nsoption.h.

◆ DEFAULT_MARGIN_LEFT_MM

#define DEFAULT_MARGIN_LEFT_MM   10

Definition at line 92 of file nsoption.h.

◆ DEFAULT_MARGIN_RIGHT_MM

#define DEFAULT_MARGIN_RIGHT_MM   10

Definition at line 93 of file nsoption.h.

◆ DEFAULT_MARGIN_TOP_MM

#define DEFAULT_MARGIN_TOP_MM   10

Definition at line 90 of file nsoption.h.

◆ DEFAULT_REFLOW_PERIOD

#define DEFAULT_REFLOW_PERIOD   25

Default reflow time in cs.

Definition at line 98 of file nsoption.h.

◆ NSOPTION_BOOL [1/2]

#define NSOPTION_BOOL (   NAME,
  DEFAULT 
)

Definition at line 125 of file nsoption.h.

◆ NSOPTION_BOOL [2/2]

#define NSOPTION_BOOL (   NAME,
  DEFAULT 
)    NSOPTION_##NAME,

Definition at line 125 of file nsoption.h.

◆ nsoption_bool

#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.

Note
option type is unchecked so care must be taken in caller.

Definition at line 304 of file nsoption.h.

◆ nsoption_charp

#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.

Note
option type is unchecked so care must be taken in caller.

Definition at line 331 of file nsoption.h.

◆ NSOPTION_COLOUR [1/2]

#define NSOPTION_COLOUR (   NAME,
  DEFAULT 
)

Definition at line 129 of file nsoption.h.

◆ NSOPTION_COLOUR [2/2]

#define NSOPTION_COLOUR (   NAME,
  DEFAULT 
)    NSOPTION_##NAME,

Definition at line 129 of file nsoption.h.

◆ nsoption_colour

#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.

Note
option type is unchecked so care must be taken in caller.

Definition at line 340 of file nsoption.h.

◆ nsoption_int

#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.

Note
option type is unchecked so care must be taken in caller.

Definition at line 313 of file nsoption.h.

◆ NSOPTION_INTEGER [1/2]

#define NSOPTION_INTEGER (   NAME,
  DEFAULT 
)

Definition at line 127 of file nsoption.h.

◆ NSOPTION_INTEGER [2/2]

#define NSOPTION_INTEGER (   NAME,
  DEFAULT 
)    NSOPTION_##NAME,

Definition at line 127 of file nsoption.h.

◆ nsoption_set_bool

#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.

◆ nsoption_set_charp

#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.

◆ nsoption_set_colour

#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.

◆ nsoption_set_int

#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.

◆ nsoption_set_uint

#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.

◆ nsoption_setnull_charp

#define nsoption_setnull_charp (   OPTION,
  VALUE 
)
Value:
do { \
if (nsoptions[NSOPTION_##OPTION].value.s == NULL) { \
nsoption_set_tbl_charp(nsoptions, NSOPTION_##OPTION, VALUE); \
} else { \
free(VALUE); \
} \
} while (0)
char * s
Definition: nsoption.h:118
struct nsoption_s * nsoptions
global active option table.
Definition: nsoption.c:45

set string option in default table if currently unset

Definition at line 376 of file nsoption.h.

◆ NSOPTION_STRING [1/2]

#define NSOPTION_STRING (   NAME,
  DEFAULT 
)

Definition at line 126 of file nsoption.h.

◆ NSOPTION_STRING [2/2]

#define NSOPTION_STRING (   NAME,
  DEFAULT 
)    NSOPTION_##NAME,

Definition at line 126 of file nsoption.h.

◆ NSOPTION_UINT [1/2]

#define NSOPTION_UINT (   NAME,
  DEFAULT 
)

Definition at line 128 of file nsoption.h.

◆ NSOPTION_UINT [2/2]

#define NSOPTION_UINT (   NAME,
  DEFAULT 
)    NSOPTION_##NAME,

Definition at line 128 of file nsoption.h.

◆ nsoption_uint

#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.

Note
option type is unchecked so care must be taken in caller.

Definition at line 322 of file nsoption.h.

Typedef Documentation

◆ nsoption_generate_cb

typedef size_t() nsoption_generate_cb(struct nsoption_s *option, void *ctx)

option generate callback

Definition at line 180 of file nsoption.h.

◆ nsoption_set_default_t

typedef nserror() nsoption_set_default_t(struct nsoption_s *defaults)

default setting callback.

Definition at line 174 of file nsoption.h.

Enumeration Type Documentation

◆ anonymous enum

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.

◆ nsoption_e

enum nsoption_e
Enumerator
NSOPTION_LISTEND 

Definition at line 131 of file nsoption.h.

◆ nsoption_generate_flags

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.

◆ nsoption_type_e

The options type.

Enumerator
OPTION_BOOL 

Option is a boolean.

OPTION_INTEGER 

Option is an integer.

OPTION_UINT 

Option is an unsigned integer.

OPTION_STRING 

option is a heap allocated string.

OPTION_COLOUR 

Option is a netsurf colour.

Definition at line 102 of file nsoption.h.

Function Documentation

◆ nsoption_commandline()

nserror nsoption_commandline ( int *  pargc,
char **  argv,
struct nsoption_s opts 
)

Process commandline and set options approriately.

Parameters
pargcPointer to the size of the argument vector.
argvThe argument vector.
optsThe options table to enerate values from or NULL to use global
Returns
The error status

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsoption_dump()

nserror nsoption_dump ( FILE *  outf,
struct nsoption_s opts 
)

Write all options to a stream.

Parameters
outfThe stream to write to
optsThe options table to enerate values from or NULL to use global
Returns
The error status

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsoption_finalise()

nserror nsoption_finalise ( struct nsoption_s opts,
struct nsoption_s defs 
)

Finalise option system.

Releases all resources allocated in the initialisation.

Parameters
optsthe options table or NULL to use global table.
defsthe 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsoption_generate()

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.

Parameters
cbFunction called for each option to be output.
ctxThe context for the callback.
flagsFlags controlling option matching.
optsThe options table to enerate values from or NULL to use global.
defsThe default table to use or NULL to use global.
Returns
The error status.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsoption_init()

nserror nsoption_init ( nsoption_set_default_t set_default,
struct nsoption_s **  popts,
struct nsoption_s **  pdefs 
)

Initialise option system.

Parameters
set_defaultcallback to allow the customisation of the default options.
poptspointer to update to get options table or NULL.
pdefspointer to update to get default options table or NULL.
Returns
The error status
Todo:
it would be better if the frontends actually set values in the passed in table instead of assuming the global one.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsoption_read()

nserror nsoption_read ( const char *  path,
struct nsoption_s opts 
)

Read choices file and set them in the passed table.

Parameters
pathThe path to read the file from
optsThe options table to enerate values from or NULL to use global
Returns
The error status
Todo:
is this an API bug not being a parameter

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsoption_set_tbl_charp()

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.

Parameters
optsThe table to set option in
option_idxThe option
sThe 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.

◆ nsoption_snoptionf()

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"

Parameters
stringThe buffer in which to place the results.
sizeThe size of the string buffer.
optionThe option .
fmtThe format string.
Returns
The number of bytes written to string or -1 on error

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.

Here is the call graph for this function:

◆ nsoption_write()

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.

Parameters
pathThe path to read the file from
optsThe options table to enerate values from or NULL to use global
defsThe default table to use or NULL to use global
Returns
The error status

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().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ nsoptions

struct nsoption_s* nsoptions
extern

◆ nsoptions_default

struct nsoption_s* nsoptions_default
extern