Annotation of freem/src/ssvn.c, revision 1.1.1.1
1.1 snw 1: /*
2: * *
3: * * *
4: * * *
5: * ***************
6: * * * * *
7: * * MUMPS *
8: * * * * *
9: * ***************
10: * * *
11: * * *
12: * *
13: *
14: * ssvn.c
15: * structured system variable support
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 <stdio.h>
41: #include <stdlib.h>
42: #include <string.h>
43: #include <sys/types.h>
44: #if !defined(__OpenBSD__) && !defined(__FreeBSD__)
45: # include <sys/timeb.h>
46: #endif
47: #include "mpsdef.h"
48: #include "freem.h"
49: #include "mref.h"
50: #include "mdebug.h"
51:
52: #ifdef USE_SYS_TIME_H
53: # include <sys/time.h>
54: #endif
55:
56: typedef struct ssvn_lut {
57: const char *input_name;
58: const char *canonical_name;
59: } ssvn_lut;
60:
61: ssvn_lut ssv_tab[] = {
62: {"^$C", "^$CHARACTER"},
63: {"^$CHARACTER", "^$CHARACTER"},
64: {"^$D", "^$DEVICE"},
65: {"^$DEVICE", "^$DEVICE"},
66: {"^$DI", "^$DISPLAY"},
67: {"^$DISPLAY", "^$DISPLAY"},
68: {"^$E", "^$EVENT"},
69: {"^$EVENT", "^$EVENT"},
70: {"^$G", "^$GLOBAL"},
71: {"^$GLOBAL", "^$GLOBAL"},
72: {"^$J", "^$JOB"},
73: {"^$JOB", "^$JOB"},
74: {"^$LI","^$LIBRARY"},
75: {"^$LIBRARY","^$LIBRARY"},
76: {"^$L", "^$LOCK"},
77: {"^$LOCK", "^$LOCK"},
78: {"^$O", "^$OBJECT"},
79: {"^$OBJECT", "^$OBJECT"},
80: {"^$R", "^$ROUTINE"},
81: {"^$ROUTINE", "^$ROUTINE"},
82: {"^$S", "^$SYSTEM"},
83: {"^$SYSTEM", "^$SYSTEM"},
84: {"^$W", "^$WINDOW"},
85: {"^$WINDOW", "^$WINDOW"},
86: {"^$ZF", "^$ZFILE"},
87: {"^$ZFILE", "^$ZFILE"},
88: {"^$ZFR", "^$ZFREEM"},
89: {"^$ZFREEM", "^$ZFREEM"},
90: {"^$ZD", "^$ZDIRECTORY"},
91: {"^$ZDIRECTORY", "^$ZDIRECTORY"},
92: {"^$ZO", "^$ZOS"},
93: {"^$ZOS", "^$ZOS"},
94: {"^$ZP", "^$ZPROCESS"},
95: {"^$ZPROCESS", "^$ZPROCESS"},
96: {"^$ZR", "^$ZRPI"},
97: {"^$ZRPI", "^$ZRPI"},
98: {NULL, NULL}
99: };
100:
101:
102: void ssvn (short action, char *key, char *data);
103: void ssvn_normalize_key (char *key);
104:
105: /* structured system variable management */
106: /* set_sym get_sym */
107: /* kill_sym $data */
108: /* kill_all $fra_order */
109: /* killexcl $fra_query */
110: /* new_sym */
111: /* new_all getinc */
112: /* newexcl */
113: /* killone m_alias */
114: /* merge_sym zdata */
115: void ssvn (short action, char *key, char *data)
116: {
117: int i, j;
118: char ch;
119: char ptmp[256];
120:
121: if ((rtn_dialect () == D_M77) ||
122: (rtn_dialect () == D_M84) ||
123: (rtn_dialect () == D_M90)) {
124: merr_raise (NOSTAND);
125: return;
126: }
127:
128: i = 1;
129: j = 2;
130:
131: while ((ch = key[j]) != EOL) {
132:
133: if (ch >= 'a' && ch <= 'z') ch -= 32;
134: if (ch == DELIM) break;
135:
136: ptmp[i++] = ch;
137: j++;
138:
139: }
140:
141: ptmp[0] = SP;
142: ptmp[i++] = SP;
143: ptmp[i] = EOL;
144:
145: ssvn_normalize_key (key);
146:
147: if (dbg_enable_watch && (action == set_sym)) dbg_fire_watch (key);
148:
149: if (merr () > OK) return;
150:
151:
152: if ((ptmp[1] != 'Z') && (ptmp[1] != 'Y')) {
153:
154: if (find (" C CHARACTER D DEVICE DI DISPLAY E EVENT G GLOBAL J JOB LI LIBRARY L LOCK O OBJECT P R ROUTINE S SYSTEM W WINDOW ", ptmp) == FALSE) {
155: merr_raise (M60);
156: return;
157: }
158:
159: switch (ptmp[1]) {
160:
161: case 'C': /* ^$CHARACTER ssvn */
162: ssvn_character (action, key, data);
163: break;
164:
165: case 'D': /* ^$DEVICE and ^$DISPLAY ssvns */
166: switch(ptmp[2]) {
167:
168: case 'E': /* ^$DEVICE */
169: ssvn_device (action, key, data);
170: break;
171:
172: case 'I': /* ^$DISPLAY */
173: ssvn_display (action, key, data);
174: break;
175:
176: default:
177: merr_raise (INVREF);
178: break;
179: }
180:
181: break;
182:
183: case 'E': /* ^$EVENT ssvn */
184: ssvn_event (action, key, data);
185: break;
186:
187: case 'G': /* ^$GLOBAL ssvn */
188: ssvn_global (action, key, data);
189: break;
190:
191: case 'J': /* ^$JOB ssvn */
192: ssvn_job (action, key, data);
193: break;
194:
195: case 'L': /* ^$LIBRARY/^$LOCK ssvns */
196: if (ptmp[2] == 'I') {
197: ssvn_library (action, key, data);
198: }
199: else {
200: ssvn_lock (action, key, data);
201: }
202: break;
203:
204: case 'O':
205: ssvn_object (action, key, data);
206: break;
207:
208: case 'R': /* ^$ROUTINE ssvn */
209: ssvn_routine (action, key, data);
210: break;
211:
212: case 'S': /* ^$SYSTEM ssvn */
213: ssvn_system (action, key, data);
214: break;
215:
216: case 'W': /* ^$WINDOW ssvn */
217: ssvn_window (action, key, data);
218: break;
219:
220: default:
221: merr_raise (INVREF);
222: break;
223: }
224: }
225: else { /* implementation-specific ssvns */
226: ssvn_z (action, key, data);
227: return;
228: }
229:
230: return;
231: }
232:
233: /* convert SSVN names to canonical form (all caps, full-length name) */
234: void ssvn_normalize_key (char *key)
235: {
236: freem_ref_t *ref;
237: char *new_key;
238: ssvn_lut *p;
239: register int i;
240:
241:
242: ref = malloc (sizeof (freem_ref_t));
243: NULLPTRCHK(ref,"ssvn_normalize_key");
244:
245: mref_init (ref, MREF_RT_SSVN, "");
246: internal_to_mref (ref, key);
247:
248: for (i = 0; i < strlen (ref->name); i++) {
249: if (ref->name[i] >= 'a' && ref->name[i] <= 'z') ref->name[i] -= 32;
250: }
251:
252:
253: for (p = ssv_tab; p->input_name != NULL; ++p) {
254:
255: if (strcmp (ref->name, p->input_name) == 0) {
256:
257: strcpy (ref->name, p->canonical_name);
258:
259: new_key = mref_to_internal (ref);
260: stcpy (key, new_key);
261:
262: free (ref);
263: free (new_key);
264:
265: merr_clear ();
266: return;
267:
268: }
269:
270: }
271:
272: merr_raise (M60);
273:
274: free (ref);
275:
276: return;
277:
278: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>