diff options
-rw-r--r-- | tterm.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -9,11 +9,16 @@ #include <X11/Xatom.h> #include <X11/Xlib.h> -#define die(...) do{fprintf(stderr,__VA_ARGS__);exit(1);}while(0) +/* configuration */ +#define ARGV "xterm", "xterm", "-e", "/usr/local/bin/ksh", "-w", writefile, NULL +#define MAX_CMD 1000 +#define MAX_LOOK 1000 +/* state */ Atom pidatom; Display *display; -Window root; + +#define die(...) do{fprintf(stderr,__VA_ARGS__);exit(1);}while(0) unsigned char *pidprop = 0; @@ -67,7 +72,7 @@ main(int argc, char *argv[]) pid_t child; size_t size; ssize_t len; - Window w; + Window root, w; /* create fifo */ @@ -83,8 +88,7 @@ main(int argc, char *argv[]) /* start terminal */ if ((child = fork()) == 0) { - execlp("xterm", "xterm", "-e", "/usr/local/bin/ksh", - "-w", writefile, NULL); + execlp(ARGV); err(1, "execvp"); } @@ -97,14 +101,14 @@ main(int argc, char *argv[]) pidatom = XInternAtom(display, "_NET_WM_PID", 1); if (pidatom == None) die("no _NET_WM_PID atom found\n"); - for (i = 0; !w && i++ < 1000; w = findwindow(child, root)) ; + for (i = 0; !w && i++ < MAX_LOOK; w = findwindow(child, root)) ; if (!w) die("could not find window\n"); /* watch fifo and update title */ writefp = fopen(writefile, "r"); if (writefp == NULL) err(1, "fopen"); - cmd = malloc(1000*sizeof(char)); + cmd = malloc(MAX_CMD*sizeof(char)); if (cmd == NULL) err(1, "malloc"); line = NULL; @@ -117,7 +121,7 @@ main(int argc, char *argv[]) XFlush(display); } else if (strncmp(line, "cmd", 3) == 0) { line += 3; line[len-4] = 0; /* chomp */ - snprintf(cmd, 1000, "%s (%s)", line, cwd); + snprintf(cmd, MAX_CMD, "%s (%s)", line, cwd); XStoreName(display, w, cmd); XFlush(display); } else { |