]>
diplodocus.org Git - nmh/blob - sbr/context_replace.c
3 * context_replace.c -- add/replace an entry in the context/profile list
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.
16 context_replace (char *key
, char *value
)
18 register struct node
*np
;
20 /* sanity check - check that context has been read */
22 adios (NULL
, "oops, context hasn't been read yet");
25 * If list is emtpy, allocate head of profile/context list.
28 if (!(m_defs
= (struct node
*) malloc (sizeof(*np
))))
29 adios (NULL
, "unable to allocate profile storage");
32 np
->n_name
= getcpy (key
);
33 np
->n_field
= getcpy (value
);
41 * Search list of context/profile entries for
42 * this key, and replace its value if found.
44 for (np
= m_defs
;; np
= np
->n_next
) {
45 if (!strcasecmp (np
->n_name
, key
)) {
46 if (strcmp (value
, np
->n_field
)) {
48 admonish (NULL
, "bug: context_replace(key=\"%s\",value=\"%s\")", key
, value
);
51 np
->n_field
= getcpy (value
);
61 * Else add this new entry at the end
63 np
->n_next
= (struct node
*) malloc (sizeof(*np
));
65 adios (NULL
, "unable to allocate profile storage");
68 np
->n_name
= getcpy (key
);
69 np
->n_field
= getcpy (value
);