xref: /minix3/external/bsd/nvi/dist/cl/cl_main.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: cl_main.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc  * Copyright (c) 1993, 1994
484d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
584d9c625SLionel Sambuc  * Copyright (c) 1993, 1994, 1995, 1996
684d9c625SLionel Sambuc  *	Keith Bostic.  All rights reserved.
784d9c625SLionel Sambuc  *
884d9c625SLionel Sambuc  * See the LICENSE file for redistribution information.
984d9c625SLionel Sambuc  */
1084d9c625SLionel Sambuc 
1184d9c625SLionel Sambuc #include "config.h"
1284d9c625SLionel Sambuc 
13*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
14*0a6a1f1dSLionel Sambuc #if 0
1584d9c625SLionel Sambuc #ifndef lint
1684d9c625SLionel Sambuc static const char sccsid[] = "Id: cl_main.c,v 10.54 2001/07/29 19:07:27 skimo Exp  (Berkeley) Date: 2001/07/29 19:07:27 ";
1784d9c625SLionel Sambuc #endif /* not lint */
18*0a6a1f1dSLionel Sambuc #else
19*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: cl_main.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
20*0a6a1f1dSLionel Sambuc #endif
2184d9c625SLionel Sambuc 
2284d9c625SLionel Sambuc #include <sys/types.h>
2384d9c625SLionel Sambuc #include <sys/queue.h>
2484d9c625SLionel Sambuc 
2584d9c625SLionel Sambuc #include <bitstring.h>
2684d9c625SLionel Sambuc #include <errno.h>
2784d9c625SLionel Sambuc #include <fcntl.h>
2884d9c625SLionel Sambuc #include <signal.h>
2984d9c625SLionel Sambuc #include <stdio.h>
3084d9c625SLionel Sambuc #include <stdlib.h>
3184d9c625SLionel Sambuc #include <string.h>
3284d9c625SLionel Sambuc #include <termios.h>
3384d9c625SLionel Sambuc #include <unistd.h>
3484d9c625SLionel Sambuc 
3584d9c625SLionel Sambuc #include "../common/common.h"
3684d9c625SLionel Sambuc #include "ip_extern.h"
3784d9c625SLionel Sambuc #include "cl.h"
3884d9c625SLionel Sambuc #include "pathnames.h"
3984d9c625SLionel Sambuc 
4084d9c625SLionel Sambuc GS *__global_list;				/* GLOBAL: List of screens. */
4184d9c625SLionel Sambuc sigset_t __sigblockset;				/* GLOBAL: Blocked signals. */
4284d9c625SLionel Sambuc 
4384d9c625SLionel Sambuc static void	   cl_func_std __P((WIN *));
4484d9c625SLionel Sambuc #ifdef notused
4584d9c625SLionel Sambuc static void	   cl_end __P((CL_PRIVATE *));
4684d9c625SLionel Sambuc #endif
4784d9c625SLionel Sambuc static CL_PRIVATE *cl_init __P((WIN *));
4884d9c625SLionel Sambuc __dead static void	   perr __P((const char *, const char *));
4984d9c625SLionel Sambuc static int	   setsig __P((int, struct sigaction *, void (*)(int)));
5084d9c625SLionel Sambuc static void	   sig_end __P((GS *));
5184d9c625SLionel Sambuc static void	   term_init __P((const char *, const char *));
5284d9c625SLionel Sambuc 
5384d9c625SLionel Sambuc /*
5484d9c625SLionel Sambuc  * main --
5584d9c625SLionel Sambuc  *	This is the main loop for the standalone curses editor.
5684d9c625SLionel Sambuc  */
5784d9c625SLionel Sambuc int
main(int argc,char ** argv)5884d9c625SLionel Sambuc main(int argc, char **argv)
5984d9c625SLionel Sambuc {
6084d9c625SLionel Sambuc 	static int reenter;
6184d9c625SLionel Sambuc 	CL_PRIVATE *clp;
6284d9c625SLionel Sambuc 	GS *gp;
6384d9c625SLionel Sambuc 	WIN *wp;
6484d9c625SLionel Sambuc 	size_t rows, cols;
6584d9c625SLionel Sambuc 	int rval;
6684d9c625SLionel Sambuc 	char **p_av, **t_av;
6784d9c625SLionel Sambuc 	const char *ttype;
6884d9c625SLionel Sambuc 
6984d9c625SLionel Sambuc 	/* If loaded at 0 and jumping through a NULL pointer, stop. */
7084d9c625SLionel Sambuc 	if (reenter++)
7184d9c625SLionel Sambuc 		abort();
7284d9c625SLionel Sambuc 
7384d9c625SLionel Sambuc 	/* Create and initialize the global structure. */
7484d9c625SLionel Sambuc 	__global_list = gp = gs_init(argv[0]);
7584d9c625SLionel Sambuc 
7684d9c625SLionel Sambuc 	/*
7784d9c625SLionel Sambuc 	 * Strip out any arguments that vi isn't going to understand.  There's
7884d9c625SLionel Sambuc 	 * no way to portably call getopt twice, so arguments parsed here must
7984d9c625SLionel Sambuc 	 * be removed from the argument list.
8084d9c625SLionel Sambuc 	 */
8184d9c625SLionel Sambuc 	for (p_av = t_av = argv;;) {
8284d9c625SLionel Sambuc 		if (*t_av == NULL) {
8384d9c625SLionel Sambuc 			*p_av = NULL;
8484d9c625SLionel Sambuc 			break;
8584d9c625SLionel Sambuc 		}
8684d9c625SLionel Sambuc 		if (!strcmp(*t_av, "--")) {
8784d9c625SLionel Sambuc 			while ((*p_av++ = *t_av++) != NULL);
8884d9c625SLionel Sambuc 			break;
8984d9c625SLionel Sambuc 		}
9084d9c625SLionel Sambuc 		*p_av++ = *t_av++;
9184d9c625SLionel Sambuc 	}
9284d9c625SLionel Sambuc 
9384d9c625SLionel Sambuc 	/* Create new window */
9484d9c625SLionel Sambuc 	wp = gs_new_win(gp);
9584d9c625SLionel Sambuc 
9684d9c625SLionel Sambuc 	/* Create and initialize the CL_PRIVATE structure. */
9784d9c625SLionel Sambuc 	clp = cl_init(wp);
9884d9c625SLionel Sambuc 
9984d9c625SLionel Sambuc 	/*
10084d9c625SLionel Sambuc 	 * Initialize the terminal information.
10184d9c625SLionel Sambuc 	 *
10284d9c625SLionel Sambuc 	 * We have to know what terminal it is from the start, since we may
10384d9c625SLionel Sambuc 	 * have to use termcap/terminfo to find out how big the screen is.
10484d9c625SLionel Sambuc 	 */
10584d9c625SLionel Sambuc 	if ((ttype = getenv("TERM")) == NULL) {
10684d9c625SLionel Sambuc 		if (isatty(STDIN_FILENO))
10784d9c625SLionel Sambuc 			fprintf(stderr, "%s: warning: TERM is not set\n",
10884d9c625SLionel Sambuc 			    gp->progname);
10984d9c625SLionel Sambuc 		ttype = "unknown";
11084d9c625SLionel Sambuc 	}
11184d9c625SLionel Sambuc 	term_init(gp->progname, ttype);
11284d9c625SLionel Sambuc 
11384d9c625SLionel Sambuc 	/* Add the terminal type to the global structure. */
11484d9c625SLionel Sambuc 	if ((OG_D_STR(gp, GO_TERM) =
11584d9c625SLionel Sambuc 	    OG_STR(gp, GO_TERM) = strdup(ttype)) == NULL)
11684d9c625SLionel Sambuc 		perr(gp->progname, NULL);
11784d9c625SLionel Sambuc 
11884d9c625SLionel Sambuc 	/* Figure out how big the screen is. */
11984d9c625SLionel Sambuc 	if (cl_ssize(NULL, 0, &rows, &cols, NULL))
12084d9c625SLionel Sambuc 		exit (1);
12184d9c625SLionel Sambuc 
12284d9c625SLionel Sambuc 	/* Add the rows and columns to the global structure. */
12384d9c625SLionel Sambuc 	OG_VAL(gp, GO_LINES) = OG_D_VAL(gp, GO_LINES) = rows;
12484d9c625SLionel Sambuc 	OG_VAL(gp, GO_COLUMNS) = OG_D_VAL(gp, GO_COLUMNS) = cols;
12584d9c625SLionel Sambuc 
12684d9c625SLionel Sambuc 	/* Ex wants stdout to be buffered. */
12784d9c625SLionel Sambuc 	(void)setvbuf(stdout, NULL, _IOFBF, 0);
12884d9c625SLionel Sambuc 
12984d9c625SLionel Sambuc 	/* Start catching signals. */
13084d9c625SLionel Sambuc 	if (sig_init(gp, NULL))
13184d9c625SLionel Sambuc 		exit (1);
13284d9c625SLionel Sambuc 
13384d9c625SLionel Sambuc 	/* Run ex/vi. */
13484d9c625SLionel Sambuc 	rval = editor(wp, argc, argv);
13584d9c625SLionel Sambuc 
13684d9c625SLionel Sambuc 	/* Clean out the global structure. */
13784d9c625SLionel Sambuc 	gs_end(gp);
13884d9c625SLionel Sambuc 
13984d9c625SLionel Sambuc 	/* Clean up signals. */
14084d9c625SLionel Sambuc 	sig_end(gp);
14184d9c625SLionel Sambuc 
14284d9c625SLionel Sambuc 	/* Clean up the terminal. */
14384d9c625SLionel Sambuc 	(void)cl_quit(gp);
14484d9c625SLionel Sambuc 
14584d9c625SLionel Sambuc 	/*
14684d9c625SLionel Sambuc 	 * XXX
14784d9c625SLionel Sambuc 	 * Reset the O_MESG option.
14884d9c625SLionel Sambuc 	 */
14984d9c625SLionel Sambuc 	if (clp->tgw != TGW_UNKNOWN)
15084d9c625SLionel Sambuc 		(void)cl_omesg(NULL, clp, clp->tgw == TGW_SET);
15184d9c625SLionel Sambuc 
15284d9c625SLionel Sambuc 	/*
15384d9c625SLionel Sambuc 	 * XXX
15484d9c625SLionel Sambuc 	 * Reset the X11 xterm icon/window name.
15584d9c625SLionel Sambuc 	 */
15684d9c625SLionel Sambuc 	if (F_ISSET(clp, CL_RENAME))
15784d9c625SLionel Sambuc 		cl_setname(gp, clp->oname);
15884d9c625SLionel Sambuc 
15984d9c625SLionel Sambuc 	/* If a killer signal arrived, pretend we just got it. */
16084d9c625SLionel Sambuc 	if (clp->killersig) {
16184d9c625SLionel Sambuc 		(void)signal(clp->killersig, SIG_DFL);
16284d9c625SLionel Sambuc 		(void)kill(getpid(), clp->killersig);
16384d9c625SLionel Sambuc 		/* NOTREACHED */
16484d9c625SLionel Sambuc 	}
16584d9c625SLionel Sambuc 
16684d9c625SLionel Sambuc 	/* Free the global and CL private areas. */
16784d9c625SLionel Sambuc #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
16884d9c625SLionel Sambuc 	cl_end(clp);
16984d9c625SLionel Sambuc 	free(gp);
17084d9c625SLionel Sambuc #endif
17184d9c625SLionel Sambuc 
17284d9c625SLionel Sambuc 	exit (rval);
17384d9c625SLionel Sambuc }
17484d9c625SLionel Sambuc 
17584d9c625SLionel Sambuc /*
17684d9c625SLionel Sambuc  * cl_init --
17784d9c625SLionel Sambuc  *	Create and partially initialize the CL structure.
17884d9c625SLionel Sambuc  */
17984d9c625SLionel Sambuc static CL_PRIVATE *
cl_init(WIN * wp)18084d9c625SLionel Sambuc cl_init(WIN *wp)
18184d9c625SLionel Sambuc {
18284d9c625SLionel Sambuc 	CL_PRIVATE *clp;
18384d9c625SLionel Sambuc 	int fd;
18484d9c625SLionel Sambuc 	GS *gp;
18584d9c625SLionel Sambuc 
18684d9c625SLionel Sambuc 	gp = wp->gp;
18784d9c625SLionel Sambuc 
18884d9c625SLionel Sambuc 	/* Allocate the CL private structure. */
18984d9c625SLionel Sambuc 	CALLOC_NOMSG(NULL, clp, CL_PRIVATE *, 1, sizeof(CL_PRIVATE));
19084d9c625SLionel Sambuc 	if (clp == NULL)
19184d9c625SLionel Sambuc 		perr(gp->progname, NULL);
19284d9c625SLionel Sambuc 	gp->cl_private = clp;
19384d9c625SLionel Sambuc 
19484d9c625SLionel Sambuc 	/*
19584d9c625SLionel Sambuc 	 * Set the CL_STDIN_TTY flag.  It's purpose is to avoid setting
19684d9c625SLionel Sambuc 	 * and resetting the tty if the input isn't from there.  We also
19784d9c625SLionel Sambuc 	 * use the same test to determine if we're running a script or
19884d9c625SLionel Sambuc 	 * not.
19984d9c625SLionel Sambuc 	 */
20084d9c625SLionel Sambuc 	if (isatty(STDIN_FILENO))
20184d9c625SLionel Sambuc 		F_SET(clp, CL_STDIN_TTY);
20284d9c625SLionel Sambuc 	else
20384d9c625SLionel Sambuc 		F_SET(gp, G_SCRIPTED);
20484d9c625SLionel Sambuc 
20584d9c625SLionel Sambuc 	/*
20684d9c625SLionel Sambuc 	 * We expect that if we've lost our controlling terminal that the
20784d9c625SLionel Sambuc 	 * open() (but not the tcgetattr()) will fail.
20884d9c625SLionel Sambuc 	 */
20984d9c625SLionel Sambuc 	if (F_ISSET(clp, CL_STDIN_TTY)) {
21084d9c625SLionel Sambuc 		if (tcgetattr(STDIN_FILENO, &clp->orig) == -1)
21184d9c625SLionel Sambuc 			goto tcfail;
21284d9c625SLionel Sambuc 	} else if ((fd = open(_PATH_TTY, O_RDONLY, 0)) != -1) {
21384d9c625SLionel Sambuc 		if (tcgetattr(fd, &clp->orig) == -1) {
21484d9c625SLionel Sambuc tcfail:			perr(gp->progname, "tcgetattr");
21584d9c625SLionel Sambuc 			exit (1);
21684d9c625SLionel Sambuc 		}
21784d9c625SLionel Sambuc 		(void)close(fd);
21884d9c625SLionel Sambuc 	}
21984d9c625SLionel Sambuc 
22084d9c625SLionel Sambuc 	/* Initialize the list of curses functions. */
22184d9c625SLionel Sambuc 	cl_func_std(wp);
22284d9c625SLionel Sambuc 
22384d9c625SLionel Sambuc 	return (clp);
22484d9c625SLionel Sambuc }
22584d9c625SLionel Sambuc 
22684d9c625SLionel Sambuc #ifdef notused
22784d9c625SLionel Sambuc /*
22884d9c625SLionel Sambuc  * cl_end --
22984d9c625SLionel Sambuc  *	Discard the CL structure.
23084d9c625SLionel Sambuc  */
23184d9c625SLionel Sambuc static void
cl_end(CL_PRIVATE * clp)23284d9c625SLionel Sambuc cl_end(CL_PRIVATE *clp)
23384d9c625SLionel Sambuc {
23484d9c625SLionel Sambuc 	if (clp->oname != NULL)
23584d9c625SLionel Sambuc 		free(clp->oname);
23684d9c625SLionel Sambuc 	free(clp);
23784d9c625SLionel Sambuc }
23884d9c625SLionel Sambuc #endif
23984d9c625SLionel Sambuc 
24084d9c625SLionel Sambuc /*
24184d9c625SLionel Sambuc  * term_init --
24284d9c625SLionel Sambuc  *	Initialize terminal information.
24384d9c625SLionel Sambuc  */
24484d9c625SLionel Sambuc static void
term_init(const char * name,const char * ttype)24584d9c625SLionel Sambuc term_init(const char *name, const char *ttype)
24684d9c625SLionel Sambuc {
247*0a6a1f1dSLionel Sambuc 	int error;
24884d9c625SLionel Sambuc 
24984d9c625SLionel Sambuc 	/* Set up the terminal database information. */
250*0a6a1f1dSLionel Sambuc 	setupterm(__UNCONST(ttype), STDOUT_FILENO, &error);
251*0a6a1f1dSLionel Sambuc 	switch (error) {
25284d9c625SLionel Sambuc 	case -1:
25384d9c625SLionel Sambuc 		(void)fprintf(stderr,
25484d9c625SLionel Sambuc 		    "%s: No terminal database found\n", name);
25584d9c625SLionel Sambuc 		exit (1);
25684d9c625SLionel Sambuc 	case 0:
25784d9c625SLionel Sambuc 		(void)fprintf(stderr,
25884d9c625SLionel Sambuc 		    "%s: %s: unknown terminal type\n", name, ttype);
25984d9c625SLionel Sambuc 		exit (1);
26084d9c625SLionel Sambuc 	}
26184d9c625SLionel Sambuc }
26284d9c625SLionel Sambuc 
26384d9c625SLionel Sambuc #define	GLOBAL_CLP \
26484d9c625SLionel Sambuc 	CL_PRIVATE *clp = GCLP(__global_list);
26584d9c625SLionel Sambuc static void
h_hup(int signo)26684d9c625SLionel Sambuc h_hup(int signo)
26784d9c625SLionel Sambuc {
26884d9c625SLionel Sambuc 	GLOBAL_CLP;
26984d9c625SLionel Sambuc 
27084d9c625SLionel Sambuc 	F_SET(clp, CL_SIGHUP);
27184d9c625SLionel Sambuc 	clp->killersig = SIGHUP;
27284d9c625SLionel Sambuc }
27384d9c625SLionel Sambuc 
27484d9c625SLionel Sambuc static void
h_int(int signo)27584d9c625SLionel Sambuc h_int(int signo)
27684d9c625SLionel Sambuc {
27784d9c625SLionel Sambuc 	GLOBAL_CLP;
27884d9c625SLionel Sambuc 
27984d9c625SLionel Sambuc 	F_SET(clp, CL_SIGINT);
28084d9c625SLionel Sambuc }
28184d9c625SLionel Sambuc 
28284d9c625SLionel Sambuc static void
h_term(int signo)28384d9c625SLionel Sambuc h_term(int signo)
28484d9c625SLionel Sambuc {
28584d9c625SLionel Sambuc 	GLOBAL_CLP;
28684d9c625SLionel Sambuc 
28784d9c625SLionel Sambuc 	F_SET(clp, CL_SIGTERM);
28884d9c625SLionel Sambuc 	clp->killersig = SIGTERM;
28984d9c625SLionel Sambuc }
29084d9c625SLionel Sambuc 
29184d9c625SLionel Sambuc static void
h_winch(int signo)29284d9c625SLionel Sambuc h_winch(int signo)
29384d9c625SLionel Sambuc {
29484d9c625SLionel Sambuc 	GLOBAL_CLP;
29584d9c625SLionel Sambuc 
29684d9c625SLionel Sambuc 	F_SET(clp, CL_SIGWINCH);
29784d9c625SLionel Sambuc }
29884d9c625SLionel Sambuc #undef	GLOBAL_CLP
29984d9c625SLionel Sambuc 
30084d9c625SLionel Sambuc /*
30184d9c625SLionel Sambuc  * sig_init --
30284d9c625SLionel Sambuc  *	Initialize signals.
30384d9c625SLionel Sambuc  *
30484d9c625SLionel Sambuc  * PUBLIC: int sig_init __P((GS *, SCR *));
30584d9c625SLionel Sambuc  */
30684d9c625SLionel Sambuc int
sig_init(GS * gp,SCR * sp)30784d9c625SLionel Sambuc sig_init(GS *gp, SCR *sp)
30884d9c625SLionel Sambuc {
30984d9c625SLionel Sambuc 	CL_PRIVATE *clp;
31084d9c625SLionel Sambuc 
31184d9c625SLionel Sambuc 	clp = GCLP(gp);
31284d9c625SLionel Sambuc 
31384d9c625SLionel Sambuc 	if (sp == NULL) {
31484d9c625SLionel Sambuc 		(void)sigemptyset(&__sigblockset);
31584d9c625SLionel Sambuc 		if (sigaddset(&__sigblockset, SIGHUP) ||
31684d9c625SLionel Sambuc 		    setsig(SIGHUP, &clp->oact[INDX_HUP], h_hup) ||
31784d9c625SLionel Sambuc 		    sigaddset(&__sigblockset, SIGINT) ||
31884d9c625SLionel Sambuc 		    setsig(SIGINT, &clp->oact[INDX_INT], h_int) ||
31984d9c625SLionel Sambuc 		    sigaddset(&__sigblockset, SIGTERM) ||
32084d9c625SLionel Sambuc 		    setsig(SIGTERM, &clp->oact[INDX_TERM], h_term)
32184d9c625SLionel Sambuc #ifdef SIGWINCH
32284d9c625SLionel Sambuc 		    ||
32384d9c625SLionel Sambuc 		    sigaddset(&__sigblockset, SIGWINCH) ||
32484d9c625SLionel Sambuc 		    setsig(SIGWINCH, &clp->oact[INDX_WINCH], h_winch)
32584d9c625SLionel Sambuc #endif
32684d9c625SLionel Sambuc 		    ) {
32784d9c625SLionel Sambuc 			perr(gp->progname, NULL);
32884d9c625SLionel Sambuc 			return (1);
32984d9c625SLionel Sambuc 		}
33084d9c625SLionel Sambuc 	} else
33184d9c625SLionel Sambuc 		if (setsig(SIGHUP, NULL, h_hup) ||
33284d9c625SLionel Sambuc 		    setsig(SIGINT, NULL, h_int) ||
33384d9c625SLionel Sambuc 		    setsig(SIGTERM, NULL, h_term)
33484d9c625SLionel Sambuc #ifdef SIGWINCH
33584d9c625SLionel Sambuc 		    ||
33684d9c625SLionel Sambuc 		    setsig(SIGWINCH, NULL, h_winch)
33784d9c625SLionel Sambuc #endif
33884d9c625SLionel Sambuc 		    ) {
33984d9c625SLionel Sambuc 			msgq(sp, M_SYSERR, "signal-reset");
34084d9c625SLionel Sambuc 		}
34184d9c625SLionel Sambuc 	return (0);
34284d9c625SLionel Sambuc }
34384d9c625SLionel Sambuc 
34484d9c625SLionel Sambuc /*
34584d9c625SLionel Sambuc  * setsig --
34684d9c625SLionel Sambuc  *	Set a signal handler.
34784d9c625SLionel Sambuc  */
34884d9c625SLionel Sambuc static int
setsig(int signo,struct sigaction * oactp,void (* handler)(int))34984d9c625SLionel Sambuc setsig(int signo, struct sigaction *oactp, void (*handler) (int))
35084d9c625SLionel Sambuc {
35184d9c625SLionel Sambuc 	struct sigaction act;
35284d9c625SLionel Sambuc 
35384d9c625SLionel Sambuc 	/*
35484d9c625SLionel Sambuc 	 * Use sigaction(2), not signal(3), since we don't always want to
35584d9c625SLionel Sambuc 	 * restart system calls.  The example is when waiting for a command
35684d9c625SLionel Sambuc 	 * mode keystroke and SIGWINCH arrives.  Besides, you can't portably
35784d9c625SLionel Sambuc 	 * restart system calls (thanks, POSIX!).  On the other hand, you
35884d9c625SLionel Sambuc 	 * can't portably NOT restart system calls (thanks, Sun!).  SunOS
35984d9c625SLionel Sambuc 	 * used SA_INTERRUPT as their extension to NOT restart read calls.
36084d9c625SLionel Sambuc 	 * We sure hope nobody else used it for anything else.  Mom told me
36184d9c625SLionel Sambuc 	 * there'd be days like this.  She just never told me that there'd
36284d9c625SLionel Sambuc 	 * be so many.
36384d9c625SLionel Sambuc 	 */
36484d9c625SLionel Sambuc 	act.sa_handler = handler;
36584d9c625SLionel Sambuc 	sigemptyset(&act.sa_mask);
36684d9c625SLionel Sambuc 
36784d9c625SLionel Sambuc #ifdef SA_INTERRUPT
36884d9c625SLionel Sambuc 	act.sa_flags = SA_INTERRUPT;
36984d9c625SLionel Sambuc #else
37084d9c625SLionel Sambuc 	act.sa_flags = 0;
37184d9c625SLionel Sambuc #endif
37284d9c625SLionel Sambuc 	return (sigaction(signo, &act, oactp));
37384d9c625SLionel Sambuc }
37484d9c625SLionel Sambuc 
37584d9c625SLionel Sambuc /*
37684d9c625SLionel Sambuc  * sig_end --
37784d9c625SLionel Sambuc  *	End signal setup.
37884d9c625SLionel Sambuc  */
37984d9c625SLionel Sambuc static void
sig_end(GS * gp)38084d9c625SLionel Sambuc sig_end(GS *gp)
38184d9c625SLionel Sambuc {
38284d9c625SLionel Sambuc 	CL_PRIVATE *clp;
38384d9c625SLionel Sambuc 
38484d9c625SLionel Sambuc 	clp = GCLP(gp);
38584d9c625SLionel Sambuc 	(void)sigaction(SIGHUP, NULL, &clp->oact[INDX_HUP]);
38684d9c625SLionel Sambuc 	(void)sigaction(SIGINT, NULL, &clp->oact[INDX_INT]);
38784d9c625SLionel Sambuc 	(void)sigaction(SIGTERM, NULL, &clp->oact[INDX_TERM]);
38884d9c625SLionel Sambuc #ifdef SIGWINCH
38984d9c625SLionel Sambuc 	(void)sigaction(SIGWINCH, NULL, &clp->oact[INDX_WINCH]);
39084d9c625SLionel Sambuc #endif
39184d9c625SLionel Sambuc }
39284d9c625SLionel Sambuc 
39384d9c625SLionel Sambuc /*
39484d9c625SLionel Sambuc  * cl_func_std --
39584d9c625SLionel Sambuc  *	Initialize the standard curses functions.
39684d9c625SLionel Sambuc  */
39784d9c625SLionel Sambuc static void
cl_func_std(WIN * wp)39884d9c625SLionel Sambuc cl_func_std(WIN *wp)
39984d9c625SLionel Sambuc {
40084d9c625SLionel Sambuc 	GS *gp;
40184d9c625SLionel Sambuc 
40284d9c625SLionel Sambuc 	gp = wp->gp;
40384d9c625SLionel Sambuc 
40484d9c625SLionel Sambuc 	gp->scr_addstr = cl_addstr;
40584d9c625SLionel Sambuc 	gp->scr_waddstr = cl_waddstr;
40684d9c625SLionel Sambuc 	gp->scr_attr = cl_attr;
40784d9c625SLionel Sambuc 	gp->scr_baud = cl_baud;
40884d9c625SLionel Sambuc 	gp->scr_bell = cl_bell;
40984d9c625SLionel Sambuc 	gp->scr_busy = NULL;
41084d9c625SLionel Sambuc 	gp->scr_child = NULL;
41184d9c625SLionel Sambuc 	gp->scr_clrtoeol = cl_clrtoeol;
41284d9c625SLionel Sambuc 	gp->scr_cursor = cl_cursor;
41384d9c625SLionel Sambuc 	gp->scr_deleteln = cl_deleteln;
41484d9c625SLionel Sambuc 	gp->scr_reply = NULL;
41584d9c625SLionel Sambuc 	gp->scr_discard = cl_discard;
41684d9c625SLionel Sambuc 	gp->scr_event = cl_event;
41784d9c625SLionel Sambuc 	gp->scr_ex_adjust = cl_ex_adjust;
41884d9c625SLionel Sambuc 	gp->scr_fmap = cl_fmap;
41984d9c625SLionel Sambuc 	gp->scr_insertln = cl_insertln;
42084d9c625SLionel Sambuc 	gp->scr_keyval = cl_keyval;
42184d9c625SLionel Sambuc 	gp->scr_move = cl_move;
42284d9c625SLionel Sambuc 	wp->scr_msg = NULL;
42384d9c625SLionel Sambuc 	gp->scr_optchange = cl_optchange;
42484d9c625SLionel Sambuc 	gp->scr_refresh = cl_refresh;
42584d9c625SLionel Sambuc 	gp->scr_rename = cl_rename;
42684d9c625SLionel Sambuc 	gp->scr_screen = cl_screen;
42784d9c625SLionel Sambuc 	gp->scr_split = cl_split;
42884d9c625SLionel Sambuc 	gp->scr_suspend = cl_suspend;
42984d9c625SLionel Sambuc 	gp->scr_usage = cl_usage;
43084d9c625SLionel Sambuc }
43184d9c625SLionel Sambuc 
43284d9c625SLionel Sambuc /*
43384d9c625SLionel Sambuc  * perr --
43484d9c625SLionel Sambuc  *	Print system error.
43584d9c625SLionel Sambuc  */
43684d9c625SLionel Sambuc static void
perr(const char * name,const char * msg)43784d9c625SLionel Sambuc perr(const char *name, const char *msg)
43884d9c625SLionel Sambuc {
43984d9c625SLionel Sambuc 	(void)fprintf(stderr, "%s:", name);
44084d9c625SLionel Sambuc 	if (msg != NULL)
44184d9c625SLionel Sambuc 		(void)fprintf(stderr, "%s:", msg);
44284d9c625SLionel Sambuc 	(void)fprintf(stderr, "%s\n", strerror(errno));
44384d9c625SLionel Sambuc 	exit(1);
44484d9c625SLionel Sambuc }
445