about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-14 16:43:49 -0500
committerJune McEnroe <june@causal.agency>2018-12-14 16:43:49 -0500
commite84c36a0bd255dfa1995c94b30f1c59d7dad7244 (patch)
treec8cc7a9a3d5383bb0b6429eb2c9377c26f4f0477
parentAdd uint typedef (diff)
downloadcatgirl-e84c36a0bd255dfa1995c94b30f1c59d7dad7244.tar.gz
catgirl-e84c36a0bd255dfa1995c94b30f1c59d7dad7244.zip
Factor out ircQuit
-rw-r--r--chat.h1
-rw-r--r--event.c8
-rw-r--r--input.c7
-rw-r--r--irc.c5
4 files changed, 13 insertions, 8 deletions
diff --git a/chat.h b/chat.h
index 1deb693..079a214 100644
--- a/chat.h
+++ b/chat.h
@@ -111,6 +111,7 @@ int ircConnect(void);
 void ircRead(void);
 void ircWrite(const char *ptr, size_t len);
 void ircFmt(const char *format, ...) __attribute__((format(printf, 1, 2)));
+void ircQuit(const char *mesg);
 
 void uiInit(void);
 void uiShow(void);
diff --git a/event.c b/event.c
index a5a49cc..c324a65 100644
--- a/event.c
+++ b/event.c
@@ -131,14 +131,10 @@ noreturn void eventLoop(void) {
 
 	for (;;) {
 		if (sig[SIGCHLD]) childWait();
-		if (sig[SIGHUP]) {
-			ircFmt("QUIT :zzz\r\n");
-			self.quit = true;
-		}
+		if (sig[SIGHUP]) ircQuit("zzz");
 		if (sig[SIGINT]) {
 			signal(SIGINT, SIG_DFL);
-			ircFmt("QUIT :Goodbye\r\n");
-			self.quit = true;
+			ircQuit("Goodbye");
 		}
 		if (sig[SIGWINCH]) {
 			curses.sa_handler(SIGWINCH);
diff --git a/input.c b/input.c
index 2cd0ca6..de27778 100644
--- a/input.c
+++ b/input.c
@@ -118,8 +118,11 @@ static void inputTopic(struct Tag tag, char *params) {
 
 static void inputQuit(struct Tag tag, char *params) {
 	(void)tag;
-	ircFmt("QUIT :%s\r\n", params ? params : "Goodbye");
-	self.quit = true;
+	if (params) {
+		ircQuit(params);
+	} else {
+		ircQuit("Goodbye");
+	}
 }
 
 static void inputURL(struct Tag tag, char *params) {
diff --git a/irc.c b/irc.c
index d562622..78b1ed5 100644
--- a/irc.c
+++ b/irc.c
@@ -117,6 +117,11 @@ void ircFmt(const char *format, ...) {
 	free(buf);
 }
 
+void ircQuit(const char *mesg) {
+	ircFmt("QUIT :%s\r\n", mesg);
+	self.quit = true;
+}
+
 void ircRead(void) {
 	static char buf[4096];
 	static size_t len;