1: /*
2: * $Id: cmd_tstart.c,v 1.4 2025/04/10 01:24:38 snw Exp $
3: * Implementation of the TSTART command
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: cmd_tstart.c,v $
27: * Revision 1.4 2025/04/10 01:24:38 snw
28: * Remove C++ style comments
29: *
30: * Revision 1.3 2025/03/09 19:14:24 snw
31: * First 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 <stdlib.h>
40: #include <ctype.h>
41: #include "mpsdef.h"
42: #include "mcommand.h"
43: #include "consttbl.h"
44: #include "transact.h"
45:
46: MRESULT cmd_tstart(MACTION *ra)
47: {
48: register char ch;
49: short serial = FALSE;
50: short restartable = FALSE;
51: char tran_ident[50];
52: char tre_offset[50];
53: short parct = 0;
54:
55: if ((rtn_dialect () != D_M95) &&
56: (rtn_dialect () != D_MDS) &&
57: (rtn_dialect () != D_M5) &&
58: (rtn_dialect () != D_FREEM)) {
59: return NOSTAND;
60: }
61:
62: uuid_v4 (tran_ident);
63:
64: if (((ch = *codptr) == SP) || ch == EOL) {
65:
66: serial = FALSE;
67: restartable = FALSE;
68:
69: goto exec_tstart;
70:
71: }
72:
73: restartable = TRUE;
74: getraddress (tre_offset, nstx);
75:
76: if (ch == ':') {
77: restartable = FALSE;
78: goto tstart_param;
79: }
80: else if (ch == '(') {
81: ch = *codptr++;
82:
83: if (ch == ')') goto tstart_param;
84: }
85: else if (ch == '*') {
86: printf ("all varnames\r\n");
87: }
88: else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
89: printf ("one varname\r\n");
90: }
91:
92:
93: tstart_param:
94:
95: codptr++;
96: ch = *codptr;
97:
98: switch (ch) {
99:
100: case ':':
101: goto tstart_param;
102:
103: case 's':
104: case 'S':
105:
106: expr (NAME);
107: if (merr ()) return merr ();
108:
109: stcnv_m2c (varnam);
110: {
111: int stct;
112: for (stct = 0; stct < strlen (varnam); stct++) {
113: varnam[stct] = toupper (varnam[stct]);
114: }
115: }
116:
117: if ((strcmp (varnam, "S") == 0) ||
118: (strcmp (varnam, "SERIAL") == 0)) {
119: serial = TRUE;
120: }
121: else {
122: return SYNTERR;
123: }
124:
125: goto tstart_param;
126:
127: case 't':
128: case 'T':
129:
130: expr (NAME);
131: if (merr ()) return merr ();
132:
133: stcnv_m2c (varnam);
134: {
135: int stct;
136: for (stct = 0; stct < strlen (varnam); stct++) {
137: varnam[stct] = toupper (varnam[stct]);
138: }
139: }
140:
141: if ((strcmp (varnam, "T") == 0) ||
142: (strcmp (varnam, "TRANSACTIONID") == 0)) {
143:
144: codptr++;
145:
146: if ((ch = *codptr) != '=') {
147: return ASSIGNER;
148: }
149:
150: codptr++;
151:
152: expr (STRING);
153: if (merr () == BRAER) merr_clear ();
154: if (merr () > OK) {
155: return merr ();
156: }
157:
158: stcnv_m2c (argptr);
159: strcpy (tran_ident, argptr);
160:
161: codptr--;
162:
163: goto tstart_param;
164:
165: }
166: break;
167:
168: case '(':
169:
170: parct++;
171:
172: if (parct > 1) {
173: return SYNTERR;
174: }
175:
176: goto tstart_param;
177:
178: break;
179:
180: case ')':
181:
182: parct--;
183:
184: if (parct < 0) {
185: return SYNTERR;
186: }
187:
188: goto exec_tstart;
189:
190: case SP:
191: case EOL:
192:
193: if (parct > 0) {
194: return BRAER;
195: }
196:
197: goto exec_tstart;
198:
199: default:
200:
201: return SYNTERR;
202:
203: }
204:
205:
206: exec_tstart:
207: tp_tstart (tran_ident, serial, restartable, NULL);
208:
209: while ((ch = *(codptr++)) != SP && ch != EOL) ; /* skip to the end of the command */
210: *ra = RA_NEXTCMND;
211: return OK;
212: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>