Annotation of freem/src/objects.c, revision 1.1.1.1
1.1 snw 1: /*
2: * *
3: * * *
4: * * *
5: * ***************
6: * * * * *
7: * * MUMPS *
8: * * * * *
9: * ***************
10: * * *
11: * * *
12: * *
13: *
14: * objects.c
15: * implementation of OO support
16: *
17: *
18: * Author: Serena Willis <jpw@coherent-logic.com>
19: * Copyright (C) 1998 MUG Deutschland
20: * Copyright (C) 2023 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: #include <string.h>
40: #include <stdlib.h>
41: #include <stdio.h>
42: #include <unistd.h>
43: #include <ctype.h>
44:
45: #include "mpsdef.h"
46: #include "mref.h"
47: #include "objects.h"
48:
49: void obj_init(void)
50: {
51: register int i;
52:
53: for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
54: private_keys[i][0] = EOL;
55: }
56: }
57:
58: short obj_is_field_private(char *key)
59: {
60: register int i;
61:
62: for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
63: if (stcmp (private_keys[i], key) == 0) {
64: return TRUE;
65: }
66: }
67:
68: return FALSE;
69: }
70:
71: void obj_set_field_private(char *key)
72: {
73: register int i;
74:
75: if (obj_is_field_private (key) == TRUE) return;
76:
77: for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
78: if (private_keys[i][0] == EOL) {
79: stcpy (private_keys[i], key);
80: return;
81: }
82: }
83:
84: merr_raise (OBJPRIVOVFL);
85: return;
86: }
87:
88: void obj_set_field_public(char *key)
89: {
90: register int i;
91:
92: for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
93: if (stcmp (private_keys[i], key) == 0) {
94: private_keys[i][0] = EOL;
95: return;
96: }
97: }
98: }
99:
100: short obj_is_object(char *inst)
101: {
102: char t_buf[255];
103:
104: return obj_get_attribute (inst, "CLASS", t_buf);
105: }
106:
107: short obj_instance_of(char *inst, char *class)
108: {
109: char t_buf[255];
110: short res;
111:
112: res = obj_get_attribute (inst, "CLASS", t_buf);
113:
114: if ((res == FALSE) || (strcmp (t_buf, class) != 0)) {
115: return FALSE;
116: }
117:
118: return TRUE;
119: }
120:
121: void obj_set_attribute(char *inst, char *attrib, char *value)
122: {
123: char t_key[255];
124: char t_data[255];
125:
126: snprintf (t_key, 254, "^$OBJECT\202%s\202%s\201", inst, attrib);
127: snprintf (t_data, 254, "%s\201", value);
128:
129: symtab_bltin (set_sym, t_key, t_data);
130: }
131:
132: short obj_get_attribute(char *inst, char *attrib, char *buf)
133: {
134: char t_key[255];
135:
136: snprintf (t_key, 254, "^$OBJECT\202%s\202%s\201", inst, attrib);
137:
138: symtab_bltin (get_sym, t_key, buf);
139:
140: if (merr () == UNDEF || merr () == M6) {
141:
142: if (strcmp (attrib, "CLASS") == 0) {
143: // non-object variables always belong to the ^%STRING class
144: snprintf (buf, 9, "^%%STRING");
145:
146: merr_clear ();
147: return TRUE;
148:
149: }
150: else {
151: merr_clear ();
152: return FALSE;
153: }
154: }
155: else {
156: stcnv_m2c (buf);
157: return TRUE;
158: }
159:
160: }
161:
162: void obj_destroy(char *inst)
163: {
164: char t_key[255];
165:
166: snprintf (t_key, 254, "^$OBJECT\202\%s\201", inst);
167: symtab_bltin (kill_sym, t_key, " \201");
168: }
169:
170: void obj_create_symbols(char *objvar, char *class)
171: {
172: char t_key[255];
173: char t_data[255];
174:
175: snprintf (t_key, 254, "%s\201", objvar);
176: snprintf (t_data, 254, " \201");
177:
178: symtab_bltin (set_sym, t_key, t_data);
179:
180: obj_set_attribute (objvar, "CLASS", class);
181:
182: }
183:
184: void obj_get_constructor(char *constructor, char *class, char *instvar)
185: {
186: freem_ref_t inref;
187: freem_ref_t outref;
188: register int i;
189: int argct;
190:
191: argct = 0;
192:
193: mref_init (&inref, MREF_RT_GLOBAL, "");
194: internal_to_mref (&inref, class);
195: mref_init (&outref, MREF_RT_GLOBAL, inref.name);
196:
197: strcpy (outref.name, inref.name);
198: outref.subscript_count = inref.subscript_count + 1;
199:
200: snprintf (outref.subscripts[0], 255, ".%s", instvar);
201:
202: for (i = 0; i < inref.subscript_count; i++) {
203: strcpy (outref.subscripts[i + 1], inref.subscripts[i]);
204: }
205:
206: // mref_to_internal_prealloc (constructor, &outref);
207: mref_to_external (&outref, constructor);
208: return;
209:
210: /*
211: for (i = 0; i < stlen (constructor); i++) {
212:
213: switch (constructor[i]) {
214: case '\202':
215: if (argct == 0) {
216: constructor[i] = '(';
217: argct++;
218: }
219: else {
220: constructor[i] = ',';
221: argct++;
222: }
223: break;
224: case '\201':
225: constructor[i] = ')';
226: }
227:
228: }
229: constructor[i] = ')';
230:
231: if (argct > 1) ierr = ARGLIST;
232: */
233: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>