summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-11-22 19:55:38 +0100
committerSebastien Helleu <flashcode@flashtux.org>2012-11-22 19:55:38 +0100
commit1281b18688171dc57d2e3cafb93c9e2f1dcf6c85 (patch)
treea2e68c9f627a927ce6a95f94476909369cd630a1 /src
parent425256b38d12f9a6bf038d658bb1cc3233852296 (diff)
downloadweechat-1281b18688171dc57d2e3cafb93c9e2f1dcf6c85.zip
api: use hashtable "options" for command arguments in function hook_process_hashtable (optional, default is a split of string with command)
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-hook.c49
1 files changed, 46 insertions, 3 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index 5e708d0d6..40ae1a52f 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char **exec_args;
+ char **exec_args, str_arg[64];
const char *ptr_url;
- int rc, i;
+ int rc, i, num_args;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,7 +1429,50 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ num_args = 0;
+ if (HOOK_PROCESS(hook_process, options))
+ {
+ /*
+ * count number of arguments given in the hashable options,
+ * keys are: "arg1", "arg2", ...
+ */
+ while (1)
+ {
+ snprintf (str_arg, sizeof (str_arg), "arg%d", num_args + 1);
+ if (!hashtable_has_key (HOOK_PROCESS(hook_process, options), str_arg))
+ break;
+ num_args++;
+ }
+ }
+ if (num_args > 0)
+ {
+ /*
+ * if at least one argument was found in hashtable option, the
+ * "command" contains only path to binary (without arguments), and
+ * the arguments are in hashtable
+ */
+ exec_args = malloc ((num_args + 2) * sizeof (exec_args[0]));
+ if (exec_args)
+ {
+ exec_args[0] = HOOK_PROCESS(hook_process, command);
+ for (i = 1; i <= num_args; i++)
+ {
+ snprintf (str_arg, sizeof (str_arg), "arg%d", i);
+ exec_args[i] = (char *)hashtable_get (HOOK_PROCESS(hook_process, options),
+ str_arg);
+ }
+ exec_args[num_args + 1] = NULL;
+ }
+ }
+ else
+ {
+ /*
+ * if no arguments were found in hashtable, make an automatic split
+ * of command, like the shell does
+ */
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ }
+
if (exec_args)
{
if (weechat_debug_core >= 1)