3 * context_read.c -- find and read profile and context files
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
22 register char *cp, *pp;
25 register struct passwd *pw;
32 * Find user's home directory
35 if ((mypath = getenv ("HOME")))
36 mypath = getcpy (mypath);
38 if ((pw = getpwuid (getuid ())) == NULL
41 adios (NULL, "no HOME envariable");
43 mypath = getcpy (pw->pw_dir);
44 if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
49 * open and read user's profile
51 if ((cp = getenv ("MH")) && *cp != '\0') {
52 defpath = path (cp, TFILE);
53 if ((ib = fopen (defpath, "r")) == NULL)
54 adios (defpath, "unable to read");
56 m_putenv ("MH", defpath);
58 defpath = concat (mypath, "/", mh_profile, NULL);
60 if ((ib = fopen (defpath, "r")) == NULL) {
61 switch (pid = vfork ()) {
63 adios ("fork", "unable to");
69 execlp (installproc, "install-mh", "-auto", NULL);
70 fprintf (stderr, "unable to exec ");
76 || (ib = fopen (defpath, "r")) == NULL)
77 adios (NULL, "[install-mh aborted]");
81 readconfig (&m_defs, ib, mh_profile, 0);
85 * Find user's nmh directory
87 if ((pp = context_find ("path")) && *pp != '\0') {
89 snprintf (buf, sizeof(buf), "%s/%s", mypath, pp);
91 strncpy (buf, pp, sizeof(buf));
92 if (stat(buf, &st) == -1) {
94 adios (buf, "error opening");
95 cp = concat ("Your MH-directory \"", buf,
96 "\" doesn't exist; Create it? ", NULL);
98 adios (NULL, "unable to access MH-directory \"%s\"", buf);
101 adios (NULL, "unable to create", buf);
106 * open and read user's context file
108 if (!(cp = getenv ("MHCONTEXT")) || *cp == '\0')
110 ctxpath = getcpy (m_maildir (cp));
111 if ((ib = fopen (ctxpath, "r"))) {
112 readconfig ((struct node **) 0, ib, cp, 1);