/*
*
* $Id: cmd_const.c,v 1.3 2025/03/09 19:14:24 snw Exp $
* Implementation of the CONST command
*
*
* Author: Serena Willis <snw@coherent-logic.com>
* Copyright (C) 1998 MUG Deutschland
* Copyright (C) 2023 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: cmd_const.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 <string.h>
#include <stdlib.h>
#include "mpsdef.h"
#include "mcommand.h"
#include "consttbl.h"
MRESULT cmd_const(MACTION *ra)
{
char an[255];
char vn[255];
register char ch;
if (rtn_dialect () != D_FREEM) {
return NOSTAND;
}
/* argumentless is not supported */
if (((ch = *codptr) == SP) || ch == EOL) {
return ARGLIST;
}
for (;;) {
/* grab an mname */
expr (NAME);
if (merr ()) return merr();
stcpy (vn, varnam);
/* CONSTs cannot be globals or SSVNs */
if (vn[0] == '^') {
return GLOBER;
}
/* move to next position */
codptr++;
/* must initialize CONSTs */
if (*codptr != '=') {
return ASSIGNER;
}
/* move past = sign */
codptr++;
/* grab initialization value */
expr (STRING);
if (merr ()) return merr();
/* at this point, the constant name is in vn
and the initializer in argptr */
if (const_is_defined (vn)) {
return CREDEF;
}
stcpy (an, argptr);
symtab (set_sym, vn, an);
const_define (vn, an);
/* TODO: call into const-init code */
if ((ch = *(codptr + 1)) == EOL || ch == SP) {
codptr++;
break;
}
else if (*codptr == ',') {
codptr++;
}
else {
return CMMND;
}
}
*ra = RA_CONTINUE;
return OK;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>