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