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