From 133cd6bad77de6faefeadb876a37b3e9a6c4b8ca Mon Sep 17 00:00:00 2001
From: Dan Egnor <egnor@ofb.net>
Date: Mon, 16 Oct 2000 06:34:28 +0000
Subject: [PATCH] EXCEPTION etc.

---
 oop.h      |  2 +-
 readline.c | 26 ++++++++++++++++++++++++++
 select.c   |  6 +++---
 test-oop.c |  5 +++--
 4 files changed, 33 insertions(+), 6 deletions(-)
 create mode 100644 readline.c

diff --git a/oop.h b/oop.h
index 0e68618..a955280 100644
--- a/oop.h
+++ b/oop.h
@@ -19,7 +19,7 @@ typedef struct oop_source oop_source;
 typedef enum {
 	OOP_READ,
 	OOP_WRITE,
-	OOP_EXCEPT,
+	OOP_EXCEPTION,
 
 	OOP_NUM_EVENTS
 } oop_event;
diff --git a/readline.c b/readline.c
new file mode 100644
index 0000000..60a1b02
--- /dev/null
+++ b/readline.c
@@ -0,0 +1,26 @@
+/* readline.c, liboop, copyright 1999 Dan Egnor
+
+   This is free software; you can redistribute it and/or modify it under the
+   terms of the GNU Lesser General Public License, version 2.1 or later.
+   See the file COPYING for details. */
+
+#ifdef HAVE_READLINE
+
+#include <stdio.h> /* readline needs this! */
+#include "readline/readline.h"
+#include "oop-rl.h"
+
+static void *on_input(oop_source *oop,int fd,oop_event evt,void *x) {
+	rl_callback_read_char();
+	return OOP_CONTINUE;
+}
+
+void oop_readline_register(oop_source *oop) {
+	oop->on_fd(oop,0,OOP_READ,on_input,NULL);
+}
+
+void oop_readline_cancel(oop_source *oop) {
+	oop->cancel_fd(oop,0,OOP_READ);
+}
+
+#endif
diff --git a/select.c b/select.c
index 1f4f969..1c27967 100644
--- a/select.c
+++ b/select.c
@@ -98,12 +98,12 @@ void oop_select_set(
 		}
 
 		if (xfd_set && !w_xfd_set) {
-			s->source->on_fd(s->source,fd,OOP_EXCEPT,on_fd,s);
+			s->source->on_fd(s->source,fd,OOP_EXCEPTION,on_fd,s);
 			FD_SET(fd,&s->watch.xfd);
 		}
 
 		if (!xfd_set && w_xfd_set) {
-			s->source->cancel_fd(s->source,fd,OOP_EXCEPT);
+			s->source->cancel_fd(s->source,fd,OOP_EXCEPTION);
 			FD_CLR(fd,&s->watch.xfd);
 		}
 	}
@@ -155,7 +155,7 @@ static void *on_fd(oop_source *source,int fd,oop_event event,void *data) {
 		assert(FD_ISSET(fd,&s->watch.wfd));
 		set_fd(fd,&s->active.wfd,&s->num_fd_active);
 		break;
-	case OOP_EXCEPT:
+	case OOP_EXCEPTION:
 		assert(FD_ISSET(fd,&s->watch.xfd));
 		set_fd(fd,&s->active.xfd,&s->num_fd_active);
 		break;
diff --git a/test-oop.c b/test-oop.c
index 605f659..49cc9be 100644
--- a/test-oop.c
+++ b/test-oop.c
@@ -167,7 +167,7 @@ static void add_readline(oop_source *src) {
 #include "adns.h"
 #include "oop-adns.h"
 
-#define ADNS_CANCEL
+#undef ADNS_CANCEL
 #define NUM_Q 6
 oop_adns_query *q[NUM_Q];
 oop_adapter_adns *adns;
@@ -443,7 +443,8 @@ int main(int argc,char *argv[]) {
 	int i;
 
 	if (argc < 3) usage();
-	puts("test-oop: use ^\\ (SIGQUIT) for clean shutdown");
+	puts("test-oop: use ^\\ (SIGQUIT) for clean shutdown or "
+	     "^C (SIGINT) to stop abruptly.");
 	source = create_source(argv[1]);
 	source->on_signal(source,SIGQUIT,stop_loop,NULL);
 	for (i = 2; i < argc; ++i)
-- 
GitLab