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:
35 #include <sys/types.h>
36 #if defined(aix) || defined(hpux) || defined(sgi)
37 #include <sys/termio.h>
52 extern struct tagstruct *taglist;
53 extern s_char buf[4096];
63 termio(fd, sock, auxfi)
71 s_char *p, *q, *r, *s, *t;
73 int numarg, prespace, exec_com, inarg, quoted, tagging;
74 struct tagstruct *tag;
77 INPUT_RECORD InpBuffer[2];
84 n = read(fd, p, sizeof(buf) - i);
86 /* The keyboard is sometimes generating both keydown and keyup
87 * events for the same key. Thus, we only want to grab keydown
90 err = PeekConsoleInput(hStdIn, InpBuffer, 1, &n);
91 if (InpBuffer[0].EventType != KEY_EVENT) {
92 ReadConsoleInput(hStdIn, InpBuffer, 1, &n);
95 if (!InpBuffer[0].Event.KeyEvent.bKeyDown) {
96 ReadConsoleInput(hStdIn, InpBuffer, 1, &n);
99 c = InpBuffer[0].Event.KeyEvent.uChar.AsciiChar;
107 ReadConsole(hStdIn, &p[0], sizeof(buf) - i, &n, NULL);
110 /* Strip off the CRLF to just LF */
112 if (p[n - 2] == 13 && p[n - 1] == 10) {
118 FlushConsoleInputBuffer(hStdIn);
120 n = read(fd, p, sizeof(buf) - i);
128 perror("read standard input");
141 while (p < buf + n && q < out + 4000) {
144 tag = (struct tagstruct *)malloc(sizeof(struct tagstruct));
145 tag->item = (s_char *)malloc((1 + p - s) * sizeof(s_char));
161 } else if (tagging) {
163 } else if (!quoted && isspace(*p)) {
166 if (numarg == 1 && exec_com && s > exec + 2) {
170 } else if (prespace && *p == '|') {
174 } else if (prespace && *p == '>') {
177 if (*p != '\n' && (*p == '!' || *p == '>'))
185 if (!inarg && *p != '?') {
191 if (*s && *s++ != *p)
198 while (ptr < buf + n)
204 fwrite(out, n, 1, auxfi);
208 nbytes = write(sock, ptr, n);
210 nbytes = send(sock, ptr, n, 0);
214 errno = WSAGetLastError();
216 perror("write server socket");
230 if (write(sock, "ctld\n", 5) < 5) {
232 if (send(sock, "ctld\n", 5, 0) < 5) {
234 fprintf(stderr, "sendeof: EOF send failed\n");
243 #if defined(hpux) || defined(aix) || defined (sgi) || defined(linux)
251 (void)ioctl(fd, TCGETA, &io);
253 (void)ioctl(fd, TCSETA, &io);
264 (void)ioctl(fd, TCGETA, &io);
266 (void)ioctl(fd, TCSETA, &io);
280 (void)ioctl(fd, TIOCGETP, &sgbuf);
281 sgbuf.sg_flags &= ~ECHO;
282 (void)ioctl(fd, TIOCSETP, &sgbuf);
293 (void)ioctl(fd, TIOCGETP, &sgbuf);
294 sgbuf.sg_flags |= ECHO;
295 (void)ioctl(0, TIOCSETP, &sgbuf);