head	1.1;
branch	1.1.1;
access;
symbols
	perseant-exfatfs-base-20250801:1.1.1.2
	perseant-exfatfs-base-20240630:1.1.1.2
	perseant-exfatfs:1.1.1.2.0.46
	perseant-exfatfs-base:1.1.1.2
	cjep_sun2x:1.1.1.2.0.44
	cjep_sun2x-base:1.1.1.2
	cjep_staticlib_x-base1:1.1.1.2
	cjep_staticlib_x:1.1.1.2.0.42
	cjep_staticlib_x-base:1.1.1.2
	phil-wifi-20200421:1.1.1.2
	phil-wifi-20200411:1.1.1.2
	phil-wifi-20200406:1.1.1.2
	pgoyette-compat-merge-20190127:1.1.1.2
	pgoyette-compat-20190127:1.1.1.2
	pgoyette-compat-20190118:1.1.1.2
	pgoyette-compat-1226:1.1.1.2
	pgoyette-compat-1126:1.1.1.2
	pgoyette-compat-1020:1.1.1.2
	pgoyette-compat-0930:1.1.1.2
	pgoyette-compat-0906:1.1.1.2
	pgoyette-compat-0728:1.1.1.2
	pgoyette-compat-0625:1.1.1.2
	pgoyette-compat-0521:1.1.1.2
	pgoyette-compat-0502:1.1.1.2
	pgoyette-compat-0422:1.1.1.2
	pgoyette-compat-0415:1.1.1.2
	pgoyette-compat-0407:1.1.1.2
	pgoyette-compat-0330:1.1.1.2
	pgoyette-compat-0322:1.1.1.2
	pgoyette-compat-0315:1.1.1.2
	pgoyette-compat:1.1.1.2.0.40
	pgoyette-compat-base:1.1.1.2
	perseant-stdc-iso10646:1.1.1.2.0.38
	perseant-stdc-iso10646-base:1.1.1.2
	prg-localcount2-base3:1.1.1.2
	prg-localcount2-base2:1.1.1.2
	prg-localcount2-base1:1.1.1.2
	prg-localcount2:1.1.1.2.0.36
	prg-localcount2-base:1.1.1.2
	pgoyette-localcount-20170426:1.1.1.2
	bouyer-socketcan-base1:1.1.1.2
	pgoyette-localcount-20170320:1.1.1.2
	bouyer-socketcan:1.1.1.2.0.34
	bouyer-socketcan-base:1.1.1.2
	pgoyette-localcount-20170107:1.1.1.2
	pgoyette-localcount-20161104:1.1.1.2
	localcount-20160914:1.1.1.2
	pgoyette-localcount-20160806:1.1.1.2
	pgoyette-localcount-20160726:1.1.1.2
	pgoyette-localcount:1.1.1.2.0.32
	pgoyette-localcount-base:1.1.1.2
	netbsd-5-2-3-RELEASE:1.1.1.2
	netbsd-5-1-5-RELEASE:1.1.1.2
	yamt-pagecache-base9:1.1.1.2
	yamt-pagecache-tag8:1.1.1.2
	tls-earlyentropy:1.1.1.2.0.28
	tls-earlyentropy-base:1.1.1.2
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.2
	riastradh-drm2-base3:1.1.1.2
	netbsd-5-2-2-RELEASE:1.1.1.2
	netbsd-5-1-4-RELEASE:1.1.1.2
	netbsd-5-2-1-RELEASE:1.1.1.2
	netbsd-5-1-3-RELEASE:1.1.1.2
	agc-symver:1.1.1.2.0.30
	agc-symver-base:1.1.1.2
	tls-maxphys-base:1.1.1.2
	yamt-pagecache-base8:1.1.1.2
	netbsd-5-2:1.1.1.2.0.26
	yamt-pagecache-base7:1.1.1.2
	netbsd-5-2-RELEASE:1.1.1.2
	netbsd-5-2-RC1:1.1.1.2
	yamt-pagecache-base6:1.1.1.2
	yamt-pagecache-base5:1.1.1.2
	yamt-pagecache-base4:1.1.1.2
	netbsd-5-1-2-RELEASE:1.1.1.2
	netbsd-5-1-1-RELEASE:1.1.1.2
	yamt-pagecache-base3:1.1.1.2
	yamt-pagecache-base2:1.1.1.2
	yamt-pagecache:1.1.1.2.0.24
	yamt-pagecache-base:1.1.1.2
	bouyer-quota2-nbase:1.1.1.2
	bouyer-quota2:1.1.1.2.0.22
	bouyer-quota2-base:1.1.1.2
	matt-nb5-pq3:1.1.1.2.0.20
	matt-nb5-pq3-base:1.1.1.2
	netbsd-5-1:1.1.1.2.0.18
	netbsd-5-1-RELEASE:1.1.1.2
	netbsd-5-1-RC4:1.1.1.2
	netbsd-5-1-RC3:1.1.1.2
	netbsd-5-1-RC2:1.1.1.2
	netbsd-5-1-RC1:1.1.1.2
	netbsd-5-0-2-RELEASE:1.1.1.2
	netbsd-5-0-1-RELEASE:1.1.1.2
	jym-xensuspend-nbase:1.1.1.2
	netbsd-5-0:1.1.1.2.0.16
	netbsd-5-0-RELEASE:1.1.1.2
	netbsd-5-0-RC4:1.1.1.2
	netbsd-5-0-RC3:1.1.1.2
	netbsd-5-0-RC2:1.1.1.2
	jym-xensuspend:1.1.1.2.0.14
	jym-xensuspend-base:1.1.1.2
	netbsd-5-0-RC1:1.1.1.2
	netbsd-5:1.1.1.2.0.12
	netbsd-5-base:1.1.1.2
	mjf-devfs2:1.1.1.2.0.10
	mjf-devfs2-base:1.1.1.2
	yamt-pf42-base4:1.1.1.2
	yamt-pf42-base3:1.1.1.2
	hpcarm-cleanup-nbase:1.1.1.2
	yamt-pf42-base2:1.1.1.2
	yamt-pf42:1.1.1.2.0.8
	yamt-pf42-base:1.1.1.2
	keiichi-mipv6-nbase:1.1.1.2
	keiichi-mipv6:1.1.1.2.0.6
	keiichi-mipv6-base:1.1.1.2
	cube-autoconf:1.1.1.2.0.4
	cube-autoconf-base:1.1.1.2
	hpcarm-cleanup:1.1.1.2.0.2
	hpcarm-cleanup-base:1.1.1.2
	netbsd-1-0-base:1.1.1.1
	nvi-1-11b:1.1.1.1
	bostic-nvi:1.1.1;
locks; strict;
comment	@ * @;


1.1
date	94.03.28.02.52.35;	author cgd;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	94.03.28.02.52.36;	author cgd;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	94.08.17.16.35.24;	author mycroft;	state dead;
branches;
next	;


desc
@@



1.1
log
@Initial revision
@
text
@/*-
 * Copyright (c) 1993, 1994
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef lint
static char sccsid[] = "@@(#)intr.c	8.1 (Berkeley) 3/23/94";
#endif /* not lint */

#include <sys/types.h>
#include <sys/queue.h>
#include <sys/time.h>

#include <bitstring.h>
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>

#include "compat.h"
#include <db.h>
#include <regex.h>

#include "vi.h"

/* 
 * There's a count of how deep the interrupt level in the SCR structure
 * has gone.  Each routine that wants to be interrupted increments this
 * level, and decrements it when it tears the interrupts down.  There are
 * two simplifying assumptions:
 *
 *	1: All interruptible areas want the same handler (we don't have
 *	   to save/restore the old handler).
 *	2: This is the only way to turn on interrupts (we don't have to
 *	   worry about them already being turned on if the interrupt
 *	   level is 0).
 *
 * We do it this way because interrupts have to be very fast -- if the
 * O_REMAPMAX option is turned off, we are setting interrupts per key
 * stroke.
 *
 * If an interrupt arrives, the S_INTERRUPTED bit is set in any SCR that
 * has the S_INTERRUPTIBLE bit set.  In the future this may be a problem.
 * The user should be able to move to another screen and keep typing while
 * another screen runs.  Currently, if the user does this and the user has
 * more than one interruptible thing running, there will be no way to know
 * which one to stop.
 */

static void intr_def __P((int));

/*
 * intr_init --
 *	Set up a interrupts.
 */
int
intr_init(sp)
	SCR *sp;
{
	struct sigaction act;
	struct termios nterm;

	/* You can never interrupt sessions not using tty's. */
	if (!F_ISSET(sp->gp, G_STDIN_TTY))
		return (1);

	/* If interrupts already set up, just increase the level. */
	if (sp->intr_level++)
		return (0);

	/* Turn interrupts on in this screen. */
	F_SET(sp, S_INTERRUPTIBLE);

	/* Install a handler. */
	act.sa_handler = intr_def;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	if (sigaction(SIGINT, &act, &sp->intr_act)) {
		msgq(sp, M_SYSERR, "sigaction");
		goto err1;
	}

	/*
	 * Turn on interrupts.  ISIG turns on VINTR, VQUIT and VSUSP.  We
	 * want VINTR to interrupt, so we install a handler.  VQUIT is
	 * ignored by main() because nvi never wants to catch it.  A handler
	 * for VSUSP should have been installed by the screen code.
	 */
	if (tcgetattr(STDIN_FILENO, &sp->intr_term)) {
		msgq(sp, M_SYSERR, "tcgetattr");
		goto err2;
	}
	nterm = sp->intr_term;
	nterm.c_lflag |= ISIG;
	if (tcsetattr(STDIN_FILENO, TCSANOW | TCSASOFT, &nterm)) {
		msgq(sp, M_SYSERR, "tcsetattr");
		/*
		 * If an error occurs, back out the changes and run
		 * without interrupts.
		 */
err2:		(void)sigaction(SIGINT, &sp->intr_act, NULL);
err1:		sp->intr_level = 0;
		F_CLR(sp, S_INTERRUPTIBLE);
		return (1);
	}
	return (0);
}

/*
 * intr_end --
 *	Tear down interrupts.
 */
void
intr_end(sp)
	SCR *sp;
{
	/* If not the bottom level of interrupts, just return. */
	if (--sp->intr_level)
		return;

	/* Turn off interrupts. */
	if (tcsetattr(STDIN_FILENO, TCSANOW | TCSASOFT, &sp->intr_term))
		msgq(sp, M_SYSERR, "tcsetattr");

	/* Reset the signal state. */
	if (sigaction(SIGINT, &sp->intr_act, NULL))
		msgq(sp, M_SYSERR, "sigaction");

	/* Clear interrupt bits in this screen. */
	F_CLR(sp, S_INTERRUPTED | S_INTERRUPTIBLE);
}

/*
 * intr_def --
 *	Default interrupt handler.
 */
static void
intr_def(signo)
	int signo;
{
	SCR *sp;

	for (sp = __global_list->dq.cqh_first;
	    sp != (void *)&__global_list->dq; sp = sp->q.cqe_next)
		if (F_ISSET(sp, S_INTERRUPTIBLE))
			F_SET(sp, S_INTERRUPTED);
}
@


1.1.1.1
log
@nvi/nex 1.11beta from bostic.
@
text
@@


1.1.1.2
log
@Clean up deleted files.
@
text
@@
