#include <tack.h>
MODULE_ID("$Id: init.c,v 1.1.1.1 2001/11/29 20:40:59 jevans Exp $")
#if NCURSES_VERSION_MAJOR >= 5 || NCURSES_VERSION_PATCH >= 981219
#define _nc_get_curterm(p) _nc_get_tty_mode(p)
#endif
FILE *debug_fp;
char temp[1024];
char tty_basename[64];
void
put_name(const char *cap, const char *name)
{
if (cap) {
ptext(name);
tc_putp(cap);
}
}
static void
report_cap(const char *tag, const char *s)
{
int i;
ptext(tag);
for (i = char_count; i < 13; i++) {
putchp(' ');
}
put_str(" = ");
if (s) {
putln(expand(s));
} else {
putln("*** missing ***");
}
}
void
reset_init(void)
{
int i;
ptext("Terminal reset");
i = char_count;
put_name(reset_1string, " (rs1)");
put_name(reset_2string, " (rs2)");
if (reset_file && reset_file[0]) {
FILE *fp;
int ch;
can_test("rf", FLAG_TESTED);
if ((fp = fopen(reset_file, "r"))) {
sprintf(temp, " (rf) %s", reset_file);
ptextln(temp);
while (1) {
ch = getc(fp);
if (ch == EOF)
break;
put_this(ch);
}
fclose(fp);
} else {
sprintf(temp, "\nCannot open reset file (rf) %s", reset_file);
ptextln(temp);
}
}
put_name(reset_3string, " (rs3)");
if (i != char_count) {
put_crlf();
}
ptext(" init");
put_name(init_1string, " (is1)");
put_name(init_2string, " (is2)");
if (set_tab && clear_all_tabs && init_tabs != 8) {
put_crlf();
tc_putp(clear_all_tabs);
for (char_count = 0; char_count < columns; char_count++) {
put_this(' ');
if ((char_count & 7) == 7) {
tc_putp(set_tab);
}
}
put_cr();
}
if (init_file && init_file[0]) {
FILE *fp;
int ch;
can_test("if", FLAG_TESTED);
if ((fp = fopen(init_file, "r"))) {
sprintf(temp, " (if) %s", init_file);
ptextln(temp);
while (1) {
ch = getc(fp);
if (ch == EOF)
break;
put_this(ch);
}
fclose(fp);
} else {
sprintf(temp, "\nCannot open init file (if) %s", init_file);
ptextln(temp);
}
}
if (init_prog) {
can_test("iprog", FLAG_TESTED);
(void) system(init_prog);
}
put_name(init_3string, " (is3)");
fflush(stdout);
}
void
display_basic(void)
{
put_str("Name: ");
putln(ttytype);
report_cap("\\r ^M (cr)", carriage_return);
report_cap("\\n ^J (ind)", scroll_forward);
report_cap("\\b ^H (cub1)", cursor_left);
report_cap("\\t ^I (ht)", tab);
if (newline) {
report_cap(" (nel)", newline);
}
report_cap(" (clear)", clear_screen);
if (!cursor_home && cursor_address) {
report_cap("(cup) (home)", tparm(cursor_address, 0, 0));
} else {
report_cap(" (home)", cursor_home);
}
#ifdef user9
report_cap("ENQ (u9)", user9);
#endif
#ifdef user8
report_cap("ACK (u8)", user8);
#endif
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);
putln(temp);
}
void
curses_setup(
char *exec_name)
{
int status;
static TERMTYPE term;
char tty_filename[2048];
tty_init();
if ((status = _nc_read_entry(tty_basename, tty_filename, &term)) == 0) {
fprintf(stderr, "Terminal not found: TERM=%s\n", tty_basename);
show_usage(exec_name);
exit(1);
}
if (status == -1) {
fprintf(stderr, "Terminfo database is inaccessible\n");
exit(1);
}
setupterm(tty_basename, 1, &status);
_nc_get_curterm(&cur_term->Nttyb);
tty_baud_rate = baudrate();
tty_cps = (tty_baud_rate << 1) / tty_frame_size;
replace_mode = TRUE;
scan_mode = 0;
char_count = 0;
select_delay_type = debug_level = 0;
char_mask = (meta_on && meta_on[0] == '\0') ? ALLOW_PARITY : STRIP_PARITY;
select_xon_xoff = initial_stty_query(TTY_XON_XOFF) ? 1 : needs_xon_xoff;
fflush(stdout);
tty_set();
go_home();
put_clear();
if (send_reset_init) {
reset_init();
}
fflush(stdout);
sleep(1);
charset_can_test();
can_test("lines cols cr nxon rf if iprog rmp smcup rmcup", FLAG_CAN_TEST);
edit_init();
if (send_reset_init && enter_ca_mode) {
tc_putp(enter_ca_mode);
put_clear();
}
put_crlf();
ptext("Using terminfo from: ");
ptextln(tty_filename);
put_crlf();
if (tty_can_sync == SYNC_NEEDED) {
verify_time();
}
display_basic();
}
void
bye_kids(int n)
{
ignoresig();
if (send_reset_init) {
if (exit_ca_mode) {
tc_putp(exit_ca_mode);
}
if (initial_stty_query(TTY_XON_XOFF)) {
if (enter_xon_mode) {
tc_putp(enter_xon_mode);
}
} else if (exit_xon_mode) {
tc_putp(exit_xon_mode);
}
}
if (debug_fp) {
fclose(debug_fp);
}
if (log_fp) {
fclose(log_fp);
}
tty_reset();
fclose(stdin);
fclose(stdout);
fclose(stderr);
if (not_a_tty)
sleep(1);
exit(n);
}