Annotation of freem/src/iftab.c, revision 1.1.1.1
1.1 snw 1: /*
2: * *
3: * * *
4: * * *
5: * ***************
6: * * * * *
7: * * MUMPS *
8: * * * * *
9: * ***************
10: * * *
11: * * *
12: * *
13: *
14: * iftab.c
15: * implementation of the freem transactions-in-flight symbol table
16: *
17: *
18: * Author: Serena Willis <jpw@coherent-logic.com>
19: * Copyright (C) 1998 MUG Deutschland
20: * Copyright (C) 2020 Coherent Logic Development LLC
21: *
22: *
23: * This file is part of FreeM.
24: *
25: * FreeM is free software: you can redistribute it and/or modify
26: * it under the terms of the GNU Affero Public License as published by
27: * the Free Software Foundation, either version 3 of the License, or
28: * (at your option) any later version.
29: *
30: * FreeM is distributed in the hope that it will be useful,
31: * but WITHOUT ANY WARRANTY; without even the implied warranty of
32: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33: * GNU Affero Public License for more details.
34: *
35: * You should have received a copy of the GNU Affero Public License
36: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
37: *
38: **/
39:
40: #include <stdlib.h>
41: #include "iftab.h"
42: #include "mpsdef.h"
43: #include "transact.h"
44:
45: iftab *iftab_head;
46:
47: iftab *iftab_insert(short action, char *key, char *data, int tlevel)
48: {
49: iftab *t;
50:
51: for (t = iftab_head; t != NULL; t = t->next) {
52:
53: if (stcmp (t->key, key) == 0) {
54:
55: /* the key already exists. this is now an update. */
56: free (t->data);
57:
58: t->data = malloc (stlen (data) + 1);
59: NULLPTRCHK(t->data,"iftab_insert");
60:
61: stcpy (t->data, data);
62: t->killed = FALSE;
63:
64: return t;
65: }
66:
67: }
68:
69: /* key did not exist. this is now a true insert. */
70:
71: t = (iftab *) malloc (sizeof (iftab));
72: NULLPTRCHK(t,"iftab_insert");
73:
74: t->key = malloc (stlen (key) + 1);
75: NULLPTRCHK(t->key,"iftab_insert");
76:
77: t->data = malloc (stlen (data) + 1);
78: NULLPTRCHK(t->data,"iftab_insert");
79:
80: stcpy (t->key, key);
81: stcpy (t->data, data);
82:
83: t->killed = FALSE;
84: t->tlevel = tlevel;
85: t->action = action;
86:
87: t->next = iftab_head;
88: iftab_head = t;
89:
90: return t;
91: }
92:
93: iftab *iftab_retrieve(char *key, char *data)
94: {
95: iftab *t;
96:
97: for (t = iftab_head; t != NULL; t = t->next) {
98: if (stcmp (t->key, key) == 0) {
99:
100: data = (char *) malloc (stlen (t->data) + 1);
101: NULLPTRCHK(data,"iftab_retrieve");
102:
103: stcpy (data, t->data);
104:
105: return t;
106: }
107: }
108:
109: return (iftab *) NULL;
110: }
111:
112: void iftab_delete(char *key)
113: {
114: iftab *t = iftab_head;
115: iftab *p = NULL;
116:
117:
118: if ((t != (iftab *) NULL) && (stcmp (t->key, key) == 0)) {
119: iftab_head = t->next;
120:
121: free (t->key);
122: free (t->data);
123: free (t);
124: return;
125: }
126:
127: while ((t != NULL) && (stcmp (t->key, key) != 0)) {
128: p = t;
129: t = t->next;
130: }
131:
132: if (t == NULL) return;
133:
134: p->next = t->next;
135: free (t->key);
136: free (t->data);
137: free (t);
138:
139: return;
140: }
141:
142: iftab *iftab_kill(char *key)
143: {
144: iftab *t;
145:
146: for(t = iftab_head; t != NULL; t = t->next) {
147: if (stcmp (t->key, key) == 0) {
148: t->killed = TRUE;
149:
150: return t;
151: }
152: }
153:
154: t = iftab_insert (kill_sym, key, "\201", tp_level);
155: t->killed = TRUE;
156:
157: return t;
158: }
159:
160: void iftab_pop_tlevel(int tlevel)
161: {
162: iftab *t;
163:
164: for (t = iftab_head; t != NULL; t = t->next) {
165: if (t->tlevel == tlevel) iftab_delete (t->key);
166: }
167: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>