1: /*
2: * $Id: consttbl.c,v 1.3 2025/03/09 19:14:24 snw Exp $
3: * support for local constants
4: *
5: *
6: * Author: Serena Willis <snw@coherent-logic.com>
7: * Copyright (C) 1998 MUG Deutschland
8: * Copyright (C) 2021, 2025 Coherent Logic Development LLC
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: *
26: * $Log: consttbl.c,v $
27: * Revision 1.3 2025/03/09 19:14:24 snw
28: * First phase of REUSE compliance and header reformat
29: *
30: *
31: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
32: * SPDX-License-Identifier: AGPL-3.0-or-later
33: **/
34:
35: #include <stdlib.h>
36: #include "mpsdef.h"
37: #include "consttbl.h"
38:
39: ll_constant *const_head;
40:
41: short const_define(char *key, char *data)
42: {
43:
44: ll_constant *t;
45:
46: for (t = const_head; t != NULL; t = t->next) {
47:
48: if (stcmp (t->key, key) == 0) {
49: return 0;
50: }
51:
52: }
53:
54: t = (ll_constant *) malloc (sizeof (ll_constant));
55: NULLPTRCHK(t,"const_define");
56:
57: t->key = (char *) malloc (stlen (key) + 1);
58: NULLPTRCHK(t->key,"const_define");
59:
60: t->data = (char *) malloc (stlen (data) + 1);
61: NULLPTRCHK(t->data,"const_define");
62:
63: stcpy (t->key, key);
64: stcpy (t->data, data);
65: t->next = const_head;
66: const_head = t;
67:
68: return stlen(t->key);
69:
70: }
71:
72: short const_is_defined(char *key)
73: {
74: ll_constant *t;
75:
76: for (t = const_head; t != NULL; t = t->next) if (stcmp (t->key, key) == 0) return 1;
77:
78: return 0;
79:
80: }
81:
82: void const_restore(void)
83: {
84: ll_constant *t;
85:
86: restoring_consts = TRUE;
87:
88: for (t = const_head; t != NULL; t = t->next) {
89: symtab (set_sym, t->key, t->data);
90: }
91:
92: restoring_consts = FALSE;
93:
94: return;
95: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>