Rearranged whitespace (and comments) in all the code!
[mmh] / sbr / context_replace.c
1 /*
2  * context_replace.c -- add/replace an entry in the context/profile list
3  *
4  * This code is Copyright (c) 2002, by the authors of nmh.  See the
5  * COPYRIGHT file in the root directory of the nmh distribution for
6  * complete copyright information.
7  */
8
9 #include <h/mh.h>
10 #include <h/utils.h>
11
12
13 void
14 context_replace (char *key, char *value)
15 {
16         register struct node *np;
17
18         /*
19          * If list is emtpy, allocate head of profile/context list.
20          */
21         if (!m_defs) {
22                 m_defs = (struct node *) mh_xmalloc (sizeof(*np));
23
24                 np = m_defs;
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 (!mh_strcasecmp (np->n_name, 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                                 if (np->n_field)
43                                         free (np->n_field);
44                                 np->n_field = getcpy (value);
45                                 ctxflags |= CTXMOD;
46                         }
47                         return;
48                 }
49                 if (!np->n_next)
50                         break;
51         }
52
53         /*
54          * Else add this new entry at the end
55          */
56         np->n_next = (struct node *) mh_xmalloc (sizeof(*np));
57
58         np = np->n_next;
59         np->n_name = getcpy (key);
60         np->n_field = getcpy (value);
61         np->n_context = 1;
62         np->n_next = NULL;
63         ctxflags |= CTXMOD;
64 }