Annotation of freem/src/mcommand.c, revision 1.4
1.1 snw 1: /*
1.4 ! snw 2: * $Id: mcommand.c,v 1.3 2025/03/09 19:50:47 snw Exp $
1.1 snw 3: * M command utility functions
4: *
5: *
1.2 snw 6: * Author: Serena Willis <snw@coherent-logic.com>
1.1 snw 7: * Copyright (C) 1998 MUG Deutschland
1.3 snw 8: * Copyright (C) 2023, 2025 Coherent Logic Development LLC
1.1 snw 9: *
10: *
11: * This file is part of FreeM.
12: *
13: * FreeM is free software: you can redistribute it and/or modify
14: * it under the terms of the GNU Affero Public License as published by
15: * the Free Software Foundation, either version 3 of the License, or
16: * (at your option) any later version.
17: *
18: * FreeM is distributed in the hope that it will be useful,
19: * but WITHOUT ANY WARRANTY; without even the implied warranty of
20: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: * GNU Affero Public License for more details.
22: *
23: * You should have received a copy of the GNU Affero Public License
24: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
25: *
1.4 ! snw 26: * $Log: mcommand.c,v $
! 27: * Revision 1.3 2025/03/09 19:50:47 snw
! 28: * Second phase of REUSE compliance and header reformat
! 29: *
1.3 snw 30: *
31: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
32: * SPDX-License-Identifier: AGPL-3.0-or-later
1.1 snw 33: **/
34:
35: #include <string.h>
1.4 ! snw 36: #include <ctype.h>
1.1 snw 37: #include <stdlib.h>
38: #include "mpsdef.h"
39: #include "mcommand.h"
40:
41: MRESULT mcmd_tokenize(MACTION *ra, char *tmp3, char *deferrable_codptr, char *deferrable_code, int *j)
42: {
43: tmp3[0] = SP;
44: tmp3[1] = mcmnd;
45: tmp3[++(*j)] = SP;
46: tmp3[++(*j)] = EOL;
47:
48: if (mcmnd != 'z') {
49:
50: if (find (" ab ablock assert assign asta astart asto astop aunb aunblock \
1.4 ! snw 51: break close do else esta estart esto estop etr etrigger for goto hang halt \
! 52: if job kill ks ksubscripts kv kvalue lock merge new open quit read rl rload \
! 53: rs rsave set tc tcommit th then tro trollback ts tstart use \
! 54: view wa watch write xecute ", tmp3) == FALSE) {
1.1 snw 55: return CMMND;
56: }
57:
58: switch (mcmnd)
59: {
60:
61: case 'a':
62:
63: if (tmp3[2] == 'b') {
64: mcmnd = ABLOCK;
65: }
66: else if (tmp3[2] == 'u') {
67: mcmnd = AUNBLOCK;
68: }
69: else if (tmp3[2] == 's') {
70:
71: if (tmp3[4] == 'a') {
72: mcmnd = ASTART;
73: }
74: else if (tmp3[4] == 'o') {
75: mcmnd = ASTOP;
76: }
77:
78: }
79:
80: break;
81:
1.4 ! snw 82: case 'c':
! 83: mcmnd = CLOSE;
! 84: break;
1.1 snw 85:
86: case 'e':
87: if (tmp3[2] == 't') mcmnd = ETRIGGER;
88: else if (tmp3[4] == 'a') mcmnd = ESTART;
89: else if (tmp3[4] == 'o') mcmnd = ESTOP;
90: break;
91:
92: case 'h':
93: mcmnd = tmp3[4] == 't' ? HALT : HANG;
94: break;
95:
96: case 'k':
97: if (tmp3[2] == 'v') mcmnd = KVALUE;
98: else if (tmp3[2] == 's') mcmnd = KSUBSC;
99: break;
100:
101: case 'm':
102:
103: if (tmp3[2] == 'e') {
104:
105: /* save off pre-parse codptr and code for commands implemented in M routines */
106: deferrable_codptr = codptr;
107: stcpy (deferrable_code, "MERGE\201");
108: stcat (deferrable_code, deferrable_codptr);
109:
110: break;
111:
112: }
113:
114: case 'r':
115: if (tmp3[2] == 'l') mcmnd = RLOAD;
116: else if (tmp3[2] == 's') mcmnd = RSAVE;
117: break;
118:
119: case 't':
120: if (tmp3[2] == 'c') mcmnd = TCOMMIT;
121: else if (tmp3[2] == 'h') {
122: if (tmp3[3] == 'e') {
123: mcmnd = THEN;
124: }
125: }
126: else if (tmp3[3] == 'o') mcmnd = TROLLBACK;
127: else if (tmp3[2] == 's') mcmnd = TSTART;
128: break;
129:
130: case 'w':
1.4 ! snw 131: mcmnd = WRITE;
1.1 snw 132: break;
133:
1.4 ! snw 134: case 'u':
! 135: mcmnd = USE;
! 136: break;
1.1 snw 137:
138: } /* end of switch(mcmnd) */
139:
140: }
141: else {
142:
143: mcmnd = tmp3[2] - 32; /* z_command select */
1.4 ! snw 144:
! 145: switch (mcmnd) {
! 146:
! 147: case 'A':
! 148: mcmnd = ASSERT_TKN;
! 149: break;
! 150:
! 151: case 'C':
! 152: mcmnd = CONST;
! 153: break;
! 154:
! 155: case 'M':
! 156: mcmnd = MAP;
! 157: break;
! 158:
! 159: case 'T':
! 160: mcmnd = THROW;
! 161: break;
! 162:
! 163: case 'U':
! 164: mcmnd = UNMAP;
! 165: break;
! 166:
! 167: case 'W':
! 168: switch (toupper (tmp3[3])) {
! 169: case 'R':
! 170: mcmnd = ZWRITE;
! 171: break;
! 172: case 'A':
! 173: mcmnd = WATCH;
! 174: break;
! 175: case 'I':
! 176: mcmnd = OO_WITH;
! 177: break;
! 178: }
! 179: break;
! 180:
! 181: }
1.1 snw 182:
183: if (find (zcommds, tmp3) == FALSE) mcmnd = PRIVATE;
184: }
185:
1.4 ! snw 186: mcmnd_done:
1.1 snw 187: *ra = RA_CONTINUE;
188: return OK;
189: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>