File:  [Coherent Logic Development] / freem / src / cmd_kvalue.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: cmd_kvalue.c,v 1.3 2025/03/09 19:14:24 snw Exp $
 *    Implementation of the KVALUE command
 *
 *  
 *   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: cmd_kvalue.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_kvalue(MACTION *ra)
{
    register char ch;
    char vn[255];
    
    if ((rtn_dialect () != D_FREEM) &&
        (rtn_dialect () != D_MDS)) {
        return NOSTAND;
    }
    
    /* argumentless: KVALUE nukleurrr winturr */
    if (((ch = *codptr) == SP) || ch == EOL) {
        write_m ("Argumentless KVALUE not yet implemented.\201");
        *ra = RA_NEXTCMND;
        return OK;
    }
    
    
    if (ch != '(') { /* inclusive KVALUE */
        
        for (;;) {

            expr (NAME);                            /* try to interpret an mname */
            if (merr ()) return merr ();
            
            stcpy (vn, varnam);
            
            if (vn[0] != '^') {
                symtab (killone, vn, NULL);
            }
            else {
                if (vn[1] == '$') {
                    ssvn (killone, vn, NULL);
                }
                else {
                    global (killone, vn, NULL);
                }
            }
            
            if (merr ()) return merr ();
            
            if ((ch = *(codptr + 1)) == EOL) {
                codptr++;
                break;
            }
            else if (ch == ',') {
                codptr += 2;
            }
            else {
                return CMMND;
            }
        } 
        
    }
    else { /* exclusive KVALUE */
        
        write_m ("Exclusive KVALUE 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>