/* * Suspend / Resume */ static errr Term_xtra_sla_alive(int v) { /* Suspend */ if (!v) { /* Oops */ if (!slang_on) return (1); /* We are now off */ slang_on = FALSE; /* Block further signals, so double signals wont confuse us */ SLsig_block_signals(); /* Shut down (temporarily) */ if (SLsmg_suspend_smg() < 0) quit("Could not save S-Lang state"); SLang_reset_tty(); /* Done with blocking */ SLsig_unblock_signals(); } /* Resume */ else { /* Oops */ if (slang_on) return (1); /* Block further signals, so double signals wont confuse us */ SLsig_block_signals(); /* Initialize, check for errors */ if (SLang_init_tty(-1, TRUE, 0) == -1) quit("S-Lang re-initialization failed"); #ifdef HANDLE_SIGNALS /* Allow keyboard generated suspend signal (on Unix, ^Z) */ SLtty_set_suspend_state(TRUE); #endif /* Restore the and screen and screen management state */ if (SLsmg_resume_smg() == -1) { SLang_reset_tty(); quit("Could not get back virtual display memory"); } /* Done with blocking */ SLsig_unblock_signals(); /* Note that we are on */ slang_on = TRUE; } /* Success */ return (0); }
static int init_tty (int suspend_ok) { if (-1 == SLang_init_tty (-1, 1, 0)) return -1; #ifdef REAL_UNIX_SYSTEM if (suspend_ok) SLtty_set_suspend_state (1); #endif return 0; }
static void init_tty (void) { int abort_char = 3; TTY_Inited++; if (TTY_Inited > 1) return; # if SYSTEM_SUPPORTS_SIGNALS SLsig_block_signals (); SLang_TT_Read_FD = fileno (stdin); init_sigtstp (); # endif # ifdef REAL_UNIX_SYSTEM abort_char = -1; /* determine from tty */ # endif if (-1 == SLang_init_tty (abort_char, 1, 1)) /* opost was 0 */ { # if SYSTEM_SUPPORTS_SIGNALS deinit_sigtstp (); SLsig_unblock_signals (); # endif SLang_exit_error ("Error initializing terminal."); } # ifdef REAL_UNIX_SYSTEM SLang_getkey_intr_hook = getkey_intr_hook; # endif (void) add_sigwinch_handlers (); SLtt_get_screen_size (); # if SYSTEM_SUPPORTS_SIGNALS SLtty_set_suspend_state (1); SLsig_unblock_signals (); # endif }
static void init_tty (void) /*{{{*/ { #ifdef HAVE_GNU_READLINE if (Use_SLang_Readline == 0) { SLsig_block_signals (); last_sig_sigint = SLsignal (SIGINT, gnu_rl_sigint_handler); last_sig_sigtstp = SLsignal (SIGTSTP, sig_sigtstp); SLsig_unblock_signals (); return; } #endif if (TTY_Inited) return; TTY_Inited++; SLsig_block_signals (); SLang_TT_Read_FD = fileno (stdin); last_sig_sigtstp = SLsignal (SIGTSTP, sig_sigtstp); if (-1 == SLang_init_tty (-1, 1, 0)) { SLsignal (SIGTSTP, last_sig_sigtstp); SLsig_unblock_signals (); fprintf (stderr, "Error initializing terminal."); exit (EXIT_FAILURE); } SLang_getkey_intr_hook = getkey_intr_hook; (void) add_sigwinch_handlers (); SLtt_get_screen_size (); SLtty_set_suspend_state (1); SLsig_unblock_signals (); }
/* * Prepare "S-Lang" for use by the file "z-term.c" * Installs the "hook" functions defined above */ errr init_sla(int argc, char **argv) { int err; term *t = &term_screen_body; /* Unused parameters */ (void)argc; (void)argv; /* Block signals, so signals cannot confuse the setup */ SLsig_block_signals(); /* Initialize, check for errors */ err = (SLang_init_tty(-1, TRUE, 0) == -1); /* Quit on error */ if (err) quit("SLang initialization failed"); /* Get terminal info */ SLtt_get_terminfo(); #ifdef HANDLE_SIGNALS /* Allow keyboard generated suspend signal (on Unix, ^Z) */ SLtty_set_suspend_state(TRUE); /* Instead of signal(), use sigaction():SA_RESTART via SLsignal() */ signal_aux = SLsignal; #endif /* Initialize some more */ if (SLsmg_init_smg() == -1) { SLang_reset_tty(); quit("Could not get virtual display memory"); } /* Check we have enough screen. */ err = ((SLtt_Screen_Rows < 24) || (SLtt_Screen_Cols < 80)); /* Quit with message */ if (err) { SLsmg_reset_smg(); SLang_reset_tty(); quit("SLang screen must be at least 80x24"); } /* Now let's go for a little bit of color! */ err = !has_colors(); /* Do we have color available? */ can_use_color = !err; /* Init the Color-pairs and set up a translation table */ /* If the terminal has enough colors */ /* Color-pair 0 is *always* WHITE on BLACK */ /* XXX XXX XXX See "main-gcu.c" for proper method */ /* Only do this on color machines */ if (can_use_color) { /* Prepare the color pairs */ init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_BLACK, COLOR_BLACK); init_pair(9, COLOR_BRED, COLOR_BLACK); init_pair(10, COLOR_BGREEN, COLOR_BLACK); init_pair(11, COLOR_BYELLOW, COLOR_BLACK); init_pair(12, COLOR_BBLUE, COLOR_BLACK); init_pair(13, COLOR_BMAGENTA, COLOR_BLACK); init_pair(14, COLOR_BCYAN, COLOR_BLACK); init_pair(15, COLOR_BBLACK, COLOR_BLACK); /* Prepare the color table */ colortable[0] = 7; /* Black */ colortable[1] = 0; /* White */ colortable[2] = 6; /* Grey XXX */ colortable[3] = 11; /* Orange XXX */ colortable[4] = 1; /* Red */ colortable[5] = 2; /* Green */ colortable[6] = 4; /* Blue */ colortable[7] = 3; /* Brown */ colortable[8] = 15; /* Dark-grey XXX */ colortable[9] = 14; /* Light-grey XXX */ colortable[10] = 5; /* Purple */ colortable[11] = 11; /* Yellow */ colortable[12] = 9; /* Light Red */ colortable[13] = 10; /* Light Green */ colortable[14] = 12; /* Light Blue */ colortable[15] = 3; /* Light Brown XXX */ } /* Done with blocking */ SLsig_unblock_signals(); /* Initialize the term */ term_init(t, 80, 24, 64); /* Stick in some hooks */ t->nuke_hook = Term_nuke_sla; t->init_hook = Term_init_sla; /* Stick in some more hooks */ t->xtra_hook = Term_xtra_sla; t->curs_hook = Term_curs_sla; t->wipe_hook = Term_wipe_sla; t->text_hook = Term_text_sla; /* Save the term */ term_screen = t; /* Activate it */ Term_activate(t); /* Success */ return 0; }