[PATCH 43/65] improve

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sat, 23 Aug 2014 23:18:33 +0000

Signed-off-by: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
---
 ii.c | 40 ++++++++++++++--------------------------
 1 file changed, 14 insertions(+), 26 deletions(-)
diff --git a/ii.c b/ii.c
index 8d3523c..387e1f5 100644
--- a/ii.c
+++ b/ii.c
_AT_@ -29,7 +29,7 @@ typedef struct Channel Channel;
 struct Channel {
 	int fd;
 	char name[IRC_CHANNEL_MAX]; /* channel name (normalized) */
-	char inpath[PATH_MAX];      /* input path (normalized) */
+	char inpath[PATH_MAX];      /* input path */
 	char outpath[PATH_MAX];     /* output path */
 	Channel *next;
 };
_AT_@ -316,43 +316,31 @@ tokenize(char **result, size_t reslen, char *str, int delim) {
 }
 
 static void
-print_outfile(const char *path, const char *buf) {
+channel_print(Channel *c, const char *buf) {
 	time_t t = time(NULL);
 	FILE *fp = NULL;
-	char buft[18] = "";
 
-	if(!(fp = fopen(path, "a")))
+	if(!(fp = fopen(c->outpath, "a")))
 		return;
-	strftime(buft, sizeof(buft), "%Y-%m-%d %H:%M", localtime(&t));
-	fprintf(fp, "%s %s\n", buft, buf);
+	fprintf(fp, "%lu %s\n", t, buf);
 	fclose(fp);
 }
 
 static void
-channel_print(Channel *c, const char *buf) {
-	/* starts with "-!- " #channel */
-	if(!strncmp(buf, "-!- ", 4) &&
-	   !strncmp(&buf[4], c->name, strlen(c->name))) {
-		c = channelmaster;
-	}
-	print_outfile(c->outpath, buf);
-}
-
-static void
-proc_channels_privmsg(int fd, Channel *c, char *buf) {
+proc_channels_privmsg(int ircfd, Channel *c, char *buf) {
 	snprintf(msg, sizeof(msg), "<%s> %s", nick, buf);
 	channel_print(c, msg);
 	snprintf(msg, sizeof(msg), "PRIVMSG %s :%s\r\n", c->name, buf);
-	writestr(fd, msg);
+	writestr(ircfd, msg);
 }
 
 static void
-proc_channels_input(int fd, Channel *c, char *buf) {
+proc_channels_input(int ircfd, Channel *c, char *buf) {
 	char *p = NULL;
 	size_t buflen;
 
 	if(buf[0] != '/' && buf[0] != '\0') {
-		proc_channels_privmsg(fd, c, buf);
+		proc_channels_privmsg(ircfd, c, buf);
 		return;
 	}
 	msg[0] = '\0';
_AT_@ -373,7 +361,7 @@ proc_channels_input(int fd, Channel *c, char *buf) {
 				c = channel_join(&buf[3]);
 			} else if(p) {
 				if((c = channel_join(&buf[3])))
-					proc_channels_privmsg(fd, c, p + 1);
+					proc_channels_privmsg(ircfd, c, p + 1);
 				return;
 			}
 			break;
_AT_@ -398,14 +386,14 @@ proc_channels_input(int fd, Channel *c, char *buf) {
 			}
 			break;
 		case 'l': /* leave */
-			if(c->name[0] == '\0')
+			if(c == channelmaster)
 				return;
 			if(buflen >= 3)
 				snprintf(msg, sizeof(msg), "PART %s :%s\r\n", c->name, &buf[3]);
 			else
 				snprintf(msg, sizeof(msg),
 				         "PART %s :leaving\r\n", c->name);
-			writestr(fd, msg);
+			writestr(ircfd, msg);
 			channel_leave(c);
 			return;
 			break;
_AT_@ -418,7 +406,7 @@ proc_channels_input(int fd, Channel *c, char *buf) {
 		snprintf(msg, sizeof(msg), "%s\r\n", &buf[1]);
 	}
 	if(msg[0] != '\0')
-		writestr(fd, msg);
+		writestr(ircfd, msg);
 }
 
 static void
_AT_@ -488,7 +476,7 @@ proc_server_cmd(int fd, char *buf) {
 	} else if(!strncmp("PART", argv[TOK_CMD], 5)) {
 		snprintf(msg, sizeof(msg), "-!- %s(%s) has left %s",
 				argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_CHAN]);
-		/* if user itself leaves, don't write to out (don't reopen channel). */
+		/* if user itself leaves, don't write to channel (don't reopen channel). */
 		if(!strcmp(argv[TOK_NICKSRV], nick))
 			return;
 	} else if(!strncmp("MODE", argv[TOK_CMD], 5)) {
_AT_@ -519,7 +507,7 @@ proc_server_cmd(int fd, char *buf) {
 		snprintf(msg, sizeof(msg), "<%s> %s", argv[TOK_NICKSRV],
 				argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
 	}
-	if(!argv[TOK_CHAN] || !strncmp(argv[TOK_CHAN], nick, strlen(nick)))
+	if(!argv[TOK_CHAN] || !strncmp(argv[TOK_CHAN], nick, strlen(nick))) /* TODO: dont use strncmp? its wrong? */
 		channel = argv[TOK_NICKSRV];
 	else
 		channel = argv[TOK_CHAN];
-- 
2.4.10
--Multipart=_Mon__9_May_2016_17_21_10_+0200_I.6cpFVydhq75aaE
Content-Type: text/x-diff;
 name="0044-strncmp-strcmp-code-style.patch"
Content-Disposition: attachment;
 filename="0044-strncmp-strcmp-code-style.patch"
Content-Transfer-Encoding: 7bit
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Mon May 09 2016 - 17:24:22 CEST