Annotation of freem/src/objects.c, revision 1.5
1.1 snw 1: /*
1.5 ! snw 2: * $Id: objects.c,v 1.4 2025/04/09 19:52:02 snw Exp $
1.1 snw 3: * implementation of OO support
4: *
5: *
1.2 snw 6: * Author: Serena Willis <snw@coherent-logic.com>
1.1 snw 7: * Copyright (C) 1998 MUG Deutschland
1.3 snw 8: * Copyright (C) 2023, 2025 Coherent Logic Development LLC
1.1 snw 9: *
10: *
11: * This file is part of FreeM.
12: *
13: * FreeM is free software: you can redistribute it and/or modify
14: * it under the terms of the GNU Affero Public License as published by
15: * the Free Software Foundation, either version 3 of the License, or
16: * (at your option) any later version.
17: *
18: * FreeM is distributed in the hope that it will be useful,
19: * but WITHOUT ANY WARRANTY; without even the implied warranty of
20: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: * GNU Affero Public License for more details.
22: *
23: * You should have received a copy of the GNU Affero Public License
24: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
25: *
1.4 snw 26: * $Log: objects.c,v $
1.5 ! snw 27: * Revision 1.4 2025/04/09 19:52:02 snw
! 28: * Eliminate as many warnings as possible while building with -Wall
! 29: *
1.4 snw 30: * Revision 1.3 2025/03/09 19:50:47 snw
31: * Second phase of REUSE compliance and header reformat
32: *
1.3 snw 33: *
34: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
35: * SPDX-License-Identifier: AGPL-3.0-or-later
1.1 snw 36: **/
37: #include <string.h>
38: #include <stdlib.h>
39: #include <stdio.h>
40: #include <unistd.h>
41: #include <ctype.h>
42:
43: #include "mpsdef.h"
44: #include "mref.h"
45: #include "objects.h"
46:
47: void obj_init(void)
48: {
49: register int i;
50:
51: for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
52: private_keys[i][0] = EOL;
53: }
54: }
55:
56: short obj_is_field_private(char *key)
57: {
58: register int i;
59:
60: for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
61: if (stcmp (private_keys[i], key) == 0) {
62: return TRUE;
63: }
64: }
65:
66: return FALSE;
67: }
68:
69: void obj_set_field_private(char *key)
70: {
71: register int i;
72:
73: if (obj_is_field_private (key) == TRUE) return;
74:
75: for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
76: if (private_keys[i][0] == EOL) {
77: stcpy (private_keys[i], key);
78: return;
79: }
80: }
81:
82: merr_raise (OBJPRIVOVFL);
83: return;
84: }
85:
86: void obj_set_field_public(char *key)
87: {
88: register int i;
89:
90: for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
91: if (stcmp (private_keys[i], key) == 0) {
92: private_keys[i][0] = EOL;
93: return;
94: }
95: }
96: }
97:
98: short obj_is_object(char *inst)
99: {
100: char t_buf[255];
101:
102: return obj_get_attribute (inst, "CLASS", t_buf);
103: }
104:
105: short obj_instance_of(char *inst, char *class)
106: {
107: char t_buf[255];
108: short res;
109:
110: res = obj_get_attribute (inst, "CLASS", t_buf);
111:
112: if ((res == FALSE) || (strcmp (t_buf, class) != 0)) {
113: return FALSE;
114: }
115:
116: return TRUE;
117: }
118:
119: void obj_set_attribute(char *inst, char *attrib, char *value)
120: {
121: char t_key[255];
122: char t_data[255];
123:
124: snprintf (t_key, 254, "^$OBJECT\202%s\202%s\201", inst, attrib);
125: snprintf (t_data, 254, "%s\201", value);
126:
127: symtab_bltin (set_sym, t_key, t_data);
128: }
129:
130: short obj_get_attribute(char *inst, char *attrib, char *buf)
131: {
132: char t_key[255];
133:
134: snprintf (t_key, 254, "^$OBJECT\202%s\202%s\201", inst, attrib);
135:
136: symtab_bltin (get_sym, t_key, buf);
137:
138: if (merr () == UNDEF || merr () == M6) {
139:
140: if (strcmp (attrib, "CLASS") == 0) {
1.5 ! snw 141: /* non-object variables always belong to the ^%STRING class */
1.1 snw 142: snprintf (buf, 9, "^%%STRING");
143:
144: merr_clear ();
145: return TRUE;
146:
147: }
148: else {
149: merr_clear ();
150: return FALSE;
151: }
152: }
153: else {
154: stcnv_m2c (buf);
155: return TRUE;
156: }
157:
158: }
159:
160: void obj_destroy(char *inst)
161: {
162: char t_key[255];
163:
164: snprintf (t_key, 254, "^$OBJECT\202\%s\201", inst);
165: symtab_bltin (kill_sym, t_key, " \201");
166: }
167:
168: void obj_create_symbols(char *objvar, char *class)
169: {
170: char t_key[255];
171: char t_data[255];
172:
173: snprintf (t_key, 254, "%s\201", objvar);
174: snprintf (t_data, 254, " \201");
175:
176: symtab_bltin (set_sym, t_key, t_data);
177:
178: obj_set_attribute (objvar, "CLASS", class);
179:
180: }
181:
182: void obj_get_constructor(char *constructor, char *class, char *instvar)
183: {
184: freem_ref_t inref;
185: freem_ref_t outref;
186: register int i;
187:
188: mref_init (&inref, MREF_RT_GLOBAL, "");
189: internal_to_mref (&inref, class);
190: mref_init (&outref, MREF_RT_GLOBAL, inref.name);
191:
192: strcpy (outref.name, inref.name);
193: outref.subscript_count = inref.subscript_count + 1;
194:
195: snprintf (outref.subscripts[0], 255, ".%s", instvar);
196:
197: for (i = 0; i < inref.subscript_count; i++) {
198: strcpy (outref.subscripts[i + 1], inref.subscripts[i]);
199: }
200:
1.4 snw 201:
1.1 snw 202: mref_to_external (&outref, constructor);
203: return;
204:
205: /*
206: for (i = 0; i < stlen (constructor); i++) {
207:
208: switch (constructor[i]) {
209: case '\202':
210: if (argct == 0) {
211: constructor[i] = '(';
212: argct++;
213: }
214: else {
215: constructor[i] = ',';
216: argct++;
217: }
218: break;
219: case '\201':
220: constructor[i] = ')';
221: }
222:
223: }
224: constructor[i] = ')';
225:
226: if (argct > 1) ierr = ARGLIST;
227: */
228: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>