simple ed
git clone git://git.2f30.org/ed.git
Log | Files | Refs

commit b887c9efd18179da5b6f5296afac9edec3b7bf24
parent c421255440a1baaca0ab5f7a9280c09c2bd9bf89
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu Dec  3 06:35:12 +0100

Add basic support for signals

Ed must ignore SIGQUIT, SIGINT interrupts
any operation and SIGHUP write the file ed.hup and
finish the execution. This patch adds support for
SIGQUIT and SIGINT, although in the case of SIGINT
we have to add some stuff, to ensure that the state
of ed is the same before of the beginning of the
operation (this can be said of all the commands
when they find an error).

ed.c | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/ed.c b/ed.c @@ -7,6 +7,7 @@ #include <ctype.h> #include <limits.h> #include <setjmp.h> +#include <signal.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -975,6 +976,13 @@ usage(void) exit(1); } +static void +sigintr(int n) +{ + signal(SIGINT, sigintr); + error("interrupt"); +} + int main(int argc, char *argv[]) { @@ -999,6 +1007,8 @@ main(int argc, char *argv[]) } } + signal(SIGINT, sigintr); + signal(SIGQUIT, SIG_IGN); if (!setjmp(savesp)) { setscratch(); if (*argv) {