Fix mhsign for gpg2: Expiry date format
[mmh] / sbr / context_read.c
index 5733d3f..cfdcff2 100644 (file)
 */
 
 #include <h/mh.h>    /* mh internals */
+#include <h/utils.h>
 #include <errno.h>   /* system call errors */
 #include <pwd.h>     /* structure for getpwuid() results */
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sysexits.h>
 
 void
 context_read(void)
@@ -35,8 +39,8 @@ context_read(void)
        char *cp;                    /* miscellaneous pointer            */
        char *nd;                    /* nmh directory pointer            */
        struct stat st;              /* stat() results                   */
-       register struct passwd *pw;  /* getpwuid() results               */
-       register FILE *ib;           /* profile and context file pointer */
+       struct passwd *pw;           /* getpwuid() results               */
+       FILE *ib;                    /* profile and context file pointer */
 
        /*
        ** If this routine _is_ called again (despite the wanings in the
@@ -52,7 +56,7 @@ context_read(void)
        */
        if (!(mypath = getenv("HOME"))) {
                if (!(pw = getpwuid(getuid())) || !*pw->pw_dir) {
-                       adios(NULL, "cannot determine your home directory");
+                       adios(EX_OSERR, NULL, "cannot determine your home directory");
                }
                mypath = pw->pw_dir;
        }
@@ -61,14 +65,14 @@ context_read(void)
        ** set mmhpath
        */
        if ((cp = getenv("MMH")) && *cp) {
-               mmhpath = getcpy(expanddir(cp));  /* rel to cwd */
+               mmhpath = mh_xstrdup(expanddir(cp));  /* rel to cwd */
                if (stat(mmhpath, &st) != -1 && (st.st_mode & S_IFDIR) == 0) {
-                       adios(NULL, "`%s' specified by your MMH environment variable is not a directory", cp);
+                       adios(EX_CONFIG, NULL, "`%s' specified by your MMH environment variable is not a directory", cp);
                }
        } 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(EX_CONFIG, NULL, "Doesn't look like mmh is set up for your account.  Run `mmh' to do so.");
                }
        }
 
@@ -79,20 +83,20 @@ context_read(void)
        */
        if ((cp = getenv("MMHP")) && *cp) {
                if (*cp == '/') {
-                       defpath = getcpy(cp);
+                       defpath = mh_xstrdup(cp);
                } else {
                        defpath = concat(mmhpath, "/", cp, NULL);
                }
                if (stat(defpath, &st) != -1 && (st.st_mode & S_IFREG) == 0) {
-                       adios(NULL, "Your profile `%s', specified by the MMHP environment variable, is not a normal file", cp);
+                       adios(EX_CONFIG, NULL, "Your profile `%s', specified by the MMHP environment variable, is not a normal file", cp);
                }
                if ((ib = fopen(defpath, "r")) == (FILE *)0) {
-                       adios(NULL, "Unable to read your profile `%s', specified by the MMHP environment variable", defpath);
+                       adios(EX_IOERR, NULL, "Unable to read your profile `%s', specified by the MMHP environment variable", defpath);
                }
        } else {
                defpath = concat(mmhpath, "/", profile, NULL);
                if ((ib = fopen(defpath, "r")) == (FILE *)0) {
-                       adios(NULL, "No profile found. Please create `%s' first.", defpath);
+                       adios(EX_CONFIG, NULL, "No profile found. Please create `%s' first.", defpath);
                }
                cp = profile;
        }
@@ -105,10 +109,10 @@ context_read(void)
        ** to an absolute one rooted in the home directory.
        */
        if ((cp = context_find("path")) == NULL) {
-               adios(NULL, "Your profile `%s' does not contain the required path entry.", defpath);
+               adios(EX_CONFIG, NULL, "Your profile `%s' does not contain the required path entry.", defpath);
        }
        if (!*cp) {
-               adios(NULL, "The Path entry of your profile `%s' must be non-empty.", defpath);
+               adios(EX_CONFIG, NULL, "The Path entry of your profile `%s' must be non-empty.", defpath);
        }
        if (*cp == '/') {
                nd = cp;
@@ -117,18 +121,18 @@ context_read(void)
        }
        if (stat(nd, &st) == -1) {
                if (errno != ENOENT) {
-                       adios(nd, "error opening");
+                       adios(EX_IOERR, nd, "error opening");
                }
                cp = concat("Your mail storage directory `", nd, "' doesn't exist; Create it? ", NULL);
                if (!getanswer(cp)) {
-                       adios(NULL, "Unable to access the mail storage directory `%s'", nd);
+                       adios(EX_NOPERM, NULL, "Unable to access the mail storage directory `%s'", nd);
                }
-               free(cp);
+               mh_free0(&cp);
                if (!makedir(nd)) {
-                       adios(nd, "unable to create");
+                       adios(EX_CANTCREAT, nd, "unable to create");
                }
        } else if ((st.st_mode & S_IFDIR) == 0) {
-               adios(NULL, "Your mail storage `%s' is not a directory", nd);
+               adios(EX_DATAERR, NULL, "Your mail storage `%s' is not a directory", nd);
        }
        /*
        ** Create the default folder (inbox)
@@ -136,10 +140,10 @@ context_read(void)
        cp = toabsdir(defaultfolder);
        if (stat(cp, &st) == -1) {
                if (!makedir(cp)) {
-                       adios(cp, "Unable to create the default folder");
+                       adios(EX_CANTCREAT, cp, "Unable to create the default folder");
                }
        } else if ((st.st_mode & S_IFDIR) == 0) {
-               adios(NULL, "The default folder `%s' is not a directory", cp);
+               adios(EX_DATAERR, NULL, "The default folder `%s' is not a directory", cp);
        }
 
        /*
@@ -154,8 +158,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.)
        */
@@ -165,7 +169,7 @@ context_read(void)
        }
 
        if (*cp == '/') {
-               ctxpath = getcpy(cp);
+               ctxpath = mh_xstrdup(cp);
        } else {
                ctxpath = concat(mmhpath, "/", cp, NULL);
        }