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
/**
* 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;
}
}
- 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);
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
#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);
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);
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();
// 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);
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());
}