/*
* $Id: objects.c,v 1.3 2025/03/09 19:50:47 snw Exp $
* implementation of OO support
*
*
* Author: Serena Willis <snw@coherent-logic.com>
* Copyright (C) 1998 MUG Deutschland
* Copyright (C) 2023, 2025 Coherent Logic Development LLC
*
*
* This file is part of FreeM.
*
* FreeM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero Public License for more details.
*
* You should have received a copy of the GNU Affero Public License
* along with FreeM. If not, see <https://www.gnu.org/licenses/>.
*
* $Log: objects.c,v $
* Revision 1.3 2025/03/09 19:50:47 snw
* Second phase of REUSE compliance and header reformat
*
*
* SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
* SPDX-License-Identifier: AGPL-3.0-or-later
**/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include "mpsdef.h"
#include "mref.h"
#include "objects.h"
void obj_init(void)
{
register int i;
for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
private_keys[i][0] = EOL;
}
}
short obj_is_field_private(char *key)
{
register int i;
for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
if (stcmp (private_keys[i], key) == 0) {
return TRUE;
}
}
return FALSE;
}
void obj_set_field_private(char *key)
{
register int i;
if (obj_is_field_private (key) == TRUE) return;
for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
if (private_keys[i][0] == EOL) {
stcpy (private_keys[i], key);
return;
}
}
merr_raise (OBJPRIVOVFL);
return;
}
void obj_set_field_public(char *key)
{
register int i;
for (i = 0; i < MAX_PRIVATE_KEYS; i++) {
if (stcmp (private_keys[i], key) == 0) {
private_keys[i][0] = EOL;
return;
}
}
}
short obj_is_object(char *inst)
{
char t_buf[255];
return obj_get_attribute (inst, "CLASS", t_buf);
}
short obj_instance_of(char *inst, char *class)
{
char t_buf[255];
short res;
res = obj_get_attribute (inst, "CLASS", t_buf);
if ((res == FALSE) || (strcmp (t_buf, class) != 0)) {
return FALSE;
}
return TRUE;
}
void obj_set_attribute(char *inst, char *attrib, char *value)
{
char t_key[255];
char t_data[255];
snprintf (t_key, 254, "^$OBJECT\202%s\202%s\201", inst, attrib);
snprintf (t_data, 254, "%s\201", value);
symtab_bltin (set_sym, t_key, t_data);
}
short obj_get_attribute(char *inst, char *attrib, char *buf)
{
char t_key[255];
snprintf (t_key, 254, "^$OBJECT\202%s\202%s\201", inst, attrib);
symtab_bltin (get_sym, t_key, buf);
if (merr () == UNDEF || merr () == M6) {
if (strcmp (attrib, "CLASS") == 0) {
// non-object variables always belong to the ^%STRING class
snprintf (buf, 9, "^%%STRING");
merr_clear ();
return TRUE;
}
else {
merr_clear ();
return FALSE;
}
}
else {
stcnv_m2c (buf);
return TRUE;
}
}
void obj_destroy(char *inst)
{
char t_key[255];
snprintf (t_key, 254, "^$OBJECT\202\%s\201", inst);
symtab_bltin (kill_sym, t_key, " \201");
}
void obj_create_symbols(char *objvar, char *class)
{
char t_key[255];
char t_data[255];
snprintf (t_key, 254, "%s\201", objvar);
snprintf (t_data, 254, " \201");
symtab_bltin (set_sym, t_key, t_data);
obj_set_attribute (objvar, "CLASS", class);
}
void obj_get_constructor(char *constructor, char *class, char *instvar)
{
freem_ref_t inref;
freem_ref_t outref;
register int i;
int argct;
argct = 0;
mref_init (&inref, MREF_RT_GLOBAL, "");
internal_to_mref (&inref, class);
mref_init (&outref, MREF_RT_GLOBAL, inref.name);
strcpy (outref.name, inref.name);
outref.subscript_count = inref.subscript_count + 1;
snprintf (outref.subscripts[0], 255, ".%s", instvar);
for (i = 0; i < inref.subscript_count; i++) {
strcpy (outref.subscripts[i + 1], inref.subscripts[i]);
}
// mref_to_internal_prealloc (constructor, &outref);
mref_to_external (&outref, constructor);
return;
/*
for (i = 0; i < stlen (constructor); i++) {
switch (constructor[i]) {
case '\202':
if (argct == 0) {
constructor[i] = '(';
argct++;
}
else {
constructor[i] = ',';
argct++;
}
break;
case '\201':
constructor[i] = ')';
}
}
constructor[i] = ')';
if (argct > 1) ierr = ARGLIST;
*/
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>