From: Richard Russon Date: Sun, 9 Jun 2019 11:33:28 +0000 (+0100) Subject: drop mutt dump X-Git-Tag: 2019-10-25~166^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6395ccfc88d3ab3fd43fa20b87b89fdb61ba4848;p=neomutt drop mutt dump Drop the legacy config dump code. It's less versatile than the new code. --- diff --git a/config/dump.c b/config/dump.c index f88d2d999..9f06d72d2 100644 --- a/config/dump.c +++ b/config/dump.c @@ -139,40 +139,6 @@ struct HashElem **get_elem_list(struct ConfigSet *cs) return list; } -/** - * dump_config_mutt - Dump the config in the style of Mutt - * @param cs Config items - * @param he HashElem representing config item - * @param value Current value of the config item - * @param initial Initial value of the config item - * @param flags Flags, see #ConfigDumpFlags - * @param fp File pointer to write to - */ -void dump_config_mutt(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, - struct Buffer *initial, ConfigDumpFlags flags, FILE *fp) -{ - if (!he || !value || !fp) - return; - - const char *name = he->key.strkey; - - if (DTYPE(he->type) == DT_BOOL) - { - if ((value->data[0] == 'y') || ((value->data[0] == '"') && (value->data[1] == 'y'))) - { - fprintf(fp, "%s is set\n", name); - } - else - { - fprintf(fp, "%s is unset\n", name); - } - } - else - { - fprintf(fp, "%s=%s\n", name, value->data); - } -} - /** * dump_config_neo - Dump the config in the style of NeoMutt * @param cs Config items @@ -227,12 +193,10 @@ void dump_config_neo(struct ConfigSet *cs, struct HashElem *he, struct Buffer *v /** * dump_config - Write all the config to a file * @param cs ConfigSet to dump - * @param style Output style, e.g. #CS_DUMP_STYLE_MUTT * @param flags Flags, see #ConfigDumpFlags * @param fp File to write config to */ -bool dump_config(struct ConfigSet *cs, enum CsDumpStyle style, - ConfigDumpFlags flags, FILE *fp) +bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp) { if (!cs) return false; @@ -318,10 +282,7 @@ bool dump_config(struct ConfigSet *cs, enum CsDumpStyle style, } } - if (style == CS_DUMP_STYLE_MUTT) - dump_config_mutt(cs, he, value, initial, flags, fp); - else - dump_config_neo(cs, he, value, initial, flags, fp); + dump_config_neo(cs, he, value, initial, flags, fp); } FREE(&list); diff --git a/config/dump.h b/config/dump.h index 1dd909961..53169cc68 100644 --- a/config/dump.h +++ b/config/dump.h @@ -31,15 +31,6 @@ struct Buffer; struct ConfigSet; struct HashElem; -/** - * enum CsDumpStyle - Styles of dumping all the config - */ -enum CsDumpStyle -{ - CS_DUMP_STYLE_MUTT, ///< Display config in Mutt style - CS_DUMP_STYLE_NEO, ///< Display config in NeoMutt style -}; - typedef uint8_t ConfigDumpFlags; ///< Flags for dump_config(), e.g. #CS_DUMP_ONLY_CHANGED #define CS_DUMP_NO_FLAGS 0 ///< No flags are set #define CS_DUMP_ONLY_CHANGED (1 << 0) ///< Only show config that the user has changed @@ -51,9 +42,8 @@ typedef uint8_t ConfigDumpFlags; ///< Flags for dump_config(), e.g. #CS_D #define CS_DUMP_SHOW_DISABLED (1 << 6) ///< Show disabled config items, too #define CS_DUMP_SHOW_SYNONYMS (1 << 7) ///< Show synonyms and the config items their linked to -void dump_config_mutt(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, struct Buffer *initial, ConfigDumpFlags flags, FILE *fp); void dump_config_neo(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, struct Buffer *initial, ConfigDumpFlags flags, FILE *fp); -bool dump_config(struct ConfigSet *cs, enum CsDumpStyle style, ConfigDumpFlags flags, FILE *fp); +bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp); int elem_list_sort(const void *a, const void *b); size_t escape_string(struct Buffer *buf, const char *src); struct HashElem **get_elem_list(struct ConfigSet *cs); diff --git a/icommands.c b/icommands.c index d21c08369..50a51ea2c 100644 --- a/icommands.c +++ b/icommands.c @@ -323,11 +323,11 @@ static enum CommandResult icmd_set(struct Buffer *buf, struct Buffer *s, if (mutt_str_strcmp(s->data, "set all") == 0) { - dump_config(Config, CS_DUMP_STYLE_NEO, CS_DUMP_NO_FLAGS, fp_out); + dump_config(Config, CS_DUMP_NO_FLAGS, fp_out); } else if (mutt_str_strcmp(s->data, "set") == 0) { - dump_config(Config, CS_DUMP_STYLE_NEO, CS_DUMP_ONLY_CHANGED, fp_out); + dump_config(Config, CS_DUMP_ONLY_CHANGED, fp_out); } else { diff --git a/main.c b/main.c index 480a89726..f39dc42fa 100644 --- a/main.c +++ b/main.c @@ -754,8 +754,7 @@ int main(int argc, char *argv[], char *envp[]) if (dump_variables) { - dump_config(Config, CS_DUMP_STYLE_NEO, - hide_sensitive ? CS_DUMP_HIDE_SENSITIVE : CS_DUMP_NO_FLAGS, stdout); + dump_config(Config, hide_sensitive ? CS_DUMP_HIDE_SENSITIVE : CS_DUMP_NO_FLAGS, stdout); goto main_ok; // TEST18: neomutt -D } diff --git a/test/config/dump.c b/test/config/dump.c index c360d406e..ce08cac77 100644 --- a/test/config/dump.c +++ b/test/config/dump.c @@ -209,75 +209,6 @@ bool test_get_elem_list(void) return true; } -bool test_dump_config_mutt(void) -{ - // void dump_config_mutt(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, struct Buffer *initial, ConfigDumpFlags flags, FILE *fp); - - { - struct ConfigSet *cs = create_sample_data(); - if (!cs) - return false; - - struct HashElem *he = cs_get_elem(cs, "Apple"); - - struct Buffer *buf_val = mutt_buffer_from("yes"); - struct Buffer *buf_init = mutt_buffer_from("initial"); - - FILE *fp = fopen("/dev/null", "w"); - if (!fp) - return false; - - // Degenerate tests - - dump_config_mutt(NULL, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp); - TEST_CHECK_( - 1, - "dump_config_mutt(NULL, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp)"); - dump_config_mutt(cs, NULL, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp); - TEST_CHECK_( - 1, - "dump_config_mutt(cs, NULL, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp)"); - dump_config_mutt(cs, he, NULL, buf_init, CS_DUMP_NO_FLAGS, fp); - TEST_CHECK_( - 1, "dump_config_mutt(cs, he, NULL, buf_init, CS_DUMP_NO_FLAGS, fp)"); - dump_config_mutt(cs, he, buf_val, NULL, CS_DUMP_NO_FLAGS, fp); - TEST_CHECK_( - 1, "dump_config_mutt(cs, he, buf_val, NULL, CS_DUMP_NO_FLAGS, fp)"); - dump_config_mutt(cs, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, NULL); - TEST_CHECK_( - 1, - "dump_config_mutt(cs, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, NULL)"); - - // Normal tests - - dump_config_mutt(cs, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp); - TEST_CHECK_( - 1, "dump_config_mutt(cs, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp)"); - - mutt_buffer_reset(buf_val); - mutt_buffer_addstr(buf_val, "no"); - - dump_config_mutt(cs, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp); - TEST_CHECK_( - 1, - "dump_config_mutt(NULL, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp)"); - - he = cs_get_elem(cs, "Cherry"); - - dump_config_mutt(cs, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp); - TEST_CHECK_( - 1, - "dump_config_mutt(NULL, he, buf_val, buf_init, CS_DUMP_NO_FLAGS, fp)"); - - fclose(fp); - mutt_buffer_free(&buf_val); - mutt_buffer_free(&buf_init); - cs_free(&cs); - } - - return true; -} - bool test_dump_config_neo(void) { // void dump_config_neo(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, struct Buffer *initial, ConfigDumpFlags flags, FILE *fp); @@ -348,7 +279,7 @@ bool test_dump_config_neo(void) bool test_dump_config(void) { - // bool dump_config(struct ConfigSet *cs, enum CsDumpStyle style, ConfigDumpFlags flags, FILE *fp); + // bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp); { struct ConfigSet *cs = create_sample_data(); @@ -361,20 +292,17 @@ bool test_dump_config(void) // Degenerate tests - TEST_CHECK(!dump_config(NULL, CS_DUMP_STYLE_NEO, CS_DUMP_NO_FLAGS, fp)); - TEST_CHECK(dump_config(cs, CS_DUMP_STYLE_NEO, CS_DUMP_NO_FLAGS, NULL)); + TEST_CHECK(!dump_config(NULL, CS_DUMP_NO_FLAGS, fp)); + TEST_CHECK(dump_config(cs, CS_DUMP_NO_FLAGS, NULL)); // Normal tests - TEST_CHECK(dump_config(cs, CS_DUMP_STYLE_MUTT, CS_DUMP_NO_FLAGS, fp)); - TEST_CHECK(dump_config(cs, CS_DUMP_STYLE_NEO, CS_DUMP_NO_FLAGS, fp)); - TEST_CHECK(dump_config(cs, CS_DUMP_STYLE_NEO, - CS_DUMP_ONLY_CHANGED | CS_DUMP_HIDE_SENSITIVE, fp)); - TEST_CHECK(dump_config(cs, CS_DUMP_STYLE_NEO, - CS_DUMP_HIDE_VALUE | CS_DUMP_SHOW_DEFAULTS, fp)); + TEST_CHECK(dump_config(cs, CS_DUMP_NO_FLAGS, fp)); + TEST_CHECK(dump_config(cs, CS_DUMP_ONLY_CHANGED | CS_DUMP_HIDE_SENSITIVE, fp)); + TEST_CHECK(dump_config(cs, CS_DUMP_HIDE_VALUE | CS_DUMP_SHOW_DEFAULTS, fp)); struct ConfigSet *cs_bad = cs_new(30); - TEST_CHECK(dump_config(cs_bad, CS_DUMP_STYLE_NEO, CS_DUMP_NO_FLAGS, fp)); + TEST_CHECK(dump_config(cs_bad, CS_DUMP_NO_FLAGS, fp)); fclose(fp); cs_free(&cs_bad); @@ -386,18 +314,10 @@ bool test_dump_config(void) void config_dump(void) { - if (!test_pretty_var()) - return; - if (!test_escape_string()) - return; - if (!test_elem_list_sort()) - return; - if (!test_get_elem_list()) - return; - if (!test_dump_config_mutt()) - return; - if (!test_dump_config_neo()) - return; - if (!test_dump_config()) - return; + TEST_CHECK(test_pretty_var()); + TEST_CHECK(test_escape_string()); + TEST_CHECK(test_elem_list_sort()); + TEST_CHECK(test_get_elem_list()); + TEST_CHECK(test_dump_config_neo()); + TEST_CHECK(test_dump_config()); }