4 Written Novemeber 1983 - July 1984 by Per Lindberg,
5 Stockholm University Computer Center (QZ), Sweden.
7 THE MAD PROGRAMMER STRIKES AGAIN!
9 This software is (c) 1984 by QZ
10 Non-commercial use and copying allowed.
12 If you are developing a commercial product, and use this program to do
13 it, and that product is successful, please send a sum of money of your
14 choice to the address below.
24 printf("%c%s", 27, s
);
27 esc2(s1
, s2
) char s1
, s2
; {
28 printf("%c%s%s", 27, s1
, s2
);
31 brcstr(ps
, c
) char *ps
, c
; {
32 printf("%c[%s%c", 27, ps
, c
);
35 brc(pn
,c
) int pn
; char c
; {
36 printf("%c[%d%c", 27, pn
, c
);
39 brc2(pn1
, pn2
,c
) int pn1
, pn2
; char c
; {
40 printf("%c[%d;%d%c", 27, pn1
, pn2
, c
);
43 cub(pn
) int pn
; { /* Cursor Backward */
46 cud(pn
) int pn
; { /* Cursor Down */
49 cuf(pn
) int pn
; { /* Cursor Forward */
52 cup(pn1
, pn2
) int pn1
, pn2
; { /* Cursor Position */
55 cuu(pn
) int pn
; { /* Cursor Up */
58 da() { /* Device Attributes */
61 decaln() { /* Screen Alignment Display */
64 decdhl(lower
) int lower
; { /* Double Height Line (also double width) */
68 decdwl() { /* Double Wide Line */
71 deckpam() { /* Keypad Application Mode */
74 deckpnm() { /* Keypad Numeric Mode */
77 decll(ps
) char *ps
; { /* Load LEDs */
80 decrc() { /* Restore Cursor */
83 decreqtparm(pn
) int pn
; { /* Request Terminal Parameters */
86 decsc() { /* Save Cursor */
89 decstbm(pn1
, pn2
) int pn1
, pn2
; { /* Set Top and Bottom Margins */
90 if (pn1
|| pn2
) brc2(pn1
, pn2
, 'r');
92 /* Good for >24-line terminals */
94 decswl() { /* Single With Line */
97 dectst(pn
) int pn
; { /* Invoke Confidence Test */
100 dsr(pn
) int pn
; { /* Device Status Report */
103 ed(pn
) int pn
; { /* Erase in Display */
106 el(pn
) int pn
; { /* Erase in Line */
109 hts() { /* Horizontal Tabulation Set */
112 hvp(pn1
, pn2
) int pn1
, pn2
; { /* Horizontal and Vertical Position */
118 nel() { /* Next Line */
121 ri() { /* Reverse Index */
124 ris() { /* Reset to Initial State */
127 rm(ps
) char *ps
; { /* Reset Mode */
130 scs(g
,c
) int g
; char c
; { /* Select character Set */
131 printf("%c%c%c%c%c%c%c", 27, g
? ')' : '(', c
,
132 27, g
? '(' : ')', 'B',
135 sgr(ps
) char *ps
; { /* Select Graphic Rendition */
138 sm(ps
) char *ps
; { /* Set Mode */
141 tbc(pn
) int pn
; { /* Tabulation Clear */
145 vt52cup(l
,c
) int l
,c
; {
146 printf("%cY%c%c", 27, l
+ 31, c
+ 31);
152 * Wait until a character is typed on the terminal
153 * then read it, without waiting for CR.
157 int lval
, waittime
, getpid(); static int val
; char ch
;
169 if ((val
==0177) && (val
==lval
))
170 kill(getpid(), (int) SIGTERM
);
176 while(!uuo(051,2,&val
)) { /* TTCALL 2, (INCHRS) */
177 zleep(100); /* Wait 0.1 seconds */
178 if ((waittime
+= ttymode
) > 600) /* Time-out, in case */
179 return('\177'); /* of hung in ttybin(1) */
182 #ifdef SARG20 /* try to fix a time-out function */
186 while(jsys(SIBE
,2,_PRIIN
) == 0) { /* Is input empty? */
188 if ((waittime
+= ttymode
) > 600)
200 * Get an unfinished string from the terminal:
201 * wait until a character is typed on the terminal,
202 * then read it, and all other available characters.
203 * Return a pointer to that string.
207 int i
, val
, crflag
; long l1
; char ch
;
208 static char result
[80];
211 result
[i
++] = inchar();
212 /* Wait 0.1 seconds (1 second in vanilla UNIX) */
214 if (trmop(01031,0) < 5) zleep(500); /* wait longer if low speed */
224 if (i
++ == 78) break;
228 while(read(2,result
+i
,1) == 1)
229 if (i
++ == 78) break;
231 while(ioctl(0,FIONREAD
,&l1
), l1
> 0L) {
234 if (i
++ == 78) goto out1
;
242 while(uuo(051,2,&val
)) { /* TTCALL 2, (INCHRS) */
243 if (!(val
== '\012' && crflag
)) /* TOPS-10 adds LF to CR */
245 crflag
= val
== '\015';
247 zleep(50); /* Wait 0.05 seconds */
251 while(jsys(SIBE
,2,_PRIIN
) != 0) { /* read input until buffer is empty */
253 result
[i
++] = jsac
[2];
255 zleep(50); /* Wait 0.05 seconds */
262 ttybin(bin
) int bin
; {
265 #define IO_MOD 0000017
272 static int arglst
[] = {
277 arglst
[0] = bin
? _IOPIM
: _IOASC
;
278 v
= uuo(OPEN
, 1, &arglst
[0]);
279 if (!v
) { printf("OPEN failed"); exit(); }
280 trmop(_TOPAG
+ _TOSET
, bin
? 0 : 1);
284 /* TTYBIN will set the line in BINARY/ASCII mode
285 * BINARY mode is needed to send control characters
286 * Bit 28 must be 0 (we don't flip it).
287 * Bit 29 is used for the mode change.
290 #define _TTASC 0000100
291 #define _MOXOF 0000043
296 v
= ejsys(SFMOD
,_CTTRM
, bin
? (~_TTASC
& jsac
[2]) : (_TTASC
| jsac
[2]));
297 if (v
) { printf("SFMOD failed"); exit(); }
298 v
= ejsys(MTOPR
,_CTTRM
,_MOXOF
,0);
299 if (v
) { printf("MTOPR failed"); exit(); }
305 * SUPERBIN turns off/on all input character interrupts
306 * This affects ^C, ^O, ^T
307 * Beware where and how you use it !!!!!!!
310 superbin(bin
) int bin
; {
313 v
= ejsys(STIW
,(0//-5), bin ? 0 : -1);
314 if (v
) { printf("STIW superbinary setting failed"); exit(); }
319 * PAGE affects the ^S/^Q handshake.
320 * Set bit 34 to turn it on. Clear it for off.
326 #define TT_PGM 0000002
328 ejsys(RFMOD
,_CTTRM
); /* Get the current terminal status */
329 v
= ejsys(STPAR
,_CTTRM
, bin
? (TT_PGM
| jsac
[2]) : (~TT_PGM
& jsac
[2]));
330 if (v
) { printf("STPAR failed"); exit(); }
334 trmop(fc
,arg
) int fc
, arg
; {
339 /* TRMOP is a TOPS-10 monitor call that does things to the terminal. */
341 /* Find out TTY nbr (PA1050 barfs if TRMOP get -1 instead of udx) */
342 /* A TRMNO monitor call returns the udx (Universal Device Index) */
344 arglst
[0] = fc
; /* function code */
345 arglst
[1] = calli(0115, -1); /* udx, TRMNO. UUO */
346 arglst
[2] = arg
; /* Optional argument */
348 if (calli(0116, 3 // &arglst[0], &retvalp)) /* TRMOP. UUO */
351 printf("?Error return in TRMOP.");
357 inputline(s
) char *s
; {
370 * Flush input buffer, make sure no pending input character
377 while(rdchk(0)) read(0,&val
,1);
380 while(read(2,&val
,1));
383 ioctl (0, FIONREAD
, &l1
);
384 while(l1
-- > 0L) read(0,&val
,1);
389 while(uuo(051,2,&val
)) /* TTCALL 2, (INCHRS) */
393 ejsys(CFIBF
,_PRIIN
); /* Clear input buffer */
400 * Sleep and do nothing (don't waste CPU) for t milliseconds
404 calli(072,t
); /* (HIBER) t milliseconds */
407 ejsys(DISMS
,t
); /* DISMISS for t milliseconds */
412 sleep(t
); /* UNIX can only sleep whole seconds */