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))) {
298 if ((all ==
false) &&
303 switch (opts[entry].
type) {
305 fprintf(fp,
"%s:%c\n",
307 opts[entry].
value.b ?
'1' :
'0');
311 fprintf(fp,
"%s:%i\n",
313 opts[entry].
value.i);
318 fprintf(fp,
"%s:%u\n",
320 opts[entry].
value.u);
324 rgbcolour = (((0x000000FF & opts[entry].
value.
c) << 16) |
325 ((0x0000FF00 & opts[entry].
value.
c) << 0) |
326 ((0x00FF0000 & opts[entry].
value.
c) >> 16));
327 fprintf(fp,
"%s:%06"PRIx32
"\n",
334 fprintf(fp,
"%s:%s\n",
336 ((opts[entry].
value.s == NULL) ||
337 (*opts[entry].
value.
s == 0)) ?
"" : opts[entry].
value.
s);
364 switch (option->
type) {
366 slen = snprintf(
string + pos,
369 option->
value.
b ?
"true" :
"false");
373 slen = snprintf(
string + pos,
380 slen = snprintf(
string + pos,
388 slen = snprintf(
string + pos,
390 "<span style=\"font-family:Monospace;\">"
393 "<span style=\"background-color: #%06"PRIx32
"; "
394 "border: 1px solid #%06"PRIx32
"; "
395 "display: inline-block; "
396 "width: 1em; height: 1em;\">"
404 if (option->
value.
s != NULL) {
405 slen = snprintf(
string + pos, size - pos,
"%s",
408 slen = snprintf(
string + pos, size - pos,
409 "<span class=\"null-content\">NULL"
437 switch (option->
type) {
439 slen = snprintf(
string + pos,
442 option->
value.
b ?
'1' :
'0');
446 slen = snprintf(
string + pos,
453 slen = snprintf(
string + pos,
460 rgbcolour = (((0x000000FF & option->
value.
c) << 16) |
461 ((0x0000FF00 & option->
value.
c) << 0) |
462 ((0x00FF0000 & option->
value.
c) >> 16));
463 slen = snprintf(
string + pos, size - pos,
"%06"PRIx32, rgbcolour);
467 if (option->
value.
s != NULL) {
468 slen = snprintf(
string + pos,
501 while (src->
key != NULL) {
532 while (cur->
key != NULL) {
559 if ((*
key !=
' ') && (*
key !=
'\t') && (*
key !=
'\n')) {
589 if (
line[linelen - 1] ==
'\n') {
616 for (idx = 0; opts[idx].
key != NULL; idx++) {
617 if (strcasecmp(
key, opts[idx].
key) == 0) {
737 if ((opts == NULL) || (defs == NULL)) {
741 fp = fopen(
path,
"r");
743 NSLOG(netsurf, INFO,
"Failed to open file '%s'",
path);
747 NSLOG(netsurf, INFO,
"Successfully opened '%s' for Options file",
path);
784 if ((opts == NULL) || (defs == NULL)) {
788 fp = fopen(
path,
"w");
790 NSLOG(netsurf, INFO,
"failed to open file '%s' for writing",
831 unsigned int entry_loop;
833 if ((pargc == NULL) || (argv == NULL)) {
845 while (idx < *pargc) {
847 arglen = strlen(arg);
851 if ((arglen < (2+5) ) || (arg[0] !=
'-') || (arg[1] !=
'-'))
856 val = strchr(arg,
'=');
871 NSLOG(netsurf, INFO,
"%.*s = %s", arglen, arg, val);
876 if (strncmp(arg, opts[entry_loop].
key, arglen) == 0) {
886 for (mv_loop=0; mv_loop < (*pargc - idx); mv_loop++) {
887 argv[mv_loop + 1] = argv[mv_loop + idx];
920 if (option == NULL || option->
key == NULL) {
924 while ((slen < size) && (fmt[fmtc] != 0)) {
925 if (fmt[fmtc] ==
'%') {
929 slen += snprintf(
string + slen,
939 slen += snprintf(
string + slen,
943 slen += snprintf(
string + slen,
950 switch (option->
type) {
952 slen += snprintf(
string + slen,
958 slen += snprintf(
string + slen,
964 slen += snprintf(
string + slen,
970 slen += snprintf(
string + slen,
976 slen += snprintf(
string + slen,
1000 string[slen] = fmt[fmtc];
1007 string[
min(slen, size - 1)] =
'\0';
1020 option = &opts[option_idx];
1028 if (option->
value.
s != NULL) {
1035 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 nserror nsoption_output(FILE *fp, struct nsoption_s *opts, struct nsoption_s *defs, bool all)
Output choices to file stream.
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.
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.
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.
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.