mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
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@.
This commit is contained in:
parent
887a5aa65f
commit
d5794a6b02
2
calmwm.h
2
calmwm.h
@ -401,7 +401,7 @@ int xu_getstate(struct client_ctx *, int *);
|
|||||||
void xu_key_grab_keycode(Window, int, int);
|
void xu_key_grab_keycode(Window, int, int);
|
||||||
|
|
||||||
int u_spawn(char *);
|
int u_spawn(char *);
|
||||||
void exec_wm(char *);
|
void u_exec(char *);
|
||||||
|
|
||||||
void grab_sweep(struct client_ctx *);
|
void grab_sweep(struct client_ctx *);
|
||||||
void grab_drag(struct client_ctx *);
|
void grab_drag(struct client_ctx *);
|
||||||
|
3
kbfunc.c
3
kbfunc.c
@ -359,7 +359,8 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
|
|||||||
u_spawn(mi->text);
|
u_spawn(mi->text);
|
||||||
break;
|
break;
|
||||||
case CWM_EXEC_WM:
|
case CWM_EXEC_WM:
|
||||||
exec_wm(mi->text);
|
u_exec(mi->text);
|
||||||
|
warn("%s", mi->text);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
err(1, "kb_func: egad, cmd changed value!");
|
err(1, "kb_func: egad, cmd changed value!");
|
||||||
|
40
util.c
40
util.c
@ -26,19 +26,10 @@
|
|||||||
int
|
int
|
||||||
u_spawn(char *argstr)
|
u_spawn(char *argstr)
|
||||||
{
|
{
|
||||||
char *args[MAXARGLEN], **ap;
|
|
||||||
char **end = &args[MAXARGLEN - 1];
|
|
||||||
|
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case 0:
|
case 0:
|
||||||
ap = args;
|
u_exec(argstr);
|
||||||
while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL)
|
err(1, "%s", argstr);
|
||||||
ap++;
|
|
||||||
|
|
||||||
*ap = NULL;
|
|
||||||
setsid();
|
|
||||||
execvp(args[0], args);
|
|
||||||
err(1, args[0]);
|
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
warn("fork");
|
warn("fork");
|
||||||
@ -51,16 +42,35 @@ u_spawn(char *argstr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
exec_wm(char *argstr)
|
u_exec(char *argstr)
|
||||||
{
|
{
|
||||||
char *args[MAXARGLEN], **ap = args;
|
char *args[MAXARGLEN], **ap = args;
|
||||||
char **end = &args[MAXARGLEN - 1];
|
char **end = &args[MAXARGLEN - 1];
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL)
|
while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL) {
|
||||||
ap++;
|
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;
|
*ap = NULL;
|
||||||
setsid();
|
setsid();
|
||||||
execvp(args[0], args);
|
execvp(args[0], args);
|
||||||
warn(args[0]);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user