1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Terminal capability interaction.
4 * Copyright (c) 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #define n_FILE termcap
21 #ifndef HAVE_AMALGAMATION
27 /* If available, curses.h must be included before term.h! */
28 #ifdef HAVE_TERMCAP_CURSES
33 static char *a_termcap_buffer
, *a_termcap_ti
, *a_termcap_te
;
35 static int a_termcap_putc(int c
);
38 a_termcap_putc(int c
){
44 /* For newer ncurses based termcap emulation buf will remain unused, for
45 * elder non-emulated ones really weird things will happen if an entry
46 * would require more than 1024 bytes, so don't mind.
47 * Things are more unserious with cmdbuf, but a single termcap command
48 * should really not excess that limit */
49 char buf
[1024 + 512], cmdbuf
[2048], *cpb
, *cpti
, *cpte
, *cp
;
52 assert(options
& OPT_INTERACTIVE
);
54 if(!ok_blook(term_ca_mode
))
56 if((cp
= env_vlook("TERM", FAL0
)) == NULL
)
64 if((cp
= tgetstr(UNCONST("ti"), &cpb
)) == NULL
)
67 if((cp
= tgetstr(UNCONST("te"), &cpb
)) == NULL
)
70 a_termcap_buffer
= smalloc(PTR2SIZE(cpb
- cmdbuf
));
71 memcpy(a_termcap_buffer
, cmdbuf
, PTR2SIZE(cpb
- cmdbuf
));
73 a_termcap_ti
= a_termcap_buffer
+ PTR2SIZE(cpti
- cmdbuf
);
74 a_termcap_te
= a_termcap_ti
+ PTR2SIZE(cpte
- cpti
);
76 tputs(a_termcap_ti
, 1, &a_termcap_putc
);
83 (termcap_destroy
)(void){
85 assert(options
& OPT_INTERACTIVE
);
87 if(a_termcap_buffer
!= NULL
){
88 tputs(a_termcap_te
, 1, &a_termcap_putc
);
91 free(a_termcap_buffer
);
92 DBG( a_termcap_buffer
= NULL
; )
98 (termcap_suspend
)(void){
100 assert(options
& OPT_INTERACTIVE
);
102 if(a_termcap_buffer
!= NULL
){
103 tputs(a_termcap_te
, 1, &a_termcap_putc
);
110 (termcap_resume
)(void){
112 assert(options
& OPT_INTERACTIVE
);
114 if(a_termcap_buffer
!= NULL
){
115 tputs(a_termcap_ti
, 1, &a_termcap_putc
);
120 #endif /* HAVE_TERMCAP */