Commits

Anonymous committed d47ca76

don't need cwr, made srw

Comments (0)

Files changed (2)

 
 void win(int wd)
 {
-	char cmd[1024];
+	char in[1024], out[1024];
 
 	if (wins[wd])
 		return;
 
-	sprintf(cmd, "cw %s/out %s/in", paths[wd], paths[wd]);
+	sprintf(out, "%s/out", paths[wd]);
+	sprintf(in,  "%s/in",  paths[wd]);
 
-	printf("about to run urxvt -title %s -e cwr %s\n", paths[wd], cmd);
+	printf("about to run urxvt -title %s -e srw cw %s %s\n", paths[wd], out, in);
 
 	if ((wins[wd] = fork()) == 0) {
-		execlp("urxvt", "urxvt", "-title", paths[wd], "-e", "cwr", cmd, NULL);
+		execlp("urxvt", "urxvt", "-title", paths[wd], "-e", "srw", "cw", out, in, NULL);
 		err(1, "failed on execlp cw");
 	} else {
 		printf("child has pid %d\n", wins[wd]);

cwr.c

-#include <termios.h>
-#include <stdio.h>
-#include <sys/select.h>
-
-int main(int argc, char **argv)
-{
-	struct termios set;
-	char buf[4096], bufout[4096], tput_cub[32], tmp[L_tmpnam], cmd[1024];
-	int i, j, len;
-	FILE *pipe, *fifo;
-	fd_set rd;
-
-	if ((pipe = popen("tput cub1", "r")) == NULL)
-		warn("failed on popen tput (please forgive me)");
-
-	if (fgets(tput_cub, sizeof(tput_cub), pipe) == NULL)
-		warn("failed to read tput cub1 (please forgive me)");
-
-	pclose(pipe);
-
-	if (mkfifo(tmpnam(tmp), 0700) < 0)
-		err(1, "could not mkfifo %s", tmp);
-
-	sprintf(cmd, "%s > %s", argv[1], tmp);
-
-	if ((pipe = popen(cmd, "w")) == NULL)
-		warn("could not popen %s", cmd);
-
-	if ((fifo = fopen(tmp, "w+")) == NULL)
-		err(1, "could not open fifo %s", tmp);
-
-	tcgetattr(0, &set);
-	set.c_lflag &= ~(ICANON | ECHO);
-	set.c_cc[VMIN ] = 1;
-	set.c_cc[VTIME] = 0;
-	tcsetattr(0, TCSANOW, &set);
-
-	//for (i = 0; i < sizeof(buf) - 1 && read(0, buf + i, 1) > 0; i++) {
-	for (;;) {
-		FD_ZERO(&rd);
-		FD_SET(0, &rd);
-		FD_SET(fileno(fifo), &rd);
-
-		select(fileno(fifo) + 1, &rd, NULL, NULL, NULL);
-
-		if (FD_ISSET(0, &rd)) {
-			if (read(0, buf + i, 1) < 0)
-				warn("failed reading from stdin");
-
-			buf[i + 1] = '\0';
-
-			switch (buf[i]) {
-				case '\n' :
-					if (i == 0) {
-						i = -1;
-						break;
-					}
-					for (j = 0; j < i; j++)
-						printf("%s %s", tput_cub, tput_cub);
-					fputs(buf, pipe);
-					fflush(pipe);
-					buf[0] = '\0';
-					i = -1;
-					break;
-				case '\b' :
-				case 127  :
-					if (i--) {
-						buf[i--] = '\0';
-						fprintf(stdout, "%s %s", tput_cub, tput_cub);
-					}
-					break;
-				default :
-					putc(buf[i], stdout);
-			}
-			fflush(stdout);
-			i++;
-		}
-		if (FD_ISSET(fileno(fifo), &rd)) {
-			for (j = 0; j < i; j++)
-				printf("%s %s", tput_cub, tput_cub);
-			fflush(stdout);
-
-			if ((len = read(fileno(fifo), bufout, sizeof(bufout))) < 0)
-				warn("failed to read from fifo %s", tmp);
-			write(1, bufout, len);
-
-			fputs(buf, stdout);
-			fflush(stdout);
-		}
-	}
-
-	return 0;
-}