]> diplodocus.org Git - nmh/blob - sbr/context_find.c
Undid commit 475fef2edee9db3c63fc089df76f8e93e3d598cd, it didn't
[nmh] / sbr / context_find.c
1
2 /*
3 * context_find.c -- find an entry in the context/profile list
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
12
13 char *
14 context_find (const char *str)
15 {
16 struct node *np;
17
18 for (np = m_defs; np; np = np->n_next)
19 if (!strcasecmp (np->n_name ? np->n_name : "", str ? str : ""))
20 return (np->n_field);
21
22 return NULL;
23 }
24
25
26 /*
27 * Helper function to search first, if subtype is non-NULL, for
28 * invoname-string-type/subtype and then invoname-string-type.
29 * If entry is found but is empty, returns NULL.
30 */
31 char *
32 context_find_by_type (const char *string, const char *type,
33 const char *subtype) {
34 char *value = NULL;
35
36 if (subtype) {
37 char *cp;
38
39 cp = concat (invo_name, "-", string, "-", type, "/", subtype, NULL);
40 if ((value = context_find (cp)) != NULL && *value == '\0') value = NULL;
41 free (cp);
42 }
43
44 if (value == NULL) {
45 char *cp;
46
47 cp = concat (invo_name, "-", string, "-", type, NULL);
48 if ((value = context_find (cp)) != NULL && *value == '\0') value = NULL;
49 free (cp);
50 }
51
52 return value;
53 }