Move #include from h/mh.h to source files
[mmh] / sbr / context_read.c
index d1b22ac..166fe59 100644 (file)
@@ -27,6 +27,8 @@
 #include <h/mh.h>    /* mh internals */
 #include <errno.h>   /* system call errors */
 #include <pwd.h>     /* structure for getpwuid() results */
+#include <unistd.h>
+#include <sys/stat.h>
 
 void
 context_read(void)
@@ -68,7 +70,7 @@ context_read(void)
        } else {
                mmhpath = concat(mypath, "/", mmhdir, NULL);
                if (stat(mmhpath, &st) == -1 || (st.st_mode & S_IFDIR) == 0) {
-                       adios(NULL, "Doesn't look like mmh is set up for your account.  Run `install-mh' to do so.");
+                       adios(NULL, "Doesn't look like mmh is set up for your account.  Run `mmh' to do so.");
                }
        }
 
@@ -154,8 +156,8 @@ context_read(void)
        }
 
        /*
-       ** context is NULL if context_foil() was called to disable use
-       ** of context. We also support users setting explicitly setting
+       ** context is NULL if the use of the context was diabled.
+       ** We also support users setting explicitly setting
        ** MMHC to /dev/null.  (If this wasn't special-cased then the
        ** locking would be liable to fail.)
        */
@@ -174,6 +176,18 @@ context_read(void)
                lkfclose(ib, ctxpath);
        }
 
+       /* Set editor */
+       if (!(cp = getenv("MMHEDITOR")) || !*cp) {
+               if (!(cp = context_find("editor")) || !*cp) {
+                       if (!(cp = getenv("VISUAL")) || !*cp) {
+                               if (!(cp = getenv("EDITOR")) || !*cp) {
+                                       cp = defaulteditor;
+                               }
+                       }
+               }
+       }
+       defaulteditor = cp;
+
        /* Set pager */
        if (!(cp = getenv("MMHPAGER")) || !*cp) {
                if (!(cp = context_find("pager")) || !*cp) {