1 | |
---|
2 | /* |
---|
3 | * context_replace.c -- add/replace an entry in the context/profile list |
---|
4 | * |
---|
5 | * $Id: context_replace.c,v 1.1.1.1 1999-02-07 18:14:07 danw Exp $ |
---|
6 | */ |
---|
7 | |
---|
8 | #include <h/mh.h> |
---|
9 | |
---|
10 | |
---|
11 | void |
---|
12 | context_replace (char *key, char *value) |
---|
13 | { |
---|
14 | register struct node *np; |
---|
15 | |
---|
16 | /* sanity check - check that context has been read */ |
---|
17 | if (defpath == NULL) |
---|
18 | adios (NULL, "oops, context hasn't been read yet"); |
---|
19 | |
---|
20 | /* |
---|
21 | * If list is emtpy, allocate head of profile/context list. |
---|
22 | */ |
---|
23 | if (!m_defs) { |
---|
24 | if (!(m_defs = (struct node *) malloc (sizeof(*np)))) |
---|
25 | adios (NULL, "unable to allocate profile storage"); |
---|
26 | |
---|
27 | np = m_defs; |
---|
28 | np->n_name = getcpy (key); |
---|
29 | np->n_field = getcpy (value); |
---|
30 | np->n_context = 1; |
---|
31 | np->n_next = NULL; |
---|
32 | ctxflags |= CTXMOD; |
---|
33 | return; |
---|
34 | } |
---|
35 | |
---|
36 | /* |
---|
37 | * Search list of context/profile entries for |
---|
38 | * this key, and replace its value if found. |
---|
39 | */ |
---|
40 | for (np = m_defs;; np = np->n_next) { |
---|
41 | if (!strcasecmp (np->n_name, key)) { |
---|
42 | if (strcmp (value, np->n_field)) { |
---|
43 | if (!np->n_context) |
---|
44 | admonish (NULL, "bug: context_replace(key=\"%s\",value=\"%s\")", key, value); |
---|
45 | if (np->n_field) |
---|
46 | free (np->n_field); |
---|
47 | np->n_field = getcpy (value); |
---|
48 | ctxflags |= CTXMOD; |
---|
49 | } |
---|
50 | return; |
---|
51 | } |
---|
52 | if (!np->n_next) |
---|
53 | break; |
---|
54 | } |
---|
55 | |
---|
56 | /* |
---|
57 | * Else add this new entry at the end |
---|
58 | */ |
---|
59 | np->n_next = (struct node *) malloc (sizeof(*np)); |
---|
60 | if (!np->n_next) |
---|
61 | adios (NULL, "unable to allocate profile storage"); |
---|
62 | |
---|
63 | np = np->n_next; |
---|
64 | np->n_name = getcpy (key); |
---|
65 | np->n_field = getcpy (value); |
---|
66 | np->n_context = 1; |
---|
67 | np->n_next = NULL; |
---|
68 | ctxflags |= CTXMOD; |
---|
69 | } |
---|