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