+/* if additional data more == 1, we want to resolve synonyms */
+static void mutt_set_default(const char *name __attribute__ ((unused)), void* p, unsigned long more)
+{
+ char buf[LONG_STRING];
+ struct option_t *ptr = p;
+
+ if (!ptr || *ptr->init || !FuncTable[DTYPE (ptr->type)].opt_fromstr)
+ return;
+
+ mutt_option_value(ptr->option, buf, sizeof(buf));
+ if (m_strlen(ptr->init) == 0 && buf && *buf)
+ ptr->init = m_strdup(buf);
+}
+
+static int init_expand (char** dst, struct option_t* src) {
+ BUFFER token, in;
+ ssize_t len = 0;
+
+ p_delete(dst);
+
+ if (DTYPE(src->type) == DT_STR || DTYPE(src->type) == DT_PATH) {
+ /* only expand for string as it's the only place where
+ * we want to expand vars right now */
+ if (src->init && *src->init) {
+ p_clear(&token, 1);
+ p_clear(&in, 1);
+ len = m_strlen(src->init) + 2;
+ in.data = p_new(char, len + 1);
+ snprintf (in.data, len, "\"%s\"", src->init);
+ in.dptr = in.data;
+ in.dsize = len;
+ mutt_extract_token (&token, &in, 0);
+ if (token.data && *token.data)
+ *dst = m_strdup(token.data);
+ else
+ *dst = m_strdup("");
+ p_delete(&in.data);
+ p_delete(&token.data);
+ } else
+ *dst = m_strdup("");
+ } else
+ /* for non-string: take value as is */
+ *dst = m_strdup(src->init);
+ return (1);
+}
+
+/* if additional data more == 1, we want to resolve synonyms */
+static void mutt_restore_default (const char* name __attribute__ ((unused)),
+ void* p, unsigned long more) {
+ char errbuf[STRING];
+ struct option_t* ptr = (struct option_t*) p;
+ char* init = NULL;
+
+ if (!ptr)
+ return;
+ if (FuncTable[DTYPE (ptr->type)].opt_fromstr) {
+ init_expand (&init, ptr);
+ if (!FuncTable[DTYPE (ptr->type)].opt_fromstr (ptr, init, errbuf,
+ sizeof(errbuf))) {
+ if (!option (OPTNOCURSES))
+ mutt_endwin (NULL);
+ fprintf (stderr, _("Invalid default setting for $%s found: \"%s\".\n"
+ "Please report this error: \"%s\"\n"),
+ ptr->option, NONULL (init), errbuf);
+ exit (1);
+ }
+ p_delete(&init);
+ }
+
+ if (ptr->flags & R_INDEX)
+ set_option (OPTFORCEREDRAWINDEX);
+ if (ptr->flags & R_PAGER)
+ set_option (OPTFORCEREDRAWPAGER);
+ if (ptr->flags & R_RESORT_SUB)
+ set_option (OPTSORTSUBTHREADS);
+ if (ptr->flags & R_RESORT)
+ set_option (OPTNEEDRESORT);
+ if (ptr->flags & R_RESORT_INIT)
+ set_option (OPTRESORTINIT);
+ if (ptr->flags & R_TREE)
+ set_option (OPTREDRAWTREE);
+}
+
+static int check_num (const char* option, unsigned long p,
+ char* errbuf, ssize_t errlen) {
+ if ((int) p < 0) {
+ if (errbuf)
+ snprintf (errbuf, errlen, _("'%d' is invalid for $%s"), (int) p, option);
+ return (0);
+ }
+ return (1);
+}
+
+static int check_history (const char* option __attribute__ ((unused)), unsigned long p,
+ char* errbuf, ssize_t errlen) {
+ if (!check_num ("history", p, errbuf, errlen))
+ return (0);
+ mutt_init_history ();
+ return (1);
+}