Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!eos!ames!dftsrv!iris613!stailey From: stailey@iris613.gsfc.nasa.gov (Ken Stailey) Newsgroups: comp.os.minix Subject: fast terminal program Summary: shell archive of source code Keywords: terminal rs232 Message-ID: <125@dftsrv.gsfc.nasa.gov> Date: 8 Mar 89 12:40:43 GMT Sender: news@dftsrv.gsfc.nasa.gov Organization: Goddard Space Flight Center Climate and Radiation Branch Lines: 232 This is a terminal program that uses stdio to buffer reads from the rs232 port. The result is a fast terminal session to whatever is plugged into the port. The buffer gets flushed either every second, or every carriage return, whichever comes first. Although it was developed on an ST, it probably will work on a PC version of minix as well. -------------cut here------------cut here----------------cut here----------- echo x - makefile sed "s/^X//" > makefile << '/' Xall: term write_tty read_tty X X Xterm: term.o err.o clean_up.o X $(CC) -o term term.o err.o X Xwrite_tty: write_tty.o err.o X $(CC) -o write_tty write_tty.o err.o X Xread_tty: read_tty.o err.o X $(CC) -o read_tty read_tty.o err.o X X Xwrite_tty.o: write_tty.c const.h X $(CC) -c -O write_tty.c X Xread_tty.o: read_tty.c const.h X $(CC) -c -O read_tty.c X Xterm.o: term.c X $(CC) -c -O term.c X Xerr.o: err.c X $(CC) -c -O err.c X / echo x - err.c sed "s/^X//" > err.c << '/' X#include X Xextern int errno; Xextern char *sys_errlist[]; X Xerr(s) Xchar *s; X{ X fprintf(stderr, "We failed to %s because %s (errno %d).\n", X s, sys_errlist[errno], errno); X X exit(-1); X} / echo x - read_tty.c sed "s/^X//" > read_tty.c << '/' X/* get chars from rs232 and display them */ X X#include X#include X#include X#include X#include "const.h" X Xstatic jmp_buf alrm_ret; X Xcleanup() X{ X fclose(1); X fclose(0); X X exit(0); X} X Xdump() X{ X fflush(stdout); X signal(SIGALRM, dump); X longjmp(alrm_ret, 0); X} X Xchar err_buf[BUFSIZ]; X Xchar line[81]; X Xmain() X{ X signal(SIGINT, cleanup); X signal(SIGQUIT, cleanup); X signal(SIGALRM, dump); X X setbuf(stderr, err_buf); X X fprintf(stderr, "reader started\n"); X fflush(stderr); X X setjmp(alrm_ret); X X while (TRUE) { X alarm(1); X while(( putchar(getchar()) ) != '\r') X ; X fflush(stdout); X } X} / echo x - term.c sed "s/^X//" > term.c << '/' X/* minix doesn't suport open(path, oflag, mode) so no NODELAY */ X X/* my work around is to run term as 2 procs one that reads /dev/tty1 */ X/* and one that writes to it. Now if we block for reading it doesn't */ X/* matter. */ X X#include X#include X#include X#include X#include "const.h" X Xextern void err(); X Xint rd_pid, wr_pid; X Xcleanup() X{ X system("stty -raw echo"); X system("stty -raw echo write_tty.c << '/' X/* get chars from keyboard and put them to rs232 */ X X#include X#include X#include X#include "const.h" X Xextern void err(); X Xint tty_out; Xint kbd_in; X Xcleanup() X{ X close(tty_out); X close(kbd_in); X X exit(0); X} X Xmain() X{ X char ch; X X signal(SIGINT, cleanup); X signal(SIGQUIT, cleanup); X X close(0); X X if ((tty_out = open("/dev/tty1", O_WRONLY)) == ERR) X err("open /dev/tty1 for writing"); X X if ((kbd_in = open("/dev/tty0", O_RDONLY)) == ERR) X err("open keyboard for reading"); X X if (ioctl(tty_out, TCFLSH, 1) == ERR) X err("flush output for /dev/tty1"); X X printf("writer started\n"); X X while (TRUE) { X read(kbd_in, &ch, 1); X X if (ch == 127) /* stop on del without intr working (raw mode) */ X exit(0); X X write(tty_out, &ch, 1); X } X} / echo x - const.h sed "s/^X//" > const.h << '/' X#define TRUE 1 X#define ERR -1 /