File:  [Coherent Logic Development] / freem / src / consttbl.c
Revision 1.3: download - view: text, annotated - select for diffs
Sun Mar 9 19:14:24 2025 UTC (3 weeks, 2 days ago) by snw
Branches: MAIN
CVS tags: v0-62-3, v0-62-2, v0-62-1, v0-62-0, HEAD
First phase of REUSE compliance and header reformat

/*
 *   $Id: consttbl.c,v 1.3 2025/03/09 19:14:24 snw Exp $
 *    support for local constants
 *
 *  
 *   Author: Serena Willis <snw@coherent-logic.com>
 *    Copyright (C) 1998 MUG Deutschland
 *    Copyright (C) 2021, 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: consttbl.c,v $
 *   Revision 1.3  2025/03/09 19:14:24  snw
 *   First phase of REUSE compliance and header reformat
 *
 *
 * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
 * SPDX-License-Identifier: AGPL-3.0-or-later 
 **/

#include <stdlib.h>
#include "mpsdef.h"
#include "consttbl.h"

ll_constant *const_head;

short const_define(char *key, char *data)
{
    
    ll_constant *t;    
    
    for (t = const_head; t != NULL; t = t->next) {

	if (stcmp (t->key, key) == 0) {
	    return 0;
	}

    }

    t = (ll_constant *) malloc (sizeof (ll_constant));
    NULLPTRCHK(t,"const_define");

    t->key = (char *) malloc (stlen (key) + 1);
    NULLPTRCHK(t->key,"const_define");

    t->data = (char *) malloc (stlen (data) + 1);
    NULLPTRCHK(t->data,"const_define");
    
    stcpy (t->key, key);
    stcpy (t->data, data);
    t->next = const_head;
    const_head = t;

    return stlen(t->key);

}

short const_is_defined(char *key)
{
    ll_constant *t;

    for (t = const_head; t != NULL; t = t->next) if (stcmp (t->key, key) == 0) return 1;	

    return 0;
    	
}

void const_restore(void)
{
    ll_constant *t;

    restoring_consts = TRUE;
    
    for (t = const_head; t != NULL; t = t->next) {
        symtab (set_sym, t->key, t->data);        
    }

    restoring_consts = FALSE;
    
    return;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>