43#define NSOPTION_MAX_LINE_LEN 1024
48#define NSOPTION_BOOL(NAME, DEFAULT) \
49 { #NAME, sizeof(#NAME) - 1, OPTION_BOOL, { .b = DEFAULT } },
51#define NSOPTION_STRING(NAME, DEFAULT) \
52 { #NAME, sizeof(#NAME) - 1, OPTION_STRING, { .cs = DEFAULT } },
54#define NSOPTION_INTEGER(NAME, DEFAULT) \
55 { #NAME, sizeof(#NAME) - 1, OPTION_INTEGER, { .i = DEFAULT } },
57#define NSOPTION_UINT(NAME, DEFAULT) \
58 { #NAME, sizeof(#NAME) - 1, OPTION_UINT, { .u = DEFAULT } },
60#define NSOPTION_COLOUR(NAME, DEFAULT) \
61 { #NAME, sizeof(#NAME) - 1, OPTION_COLOUR, { .c = DEFAULT } },
75#elif defined(nsframebuffer)
79#elif defined(nsmonkey)
89#undef NSOPTION_INTEGER
102 switch (option->
type) {
116 if (sscanf(
value,
"%"SCNx32
"", &rgbcolour) == 1) {
117 option->
value.
c = (((0x000000FF & rgbcolour) << 16) |
118 ((0x0000FF00 & rgbcolour) << 0) |
119 ((0x00FF0000 & rgbcolour) >> 16));
124 if (option->
value.
s != NULL) {
150 if (opts[NSOPTION_treeview_font_size].
value.i < 50) {
151 opts[NSOPTION_treeview_font_size].
value.
i = 50;
154 if (opts[NSOPTION_treeview_font_size].
value.i > 1000) {
155 opts[NSOPTION_treeview_font_size].
value.
i = 1000;
158 if (opts[NSOPTION_font_size].
value.i < 50) {
159 opts[NSOPTION_font_size].
value.
i = 50;
162 if (opts[NSOPTION_font_size].
value.i > 1000) {
163 opts[NSOPTION_font_size].
value.
i = 1000;
166 if (opts[NSOPTION_font_min_size].
value.i < 10) {
167 opts[NSOPTION_font_min_size].
value.
i = 10;
170 if (opts[NSOPTION_font_min_size].
value.i > 500) {
171 opts[NSOPTION_font_min_size].
value.
i = 500;
174 if (opts[NSOPTION_memory_cache_size].
value.i < 0) {
175 opts[NSOPTION_memory_cache_size].
value.
i = 0;
186 if (opts[cloop].
value.c != 0) {
191 if (black ==
true && defs != NULL) {
203 if (opts[NSOPTION_max_retried_fetches].
value.u == 0)
204 opts[NSOPTION_max_retried_fetches].
value.
u = 1;
205 if (opts[NSOPTION_curl_fetch_timeout].
value.u < 5)
206 opts[NSOPTION_curl_fetch_timeout].
value.
u = 5;
207 if (opts[NSOPTION_curl_fetch_timeout].
value.u > 60)
208 opts[NSOPTION_curl_fetch_timeout].
value.
u = 60;
209 while (((opts[NSOPTION_curl_fetch_timeout].
value.u *
210 opts[NSOPTION_max_retried_fetches].
value.
u) > 60) &&
211 (opts[NSOPTION_max_retried_fetches].
value.
u > 1))
212 opts[NSOPTION_max_retried_fetches].
value.
u--;
233 switch (opts[entry].
type) {
266 if (((defs[entry].
value.s == NULL) &&
267 (opts[entry].
value.
s != NULL)) ||
268 ((defs[entry].
value.
s != NULL) &&
269 (opts[entry].
value.
s == NULL)) ||
271 (strcmp(opts[entry].
value.s, defs[entry].
value.
s) != 0))) {
293 switch (option->
type) {
295 slen = fprintf(fp,
"%s:%c\n", option->
key, option->
value.
b ?
'1' :
'0');
299 slen = fprintf(fp,
"%s:%i\n", option->
key, option->
value.
i);
304 slen = fprintf(fp,
"%s:%u\n", option->
key, option->
value.
u);
308 rgbcolour = (((0x000000FF & option->
value.
c) << 16) |
309 ((0x0000FF00 & option->
value.
c) << 0) |
310 ((0x00FF0000 & option->
value.
c) >> 16));
311 slen = fprintf(fp,
"%s:%06"PRIx32
"\n", option->
key, rgbcolour);
315 slen = fprintf(fp,
"%s:%s\n",
317 ((option->
value.
s == NULL) ||
343 switch (option->
type) {
345 slen = snprintf(
string + pos,
348 option->
value.
b ?
"true" :
"false");
352 slen = snprintf(
string + pos,
359 slen = snprintf(
string + pos,
367 slen = snprintf(
string + pos,
369 "<span style=\"font-family:Monospace;\">"
372 "<span style=\"background-color: #%06"PRIx32
"; "
373 "border: 1px solid #%06"PRIx32
"; "
374 "display: inline-block; "
375 "width: 1em; height: 1em;\">"
383 if (option->
value.
s != NULL) {
384 slen = snprintf(
string + pos, size - pos,
"%s",
387 slen = snprintf(
string + pos, size - pos,
388 "<span class=\"null-content\">NULL"
416 switch (option->
type) {
418 slen = snprintf(
string + pos,
421 option->
value.
b ?
'1' :
'0');
425 slen = snprintf(
string + pos,
432 slen = snprintf(
string + pos,
439 rgbcolour = (((0x000000FF & option->
value.
c) << 16) |
440 ((0x0000FF00 & option->
value.
c) << 0) |
441 ((0x00FF0000 & option->
value.
c) >> 16));
442 slen = snprintf(
string + pos, size - pos,
"%06"PRIx32, rgbcolour);
446 if (option->
value.
s != NULL) {
447 slen = snprintf(
string + pos,
480 while (src->
key != NULL) {
511 while (cur->
key != NULL) {
538 if ((*
key !=
' ') && (*
key !=
'\t') && (*
key !=
'\n')) {
568 if (
line[linelen - 1] ==
'\n') {
595 for (idx = 0; opts[idx].
key != NULL; idx++) {
596 if (strcasecmp(
key, opts[idx].
key) == 0) {
716 if ((opts == NULL) || (defs == NULL)) {
720 fp = fopen(
path,
"r");
722 NSLOG(netsurf, INFO,
"Failed to open file '%s'",
path);
726 NSLOG(netsurf, INFO,
"Successfully opened '%s' for Options file",
path);
764 if ((opts == NULL) || (defs == NULL)) {
773 generate_cb(opts + entry, generate_ctx);
807 if ((opts == NULL) || (defs == NULL)) {
811 fp = fopen(
path,
"w");
813 NSLOG(netsurf, INFO,
"failed to open file '%s' for writing",
863 unsigned int entry_loop;
865 if ((pargc == NULL) || (argv == NULL)) {
877 while (idx < *pargc) {
879 arglen = strlen(arg);
883 if ((arglen < (2+5) ) || (arg[0] !=
'-') || (arg[1] !=
'-'))
888 val = strchr(arg,
'=');
903 NSLOG(netsurf, INFO,
"%.*s = %s", arglen, arg, val);
908 if (strncmp(arg, opts[entry_loop].
key, arglen) == 0) {
918 for (mv_loop=0; mv_loop < (*pargc - idx); mv_loop++) {
919 argv[mv_loop + 1] = argv[mv_loop + idx];
952 if (option == NULL || option->
key == NULL) {
956 while ((slen < size) && (fmt[fmtc] != 0)) {
957 if (fmt[fmtc] ==
'%') {
961 slen += snprintf(
string + slen,
971 slen += snprintf(
string + slen,
975 slen += snprintf(
string + slen,
982 switch (option->
type) {
984 slen += snprintf(
string + slen,
990 slen += snprintf(
string + slen,
996 slen += snprintf(
string + slen,
1002 slen += snprintf(
string + slen,
1008 slen += snprintf(
string + slen,
1032 string[slen] = fmt[fmtc];
1039 string[
min(slen, size - 1)] =
'\0';
1052 option = &opts[option_idx];
1060 if (option->
value.
s != NULL) {
1067 if ((option->
value.
s != NULL) && (*option->
value.
s == 0)) {
static nserror set_defaults(struct nsoption_s *defaults)
Set option defaults for atari frontend.
Option available on all platforms.
#define NSOPTION_SYS_COLOUR_END
#define NSOPTION_SYS_COLOUR_START
nserror
Enumeration of error codes.
@ NSERROR_NOT_FOUND
Requested item not found.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_INVALID
Invalid data.
@ NSERROR_NOMEM
Memory exhaustion.
Option specific to RISC OS.
Netsurf additional integer type formatting macros.
nserror nslog_set_filter_by_options(void)
Set the logging filter according to the options.
#define NSLOG(catname, level, logmsg, args...)
plotter style interfaces, generic styles and style colour helpers.
#define colour_to_bw_furthest(c0)
#define colour_rb_swap(c)
Interface to utility string handling.
union nsoption_s::@149 value
enum nsoption_type_e type
uint32_t colour
Colour type: XBGR.
struct nsoption_s * nsoptions_default
global default option table.
static bool strtooption(const char *value, struct nsoption_s *option)
Set an option value based on a string.
#define NSOPTION_MAX_LINE_LEN
Length of buffer used to read lines from input file.
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.
static nserror nsoption_dup(struct nsoption_s *src, struct nsoption_s **pdst)
Duplicates an option table.
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.
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.
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.
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.
static nserror optionline(struct nsoption_s *opts, char *line, int linelen)
Process a line from a user option file.
nserror nsoption_set_tbl_charp(struct nsoption_s *opts, enum nsoption_e option_idx, char *s)
Set string option in specified table.
static struct nsoption_s defaults[]
The table of compiled in default options.
static void nsoption_validate(struct nsoption_s *opts, struct nsoption_s *defs)
nserror nsoption_dump(FILE *outf, struct nsoption_s *opts)
Write all options to a stream.
nserror nsoption_read(const char *path, struct nsoption_s *opts)
Read choices file and set them in the passed table.
struct nsoption_s * nsoptions
global active option table.
static nserror nsoption_free(struct nsoption_s *opts)
frees an option table.
nserror nsoption_commandline(int *pargc, char **argv, struct nsoption_s *opts)
Process commandline and set options approriately.
nserror nsoption_init(nsoption_set_default_t *set_defaults, struct nsoption_s **popts, struct nsoption_s **pdefs)
Initialise option system.
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.
nserror nsoption_finalise(struct nsoption_s *opts, struct nsoption_s *defs)
Finalise option system.
static nserror get_key_value(char *line, int linelen, char **key_out, char **value_out)
extract key/value from a line of input
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.
Option reading and saving interface.
size_t() nsoption_generate_cb(struct nsoption_s *option, void *ctx)
option generate callback
nserror() nsoption_set_default_t(struct nsoption_s *defaults)
default setting callback.
@ OPTION_STRING
option is a heap allocated string.
@ OPTION_COLOUR
Option is a netsurf colour.
@ OPTION_UINT
Option is an unsigned integer.
@ OPTION_INTEGER
Option is an integer.
@ OPTION_BOOL
Option is a boolean.
nsoption_generate_flags
flags to control option output in the generate call
@ NSOPTION_GENERATE_ALL
Generate output for all options.
@ NSOPTION_GENERATE_CHANGED
Generate output for options which differ from the default.
Interface to a number of general purpose functionality.
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
static nserror line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.