2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * termio.c: Various io functions
30 * Known contributors to this file:
36 #include <sys/types.h>
37 #if defined(aix) || defined(hpux) || defined(sgi)
38 #include <sys/termio.h>
53 extern struct tagstruct *taglist;
54 extern s_char buf[4096];
64 termio(fd, sock, auxfi)
72 s_char *p, *q, *r, *s, *t;
74 int numarg, prespace, exec_com, inarg, quoted, tagging;
75 struct tagstruct *tag;
78 INPUT_RECORD InpBuffer[2];
85 n = read(fd, p, sizeof(buf) - i);
87 /* The keyboard is sometimes generating both keydown and keyup
88 * events for the same key. Thus, we only want to grab keydown
91 err = PeekConsoleInput(hStdIn, InpBuffer, 1, &n);
92 if (InpBuffer[0].EventType != KEY_EVENT) {
93 ReadConsoleInput(hStdIn, InpBuffer, 1, &n);
96 if (!InpBuffer[0].Event.KeyEvent.bKeyDown) {
97 ReadConsoleInput(hStdIn, InpBuffer, 1, &n);
100 c = InpBuffer[0].Event.KeyEvent.uChar.AsciiChar;
108 ReadConsole(hStdIn, &p[0], sizeof(buf) - i, &n, NULL);
111 /* Strip off the CRLF to just LF */
113 if (p[n - 2] == 13 && p[n - 1] == 10) {
119 FlushConsoleInputBuffer(hStdIn);
121 n = read(fd, p, sizeof(buf) - i);
129 perror("read standard input");
142 while (p < buf + n && q < out + 4000) {
145 tag = (struct tagstruct *)malloc(sizeof(struct tagstruct));
146 tag->item = (s_char *)malloc((1 + p - s) * sizeof(s_char));
162 } else if (tagging) {
164 } else if (!quoted && isspace(*p)) {
167 if (numarg == 1 && exec_com && s > exec + 2) {
171 } else if (prespace && *p == '|') {
175 } else if (prespace && *p == '>') {
178 if (*p != '\n' && (*p == '!' || *p == '>'))
186 if (!inarg && *p != '?') {
192 if (*s && *s++ != *p)
199 while (ptr < buf + n)
205 fwrite(out, n, 1, auxfi);
209 nbytes = write(sock, ptr, n);
211 nbytes = send(sock, ptr, n, 0);
215 errno = WSAGetLastError();
217 perror("write server socket");
231 if (write(sock, "ctld\n", 5) < 5) {
233 if (send(sock, "ctld\n", 5, 0) < 5) {
235 fprintf(stderr, "sendeof: EOF send failed\n");
244 #if defined(hpux) || defined(aix) || defined (sgi) || defined(linux)
252 (void)ioctl(fd, TCGETA, &io);
254 (void)ioctl(fd, TCSETA, &io);
265 (void)ioctl(fd, TCGETA, &io);
267 (void)ioctl(fd, TCSETA, &io);
281 (void)ioctl(fd, TIOCGETP, &sgbuf);
282 sgbuf.sg_flags &= ~ECHO;
283 (void)ioctl(fd, TIOCSETP, &sgbuf);
294 (void)ioctl(fd, TIOCGETP, &sgbuf);
295 sgbuf.sg_flags |= ECHO;
296 (void)ioctl(0, TIOCSETP, &sgbuf);