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

    1: /*
    2:  *
    3:  *   $Id: cmd_const.c,v 1.3 2025/03/09 19:14:24 snw Exp $
    4:  *    Implementation of the CONST command
    5:  *
    6:  *  
    7:  *   Author: Serena Willis <snw@coherent-logic.com>
    8:  *    Copyright (C) 1998 MUG Deutschland
    9:  *    Copyright (C) 2023 Coherent Logic Development LLC
   10:  *
   11:  *
   12:  *   This file is part of FreeM.
   13:  *
   14:  *   FreeM is free software: you can redistribute it and/or modify
   15:  *   it under the terms of the GNU Affero Public License as published by
   16:  *   the Free Software Foundation, either version 3 of the License, or
   17:  *   (at your option) any later version.
   18:  *
   19:  *   FreeM is distributed in the hope that it will be useful,
   20:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   21:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22:  *   GNU Affero Public License for more details.
   23:  *
   24:  *   You should have received a copy of the GNU Affero Public License
   25:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
   26:  *
   27:  *   $Log: cmd_const.c,v $
   28:  *   Revision 1.3  2025/03/09 19:14:24  snw
   29:  *   First phase of REUSE compliance and header reformat
   30:  *
   31:  *
   32:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
   33:  * SPDX-License-Identifier: AGPL-3.0-or-later
   34:  **/
   35: 
   36: #include <string.h>
   37: #include <stdlib.h>
   38: #include "mpsdef.h"
   39: #include "mcommand.h"
   40: #include "consttbl.h"
   41: 
   42: MRESULT cmd_const(MACTION *ra)
   43: {
   44:     char an[255];
   45:     char vn[255];
   46:     register char ch;
   47:     
   48:     if (rtn_dialect () != D_FREEM) {
   49:         return NOSTAND;
   50:     }
   51:     
   52:     /* argumentless is not supported */
   53:     if (((ch = *codptr) == SP) || ch == EOL) {
   54:         return ARGLIST;
   55:     }
   56:     
   57:     for (;;) {
   58:         
   59:         /* grab an mname */
   60:         expr (NAME);
   61:         if (merr ()) return merr();
   62:         
   63:         stcpy (vn, varnam);
   64:         
   65:         /* CONSTs cannot be globals or SSVNs */
   66:         if (vn[0] == '^') {
   67:             return GLOBER;
   68:         }
   69:         
   70:         /* move to next position */
   71:         codptr++;	       
   72:         
   73:         /* must initialize CONSTs */
   74:         if (*codptr != '=') {		    
   75:             return ASSIGNER;
   76:         }
   77:         
   78:         /* move past = sign */
   79:         codptr++;
   80:         
   81:         /* grab initialization value */
   82:         expr (STRING);		
   83:         if (merr ()) return merr();
   84:         
   85:         /* at this point, the constant name is in vn
   86:            and the initializer in argptr */
   87:         if (const_is_defined (vn)) {
   88:             return CREDEF;
   89:         }
   90:         
   91:         stcpy (an, argptr);
   92:         symtab (set_sym, vn, an);
   93:         const_define (vn, an);		
   94: 	
   95:         /* TODO: call into const-init code */
   96:         
   97:         if ((ch = *(codptr + 1)) == EOL || ch == SP) {
   98:             codptr++;
   99:             break;
  100:         }
  101:         else if (*codptr == ',') {
  102:             codptr++;
  103:         }
  104:         else {
  105:             return CMMND;
  106:         }
  107:         
  108:     }
  109: 
  110:     *ra = RA_CONTINUE;
  111:     return OK;
  112: }

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