5 static const char rcsid[] =
14 printf("%c%s", 27, s);
17 esc2(s1, s2) char s1, s2; {
18 printf("%c%s%s", 27, s1, s2);
21 brcstr(ps, c) char *ps, c; {
22 printf("%c[%s%c", 27, ps, c);
25 brc(pn,c) int pn; char c; {
26 printf("%c[%d%c", 27, pn, c);
29 brc2(pn1, pn2 ,c) int pn1, pn2; char c; {
30 printf("%c[%d;%d%c", 27, pn1, pn2, c);
33 cub(pn) int pn; { /* Cursor Backward */
36 cud(pn) int pn; { /* Cursor Down */
39 cuf(pn) int pn; { /* Cursor Forward */
42 cup(pn1, pn2) int pn1, pn2; { /* Cursor Position */
45 cuu(pn) int pn; { /* Cursor Up */
48 da() { /* Device Attributes */
51 decaln() { /* Screen Alignment Display */
54 decdhl(lower) int lower; { /* Double Height Line (also double width) */
58 decdwl() { /* Double Wide Line */
61 deckpam() { /* Keypad Application Mode */
64 deckpnm() { /* Keypad Numeric Mode */
67 decll(ps) char *ps; { /* Load LEDs */
70 decrc() { /* Restore Cursor */
73 decreqtparm(pn) int pn; { /* Request Terminal Parameters */
76 decsc() { /* Save Cursor */
79 decstbm(pn1, pn2) int pn1, pn2; { /* Set Top and Bottom Margins */
80 if (pn1 || pn2) brc2(pn1, pn2, 'r');
82 /* Good for >24-line terminals */
84 decswl() { /* Single With Line */
87 dectst(pn) int pn; { /* Invoke Confidence Test */
90 dsr(pn) int pn; { /* Device Status Report */
93 ed(pn) int pn; { /* Erase in Display */
96 el(pn) int pn; { /* Erase in Line */
99 hts() { /* Horizontal Tabulation Set */
102 hvp(pn1, pn2) int pn1, pn2; { /* Horizontal and Vertical Position */
108 nel() { /* Next Line */
111 ri() { /* Reverse Index */
114 ris() { /* Reset to Initial State */
117 rm(ps) char *ps; { /* Reset Mode */
120 scs(g,c) int g; char c; { /* Select character Set */
121 printf("%c%c%c%c%c%c%c", 27, g ? ')' : '(', c,
122 27, g ? '(' : ')', 'B',
125 sgr(ps) char *ps; { /* Select Graphic Rendition */
128 sm(ps) char *ps; { /* Set Mode */
131 tbc(pn) int pn; { /* Tabulation Clear */
135 vt52cup(l,c) int l,c; {
136 printf("%cY%c%c", 27, l + 31, c + 31);
142 * Wait until a character is typed on the terminal
143 * then read it, without waiting for CR.
147 int lval, waittime, getpid(); static int val; char ch;
153 read(STDIN_FILENO,&ch,1);
159 if ((val==0177) && (val==lval))
160 kill(getpid(), (int) SIGTERM);
166 while(!uuo(051,2,&val)) { /* TTCALL 2, (INCHRS) */
167 zleep(100); /* Wait 0.1 seconds */
168 if ((waittime += ttymode) > 600) /* Time-out, in case */
169 return('\177'); /* of hung in ttybin(1) */
172 #ifdef SARG20 /* try to fix a time-out function */
176 while(jsys(SIBE,2,_PRIIN) == 0) { /* Is input empty? */
178 if ((waittime += ttymode) > 600)
190 * Get an unfinished string from the terminal:
191 * wait until a character is typed on the terminal,
192 * then read it, and all other available characters.
193 * Return a pointer to that string.
197 int i, val, crflag; long l1; char ch;
198 static char result[80];
201 result[i++] = inchar();
202 /* Wait 0.1 seconds (1 second in vanilla UNIX) */
204 if (trmop(01031,0) < 5) zleep(500); /* wait longer if low speed */
213 read(STDIN_FILENO,result+i,1);
214 if (i++ == 78) break;
218 while(read(STDERR_FILENO,result+i,1) == 1)
219 if (i++ == 78) break;
221 while(ioctl(0,FIONREAD,&l1), l1 > 0L) {
223 read(STDIN_FILENO,result+i,1);
224 if (i++ == 78) goto out1;
232 while(uuo(051,2,&val)) { /* TTCALL 2, (INCHRS) */
233 if (!(val == '\012' && crflag)) /* TOPS-10 adds LF to CR */
235 crflag = val == '\015';
237 zleep(50); /* Wait 0.05 seconds */
241 while(jsys(SIBE,2,_PRIIN) != 0) { /* read input until buffer is empty */
243 result[i++] = jsac[2];
245 zleep(50); /* Wait 0.05 seconds */
252 ttybin(bin) int bin; {
255 #define IO_MOD 0000017
262 static int arglst[] = {
267 arglst[0] = bin ? _IOPIM : _IOASC;
268 v = uuo(OPEN, 1, &arglst[0]);
269 if (!v) { printf("OPEN failed"); exit(); }
270 trmop(_TOPAG + _TOSET, bin ? 0 : 1);
274 /* TTYBIN will set the line in BINARY/ASCII mode
275 * BINARY mode is needed to send control characters
276 * Bit 28 must be 0 (we don't flip it).
277 * Bit 29 is used for the mode change.
280 #define _TTASC 0000100
281 #define _MOXOF 0000043
286 v = ejsys(SFMOD,_CTTRM, bin ? (~_TTASC & jsac[2]) : (_TTASC | jsac[2]));
287 if (v) { printf("SFMOD failed"); exit(); }
288 v = ejsys(MTOPR,_CTTRM,_MOXOF,0);
289 if (v) { printf("MTOPR failed"); exit(); }
295 * SUPERBIN turns off/on all input character interrupts
296 * This affects ^C, ^O, ^T
297 * Beware where and how you use it !!!!!!!
300 superbin(bin) int bin; {
303 v = ejsys(STIW,(0//-5), bin ? 0 : -1);
304 if (v) { printf("STIW superbinary setting failed"); exit(); }
309 * PAGE affects the ^S/^Q handshake.
310 * Set bit 34 to turn it on. Clear it for off.
316 #define TT_PGM 0000002
318 ejsys(RFMOD,_CTTRM); /* Get the current terminal status */
319 v = ejsys(STPAR,_CTTRM, bin ? (TT_PGM | jsac[2]) : (~TT_PGM & jsac[2]));
320 if (v) { printf("STPAR failed"); exit(); }
324 trmop(fc,arg) int fc, arg; {
329 /* TRMOP is a TOPS-10 monitor call that does things to the terminal. */
331 /* Find out TTY nbr (PA1050 barfs if TRMOP get -1 instead of udx) */
332 /* A TRMNO monitor call returns the udx (Universal Device Index) */
334 arglst[0] = fc; /* function code */
335 arglst[1] = calli(0115, -1); /* udx, TRMNO. UUO */
336 arglst[2] = arg; /* Optional argument */
338 if (calli(0116, 3 // &arglst[0], &retvalp)) /* TRMOP. UUO */
341 printf("?Error return in TRMOP.");
347 inputline(s) char *s; {
360 * Flush input buffer, make sure no pending input character
367 while(rdchk(0)) read(STDIN_FILENO,&val,1);
370 while(read(STDERR_FILENO,&val,1));
373 ioctl (0, FIONREAD, &l1);
374 while(l1-- > 0L) read(STDIN_FILENO,&val,1);
379 while(uuo(051,2,&val)) /* TTCALL 2, (INCHRS) */
383 ejsys(CFIBF,_PRIIN); /* Clear input buffer */
390 * Sleep and do nothing (don't waste CPU) for t milliseconds
394 calli(072,t); /* (HIBER) t milliseconds */
397 ejsys(DISMS,t); /* DISMISS for t milliseconds */
402 sleep(t); /* UNIX can only sleep whole seconds */