diff options
author | Emanuele Giaquinta <exg@irssi.org> | 2008-11-11 23:33:47 +0000 |
---|---|---|
committer | exg <exg@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2008-11-11 23:33:47 +0000 |
commit | f0647439a9fbcc0387856c21a83bec4668d6bf56 (patch) | |
tree | c99c32a7669b346b40e3e8c13372bd14a52c0d6c | |
parent | f4e9745c9f5f4f9e4c5f9c7d1ab9c88481577eeb (diff) | |
download | irssi-f0647439a9fbcc0387856c21a83bec4668d6bf56.zip |
Add Irssi::command_parse_options function to parse options for a command which
have been set with Irssi::command_set_options.
git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@4896 dbcabf3a-b0e7-0310-adc4-f8d773084564
-rw-r--r-- | docs/perl.txt | 14 | ||||
-rw-r--r-- | src/perl/common/Core.xs | 30 |
2 files changed, 44 insertions, 0 deletions
diff --git a/docs/perl.txt b/docs/perl.txt index ad899cf0..c5f1726b 100644 --- a/docs/perl.txt +++ b/docs/perl.txt @@ -351,6 +351,20 @@ command_runsub(cmd, data, server, item) command_unbind(cmd, func) Unbind command `cmd' from function 'func. +command_set_options(cmd, data) + Set options for command `cmd' to `data'. `data' is a string of + space separated words which specify the options. Each word can be + optionally prefixed with one of the following character: + + '-': optional argument + '+': argument required + '@': optional numeric argument + +command_parse_options(cmd, data) + Parse options for command `cmd' in `data'. It returns a reference to + an hash table with the options and a string with the remaining part + of `data'. On error it returns the undefined value. + *** Windows diff --git a/src/perl/common/Core.xs b/src/perl/common/Core.xs index 451a07e2..c1e526bb 100644 --- a/src/perl/common/Core.xs +++ b/src/perl/common/Core.xs @@ -57,6 +57,14 @@ static void handle_command_bind(int priority, int items, SV *p0, SV *p1, SV *p2) } } +static void add_tuple(gpointer key_, gpointer value_, gpointer user_data) +{ + HV *hash = user_data; + char *key = key_; + char *value = value_; + hv_store(hash, key, strlen(key), new_pv(value), 0); +} + MODULE = Irssi::Core PACKAGE = Irssi PROTOTYPES: ENABLE @@ -553,6 +561,28 @@ command_set_options(cmd, options) char *options void +command_parse_options(cmd, data) + char *cmd + char *data +PREINIT: + HV *hash; + GHashTable *optlist; + void *free_arg; + char *ptr; +PPCODE: + if (cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST, + cmd, &optlist, &ptr)) { + hash = newHV(); + g_hash_table_foreach(optlist, add_tuple, hash); + XPUSHs(sv_2mortal(newRV_noinc((SV*)hash))); + XPUSHs(sv_2mortal(new_pv(ptr))); + cmd_params_free(free_arg); + } else { + XPUSHs(&PL_sv_undef); + XPUSHs(&PL_sv_undef); + } + +void pidwait_add(pid) int pid |