Robert Lowry avatar Robert Lowry committed 34f169a

still refactoring pcw, currently non-functioning

Comments (0)

Files changed (1)

 #define MAX_OPENFD  4
 #define MAX_WATCH   512
 
+typedef struct watch_t watch_t;
+struct watch_t {
+	int pid;
+	char *path;
+	watch_t *next;
+#ifdef HAVE_INOTIFY
+	int wd;
+#endif
+};
+
+watch_t *watch = NULL;
+
 int evq, init;
 int wins[MAX_WATCH] = {0};
 char paths[MAX_WATCH][PATH_MAX] = {{0}};
 
+/*
 void spawn_win(int wd)
 {
 	char out[PATH_MAX], in[PATH_MAX], path[PATH_MAX], channel[32];
 		execvp(cmd[0], cmd);
 		err(1, "failed on execvp %s", cmd[0]);
 	}
+} */
+
+void spawn_win(watch_t *w)
+{
+	
 }
 
-int add_dir(const char *fpath, const struct stat *sb, int typeflag)
+#ifdef HAVE_INOTIFY
+int add_dir_inotify(const char *fpath, const struct stat *sb, int typeflag)
 {
-	int wd;
-	char out[PATH_MAX];
+/*	int wd;
+	Char out[PATH_MAX];
 	struct stat st;
 
 	if (!(typeflag & FTW_D))
 		sprintf(out, "%s/out", fpath);
 		if (!init && stat(out, &st) == 0)
 			spawn_win(wd);
+	}*/
+
+	char out[PATH_MAX];
+	struct stat st;
+	watch_t *w;
+	int wd;
+
+	if(!(typeflag & FTW_D))
+		return 0;
+
+	if ((wd = inotify_add_watch(evq, fpath, IN_CREATE | IN_MODIFY)) < 0) {
+		warn("failed on inotify_add_watch on %s", fpath);
 	}
 
+	for(w = watch; w; w = w->next) {
+		if (w->wd == wd) {
+			if(!w->path) {
+				w->path = strdup(fpath);
+				snprintf(out,sizeof(out),"%s/out",fpath);
+				if(!init && stat(out, &st) == 0)
+					spawn_win(w);
+			}
+			break;
+		}
+		if (w->next == NULL) {
+			w->next = malloc(sizeof(watch_t));
+			w->next->wd = wd;
+		}
+	}
 	return 0;
 }
+#endif
 
 int find(int *haystack, int needle, int len)
 {
 	char buf[4096];
 	int len;
 	struct inotify_event *cur;
+	watch *w;
 
 	if ((evq = inotify_init()) < 0)
 		err(1, "failed on inotify_init()");
 
 	init = 1;
-	ftw(dir, add_dir, MAX_OPENFD);
+	ftw(dir, add_dir_inotify, MAX_OPENFD);
 	init = 0;
 
 	for (;;) {
 			 cur = (struct inotify_event *)((char *)cur + sizeof(struct inotify_event) + cur->len)) {
 
 			if (cur->mask & (IN_CREATE | IN_ISDIR))
-				ftw(dir, add_dir, MAX_OPENFD);
+				ftw(dir, add_dir_inotify, MAX_OPENFD);
 			if (cur->mask & (IN_CREATE | IN_MODIFY) && !strcmp(cur->name, "out"))
 				spawn_win(cur->wd);
 		}
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.