diff options
author | Timo Sirainen <cras@irssi.org> | 2002-12-04 22:17:07 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2002-12-04 22:17:07 +0000 |
commit | 6230c055f2f2f62ffe4cd242105db938a9f030d5 (patch) | |
tree | 2167229e196df0607f380a87b5b8a31fa6524aad /src/perl/perl-signals.c | |
parent | 54000e19082a1fd9d8ad1e093e7ebcf23232721a (diff) | |
download | irssi-6230c055f2f2f62ffe4cd242105db938a9f030d5.zip |
Added Irssi::signal_register() to dynamically register new signals.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3045 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/perl/perl-signals.c')
-rw-r--r-- | src/perl/perl-signals.c | 67 |
1 files changed, 54 insertions, 13 deletions
diff --git a/src/perl/perl-signals.c b/src/perl/perl-signals.c index 6dcde221..85e537de 100644 --- a/src/perl/perl-signals.c +++ b/src/perl/perl-signals.c @@ -39,6 +39,7 @@ typedef struct { typedef struct { char *signal; char *args[7]; + int dynamic; } PERL_SIGNAL_ARGS_REC; #include "perl-signals-list.h" @@ -388,6 +389,34 @@ void perl_signals_stop(void) signals = NULL; } +static void register_signal_rec(PERL_SIGNAL_ARGS_REC *rec) +{ + if (rec->signal[strlen(rec->signal)-1] == ' ') { + perl_signal_args_partial = + g_slist_append(perl_signal_args_partial, rec); + } else { + int signal_id = signal_get_uniq_id(rec->signal); + g_hash_table_insert(perl_signal_args_hash, + GINT_TO_POINTER(signal_id), rec); + } +} + +void perl_signal_register(const char *signal, const char **args) +{ + PERL_SIGNAL_ARGS_REC *rec; + int i; + + if (perl_signal_args_find(signal_get_uniq_id(signal)) != NULL) + return; + + rec = g_new0(PERL_SIGNAL_ARGS_REC, 1); + for (i = 0; i < 6 && args[i] != NULL; i++) + rec->args[i] = g_strdup(args[i]); + rec->dynamic = TRUE; + rec->signal = g_strdup(signal); + register_signal_rec(rec); +} + void perl_signals_init(void) { int n; @@ -396,23 +425,35 @@ void perl_signals_init(void) (GCompareFunc) g_direct_equal); perl_signal_args_partial = NULL; - for (n = 0; perl_signal_args[n].signal != NULL; n++) { - PERL_SIGNAL_ARGS_REC *rec = &perl_signal_args[n]; + for (n = 0; perl_signal_args[n].signal != NULL; n++) + register_signal_rec(&perl_signal_args[n]); +} - if (rec->signal[strlen(rec->signal)-1] == ' ') { - perl_signal_args_partial = - g_slist_append(perl_signal_args_partial, rec); - } else { - int signal_id = signal_get_uniq_id(rec->signal); - g_hash_table_insert(perl_signal_args_hash, - GINT_TO_POINTER(signal_id), - rec); - } - } +static void signal_args_free(PERL_SIGNAL_ARGS_REC *rec) +{ + int i; + + if (!rec->dynamic) + return; + + for (i = 0; i < 6 && rec->args[i] != NULL; i++) + g_free(rec->args[i]); + g_free(rec->signal); + g_free(rec); +} + +static void signal_args_hash_free(void *key, PERL_SIGNAL_ARGS_REC *rec) +{ + signal_args_free(rec); } void perl_signals_deinit(void) { - g_slist_free(perl_signal_args_partial); + g_slist_foreach(perl_signal_args_partial, + (GFunc) signal_args_free, NULL); + g_slist_free(perl_signal_args_partial); + + g_hash_table_foreach(perl_signal_args_hash, + (GHFunc) signal_args_hash_free, NULL); g_hash_table_destroy(perl_signal_args_hash); } |