GC OLDCARD userland tools.
[dragonfly.git] / usr.sbin / pcvt / vttest / esc.c
1 /* $DragonFly: src/usr.sbin/pcvt/vttest/Attic/esc.c,v 1.2 2005/02/20 17:19:11 asmodai Exp $ */
2
3 #include "header.h"
4
5 println(s) char *s; {
6   printf("%s\n", s);
7 }
8
9 esc(s) char *s; {
10   printf("%c%s", 27, s);
11 }
12
13 esc2(s1, s2) char s1, s2; {
14   printf("%c%s%s", 27, s1, s2);
15 }
16
17 brcstr(ps, c) char *ps, c; {
18   printf("%c[%s%c", 27, ps, c);
19 }
20
21 brc(pn,c) int pn; char c; {
22   printf("%c[%d%c", 27, pn, c);
23 }
24
25 brc2(pn1, pn2 ,c) int pn1, pn2; char c; {
26   printf("%c[%d;%d%c", 27, pn1, pn2, c);
27 }
28
29 cub(pn) int pn; {  /* Cursor Backward */
30   brc(pn,'D');
31 }
32 cud(pn) int pn; {  /* Cursor Down */
33   brc(pn,'B');
34 }
35 cuf(pn) int pn; {  /* Cursor Forward */
36   brc(pn,'C');
37 }
38 cup(pn1, pn2) int pn1, pn2; {  /* Cursor Position */
39   brc2(pn1, pn2, 'H');
40 }
41 cuu(pn) int pn; {  /* Cursor Up */
42   brc(pn,'A');
43 }
44 da() {  /* Device Attributes */
45   brc(0,'c');
46 }
47 decaln() {  /* Screen Alignment Display */
48   esc("#8");
49 }
50 decdhl(lower) int lower; {  /* Double Height Line (also double width) */
51   if (lower) esc("#4");
52   else       esc("#3");
53 }
54 decdwl() {  /* Double Wide Line */
55   esc("#6");
56 }
57 deckpam() {  /* Keypad Application Mode */
58   esc("=");
59 }
60 deckpnm() {  /* Keypad Numeric Mode */
61   esc(">");
62 }
63 decll(ps) char *ps; {  /* Load LEDs */
64   brcstr(ps, 'q');
65 }
66 decrc() {  /* Restore Cursor */
67   esc("8");
68 }
69 decreqtparm(pn) int pn; {  /* Request Terminal Parameters */
70   brc(pn,'x');
71 }
72 decsc() {  /* Save Cursor */
73   esc("7");
74 }
75 decstbm(pn1, pn2) int pn1, pn2; {  /* Set Top and Bottom Margins */
76   if (pn1 || pn2) brc2(pn1, pn2, 'r');
77   else            esc("[r");
78   /* Good for >24-line terminals */
79 }
80 decswl() {  /* Single With Line */
81   esc("#5");
82 }
83 dectst(pn) int pn; {  /* Invoke Confidence Test */
84   brc2(2, pn, 'y');
85 }
86 dsr(pn) int pn; {  /* Device Status Report */
87   brc(pn, 'n');
88 }
89 ed(pn) int pn; {  /* Erase in Display */
90   brc(pn, 'J');
91 }
92 el(pn) int pn; {  /* Erase in Line */
93   brc(pn,'K');
94 }
95 hts() {  /* Horizontal Tabulation Set */
96   esc("H");
97 }
98 hvp(pn1, pn2) int pn1, pn2; {  /* Horizontal and Vertical Position */
99   brc2(pn1, pn2, 'f');
100 }
101 ind() {  /* Index */
102   esc("D");
103 }
104 nel() {  /* Next Line */
105   esc("E");
106 }
107 ri() {  /* Reverse Index */
108   esc("M");
109 }
110 ris() { /*  Reset to Initial State */
111   esc("c");
112 }
113 rm(ps) char *ps; {  /* Reset Mode */
114   brcstr(ps, 'l');
115 }
116 scs(g,c) int g; char c; {  /* Select character Set */
117   printf("%c%c%c%c%c%c%c", 27, g ? ')' : '(', c,
118                            27, g ? '(' : ')', 'B',
119                            g ? 14 : 15);
120 }
121 sgr(ps) char *ps; {  /* Select Graphic Rendition */
122   brcstr(ps, 'm');
123 }
124 sm(ps) char *ps; {  /* Set Mode */
125   brcstr(ps, 'h');
126 }
127 tbc(pn) int pn; {  /* Tabulation Clear */
128   brc(pn, 'g');
129 }
130
131 vt52cup(l,c) int l,c; {
132   printf("%cY%c%c", 27, l + 31, c + 31);
133 }
134
135 char inchar() {
136
137   /*
138    *   Wait until a character is typed on the terminal
139    *   then read it, without waiting for CR.
140    */
141
142   int lval, waittime, getpid(); static int val; char ch;
143
144   fflush(stdout);
145   lval = val;
146   brkrd = 0;
147   reading = 1;
148   read(0,&ch,1);
149   reading = 0;
150   if (brkrd)
151     val = 0177;
152   else
153     val = ch;
154   if ((val==0177) && (val==lval))
155     kill(getpid(), (int) SIGTERM);
156   return(val);
157 }
158
159 char *instr() {
160
161   /*
162    *   Get an unfinished string from the terminal:
163    *   wait until a character is typed on the terminal,
164    *   then read it, and all other available characters.
165    *   Return a pointer to that string.
166    */
167
168
169   int i, val, crflag; long l1; char ch;
170   static char result[80];
171
172   i = 0;
173   result[i++] = inchar();
174 /* Wait 0.1 seconds (1 second in vanilla UNIX) */
175   zleep(100);
176   fflush(stdout);
177   while(ioctl(0,FIONREAD,&l1), l1 > 0L) {
178     while(l1-- > 0L) {
179       read(0,result+i,1);
180       if (i++ == 78) goto out1;
181     }
182   }
183 out1:
184   result[i] = '\0';
185   return(result);
186 }
187
188 ttybin(bin) int bin; {
189 }
190
191
192 trmop(fc,arg) int fc, arg; {
193 }
194
195 inputline(s) char *s; {
196   scanf("%s",s);
197 }
198
199 inflush() {
200
201   /*
202    *   Flush input buffer, make sure no pending input character
203    */
204
205   int val;
206
207   long l1;
208   ioctl (0, FIONREAD, &l1);
209   while(l1-- > 0L) read(0,&val,1);
210 }
211
212 zleep(t) int t; {
213
214 /*
215  *    Sleep and do nothing (don't waste CPU) for t milliseconds
216  */
217
218   t = t / 1000;
219   if (t == 0) t = 1;
220   sleep(t);             /* UNIX can only sleep whole seconds */
221 }