projects
/
mmh
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
send use m_getfld2
[mmh]
/
sbr
/
context_read.c
diff --git
a/sbr/context_read.c
b/sbr/context_read.c
index
abf666c
..
51592a9
100644
(file)
--- a/
sbr/context_read.c
+++ b/
sbr/context_read.c
@@
-25,8
+25,12
@@
*/
#include <h/mh.h> /* mh internals */
*/
#include <h/mh.h> /* mh internals */
+#include <h/utils.h>
#include <errno.h> /* system call errors */
#include <pwd.h> /* structure for getpwuid() results */
#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)
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 */
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
/*
** 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) {
*/
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;
}
}
mypath = pw->pw_dir;
}
@@
-61,14
+65,14
@@
context_read(void)
** set mmhpath
*/
if ((cp = getenv("MMH")) && *cp) {
** 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) {
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) {
}
} 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 `mmh' 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 == '/') {
*/
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) {
} 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) {
}
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) {
}
} 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;
}
}
cp = profile;
}
@@
-105,10
+109,10
@@
context_read(void)
** to an absolute one rooted in the home directory.
*/
if ((cp = context_find("path")) == NULL) {
** 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) {
}
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;
}
if (*cp == '/') {
nd = cp;
@@
-117,29
+121,29
@@
context_read(void)
}
if (stat(nd, &st) == -1) {
if (errno != ENOENT) {
}
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)) {
}
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)) {
if (!makedir(nd)) {
- adios(nd, "unable to create");
+ adios(EX_CANTCREAT, nd, "unable to create");
}
} else if ((st.st_mode & S_IFDIR) == 0) {
}
} 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)
*/
}
/*
** Create the default folder (inbox)
*/
- cp = toabsdir(defaultfolder);
+ cp = toabsdir(getdeffol());
if (stat(cp, &st) == -1) {
if (!makedir(cp)) {
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) {
}
} 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);
}
/*
}
/*
@@
-165,7
+169,7
@@
context_read(void)
}
if (*cp == '/') {
}
if (*cp == '/') {
- ctxpath = getcpy(cp);
+ ctxpath = mh_xstrdup(cp);
} else {
ctxpath = concat(mmhpath, "/", cp, NULL);
}
} else {
ctxpath = concat(mmhpath, "/", cp, NULL);
}