aboutsummaryrefslogtreecommitdiff
path: root/status.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-02-01 18:14:49 +0000
committerTiago Cunha <tcunha@gmx.com>2009-02-01 18:14:49 +0000
commit804beb9266f9f731329d90b56842a863598f25ff (patch)
treef6e5ecc9c255ff0b80c2df09093a2731933e07c5 /status.c
parent051dcdcba803211e05f7a8a53b44aac3af5a0056 (diff)
downloadrtmux-804beb9266f9f731329d90b56842a863598f25ff.tar.gz
rtmux-804beb9266f9f731329d90b56842a863598f25ff.tar.bz2
rtmux-804beb9266f9f731329d90b56842a863598f25ff.zip
Support commands with right parenthesis. From nicm and me.
Diffstat (limited to 'status.c')
-rw-r--r--status.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/status.c b/status.c
index 7850cfd6..47299388 100644
--- a/status.c
+++ b/status.c
@@ -1,4 +1,4 @@
-/* $Id: status.c,v 1.70 2009-01-30 00:24:49 nicm Exp $ */
+/* $Id: status.c,v 1.71 2009-02-01 18:14:49 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -376,16 +376,37 @@ char *
status_replace_popen(char **iptr)
{
FILE *f;
- char *buf = NULL;
- char cmd[BUFSIZ];
- char *ptr = NULL;
+ char *buf, *cmd, *ptr;
+ int lastesc;
size_t len;
- if (**iptr == '\0' || strchr(*iptr, ')') == NULL)
+ if (**iptr == '\0')
return (NULL);
+ if (**iptr == ')') { /* no command given */
+ (*iptr)++;
+ return (NULL);
+ }
+
+ buf = NULL;
+
+ cmd = xmalloc(strlen(*iptr) + 1);
+ len = 0;
- strlcpy(cmd, *iptr, sizeof cmd);
- cmd[strcspn(cmd, ")")] = '\0';
+ lastesc = 0;
+ for (; **iptr != '\0'; (*iptr)++) {
+ if (!lastesc && **iptr == ')')
+ break; /* unescaped ) is the end */
+ if (!lastesc && **iptr == '\\') {
+ lastesc = 1;
+ continue; /* skip \ if not escaped */
+ }
+ lastesc = 0;
+ cmd[len++] = **iptr;
+ }
+ if (**iptr == '\0') /* no terminating ) */
+ goto out;
+ (*iptr)++; /* skip final ) */
+ cmd[len] = '\0';
if ((f = popen(cmd, "r")) == NULL)
goto out;
@@ -398,7 +419,7 @@ status_replace_popen(char **iptr)
buf[len - 1] = '\0';
buf = xstrdup(buf);
} else {
- ptr = xrealloc(ptr, 1, len + 1);
+ ptr = xmalloc(len + 1);
memcpy(ptr, buf, len);
ptr[len] = '\0';
buf = ptr;
@@ -406,7 +427,7 @@ status_replace_popen(char **iptr)
pclose(f);
out:
- *iptr = (strchr(*iptr, ')') + 1);
+ xfree(cmd);
return (buf);
}