Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!dftsrv!iris613!stailey From: stailey@iris613.gsfc.nasa.gov (Ken Stailey) Newsgroups: comp.os.minix Subject: Re: Terminal Program Summary: term Message-ID: <181@dftsrv.gsfc.nasa.gov> Date: 23 Apr 89 16:40:02 GMT References: <4103@crash.cts.com> Sender: news@dftsrv.gsfc.nasa.gov Reply-To: stailey@iris613.UUCP (Ken Stailey) Organization: Goddard Space Flight Center Climate and Radiation Branch Lines: 251 It was mine. I through it together in an enormous hurry but the code it somewhat structured. I still use it because it's pretty fast with 1K buffers but there must be a bug in my serial driver because the reading child proc takes a dive after about 15 min of continuous operation. Re-running it does not help. Mostly it was a responce to the binary only postings of "cu". Here it is: This is a much improved version of the fast terminal program posted on Tue Mar 7. Gone is quite a bit of junk that would never work right because of handshaking problems using stdio on /dev/tty1. In its place is a cu-like command set and quite a bit more robustness. Ken --------------- cut here ------------------------ cut here ----------------- echo x - makefile sed "s/^X//" > makefile << '/' Xall: term write_tty read_tty X X Xterm: term.o err.o X $(CC) -o term term.o err.o X Xwrite_tty: write_tty.o do_shell.o X $(CC) -o write_tty write_tty.o do_shell.o X Xread_tty: read_tty.o X $(CC) -o read_tty read_tty.o 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 Xdo_shell.o: do_shell.c X $(CC) -c -O do_shell.c / echo x - const.h sed "s/^X//" > const.h << '/' X#define TRUE 1 X#define FALSE 0 X X#define ERR -1 / echo x - do_shell.c sed "s/^X//" > do_shell.c << '/' Xdo_shell() X{ X} / echo x - err.c sed "s/^X//" > err.c << '/' X#include X Xextern int errno; Xextern char *sys_errlist[]; Xextern char *i_am; X Xerr(s) Xchar *s; X{ X fprintf(stderr, "%s failed to %s because %s (errno %d).\n", X i_am, 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 "const.h" X Xcleanup() X{ X fprintf(stderr, "reader stopped\n"); X fflush(stderr); X X exit(0); X} X X Xchar err_buf[BUFSIZ]; X Xmain() X{ X char chrs[1024]; X X signal(SIGINT, cleanup); X signal(SIGQUIT, cleanup); X signal(SIGTERM, cleanup); X X setbuf(stderr, err_buf); X X fprintf(stderr, "reader started\n"); X fflush(stderr); X X while (TRUE) { X write(1, chrs, read(0, chrs, 10)); 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 Xchar *i_am = "term"; /* name used in err() */ Xextern void err(); /* error printing routine */ 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 Xchar err_buf[BUFSIZ]; X Xcleanup() X{ X fprintf(stderr, "writer stopped\n"); X fflush(stderr); X X exit(0); X} X Xmain() X{ X char ch; X char was_newline = TRUE; X X signal(SIGINT, SIG_IGN); X signal(SIGQUIT, SIG_IGN); X signal(SIGTERM, cleanup); X X setbuf(stderr, err_buf); X X fprintf(stderr, "writer started\n"); X fflush(stderr); X X while (TRUE) { X read(0, &ch, 1); X X if (was_newline) { X if (ch == '~') { X read(0, &ch, 1); X X switch (ch) { X X case '.': X cleanup(); /* go home! */ X X case '!': X do_shell(); X break; X X case '~': X break; X X default: X fprintf(stderr, "invalid command--use\ X \"~~\" to start a line with \"~\"\n"); X } X } X } X X if (ch == '\r') X was_newline = TRUE; X else X was_newline = FALSE; X X write(1, &ch, 1); X } X} / *========================================================================* { what opinions?!? what disclaimer !?!?! ken@all.over.the.place } *========================================================================*