]> granicus.if.org Git - neomutt/commitdiff
factor out struct MyVar
authorRichard Russon <rich@flatcap.org>
Tue, 21 Aug 2018 18:44:44 +0000 (19:44 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 21 Aug 2018 18:44:44 +0000 (19:44 +0100)
Makefile.autosetup
init.c
myvar.c [new file with mode: 0644]
myvar.h

index 566b53f2a09f9244f4966b5757d630ad662fe0e2..2f3f86442d7f4f388bd44489b325af14a1c30036 100644 (file)
@@ -68,7 +68,7 @@ NEOMUTTOBJS=  addrbook.o alias.o bcache.o browser.o color.o commands.o \
                init.o keymap.o mailbox.o main.o menu.o muttlib.o \
                mutt_account.o mutt_attach.o mutt_body.o mutt_header.o \
                mutt_history.o mutt_logging.o mutt_parse.o mutt_signal.o \
-               mutt_socket.o mutt_thread.o mutt_url.o mutt_window.o mx.o \
+               mutt_socket.o mutt_thread.o mutt_url.o mutt_window.o mx.o myvar.o \
                pager.o pattern.o postpone.o progress.o query.o recvattach.o \
                recvcmd.o resize.o rfc1524.o rfc3676.o safe_asprintf.o \
                score.o send.o sendlib.o sidebar.o smtp.o sort.o state.o \
diff --git a/init.c b/init.c
index 54353904ce6c00c72b31fabbf5b53d7d0e61ee37..5d0d1f76618f6345d5d127822afb159582eb47ae 100644 (file)
--- a/init.c
+++ b/init.c
@@ -84,18 +84,6 @@ static const char **Matches;
 /* this is a lie until mutt_init runs: */
 static int MatchesListsize = MAX(NUMVARS, NUMCOMMANDS) + 10;
 
-/**
- * struct MyVar - A user-set variable
- */
-struct MyVar
-{
-  char *name;
-  char *value;
-  TAILQ_ENTRY(MyVar) entries;
-};
-
-static TAILQ_HEAD(, MyVar) MyVars = TAILQ_HEAD_INITIALIZER(MyVars);
-
 #ifdef USE_NOTMUCH
 /* List of tags found in last call to mutt_nm_query_complete(). */
 static char **nm_tags;
@@ -460,27 +448,6 @@ static bool get_hostname(void)
   return true;
 }
 
-/**
- * myvar_del - Unset the value of a "my_" variable
- * @param var Variable name
- */
-static void myvar_del(const char *var)
-{
-  struct MyVar *myv = NULL;
-
-  TAILQ_FOREACH(myv, &MyVars, entries)
-  {
-    if (mutt_str_strcmp(myv->name, var) == 0)
-    {
-      TAILQ_REMOVE(&MyVars, myv, entries);
-      FREE(&myv->name);
-      FREE(&myv->value);
-      FREE(&myv);
-      return;
-    }
-  }
-}
-
 /**
  * parse_attach_list - Parse the "attachments" command
  * @param buf  Buffer for temporary storage
@@ -3270,49 +3237,6 @@ int query_quadoption(int opt, const char *prompt)
   /* not reached */
 }
 
-/**
- * myvar_get - Get the value of a "my_" variable
- * @param var Variable name
- * @retval ptr  Success, value of variable
- * @retval NULL Error, variable doesn't exist
- */
-const char *myvar_get(const char *var)
-{
-  struct MyVar *myv = NULL;
-
-  TAILQ_FOREACH(myv, &MyVars, entries)
-  {
-    if (mutt_str_strcmp(myv->name, var) == 0)
-      return NONULL(myv->value);
-  }
-
-  return NULL;
-}
-
-/**
- * myvar_set - Set the value of a "my_" variable
- * @param var Variable name
- * @param val Value to set
- */
-void myvar_set(const char *var, const char *val)
-{
-  struct MyVar *myv = NULL;
-
-  TAILQ_FOREACH(myv, &MyVars, entries)
-  {
-    if (mutt_str_strcmp(myv->name, var) == 0)
-    {
-      mutt_str_replace(&myv->value, val);
-      return;
-    }
-  }
-
-  myv = mutt_mem_calloc(1, sizeof(struct MyVar));
-  myv->name = mutt_str_strdup(var);
-  myv->value = mutt_str_strdup(val);
-  TAILQ_INSERT_TAIL(&MyVars, myv, entries);
-}
-
 /**
  * mutt_command_complete - Complete a command name
  * @param buf     Buffer for the result
diff --git a/myvar.c b/myvar.c
new file mode 100644 (file)
index 0000000..c50efce
--- /dev/null
+++ b/myvar.c
@@ -0,0 +1,92 @@
+/**
+ * @file
+ * Handling of personal config ('my' variables)
+ *
+ * @authors
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <stddef.h>
+#include "mutt/mutt.h"
+#include "myvar.h"
+
+struct MyVarHead MyVars = TAILQ_HEAD_INITIALIZER(MyVars);
+
+/**
+ * myvar_get - Get the value of a "my_" variable
+ * @param var Variable name
+ * @retval ptr  Success, value of variable
+ * @retval NULL Error, variable doesn't exist
+ */
+const char *myvar_get(const char *var)
+{
+  struct MyVar *myv = NULL;
+
+  TAILQ_FOREACH(myv, &MyVars, entries)
+  {
+    if (mutt_str_strcmp(myv->name, var) == 0)
+      return NONULL(myv->value);
+  }
+
+  return NULL;
+}
+
+/**
+ * myvar_set - Set the value of a "my_" variable
+ * @param var Variable name
+ * @param val Value to set
+ */
+void myvar_set(const char *var, const char *val)
+{
+  struct MyVar *myv = NULL;
+
+  TAILQ_FOREACH(myv, &MyVars, entries)
+  {
+    if (mutt_str_strcmp(myv->name, var) == 0)
+    {
+      mutt_str_replace(&myv->value, val);
+      return;
+    }
+  }
+
+  myv = mutt_mem_calloc(1, sizeof(struct MyVar));
+  myv->name = mutt_str_strdup(var);
+  myv->value = mutt_str_strdup(val);
+  TAILQ_INSERT_TAIL(&MyVars, myv, entries);
+}
+
+/**
+ * myvar_del - Unset the value of a "my_" variable
+ * @param var Variable name
+ */
+void myvar_del(const char *var)
+{
+  struct MyVar *myv = NULL;
+
+  TAILQ_FOREACH(myv, &MyVars, entries)
+  {
+    if (mutt_str_strcmp(myv->name, var) == 0)
+    {
+      TAILQ_REMOVE(&MyVars, myv, entries);
+      FREE(&myv->name);
+      FREE(&myv->value);
+      FREE(&myv);
+      return;
+    }
+  }
+}
diff --git a/myvar.h b/myvar.h
index b48e8535ba2bcb34e2ede77e72aea6731035688c..1e3165cafe56286611accfb00a47b5abe3a8aae1 100644 (file)
--- a/myvar.h
+++ b/myvar.h
@@ -3,6 +3,8 @@
  * Handling of personal config ('my' variables)
  *
  * @authors
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
+ *
  * @copyright
  * This program is free software: you can redistribute it and/or modify it under
  * the terms of the GNU General Public License as published by the Free Software
 #ifndef _MUTT_MYVAR_H
 #define _MUTT_MYVAR_H
 
-#include <stddef.h>
+#include "mutt/mutt.h"
+
+/**
+ * struct MyVar - A user-set variable
+ */
+struct MyVar
+{
+  char *name;
+  char *value;
+  TAILQ_ENTRY(MyVar) entries;
+};
+TAILQ_HEAD(MyVarHead, MyVar);
+
+extern struct MyVarHead MyVars;
 
+void        myvar_del(const char *var);
 const char *myvar_get(const char *var);
+void        myvar_set(const char *var, const char *val);
 
 #endif /* _MUTT_MYVAR_H */