New expansions for alias arguments ($n, $-m, $n-, $n-m, $*, $~) (patch #6917)

This commit is contained in:
Sebastien Helleu 2009-10-02 09:56:07 +02:00
parent ae13264314
commit 3a429ca6c3
12 changed files with 259 additions and 102 deletions

View File

@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
FlashCode <flashcode@flashtux.org>
v0.3.1-dev, 2009-09-30
v0.3.1-dev, 2009-10-02
Version 0.3.1 (under dev!)
@ -12,6 +12,8 @@ Version 0.3.1 (under dev!)
* core: fix plural form in translation files (bug #27430)
* core: fix terminal title bug: do not reset it when option
weechat.look.set_title is off (bug #27399)
* alias: new expansions for alias arguments ($n, $-m, $n-, $n-m, $*, $~)
(patch #6917)
* alias: allow use of wildcards for /alias list (patch #6925)
* alias: allow /unalias to remove multiple aliases (patch #6926)
* alias: fix bug with arguments (bug #27440)

View File

@ -9,7 +9,15 @@
Without argument, this command lists all defined alias.
Note: in command, special variables $1, $2,..,$9 are replaced by arguments given by user, and $* is replaced by all arguments.
Variables $nick, $channel and $server are replaced by current nick/channel/server.
Note: in command, special variables are replaced:
$n: argument 'n' (between 1 and 9)
$-m: arguments from 1 to 'm'
$n-: arguments from 'n' to last
$n-m: arguments from 'n' to 'm'
$*: all arguments
$~: last argument
$nick: current nick
$channel: current channel
$server: current server
........................................

View File

@ -9,7 +9,15 @@
Sans paramètre, cette commande liste tous les alias définis.
Note: dans la commande, les variables spéciales $1, $2,..,$9 sont remplacés par les paramètres donnés par l'utilisateur, et $* est remplacé par tous les paramètres.
Les variables $nick, $channel et $server sont remplacées par le pseudo/canal/serveur courant.
Note: dans la commande, les variables spéciales sont remplacées :
$n: paramètre 'n' (entre 1 et 9)
$-m: paramètres de 1 à 'm'
$n-: paramètres de 'n' au dernier
$n-m: paramètres de 'n' à 'm'
$*: tous les paramètres
$~: le dernier paramètre
$nick: pseudo courant
$channel: canal courant
$server: serveur courant
........................................

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.1-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-09-30 17:50+0200\n"
"POT-Creation-Date: 2009-10-02 00:08+0200\n"
"PO-Revision-Date: 2009-09-14 10:56+0200\n"
"Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2354,10 +2354,16 @@ msgid ""
"\n"
"Without argument, this command lists all defined alias.\n"
"\n"
"Note: in command, special variables $1, $2,..,$9 are replaced by arguments "
"given by user, and $* is replaced by all arguments.\n"
"Variables $nick, $channel and $server are replaced by current nick/channel/"
"server."
"Note: in command, special variables are replaced:\n"
" $n: argument 'n' (between 1 and 9)\n"
" $-m: arguments from 1 to 'm'\n"
" $n-: arguments from 'n' to last\n"
" $n-m: arguments from 'n' to 'm'\n"
" $*: all arguments\n"
" $~: last argument\n"
" $nick: current nick\n"
" $channel: current channel\n"
" $server: current server"
msgstr ""
"jméno_aliasu: jméno aliasu\n"
" příkaz: jméno příkazu (více příkazů se rozděluje středníky)\n"

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.1-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-09-30 17:50+0200\n"
"POT-Creation-Date: 2009-10-02 00:08+0200\n"
"PO-Revision-Date: 2009-09-20 13:58+0200\n"
"Last-Translator: Thomas Schuetz <i18n@internet-villa.de>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2230,10 +2230,16 @@ msgid ""
"\n"
"Without argument, this command lists all defined alias.\n"
"\n"
"Note: in command, special variables $1, $2,..,$9 are replaced by arguments "
"given by user, and $* is replaced by all arguments.\n"
"Variables $nick, $channel and $server are replaced by current nick/channel/"
"server."
"Note: in command, special variables are replaced:\n"
" $n: argument 'n' (between 1 and 9)\n"
" $-m: arguments from 1 to 'm'\n"
" $n-: arguments from 'n' to last\n"
" $n-m: arguments from 'n' to 'm'\n"
" $*: all arguments\n"
" $~: last argument\n"
" $nick: current nick\n"
" $channel: current channel\n"
" $server: current server"
msgstr ""
"Aliasname: Name des Alias\n"
" Befehl: Befehlsname (WeeChat- oder IRC-Befehl ohne führenden '/', mehrere "

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.1-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-09-30 17:50+0200\n"
"POT-Creation-Date: 2009-10-02 00:08+0200\n"
"PO-Revision-Date: 2009-09-06 21:25+0200\n"
"Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2182,10 +2182,16 @@ msgid ""
"\n"
"Without argument, this command lists all defined alias.\n"
"\n"
"Note: in command, special variables $1, $2,..,$9 are replaced by arguments "
"given by user, and $* is replaced by all arguments.\n"
"Variables $nick, $channel and $server are replaced by current nick/channel/"
"server."
"Note: in command, special variables are replaced:\n"
" $n: argument 'n' (between 1 and 9)\n"
" $-m: arguments from 1 to 'm'\n"
" $n-: arguments from 'n' to last\n"
" $n-m: arguments from 'n' to 'm'\n"
" $*: all arguments\n"
" $~: last argument\n"
" $nick: current nick\n"
" $channel: current channel\n"
" $server: current server"
msgstr ""
"nombre_alias: nombre del seudónimo\n"
" comando: nombre del comando (comando WeeChat o IRC, sin el primer '/')\n"

View File

@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.1-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-09-30 17:50+0200\n"
"PO-Revision-Date: 2009-09-30 17:50+0200\n"
"POT-Creation-Date: 2009-10-02 00:08+0200\n"
"PO-Revision-Date: 2009-10-02 00:09+0200\n"
"Last-Translator: FlashCode <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"MIME-Version: 1.0\n"
@ -2409,10 +2409,16 @@ msgid ""
"\n"
"Without argument, this command lists all defined alias.\n"
"\n"
"Note: in command, special variables $1, $2,..,$9 are replaced by arguments "
"given by user, and $* is replaced by all arguments.\n"
"Variables $nick, $channel and $server are replaced by current nick/channel/"
"server."
"Note: in command, special variables are replaced:\n"
" $n: argument 'n' (between 1 and 9)\n"
" $-m: arguments from 1 to 'm'\n"
" $n-: arguments from 'n' to last\n"
" $n-m: arguments from 'n' to 'm'\n"
" $*: all arguments\n"
" $~: last argument\n"
" $nick: current nick\n"
" $channel: current channel\n"
" $server: current server"
msgstr ""
" nom_alias: nom de l'alias (peut démarrer ou se terminer par \"*\" pour une "
"liste d'alias)\n"
@ -2422,11 +2428,16 @@ msgstr ""
"\n"
"Sans paramètre, cette commande liste tous les alias définis.\n"
"\n"
"Note: dans la commande, les variables spéciales $1, $2,..,$9 sont remplacés "
"par les paramètres donnés par l'utilisateur, et $* est remplacé par tous les "
"paramètres.\n"
"Les variables $nick, $channel et $server sont remplacées par le pseudo/canal/"
"serveur courant."
"Note: dans la commande, les variables spéciales sont remplacées :\n"
" $n: paramètre 'n' (entre 1 et 9)\n"
" $-m: paramètres de 1 à 'm'\n"
" $n-: paramètres de 'n' au dernier\n"
" $n-m: paramètres de 'n' à 'm'\n"
" $*: tous les paramètres\n"
" $~: le dernier paramètre\n"
" $nick: pseudo courant\n"
" $channel: canal courant\n"
" $server: serveur courant"
msgid "remove aliases"
msgstr "supprimer des alias"

View File

@ -12,7 +12,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.1-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-09-30 17:50+0200\n"
"POT-Creation-Date: 2009-10-02 00:08+0200\n"
"PO-Revision-Date: 2009-09-20 13:51+0200\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2300,10 +2300,16 @@ msgid ""
"\n"
"Without argument, this command lists all defined alias.\n"
"\n"
"Note: in command, special variables $1, $2,..,$9 are replaced by arguments "
"given by user, and $* is replaced by all arguments.\n"
"Variables $nick, $channel and $server are replaced by current nick/channel/"
"server."
"Note: in command, special variables are replaced:\n"
" $n: argument 'n' (between 1 and 9)\n"
" $-m: arguments from 1 to 'm'\n"
" $n-: arguments from 'n' to last\n"
" $n-m: arguments from 'n' to 'm'\n"
" $*: all arguments\n"
" $~: last argument\n"
" $nick: current nick\n"
" $channel: current channel\n"
" $server: current server"
msgstr ""
" alias_név: az alias neve\n"
" parancs: parancs neve (WeeChat vagy IRC parancs, több parancs "

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.1-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-09-30 17:50+0200\n"
"POT-Creation-Date: 2009-10-02 00:08+0200\n"
"PO-Revision-Date: 2009-09-06 21:25+0200\n"
"Last-Translator: Krzysztof Korościk <soltys@szluug.org>\n"
"Language-Team: Polish\n"
@ -2388,10 +2388,16 @@ msgid ""
"\n"
"Without argument, this command lists all defined alias.\n"
"\n"
"Note: in command, special variables $1, $2,..,$9 are replaced by arguments "
"given by user, and $* is replaced by all arguments.\n"
"Variables $nick, $channel and $server are replaced by current nick/channel/"
"server."
"Note: in command, special variables are replaced:\n"
" $n: argument 'n' (between 1 and 9)\n"
" $-m: arguments from 1 to 'm'\n"
" $n-: arguments from 'n' to last\n"
" $n-m: arguments from 'n' to 'm'\n"
" $*: all arguments\n"
" $~: last argument\n"
" $nick: current nick\n"
" $channel: current channel\n"
" $server: current server"
msgstr ""
"nazwa_aliasu: nazwa aliasu\n"
" komenda: nazwa komendy (wiele komend można oddzielić za pomocą średnika)\n"

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.1-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-09-30 17:50+0200\n"
"POT-Creation-Date: 2009-10-02 00:08+0200\n"
"PO-Revision-Date: 2009-09-20 13:50+0200\n"
"Last-Translator: Pavel Shevchuk <stlwrt@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2313,10 +2313,16 @@ msgid ""
"\n"
"Without argument, this command lists all defined alias.\n"
"\n"
"Note: in command, special variables $1, $2,..,$9 are replaced by arguments "
"given by user, and $* is replaced by all arguments.\n"
"Variables $nick, $channel and $server are replaced by current nick/channel/"
"server."
"Note: in command, special variables are replaced:\n"
" $n: argument 'n' (between 1 and 9)\n"
" $-m: arguments from 1 to 'm'\n"
" $n-: arguments from 'n' to last\n"
" $n-m: arguments from 'n' to 'm'\n"
" $*: all arguments\n"
" $~: last argument\n"
" $nick: current nick\n"
" $channel: current channel\n"
" $server: current server"
msgstr ""
"сокращение: название сокращения\n"
" команда: название команды (команда WeeChat или IRC, несколько команд "

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-09-30 17:50+0200\n"
"POT-Creation-Date: 2009-10-02 00:08+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1968,10 +1968,16 @@ msgid ""
"\n"
"Without argument, this command lists all defined alias.\n"
"\n"
"Note: in command, special variables $1, $2,..,$9 are replaced by arguments "
"given by user, and $* is replaced by all arguments.\n"
"Variables $nick, $channel and $server are replaced by current nick/channel/"
"server."
"Note: in command, special variables are replaced:\n"
" $n: argument 'n' (between 1 and 9)\n"
" $-m: arguments from 1 to 'm'\n"
" $n-: arguments from 'n' to last\n"
" $n-m: arguments from 'n' to 'm'\n"
" $*: all arguments\n"
" $~: last argument\n"
" $nick: current nick\n"
" $channel: current channel\n"
" $server: current server"
msgstr ""
msgid "remove aliases"

View File

@ -34,6 +34,8 @@ WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE("GPL3");
#define ALIAS_IS_ARG_NUMBER(number) ((number >= '1') && (number <= '9'))
struct t_weechat_plugin *weechat_alias_plugin = NULL;
struct t_config_file *alias_config_file = NULL;
@ -87,12 +89,11 @@ alias_search (const char *alias_name)
}
/*
* alias_add_word: add word to string and increment length
* This function should NOT be called directly.
* alias_string_add_word: add word to string and increment length
*/
void
alias_add_word (char **alias, int *length, const char *word)
alias_string_add_word (char **alias, int *length, const char *word)
{
int length_word;
@ -117,15 +118,61 @@ alias_add_word (char **alias, int *length, const char *word)
}
/*
* alias_replace_args: replace arguments ($1, $2, .. or $*) in alias arguments
* alias_string_add_word_range: add word (in range) to string and increment
* length
*/
void
alias_string_add_word_range (char **alias, int *length, const char *start,
const char *end)
{
char *word;
word = weechat_strndup (start, end - start);
if (word)
{
alias_string_add_word (alias, length, word);
free (word);
}
}
/*
* alias_string_add_arguments: add some arguments to string and increment
* length
*/
void
alias_string_add_arguments (char **alias, int *length, char **argv, int start,
int end)
{
int i;
for (i = start; i <= end; i++)
{
if (i != start)
alias_string_add_word (alias, length, " ");
alias_string_add_word (alias, length, argv[i]);
}
}
/*
* alias_replace_args: replace arguments in alias
* arguments are:
* $n argument n
* $-m arguments from 1 to m
* $n- arguments from n to last
* $n-m arguments from n to m
* $* all arguments
* $~ last argument
* with n and m in 1..9
*/
char *
alias_replace_args (const char *alias_args, const char *user_args)
{
char **argv, *res, *word;
char **argv, *res;
const char *start, *pos;
int argc, length_res, args_count;
int n, m, argc, length_res, args_count, offset;
argv = weechat_string_split (user_args, " ", 0, 0, &argc);
@ -136,17 +183,13 @@ alias_replace_args (const char *alias_args, const char *user_args)
pos = start;
while (pos && pos[0])
{
offset = 0;
if ((pos[0] == '\\') && (pos[1] == '$'))
{
word = weechat_strndup (start, pos - start);
if (word)
{
alias_add_word (&res, &length_res, word);
free (word);
}
alias_add_word (&res, &length_res, "$");
start = pos + 2;
pos = start;
offset = 2;
alias_string_add_word_range (&res, &length_res, start, pos);
alias_string_add_word (&res, &length_res, "$");
}
else
{
@ -154,50 +197,87 @@ alias_replace_args (const char *alias_args, const char *user_args)
{
if (pos[1] == '*')
{
/* replace with all arguments */
args_count++;
offset = 2;
if (pos > start)
{
word = weechat_strndup (start, pos - start);
if (word)
{
alias_add_word (&res, &length_res, word);
free (word);
}
}
alias_add_word (&res, &length_res, user_args);
start = pos + 2;
pos = start;
alias_string_add_word_range (&res, &length_res, start, pos);
alias_string_add_word (&res, &length_res, user_args);
}
else
else if (pos[1] == '~')
{
if ((pos[1] >= '1') && (pos[1] <= '9'))
/* replace with last argument */
args_count++;
offset = 2;
if (pos > start)
alias_string_add_word_range (&res, &length_res, start, pos);
if (argc > 0)
alias_string_add_word (&res, &length_res, argv[argc - 1]);
}
else if ((pos[1] == '-') && ALIAS_IS_ARG_NUMBER(pos[2]))
{
/* replace with arguments 1 to m */
args_count++;
offset = 3;
if (pos > start)
alias_string_add_word_range (&res, &length_res, start, pos);
if (pos[2] - '1' < argc)
m = pos[2] - '1';
else
m = argc - 1;
alias_string_add_arguments (&res, &length_res, argv, 0, m);
}
else if (ALIAS_IS_ARG_NUMBER(pos[1]))
{
args_count++;
n = pos[1] - '1';
if (pos > start)
alias_string_add_word_range (&res, &length_res, start, pos);
if (pos[2] != '-')
{
args_count++;
if (pos > start)
{
word = weechat_strndup (start, pos - start);
if (word)
{
alias_add_word (&res, &length_res, word);
free (word);
}
}
if (pos[1] - '1' < argc)
alias_add_word (&res, &length_res, argv[pos[1] - '1']);
start = pos + 2;
pos = start;
/* replace with argument n */
offset = 2;
if (n < argc)
alias_string_add_word (&res, &length_res, argv[n]);
}
else
pos++;
{
if (ALIAS_IS_ARG_NUMBER(pos[3]))
{
/* replace with arguments n to m */
offset = 4;
if (pos[3] - '1' < argc)
m = pos[3] - '1';
else
m = argc - 1;
}
else
{
/* replace with arguments n to last */
offset = 3;
m = argc - 1;
}
if (n < argc)
{
alias_string_add_arguments (&res, &length_res,
argv, n, m);
}
}
}
}
else
pos++;
}
if (offset != 0)
{
pos += offset;
start = pos;
}
else
pos++;
}
if (start < pos)
alias_add_word (&res, &length_res, start);
if (pos > start)
alias_string_add_word (&res, &length_res, start);
if (argv)
weechat_string_free_split (argv);
@ -942,10 +1022,16 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
"Without argument, this command lists all "
"defined alias.\n\n"
"Note: in command, special variables "
"$1, $2,..,$9 are replaced by arguments given "
"by user, and $* is replaced by all arguments.\n"
"Variables $nick, $channel and $server are "
"replaced by current nick/channel/server."),
"are replaced:\n"
" $n: argument 'n' (between 1 and 9)\n"
" $-m: arguments from 1 to 'm'\n"
" $n-: arguments from 'n' to last\n"
" $n-m: arguments from 'n' to 'm'\n"
" $*: all arguments\n"
" $~: last argument\n"
" $nick: current nick\n"
" $channel: current channel\n"
" $server: current server"),
"%(alias) %(commands)",
&alias_command_cb, NULL);