Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / sbr / m_replace.c
1 /* m_replace.c - replace an entry in the profile */
2
3 #include "../h/mh.h"
4 #include <stdio.h>
5
6
7 void m_replace (key, value)
8 register char  *key,
9                *value;
10 {
11     register struct node   *np;
12
13     m_getdefs ();
14     if (m_defs == NULL) {
15         np = m_defs = (struct node *) malloc (sizeof *np);
16         if (np == NULL)
17             adios (NULLCP, "unable to allocate profile storage");
18
19         np -> n_name = getcpy (key);
20         np -> n_field = getcpy (value);
21         np -> n_context = 1;
22         np -> n_next = NULL;
23         ctxflags |= CTXMOD;
24         return;
25     }
26
27     for (np = m_defs;; np = np -> n_next) {
28         if (uleq (np -> n_name, key)) {
29             if (strcmp (value, np -> n_field) != 0) {
30                 if (!np -> n_context)
31                     admonish (NULLCP, "bug: m_replace(key=\"%s\",value=\"%s\")",
32                             key, value);
33                 if (np -> n_field)
34                     free (np -> n_field);
35                 np -> n_field = getcpy (value);
36                 ctxflags |= CTXMOD;
37             }
38             return;
39         }
40         if (!np -> n_next)
41             break;
42     }
43     np -> n_next = (struct node *) malloc (sizeof *np);
44     if (np -> n_next == NULL)
45         adios (NULLCP, "unable to allocate profile storage");
46
47     np = np -> n_next;
48     np -> n_name = getcpy (key);
49     np -> n_field = getcpy (value);
50     np -> n_context = 1;
51     np -> n_next = NULL;
52     ctxflags |= CTXMOD;
53 }