wm: ticl

Download patch

ref: c280d99d0354f96611acaa905c46c3eee4e3a37b
parent: 7c65a52929d95ad5a4108706bb32c7c7f754b193
author: mkf <mkf@cloud9p.org>
date: Tue Sep 26 00:24:12 EDT 2023

de-hardcode(?) wnick

--- a/main.c
+++ b/main.c
@@ -37,6 +37,8 @@
 
 #define EV_READ		1
 #define EV_WRITE	2
+	
+char	 wnick	[NICK_LEN];	/* watcher nick */
 
 enum {
 	IDLE = 0,
@@ -132,10 +134,14 @@
 	setvbuf(stdout, NULL, _IONBF, 0);
 
 	/* handle arguments */
-	if (argc != 2)
-		fatal("usage: ticl fifo");
+	if (argc < 2 || argc > 3)
+		fatal("usage: ticl fifo [wnick]");
 	else
 		fifopath = argv[1];
+	if (argc == 3)
+		wnick = argv[2];
+	else
+		wnick = "watcher";
 
 	/* init global variables */
 	netcap = NET_ADDEND;
@@ -395,7 +401,10 @@
 	fd_register(fd, EV_READ);
 #endif
 	if (fdtodata[fd]->user == NULL) {	/* watcher */
-		snprintf(msg, sizeof(msg), "NICK watcher\r\nUSER watcher 0 * :watcher\r\n");
+		snprintf(msg, sizeof(msg),
+				"NICK %s\r\n"
+				"USER %s 0 * :%s\r\n",
+				wnick, wnick, wnick);
 		writeall(fd, msg);
 	} else {			/* user */
 		snprintf(msg, sizeof(msg), "NICK %s\r\nUSER user 0 * :user\r\n", fdtodata[fd]->user);
@@ -408,7 +417,6 @@
 {
 	char	 buffer	[BUFSIZE];
 	char	 backup	[BUFSIZE];
-	char	 wnick	[NICK_LEN];	/* watcher nick */
 	char	*buf;
 	char	*cmd;
 	char	*nick;
@@ -635,7 +643,7 @@
 		int *fds;
 		char *user;
 
-		split(&buf, ' ');		/* channel name				*/
+		split(&buf, ' ');		/* channel name			*/
 		user = split(&buf, ' ');	/* user who is being kicked		*/
 		split(&buf, ':');		/* ignore ':' and store reason to buf	*/