2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)ttgeneric.c 8.1 (Berkeley) 6/6/93
37 * $FreeBSD: src/usr.bin/window/ttgeneric.c,v 1.2.8.1 2001/05/17 09:45:01 obrien Exp $
38 * $DragonFly: src/usr.bin/window/ttgeneric.c,v 1.2 2003/06/17 04:29:34 dillon Exp $
47 short gen_frame
[16] = {
54 /* ANSI graphics frame */
55 #define G (WWM_GRP << WWC_MSHIFT)
56 short ansi_frame
[16] = {
57 ' ', 'x'|G
, 'Q'|G
, 'm'|G
,
58 'x'|G
, 'x'|G
, 'l'|G
, 't'|G
,
59 'q'|G
, 'j'|G
, 'q'|G
, 'v'|G
,
60 'k'|G
, 'u'|G
, 'w'|G
, 'n'|G
62 struct tt_str ansi_AS
= {
66 struct tt_str
*gen_PC
;
67 struct tt_str
*gen_CM
;
68 struct tt_str
*gen_IM
;
69 struct tt_str
*gen_IC
;
70 struct tt_str
*gen_ICn
;
71 struct tt_str
*gen_IP
;
72 struct tt_str
*gen_EI
;
73 struct tt_str
*gen_DC
;
74 struct tt_str
*gen_DCn
;
75 struct tt_str
*gen_AL
;
76 struct tt_str
*gen_ALn
;
77 struct tt_str
*gen_DL
;
78 struct tt_str
*gen_DLn
;
79 struct tt_str
*gen_CE
;
80 struct tt_str
*gen_CD
;
81 struct tt_str
*gen_CL
;
82 struct tt_str
*gen_VS
;
83 struct tt_str
*gen_VE
;
84 struct tt_str
*gen_TI
;
85 struct tt_str
*gen_TE
;
86 struct tt_str
*gen_SO
;
87 struct tt_str
*gen_SE
;
88 struct tt_str
*gen_US
;
89 struct tt_str
*gen_UE
;
90 struct tt_str
*gen_LE
;
91 struct tt_str
*gen_ND
;
92 struct tt_str
*gen_UP
;
93 struct tt_str
*gen_DO
;
94 struct tt_str
*gen_BC
;
95 struct tt_str
*gen_NL
;
96 struct tt_str
*gen_CR
;
97 struct tt_str
*gen_HO
;
98 struct tt_str
*gen_AS
;
99 struct tt_str
*gen_AE
;
100 struct tt_str
*gen_XS
;
101 struct tt_str
*gen_XE
;
102 struct tt_str
*gen_SF
;
103 struct tt_str
*gen_SFn
;
104 struct tt_str
*gen_SR
;
105 struct tt_str
*gen_SRn
;
106 struct tt_str
*gen_CS
;
138 diff
= new ^ tt
.tt_modes
;
139 if (diff
& WWM_REV
) {
155 if (diff
& WWM_GRP
) {
163 if (diff
& WWM_USR
) {
176 if (tt
.tt_modes
) /* for concept 100 */
179 ttpgoto(gen_ALn
, 0, n
, gen_LI
- tt
.tt_row
);
182 tttputs(gen_AL
, gen_LI
- tt
.tt_row
);
187 if (tt
.tt_modes
) /* for concept 100 */
190 ttpgoto(gen_DLn
, 0, n
, gen_LI
- tt
.tt_row
);
193 tttputs(gen_DL
, gen_LI
- tt
.tt_row
);
201 if (tt
.tt_nmodes
!= tt
.tt_modes
)
202 gen_setmodes(tt
.tt_nmodes
);
204 if (++tt
.tt_col
== gen_CO
)
206 tt
.tt_col
= tt
.tt_row
= -10;
208 tt
.tt_col
= 0, tt
.tt_row
++;
219 if (tt
.tt_nmodes
!= tt
.tt_modes
)
220 gen_setmodes(tt
.tt_nmodes
);
223 if (tt
.tt_col
== gen_CO
)
225 tt
.tt_col
= tt
.tt_row
= -10;
227 tt
.tt_col
= 0, tt
.tt_row
++;
233 register int row
, col
;
235 if (tt
.tt_row
== row
&& tt
.tt_col
== col
)
237 if (!gen_MI
&& tt
.tt_insert
)
239 if (!gen_MS
&& tt
.tt_modes
)
241 if (row
< tt
.tt_scroll_top
|| row
> tt
.tt_scroll_bot
)
242 gen_setscroll(0, tt
.tt_nrow
- 1);
243 if (tt
.tt_row
== row
) {
248 if (tt
.tt_col
== col
- 1) {
253 } else if (tt
.tt_col
== col
+ 1) {
260 if (tt
.tt_col
== col
) {
261 if (tt
.tt_row
== row
+ 1) {
266 } else if (tt
.tt_row
== row
- 1) {
271 if (gen_HO
&& col
== 0 && row
== 0) {
275 tttgoto(gen_CM
, col
, row
);
288 tt
.tt_col
= tt
.tt_row
= 0;
290 tt
.tt_nmodes
= tt
.tt_modes
= 0;
305 if (tt
.tt_modes
) /* for concept 100 */
307 tttputs(gen_CE
, gen_CO
- tt
.tt_col
);
312 if (tt
.tt_modes
) /* for concept 100 */
314 tttputs(gen_CD
, gen_LI
- tt
.tt_row
);
319 if (tt
.tt_modes
) /* for concept 100 */
329 if (tt
.tt_nmodes
!= tt
.tt_modes
)
330 gen_setmodes(tt
.tt_nmodes
);
332 tttputs(gen_IC
, gen_CO
- tt
.tt_col
);
335 tttputs(gen_IP
, gen_CO
- tt
.tt_col
);
336 if (++tt
.tt_col
== gen_CO
)
338 tt
.tt_col
= tt
.tt_row
= -10;
340 tt
.tt_col
= 0, tt
.tt_row
++;
348 ttpgoto(gen_ICn
, 0, n
, gen_CO
- tt
.tt_col
);
351 tttputs(gen_IC
, gen_CO
- tt
.tt_col
);
357 ttpgoto(gen_DCn
, 0, n
, gen_CO
- tt
.tt_col
);
360 tttputs(gen_DC
, gen_CO
- tt
.tt_col
);
365 gen_move(tt
.tt_scroll_bot
, 0);
367 ttpgoto(gen_SFn
, 0, n
, n
);
375 gen_move(tt
.tt_scroll_top
, 0);
377 ttpgoto(gen_SRn
, 0, n
, n
);
383 gen_setscroll(top
, bot
)
385 tttgoto(gen_CS
, bot
, top
);
386 tt
.tt_scroll_top
= top
;
387 tt
.tt_scroll_bot
= bot
;
388 tt
.tt_row
= tt
.tt_col
= -10;
393 gen_PC
= tttgetstr("pc");
394 PC
= gen_PC
? *gen_PC
->ts_str
: 0;
396 gen_CM
= ttxgetstr("cm"); /* may not work */
397 gen_IM
= ttxgetstr("im");
398 gen_IC
= tttgetstr("ic");
399 gen_ICn
= tttgetstr("IC");
400 gen_IP
= tttgetstr("ip");
401 gen_EI
= ttxgetstr("ei");
402 gen_DC
= tttgetstr("dc");
403 gen_DCn
= tttgetstr("DC");
404 gen_AL
= tttgetstr("al");
405 gen_ALn
= tttgetstr("AL");
406 gen_DL
= tttgetstr("dl");
407 gen_DLn
= tttgetstr("DL");
408 gen_CE
= tttgetstr("ce");
409 gen_CD
= tttgetstr("cd");
410 gen_CL
= ttxgetstr("cl");
411 gen_VS
= ttxgetstr("vs");
412 gen_VE
= ttxgetstr("ve");
413 gen_TI
= ttxgetstr("ti");
414 gen_TE
= ttxgetstr("te");
415 gen_SO
= ttxgetstr("so");
416 gen_SE
= ttxgetstr("se");
417 gen_US
= ttxgetstr("us");
418 gen_UE
= ttxgetstr("ue");
419 gen_LE
= ttxgetstr("le");
420 gen_ND
= ttxgetstr("nd");
421 gen_UP
= ttxgetstr("up");
422 gen_DO
= ttxgetstr("do");
423 gen_BC
= ttxgetstr("bc");
424 gen_NL
= ttxgetstr("nl");
425 gen_CR
= ttxgetstr("cr");
426 gen_HO
= ttxgetstr("ho");
427 gen_AS
= ttxgetstr("as");
428 gen_AE
= ttxgetstr("ae");
429 gen_XS
= ttxgetstr("XS");
430 gen_XE
= ttxgetstr("XE");
431 gen_SF
= ttxgetstr("sf");
432 gen_SFn
= ttxgetstr("SF");
433 gen_SR
= ttxgetstr("sr");
434 gen_SRn
= ttxgetstr("SR");
435 gen_CS
= ttxgetstr("cs");
436 gen_MI
= tgetflag("mi");
437 gen_MS
= tgetflag("ms");
438 gen_AM
= tgetflag("am");
439 gen_OS
= tgetflag("os");
440 gen_BS
= tgetflag("bs");
441 gen_DA
= tgetflag("da");
442 gen_DB
= tgetflag("db");
443 gen_NS
= tgetflag("ns");
444 gen_XN
= tgetflag("xn");
445 gen_CO
= tgetnum("co");
446 gen_LI
= tgetnum("li");
447 gen_UG
= tgetnum("ug");
448 gen_SG
= tgetnum("sg");
449 if (gen_CL
== 0 || gen_OS
|| gen_CM
== 0)
453 * Deal with obsolete termcap fields.
459 static struct tt_str bc
= { "\b", 1 };
463 static struct tt_str nl
= { "\n", 1 };
469 static struct tt_str cr
= { "\r", 1 };
473 * Most terminal will scroll with "nl", but very few specify "sf".
474 * We shouldn't use "do" here.
476 if (gen_SF
== 0 && !gen_NS
)
478 BC
= gen_LE
? gen_LE
->ts_str
: 0;
479 UP
= gen_UP
? gen_UP
->ts_str
: 0;
481 * Fix up display attributes that we can't handle, or don't
486 if (gen_UG
> 0 || gen_US
&& gen_SO
&& ttstrcmp(gen_US
, gen_SO
) == 0)
489 if (gen_IM
&& gen_IM
->ts_n
== 0) {
490 free((char *) gen_IM
);
493 if (gen_EI
&& gen_EI
->ts_n
== 0) {
494 free((char *) gen_EI
);
497 if (gen_IC
&& gen_IC
->ts_n
== 0) {
498 free((char *) gen_IC
);
502 tt
.tt_inschar
= gen_inschar
;
504 tt
.tt_insspace
= gen_insspace
;
506 tt
.tt_delchar
= gen_delchar
;
508 tt
.tt_insline
= gen_insline
;
510 tt
.tt_delline
= gen_delline
;
512 tt
.tt_clreol
= gen_clreol
;
514 tt
.tt_clreos
= gen_clreos
;
516 tt
.tt_scroll_down
= gen_scroll_down
;
518 * Don't allow scroll_up if da or db but not cs.
519 * See comment in wwscroll.c.
521 if (gen_SR
&& (gen_CS
|| !gen_DA
&& !gen_DB
))
522 tt
.tt_scroll_up
= gen_scroll_up
;
524 tt
.tt_setscroll
= gen_setscroll
;
526 tt
.tt_availmodes
|= WWM_REV
;
528 tt
.tt_availmodes
|= WWM_UL
;
530 tt
.tt_availmodes
|= WWM_GRP
;
532 tt
.tt_availmodes
|= WWM_USR
;
534 tt
.tt_retain
= gen_DB
;
537 tt
.tt_start
= gen_start
;
539 tt
.tt_write
= gen_write
;
540 tt
.tt_putc
= gen_putc
;
541 tt
.tt_move
= gen_move
;
542 tt
.tt_clear
= gen_clear
;
543 tt
.tt_setmodes
= gen_setmodes
;
544 tt
.tt_frame
= gen_AS
&& ttstrcmp(gen_AS
, &ansi_AS
) == 0 ?
545 ansi_frame
: gen_frame
;