summaryrefslogtreecommitdiff
path: root/tterm.c
diff options
context:
space:
mode:
Diffstat (limited to 'tterm.c')
-rw-r--r--tterm.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/tterm.c b/tterm.c
index 3a71821..21beb54 100644
--- a/tterm.c
+++ b/tterm.c
@@ -10,7 +10,7 @@
#include <X11/Xlib.h>
/* configuration */
-#define ARGV "xterm", "xterm", "-e", "/usr/local/bin/ksh", "-w", writefile, NULL
+#define ARGV "xterm", "xterm", "-e", "/usr/local/bin/ksh", "-w", fifo
#define MAX_CMD 1000
#define MAX_LOOK 1000
@@ -18,7 +18,8 @@
Atom pidatom;
Display *display;
-#define die(...) do{fprintf(stderr,__VA_ARGS__);exit(1);}while(0)
+/* print on stderr and exit */
+#define die(...) do { fprintf(stderr, __VA_ARGS__); exit(1); } while (0)
/* find window associated with pid */
Window
@@ -53,7 +54,6 @@ cwdcpy(char *path)
int len;
r = strdup(path);
-
if (strncmp(path, "/home/", sizeof("/home")-1) == 0) {
user = getenv("USER");
len = strlen(user);
@@ -62,15 +62,14 @@ cwdcpy(char *path)
r += len;
r[0] = '~';
}
-
return r;
}
int
main(int argc, char *argv[])
{
- char *cwd, *cmd, *line, *writefile;
- FILE *writefp;
+ char *cwd, *cmd, *line, *fifo;
+ FILE *fifofp;
int i;
pid_t child;
size_t size;
@@ -80,18 +79,17 @@ main(int argc, char *argv[])
if ((display = XOpenDisplay(0)) == NULL)
die("could not open display\n");
- /* create fifo directory */
if (mkdir("/var/tmp/tterm", 0700) == -1 && errno != EEXIST)
err(1, "mkdir");
/* build fifo path */
- if ((writefile = malloc(40*sizeof(char))) == NULL)
+ if ((fifo = malloc(40*sizeof(char))) == NULL)
err(1, "malloc");
- sprintf(writefile, "/var/tmp/tterm/%d.w", getpid());
+ sprintf(fifo, "/var/tmp/tterm/%d", getpid());
/* create fifo */
- unlink(writefile);
- if (mkfifo(writefile, 0600) == -1)
+ unlink(fifo);
+ if (mkfifo(fifo, 0600) == -1)
err(1, "mkfifo");
/* retrieve atom for _NET_WM_PID */
@@ -100,7 +98,7 @@ main(int argc, char *argv[])
/* start terminal */
if ((child = fork()) == 0) {
- execlp(ARGV);
+ execlp(ARGV, NULL);
err(1, "execvp");
}
@@ -111,7 +109,7 @@ main(int argc, char *argv[])
die("could not find window\n");
/* read from fifo */
- if ((writefp = fopen(writefile, "r")) == NULL)
+ if ((fifofp = fopen(fifo, "r")) == NULL)
err(1, "fopen");
if ((cmd = malloc(MAX_CMD*sizeof(char))) == NULL)
err(1, "malloc");
@@ -120,12 +118,12 @@ main(int argc, char *argv[])
size = 0;
/* get first line and unlink fifo */
- if ((len = getline(&line, &size, writefp)) == -1) goto end;
- unlink(writefile);
+ if ((len = getline(&line, &size, fifofp)) == -1) goto end;
+ unlink(fifo);
goto loop;
/* process line and update title */
- while ((len = getline(&line, &size, writefp)) != -1) {
+ while ((len = getline(&line, &size, fifofp)) != -1) {
loop: if (strncmp(line, "cwd", 3) == 0) {
line[len-1] = 0;
line += 3;