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