Commits

Anonymous committed a11c6c6 Merge

merge changes i was making on bsd branch, so far they are general changes and none of the bsd stuff has happened

Comments (0)

Files changed (5)

       for an explanation of the patches
 
 [1](http://tools.suckless.org/ii)
-[2](http://bitbucket.org/emg/srw)
+[2](http://deepcube.net/code/srw)
 [3](http://tools.suckless.org/ii/patches)
 /*
  * The default command
  */
-#define CMD { "urxvt", "-title", paths[wd], "-e", "srw", "-p", channel, "cw", out, in, NULL }
+#define CMD { "urxvt", "-title", w->path, "-e", "srw", "-p", channel, "cw", out, in, NULL }
 
 /*
  * Use this if for some reason you really don't want to use srw, it's not necessary, but it makes
  * everything much nicer, there's a reason, it's the default...
  */
-//#define CMD { "urxvt", "-title", paths[wd], "-e", "cw", out, in, NULL }
+//#define CMD { "urxvt", "-title", w->path, "-e", "cw", out, in, NULL }
 
 
 /*
  * nick if you don't want to use -n nick every time, then place it in your path. It is not installed
  * by default.
  */
-//#define CMD { "urxvt", "-title", paths[wd], "-e", "srw", "-p", channel, "cw_color.sh", out, in, nick, NULL }
+//#define CMD { "urxvt", "-title", w->path, "-e", "srw", "-p", channel, "cw_color.sh", out, in, nick, NULL }
 
 /*
  * Use this if you want to use tabbed (http://tools.suckless.org/tabbed) so that each new channel is
  * It would be fairly simple to do all three steps in a script, have fun! (and you can add the color
  * too if you want)
  */
-//#define CMD { "urxvt", "-embed", getenv("pcw_window_id"), "-title", paths[wd], "-e", "srw", "-p", channel, "cw", out, in, NULL }
+//#define CMD { "urxvt", "-embed", getenv("pcw_window_id"), "-title", w->path, "-e", "srw", "-p", channel, "cw", out, in, NULL }

ii-1.4-autojoin.diff

 diff -r d93eaacde742 ii.c
 --- a/ii.c	Fri Jun 25 10:55:05 2010 +0200
-+++ b/ii.c	Mon Jul 12 15:30:45 2010 -0700
++++ b/ii.c	Tue Jul 13 02:19:27 2010 -0700
 @@ -210,6 +210,7 @@
  	if(channel) snprintf(server, sizeof(server), "-!- %s", channel);
  	if(strstr(buf, server)) channel="";
  	if(!(out = fopen(outfile, "a"))) return;
  
  	strftime(buft, sizeof(buft), "%F %R", localtime(&t));
+@@ -357,6 +358,8 @@
+ 		argv[TOK_CHAN] = argv[TOK_TEXT];
+ 		snprintf(message, PIPE_BUF, "-!- %s(%s) has joined %s", argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_TEXT]);
+ 	} else if(!strncmp("PART", argv[TOK_CMD], 5)) {
++		if (!strcmp(nick, argv[TOK_NICKSRV]))
++			return;
+ 		snprintf(message, PIPE_BUF, "-!- %s(%s) has left %s", 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] : "");

ii-1.4-joinuser.diff

 diff -r d93eaacde742 ii.c
 --- a/ii.c	Fri Jun 25 10:55:05 2010 +0200
-+++ b/ii.c	Mon Jul 12 15:37:39 2010 -0700
++++ b/ii.c	Tue Jul 13 02:20:46 2010 -0700
 @@ -105,6 +105,7 @@
  	return open(infile, O_RDONLY | O_NONBLOCK, 0);
  }
  			}
  			break;
  		case 't':
+@@ -357,6 +362,8 @@
+ 		argv[TOK_CHAN] = argv[TOK_TEXT];
+ 		snprintf(message, PIPE_BUF, "-!- %s(%s) has joined %s", argv[TOK_NICKSRV], argv[TOK_USER], argv[TOK_TEXT]);
+ 	} else if(!strncmp("PART", argv[TOK_CMD], 5)) {
++		if (!strcmp(nick, argv[TOK_NICKSRV]))
++			return;
+ 		snprintf(message, PIPE_BUF, "-!- %s(%s) has left %s", 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] : "");
 #include "config.h" // for CMD
 
 // fairly arbitray values...feel free to change
-#define PATH_MAX    1024
-#define CMD_MAX     1024
-#define MAX_ARGS    64
+#define PATH_MAX    256
 #define MAX_OPENFD  4
-#define MAX_WATCH   512
 
-int evq;
-int wins[MAX_WATCH] = {0};
-char paths[MAX_WATCH][PATH_MAX] = {{0}};
-char *nick = "";
+struct watch {
+	int wd;
+	pid_t pid;
+	char path[PATH_MAX];
+	struct watch *next;
+};
 
-void win(int wd)
+static struct watch *watches = NULL;
+static int evq;
+static char *nick = "";
+
+void win(struct watch *w)
 {
+	int fd = 0;
 	char out[PATH_MAX], in[PATH_MAX], path[PATH_MAX], channel[32];
 	char *cmd[] = CMD; // from config.h
+	struct stat st;
 
-	if (wins[wd])
+	if (w->pid)
 		return;
 
-	strcpy(path, paths[wd]); // stupid basename messing with my strings
-	sprintf(channel, "%s> ", basename(path));
-	sprintf(out, "%s/out", paths[wd]);
-	sprintf(in,  "%s/in",  paths[wd]);
+	sprintf(out, "%s/out", w->path);
+	sprintf(in,  "%s/in",  w->path);
 
-	if ((wins[wd] = fork()) == 0) {
+	// open() to see if ii has the fifo open for reading
+	if (stat(out, &st) < 0 || stat(in, &st) < 0 || (fd = open(in, O_WRONLY | O_NONBLOCK)) < 0)
+		return;
+
+	close(fd);
+	strcpy(path, w->path); // stupid basename messing with my strings
+	snprintf(channel, sizeof(channel), "%s> ", basename(path));
+
+	if ((w->pid = fork()) == 0) {
 		execvp(cmd[0], cmd);
 		err(1, "failed on execvp %s", cmd[0]);
 	}
 
 int add_dir(const char *fpath, const struct stat *sb, int typeflag)
 {
-	int wd, fd;
-	char out[PATH_MAX], in[PATH_MAX];
-	struct stat st;
+	int wd;
+	struct watch *w;
 
 	if (!(typeflag & FTW_D))
 		return 0;
 		return 0;
 	}
 
-	if (paths[wd][0] == '\0') {
-		strcpy(paths[wd], fpath);
-		sprintf(out, "%s/out", fpath);
-		sprintf(in,  "%s/in",  fpath);
-		// open() to see if ii has the fifo open for reading
-		if (stat(out, &st) == 0 && stat(in, &st) == 0 && (fd = open(in, O_WRONLY | O_NONBLOCK)) != -1) {
-			close(fd);
-			win(wd);
-		}
-	}
+	for (w = watches; w; w = w->next)
+		if (w->wd == wd)
+			return 0;
+
+	if ((w = calloc(1, sizeof(struct watch))) == NULL)
+		err(1, "error on calloc");
+
+	w->next = watches;
+	watches = w;
+
+	w->wd = wd;
+	strcpy(w->path, fpath);
+
+	win(w);
 
 	return 0;
 }
 
-int find(int *haystack, int needle, int len)
-{
-	int i;
+void sigusr(int unused) {
+	struct watch *w;
 
-	for (i = 0; i < len; i++)
-		if (haystack[i] == needle)
-			return i;
-
-	return -1;
-}
-
-void sigusr(int unused) {
-	int i, fd;
-	char out[PATH_MAX], in[PATH_MAX];
-	struct stat st;
-
-	for (i = 0; i < MAX_WATCH; i++) {
-		if (paths[i][0] == '\0')
-			continue;
-		sprintf(out, "%s/out", paths[i]);
-		sprintf(in,  "%s/in",  paths[i]);
-		if (stat(out, &st) == 0 && stat(in, &st) == 0 && (fd = open(in, O_WRONLY | O_NONBLOCK)) != -1) {
-			close(fd);
-			win(i);
-		}
-	}
+	for (w = watches; w; w = w->next)
+		win(w);
 }
 
 void sigchld(int unused)
 {
 	pid_t pid;
-	int wd;
+	struct watch *w;
 
-	while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
-		if ((wd = find(wins, pid, MAX_WATCH)) > -1)
-			wins[wd] = 0;
-	}
+	while ((pid = waitpid(-1, NULL, WNOHANG)) > 0)
+		for (w = watches; w; w = w->next)
+			if (w->pid == pid)
+				w->pid = 0;
 }
+
 void usage(void)
 {
 	fprintf(stderr, "Usage: pcw [-n nick] [-v] dir\n");
 	int len, i;
 	struct inotify_event *cur;
 	struct stat st;
+	struct watch *w;
 
 	for (i = 1; i < argc; i++) {
 		if (argv[i][0] != '-')
 
 			if (cur->mask & (IN_CREATE | IN_ISDIR))
 				ftw(argv[i], add_dir, MAX_OPENFD);
-			if (cur->mask & (IN_CREATE | IN_MODIFY) && !strcmp(cur->name, "out"))
-				win(cur->wd);
+			if (cur->mask & (IN_CREATE | IN_MODIFY) && !strcmp(cur->name, "out")) {
+				for (w = watches; w; w = w->next) {
+					if (w->wd == cur->wd) {
+						win(w);
+						break;
+					}
+				}
+			}
 		}
 	}
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.