home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume30
/
tin
/
part13
/
signal.c
< prev
Wrap
C/C++ Source or Header
|
1992-05-20
|
8KB
|
557 lines
/*
* Project : tin - a threaded Netnews reader
* Module : signal.c
* Author : I.Lea
* Created : 01-04-91
* Updated : 11-05-92
* Notes : signal handlers for different modes and window resizing
* Copyright : (c) Copyright 1991-92 by Iain Lea
* You may freely copy or redistribute this software,
* so long as there is no profit made from its use, sale
* trade or reproduction. You may not change this copy-
* right notice, and it must be included in any copy made
*/
#include "tin.h"
extern char *glob_art_group;
extern char *glob_group;
extern char *glob_page_group;
extern int glob_respnum;
extern int reread_active_file;
#ifdef SIGTSTP
int do_sigtstp = 0;
#endif
#ifdef POSIX_JOB_CONTROL
/*
* for POSIX systems we know SIGTYPE is void
*/
void (*sigdisp(sig, func))()
int sig;
void (*func)();
{
struct sigaction sa, osa;
sa.sa_handler = func;
sigemptyset (&sa.sa_mask);
sa.sa_flags = 0;
#ifdef SA_RESTART
sa.sa_flags |= SA_RESTART;
#endif
if (sigaction (sig, &sa, &osa) < 0) {
return ((void (*)(int))(-1));
}
return (osa.sa_handler);
}
#else
sigtype_t (*sigdisp(sig, func))()
int sig;
sigtype_t (*func)();
{
return (signal (sig, func));
}
#endif
void set_signal_handlers ()
{
signal (SIGINT, signal_handler); /* ctrl-C */
signal (SIGQUIT, signal_handler); /* ctrl-\ */
signal (SIGILL, signal_handler);
signal (SIGBUS, signal_handler);
signal (SIGSEGV, signal_handler);
signal (SIGPIPE, SIG_IGN);
#ifdef SIGWINCH
if (debug == 2) {
wait_message ("SIGWINCH setting signal...");
sleep (2);
}
signal (SIGWINCH, main_resize);
#endif
#if defined(SIGTSTP) && ! defined(MINIX)
{
sigtype_t (*ptr)();
ptr = signal (SIGTSTP, SIG_DFL);
signal (SIGTSTP, ptr);
if (ptr != SIG_IGN) {
/*
* SIGTSTP is ignored when starting from shells
* without job-control
*/
do_sigtstp = 1;
signal (SIGTSTP, main_suspend);
}
}
#endif
}
void set_alarm_signal ()
{
#ifndef NO_RESYNC_ACTIVE_FILE
/*
* Only reread active file if news is not static (ie. CD-ROM)
*/
if (strcmp (spooldir_alias, "news") == 0) {
signal (SIGALRM, signal_handler);
alarm (RESYNC_ACTIVE_SECS);
}
reread_active_file = FALSE;
#endif
}
void signal_handler (sig)
int sig;
{
char *sigtext;
switch (sig) {
case SIGINT:
if (update) {
sigtext = "SIGINT ";
} else {
signal (SIGINT, signal_handler);
return;
}
break;
case SIGQUIT:
sigtext = "SIGQUIT ";
break;
case SIGBUS:
sigtext = "SIGBUS ";
break;
case SIGSEGV:
sigtext = "SIGSEGV ";
break;
#ifndef NO_RESYNC_ACTIVE_FILE
case SIGALRM:
set_alarm_signal ();
reread_active_file = TRUE;
return;
#endif
default:
sigtext = "";
break;
}
Raw (FALSE);
EndWin ();
fprintf (stderr, "\n%s: signal handler caught signal %s(%d).\n",
progname, sigtext, sig);
if (sig != SIGINT && sig != SIGQUIT) {
fprintf (stderr, "%s: send a bug report to %s\n",
progname, BUG_REPORT_ADDRESS);
}
fflush (stderr);
exit (1);
}
void set_win_size (num_lines, num_cols)
int *num_lines;
int *num_cols;
{
#ifdef TIOCGSIZE
struct ttysize win;
#else
# ifdef TIOCGWINSZ
struct winsize win;
# endif
#endif
init_screen_array (FALSE); /* deallocate screen array */
#ifdef TIOCGSIZE
if (ioctl (0, TIOCGSIZE, &win) == 0) {
if (win.ts_lines != 0) {
*num_lines = win.ts_lines - 1;
}
if (win.ts_cols != 0) {
*num_cols = win.ts_cols;
}
}
#else
# ifdef TIOCGWINSZ
if (ioctl (0, TIOCGWINSZ, &win) == 0) {
if (win.ws_row != 0) {
*num_lines = win.ws_row - 1;
}
if (win.ws_col != 0) {
*num_cols = win.ws_col;
}
}
# endif
#endif
init_screen_array (TRUE); /* allocate screen array for resize */
set_subj_from_size (*num_cols);
RIGHT_POS = *num_cols - 20;
MORE_POS = *num_cols - 15;
NOTESLINES = *num_lines - INDEX_TOP - 1;
if (NOTESLINES <= 0) {
NOTESLINES = 1;
}
}
void set_signals_art ()
{
#ifdef SIGTSTP
if (do_sigtstp) {
sigdisp (SIGTSTP, art_suspend);
}
#endif
#ifdef SIGWINCH
signal (SIGWINCH, art_resize);
#endif
}
void set_signals_group ()
{
#ifdef SIGTSTP
if (do_sigtstp) {
sigdisp (SIGTSTP, group_suspend);
}
#endif
#ifdef SIGWINCH
signal (SIGWINCH, group_resize);
#endif
}
void set_signals_page ()
{
#ifdef SIGTSTP
if (do_sigtstp) {
sigdisp (SIGTSTP, page_suspend);
}
#endif
#ifdef SIGWINCH
signal (SIGWINCH, page_resize);
#endif
}
void set_signals_select ()
{
#ifdef SIGTSTP
if (do_sigtstp) {
sigdisp (SIGTSTP, select_suspend);
}
#endif
#ifdef SIGWINCH
signal (SIGWINCH, select_resize);
#endif
}
void set_signals_spooldir ()
{
#ifdef SIGTSTP
if (do_sigtstp) {
sigdisp (SIGTSTP, spooldir_suspend);
}
#endif
#ifdef SIGWINCH
signal (SIGWINCH, spooldir_resize);
#endif
}
void set_signals_thread ()
{
#ifdef SIGTSTP
if (do_sigtstp) {
sigdisp (SIGTSTP, thread_suspend);
}
#endif
#ifdef SIGWINCH
signal (SIGWINCH, thread_resize);
#endif
}
#ifdef SIGTSTP
/* ARGSUSED0 */
void art_suspend (sig)
int sig;
{
Raw (FALSE);
wait_message (txt_suspended_message);
kill (0, SIGSTOP);
sigdisp (SIGTSTP, art_suspend);
if (! update) {
Raw (TRUE);
art_resize (0);
}
}
/* ARGSUSED0 */
void main_suspend (sig)
int sig;
{
Raw (FALSE);
wait_message (txt_suspended_message);
kill (0, SIGSTOP);
sigdisp (SIGTSTP, main_suspend);
if (! update) {
Raw (TRUE);
main_resize (0);
}
}
/* ARGSUSED0 */
void select_suspend (sig)
int sig;
{
Raw (FALSE);
wait_message (txt_suspended_message);
kill (0, SIGSTOP);
sigdisp (SIGTSTP, select_suspend);
if (! update) {
Raw (TRUE);
}
select_resize (0);
}
/* ARGSUSED0 */
void spooldir_suspend (sig)
int sig;
{
Raw (FALSE);
wait_message (txt_suspended_message);
kill (0, SIGSTOP);
sigdisp (SIGTSTP, spooldir_suspend);
if (! update) {
Raw (TRUE);
}
spooldir_resize (0);
}
/* ARGSUSED0 */
void group_suspend (sig)
int sig;
{
Raw (FALSE);
wait_message (txt_suspended_message);
kill (0, SIGSTOP);
sigdisp (SIGTSTP, group_suspend);
if (! update) {
Raw (TRUE);
}
group_resize (0);
}
/* ARGSUSED0 */
void page_suspend (sig)
int sig;
{
Raw (FALSE);
wait_message (txt_suspended_message);
kill (0, SIGSTOP);
sigdisp (SIGTSTP, page_suspend);
mail_setup ();
if (! update) {
Raw (TRUE);
}
page_resize (0);
}
/* ARGSUSED0 */
void thread_suspend (sig)
int sig;
{
Raw (FALSE);
wait_message (txt_suspended_message);
kill (0, SIGSTOP);
sigdisp (SIGTSTP, thread_suspend);
if (! update) {
Raw (TRUE);
}
thread_resize (0);
}
/* ARGSUSED0 */
void rcfile_suspend (sig)
int sig;
{
Raw (FALSE);
wait_message (txt_suspended_message);
kill (0, SIGSTOP);
sigdisp (SIGTSTP, rcfile_suspend);
Raw (TRUE);
show_rcfile_menu ();
}
#endif /* SIGTSTP */
/* ARGSUSED0 */
void art_resize (sig)
int sig;
{
char buf[LEN];
#ifdef SIGWINCH
set_win_size (&LINES, &COLS);
signal (SIGWINCH, art_resize);
#endif
mail_setup ();
ClearScreen ();
sprintf (buf, txt_group, glob_art_group);
wait_message (buf);
}
/* ARGSUSED0 */
void main_resize (sig)
int sig;
{
#ifdef SIGWINCH
set_win_size (&LINES, &COLS);
signal (SIGWINCH, main_resize);
#endif
mail_setup ();
}
/* ARGSUSED0 */
void select_resize (sig)
int sig;
{
#ifdef SIGWINCH
set_win_size (&LINES, &COLS);
signal (SIGWINCH, select_resize);
#endif
#ifndef USE_CLEARSCREEN
ClearScreen ();
#endif
mail_setup ();
group_selection_page ();
}
/* ARGSUSED0 */
void spooldir_resize (sig)
int sig;
{
#ifdef SIGWINCH
set_win_size (&LINES, &COLS);
signal (SIGWINCH, spooldir_resize);
#endif
#ifndef USE_CLEARSCREEN
ClearScreen ();
#endif
mail_setup ();
show_spooldir_page ();
}
/* ARGSUSED0 */
void group_resize (sig)
int sig;
{
#ifdef SIGWINCH
set_win_size (&LINES, &COLS);
signal (SIGWINCH, group_resize);
#endif
#ifndef USE_CLEARSCREEN
ClearScreen ();
#endif
mail_setup ();
show_group_page (glob_group);
}
/* ARGSUSED0 */
void page_resize (sig)
int sig;
{
#ifdef SIGWINCH
set_win_size (&LINES, &COLS);
signal (SIGWINCH, page_resize);
#endif
#ifndef USE_CLEARSCREEN
ClearScreen ();
#endif
redraw_page (glob_respnum, glob_page_group);
}
/* ARGSUSED0 */
void thread_resize (sig)
int sig;
{
#ifdef SIGWINCH
set_win_size (&LINES, &COLS);
signal (SIGWINCH, thread_resize);
#endif
#ifndef USE_CLEARSCREEN
ClearScreen ();
#endif
mail_setup ();
show_thread_page ();
}