Annotation of freem/src/cmd_read.c, revision 1.1
1.1 ! snw 1: /*
! 2: * *
! 3: * * *
! 4: * * *
! 5: * ***************
! 6: * * * * *
! 7: * * MUMPS *
! 8: * * * * *
! 9: * ***************
! 10: * * *
! 11: * * *
! 12: * *
! 13: *
! 14: * cmd_read.c
! 15: * Implementation of the READ command
! 16: *
! 17: *
! 18: * Author: Serena Willis <jpw@coherent-logic.com>
! 19: * Copyright (C) 1998 MUG Deutschland
! 20: * Copyright (C) 2023 Coherent Logic Development LLC
! 21: *
! 22: *
! 23: * This file is part of FreeM.
! 24: *
! 25: * FreeM is free software: you can redistribute it and/or modify
! 26: * it under the terms of the GNU Affero Public License as published by
! 27: * the Free Software Foundation, either version 3 of the License, or
! 28: * (at your option) any later version.
! 29: *
! 30: * FreeM is distributed in the hope that it will be useful,
! 31: * but WITHOUT ANY WARRANTY; without even the implied warranty of
! 32: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 33: * GNU Affero Public License for more details.
! 34: *
! 35: * You should have received a copy of the GNU Affero Public License
! 36: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
! 37: *
! 38: **/
! 39:
! 40: #include <string.h>
! 41: #include <stdlib.h>
! 42: #include "mpsdef.h"
! 43: #include "mcommand.h"
! 44: #if !defined(MSDOS)
! 45: # include "io_socket.h"
! 46: #endif
! 47:
! 48: MRESULT cmd_read(MACTION *ra)
! 49: {
! 50: register int i;
! 51: register char ch;
! 52: char vn[255];
! 53: char an[255];
! 54:
! 55: if (io != HOME && devopen[io] != 'r' && devopen[io] != '+' && io < FIRSTSCK) {
! 56: return NOREAD;
! 57: }
! 58:
! 59: read_command:
! 60:
! 61: switch (*codptr)
! 62: {
! 63: case '!':
! 64: if (crlf[io]) {
! 65: write_m ("\012\201");
! 66: }
! 67: else {
! 68: write_m ("\012\015\201");
! 69: }
! 70:
! 71: if (*++codptr == '!' || *codptr == '#' || *codptr == '?') goto read_command;
! 72:
! 73: goto cont_read;
! 74:
! 75: case '#':
! 76: write_m ("\015\014\201");
! 77:
! 78: if (*++codptr == '!' || *codptr == '#' || *codptr == '?') goto read_command;
! 79:
! 80: goto cont_read;
! 81:
! 82: case '?':
! 83: codptr++;
! 84:
! 85: expr (STRING);
! 86:
! 87: if (merr ()) return merr ();
! 88:
! 89: write_t ((short) intexpr (argptr));
! 90:
! 91: goto cont_read;
! 92:
! 93: case '/':
! 94: codptr++;
! 95:
! 96: expr (NAME);
! 97: if (merr ()) return merr ();
! 98:
! 99: write_f (varnam);
! 100:
! 101: codptr++;
! 102:
! 103: goto cont_read;
! 104:
! 105: case '"':
! 106: i = 0;
! 107:
! 108: for (;;) {
! 109:
! 110: while ((ch = *++codptr) > '"') argptr[i++] = ch;
! 111:
! 112: /* EOL < "any ASCII character" */
! 113: if (ch == '"' && (ch = *++codptr) != '"') {
! 114: argptr[i] = EOL;
! 115: write_m (argptr);
! 116:
! 117: goto cont_read;
! 118: }
! 119:
! 120: if ((argptr[i++] = ch) == EOL) {
! 121: return QUOTER;
! 122: }
! 123: }
! 124: }
! 125:
! 126: i = InFieldLen; /* no length limit */
! 127: InFieldLen = 255; /* Not necessarily tied to STRLEN */
! 128:
! 129: if (*codptr == '*') {
! 130: codptr++;
! 131: i = 0;
! 132: } /* single char read */
! 133:
! 134: if (*codptr == '$') {
! 135: return INVREF;
! 136: }
! 137:
! 138: expr (NAME);
! 139:
! 140: if (merr ()) return merr ();
! 141:
! 142: stcpy (vn, varnam);
! 143: codptr++; /* lvn */
! 144:
! 145: if (i != 0 && *codptr == '#') { /* length limit */
! 146: codptr++;
! 147:
! 148: expr (STRING);
! 149:
! 150: if ((i = intexpr (argptr)) <= 0) return ARGER;
! 151: if (merr ()) return merr ();
! 152: }
! 153:
! 154: frm_timeout = (-1L);
! 155: timeoutms = 0; /* no timeout */
! 156:
! 157: if (*codptr == ':')
! 158: { /* timeout */
! 159: int i, ch;
! 160:
! 161: codptr++;
! 162:
! 163: expr (STRING);
! 164: numlit (argptr);
! 165:
! 166: if (merr ()) return merr ();
! 167:
! 168: frm_timeout = 0;
! 169: timeoutms = 0;
! 170:
! 171: if (argptr[0] != '-') {
! 172:
! 173: i = 0;
! 174:
! 175: for (;;) { /* get integer and fractional part */
! 176:
! 177: if ((ch = argptr[i++]) == EOL) break;
! 178:
! 179: if (ch == '.') {
! 180:
! 181: timeoutms = (argptr[i++] - '0') * 100;
! 182:
! 183: if ((ch = argptr[i++]) != EOL) {
! 184: timeoutms += (ch - '0') * 10;
! 185:
! 186: if ((ch = argptr[i]) != EOL) {
! 187: timeoutms += (ch - '0');
! 188: }
! 189:
! 190: }
! 191: break;
! 192: }
! 193: frm_timeout = frm_timeout * 10 + ch - '0';
! 194: }
! 195: }
! 196: } /* if (*codptr == ':') */
! 197:
! 198: #if 0
! 199: set_io (UNIX);
! 200: printf ("READ: io = %d timeout = %d timeoutms = %d count = %d\n", io, frm_timeout, timeoutms, i);
! 201: set_io (MUMPS);
! 202: #endif
! 203:
! 204: if (io < FIRSTSCK) {
! 205: /* $IO is not a socket device */
! 206: read_m (argptr, frm_timeout, timeoutms, i);
! 207: }
! 208: else {
! 209: /* $IO _is_ a socket device */
! 210: msck_read (io, argptr, frm_timeout, timeoutms, i);
! 211: }
! 212:
! 213: if (vn[0] != '^') {
! 214: stcpy (an, argptr);
! 215: symtab (set_sym, vn, an);
! 216: }
! 217: else {
! 218: stcpy (an, argptr);
! 219: if (vn[1] == '$') {
! 220: ssvn (set_sym, vn, an);
! 221: }
! 222: else {
! 223: global (set_sym, vn, an);
! 224: }
! 225: }
! 226:
! 227: if (merr () != OK) {
! 228: stcpy (varerr, vn);
! 229: return merr ();
! 230: }
! 231:
! 232: cont_read:
! 233:
! 234: *ra = RA_CONTINUE;
! 235: return OK;
! 236: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>