]> diplodocus.org Git - nmh/blob - sbr/context_foil.c
Bring these changes over from the branch.
[nmh] / sbr / context_foil.c
1
2 /*
3 * context_foil.c -- foil search of profile and context
4 *
5 * $Id$
6 *
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.
10 */
11
12 #include <h/mh.h>
13
14 /*
15 * Foil search of users .mh_profile
16 * If error, return -1, else return 0
17 */
18
19 int
20 context_foil (char *path)
21 {
22 register struct node *np;
23
24 defpath = context = "/dev/null";
25
26 /*
27 * If path is given, create a minimal profile/context list
28 */
29 if (path) {
30 if (!(m_defs = (struct node *) malloc (sizeof(*np)))) {
31 advise (NULL, "unable to allocate profile storage");
32 return -1;
33 }
34
35 np = m_defs;
36 if (!(np->n_name = strdup ("Path"))) {
37 advise (NULL, "strdup failed");
38 return -1;
39 }
40 if (!(np->n_field = strdup (path))) {
41 advise (NULL, "strdup failed");
42 return -1;
43 }
44 np->n_context = 0;
45 np->n_next = NULL;
46
47 if (mypath == NULL && (mypath = getenv ("HOME")) != NULL)
48 if (!(mypath = strdup (mypath))) {
49 advise (NULL, "strdup failed");
50 return -1;
51 }
52 }
53
54 return 0;
55 }
56