mirror of
https://github.com/irssi/irssi.git
synced 2026-08-21 17:42:49 +02:00
cmd_options_get_server() : allow NULL cmd argument
eval_special_string() : if any of the commands separated with ; used the arguments ($0, $1, etc.) don't anymore append all the arguments after other commands. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@903 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
2ea411093a
commit
a01275959d
2 changed files with 28 additions and 12 deletions
|
|
@ -429,6 +429,7 @@ SERVER_REC *cmd_options_get_server(const char *cmd,
|
||||||
/* get all the options, then remove the known ones. there should
|
/* get all the options, then remove the known ones. there should
|
||||||
be only one left - the server tag. */
|
be only one left - the server tag. */
|
||||||
list = hashtable_get_keys(optlist);
|
list = hashtable_get_keys(optlist);
|
||||||
|
if (cmd != NULL) {
|
||||||
for (tmp = list; tmp != NULL; tmp = next) {
|
for (tmp = list; tmp != NULL; tmp = next) {
|
||||||
char *option = tmp->data;
|
char *option = tmp->data;
|
||||||
next = tmp->next;
|
next = tmp->next;
|
||||||
|
|
@ -436,6 +437,7 @@ SERVER_REC *cmd_options_get_server(const char *cmd,
|
||||||
if (command_have_option(cmd, option))
|
if (command_have_option(cmd, option))
|
||||||
list = g_slist_remove(list, option);
|
list = g_slist_remove(list, option);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
return defserver;
|
return defserver;
|
||||||
|
|
|
||||||
|
|
@ -476,9 +476,14 @@ void eval_special_string(const char *cmd, const char *data,
|
||||||
{
|
{
|
||||||
const char *cmdchars;
|
const char *cmdchars;
|
||||||
char *orig, *str, *start, *ret;
|
char *orig, *str, *start, *ret;
|
||||||
int arg_used;
|
int arg_used, arg_used_ever;
|
||||||
|
GSList *commands;
|
||||||
|
|
||||||
|
commands = NULL;
|
||||||
|
arg_used_ever = FALSE;
|
||||||
cmdchars = settings_get_str("cmdchars");
|
cmdchars = settings_get_str("cmdchars");
|
||||||
|
|
||||||
|
/* get a list of all the commands to run */
|
||||||
orig = start = str = g_strdup(cmd);
|
orig = start = str = g_strdup(cmd);
|
||||||
do {
|
do {
|
||||||
if (is_split_char(str, start))
|
if (is_split_char(str, start))
|
||||||
|
|
@ -490,6 +495,8 @@ void eval_special_string(const char *cmd, const char *data,
|
||||||
|
|
||||||
ret = parse_special_string(start, server, item,
|
ret = parse_special_string(start, server, item,
|
||||||
data, &arg_used);
|
data, &arg_used);
|
||||||
|
if (arg_used) arg_used_ever = TRUE;
|
||||||
|
|
||||||
if (strchr(cmdchars, *ret) == NULL) {
|
if (strchr(cmdchars, *ret) == NULL) {
|
||||||
/* no command char - let's put it there.. */
|
/* no command char - let's put it there.. */
|
||||||
char *old = ret;
|
char *old = ret;
|
||||||
|
|
@ -497,19 +504,26 @@ void eval_special_string(const char *cmd, const char *data,
|
||||||
ret = g_strdup_printf("%c%s", *cmdchars, old);
|
ret = g_strdup_printf("%c%s", *cmdchars, old);
|
||||||
g_free(old);
|
g_free(old);
|
||||||
}
|
}
|
||||||
if (!arg_used && *data != '\0') {
|
commands = g_slist_append(commands, ret);
|
||||||
/* append the string with all the arguments */
|
start = str;
|
||||||
|
} while (*start != '\0');
|
||||||
|
|
||||||
|
/* run the command, if no arguments were ever used, append all of them
|
||||||
|
after each command */
|
||||||
|
while (commands != NULL) {
|
||||||
|
ret = commands->data;
|
||||||
|
|
||||||
|
if (!arg_used_ever && *data != '\0') {
|
||||||
char *old = ret;
|
char *old = ret;
|
||||||
|
|
||||||
ret = g_strconcat(old, " ", data, NULL);
|
ret = g_strconcat(old, " ", data, NULL);
|
||||||
g_free(old);
|
g_free(old);
|
||||||
}
|
}
|
||||||
signal_emit("send command", 3, ret, server, item);
|
signal_emit("send command", 3, ret, server, item);
|
||||||
|
|
||||||
g_free(ret);
|
g_free(ret);
|
||||||
|
commands = g_slist_remove(commands, commands->data);
|
||||||
start = str;
|
}
|
||||||
} while (*start != '\0');
|
|
||||||
|
|
||||||
g_free(orig);
|
g_free(orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue