diff options
Diffstat (limited to 'src/plugins/scripts/ruby/weechat-ruby.c')
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby.c | 158 |
1 files changed, 79 insertions, 79 deletions
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index b922de84f..8e66db21e 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -113,12 +113,12 @@ weechat_ruby_hashtable_map_cb (void *data, const void *value) { VALUE *hash; - + /* make C compiler happy */ (void) hashtable; - + hash = (VALUE *)data; - + rb_hash_aset (hash[0], rb_str_new2 ((char *)key), rb_str_new2 ((char *)value)); } @@ -139,7 +139,7 @@ weechat_ruby_hashtable_to_hash (struct t_hashtable *hashtable) weechat_hashtable_map (hashtable, &weechat_ruby_hashtable_map_cb, &hash); - + return hash; } @@ -147,7 +147,7 @@ int weechat_ruby_hash_foreach_cb (VALUE key, VALUE value, void *arg) { struct t_hashtable *hashtable; - + hashtable = (struct t_hashtable *)arg; if ((TYPE(key) == T_STRING) && (TYPE(value) == T_STRING)) { @@ -169,7 +169,7 @@ struct t_hashtable * weechat_ruby_hash_to_hashtable (VALUE hash, int hashtable_size) { struct t_hashtable *hashtable; - + hashtable = weechat_hashtable_new (hashtable_size, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, @@ -177,10 +177,10 @@ weechat_ruby_hash_to_hashtable (VALUE hash, int hashtable_size) NULL); if (!hashtable) return NULL; - + rb_hash_foreach (hash, &weechat_ruby_hash_foreach_cb, (unsigned long)hashtable); - + return hashtable; } @@ -205,7 +205,7 @@ VALUE rb_protect_funcall (VALUE recv, ID mid, int *state, int argc, VALUE *argv) { struct protect_call_arg arg; - + arg.recv = recv; arg.mid = mid; arg.argc = argc; @@ -227,7 +227,7 @@ weechat_ruby_print_exception (VALUE err) char* cline; char* err_msg; char* err_class; - + backtrace = rb_protect_funcall (err, rb_intern("backtrace"), &ruby_error, 0, NULL); @@ -238,7 +238,7 @@ weechat_ruby_print_exception (VALUE err) &ruby_error, 0, NULL), rb_intern("name"), &ruby_error, 0, NULL); err_class = StringValuePtr(tmp2); - + if (strcmp (err_class, "SyntaxError") == 0) { tmp3 = rb_inspect(err); @@ -285,12 +285,12 @@ weechat_ruby_print_exception (VALUE err) weechat_prefix ("error"), RUBY_PLUGIN_NAME, cline); } - + if (cline) free (cline); } } - + return 0; } @@ -308,10 +308,10 @@ weechat_ruby_exec (struct t_plugin_script *script, VALUE argv2[16]; void *ret_value; struct t_plugin_script *old_ruby_current_script; - + old_ruby_current_script = ruby_current_script; ruby_current_script = script; - + argc = 0; if (format && format[0]) { @@ -332,7 +332,7 @@ weechat_ruby_exec (struct t_plugin_script *script, } } } - + if (argc > 0) { rc = rb_protect_funcall ((VALUE) script->interpreter, @@ -345,19 +345,19 @@ weechat_ruby_exec (struct t_plugin_script *script, rb_intern(function), &ruby_error, 0, NULL); } - + if (ruby_error) { weechat_printf (NULL, weechat_gettext ("%s%s: unable to run function \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, function); - + err = rb_gv_get("$!"); weechat_ruby_print_exception(err); - + return NULL; } - + if ((TYPE(rc) == T_STRING) && (ret_type == WEECHAT_SCRIPT_EXEC_STRING)) { if (StringValuePtr (rc)) @@ -386,7 +386,7 @@ weechat_ruby_exec (struct t_plugin_script *script, ruby_current_script = old_ruby_current_script; return WEECHAT_RC_OK; } - + if (ret_value == NULL) { weechat_printf (NULL, @@ -396,9 +396,9 @@ weechat_ruby_exec (struct t_plugin_script *script, ruby_current_script = old_ruby_current_script; return NULL; } - + ruby_current_script = old_ruby_current_script; - + return ret_value; } @@ -410,12 +410,12 @@ static VALUE weechat_ruby_output (VALUE self, VALUE str) { char *msg, *p, *m; - + /* make C compiler happy */ (void) self; - + msg = strdup(StringValuePtr(str)); - + m = msg; while ((p = strchr (m, '\n')) != NULL) { @@ -431,7 +431,7 @@ weechat_ruby_output (VALUE self, VALUE str) ruby_buffer_output[0] = '\0'; m = ++p; } - + if (strlen(m) + strlen(ruby_buffer_output) > sizeof(ruby_buffer_output)) { weechat_printf (NULL, @@ -445,7 +445,7 @@ weechat_ruby_output (VALUE self, VALUE str) if (msg) free (msg); - + return Qnil; } @@ -458,7 +458,7 @@ weechat_ruby_output_flush (VALUE self) { /* make C compiler happy */ (void) self; - + return Qnil; } @@ -473,7 +473,7 @@ weechat_ruby_load (const char *filename) VALUE curModule, ruby_retcode, err, argv[1]; int ruby_error; struct stat buf; - + if (stat (filename, &buf) != 0) { weechat_printf (NULL, @@ -481,17 +481,17 @@ weechat_ruby_load (const char *filename) weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); return 0; } - + if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet) { weechat_printf (NULL, weechat_gettext ("%s: loading script \"%s\""), RUBY_PLUGIN_NAME, filename); } - + ruby_current_script = NULL; ruby_registered_script = NULL; - + snprintf (modname, sizeof(modname), "%s%d", MOD_NAME_PREFIX, ruby_num); ruby_num++; @@ -502,14 +502,14 @@ weechat_ruby_load (const char *filename) argv[0] = rb_str_new2 (filename); ruby_retcode = rb_protect_funcall (curModule, rb_intern("load_eval_file"), &ruby_error, 1, argv); - + if (ruby_retcode == Qnil) { err = rb_gv_get("$!"); weechat_ruby_print_exception(err); return 0; } - + if (NUM2INT(ruby_retcode) != 0) { switch (NUM2INT(ruby_retcode)) @@ -542,20 +542,20 @@ weechat_ruby_load (const char *filename) { weechat_ruby_print_exception(rb_iv_get(curModule, "@load_eval_file_error")); } - + return 0; } - + (void) rb_protect_funcall (curModule, rb_intern("weechat_init"), &ruby_error, 0, NULL); - + if (ruby_error) { weechat_printf (NULL, weechat_gettext ("%s%s: unable to eval function " "\"weechat_init\" in file \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); - + err = rb_gv_get("$!"); weechat_ruby_print_exception(err); @@ -568,7 +568,7 @@ weechat_ruby_load (const char *filename) return 0; } - + if (!ruby_registered_script) { weechat_printf (NULL, @@ -578,10 +578,10 @@ weechat_ruby_load (const char *filename) return 0; } ruby_current_script = ruby_registered_script; - + ruby_current_script->interpreter = (VALUE *) curModule; rb_gc_register_address (ruby_current_script->interpreter); - + /* * set input/close callbacks for buffers created by this script * (to restore callbacks after upgrade) @@ -591,7 +591,7 @@ weechat_ruby_load (const char *filename) ruby_current_script, &weechat_ruby_api_buffer_input_data_cb, &weechat_ruby_api_buffer_close_cb); - + return 1; } @@ -604,7 +604,7 @@ weechat_ruby_load_cb (void *data, const char *filename) { /* make C compiler happy */ (void) data; - + weechat_ruby_load (filename); } @@ -617,14 +617,14 @@ weechat_ruby_unload (struct t_plugin_script *script) { int *rc; void *interpreter; - + if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet) { weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), RUBY_PLUGIN_NAME, script->name); } - + if (script->shutdown_func && script->shutdown_func[0]) { rc = (int *)weechat_ruby_exec (script, @@ -634,16 +634,16 @@ weechat_ruby_unload (struct t_plugin_script *script) if (rc) free (rc); } - + interpreter = script->interpreter; - + if (ruby_current_script == script) ruby_current_script = (ruby_current_script->prev_script) ? ruby_current_script->prev_script : ruby_current_script->next_script; - + script_remove (weechat_ruby_plugin, &ruby_scripts, &last_ruby_script, script); - + if (interpreter) rb_gc_unregister_address (interpreter); } @@ -656,7 +656,7 @@ void weechat_ruby_unload_name (const char *name) { struct t_plugin_script *ptr_script; - + ptr_script = script_search (weechat_ruby_plugin, ruby_scripts, name); if (ptr_script) { @@ -682,7 +682,7 @@ weechat_ruby_reload_name (const char *name) { struct t_plugin_script *ptr_script; char *filename; - + ptr_script = script_search (weechat_ruby_plugin, ruby_scripts, name); if (ptr_script) { @@ -727,11 +727,11 @@ weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *path_script; - + /* make C compiler happy */ (void) data; (void) buffer; - + if (argc == 1) { script_display_list (weechat_ruby_plugin, ruby_scripts, @@ -802,7 +802,7 @@ weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer, weechat_prefix ("error"), RUBY_PLUGIN_NAME, "ruby"); } } - + return WEECHAT_RC_OK; } @@ -819,9 +819,9 @@ weechat_ruby_completion_cb (void *data, const char *completion_item, (void) data; (void) completion_item; (void) buffer; - + script_completion (weechat_ruby_plugin, completion, ruby_scripts); - + return WEECHAT_RC_OK; } @@ -835,17 +835,17 @@ weechat_ruby_infolist_cb (void *data, const char *infolist_name, { /* make C compiler happy */ (void) data; - + if (!infolist_name || !infolist_name[0]) return NULL; - + if (weechat_strcasecmp (infolist_name, "ruby_script") == 0) { return script_infolist_list_scripts (weechat_ruby_plugin, ruby_scripts, pointer, arguments); } - + return NULL; } @@ -861,13 +861,13 @@ weechat_ruby_signal_debug_dump_cb (void *data, const char *signal, (void) data; (void) signal; (void) type_data; - + if (!signal_data || (weechat_strcasecmp ((char *)signal_data, RUBY_PLUGIN_NAME) == 0)) { script_print_log (weechat_ruby_plugin, ruby_scripts); } - + return WEECHAT_RC_OK; } @@ -883,10 +883,10 @@ weechat_ruby_signal_buffer_closed_cb (void *data, const char *signal, (void) data; (void) signal; (void) type_data; - + if (signal_data) script_remove_buffer_callbacks (ruby_scripts, signal_data); - + return WEECHAT_RC_OK; } @@ -918,7 +918,7 @@ weechat_ruby_timer_action_cb (void *data, int remaining_calls) &ruby_action_remove_list); } } - + return WEECHAT_RC_OK; } @@ -934,7 +934,7 @@ weechat_ruby_signal_script_action_cb (void *data, const char *signal, { /* make C compiler happy */ (void) data; - + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { if (strcmp (signal, "ruby_script_install") == 0) @@ -954,7 +954,7 @@ weechat_ruby_signal_script_action_cb (void *data, const char *signal, &ruby_action_remove_list); } } - + return WEECHAT_RC_OK; } @@ -1023,25 +1023,25 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) " end\n" "end\n" }; - + weechat_ruby_plugin = plugin; - + ruby_error = 0; - + /* init stdout/stderr buffer */ ruby_buffer_output[0] = '\0'; - + #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 RUBY_INIT_STACK; #endif - + ruby_init (); ruby_init_loadpath (); ruby_script ("__weechat_plugin__"); - + ruby_mWeechat = rb_define_module("Weechat"); weechat_ruby_api_init (ruby_mWeechat); - + /* redirect stdin and stdout */ ruby_mWeechatOutputs = rb_define_module("WeechatOutputs"); rb_define_singleton_method(ruby_mWeechatOutputs, "write", @@ -1064,7 +1064,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_ruby_print_exception(err); return WEECHAT_RC_ERROR; } - + ruby_quiet = 1; script_init (weechat_ruby_plugin, argc, @@ -1077,10 +1077,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) &weechat_ruby_signal_script_action_cb, &weechat_ruby_load_cb); ruby_quiet = 0; - + script_display_short_list (weechat_ruby_plugin, ruby_scripts); - + /* init ok */ return WEECHAT_RC_OK; } @@ -1096,8 +1096,8 @@ weechat_plugin_end (struct t_weechat_plugin *plugin) ruby_quiet = 1; script_end (plugin, &ruby_scripts, &weechat_ruby_unload_all); ruby_quiet = 0; - + ruby_cleanup (0); - + return WEECHAT_RC_OK; } |