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