Return to BSD News archive
Received: by minnie.vk1xwt.ampr.org with NNTP id AA6777 ; Fri, 15 Jan 93 10:31:37 EST Xref: sserve comp.unix.bsd:9960 alt.sources:4984 Path: sserve!manuel.anu.edu.au!munnari.oz.au!spool.mu.edu!umn.edu!lynx.unm.edu!fmsrl7!destroyer!gumby!yale!yale.edu!ira.uka.de!Germany.EU.net!hcshh!hm From: hm@hcshh.hcs.de (Hellmuth Michaelis) Newsgroups: comp.unix.bsd,alt.sources Subject: [386BSD] pcvt 2.00 - VT220 console driver (part 03/11) Summary: 386BSD 0.1 VT220 console device driver source code Keywords: 386BSD console driver VT220 Message-ID: <1619@hcshh.hcs.de> Date: 15 Jan 93 13:02:10 GMT Followup-To: comp.unix.bsd Organization: HCS GmbH, Hamburg, Europe Lines: 558 Submitted-by: hm@hcshh.hcs.de (Hellmuth Michaelis) Archive-name: pcvt-2.00/part03 ---- Cut Here and unpack ---- #!/bin/sh # This is part 03 of pcvt-2.00 if touch 2>&1 | fgrep '[-amc]' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= Support/vttest/README ============== if test X"$1" != X"-c" -a -f 'Support/vttest/README'; then echo "File already exists: skipping 'Support/vttest/README'" else echo "x - extracting Support/vttest/README (Text)" sed 's/^X//' << 'SHAR_EOF' > Support/vttest/README && XNOTES FROM THE MOD.SOURCES MODERATOR: XI split the source up into the three separate pieces it now is. XIn doing this, I put lines like "int reading;" in a header file Xthat both C modules include. If your Unix requires one of these Xto be "extern int reading;" then you will have some editing to do. XAlso note that this program uses FIONREAD, which must be implemented Xdifferently in SystemV, etc., and check out the setjmp() call... X /Rich $alz XOh, yeah: I also wrote the Makefile and manpage, such as they are. X------------------------------------------------------------------- X XThis is a program to test the compatibility (or to demonstrate the Xnon-compatibility) of so-called "VT100-compatible" terminals. In Xconformance of the good old hacker traditions, the only documentation Xof this program is the source code itself. To understand it, you also Xneed a copy of the original VT100 manual from DEC. X XComments and bug reports: Since this is a release (via USENET) to the Xwhole world, a lot of people are going to have opinions and fresh Xideas about it. (What -- bugs in MY program? Aww...) I can't deal Xwith everyone sending me a hacked version, but if you have found a Xserious bug, or ported it to VMS, do tell me. I can't promise any new Xversion release, though. From this version on (1.7b) VTTEST will have Xto live its own life without its father holding its hand. X XMy adress is: X XNetwork-mail adress: (mcvax,seismo)!enea!suadb!lindberg X XReal-world-mail address: Per Lindberg X QZ, Stockholm University Computing Center X Box 27322 X S - 102 54 Stockholm X SWEDEN X XThe original version of this program is written for the Sargasso C Xcompiler for the DECsystem-10. Many thanks to all sales persons with Xquote VT100-compatible unquote terminals, who prompted me to write Xthis program, and also to: X X-- Bo Kleve, LIDAC, Linkoping University, Sweden X for the portation to DECSYSTEM-20 with the Sargasso C compiler X X-- Johan Widen, TTDS, Royal Institute of Technology, Stockholm, Sweden X for the portation to various UNIX systems (incl. System III and Xenix) X X-- Russ Herman, AES Data Inc., Missisauga, Ont. Canada X for fixes and code for the VT102 test X XThanx also to JMR "Gremlin" at KTH, and Goran Wallberg at QZ Xfor suggestions, bug fixes, etc. X XThis program does not have support for all the different variations Xof VT100, like VT125, VT131 nor the new VT200 series. Feel free to Xadd that yourself. Happy Hacking! X X /TMP SHAR_EOF $TOUCH -am 0112125693 Support/vttest/README && chmod 0640 Support/vttest/README || echo "restore of Support/vttest/README failed" set `wc -c Support/vttest/README`;Wc_c=$1 if test "$Wc_c" != "2484"; then echo original size 2484, current size $Wc_c fi fi # ============= Support/vttest/esc.c ============== if test X"$1" != X"-c" -a -f 'Support/vttest/esc.c'; then echo "File already exists: skipping 'Support/vttest/esc.c'" else echo "x - extracting Support/vttest/esc.c (Text)" sed 's/^X//' << 'SHAR_EOF' > Support/vttest/esc.c && X#include "header.h" X Xprintln(s) char *s; { X printf("%s\n", s); X} X Xesc(s) char *s; { X printf("%c%s", 27, s); X} X Xesc2(s1, s2) char s1, s2; { X printf("%c%s%s", 27, s1, s2); X} X Xbrcstr(ps, c) char *ps, c; { X printf("%c[%s%c", 27, ps, c); X} X Xbrc(pn,c) int pn; char c; { X printf("%c[%d%c", 27, pn, c); X} X Xbrc2(pn1, pn2 ,c) int pn1, pn2; char c; { X printf("%c[%d;%d%c", 27, pn1, pn2, c); X} X Xcub(pn) int pn; { /* Cursor Backward */ X brc(pn,'D'); X} Xcud(pn) int pn; { /* Cursor Down */ X brc(pn,'B'); X} Xcuf(pn) int pn; { /* Cursor Forward */ X brc(pn,'C'); X} Xcup(pn1, pn2) int pn1, pn2; { /* Cursor Position */ X brc2(pn1, pn2, 'H'); X} Xcuu(pn) int pn; { /* Cursor Up */ X brc(pn,'A'); X} Xda() { /* Device Attributes */ X brc(0,'c'); X} Xdecaln() { /* Screen Alignment Display */ X esc("#8"); X} Xdecdhl(lower) int lower; { /* Double Height Line (also double width) */ X if (lower) esc("#4"); X else esc("#3"); X} Xdecdwl() { /* Double Wide Line */ X esc("#6"); X} Xdeckpam() { /* Keypad Application Mode */ X esc("="); X} Xdeckpnm() { /* Keypad Numeric Mode */ X esc(">"); X} Xdecll(ps) char *ps; { /* Load LEDs */ X brcstr(ps, 'q'); X} Xdecrc() { /* Restore Cursor */ X esc("8"); X} Xdecreqtparm(pn) int pn; { /* Request Terminal Parameters */ X brc(pn,'x'); X} Xdecsc() { /* Save Cursor */ X esc("7"); X} Xdecstbm(pn1, pn2) int pn1, pn2; { /* Set Top and Bottom Margins */ X if (pn1 || pn2) brc2(pn1, pn2, 'r'); X else esc("[r"); X /* Good for >24-line terminals */ X} Xdecswl() { /* Single With Line */ X esc("#5"); X} Xdectst(pn) int pn; { /* Invoke Confidence Test */ X brc2(2, pn, 'y'); X} Xdsr(pn) int pn; { /* Device Status Report */ X brc(pn, 'n'); X} Xed(pn) int pn; { /* Erase in Display */ X brc(pn, 'J'); X} Xel(pn) int pn; { /* Erase in Line */ X brc(pn,'K'); X} Xhts() { /* Horizontal Tabulation Set */ X esc("H"); X} Xhvp(pn1, pn2) int pn1, pn2; { /* Horizontal and Vertical Position */ X brc2(pn1, pn2, 'f'); X} Xind() { /* Index */ X esc("D"); X} Xnel() { /* Next Line */ X esc("E"); X} Xri() { /* Reverse Index */ X esc("M"); X} Xris() { /* Reset to Initial State */ X esc("c"); X} Xrm(ps) char *ps; { /* Reset Mode */ X brcstr(ps, 'l'); X} Xscs(g,c) int g; char c; { /* Select character Set */ X printf("%c%c%c%c%c%c%c", 27, g ? ')' : '(', c, X 27, g ? '(' : ')', 'B', X g ? 14 : 15); X} Xsgr(ps) char *ps; { /* Select Graphic Rendition */ X brcstr(ps, 'm'); X} Xsm(ps) char *ps; { /* Set Mode */ X brcstr(ps, 'h'); X} Xtbc(pn) int pn; { /* Tabulation Clear */ X brc(pn, 'g'); X} X Xvt52cup(l,c) int l,c; { X printf("%cY%c%c", 27, l + 31, c + 31); X} X Xchar inchar() { X X /* X * Wait until a character is typed on the terminal X * then read it, without waiting for CR. X */ X X#ifdef UNIX X int lval, waittime, getpid(); static int val; char ch; X X fflush(stdout); X lval = val; X brkrd = 0; X reading = 1; X read(0,&ch,1); X reading = 0; X if (brkrd) X val = 0177; X else X val = ch; X if ((val==0177) && (val==lval)) X kill(getpid(), (int) SIGTERM); X#endif X#ifdef SARG10 X int val, waittime; X X waittime = 0; X while(!uuo(051,2,&val)) { /* TTCALL 2, (INCHRS) */ X zleep(100); /* Wait 0.1 seconds */ X if ((waittime += ttymode) > 600) /* Time-out, in case */ X return('\177'); /* of hung in ttybin(1) */ X } X#endif X#ifdef SARG20 /* try to fix a time-out function */ X int val, waittime; X X waittime = 0; X while(jsys(SIBE,2,_PRIIN) == 0) { /* Is input empty? */ X zleep(100); X if ((waittime += ttymode) > 600) X return('\177'); X } X ejsys(BIN,_PRIIN); X val = jsac[2]; X#endif X return(val); X} X Xchar *instr() { X X /* X * Get an unfinished string from the terminal: X * wait until a character is typed on the terminal, X * then read it, and all other available characters. X * Return a pointer to that string. X */ X X X int i, val, crflag; long l1; char ch; X static char result[80]; X X i = 0; X result[i++] = inchar(); X/* Wait 0.1 seconds (1 second in vanilla UNIX) */ X#ifdef SARG10 X if (trmop(01031,0) < 5) zleep(500); /* wait longer if low speed */ X else zleep(100); X#else X zleep(100); X#endif X#ifdef UNIX X fflush(stdout); X#ifdef XENIX X while(rdchk(0)) { X read(0,result+i,1); X if (i++ == 78) break; X } X#else X#ifdef SIII X while(read(2,result+i,1) == 1) X if (i++ == 78) break; X#else X while(ioctl(0,FIONREAD,&l1), l1 > 0L) { X while(l1-- > 0L) { X read(0,result+i,1); X if (i++ == 78) goto out1; X } X } Xout1: X#endif X#endif X#endif X#ifdef SARG10 X while(uuo(051,2,&val)) { /* TTCALL 2, (INCHRS) */ X if (!(val == '\012' && crflag)) /* TOPS-10 adds LF to CR */ X result[i++] = val; X crflag = val == '\015'; X if (i == 79) break; X zleep(50); /* Wait 0.05 seconds */ X } X#endif X#ifdef SARG20 X while(jsys(SIBE,2,_PRIIN) != 0) { /* read input until buffer is empty */ X ejsys(BIN,_PRIIN); X result[i++] = jsac[2]; X if (i == 79) break; X zleep(50); /* Wait 0.05 seconds */ X } X#endif X result[i] = '\0'; X return(result); X} X Xttybin(bin) int bin; { X#ifdef SARG10 X #define OPEN 050 X #define IO_MOD 0000017 X #define _IOPIM 2 X #define _IOASC 0 X #define _TOPAG 01021 X #define _TOSET 01000 X X int v; X static int arglst[] = { X _IOPIM, X `TTY`, X 0 X }; X arglst[0] = bin ? _IOPIM : _IOASC; X v = uuo(OPEN, 1, &arglst[0]); X if (!v) { printf("OPEN failed"); exit(); } X trmop(_TOPAG + _TOSET, bin ? 0 : 1); X ttymode = bin; X#endif X#ifdef SARG20 X /* TTYBIN will set the line in BINARY/ASCII mode X * BINARY mode is needed to send control characters X * Bit 28 must be 0 (we don't flip it). X * Bit 29 is used for the mode change. X */ X X #define _TTASC 0000100 X #define _MOXOF 0000043 X X int v; X X ejsys(RFMOD,_CTTRM); X v = ejsys(SFMOD,_CTTRM, bin ? (~_TTASC & jsac[2]) : (_TTASC | jsac[2])); X if (v) { printf("SFMOD failed"); exit(); } X v = ejsys(MTOPR,_CTTRM,_MOXOF,0); X if (v) { printf("MTOPR failed"); exit(); } X#endif X} X X#ifdef SARG20 X/* X * SUPERBIN turns off/on all input character interrupts X * This affects ^C, ^O, ^T X * Beware where and how you use it !!!!!!! X */ X Xsuperbin(bin) int bin; { X int v; X X v = ejsys(STIW,(0//-5), bin ? 0 : -1); X if (v) { printf("STIW superbinary setting failed"); exit(); } X ttymode = bin; X} X X/* X * PAGE affects the ^S/^Q handshake. X * Set bit 34 to turn it on. Clear it for off. X */ X Xpage(bin) int bin; { X int v; X X #define TT_PGM 0000002 X X ejsys(RFMOD,_CTTRM); /* Get the current terminal status */ X v = ejsys(STPAR,_CTTRM, bin ? (TT_PGM | jsac[2]) : (~TT_PGM & jsac[2])); X if (v) { printf("STPAR failed"); exit(); } X} X#endif X Xtrmop(fc,arg) int fc, arg; { X#ifdef SARG10 X int retvalp; X int arglst[3]; X X /* TRMOP is a TOPS-10 monitor call that does things to the terminal. */ X X /* Find out TTY nbr (PA1050 barfs if TRMOP get -1 instead of udx) */ X /* A TRMNO monitor call returns the udx (Universal Device Index) */ X X arglst[0] = fc; /* function code */ X arglst[1] = calli(0115, -1); /* udx, TRMNO. UUO */ X arglst[2] = arg; /* Optional argument */ X X if (calli(0116, 3 // &arglst[0], &retvalp)) /* TRMOP. UUO */ X return (retvalp); X else { X printf("?Error return in TRMOP."); X exit(); X } X#endif X} X Xinputline(s) char *s; { X scanf("%s",s); X#ifdef SARG10 X readnl(); X#endif X#ifdef SARG20 X readnl(); X#endif X} X Xinflush() { X X /* X * Flush input buffer, make sure no pending input character X */ X X int val; X X#ifdef UNIX X#ifdef XENIX X while(rdchk(0)) read(0,&val,1); X#else X#ifdef SIII X while(read(2,&val,1)); X#else X long l1; X ioctl (0, FIONREAD, &l1); X while(l1-- > 0L) read(0,&val,1); X#endif X#endif X#endif X#ifdef SARG10 X while(uuo(051,2,&val)) /* TTCALL 2, (INCHRS) */ X ; X#endif X#ifdef SARG20 X ejsys(CFIBF,_PRIIN); /* Clear input buffer */ X#endif X} X Xzleep(t) int t; { X X/* X * Sleep and do nothing (don't waste CPU) for t milliseconds X */ X X#ifdef SARG10 X calli(072,t); /* (HIBER) t milliseconds */ X#endif X#ifdef SARG20 X ejsys(DISMS,t); /* DISMISS for t milliseconds */ X#endif X#ifdef UNIX X t = t / 1000; X if (t == 0) t = 1; X sleep(t); /* UNIX can only sleep whole seconds */ X#endif X} SHAR_EOF $TOUCH -am 0112125693 Support/vttest/esc.c && chmod 0640 Support/vttest/esc.c || echo "restore of Support/vttest/esc.c failed" set `wc -c Support/vttest/esc.c`;Wc_c=$1 if test "$Wc_c" != "8060"; then echo original size 8060, current size $Wc_c fi fi # ============= Support/vttest/header.h ============== if test X"$1" != X"-c" -a -f 'Support/vttest/header.h'; then echo "File already exists: skipping 'Support/vttest/header.h'" else echo "x - extracting Support/vttest/header.h (Text)" sed 's/^X//' << 'SHAR_EOF' > Support/vttest/header.h && X#define VERSION "1.7b 1985-04-19" X X/* Choose one of these */ X X/* #define XENIX /* XENIX implies UNIX */ X/* #define SIII /* SIII implies UNIX, (NDELAY a la System III) */ X#define UNIX /* UNIX */ X/* #define VMS /* VMS not done yet -- send me your version!!!! */ X/* #define SARG20 /* Sargasso C for TOPS-20 */ X/* #define SARG10 /* Sargasso C for TOPS-10 */ X X/* These #ifdef:s are implementation dependent stuff for the Sargasso C */ X/* Unix C barfs on directives like "#strings", so we keep them */ X/* indented. Then unix c can't find them, but Sargasso C *can*. */ X/* Admittedly kludgey, but it works...) */ X#ifdef SARG10 X #define _UNIXCON /* Make UNIX-flavored I/O on TOPS */ X #strings low /* put strings in lowseg mem so we can modify them. */ X#endif X#ifdef SARG20 X #define _UNIXCON /* Make UNIX-flavored I/O on TOPS */ X #strings low /* put strings in lowseg mem so we can modify them. */ X #include <TOPS20.HDR> X#endif X X#include <stdio.h> X X X#ifdef UNIX X#include <ctype.h> X#include <sgtty.h> X#include <signal.h> X#include <setjmp.h> Xjmp_buf intrenv; Xstruct sgttyb sgttyOrg, sgttyNew; Xchar stdioBuf[BUFSIZ]; Xint brkrd, reading; Xextern onterm(), onbrk(); X#ifdef SIII X#include <fcntl.h> X#endif X#endif Xint ttymode; SHAR_EOF $TOUCH -am 0112125693 Support/vttest/header.h && chmod 0640 Support/vttest/header.h || echo "restore of Support/vttest/header.h failed" set `wc -c Support/vttest/header.h`;Wc_c=$1 if test "$Wc_c" != "1397"; then echo original size 1397, current size $Wc_c fi fi echo "End of part 3, continue with part 4" exit 0 -- hellmuth michaelis HCS Hanseatischer Computerservice GmbH hamburg, europe hm@hcshh.hcs.de tel: +49/40/55903-170 fax: +49/40/5591486