2 ** Copyright (C) 1991, 1997 Free Software Foundation, Inc.
4 ** This file is part of TACK.
6 ** TACK is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2, or (at your option)
11 ** TACK is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with TACK; see the file COPYING. If not, write to
18 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 ** Boston, MA 02111-1307, USA.
21 /* initialization and wrapup code */
25 MODULE_ID("$Id: init.c,v 1.4 2003/09/20 19:40:57 tom Exp $")
27 #if NCURSES_VERSION_MAJOR >= 5 || NCURSES_VERSION_PATCH >= 981219
28 #define _nc_get_curterm(p) _nc_get_tty_mode(p)
33 char tty_basename
[64];
36 put_name(const char *cap
, const char *name
)
37 { /* send the cap name followed by the cap */
45 report_cap(const char *tag
, const char *s
)
46 { /* expand the cap or print *** missing *** */
50 for (i
= char_count
; i
< 13; i
++) {
57 putln("*** missing ***");
64 { /* send the reset and init strings */
67 ptext("Terminal reset");
69 put_name(reset_1string
, " (rs1)");
70 put_name(reset_2string
, " (rs2)");
71 /* run the reset file */
72 if (reset_file
&& reset_file
[0]) {
76 can_test("rf", FLAG_TESTED
);
77 if ((fp
= fopen(reset_file
, "r"))) { /* send the reset file */
78 sprintf(temp
, " (rf) %s", reset_file
);
88 sprintf(temp
, "\nCannot open reset file (rf) %s", reset_file
);
92 put_name(reset_3string
, " (rs3)");
93 if (i
!= char_count
) {
97 put_name(init_1string
, " (is1)");
98 put_name(init_2string
, " (is2)");
99 if (set_tab
&& clear_all_tabs
&& init_tabs
!= 8) {
101 tc_putp(clear_all_tabs
);
102 for (char_count
= 0; char_count
< columns
; char_count
++) {
104 if ((char_count
& 7) == 7) {
110 /* run the initialization file */
111 if (init_file
&& init_file
[0]) {
115 can_test("if", FLAG_TESTED
);
116 if ((fp
= fopen(init_file
, "r"))) { /* send the init file */
117 sprintf(temp
, " (if) %s", init_file
);
127 sprintf(temp
, "\nCannot open init file (if) %s", init_file
);
132 can_test("iprog", FLAG_TESTED
);
133 (void) system(init_prog
);
135 put_name(init_3string
, " (is3)");
143 ** display the basic terminal definitions
151 report_cap("\\r ^M (cr)", carriage_return
);
152 report_cap("\\n ^J (ind)", scroll_forward
);
153 report_cap("\\b ^H (cub1)", cursor_left
);
154 report_cap("\\t ^I (ht)", tab
);
155 /* report_cap("\\f ^L (ff)", form_feed); */
158 report_cap(" (nel)", newline
);
160 report_cap(" (clear)", clear_screen
);
161 if (!cursor_home
&& cursor_address
) {
162 report_cap("(cup) (home)", tparm(cursor_address
, 0, 0));
164 report_cap(" (home)", cursor_home
);
167 report_cap("ENQ (u9)", user9
);
170 report_cap("ACK (u8)", user8
);
173 sprintf(temp
, "\nTerminal size: %d x %d. Baud rate: %ld. Frame size: %d.%d", columns
, lines
, tty_baud_rate
, tty_frame_size
>> 1, (tty_frame_size
& 1) * 5);
178 ** curses_setup(exec_name)
187 static TERMTYPE term
;
188 char tty_filename
[2048];
193 See if the terminal is in the terminfo data base. This call has
194 two useful benefits, 1) it returns the filename of the terminfo entry,
195 and 2) it searches only terminfo's. This allows us to abort before
196 ncurses starts scanning the termcap file.
198 if ((status
= _nc_read_entry(tty_basename
, tty_filename
, &term
)) == 0) {
199 const TERMTYPE
*fallback
= _nc_fallback(tty_basename
);
203 sprintf(tty_filename
, "(fallback)%s", tty_basename
);
206 fprintf(stderr
, "Terminal not found: TERM=%s\n", tty_basename
);
207 show_usage(exec_name
);
212 fprintf(stderr
, "Terminfo database is inaccessible\n");
217 This call will load the terminfo data base and set the cur-term
218 variable. Only terminals that actually exist will get here so its
219 OK to ignore errors. This is a good thing since ncurses does not
220 permit (os) or (gn) to be set.
222 setupterm(tty_basename
, 1, &status
);
225 Get the current terminal definitions. This must be done before
226 getting the baudrate.
228 _nc_get_curterm(&cur_term
->Nttyb
);
229 tty_baud_rate
= baudrate();
230 tty_cps
= (tty_baud_rate
<< 1) / tty_frame_size
;
232 /* set up the defaults */
236 select_delay_type
= debug_level
= 0;
237 char_mask
= (meta_on
&& meta_on
[0] == '\0') ? ALLOW_PARITY
: STRIP_PARITY
;
238 /* Don't change the XON/XOFF modes yet. */
239 select_xon_xoff
= initial_stty_query(TTY_XON_XOFF
) ? 1 : needs_xon_xoff
;
241 fflush(stdout
); /* flush any output */
244 go_home(); /* set can_go_home */
245 put_clear(); /* set can_clear_screen */
247 if (send_reset_init
) {
252 I assume that the reset and init strings may not have the correct
253 pads. (Because that part of the test comes much later.) Because
254 of this, I allow the terminal some time to catch up.
256 fflush(stdout
); /* waste some time */
257 sleep(1); /* waste more time */
259 can_test("lines cols cr nxon rf if iprog rmp smcup rmcup", FLAG_CAN_TEST
);
260 edit_init(); /* initialize the edit data base */
262 if (send_reset_init
&& enter_ca_mode
) {
263 tc_putp(enter_ca_mode
);
264 put_clear(); /* just in case we switched pages */
267 ptext("Using terminfo from: ");
268 ptextln(tty_filename
);
271 if (tty_can_sync
== SYNC_NEEDED
) {
279 ** bye_kids(exit-condition)
281 ** Shutdown the terminal, clear the signals, and exit
285 { /* reset the tty and exit */
287 if (send_reset_init
) {
289 tc_putp(exit_ca_mode
);
291 if (initial_stty_query(TTY_XON_XOFF
)) {
292 if (enter_xon_mode
) {
293 tc_putp(enter_xon_mode
);
295 } else if (exit_xon_mode
) {
296 tc_putp(exit_xon_mode
);