[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nmh-commits] CVS: nmh/sbr context_del.c,1.2,1.3 context_find.c,1.2,1.3
From: |
Jon Steinhart <address@hidden> |
Subject: |
[Nmh-commits] CVS: nmh/sbr context_del.c,1.2,1.3 context_find.c,1.2,1.3 context_read.c,1.2,1.3 context_replace.c,1.2,1.3 seq_read.c,1.2,1.3 seq_save.c,1.2,1.3 |
Date: |
Mon, 18 Nov 2002 13:25:10 -0500 |
Update of /cvsroot/nmh/nmh/sbr
In directory subversions:/tmp/cvs-serv2504/sbr
Modified Files:
context_del.c context_find.c context_read.c context_replace.c
seq_read.c seq_save.c
Log Message:
The file README-ATTACHMENTS was removed - it has been moved to the docs
subdirectory. I thought that this had already been done but I guess not.
It's unrelated to the rest of these changes.
The remainder of these changes affect the way that nmh is installed. Nmh
has historically prompted the user for installation when any nmh command
is invoked if it doesn't think that it's installed. This is a problem for
programs that want to, for example, interact with nmh programs via pipes.
These changes alter this behavior. Now, when an nmh program thinks that
nmh isn't installed, it tells the user to run install-mh to install it.
A -check option has been added to install-mh that allows the existence of
an installation to be silently checked and indicated via the exit status.
The bulk of this change is in sbr/read_context.c. In the process of making
these changes, I noticed a fair amount of useless code that I removed. In
particular:
1. The program started with a test for whether or not defpath had already
been set. This could only happen if context_read() was called more
than once, which it isn't. This check also existed and was removed
from the following places:
sbr/context_del.c
sbr/context_find.c
sbr/context_replace.c
sbr/seq_read.c
sbr/seq_save.c
uip/flist.c
uip/folder.c
uip/rmf.c
2. A similar test for mypath was removed. No need to test it since it
doesn't happen. I'm just not a believer that
a = 1;
if (a != 1)
error();
is a good way to write code!
3. I removed the code makes a copy of the $HOME environment variable as
returned by getenv(). It's never changed, so it doesn't need copying.
4. I removed code that copied the pw_dir member of the passwd structure
returned by getpwuid() if $HOME isn't set. Yes, the returned structure
is static, but since the function is never called again the returned
values stay valid and don't need copying.
5. I removed the test for a NULL pw_dir member in the passwd structure
returned by getpwuid() since that never happens.
6. I removed code that removed a trailing / from mypath if mypath is more
than one character long. Unnecessary as // is interpreted as / anyway.
mypath never shows up in an error message, so nobody will ever see it.
Besides, this code didn't handle the case of multiple trailing slashes.
7. I removed code that replaced the MH environment variable contents with
an absolute path if it was a relative one. I'm a bit nervous about this
one, only testing will tell. Any nmh program that's invoked will use
the same context_read() code to convert a relative path to an absolute
one anyway. And there's no guarantee (or discussion) of this feature
in any of the documentation.
8. Althout context_read() tested the MH environment variable, install-mh
didn't. This means that the behavior was not consistent between
install-mh and all other nmh programs. I changed install-mh to be
consistent with context_read().
9. install-mh has been installed in the lib directory, not bin. So a
user would be unlikely to find it when prompted to run it. The
installation has been changed to add a link from bin to lib.
Index: context_del.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/context_del.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** context_del.c 2 Jul 2002 22:09:14 -0000 1.2
--- context_del.c 18 Nov 2002 18:25:02 -0000 1.3
***************
*** 22,29 ****
register struct node *np, *pp;
- /* sanity check - check that context has been read */
- if (defpath == NULL)
- adios (NULL, "oops, context hasn't been read yet");
-
for (np = m_defs, pp = NULL; np; pp = np, np = np->n_next) {
if (!strcasecmp (np->n_name, key)) {
--- 22,25 ----
Index: context_find.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/context_find.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** context_find.c 2 Jul 2002 22:09:14 -0000 1.2
--- context_find.c 18 Nov 2002 18:25:02 -0000 1.3
***************
*** 18,25 ****
struct node *np;
- /* sanity check - check that context has been read */
- if (defpath == NULL)
- adios (NULL, "oops, context hasn't been read yet");
-
for (np = m_defs; np; np = np->n_next)
if (!strcasecmp (np->n_name, str))
--- 18,21 ----
Index: context_read.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/context_read.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** context_read.c 2 Jul 2002 22:09:14 -0000 1.2
--- context_read.c 18 Nov 2002 18:25:02 -0000 1.3
***************
*** 1,3 ****
-
/*
* context_read.c -- find and read profile and context files
--- 1,2 ----
***************
*** 8,115 ****
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
*/
! #include <h/mh.h>
! #include <errno.h>
! #include <pwd.h>
! extern int errno;
void
context_read (void)
{
! pid_t pid;
! register char *cp, *pp;
! char buf[BUFSIZ];
! struct stat st;
! register struct passwd *pw;
! register FILE *ib;
!
! if (defpath)
! return;
/*
! * Find user's home directory
*/
! if (!mypath) {
! if ((mypath = getenv ("HOME")))
! mypath = getcpy (mypath);
else
! if ((pw = getpwuid (getuid ())) == NULL
! || pw->pw_dir == NULL
! || *pw->pw_dir == 0)
! adios (NULL, "no HOME envariable");
! else
! mypath = getcpy (pw->pw_dir);
! if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
! *cp = 0;
}
/*
! * open and read user's profile
*/
! if ((cp = getenv ("MH")) && *cp != '\0') {
! defpath = path (cp, TFILE);
! if ((ib = fopen (defpath, "r")) == NULL)
! adios (defpath, "unable to read");
! if (*cp != '/')
! m_putenv ("MH", defpath);
! } else {
! defpath = concat (mypath, "/", mh_profile, NULL);
!
! if ((ib = fopen (defpath, "r")) == NULL) {
! switch (pid = vfork ()) {
! case -1:
! adios ("fork", "unable to");
!
! case 0:
! setgid (getgid ());
! setuid (getuid ());
!
! execlp (installproc, "install-mh", "-auto", NULL);
! fprintf (stderr, "unable to exec ");
! perror (installproc);
! _exit (-1);
!
! default:
! if (pidwait (pid, 0)
! || (ib = fopen (defpath, "r")) == NULL)
! adios (NULL, "[install-mh aborted]");
! }
! }
}
! readconfig (&m_defs, ib, mh_profile, 0);
fclose (ib);
/*
! * Find user's nmh directory
*/
! if ((pp = context_find ("path")) && *pp != '\0') {
! if (*pp != '/')
! snprintf (buf, sizeof(buf), "%s/%s", mypath, pp);
! else
! strncpy (buf, pp, sizeof(buf));
! if (stat(buf, &st) == -1) {
! if (errno != ENOENT)
! adios (buf, "error opening");
! cp = concat ("Your MH-directory \"", buf,
! "\" doesn't exist; Create it? ", NULL);
! if (!getanswer(cp))
! adios (NULL, "unable to access MH-directory \"%s\"", buf);
! free (cp);
! if (!makedir (buf))
! adios (NULL, "unable to create", buf);
! }
}
/*
! * open and read user's context file
*/
! if (!(cp = getenv ("MHCONTEXT")) || *cp == '\0')
cp = context;
ctxpath = getcpy (m_maildir (cp));
if ((ib = fopen (ctxpath, "r"))) {
readconfig ((struct node **) 0, ib, cp, 1);
fclose (ib);
}
}
--- 7,133 ----
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
+ *
+ * This function must be called early on in any nmh utility, and
+ * may only be called once. It does the following:
+ *
+ * o Sets the global variable "mypath" to the home directory path.
+ *
+ * o Sets the global variable "defpath" to the absolute path of
+ * the profile file.
+ *
+ * o Reads in the profile file. Bails out if it can't.
+ *
+ * o Makes sure that the mail directory exists, prompting for
+ * creation if it doesn't.
+ *
+ * o Reads the context file either as set by the MHCONTEXT
+ * environment variable or by the profile.
*/
! #include <h/mh.h> /* mh internals */
! #include <errno.h> /* system call errors */
! #include <pwd.h> /* structure for getpwuid()
results */
! extern int errno; /* system call error
number */
void
context_read (void)
{
! char buf[BUFSIZ]; /* path name buffer */
! 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 */
/*
! * Find user's home directory. Try the HOME environment variable
first,
! * the home directory field in the password file if that's not
found.
*/
!
! if ((mypath = getenv("HOME")) == (char *)0) {
! if ((pw = getpwuid(getuid())) == (struct passwd *)0 || *pw->pw_dir ==
'\0')
! adios(NULL, "cannot determine your home directory");
else
! mypath = pw->pw_dir;
}
/*
! * Find and read user's profile. Check for the existence of an MH
environment
! * variable first with non-empty contents. Convert any relative
path name
! * found there to an absolute one. Look for the profile in the
user's home
! * directory if the MH environment variable isn't set.
*/
!
! if ((cp = getenv("MH")) && *cp != '\0') {
! defpath = path(cp, TFILE);
!
! if (stat(defpath, &st) != -1 && (st.st_mode & S_IFREG) == 0)
! adios((char *)0, "`%s' specified by your MH environment
variable is not a normal file", cp);
!
! if ((ib = fopen(defpath, "r")) == (FILE *)0)
! adios((char *)0, "unable to read the `%s' profile specified by your
MH environment variable", defpath);
! }
! else {
! defpath = concat(mypath, "/", mh_profile, NULL);
!
! if ((ib = fopen(defpath, "r")) == (FILE *)0)
! adios((char *)0, "Doesn't look like nmh is installed. Run
install-mh to do so.");
!
! cp = mh_profile;
}
!
! readconfig (&m_defs, ib, cp, 0);
fclose (ib);
/*
! * Find the user's nmh directory, which is specified by the "path"
profile component.
! * Convert a relative path name to an absolute one rooted in the
home directory.
*/
!
! if ((cp = context_find ("path")) == (char *)0)
! adios(NULL, "Your %s file does not contain a path entry.", defpath);
!
! if (*cp == '\0')
! adios(NULL, "Your `%s' profile file does not contain a valid path
entry.", defpath);
!
! if (*cp != '/')
! (void)snprintf (nd = buf, sizeof(buf), "%s/%s", mypath, cp);
! else
! nd = cp;
!
! if (stat(nd, &st) == -1) {
! if (errno != ENOENT)
! adios (nd, "error opening");
!
! cp = concat ("Your MH-directory \"", nd, "\" doesn't exist; Create it?
", NULL);
!
! if (!getanswer(cp))
! adios (NULL, "unable to access MH-directory \"%s\"", nd);
!
! free (cp);
!
! if (!makedir (nd))
! adios (NULL, "unable to create", nd);
}
+ else if ((st.st_mode & S_IFDIR) == 0)
+ adios ((char *)0, "`%s' is not a directory", nd);
+
/*
! * Open and read user's context file. The name of the context
file comes from the
! * profile unless overridden by the MHCONTEXT environment variable.
*/
!
! if ((cp = getenv ("MHCONTEXT")) == (char *)0 || *cp == '\0')
cp = context;
+
ctxpath = getcpy (m_maildir (cp));
+
if ((ib = fopen (ctxpath, "r"))) {
readconfig ((struct node **) 0, ib, cp, 1);
fclose (ib);
}
+
+ return;
}
Index: context_replace.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/context_replace.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** context_replace.c 2 Jul 2002 22:09:14 -0000 1.2
--- context_replace.c 18 Nov 2002 18:25:02 -0000 1.3
***************
*** 18,25 ****
register struct node *np;
- /* sanity check - check that context has been read */
- if (defpath == NULL)
- adios (NULL, "oops, context hasn't been read yet");
-
/*
* If list is emtpy, allocate head of profile/context list.
--- 18,21 ----
Index: seq_read.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/seq_read.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** seq_read.c 2 Jul 2002 22:09:14 -0000 1.2
--- seq_read.c 18 Nov 2002 18:25:02 -0000 1.3
***************
*** 30,37 ****
seq_read (struct msgs *mp)
{
- /* sanity check - check that context has been read */
- if (defpath == NULL)
- adios (NULL, "oops, context hasn't been read yet");
-
/*
* Initialize the list of sequence names. Go ahead and
--- 30,33 ----
Index: seq_save.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/seq_save.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** seq_save.c 2 Jul 2002 22:09:14 -0000 1.2
--- seq_save.c 18 Nov 2002 18:25:02 -0000 1.3
***************
*** 32,39 ****
sigset_t set, oset;
- /* sanity check - check that context has been read */
- if (defpath == NULL)
- adios (NULL, "oops, context hasn't been read yet");
-
/* check if sequence information has changed */
if (!(mp->msgflags & SEQMOD))
--- 32,35 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Nmh-commits] CVS: nmh/sbr context_del.c,1.2,1.3 context_find.c,1.2,1.3 context_read.c,1.2,1.3 context_replace.c,1.2,1.3 seq_read.c,1.2,1.3 seq_save.c,1.2,1.3,
Jon Steinhart <address@hidden> <=
- Prev by Date:
[Nmh-commits] CVS: nmh/uip Makefile.in,1.15,1.16 flist.c,1.4,1.5 folder.c,1.4,1.5 install-mh.c,1.4,1.5 rmf.c,1.5,1.6
- Next by Date:
[Nmh-commits] CVS: nmh/man Makefile.in,1.14,1.15
- Previous by thread:
[Nmh-commits] CVS: nmh/uip Makefile.in,1.15,1.16 flist.c,1.4,1.5 folder.c,1.4,1.5 install-mh.c,1.4,1.5 rmf.c,1.5,1.6
- Next by thread:
[Nmh-commits] CVS: nmh/man Makefile.in,1.14,1.15
- Index(es):