]> diplodocus.org Git - nmh/blob - sbr/context_foil.c
Fix stupid accidental dependence on a bash quirk in previous
[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 /* In fact, nobody examines defpath in code paths where
25 * it's been set by us -- the uses in the source tree are:
26 * 1 sbr/context_read.c uses it only after setting it itself
27 * 2 uip/install_mh.c uses it only after setting it itself
28 * 3 uip/mshcmds.c and uip/mark.c print it if given the -debug switch
29 * A worthwhile piece of code cleanup would be to make 1 and
30 * 2 use a local variable and just delete 3.
31 *
32 * Similarly, context and ctxpath are not really used
33 * outside the context_* routines. It might be worth combining
34 * them into one file so the variables can be made static.
35 */
36
37 /* We set context to NULL to indicate that no context file
38 * is to be read. (Using /dev/null doesn't work because we
39 * would try to lock it, which causes timeouts with some
40 * locking methods.)
41 */
42 defpath = context = NULL;
43
44 /*
45 * If path is given, create a minimal profile/context list
46 */
47 if (path) {
48 if (!(m_defs = (struct node *) malloc (sizeof(*np)))) {
49 advise (NULL, "unable to allocate profile storage");
50 return -1;
51 }
52
53 np = m_defs;
54 if (!(np->n_name = strdup ("Path"))) {
55 advise (NULL, "strdup failed");
56 return -1;
57 }
58 if (!(np->n_field = strdup (path))) {
59 advise (NULL, "strdup failed");
60 return -1;
61 }
62 np->n_context = 0;
63 np->n_next = NULL;
64
65 if (mypath == NULL && (mypath = getenv ("HOME")) != NULL)
66 if (!(mypath = strdup (mypath))) {
67 advise (NULL, "strdup failed");
68 return -1;
69 }
70 }
71
72 return 0;
73 }
74