Add/update copyright notice in all source code files.
[mmh] / sbr / context_del.c
1
2 /*
3  * context_del.c -- delete an entry from the context/profile list
4  *
5  * $Id$
6  *
7  * This code is Copyright (c) 2002, by the authors of nmh.  See the
8  * COPYRIGHT file in the root directory of the nmh distribution for
9  * complete copyright information.
10  */
11
12 #include <h/mh.h>
13
14 /*
15  * Delete a key/value pair from the context/profile list.
16  * Return 0 if key is found, else return 1.
17  */
18
19 int
20 context_del (char *key)
21 {
22     register struct node *np, *pp;
23
24     /* sanity check - check that context has been read */
25     if (defpath == NULL)
26         adios (NULL, "oops, context hasn't been read yet");
27
28     for (np = m_defs, pp = NULL; np; pp = np, np = np->n_next) {
29         if (!strcasecmp (np->n_name, key)) {
30             if (!np->n_context)
31                 admonish (NULL, "bug: context_del(key=\"%s\")", np->n_name);
32             if (pp)
33                 pp->n_next = np->n_next;
34             else
35                 m_defs = np->n_next;
36             free (np->n_name);
37             if (np->n_field)
38                 free (np->n_field);
39             free ((char *) np);
40             ctxflags |= CTXMOD;
41             return 0;
42         }
43     }
44
45     return 1;
46 }