X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fcontext_read.c;h=cfdcff275c11192a2c753a68084452557d9fb8a9;hp=d1b22ac6bb6ac0cdc2905d2b01a6c0ccc7021ee3;hb=ee8d01d64e8832304256de53db07228e2be67f6a;hpb=0c4214ea2aec6497d0d67b436bbee9bc1d225f1e diff --git a/sbr/context_read.c b/sbr/context_read.c index d1b22ac..cfdcff2 100644 --- a/sbr/context_read.c +++ b/sbr/context_read.c @@ -25,8 +25,12 @@ */ #include /* mh internals */ +#include #include /* system call errors */ #include /* structure for getpwuid() results */ +#include +#include +#include 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); } @@ -174,6 +178,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) {