/*
* $Id: mcommand.c,v 1.3 2025/03/09 19:50:47 snw Exp $
* M command utility functions
*
*
* 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: mcommand.c,v $
* Revision 1.3 2025/03/09 19:50:47 snw
* Second 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"
MRESULT mcmd_tokenize(MACTION *ra, char *tmp3, char *deferrable_codptr, char *deferrable_code, int *j)
{
tmp3[0] = SP;
tmp3[1] = mcmnd;
tmp3[++(*j)] = SP;
tmp3[++(*j)] = EOL;
if (mcmnd != 'z') {
if (find (" ab ablock assert assign asta astart asto astop aunb aunblock \
break co const close do else esta estart esto estop etr etrigger for goto hang halt \
if job kill ks ksubscripts kv kvalue lock ma map merge new open quit read rl rload \
rs rsave set tc tcommit th then thr throw tro trollback ts tstart use \
un unmap usi using view wa watch write wi with xecute ", tmp3) == FALSE) {
return CMMND;
}
switch (mcmnd)
{
case 'a':
if (tmp3[2] == 'b') {
mcmnd = ABLOCK;
}
else if (tmp3[2] == 'u') {
mcmnd = AUNBLOCK;
}
else if (tmp3[2] == 's') {
if (tmp3[4] == 'a') {
mcmnd = ASTART;
}
else if (tmp3[4] == 'o') {
mcmnd = ASTOP;
}
else if (tmp3[4] == 'e') {
mcmnd = ASSERT_TKN;
}
}
break;
case 'c':
if (tmp3[2] == 'l') {
mcmnd = CLOSE;
}
else {
mcmnd = CONST;
}
case 'e':
if (tmp3[2] == 't') mcmnd = ETRIGGER;
else if (tmp3[4] == 'a') mcmnd = ESTART;
else if (tmp3[4] == 'o') mcmnd = ESTOP;
break;
case 'h':
mcmnd = tmp3[4] == 't' ? HALT : HANG;
break;
case 'k':
if (tmp3[2] == 'v') mcmnd = KVALUE;
else if (tmp3[2] == 's') mcmnd = KSUBSC;
break;
case 'm':
if (tmp3[2] == 'e') {
/* save off pre-parse codptr and code for commands implemented in M routines */
deferrable_codptr = codptr;
stcpy (deferrable_code, "MERGE\201");
stcat (deferrable_code, deferrable_codptr);
break;
}
else if (tmp3[2] == 'a') {
mcmnd = MAP;
break;
}
case 'r':
if (tmp3[2] == 'l') mcmnd = RLOAD;
else if (tmp3[2] == 's') mcmnd = RSAVE;
break;
case 't':
if (tmp3[2] == 'c') mcmnd = TCOMMIT;
else if (tmp3[2] == 'h') {
if (tmp3[3] == 'e') {
mcmnd = THEN;
}
else if (tmp3[3] == 'r') {
mcmnd = THROW;
}
}
else if (tmp3[3] == 'o') mcmnd = TROLLBACK;
else if (tmp3[2] == 's') mcmnd = TSTART;
break;
case 'w':
switch (tmp3[2]) {
case 'a':
mcmnd = WATCH;
break;
case 'i':
mcmnd = OO_WITH;
break;
case 'r':
mcmnd = WRITE;
break;
}
break;
case 'u':
if (tmp3[2] == 'n') {
mcmnd = UNMAP;
break;
}
switch (tmp3[3]) {
case 'e':
mcmnd = USE;
break;
case 'i':
mcmnd = OO_USING;
break;
}
} /* end of switch(mcmnd) */
}
else {
mcmnd = tmp3[2] - 32; /* z_command select */
if (find (zcommds, tmp3) == FALSE) mcmnd = PRIVATE;
}
*ra = RA_CONTINUE;
return OK;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>