/* * sig_init -- * Initialize signals. * * PUBLIC: int sig_init(GS *, SCR *); */ int sig_init(GS *gp, SCR *sp) { CL_PRIVATE *clp; clp = GCLP(gp); if (sp == NULL) { (void)sigemptyset(&__sigblockset); if (sigaddset(&__sigblockset, SIGHUP) || setsig(SIGHUP, &clp->oact[INDX_HUP], h_hup) || sigaddset(&__sigblockset, SIGINT) || setsig(SIGINT, &clp->oact[INDX_INT], h_int) || sigaddset(&__sigblockset, SIGTERM) || setsig(SIGTERM, &clp->oact[INDX_TERM], h_term) || sigaddset(&__sigblockset, SIGWINCH) || setsig(SIGWINCH, &clp->oact[INDX_WINCH], h_winch) ) { err(1, NULL); return (1); } } else if (setsig(SIGHUP, NULL, h_hup) || setsig(SIGINT, NULL, h_int) || setsig(SIGTERM, NULL, h_term) || setsig(SIGWINCH, NULL, h_winch) ) { msgq(sp, M_SYSERR, "signal-reset"); } return (0); }
/* * sig_end -- * End signal setup. */ static void sig_end(GS *gp) { CL_PRIVATE *clp; clp = GCLP(gp); (void)sigaction(SIGHUP, NULL, &clp->oact[INDX_HUP]); (void)sigaction(SIGINT, NULL, &clp->oact[INDX_INT]); (void)sigaction(SIGTERM, NULL, &clp->oact[INDX_TERM]); (void)sigaction(SIGWINCH, NULL, &clp->oact[INDX_WINCH]); }
/* * cl_ex_end -- * Shutdown the ex screen. */ static int cl_ex_end(GS *gp) { CL_PRIVATE *clp; clp = GCLP(gp); cl_freecap(clp); return (0); }
/* * cl_quit -- * Shutdown the screens. * * PUBLIC: int cl_quit __P((GS *)); */ int cl_quit(GS *gp) { CL_PRIVATE *clp; int rval; rval = 0; clp = GCLP(gp); /* * If we weren't really running, ignore it. This happens if the * screen changes size before we've called curses. */ if (!F_ISSET(clp, CL_SCR_EX_INIT | CL_SCR_VI_INIT)) return (0); /* Clean up the terminal mappings. */ if (cl_term_end(gp)) rval = 1; /* Really leave vi mode. */ if (F_ISSET(clp, CL_STDIN_TTY) && F_ISSET(clp, CL_SCR_VI_INIT) && cl_vi_end(gp)) rval = 1; /* Really leave ex mode. */ if (F_ISSET(clp, CL_STDIN_TTY) && F_ISSET(clp, CL_SCR_EX_INIT) && cl_ex_end(gp)) rval = 1; /* * If we were running ex when we quit, or we're using an implementation * of curses where endwin() doesn't get this right, restore the original * terminal modes. * * XXX * We always do this because it's too hard to figure out what curses * implementations get it wrong. It may discard type-ahead characters * from the tty queue. */ (void)tcsetattr(STDIN_FILENO, TCSADRAIN | TCSASOFT, &clp->orig); F_CLR(clp, CL_SCR_EX_INIT | CL_SCR_VI_INIT); return (rval); }
/* * cl_vi_end -- * Shutdown the vi screen. */ static int cl_vi_end(GS *gp) { CL_PRIVATE *clp; clp = GCLP(gp); /* Restore the cursor keys to normal mode. */ (void)keypad(stdscr, FALSE); /* * If we were running vi when we quit, scroll the screen up a single * line so we don't lose any information. * * Move to the bottom of the window (some endwin implementations don't * do this for you). */ if (!F_ISSET(clp, CL_IN_EX) && !F_ISSET(gp, G_SRESTART)) { (void)move(0, 0); (void)deleteln(); (void)move(LINES - 1, 0); (void)refresh(); } cl_freecap(clp); /* End curses window. */ (void)endwin(); /* Delete curses screen. */ delscreen(clp->screen); /* * XXX * The screen TE sequence just got sent. See the comment in * cl_funcs.c:cl_attr(). */ clp->ti_te = TE_SENT; return (0); }
/* * sig_init -- * Initialize signals. * * PUBLIC: int sig_init(GS *, SCR *); */ int sig_init(GS *gp, SCR *sp) { CL_PRIVATE *clp; clp = GCLP(gp); if (sp == NULL) { if (setsig(SIGHUP, &clp->oact[INDX_HUP], h_hup) || setsig(SIGINT, &clp->oact[INDX_INT], h_int) || setsig(SIGTERM, &clp->oact[INDX_TERM], h_term) || setsig(SIGWINCH, &clp->oact[INDX_WINCH], h_winch) ) err(1, NULL); } else if (setsig(SIGHUP, NULL, h_hup) || setsig(SIGINT, NULL, h_int) || setsig(SIGTERM, NULL, h_term) || setsig(SIGWINCH, NULL, h_winch) ) { msgq(sp, M_SYSERR, "signal-reset"); } return (0); }