BSD 4_3 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Tue, 17 Dec 1985 14:47:08 +0000 (06:47 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Tue, 17 Dec 1985 14:47:08 +0000 (06:47 -0800)
Work on file usr/contrib/mh/uip/install-mh.c
Work on file usr/contrib/mh/sbr/m_delete.c
Work on file usr/contrib/mh/sbr/m_replace.c
Work on file usr/contrib/mh/sbr/add.c

Synthesized-from: CSRG/cd1/4.3

usr/contrib/mh/sbr/add.c [new file with mode: 0644]
usr/contrib/mh/sbr/m_delete.c [new file with mode: 0644]
usr/contrib/mh/sbr/m_replace.c [new file with mode: 0644]
usr/contrib/mh/uip/install-mh.c [new file with mode: 0644]

diff --git a/usr/contrib/mh/sbr/add.c b/usr/contrib/mh/sbr/add.c
new file mode 100644 (file)
index 0000000..b4a5a9f
--- /dev/null
@@ -0,0 +1,24 @@
+/* add.c - concatenate two strings in managed memory */
+
+#include "../h/mh.h"
+#include <stdio.h>
+
+
+char   *add (this, that)
+register char  *this,
+               *that;
+{
+    register char  *cp;
+
+    if (!this)
+       this = "";
+    if (!that)
+       that = "";
+    if ((cp = malloc ((unsigned) (strlen (this) + strlen (that) + 1))) == NULL)
+       adios (NULLCP, "unable to allocate string storage");
+
+    (void) sprintf (cp, "%s%s", that, this);
+    if (*that)
+       free (that);
+    return cp;
+}
diff --git a/usr/contrib/mh/sbr/m_delete.c b/usr/contrib/mh/sbr/m_delete.c
new file mode 100644 (file)
index 0000000..5751371
--- /dev/null
@@ -0,0 +1,32 @@
+/* m_delete.c - delete an entry from the profile */
+
+#include "../h/mh.h"
+#include <stdio.h>
+
+
+m_delete (key)
+register char  *key;
+{
+    register struct node   *np,
+                           *pp;
+
+    m_getdefs ();
+    for (np = m_defs, pp = NULL; np; pp = np, np = np -> n_next) {
+       if (uleq (np -> n_name, key)) {
+           if (!np -> n_context)
+               admonish (NULLCP, "bug: m_delete(key=\"%s\")", np -> n_name);
+           if (pp)
+               pp -> n_next = np -> n_next;
+           else
+               m_defs = np -> n_next;
+           free (np -> n_name);
+           if (np -> n_field)
+               free (np -> n_field);
+           free ((char *) np);
+           ctxflags |= CTXMOD;
+           return 0;
+       }
+    }
+
+    return 1;
+}
diff --git a/usr/contrib/mh/sbr/m_replace.c b/usr/contrib/mh/sbr/m_replace.c
new file mode 100644 (file)
index 0000000..36ac2b9
--- /dev/null
@@ -0,0 +1,53 @@
+/* m_replace.c - replace an entry in the profile */
+
+#include "../h/mh.h"
+#include <stdio.h>
+
+
+void m_replace (key, value)
+register char  *key,
+               *value;
+{
+    register struct node   *np;
+
+    m_getdefs ();
+    if (m_defs == NULL) {
+       np = m_defs = (struct node *) malloc (sizeof *np);
+       if (np == NULL)
+           adios (NULLCP, "unable to allocate profile storage");
+
+       np -> n_name = getcpy (key);
+       np -> n_field = getcpy (value);
+       np -> n_context = 1;
+       np -> n_next = NULL;
+       ctxflags |= CTXMOD;
+       return;
+    }
+
+    for (np = m_defs;; np = np -> n_next) {
+       if (uleq (np -> n_name, key)) {
+           if (strcmp (value, np -> n_field) != 0) {
+               if (!np -> n_context)
+                   admonish (NULLCP, "bug: m_replace(key=\"%s\",value=\"%s\")",
+                           key, value);
+               if (np -> n_field)
+                   free (np -> n_field);
+               np -> n_field = getcpy (value);
+               ctxflags |= CTXMOD;
+           }
+           return;
+       }
+       if (!np -> n_next)
+           break;
+    }
+    np -> n_next = (struct node *) malloc (sizeof *np);
+    if (np -> n_next == NULL)
+       adios (NULLCP, "unable to allocate profile storage");
+
+    np = np -> n_next;
+    np -> n_name = getcpy (key);
+    np -> n_field = getcpy (value);
+    np -> n_context = 1;
+    np -> n_next = NULL;
+    ctxflags |= CTXMOD;
+}
diff --git a/usr/contrib/mh/uip/install-mh.c b/usr/contrib/mh/uip/install-mh.c
new file mode 100644 (file)
index 0000000..4ce8d66
--- /dev/null
@@ -0,0 +1,191 @@
+/* install-mh.c - initialize the MH environment */
+
+#include "../h/mh.h"
+#include <pwd.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/* \f */
+
+static char *message[] = {
+    "Prior to using MH, it is necessary to have a file in your login",
+    "directory (%s) named %s which contains information",
+    "to direct certain MH operations.  The only item which is required",
+    "is the path to use for all MH folder operations.  The suggested MH",
+    "path for you is %s/Mail...",
+    NULL
+};
+
+
+char   *geta ();
+
+struct passwd  *getpwuid ();
+
+/* \f */
+
+/* ARGSUSED */
+
+main (argc, argv)
+int     argc;
+char  **argv;
+{
+    int     autof,
+           i;
+    char   *cp,
+           *path;
+    struct node *np;
+    struct passwd *pw;
+    struct stat st;
+    FILE   *in,
+          *out;
+
+    invo_name = r1bindex (argv[0], '/');
+
+#ifdef COMPAT
+    if (argc == 2 && strcmp (argv[1], "-compat") == 0) {
+       context = "/dev/null";  /* hack past m_getdefs() */
+       
+       m_getdefs ();
+       for (np = m_defs; np; np = np -> n_next)
+           if (uleq (pfolder, np -> n_name)
+                   || ssequal ("atr-", np -> n_name)
+                   || ssequal ("cur-", np -> n_name))
+               np -> n_context = 1;
+
+       ctxpath = getcpy (m_maildir (context = "context"));
+       ctxflags |= CTXMOD;
+       m_update ();
+
+       if ((out = fopen (defpath, "w")) == NULL)
+           adios (defpath, "unable to write");
+       for (np = m_defs; np; np = np -> n_next)
+           if (!np -> n_context)
+               fprintf (out, "%s: %s\n", np -> n_name, np -> n_field);
+       (void) fclose (out);
+
+       done (0);
+    }
+#endif COMPAT
+
+    autof = (argc == 2 && strcmp (argv[1], "-auto") == 0);
+    if (mypath == NULL) {      /* straight from m_getdefs... */
+       if (mypath = getenv ("HOME"))
+           mypath = getcpy (mypath);
+       else
+           if ((pw = getpwuid (getuid ())) == NULL
+                   || pw -> pw_dir == NULL
+                   || *pw -> pw_dir == NULL)
+               adios (NULLCP, "no HOME envariable");
+           else
+               mypath = getcpy (pw -> pw_dir);
+       if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
+           *cp = NULL;
+    }
+    defpath = concat (mypath, "/", mh_profile, NULLCP);
+
+    if (stat (defpath, &st) != NOTOK)
+       if (autof)
+           adios (NULLCP, "invocation error");
+       else
+           adios (NULLCP,
+                   "You already have an MH profile, use an editor to modify it");
+
+    if (!autof && gans ("Do you want help? ", anoyes)) {
+       (void) putchar ('\n');
+       for (i = 0; message[i]; i++) {
+           printf (message[i], mypath, mh_profile);
+           (void) putchar ('\n');
+       }
+       (void) putchar ('\n');
+    }
+
+/* \f */
+
+    cp = concat (mypath, "/", "Mail", NULLCP);
+    if (stat (cp, &st) != NOTOK) {
+       if ((st.st_mode & S_IFMT) == S_IFDIR) {
+           cp = concat ("You already have the standard MH directory \"",
+                   cp, "\".\nDo you want to use it for MH? ", NULLCP);
+           if (gans (cp, anoyes))
+               path = "Mail";
+           else
+               goto query;
+       }
+       else
+           goto query;
+    }
+    else {
+       if (autof)
+           printf ("I'm going to create the standard MH path for you.\n");
+       else
+           cp = concat ("Do you want the standard MH path \"",
+                   mypath, "/", "Mail\"? ", NULLCP);
+       if (autof || gans (cp, anoyes))
+           path = "Mail";
+       else {
+    query:  ;
+           if (gans ("Do you want a path below your login directory? ",
+                       anoyes)) {
+               printf ("What is the path?  %s/", mypath);
+               path = geta ();
+           }
+           else {
+               printf ("What is the whole path?  /");
+               path = concat ("/", geta (), NULLCP);
+           }
+       }
+    }
+
+    (void) chdir (mypath);
+    if (chdir (path) == NOTOK) {
+       cp = concat ("\"", path, "\" doesn't exist; Create it? ", NULLCP);
+       if (autof || gans (cp, anoyes))
+           if (makedir (path) == 0)
+               adios (NULLCP, "unable to create %s", path);
+    }
+    else
+       printf ("[Using existing directory]\n");
+
+/* \f */
+
+    np = m_defs = (struct node *) malloc (sizeof *np);
+    if (np == NULL)
+       adios (NULLCP, "unable to allocate profile storage");
+    np -> n_name = getcpy ("Path");
+    np -> n_field = getcpy (path);
+    np -> n_context = 0;
+    np -> n_next = NULL;
+
+    if (in = fopen (mh_defaults, "r")) {
+       m_readefs (&np -> n_next, in, mh_defaults, 0);
+       (void) fclose (in);
+    }
+
+    ctxpath = getcpy (m_maildir (context = "context"));
+    m_replace (pfolder, defalt);
+    m_update ();
+
+    if ((out = fopen (defpath, "w")) == NULL)
+       adios (defpath, "unable to write");
+    for (np = m_defs; np; np = np -> n_next)
+       if (!np -> n_context)
+           fprintf (out, "%s: %s\n", np -> n_name, np -> n_field);
+    (void) fclose (out);
+
+    done (0);
+}
+
+/* \f */
+
+static char *geta () {
+    register char  *cp;
+    static char line[BUFSIZ];
+
+    (void) fflush (stdout);
+    if (fgets (line, sizeof line, stdin) == NULL)
+       done (1);
+    if (cp = index (line, '\n'))
+       *cp = NULL;
+    return line;
+}