summaryrefslogtreecommitdiff
path: root/src/actions.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2005-01-22 19:29:36 +0000
committersabetts <sabetts>2005-01-22 19:29:36 +0000
commitfee7a3ae27a66f2cbaca17944978bbff30e60089 (patch)
treefe596591a08065f77ae6e33fa2f41e343ef51bc5 /src/actions.c
parent9f6c3c6c2f62812a60e8122810fff6efc32585fb (diff)
downloadratpoison-fee7a3ae27a66f2cbaca17944978bbff30e60089.zip
* src/actions.h (argtype): add arg_RAW
* src/actions.c (init_user_commands): make unmanage'd argument optional when called non-interactively. (init_user_commands): "title" accepts 1 argument. (init_user_commands): "echo" and "putsel" take a raw argument. (read_arg): parse arg_RAW (parse_args): take a raw argument. gobble whitespace when we've hit nargs and raw is false. callers updated. (command): don't gobble whitespace after reading the command. set nargs when the argtype is arg_RAW, too. (cmd_set): set nargs when the argtype is arg_RAW, too.
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/actions.c b/src/actions.c
index e8ee550..387865e 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -176,7 +176,7 @@ init_user_commands()
add_command ("delkmap", cmd_delkmap, 1, 1, 1,
"Keymap: ", arg_KEYMAP);
add_command ("echo", cmd_echo, 1, 1, 1,
- "Echo: ", arg_REST);
+ "Echo: ", arg_RAW);
add_command ("escape", cmd_escape, 1, 1, 1,
"Key: ", arg_KEY);
add_command ("exec", cmd_exec, 1, 1, 1,
@@ -318,7 +318,7 @@ init_user_commands()
add_command ("sfdump", cmd_sfdump, 0, 0, 0);
add_command ("undo", cmd_undo, 0, 0, 0);
add_command ("putsel", cmd_putsel, 1, 1, 1,
- "Text: ", arg_REST);
+ "Text: ", arg_RAW);
add_command ("getsel", cmd_getsel, 0, 0, 0);
/*@end (tag required for genrpbindings) */
@@ -1964,6 +1964,7 @@ read_arg (struct argspec *spec, struct sbuf *s, struct cmdarg **arg)
{
case arg_STRING:
case arg_REST:
+ case arg_RAW:
ret = read_string (spec, s, trivial_completions, arg);
break;
case arg_KEYMAP:
@@ -2060,9 +2061,11 @@ fill_in_missing_args (struct user_command *cmd, struct list_head *list, struct l
/* Stick a list of sbuf's in list. if nargs >= 0 then only parse nargs
arguments and and the rest of the string to the list. Return 0 on
- success. non-zero on failure. */
+ success. non-zero on failure. When raw is true, then when we hit
+ nargs, we should keep any whitespace at the beginning. When false,
+ gobble the whitespace. */
static cmdret *
-parse_args (char *str, struct list_head *list, int nargs)
+parse_args (char *str, struct list_head *list, int nargs, int raw)
{
cmdret *ret = NULL;
char *i;
@@ -2084,8 +2087,13 @@ parse_args (char *str, struct list_head *list, int nargs)
if (nargs >= 0 && parsed_args >= nargs)
{
struct sbuf *s = sbuf_new(0);
- sbuf_concat(s, i);
- list_add_tail (&s->node, list);
+ if (!raw)
+ while (*i && *i == ' ') i++;
+ if (*i)
+ {
+ sbuf_concat(s, i);
+ list_add_tail (&s->node, list);
+ }
len = 0;
break;
}
@@ -2230,16 +2238,6 @@ command (int interactive, char *data)
rest = strtok (NULL, "\0");
- /* Gobble whitespace */
- if (rest)
- {
- while (*rest == ' ')
- rest++;
- /* If rest is empty, then we have no argument. */
- if (*rest == '\0')
- rest = NULL;
- }
-
PRINT_DEBUG (("cmd==%s rest==%s\n", cmd, rest));
/* Look for it in the aliases, first. */
@@ -2284,14 +2282,15 @@ command (int interactive, char *data)
/* We need to tell parse_args about arg_REST and arg_SHELLCMD. */
for (i=0; i<uc->num_args; i++)
if (uc->args[i].type == arg_REST
- || uc->args[i].type == arg_SHELLCMD)
+ || uc->args[i].type == arg_SHELLCMD
+ || uc->args[i].type == arg_RAW)
{
nargs = i;
break;
}
/* Parse the arguments and call the function. */
- result = parse_args (rest, &head, nargs);
+ result = parse_args (rest, &head, nargs, uc->args[nargs].type == arg_RAW);
if (result)
goto free_lists;
@@ -4719,7 +4718,8 @@ cmd_set (int interactive, struct cmdarg **args)
/* We need to tell parse_args about arg_REST and arg_SHELLCMD. */
for (i=0; i<ARG(0,variable)->nargs; i++)
if (ARG(0,variable)->args[i].type == arg_REST
- || ARG(0,variable)->args[i].type == arg_SHELLCMD)
+ || ARG(0,variable)->args[i].type == arg_SHELLCMD
+ || ARG(0,variable)->args[i].type == arg_RAW)
{
nargs = i;
break;
@@ -4730,7 +4730,7 @@ cmd_set (int interactive, struct cmdarg **args)
input = xstrdup (args[1]->string);
else
input = xstrdup ("");
- result = parse_args (input, &head, nargs);
+ result = parse_args (input, &head, nargs, ARG(0,variable)->args[i].type == arg_RAW);
free (input);
if (result)