]>
diplodocus.org Git - nmh/blob - sbr/context_read.c
3 * context_read.c -- find and read profile and context files
18 register char *cp
, *pp
;
21 register struct passwd
*pw
;
28 * Find user's home directory
31 if ((mypath
= getenv ("HOME")))
32 mypath
= getcpy (mypath
);
34 if ((pw
= getpwuid (getuid ())) == NULL
37 adios (NULL
, "no HOME envariable");
39 mypath
= getcpy (pw
->pw_dir
);
40 if ((cp
= mypath
+ strlen (mypath
) - 1) > mypath
&& *cp
== '/')
45 * open and read user's profile
47 if ((cp
= getenv ("MH")) && *cp
!= '\0') {
48 defpath
= path (cp
, TFILE
);
49 if ((ib
= fopen (defpath
, "r")) == NULL
)
50 adios (defpath
, "unable to read");
52 m_putenv ("MH", defpath
);
54 defpath
= concat (mypath
, "/", mh_profile
, NULL
);
56 if ((ib
= fopen (defpath
, "r")) == NULL
) {
57 switch (pid
= vfork ()) {
59 adios ("fork", "unable to");
65 execlp (installproc
, "install-mh", "-auto", NULL
);
66 fprintf (stderr
, "unable to exec ");
72 || (ib
= fopen (defpath
, "r")) == NULL
)
73 adios (NULL
, "[install-mh aborted]");
77 readconfig (&m_defs
, ib
, mh_profile
, 0);
81 * Find user's nmh directory
83 if ((pp
= context_find ("path")) && *pp
!= '\0') {
85 snprintf (buf
, sizeof(buf
), "%s/%s", mypath
, pp
);
87 strncpy (buf
, pp
, sizeof(buf
));
88 if (stat(buf
, &st
) == -1) {
90 adios (buf
, "error opening");
91 cp
= concat ("Your MH-directory \"", buf
,
92 "\" doesn't exist; Create it? ", NULL
);
94 adios (NULL
, "unable to access MH-directory \"%s\"", buf
);
97 adios (NULL
, "unable to create", buf
);
102 * open and read user's context file
104 if (!(cp
= getenv ("MHCONTEXT")) || *cp
== '\0')
106 ctxpath
= getcpy (m_maildir (cp
));
107 if ((ib
= fopen (ctxpath
, "r"))) {
108 readconfig ((struct node
**) 0, ib
, cp
, 1);