l_time(): give the rss fields more room
[unix-history] / usr / src / usr.bin / window / ttzapple.c
CommitLineData
1dbd69e7 1/*
2d152f42 2 * Copyright (c) 1989 Regents of the University of California.
1dbd69e7
EW
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17
18#ifndef lint
17f96a0f 19static char sccsid[] = "@(#)ttzapple.c 3.8 (Berkeley) %G%";
1dbd69e7
EW
20#endif /* not lint */
21
22#include "ww.h"
23#include "tt.h"
24#include "char.h"
25
26/*
e5dee0c2 27zz|zapple|perfect apple:\
1dbd69e7 28 :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\
e5dee0c2
EW
29 :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\
30 :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\
31 :so=\E+:se=\E-:\
32 :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\
33 :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\
34 :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\
35 :is=\E-\ET :
1dbd69e7
EW
36*/
37
ab8b3b31
EW
38#define NCOL 80
39#define NROW 24
40#define TOKEN_MAX 32
1dbd69e7 41
1dbd69e7
EW
42extern short gen_frame[];
43
1dbd69e7
EW
44zz_setmodes(new)
45{
46 if (new & WWM_REV) {
e5dee0c2 47 if ((tt.tt_modes & WWM_REV) == 0)
27c9228e 48 ttesc('+');
1dbd69e7 49 } else
e5dee0c2 50 if (tt.tt_modes & WWM_REV)
27c9228e 51 ttesc('-');
1dbd69e7
EW
52 tt.tt_modes = new;
53}
54
2d152f42 55zz_insline(n)
1dbd69e7 56{
e5dee0c2 57 if (n == 1)
27c9228e 58 ttesc('a');
e5dee0c2 59 else {
27c9228e
EW
60 ttesc('A');
61 ttputc(n + ' ');
2d152f42 62 }
1dbd69e7
EW
63}
64
2d152f42 65zz_delline(n)
1dbd69e7 66{
e5dee0c2 67 if (n == 1)
27c9228e 68 ttesc('d');
e5dee0c2 69 else {
27c9228e
EW
70 ttesc('D');
71 ttputc(n + ' ');
2d152f42 72 }
1dbd69e7
EW
73}
74
75zz_putc(c)
76 char c;
77{
1dbd69e7
EW
78 if (tt.tt_nmodes != tt.tt_modes)
79 zz_setmodes(tt.tt_nmodes);
2d152f42 80 ttputc(c);
1dbd69e7
EW
81 if (++tt.tt_col == NCOL)
82 tt.tt_col = 0, tt.tt_row++;
83}
84
1dbd69e7
EW
85zz_write(p, n)
86 register char *p;
87 register n;
88{
1dbd69e7
EW
89 if (tt.tt_nmodes != tt.tt_modes)
90 zz_setmodes(tt.tt_nmodes);
ab8b3b31 91 ttwrite(p, n);
1dbd69e7
EW
92 tt.tt_col += n;
93 if (tt.tt_col == NCOL)
94 tt.tt_col = 0, tt.tt_row++;
95}
96
97zz_move(row, col)
98 register row, col;
99{
ab8b3b31
EW
100 register x;
101
1dbd69e7 102 if (tt.tt_row == row) {
17f96a0f 103same_row:
ab8b3b31 104 if ((x = col - tt.tt_col) == 0)
1dbd69e7
EW
105 return;
106 if (col == 0) {
27c9228e 107 ttctrl('m');
1dbd69e7
EW
108 goto out;
109 }
ab8b3b31
EW
110 switch (x) {
111 case 2:
27c9228e 112 ttctrl('f');
ab8b3b31 113 case 1:
27c9228e 114 ttctrl('f');
1dbd69e7 115 goto out;
ab8b3b31 116 case -2:
27c9228e 117 ttctrl('h');
ab8b3b31 118 case -1:
27c9228e 119 ttctrl('h');
ab8b3b31
EW
120 goto out;
121 }
122 if (col & 7 == 0 && x > 0 && x <= 16) {
27c9228e 123 ttctrl('i');
ab8b3b31 124 if (x > 8)
27c9228e 125 ttctrl('i');
1dbd69e7
EW
126 goto out;
127 }
27c9228e
EW
128 ttesc('<');
129 ttputc(col + ' ');
1dbd69e7
EW
130 goto out;
131 }
132 if (tt.tt_col == col) {
ab8b3b31
EW
133 switch (row - tt.tt_row) {
134 case 2:
27c9228e 135 ttctrl('j');
ab8b3b31 136 case 1:
27c9228e 137 ttctrl('j');
1dbd69e7 138 goto out;
ab8b3b31 139 case -2:
27c9228e 140 ttctrl('k');
ab8b3b31 141 case -1:
27c9228e 142 ttctrl('k');
ab8b3b31 143 goto out;
1dbd69e7
EW
144 }
145 if (col == 0) {
146 if (row == 0)
147 goto home;
148 if (row == NROW - 1)
149 goto ll;
150 }
27c9228e
EW
151 ttesc('>');
152 ttputc(row + ' ');
1dbd69e7
EW
153 goto out;
154 }
155 if (col == 0) {
156 if (row == 0) {
157home:
27c9228e 158 ttesc('0');
1dbd69e7
EW
159 goto out;
160 }
ab8b3b31 161 if (row == tt.tt_row + 1) {
17f96a0f
EW
162 /*
163 * Do newline first to match the sequence
164 * for scroll down and return
165 */
27c9228e 166 ttctrl('j');
17f96a0f 167 ttctrl('m');
ab8b3b31
EW
168 goto out;
169 }
1dbd69e7
EW
170 if (row == NROW - 1) {
171ll:
27c9228e 172 ttesc('1');
1dbd69e7
EW
173 goto out;
174 }
175 }
17f96a0f
EW
176 /* favor local motion for better compression */
177 if (row == tt.tt_row + 1) {
178 ttctrl('j');
179 goto same_row;
180 }
181 if (row == tt.tt_row - 1) {
182 ttctrl('k');
183 goto same_row;
184 }
27c9228e
EW
185 ttesc('=');
186 ttputc(' ' + row);
187 ttputc(' ' + col);
1dbd69e7
EW
188out:
189 tt.tt_col = col;
190 tt.tt_row = row;
191}
192
ab8b3b31 193zz_start()
1dbd69e7 194{
1dbd69e7
EW
195 zz_setmodes(0);
196 zz_setscroll(0, NROW - 1);
197 zz_clear();
27c9228e
EW
198 ttesc('T');
199 ttputc(TOKEN_MAX + ' ');
1dbd69e7
EW
200}
201
202zz_end()
203{
27c9228e
EW
204 ttesc('T');
205 ttputc(' ');
1dbd69e7
EW
206}
207
208zz_clreol()
209{
27c9228e 210 ttesc('2');
1dbd69e7
EW
211}
212
213zz_clreos()
214{
27c9228e 215 ttesc('3');
1dbd69e7
EW
216}
217
218zz_clear()
219{
27c9228e 220 ttesc('4');
1dbd69e7
EW
221 tt.tt_col = tt.tt_row = 0;
222}
223
d9375810 224zz_insspace(n)
1dbd69e7 225{
e5dee0c2 226 if (n == 1)
27c9228e 227 ttesc('i');
e5dee0c2 228 else {
27c9228e
EW
229 ttesc('I');
230 ttputc(n + ' ');
2d152f42
EW
231 }
232}
233
234zz_delchar(n)
235{
e5dee0c2 236 if (n == 1)
27c9228e 237 ttesc('c');
e5dee0c2 238 else {
27c9228e
EW
239 ttesc('C');
240 ttputc(n + ' ');
2d152f42 241 }
1dbd69e7
EW
242}
243
2d152f42 244zz_scroll_down(n)
1dbd69e7 245{
e5dee0c2
EW
246 if (n == 1)
247 if (tt.tt_row == NROW - 1)
27c9228e 248 ttctrl('j');
e5dee0c2 249 else
27c9228e 250 ttesc('f');
1dbd69e7 251 else {
27c9228e
EW
252 ttesc('F');
253 ttputc(n + ' ');
1dbd69e7
EW
254 }
255}
256
2d152f42 257zz_scroll_up(n)
1dbd69e7 258{
e5dee0c2 259 if (n == 1)
27c9228e 260 ttesc('r');
e5dee0c2 261 else {
27c9228e
EW
262 ttesc('R');
263 ttputc(n + ' ');
2d152f42 264 }
1dbd69e7
EW
265}
266
267zz_setscroll(top, bot)
268{
27c9228e
EW
269 ttesc('?');
270 ttputc(top + ' ');
271 ttputc(bot + ' ');
1dbd69e7
EW
272 tt.tt_scroll_top = top;
273 tt.tt_scroll_bot = bot;
274}
275
ab8b3b31
EW
276int zz_debug = 0;
277
278zz_set_token(t, s, n)
2d152f42 279 char *s;
1dbd69e7 280{
ab8b3b31
EW
281 if (tt.tt_nmodes != tt.tt_modes)
282 zz_setmodes(tt.tt_nmodes);
283 if (zz_debug) {
284 char buf[100];
285 zz_setmodes(WWM_REV);
286 (void) sprintf(buf, "%02x=", t);
287 ttputs(buf);
288 tt.tt_col += 3;
2d152f42 289 }
27c9228e
EW
290 ttputc(0x80);
291 ttputc(t + 1);
ab8b3b31
EW
292 s[n - 1] |= 0x80;
293 ttwrite(s, n);
294 s[n - 1] &= ~0x80;
2d152f42
EW
295}
296
ab8b3b31
EW
297/*ARGSUSED*/
298zz_put_token(t, s, n)
299 char *s;
2d152f42 300{
ab8b3b31
EW
301 if (tt.tt_nmodes != tt.tt_modes)
302 zz_setmodes(tt.tt_nmodes);
303 if (zz_debug) {
304 char buf[100];
305 zz_setmodes(WWM_REV);
306 (void) sprintf(buf, "%02x>", t);
307 ttputs(buf);
308 tt.tt_col += 3;
1dbd69e7 309 }
27c9228e 310 ttputc(t + 0x81);
1dbd69e7 311}
1dbd69e7
EW
312
313tt_zapple()
314{
d9375810 315 tt.tt_insspace = zz_insspace;
1dbd69e7
EW
316 tt.tt_delchar = zz_delchar;
317 tt.tt_insline = zz_insline;
318 tt.tt_delline = zz_delline;
319 tt.tt_clreol = zz_clreol;
320 tt.tt_clreos = zz_clreos;
321 tt.tt_scroll_down = zz_scroll_down;
322 tt.tt_scroll_up = zz_scroll_up;
323 tt.tt_setscroll = zz_setscroll;
324 tt.tt_availmodes = WWM_REV;
1dbd69e7
EW
325 tt.tt_wrap = 1;
326 tt.tt_retain = 0;
ab8b3b31
EW
327 tt.tt_ncol = NCOL;
328 tt.tt_nrow = NROW;
329 tt.tt_start = zz_start;
1dbd69e7
EW
330 tt.tt_end = zz_end;
331 tt.tt_write = zz_write;
332 tt.tt_putc = zz_putc;
333 tt.tt_move = zz_move;
334 tt.tt_clear = zz_clear;
1dbd69e7
EW
335 tt.tt_setmodes = zz_setmodes;
336 tt.tt_frame = gen_frame;
17f96a0f 337 tt.tt_padc = TT_PADC_NONE;
c3f42fe5 338 tt.tt_ntoken = 127;
ab8b3b31
EW
339 tt.tt_set_token = zz_set_token;
340 tt.tt_put_token = zz_put_token;
341 tt.tt_token_min = 1;
342 tt.tt_token_max = TOKEN_MAX;
343 tt.tt_set_token_cost = 2;
344 tt.tt_put_token_cost = 1;
1dbd69e7
EW
345 return 0;
346}