Browse Source

Factor out ircQuit

Causal Agent 3 months ago
parent
commit
e84c36a0bd
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 13 additions and 8 deletions
  1. 1
    0
      chat.h
  2. 2
    6
      event.c
  3. 5
    2
      input.c
  4. 5
    0
      irc.c

+ 1
- 0
chat.h View File

@@ -111,6 +111,7 @@ int ircConnect(void);
111 111
 void ircRead(void);
112 112
 void ircWrite(const char *ptr, size_t len);
113 113
 void ircFmt(const char *format, ...) __attribute__((format(printf, 1, 2)));
114
+void ircQuit(const char *mesg);
114 115
 
115 116
 void uiInit(void);
116 117
 void uiShow(void);

+ 2
- 6
event.c View File

@@ -131,14 +131,10 @@ noreturn void eventLoop(void) {
131 131
 
132 132
 	for (;;) {
133 133
 		if (sig[SIGCHLD]) childWait();
134
-		if (sig[SIGHUP]) {
135
-			ircFmt("QUIT :zzz\r\n");
136
-			self.quit = true;
137
-		}
134
+		if (sig[SIGHUP]) ircQuit("zzz");
138 135
 		if (sig[SIGINT]) {
139 136
 			signal(SIGINT, SIG_DFL);
140
-			ircFmt("QUIT :Goodbye\r\n");
141
-			self.quit = true;
137
+			ircQuit("Goodbye");
142 138
 		}
143 139
 		if (sig[SIGWINCH]) {
144 140
 			curses.sa_handler(SIGWINCH);

+ 5
- 2
input.c View File

@@ -118,8 +118,11 @@ static void inputTopic(struct Tag tag, char *params) {
118 118
 
119 119
 static void inputQuit(struct Tag tag, char *params) {
120 120
 	(void)tag;
121
-	ircFmt("QUIT :%s\r\n", params ? params : "Goodbye");
122
-	self.quit = true;
121
+	if (params) {
122
+		ircQuit(params);
123
+	} else {
124
+		ircQuit("Goodbye");
125
+	}
123 126
 }
124 127
 
125 128
 static void inputURL(struct Tag tag, char *params) {

+ 5
- 0
irc.c View File

@@ -117,6 +117,11 @@ void ircFmt(const char *format, ...) {
117 117
 	free(buf);
118 118
 }
119 119
 
120
+void ircQuit(const char *mesg) {
121
+	ircFmt("QUIT :%s\r\n", mesg);
122
+	self.quit = true;
123
+}
124
+
120 125
 void ircRead(void) {
121 126
 	static char buf[4096];
122 127
 	static size_t len;

Loading…
Cancel
Save