summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2008-04-15 21:20:57 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2008-04-15 21:20:57 +0000
commit5f0ab4b203f3de08a07920c748ac924236e54fea (patch)
tree5fadab6ddef035294d8bab511ff35944994b6cda /app
parent137365b51ad032cfef837eb721176afc9ecbb08e (diff)
make the argument parser for commands accept quoted strings, while i'm
there make u_spawn use exec_wm (renamed to u_exec) for it's execution to remove duplicated code. This means constructs like this work in .cwmrc: bind CM-t "ssh -Y 192.168.1.2 \"xterm -e top\"" or alternatively: bind CM-t "ssh -Y 192.168.1.2 'xterm -e top'" "in it goes" okan@.
Diffstat (limited to 'app')
-rw-r--r--app/cwm/calmwm.h4
-rw-r--r--app/cwm/kbfunc.c5
-rw-r--r--app/cwm/util.c42
3 files changed, 31 insertions, 20 deletions
diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h
index ed2e3f481..dd4047ce6 100644
--- a/app/cwm/calmwm.h
+++ b/app/cwm/calmwm.h
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $Id: calmwm.h,v 1.31 2008/04/15 20:26:50 oga Exp $
+ * $Id: calmwm.h,v 1.32 2008/04/15 21:20:56 oga Exp $
*/
#ifndef _CALMWM_H_
@@ -401,7 +401,7 @@ int xu_getstate(struct client_ctx *, int *);
void xu_key_grab_keycode(Window, int, int);
int u_spawn(char *);
-void exec_wm(char *);
+void u_exec(char *);
void grab_sweep(struct client_ctx *);
void grab_drag(struct client_ctx *);
diff --git a/app/cwm/kbfunc.c b/app/cwm/kbfunc.c
index 6bd4841e5..44d1ac6bf 100644
--- a/app/cwm/kbfunc.c
+++ b/app/cwm/kbfunc.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $Id: kbfunc.c,v 1.20 2008/04/15 20:24:41 oga Exp $
+ * $Id: kbfunc.c,v 1.21 2008/04/15 21:20:56 oga Exp $
*/
#include <paths.h>
@@ -359,7 +359,8 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
u_spawn(mi->text);
break;
case CWM_EXEC_WM:
- exec_wm(mi->text);
+ u_exec(mi->text);
+ warn("%s", mi->text);
break;
default:
err(1, "kb_func: egad, cmd changed value!");
diff --git a/app/cwm/util.c b/app/cwm/util.c
index 4b10d722c..c4ceff7c7 100644
--- a/app/cwm/util.c
+++ b/app/cwm/util.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $Id: util.c,v 1.7 2008/04/15 20:26:50 oga Exp $
+ * $Id: util.c,v 1.8 2008/04/15 21:20:56 oga Exp $
*/
#include "headers.h"
@@ -26,19 +26,10 @@
int
u_spawn(char *argstr)
{
- char *args[MAXARGLEN], **ap;
- char **end = &args[MAXARGLEN - 1];
-
switch (fork()) {
case 0:
- ap = args;
- while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL)
- ap++;
-
- *ap = NULL;
- setsid();
- execvp(args[0], args);
- err(1, args[0]);
+ u_exec(argstr);
+ err(1, "%s", argstr);
break;
case -1:
warn("fork");
@@ -51,16 +42,35 @@ u_spawn(char *argstr)
}
void
-exec_wm(char *argstr)
+u_exec(char *argstr)
{
char *args[MAXARGLEN], **ap = args;
char **end = &args[MAXARGLEN - 1];
+ char *tmp;
- while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL)
- ap++;
+ while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL) {
+ if(**ap == '\0')
+ continue;
+ ap++;
+ if (argstr != NULL) {
+ /* deal with quoted strings */
+ switch(argstr[0]) {
+ case '"':
+ case '\'':
+ if ((tmp = strchr(argstr + 1, argstr[0]))
+ != NULL) {
+ *(tmp++) = '\0';
+ *(ap++) = ++argstr;
+ argstr = tmp;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
*ap = NULL;
setsid();
execvp(args[0], args);
- warn(args[0]);
}