11 esc2(s1, s2) char s1, s2; {
12 printf("%c%s%s", 27, s1, s2);
15 brcstr(ps, c) char *ps, c; {
16 printf("%c[%s%c", 27, ps, c);
19 brc(pn,c) int pn; char c; {
20 printf("%c[%d%c", 27, pn, c);
23 brc2(pn1, pn2 ,c) int pn1, pn2; char c; {
24 printf("%c[%d;%d%c", 27, pn1, pn2, c);
27 cub(pn) int pn; { /* Cursor Backward */
30 cud(pn) int pn; { /* Cursor Down */
33 cuf(pn) int pn; { /* Cursor Forward */
36 cup(pn1, pn2) int pn1, pn2; { /* Cursor Position */
39 cuu(pn) int pn; { /* Cursor Up */
42 da() { /* Device Attributes */
45 decaln() { /* Screen Alignment Display */
48 decdhl(lower) int lower; { /* Double Height Line (also double width) */
52 decdwl() { /* Double Wide Line */
55 deckpam() { /* Keypad Application Mode */
58 deckpnm() { /* Keypad Numeric Mode */
61 decll(ps) char *ps; { /* Load LEDs */
64 decrc() { /* Restore Cursor */
67 decreqtparm(pn) int pn; { /* Request Terminal Parameters */
70 decsc() { /* Save Cursor */
73 decstbm(pn1, pn2) int pn1, pn2; { /* Set Top and Bottom Margins */
74 if (pn1 || pn2) brc2(pn1, pn2, 'r');
76 /* Good for >24-line terminals */
78 decswl() { /* Single With Line */
81 dectst(pn) int pn; { /* Invoke Confidence Test */
84 dsr(pn) int pn; { /* Device Status Report */
87 ed(pn) int pn; { /* Erase in Display */
90 el(pn) int pn; { /* Erase in Line */
93 hts() { /* Horizontal Tabulation Set */
96 hvp(pn1, pn2) int pn1, pn2; { /* Horizontal and Vertical Position */
102 nel() { /* Next Line */
105 ri() { /* Reverse Index */
108 ris() { /* Reset to Initial State */
111 rm(ps) char *ps; { /* Reset Mode */
114 scs(g,c) int g; char c; { /* Select character Set */
115 printf("%c%c%c%c%c%c%c", 27, g ? ')' : '(', c,
116 27, g ? '(' : ')', 'B',
119 sgr(ps) char *ps; { /* Select Graphic Rendition */
122 sm(ps) char *ps; { /* Set Mode */
125 tbc(pn) int pn; { /* Tabulation Clear */
129 vt52cup(l,c) int l,c; {
130 printf("%cY%c%c", 27, l + 31, c + 31);
136 * Wait until a character is typed on the terminal
137 * then read it, without waiting for CR.
141 int lval, waittime, getpid(); static int val; char ch;
153 if ((val==0177) && (val==lval))
154 kill(getpid(), (int) SIGTERM);
160 while(!uuo(051,2,&val)) { /* TTCALL 2, (INCHRS) */
161 zleep(100); /* Wait 0.1 seconds */
162 if ((waittime += ttymode) > 600) /* Time-out, in case */
163 return('\177'); /* of hung in ttybin(1) */
166 #ifdef SARG20 /* try to fix a time-out function */
170 while(jsys(SIBE,2,_PRIIN) == 0) { /* Is input empty? */
172 if ((waittime += ttymode) > 600)
184 * Get an unfinished string from the terminal:
185 * wait until a character is typed on the terminal,
186 * then read it, and all other available characters.
187 * Return a pointer to that string.
191 int i, val, crflag; long l1; char ch;
192 static char result[80];
195 result[i++] = inchar();
196 /* Wait 0.1 seconds (1 second in vanilla UNIX) */
198 if (trmop(01031,0) < 5) zleep(500); /* wait longer if low speed */
208 if (i++ == 78) break;
212 while(read(2,result+i,1) == 1)
213 if (i++ == 78) break;
215 while(ioctl(0,FIONREAD,&l1), l1 > 0L) {
218 if (i++ == 78) goto out1;
226 while(uuo(051,2,&val)) { /* TTCALL 2, (INCHRS) */
227 if (!(val == '\012' && crflag)) /* TOPS-10 adds LF to CR */
229 crflag = val == '\015';
231 zleep(50); /* Wait 0.05 seconds */
235 while(jsys(SIBE,2,_PRIIN) != 0) { /* read input until buffer is empty */
237 result[i++] = jsac[2];
239 zleep(50); /* Wait 0.05 seconds */
246 ttybin(bin) int bin; {
249 #define IO_MOD 0000017
256 static int arglst[] = {
261 arglst[0] = bin ? _IOPIM : _IOASC;
262 v = uuo(OPEN, 1, &arglst[0]);
263 if (!v) { printf("OPEN failed"); exit(); }
264 trmop(_TOPAG + _TOSET, bin ? 0 : 1);
268 /* TTYBIN will set the line in BINARY/ASCII mode
269 * BINARY mode is needed to send control characters
270 * Bit 28 must be 0 (we don't flip it).
271 * Bit 29 is used for the mode change.
274 #define _TTASC 0000100
275 #define _MOXOF 0000043
280 v = ejsys(SFMOD,_CTTRM, bin ? (~_TTASC & jsac[2]) : (_TTASC | jsac[2]));
281 if (v) { printf("SFMOD failed"); exit(); }
282 v = ejsys(MTOPR,_CTTRM,_MOXOF,0);
283 if (v) { printf("MTOPR failed"); exit(); }
289 * SUPERBIN turns off/on all input character interrupts
290 * This affects ^C, ^O, ^T
291 * Beware where and how you use it !!!!!!!
294 superbin(bin) int bin; {
297 v = ejsys(STIW,(0//-5), bin ? 0 : -1);
298 if (v) { printf("STIW superbinary setting failed"); exit(); }
303 * PAGE affects the ^S/^Q handshake.
304 * Set bit 34 to turn it on. Clear it for off.
310 #define TT_PGM 0000002
312 ejsys(RFMOD,_CTTRM); /* Get the current terminal status */
313 v = ejsys(STPAR,_CTTRM, bin ? (TT_PGM | jsac[2]) : (~TT_PGM & jsac[2]));
314 if (v) { printf("STPAR failed"); exit(); }
318 trmop(fc,arg) int fc, arg; {
323 /* TRMOP is a TOPS-10 monitor call that does things to the terminal. */
325 /* Find out TTY nbr (PA1050 barfs if TRMOP get -1 instead of udx) */
326 /* A TRMNO monitor call returns the udx (Universal Device Index) */
328 arglst[0] = fc; /* function code */
329 arglst[1] = calli(0115, -1); /* udx, TRMNO. UUO */
330 arglst[2] = arg; /* Optional argument */
332 if (calli(0116, 3 // &arglst[0], &retvalp)) /* TRMOP. UUO */
335 printf("?Error return in TRMOP.");
341 inputline(s) char *s; {
354 * Flush input buffer, make sure no pending input character
361 while(rdchk(0)) read(0,&val,1);
364 while(read(2,&val,1));
367 ioctl (0, FIONREAD, &l1);
368 while(l1-- > 0L) read(0,&val,1);
373 while(uuo(051,2,&val)) /* TTCALL 2, (INCHRS) */
377 ejsys(CFIBF,_PRIIN); /* Clear input buffer */
384 * Sleep and do nothing (don't waste CPU) for t milliseconds
388 calli(072,t); /* (HIBER) t milliseconds */
391 ejsys(DISMS,t); /* DISMISS for t milliseconds */
396 sleep(t); /* UNIX can only sleep whole seconds */