/*
* $Id: cmd_ksubscripts.c,v 1.3 2025/03/09 19:14:24 snw Exp $
* Implementation of the KSUBSCRIPTS 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_ksubscripts.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_ksubscripts(MACTION *ra)
{
register char ch;
char vn[255];
char *old_value;
if ((rtn_dialect () != D_FREEM) &&
(rtn_dialect () != D_MDS)) {
return NOSTAND;
}
if ((old_value = (char *) malloc (STRLEN * sizeof (char))) == NULL) {
return MEMOV;
}
/* argumentless: KSUBSCRIPTS nukleurrr winturr */
if (((ch = *codptr) == SP) || ch == EOL) {
write_m ("Argumentless KSUBSCRIPTS not yet implemented.\201");
free (old_value);
*ra = RA_NEXTCMND;
return OK;
}
if (ch != '(') { /* inclusive KSUBSCRIPTS */
for (;;) {
expr (NAME); /* try to interpret an mname */
if (merr ()) return merr ();
stcpy (vn, varnam);
if (vn[0] != '^') {
symtab (get_sym, vn, old_value);
symtab (kill_sym, vn, NULL);
symtab (set_sym, vn, old_value);
}
else {
if (vn[1] == '$') {
ssvn (get_sym, vn, old_value);
ssvn (kill_sym, vn, NULL);
ssvn (set_sym, vn, old_value);
}
else {
global (get_sym, vn, old_value);
global (kill_sym, vn, NULL);
global (set_sym, vn, old_value);
}
}
free (old_value);
if (merr ()) return merr ();
if ((ch = *(codptr + 1)) == EOL) {
codptr++;
break;
}
else if (ch == ',') {
codptr += 2;
}
else {
return CMMND;
}
}
}
else { /* exclusive KSUBSCRIPTS */
write_m ("Exclusive KSUBSCRIPTS not yet implemented.\201");
while ((ch = *(codptr++)) != SP && ch != EOL) ; /* skip to the end of the command */
}
*ra = RA_NEXTCMND;
return OK;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>