]> diplodocus.org Git - nmh/blob - sbr/context_replace.c
mhbuildsbr.c: Flip logic, moving goto to then-block; no need for else.
[nmh] / sbr / context_replace.c
1 /* context_replace.c -- add/replace 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 #include <h/utils.h>
10
11
12 void
13 context_replace (char *key, char *value)
14 {
15 struct node *np;
16
17 /*
18 * If list is empty, allocate head of profile/context list.
19 */
20 if (!m_defs) {
21 NEW(np);
22 m_defs = np;
23 np->n_name = getcpy (key);
24 np->n_field = getcpy (value);
25 np->n_context = 1;
26 np->n_next = NULL;
27 ctxflags |= CTXMOD;
28 return;
29 }
30
31 /*
32 * Search list of context/profile entries for
33 * this key, and replace its value if found.
34 */
35 for (np = m_defs;; np = np->n_next) {
36 if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(key))) {
37 if (strcmp (value, np->n_field)) {
38 if (!np->n_context)
39 inform("bug: context_replace(key=\"%s\",value=\"%s\"), continuing...", key, value);
40 mh_xfree(np->n_field);
41 np->n_field = mh_xstrdup(value);
42 ctxflags |= CTXMOD;
43 }
44 return;
45 }
46 if (!np->n_next)
47 break;
48 }
49
50 /*
51 * Else add this new entry at the end
52 */
53 NEW(np->n_next);
54 np = np->n_next;
55 np->n_name = getcpy (key);
56 np->n_field = getcpy (value);
57 np->n_context = 1;
58 np->n_next = NULL;
59 ctxflags |= CTXMOD;
60 }