Commits

Anonymous committed 1b7d447

fix alignment

  • Participants
  • Parent commits dd65cff

Comments (0)

Files changed (1)

File patches/ii-1.4-emg.diff

-diff -r d93eaacde742 config.mk
---- a/config.mk	Fri Jun 25 10:55:05 2010 +0200
-+++ b/config.mk	Fri Jul 23 13:30:24 2010 -0700
-@@ -12,7 +12,7 @@
- 
- INCDIR      = ${PREFIX}/include
- LIBDIR      = ${PREFIX}/lib
--VERSION     = 1.4
-+VERSION     = 1.4-emg
- 
- # includes and libs
- INCLUDES    = -I. -I${INCDIR} -I/usr/include
-diff -r d93eaacde742 ii.1
---- a/ii.1	Fri Jun 25 10:55:05 2010 +0200
-+++ b/ii.1	Fri Jul 23 13:30:24 2010 -0700
-@@ -33,6 +33,8 @@
- .IR nickname ]
- .RB [ \-f
- .IR realname ]
-+.RB [ \-m
-+.IR padding ]
- 
- .SH OPTIONS
- .TP
-@@ -55,6 +57,9 @@
- .TP
- .BI \-f " realname"
- lets you specify your real name associated with your nick
-+.TP
-+.BI \-m " padding"
-+lets you specify to what length ii should pad nicks (default 12)
- 
- .SH DIRECTORIES
- .TP
-@@ -70,12 +75,18 @@
- .FN /a " [<message>]"
- mark yourself as away
- .TP
-+.FN /e " command"
-+execute command and write output to current channel
-+.TP
- .FN /j " #channel/nickname [<message>]"
- join a channel or open private conversation with user
- .TP
- .FN /l " #channel/nickname"
- leave a channel or query
- .TP
-+.FN /m " action"
-+send action as a CTCP ACTION (think /me)
-+.TP
- .FN /n " nick"
- change the nick name
- .TP
-diff -r d93eaacde742 ii.c
---- a/ii.c	Fri Jun 25 10:55:05 2010 +0200
-+++ b/ii.c	Fri Jul 23 13:30:24 2010 -0700
-@@ -33,6 +33,9 @@
- 	Channel *next;
- };
- 
-+#define IS_CHANNEL(s) (((s)[0]=='#')||((s)[0]=='&')||((s)[0]=='+')||((s)[0]=='!'))
-+
-+#define EXIT_TIMEOUT 2
- #define PING_TIMEOUT 300
- #define SERVER_PORT 6667
- static int irc;
-@@ -42,6 +45,7 @@
- static char nick[32];			/* might change while running */
- static char path[_POSIX_PATH_MAX];
- static char message[PIPE_BUF]; /* message buf used for communication */
-+static int pad = 12; /* for nick alignment */
- 
- static void usage() {
- 	fprintf(stderr, "%s",
-@@ -105,6 +109,7 @@
- 	return open(infile, O_RDONLY | O_NONBLOCK, 0);
- }
- 
-+static void print_out(char *channel, char *buf); // needs to be declared
- static void add_channel(char *name) {
- 	Channel *c;
- 	int fd;
-@@ -123,13 +128,16 @@
- 		perror("ii: cannot allocate memory");
- 		exit(EXIT_FAILURE);
- 	}
--	if(!channels) channels = c;
--	else {
--		c->next = channels;
--		channels = c;
--	}
- 	c->fd = fd;
- 	c->name = strdup(name);
-+	c->next = channels;
-+	channels = c;
-+
-+	if(name[0] && !IS_CHANNEL(name)) {
-+		char msg[128];
-+		snprintf(msg, sizeof(msg), "%*s-!- %s has joined %s", pad - 1, "", nick, name);
-+		print_out(name, msg);
-+	}
- }
- 
- static void rm_channel(Channel *c) {
-@@ -207,9 +215,10 @@
- 	FILE *out = NULL;
- 	time_t t = time(0);
- 
--	if(channel) snprintf(server, sizeof(server), "-!- %s", channel);
-+	if(channel) snprintf(server, sizeof(server), "%*s-!- %s", pad - 1, "", channel);
- 	if(strstr(buf, server)) channel="";
- 	create_filepath(outfile, sizeof(outfile), channel, "out");
-+	if(channel && channel[0]) add_channel(channel);
- 	if(!(out = fopen(outfile, "a"))) return;
- 
- 	strftime(buft, sizeof(buft), "%F %R", localtime(&t));
-@@ -218,7 +227,7 @@
- }
- 
- static void proc_channels_privmsg(char *channel, char *buf) {
--	snprintf(message, PIPE_BUF, "<%s> %s", nick, buf);
-+	snprintf(message, PIPE_BUF, "%*s | %s", pad, nick, buf);
- 	print_out(channel, message);
- 	snprintf(message, PIPE_BUF, "PRIVMSG %s :%s\r\n", channel, buf);
- 	write(irc, message, strlen(message));
-@@ -228,7 +237,9 @@
- 	static char infile[256];
- 	char *p = NULL;
- 
--	if(buf[0] != '/' && buf[0] != 0) {
-+	if(buf[0] == '\0')
-+		return;
-+	if(buf[0] != '/') {
- 		proc_channels_privmsg(c->name, buf);
- 		return;
- 	}
-@@ -237,17 +248,14 @@
- 		case 'j':
- 			p = strchr(&buf[3], ' ');
- 			if(p) *p = 0;
--			if((buf[3]=='#')||(buf[3]=='&')||(buf[3]=='+')||(buf[3]=='!')){
-+			add_channel(&buf[3]);
-+			if(IS_CHANNEL(&buf[3])) {
- 				if(p) snprintf(message, PIPE_BUF, "JOIN %s %s\r\n", &buf[3], p + 1); /* password protected channel */
- 				else snprintf(message, PIPE_BUF, "JOIN %s\r\n", &buf[3]);
--				add_channel(&buf[3]);
- 			}
--			else {
--				if(p){
--					add_channel(&buf[3]);
--					proc_channels_privmsg(&buf[3], p + 1);
--					return;
--				}
-+			else if(p) {
-+				proc_channels_privmsg(&buf[3], p + 1);
-+				return;
- 			}
- 			break;
- 		case 't':
-@@ -255,7 +263,7 @@
- 			break;
- 		case 'a':
- 			if(strlen(buf)>=3){
--				snprintf(message, PIPE_BUF, "-!- %s is away \"%s\"", nick, &buf[3]);
-+				snprintf(message, PIPE_BUF, "%*s-!- %s is away \"%s\"", pad - 1, "", nick, &buf[3]);
- 				print_out(c->name, message);
- 			}
- 			if(buf[2] == 0 || strlen(buf)<3) /* or used to make else part safe */
-@@ -277,13 +285,42 @@
- 			else
- 				snprintf(message, PIPE_BUF,
- 						"PART %s :ii - 500 SLOC are too much\r\n", c->name);
--			write(irc, message, strlen(message));
-+			if(IS_CHANNEL(c->name))
-+				write(irc, message, strlen(message));
- 			close(c->fd);
- 			create_filepath(infile, sizeof(infile), c->name, "in");
- 			unlink(infile);
- 			rm_channel(c);
- 			return;
- 			break;
-+		case 'e':
-+			if(strlen(buf)>=3) {
-+				char newbuf[PIPE_BUF];
-+				FILE *fp;
-+				int len;
-+
-+				if(!(fp = popen(&buf[3], "r"))) {
-+					fprintf(stderr, "error running %s\n", &buf[3]);
-+					return;
-+				}
-+				while (fgets(newbuf, sizeof(newbuf), fp)) {
-+					len = strlen(newbuf);
-+					if (newbuf[len - 1] == '\n')
-+						newbuf[len - 1] = '\0';
-+					proc_channels_privmsg(c->name, newbuf);
-+				}
-+				pclose(fp);
-+			}
-+			return;
-+			break;
-+		case 'm':
-+			if(strlen(buf)>=3) {
-+				char newbuf[PIPE_BUF];
-+				snprintf(newbuf, PIPE_BUF, "\01ACTION %s\01", &buf[3]);
-+				proc_channels_privmsg(c->name, newbuf);
-+			}
-+			return;
-+			break;
- 		default:
- 			snprintf(message, PIPE_BUF, "%s\r\n", &buf[1]);
- 			break;
-@@ -347,7 +384,7 @@
- 		print_out(0, message);
- 		return;
- 	} else if(!strncmp("ERROR", argv[TOK_CMD], 6))
--		snprintf(message, PIPE_BUF, "-!- error %s", argv[TOK_TEXT] ? argv[TOK_TEXT] : "unknown");
-+		snprintf(message, PIPE_BUF, "%*s-!- error %s", pad - 1, "", argv[TOK_TEXT] ? argv[TOK_TEXT] : "unknown");
- 	else if(!strncmp("JOIN", argv[TOK_CMD], 5)) {
- 		if(argv[TOK_TEXT] != NULL){
- 			p = strchr(argv[TOK_TEXT], ' ');
-@@ -355,23 +392,25 @@
- 				*p = 0;
- 		}
- 		argv[TOK_CHAN] = argv[TOK_TEXT];
--		snprintf(message, PIPE_BUF, "-!- %s(%s) has joined %s", argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_TEXT]);
-+		snprintf(message, PIPE_BUF, "%*s-!- %s(%s) has joined %s", pad - 1, "", argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_TEXT]);
- 	} else if(!strncmp("PART", argv[TOK_CMD], 5)) {
--		snprintf(message, PIPE_BUF, "-!- %s(%s) has left %s", argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_CHAN]);
-+		if (!strcmp(nick, argv[TOK_NICKSRV]))
-+			return;
-+		snprintf(message, PIPE_BUF, "%*s-!- %s(%s) has left %s", pad - 1, "", argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_CHAN]);
- 	} else if(!strncmp("MODE", argv[TOK_CMD], 5))
--		snprintf(message, PIPE_BUF, "-!- %s changed mode/%s -> %s %s", argv[TOK_NICKSRV], argv[TOK_CMD + 1] ? argv[TOK_CMD + 1] : "" , argv[TOK_CMD + 2]? argv[TOK_CMD + 2] : "", argv[TOK_CMD + 3] ? argv[TOK_CMD + 3] : "");
-+		snprintf(message, PIPE_BUF, "%*s-!- %s changed mode/%s -> %s %s", pad - 1, "", argv[TOK_NICKSRV], argv[TOK_CMD + 1] ? argv[TOK_CMD + 1] : "" , argv[TOK_CMD + 2]? argv[TOK_CMD + 2] : "", argv[TOK_CMD + 3] ? argv[TOK_CMD + 3] : "");
- 	else if(!strncmp("QUIT", argv[TOK_CMD], 5))
--		snprintf(message, PIPE_BUF, "-!- %s(%s) has quit \"%s\"", argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
-+		snprintf(message, PIPE_BUF, "%*s-!- %s(%s) has quit \"%s\"", pad - 1, "", argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
- 	else if(!strncmp("NICK", argv[TOK_CMD], 5))
--		snprintf(message, PIPE_BUF, "-!- %s changed nick to %s", argv[TOK_NICKSRV], argv[TOK_TEXT]);
-+		snprintf(message, PIPE_BUF, "%*s-!- %s changed nick to %s", pad - 1, "", argv[TOK_NICKSRV], argv[TOK_TEXT]);
- 	else if(!strncmp("TOPIC", argv[TOK_CMD], 6))
--		snprintf(message, PIPE_BUF, "-!- %s changed topic to \"%s\"", argv[TOK_NICKSRV], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
-+		snprintf(message, PIPE_BUF, "%*s-!- %s changed topic to \"%s\"", pad - 1, "", argv[TOK_NICKSRV], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
- 	else if(!strncmp("KICK", argv[TOK_CMD], 5))
--		snprintf(message, PIPE_BUF, "-!- %s kicked %s (\"%s\")", argv[TOK_NICKSRV], argv[TOK_ARG], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
-+		snprintf(message, PIPE_BUF, "%*s-!- %s kicked %s (\"%s\")", pad - 1, "", argv[TOK_NICKSRV], argv[TOK_ARG], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
- 	else if(!strncmp("NOTICE", argv[TOK_CMD], 7))
--		snprintf(message, PIPE_BUF, "-!- \"%s\")", argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
-+		snprintf(message, PIPE_BUF, "%*s-!- \"%s\")", pad - 1, "", argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
- 	else if(!strncmp("PRIVMSG", argv[TOK_CMD], 8))
--		snprintf(message, PIPE_BUF, "<%s> %s", argv[TOK_NICKSRV], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
-+		snprintf(message, PIPE_BUF, "%*s | %s", pad, argv[TOK_NICKSRV], argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
- 	if(!argv[TOK_CHAN] || !strncmp(argv[TOK_CHAN], nick, strlen(nick)))
- 		print_out(argv[TOK_NICKSRV], message);
- 	else
-@@ -442,8 +481,9 @@
- 			exit(EXIT_FAILURE);
- 		} else if(r == 0) {
- 			if(time(NULL) - last_response >= PING_TIMEOUT) {
--				print_out(NULL, "-!- ii shutting down: ping timeout");
--				exit(EXIT_FAILURE);
-+				snprintf(message, PIPE_BUF, "%*s-!- ii shutting down: ping timeout", pad - 1, "");
-+				print_out(NULL, message);
-+				exit(EXIT_TIMEOUT);
- 			}
- 			write(irc, ping_msg, strlen(ping_msg));
- 			continue;
-@@ -471,7 +511,6 @@
- 	}
- 	snprintf(nick, sizeof(nick), "%s", spw->pw_name);
- 	snprintf(prefix, sizeof(prefix),"%s/irc", spw->pw_dir);
--	if (argc <= 1 || (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'h')) usage();
- 
- 	for(i = 1; (i + 1 < argc) && (argv[i][0] == '-'); i++) {
- 		switch (argv[i][1]) {
-@@ -481,9 +520,13 @@
- 			case 'n': snprintf(nick,sizeof(nick),"%s", argv[++i]); break;
- 			case 'k': key = argv[++i]; break;
- 			case 'f': fullname = argv[++i]; break;
-+			case 'm': pad = strtol(argv[++i], NULL, 10); break;
- 			default: usage(); break;
- 		}
- 	}
-+
-+	if(i != argc) usage();
-+
- 	irc = tcpopen(port);
- 	if(!snprintf(path, sizeof(path), "%s/%s", prefix, host)) {
- 		fprintf(stderr, "%s", "ii: path to irc directory too long\n");