]> diplodocus.org Git - nmh/blob - sbr/context_find.c
pending-release-notes: add mhshow's "-prefer", and mh-format's %(kibi/kilo)
[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, if not yet found,
29 * invoname-string-type. If entry is found but is empty, it is
30 * treated as not found.
31 */
32 char *
33 context_find_by_type (const char *string, const char *type,
34 const char *subtype) {
35 char *value = NULL;
36
37 if (subtype) {
38 char *cp;
39
40 cp = concat (invo_name, "-", string, "-", type, "/", subtype, NULL);
41 if ((value = context_find (cp)) != NULL && *value == '\0') value = NULL;
42 free (cp);
43 }
44
45 if (value == NULL) {
46 char *cp;
47
48 cp = concat (invo_name, "-", string, "-", type, NULL);
49 if ((value = context_find (cp)) != NULL && *value == '\0') value = NULL;
50 free (cp);
51 }
52
53 return value;
54 }