]> diplodocus.org Git - nmh/blob - sbr/context_find.c
mhbuildsbr.c: Flip logic, moving goto to then-block; no need for else.
[nmh] / sbr / context_find.c
1 /* context_find.c -- find an entry in the context/profile list
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
10
11 char *
12 context_find (const char *str)
13 {
14 struct node *np;
15
16 for (np = m_defs; np; np = np->n_next)
17 if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(str)))
18 return (np->n_field);
19
20 return NULL;
21 }
22
23
24 /*
25 * Helper function to search first, if subtype is non-NULL, for
26 * invoname-string-type/subtype and then, if not yet found,
27 * invoname-string-type. If entry is found but is empty, it is
28 * treated as not found.
29 */
30 char *
31 context_find_by_type (const char *string, const char *type,
32 const char *subtype) {
33 char *value = NULL;
34
35 if (subtype) {
36 char *cp;
37
38 cp = concat (invo_name, "-", string, "-", type, "/", subtype, NULL);
39 if ((value = context_find (cp)) != NULL && *value == '\0') value = NULL;
40 free (cp);
41 }
42
43 if (value == NULL) {
44 char *cp;
45
46 cp = concat (invo_name, "-", string, "-", type, NULL);
47 if ((value = context_find (cp)) != NULL && *value == '\0') value = NULL;
48 free (cp);
49 }
50
51 return value;
52 }
53
54
55 /*
56 * Helper function to search profile an entry with name beginning with prefix.
57 * The search is case insensitive.
58 */
59 int
60 context_find_prefix (const char *prefix) {
61 struct node *np;
62
63 for (np = m_defs; np; np = np->n_next) {
64 if (np->n_name && ! strncasecmp (np->n_name, prefix, strlen(prefix))) {
65 return 1;
66 }
67 }
68
69 return 0;
70 }