+static struct option_t* add_option (const char* name, const char* init,
+ short type, short dup) {
+ struct option_t* option = mem_calloc (1, sizeof (struct option_t));
+
+ debug_print (1, ("adding $%s\n", name));
+
+ option->option = str_dup (name);
+ option->type = type;
+ if (init)
+ option->init = dup ? str_dup (init) : (char*) init;
+ return (option);
+}
+
+/* creates new option_t* of type DT_USER for $user_ var */
+static struct option_t* add_user_option (const char* name) {
+ return (add_option (name, NULL, DT_USER, 1));
+}
+
+/* free()'s option_t* */
+static void del_option (void* p) {
+ struct option_t* ptr = (struct option_t*) p;
+ char* s = (char*) ptr->data;
+ debug_print (1, ("removing option '%s' from table\n", NONULL (ptr->option)));
+ mem_free (&ptr->option);
+ mem_free (&s);
+ mem_free (&ptr->init);
+ mem_free (&ptr);
+}
+
+static int init_expand (char** dst, struct option_t* src) {
+ BUFFER token, in;
+ size_t len = 0;
+
+ mem_free (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) {
+ memset (&token, 0, sizeof (BUFFER));
+ memset (&in, 0, sizeof (BUFFER));
+ len = str_len (src->init) + 2;
+ in.data = mem_malloc (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 = str_dup (token.data);
+ else
+ *dst = str_dup ("");
+ mem_free (&in.data);
+ mem_free (&token.data);
+ } else
+ *dst = str_dup ("");
+ } else
+ /* for non-string: take value as is */
+ *dst = str_dup (src->init);
+ return (1);
+}
+