summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-07 19:49:34 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-07 19:49:34 +0200
commit43a4ad52a02dd5d1f3b564f2d2989c28c61c888e (patch)
treedcb4d8a25deee43123c97ddbd40eb0fcac3e61d0
parent86b3360429630d8ea78c440d8116e7248e40f9e3 (diff)
downloadtterm-43a4ad52a02dd5d1f3b564f2d2989c28c61c888e.tar.gz
Create configurable constants
-rw-r--r--tterm.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/tterm.c b/tterm.c
index 0d70cb3..015d17b 100644
--- a/tterm.c
+++ b/tterm.c
@@ -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 {