+ const char* fmt = (str_cmp (option->option, "umask") == 0) ?
+ "%s=%04o" : "%s=%d";
+ snprintf (dst, dstlen, fmt, option->option,
+ *((short*) option->data));
+}
+
+static int num_from_string (struct option_t* dst, const char* val,
+ char* errbuf, size_t errlen) {
+ int num = 0, old = 0;
+ char* t = NULL;
+
+ if (!dst)
+ return (0);
+
+ num = strtol (val, &t, 0);
+
+ if (!*val || *t || (short) num != num) {
+ if (errbuf) {
+ snprintf (errbuf, errlen, _("'%s' is invalid for $%s"),
+ val, dst->option);
+ }
+ return (0);
+ }
+
+ /* just temporarily accept new val so that check_special for
+ * $history already has it when doing history's init() */
+ old = *((short*) dst->data);
+ *((short*) dst->data) = (short) num;
+
+ if (!check_special (dst->option, (unsigned long) num, errbuf, errlen)) {
+ *((short*) dst->data) = old;
+ return (0);
+ }
+
+ return (1);
+}
+
+static void str_to_string (char* dst, size_t dstlen,
+ struct option_t* option) {
+ snprintf (dst, dstlen, "%s=\"%s\"", option->option,
+ NONULL (*((char**) option->data)));
+}
+
+static void user_to_string (char* dst, size_t dstlen,
+ struct option_t* option) {
+ snprintf (dst, dstlen, "%s=\"%s\"", option->option,
+ NONULL (((char*) option->data)));
+}
+
+static void sys_to_string (char* dst, size_t dstlen,
+ struct option_t* option) {
+ char* val = NULL, *t = NULL;
+ int clean = 0;
+
+ /* get some $muttng_ values dynamically */
+ if (ascii_strcmp ("muttng_pwd", option->option) == 0) {
+ val = mem_malloc (_POSIX_PATH_MAX);
+ val = getcwd (val, _POSIX_PATH_MAX-1);
+ clean = 1;
+ } else if (ascii_strcmp ("muttng_folder_path", option->option) == 0 &&
+ CurrentFolder && *CurrentFolder) {
+ val = CurrentFolder;
+ } else if (ascii_strcmp ("muttng_folder_name", option->option) == 0 &&
+ CurrentFolder && *CurrentFolder) {
+ if ((t = strrchr (CurrentFolder, '/')) != NULL)
+ val = t+1;
+ else
+ val = CurrentFolder;
+ } else
+ val = option->init;
+
+ snprintf (dst, dstlen, "%s=\"%s\"", option->option, NONULL (val));
+ if (clean)
+ mem_free (&val);
+}
+
+static int path_from_string (struct option_t* dst, const char* val,
+ char* errbuf, size_t errlen) {
+ char path[_POSIX_PATH_MAX];
+
+ if (!dst)
+ return (0);
+
+ if (!val || !*val) {
+ mem_free ((char**) dst->data);
+ return (1);
+ }
+
+ path[0] = '\0';
+ strfcpy (path, val, sizeof (path));
+ mutt_expand_path (path, sizeof (path));
+ str_replace ((char **) dst->data, path);
+ return (1);
+}
+
+static int str_from_string (struct option_t* dst, const char* val,
+ char* errbuf, size_t errlen) {
+ if (!dst)
+ return (0);
+
+ if (!check_special (dst->option, (unsigned long) val, errbuf, errlen))
+ return (0);
+
+ str_replace ((char**) dst->data, val);
+ return (1);