Annotation of freem/src/cmd_write.c, revision 1.6
1.1 snw 1: /*
1.6 ! snw 2: * $Id: cmd_write.c,v 1.5 2025/03/24 04:05:36 snw Exp $
1.1 snw 3: * Implementation of the WRITE command
4: *
5: *
1.2 snw 6: * Author: Serena Willis <snw@coherent-logic.com>
1.1 snw 7: * Copyright (C) 1998 MUG Deutschland
8: * Copyright (C) 2023 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: *
1.4 snw 26: * $Log: cmd_write.c,v $
1.6 ! snw 27: * Revision 1.5 2025/03/24 04:05:36 snw
! 28: * Replace crlf with frm_crlf to avoid symbol conflict with readline on OS/2
! 29: *
1.5 snw 30: * Revision 1.4 2025/03/22 18:43:54 snw
31: * Make STRLEN 255 chars and add BIGSTR macro for larger buffers
32: *
1.4 snw 33: * Revision 1.3 2025/03/09 19:14:24 snw
34: * First phase of REUSE compliance and header reformat
35: *
1.3 snw 36: *
37: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
38: * SPDX-License-Identifier: AGPL-3.0-or-later
1.1 snw 39: **/
40:
41: #include <string.h>
42: #include <stdlib.h>
43: #include "mpsdef.h"
44: #include "mcommand.h"
45: #if !defined(MSDOS)
46: # include "io_socket.h"
47: #endif
48:
49: MRESULT cmd_write(MACTION *ra, int *i)
50: {
51: char vn[255];
52: char *wr_terminator = (char *) malloc (STRLEN * sizeof (char));
1.4 snw 53: char *sw_buf = (char *) malloc (BIGSTR * sizeof (char));
1.1 snw 54:
55: NULLPTRCHK(wr_terminator,"cmd_write");
56: NULLPTRCHK(sw_buf,"cmd_write");
57:
58: if (io > FIRSTSCK) msck_get_terminator (io, wr_terminator);
59:
60: if (io != HOME && devopen[io] == 'r' && io < FIRSTSCK) {
1.6 ! snw 61: free (wr_terminator);
1.1 snw 62: free (sw_buf);
63: return NOWRITE;
64: }
65:
66: if ((*i = (*codptr)) == SP || *i == EOL) {
1.6 ! snw 67: free (wr_terminator);
! 68: free (sw_buf);
1.1 snw 69: return ARGLIST;
70: }
71:
72: writeproc:
73:
74: switch (*i)
75: {
76:
77: case '!':
78:
79: if (io < FIRSTSCK) {
80:
1.5 snw 81: if (frm_crlf[io]) {
1.1 snw 82: write_m ("\012\201");
83: }
84: else {
85: write_m ("\015\012\201");
86: }
87:
88: }
89: else {
90: /* WRITE ! for sockets */
91: strcat (sw_buf, wr_terminator);
92: }
93:
94: break;
95:
96: case '#':
97:
98: if (io < FIRSTSCK) {
99: write_m ("\015\014\201");
100: }
101: else {
102: return SYNTERR;
103: }
104:
105: break;
106:
107: case '?':
108:
109: codptr++;
110:
111: expr (STRING);
112:
113: if (merr ()) return merr ();
114:
115: if (io < FIRSTSCK) {
116: write_t ((short) intexpr (argptr));
117: }
118: else {
119: return SYNTERR;
120: }
121:
122: break;
123:
124: case '/':
125: codptr++;
126:
127: expr (NAME);
128: if (merr ()) return merr ();
129:
130: if (io < FIRSTSCK) {
131: write_f (varnam);
132: }
133: else {
134: return SYNTERR;
135: }
136:
137: codptr++;
138:
139: break;
140:
141: case '*':
142: codptr++;
143:
144: expr (STRING);
145: if (merr ()) return merr ();
146:
147: argptr[0] = (char) UNSIGN (intexpr (argptr));
148: argptr[1] = EOL;
149:
150: /* special treatment for EOL as long as we don't have 8 bit */
151: if (argptr[0] == EOL) {
152:
153: mcmnd = '*';
154:
155: if (io < FIRSTSCK) {
156: m_output (argptr);
157: }
158: else {
159: /* EOL handling for socket devices */
160: }
161: mcmnd = WRITE;
162:
163: }
164: else {
165:
166: if (io < FIRSTSCK) {
167: write_m (argptr);
168: }
169: else {
170: /* non-EOL char-code handling for sockets */
171: }
172:
173: }
174:
175: break;
176:
177: default:
178: expr (STRING);
179: if (merr ()) return merr ();
180:
181: if (io < FIRSTSCK) {
182: write_m (argptr);
183: }
184: else {
185: /* regular output for socket devices */
186: stcpy (vn, argptr);
187: stcnv_m2c (vn);
188: strcat (sw_buf, vn);
189: }
190: }
191:
192: if ((*i == '!') || (*i == '#')) {
193: if ((*i = *++codptr) == '!' || *i == '#' || *i == '?') goto writeproc;
194: }
195:
196: if (io >= FIRSTSCK) {
197: msck_write (io, sw_buf, strlen (sw_buf));
198: }
199:
200: free (sw_buf);
201: free (wr_terminator);
202:
203: *ra = RA_CONTINUE;
204: return OK;
205: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>