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)
84#include "qt/options.h"
91#undef NSOPTION_INTEGER
104 switch (option->
type) {
118 if (sscanf(
value,
"%"SCNx32
"", &rgbcolour) == 1) {
119 option->
value.
c = (((0x000000FF & rgbcolour) << 16) |
120 ((0x0000FF00 & rgbcolour) << 0) |
121 ((0x00FF0000 & rgbcolour) >> 16));
126 if (option->
value.
s != NULL) {
152 if (opts[NSOPTION_treeview_font_size].
value.i < 50) {
153 opts[NSOPTION_treeview_font_size].
value.
i = 50;
156 if (opts[NSOPTION_treeview_font_size].
value.i > 1000) {
157 opts[NSOPTION_treeview_font_size].
value.
i = 1000;
160 if (opts[NSOPTION_font_size].
value.i < 50) {
161 opts[NSOPTION_font_size].
value.
i = 50;
164 if (opts[NSOPTION_font_size].
value.i > 1000) {
165 opts[NSOPTION_font_size].
value.
i = 1000;
168 if (opts[NSOPTION_font_min_size].
value.i < 10) {
169 opts[NSOPTION_font_min_size].
value.
i = 10;
172 if (opts[NSOPTION_font_min_size].
value.i > 500) {
173 opts[NSOPTION_font_min_size].
value.
i = 500;
176 if (opts[NSOPTION_memory_cache_size].
value.i < 0) {
177 opts[NSOPTION_memory_cache_size].
value.
i = 0;
188 if (opts[cloop].
value.c != 0) {
193 if (black ==
true && defs != NULL) {
205 if (opts[NSOPTION_max_retried_fetches].
value.u == 0)
206 opts[NSOPTION_max_retried_fetches].
value.
u = 1;
207 if (opts[NSOPTION_curl_fetch_timeout].
value.u < 5)
208 opts[NSOPTION_curl_fetch_timeout].
value.
u = 5;
209 if (opts[NSOPTION_curl_fetch_timeout].
value.u > 60)
210 opts[NSOPTION_curl_fetch_timeout].
value.
u = 60;
211 while (((opts[NSOPTION_curl_fetch_timeout].
value.u *
212 opts[NSOPTION_max_retried_fetches].
value.
u) > 60) &&
213 (opts[NSOPTION_max_retried_fetches].
value.
u > 1))
214 opts[NSOPTION_max_retried_fetches].
value.
u--;
235 switch (opts[entry].
type) {
268 if (((defs[entry].
value.s == NULL) &&
269 (opts[entry].
value.
s != NULL)) ||
270 ((defs[entry].
value.
s != NULL) &&
271 (opts[entry].
value.
s == NULL)) ||
273 (strcmp(opts[entry].
value.s, defs[entry].
value.
s) != 0))) {
295 switch (option->
type) {
297 slen = fprintf(fp,
"%s:%c\n", option->
key, option->
value.
b ?
'1' :
'0');
301 slen = fprintf(fp,
"%s:%i\n", option->
key, option->
value.
i);
306 slen = fprintf(fp,
"%s:%u\n", option->
key, option->
value.
u);
310 rgbcolour = (((0x000000FF & option->
value.
c) << 16) |
311 ((0x0000FF00 & option->
value.
c) << 0) |
312 ((0x00FF0000 & option->
value.
c) >> 16));
313 slen = fprintf(fp,
"%s:%06"PRIx32
"\n", option->
key, rgbcolour);
317 slen = fprintf(fp,
"%s:%s\n",
319 ((option->
value.
s == NULL) ||
345 switch (option->
type) {
347 slen = snprintf(
string + pos,
350 option->
value.
b ?
"true" :
"false");
354 slen = snprintf(
string + pos,
361 slen = snprintf(
string + pos,
369 slen = snprintf(
string + pos,
371 "<span style=\"font-family:Monospace;\">"
374 "<span style=\"background-color: #%06"PRIx32
"; "
375 "border: 1px solid #%06"PRIx32
"; "
376 "display: inline-block; "
377 "width: 1em; height: 1em;\">"
385 if (option->
value.
s != NULL) {
386 slen = snprintf(
string + pos, size - pos,
"%s",
389 slen = snprintf(
string + pos, size - pos,
390 "<span class=\"null-content\">NULL"
418 switch (option->
type) {
420 slen = snprintf(
string + pos,
423 option->
value.
b ?
'1' :
'0');
427 slen = snprintf(
string + pos,
434 slen = snprintf(
string + pos,
441 rgbcolour = (((0x000000FF & option->
value.
c) << 16) |
442 ((0x0000FF00 & option->
value.
c) << 0) |
443 ((0x00FF0000 & option->
value.
c) >> 16));
444 slen = snprintf(
string + pos, size - pos,
"%06"PRIx32, rgbcolour);
448 if (option->
value.
s != NULL) {
449 slen = snprintf(
string + pos,
482 while (src->
key != NULL) {
513 while (cur->
key != NULL) {
540 if ((*
key !=
' ') && (*
key !=
'\t') && (*
key !=
'\n')) {
570 if (
line[linelen - 1] ==
'\n') {
597 for (idx = 0; opts[idx].
key != NULL; idx++) {
598 if (strcasecmp(
key, opts[idx].
key) == 0) {
718 if ((opts == NULL) || (defs == NULL)) {
722 fp = fopen(
path,
"r");
724 NSLOG(netsurf, INFO,
"Failed to open file '%s'",
path);
728 NSLOG(netsurf, INFO,
"Successfully opened '%s' for Options file",
path);
766 if ((opts == NULL) || (defs == NULL)) {
775 generate_cb(opts + entry, generate_ctx);
809 if ((opts == NULL) || (defs == NULL)) {
813 fp = fopen(
path,
"w");
815 NSLOG(netsurf, INFO,
"failed to open file '%s' for writing",
865 unsigned int entry_loop;
867 if ((pargc == NULL) || (argv == NULL)) {
879 while (idx < *pargc) {
881 arglen = strlen(arg);
885 if ((arglen < (2+5) ) || (arg[0] !=
'-') || (arg[1] !=
'-'))
890 val = strchr(arg,
'=');
905 NSLOG(netsurf, INFO,
"%.*s = %s", arglen, arg, val);
910 if (strncmp(arg, opts[entry_loop].
key, arglen) == 0) {
920 for (mv_loop=0; mv_loop < (*pargc - idx); mv_loop++) {
921 argv[mv_loop + 1] = argv[mv_loop + idx];
954 if (option == NULL || option->
key == NULL) {
958 while ((slen < size) && (fmt[fmtc] != 0)) {
959 if (fmt[fmtc] ==
'%') {
963 slen += snprintf(
string + slen,
973 slen += snprintf(
string + slen,
977 slen += snprintf(
string + slen,
984 switch (option->
type) {
986 slen += snprintf(
string + slen,
992 slen += snprintf(
string + slen,
998 slen += snprintf(
string + slen,
1000 "unsigned integer");
1004 slen += snprintf(
string + slen,
1010 slen += snprintf(
string + slen,
1034 string[slen] = fmt[fmtc];
1041 string[
min(slen, size - 1)] =
'\0';
1054 option = &opts[option_idx];
1062 if (option->
value.
s != NULL) {
1069 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.