13414247b1ad10e7bf9b2aefc6504527d04f66b4
[mmh] / sbr / context_del.c
1 /*
2 ** context_del.c -- delete an entry from 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
11 /*
12 ** Delete a key/value pair from the context/profile list.
13 ** Return 0 if key is found, else return 1.
14 */
15
16 int
17 context_del (char *key)
18 {
19         register struct node *np, *pp;
20
21         for (np = m_defs, pp = NULL; np; pp = np, np = np->n_next) {
22                 if (!mh_strcasecmp (np->n_name, key)) {
23                         if (!np->n_context)
24                                 admonish (NULL, "bug: context_del(key=\"%s\")", np->n_name);
25                         if (pp)
26                                 pp->n_next = np->n_next;
27                         else
28                                 m_defs = np->n_next;
29                         free (np->n_name);
30                         if (np->n_field)
31                                 free (np->n_field);
32                         free ((char *) np);
33                         ctxflags |= CTXMOD;
34                         return 0;
35                 }
36         }
37
38         return 1;
39 }