From efe737aa87c2f5538925a4c4d9b863e7e257232e Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Wed, 29 Dec 2021 22:11:47 +0100 Subject: [PATCH] [about] Added about:config It is a good place for improvements. --- src/config/conf.c | 75 ++++++++++++++++++++++++++++++++++++++------ src/config/conf.h | 1 + src/protocol/about.c | 8 +++-- 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/config/conf.c b/src/config/conf.c index 4f0bfb27..0a19dca4 100644 --- a/src/config/conf.c +++ b/src/config/conf.c @@ -30,6 +30,7 @@ #include "terminal/terminal.h" #include "util/error.h" #include "util/memory.h" +#include "util/qs_parse/qs_parse.h" #include "util/secsave.h" #include "util/string.h" @@ -671,7 +672,6 @@ parse_config_command(struct option *options, struct conf_parsing_state *state, return show_parse_error(state, ERROR_COMMAND); } -#ifdef CONFIG_EXMODE enum parse_error parse_config_exmode_command(char *cmd) { @@ -684,7 +684,6 @@ parse_config_exmode_command(char *cmd) return parse_config_command(config_options, &state, NULL, 0); } -#endif /* CONFIG_EXMODE */ void parse_config_file(struct option *options, char *name, @@ -1003,6 +1002,7 @@ smart_config_output_fn_html(struct string *string, struct option *option, int action, int i18n) { static unsigned int counter; + int is_str = 0; if (option->type == OPT_ALIAS) { return; @@ -1032,7 +1032,7 @@ smart_config_output_fn_html(struct string *string, struct option *option, add_to_string(string, option->name); add_to_string(string, ""); - add_format_to_string(string, "
", counter); + add_format_to_string(string, "", counter); add_to_string(string, "= 2 && tmp.source[0] == '"' && tmp.source[tmp.length - 1] == '"') { add_bytes_to_string(string, tmp.source + 1, tmp.length - 2); + is_str = 1; } else { add_string_to_string(string, &tmp); } done_string(&tmp); } - add_to_string(string, "\"/>" - "
\n"); + add_to_string(string, "\"/>"); + + if (is_str) { + add_to_string(string, ""); + } + add_to_string(string, "\n"); break; } } @@ -1281,7 +1286,9 @@ write_config_file(char *prefix, char *name, } } - write_config_dialog(term, config_file, secsave_errno, ret); + if (term) { + write_config_dialog(term, config_file, secsave_errno, ret); + } mem_free(config_file); free_cfg_str: @@ -1293,14 +1300,64 @@ free_cfg_str: int write_config(struct terminal *term) { - assert(term); - if (!elinks_home) { - write_config_dialog(term, get_cmd_opt_str("config-file"), + if (term) { + write_config_dialog(term, get_cmd_opt_str("config-file"), SS_ERR_DISABLED, 0); + } return -1; } return write_config_file(elinks_home, get_cmd_opt_str("config-file"), term); } + +void +set_option_or_save(const char *str) +{ +#define NUMKVPAIRS 16 +#define VALSIZE 4096 + int i; + char * kvpairs[NUMKVPAIRS]; + char value[VALSIZE]; + char *option_name; + char *option_value; + char *value_ptr; + + struct string tmp; + + init_string(&tmp); + add_to_string(&tmp, str); + i = qs_parse(tmp.source, kvpairs, 16); + + option_name = qs_k2v("option", kvpairs, i); + option_value = qs_k2v("val", kvpairs, i); + + if (qs_k2v("set", kvpairs, i)) { + struct string cmd; + + char *is_str = qs_k2v("str", kvpairs, i); + + init_string(&cmd); + add_to_string(&cmd, "set "); + add_to_string(&cmd, option_name); + add_to_string(&cmd, " = "); + if (is_str) { + add_char_to_string(&cmd, '"'); + } + add_to_string(&cmd, option_value); + if (is_str) { + add_char_to_string(&cmd, '"'); + } + + parse_config_exmode_command(cmd.source); + done_string(&cmd); + + //set_option(option_name, option_value); + } else if (qs_k2v("save", kvpairs, i)) { + write_config(NULL); + } + done_string(&tmp); +#undef NUMKVPAIRS +#undef VALSIZE +} diff --git a/src/config/conf.h b/src/config/conf.h index b2a09381..7cb1d946 100644 --- a/src/config/conf.h +++ b/src/config/conf.h @@ -29,6 +29,7 @@ int write_config(struct terminal *); char *create_config_string(char *prefix, char *name); char *create_about_config_string(void); +void set_option_or_save(const char *str); struct string *wrap_option_desc(struct string *out, const char *src, const struct string *indent, int maxwidth); diff --git a/src/protocol/about.c b/src/protocol/about.c index ea8c55cb..37b4cf61 100644 --- a/src/protocol/about.c +++ b/src/protocol/about.c @@ -97,14 +97,18 @@ about_protocol_handler(struct connection *conn) if (cached && !cached->content_type) { #ifndef CONFIG_SMALL { - if (!strcmp(conn->uri->data, "config")) { - char *str = create_about_config_string(); + if (!strncmp(conn->uri->data, "config", 6)) { + char *str; + + set_option_or_save(conn->uri->data); + str = create_about_config_string(); if (str) { int len = strlen(str); add_fragment(cached, 0, str, len); conn->from = len; + mem_free(str); } } else { const struct about_page *page = about_pages;