Added -nocontentid (and -contentid, for symmetry) switch to mhbuild. This allows...
[mmh] / 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 #include <h/utils.h>
14
15 /*
16  * Foil search of users .mh_profile
17  * If error, return -1, else return 0
18  */
19
20 int
21 context_foil (char *path)
22 {
23     register struct node *np;
24
25     /* In fact, nobody examines defpath in code paths where
26      * it's been set by us -- the uses in the source tree are:
27      *  1 sbr/context_read.c uses it only after setting it itself
28      *  2 uip/install_mh.c uses it only after setting it itself
29      *  3 uip/mshcmds.c and uip/mark.c print it if given the -debug switch
30      * A worthwhile piece of code cleanup would be to make 1 and
31      * 2 use a local variable and just delete 3.
32      *
33      * Similarly, context and ctxpath are not really used
34      * outside the context_* routines. It might be worth combining
35      * them into one file so the variables can be made static.
36      */
37
38     /* We set context to NULL to indicate that no context file
39      * is to be read. (Using /dev/null doesn't work because we
40      * would try to lock it, which causes timeouts with some
41      * locking methods.)
42      */
43     defpath = context = NULL;
44
45     /*
46      * If path is given, create a minimal profile/context list
47      */
48     if (path) {
49         m_defs = (struct node *) mh_xmalloc (sizeof(*np));
50
51         np = m_defs;
52         if (!(np->n_name = strdup ("Path"))) {
53             advise (NULL, "strdup failed");
54             return -1;
55         }
56         if (!(np->n_field = strdup (path))) {
57             advise (NULL, "strdup failed");
58             return -1;
59         }
60         np->n_context = 0;
61         np->n_next = NULL;
62
63         if (mypath == NULL && (mypath = getenv ("HOME")) != NULL)
64             if (!(mypath = strdup (mypath))) {
65                 advise (NULL, "strdup failed");
66                 return -1;
67             }
68     }
69
70     return 0;
71 }
72