delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / konsole / tests / esc.c
blob02627548699bbc85cde4d8bfa9d56eb316aaaf4b
1 /*
2 VTTEST.C
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.
17 #include "header.h"
19 println(s) char *s; {
20 printf("%s\n", s);
23 esc(s) char *s; {
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 */
44 brc(pn,'D');
46 cud(pn) int pn; { /* Cursor Down */
47 brc(pn,'B');
49 cuf(pn) int pn; { /* Cursor Forward */
50 brc(pn,'C');
52 cup(pn1, pn2) int pn1, pn2; { /* Cursor Position */
53 brc2(pn1, pn2, 'H');
55 cuu(pn) int pn; { /* Cursor Up */
56 brc(pn,'A');
58 da() { /* Device Attributes */
59 brc(0,'c');
61 decaln() { /* Screen Alignment Display */
62 esc("#8");
64 decdhl(lower) int lower; { /* Double Height Line (also double width) */
65 if (lower) esc("#4");
66 else esc("#3");
68 decdwl() { /* Double Wide Line */
69 esc("#6");
71 deckpam() { /* Keypad Application Mode */
72 esc("=");
74 deckpnm() { /* Keypad Numeric Mode */
75 esc(">");
77 decll(ps) char *ps; { /* Load LEDs */
78 brcstr(ps, 'q');
80 decrc() { /* Restore Cursor */
81 esc("8");
83 decreqtparm(pn) int pn; { /* Request Terminal Parameters */
84 brc(pn,'x');
86 decsc() { /* Save Cursor */
87 esc("7");
89 decstbm(pn1, pn2) int pn1, pn2; { /* Set Top and Bottom Margins */
90 if (pn1 || pn2) brc2(pn1, pn2, 'r');
91 else esc("[r");
92 /* Good for >24-line terminals */
94 decswl() { /* Single With Line */
95 esc("#5");
97 dectst(pn) int pn; { /* Invoke Confidence Test */
98 brc2(2, pn, 'y');
100 dsr(pn) int pn; { /* Device Status Report */
101 brc(pn, 'n');
103 ed(pn) int pn; { /* Erase in Display */
104 brc(pn, 'J');
106 el(pn) int pn; { /* Erase in Line */
107 brc(pn,'K');
109 hts() { /* Horizontal Tabulation Set */
110 esc("H");
112 hvp(pn1, pn2) int pn1, pn2; { /* Horizontal and Vertical Position */
113 brc2(pn1, pn2, 'f');
115 ind() { /* Index */
116 esc("D");
118 nel() { /* Next Line */
119 esc("E");
121 ri() { /* Reverse Index */
122 esc("M");
124 ris() { /* Reset to Initial State */
125 esc("c");
127 rm(ps) char *ps; { /* Reset Mode */
128 brcstr(ps, 'l');
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',
133 g ? 14 : 15);
135 sgr(ps) char *ps; { /* Select Graphic Rendition */
136 brcstr(ps, 'm');
138 sm(ps) char *ps; { /* Set Mode */
139 brcstr(ps, 'h');
141 tbc(pn) int pn; { /* Tabulation Clear */
142 brc(pn, 'g');
145 vt52cup(l,c) int l,c; {
146 printf("%cY%c%c", 27, l + 31, c + 31);
149 char inchar() {
152 * Wait until a character is typed on the terminal
153 * then read it, without waiting for CR.
156 #ifdef UNIX
157 int lval, waittime, getpid(); static int val; char ch;
159 fflush(stdout);
160 lval = val;
161 brkrd = 0;
162 reading = 1;
163 read(0,&ch,1);
164 reading = 0;
165 if (brkrd)
166 val = 0177;
167 else
168 val = ch;
169 if ((val==0177) && (val==lval))
170 kill(getpid(), (int) SIGTERM);
171 #endif
172 #ifdef SARG10
173 int val, waittime;
175 waittime = 0;
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) */
181 #endif
182 #ifdef SARG20 /* try to fix a time-out function */
183 int val, waittime;
185 waittime = 0;
186 while(jsys(SIBE,2,_PRIIN) == 0) { /* Is input empty? */
187 zleep(100);
188 if ((waittime += ttymode) > 600)
189 return('\177');
191 ejsys(BIN,_PRIIN);
192 val = jsac[2];
193 #endif
194 return(val);
197 char *instr() {
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];
210 i = 0;
211 result[i++] = inchar();
212 /* Wait 0.1 seconds (1 second in vanilla UNIX) */
213 #ifdef SARG10
214 if (trmop(01031,0) < 5) zleep(500); /* wait longer if low speed */
215 else zleep(100);
216 #else
217 zleep(100);
218 #endif
219 #ifdef UNIX
220 fflush(stdout);
221 #ifdef XENIX
222 while(rdchk(0)) {
223 read(0,result+i,1);
224 if (i++ == 78) break;
226 #else
227 #ifdef SIII
228 while(read(2,result+i,1) == 1)
229 if (i++ == 78) break;
230 #else
231 while(ioctl(0,FIONREAD,&l1), l1 > 0L) {
232 while(l1-- > 0L) {
233 read(0,result+i,1);
234 if (i++ == 78) goto out1;
237 out1:
238 #endif
239 #endif
240 #endif
241 #ifdef SARG10
242 while(uuo(051,2,&val)) { /* TTCALL 2, (INCHRS) */
243 if (!(val == '\012' && crflag)) /* TOPS-10 adds LF to CR */
244 result[i++] = val;
245 crflag = val == '\015';
246 if (i == 79) break;
247 zleep(50); /* Wait 0.05 seconds */
249 #endif
250 #ifdef SARG20
251 while(jsys(SIBE,2,_PRIIN) != 0) { /* read input until buffer is empty */
252 ejsys(BIN,_PRIIN);
253 result[i++] = jsac[2];
254 if (i == 79) break;
255 zleep(50); /* Wait 0.05 seconds */
257 #endif
258 result[i] = '\0';
259 return(result);
262 ttybin(bin) int bin; {
263 #ifdef SARG10
264 #define OPEN 050
265 #define IO_MOD 0000017
266 #define _IOPIM 2
267 #define _IOASC 0
268 #define _TOPAG 01021
269 #define _TOSET 01000
271 int v;
272 static int arglst[] = {
273 _IOPIM,
274 `TTY`,
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);
281 ttymode = bin;
282 #endif
283 #ifdef SARG20
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
293 int v;
295 ejsys(RFMOD,_CTTRM);
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(); }
300 #endif
303 #ifdef SARG20
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; {
311 int v;
313 v = ejsys(STIW,(0//-5), bin ? 0 : -1);
314 if (v) { printf("STIW superbinary setting failed"); exit(); }
315 ttymode = bin;
319 * PAGE affects the ^S/^Q handshake.
320 * Set bit 34 to turn it on. Clear it for off.
323 page(bin) int bin; {
324 int v;
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(); }
332 #endif
334 trmop(fc,arg) int fc, arg; {
335 #ifdef SARG10
336 int retvalp;
337 int arglst[3];
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 */
349 return (retvalp);
350 else {
351 printf("?Error return in TRMOP.");
352 exit();
354 #endif
357 inputline(s) char *s; {
358 scanf("%s",s);
359 #ifdef SARG10
360 readnl();
361 #endif
362 #ifdef SARG20
363 readnl();
364 #endif
367 inflush() {
370 * Flush input buffer, make sure no pending input character
373 int val;
375 #ifdef UNIX
376 #ifdef XENIX
377 while(rdchk(0)) read(0,&val,1);
378 #else
379 #ifdef SIII
380 while(read(2,&val,1));
381 #else
382 long l1;
383 ioctl (0, FIONREAD, &l1);
384 while(l1-- > 0L) read(0,&val,1);
385 #endif
386 #endif
387 #endif
388 #ifdef SARG10
389 while(uuo(051,2,&val)) /* TTCALL 2, (INCHRS) */
391 #endif
392 #ifdef SARG20
393 ejsys(CFIBF,_PRIIN); /* Clear input buffer */
394 #endif
397 zleep(t) int t; {
400 * Sleep and do nothing (don't waste CPU) for t milliseconds
403 #ifdef SARG10
404 calli(072,t); /* (HIBER) t milliseconds */
405 #endif
406 #ifdef SARG20
407 ejsys(DISMS,t); /* DISMISS for t milliseconds */
408 #endif
409 #ifdef UNIX
410 t = t / 1000;
411 if (t == 0) t = 1;
412 sleep(t); /* UNIX can only sleep whole seconds */
413 #endif