int exec_buffer_input_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *input_data) { char **argv, **argv_eol; int argc; /* make C compiler happy */ (void) pointer; (void) data; /* close buffer */ if (strcmp (input_data, "q") == 0) { weechat_buffer_close (buffer); return WEECHAT_RC_OK; } argv = weechat_string_split (input_data, " ", 0, 0, &argc); argv_eol = weechat_string_split (input_data, " ", 1, 0, NULL); if (argv && argv_eol) exec_command_run (buffer, argc, argv, argv_eol, 0); if (argv) weechat_string_free_split (argv); if (argv_eol) weechat_string_free_split (argv_eol); return WEECHAT_RC_OK; }
int exec_command_exec (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { int i, length, count; char *text; struct t_exec_cmd *ptr_exec_cmd, *ptr_next_exec_cmd; /* make C compiler happy */ (void) data; (void) buffer; /* list running commands */ if ((argc == 1) || ((argc == 2) && (weechat_strcasecmp (argv[1], "-list") == 0))) { exec_command_list (); return WEECHAT_RC_OK; } /* send text to a running process */ if (weechat_strcasecmp (argv[1], "-in") == 0) { WEECHAT_COMMAND_MIN_ARGS(4, "-in"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd && ptr_exec_cmd->hook) { length = strlen (argv_eol[3]) + 1 + 1; text = malloc (length); if (text) { snprintf (text, length, "%s\n", argv_eol[3]); weechat_hook_set (ptr_exec_cmd->hook, "stdin", text); free (text); } } return WEECHAT_RC_OK; } /* send text to a running process (if given), then close stdin */ if (weechat_strcasecmp (argv[1], "-inclose") == 0) { WEECHAT_COMMAND_MIN_ARGS(3, "-inclose"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd && ptr_exec_cmd->hook) { if (argc > 3) { length = strlen (argv_eol[3]) + 1 + 1; text = malloc (length); if (text) { snprintf (text, length, "%s\n", argv_eol[3]); weechat_hook_set (ptr_exec_cmd->hook, "stdin", text); free (text); } } weechat_hook_set (ptr_exec_cmd->hook, "stdin_close", "1"); } return WEECHAT_RC_OK; } /* send a signal to a running process */ if (weechat_strcasecmp (argv[1], "-signal") == 0) { WEECHAT_COMMAND_MIN_ARGS(4, "-signal"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd) weechat_hook_set (ptr_exec_cmd->hook, "signal", argv[3]); return WEECHAT_RC_OK; } /* send a KILL signal to a running process */ if (weechat_strcasecmp (argv[1], "-kill") == 0) { WEECHAT_COMMAND_MIN_ARGS(3, "-kill"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd) weechat_hook_set (ptr_exec_cmd->hook, "signal", "kill"); return WEECHAT_RC_OK; } /* send a KILL signal to all running processes */ if (weechat_strcasecmp (argv[1], "-killall") == 0) { for (ptr_exec_cmd = exec_cmds; ptr_exec_cmd; ptr_exec_cmd = ptr_exec_cmd->next_cmd) { if (ptr_exec_cmd->hook) { weechat_hook_set (ptr_exec_cmd->hook, "signal", "kill"); } } return WEECHAT_RC_OK; } /* set a hook property */ if (weechat_strcasecmp (argv[1], "-set") == 0) { WEECHAT_COMMAND_MIN_ARGS(5, "-set"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd) weechat_hook_set (ptr_exec_cmd->hook, argv[3], argv_eol[4]); return WEECHAT_RC_OK; } /* delete terminated command(s) */ if (weechat_strcasecmp (argv[1], "-del") == 0) { WEECHAT_COMMAND_MIN_ARGS(3, "-del"); if (weechat_strcasecmp (argv[2], "-all") == 0) { count = 0; ptr_exec_cmd = exec_cmds; while (ptr_exec_cmd) { ptr_next_exec_cmd = ptr_exec_cmd->next_cmd; if (!ptr_exec_cmd->hook) { exec_free (ptr_exec_cmd); count++; } ptr_exec_cmd = ptr_next_exec_cmd; } weechat_printf (NULL, _("%d commands removed"), count); } else { for (i = 2; i < argc; i++) { ptr_exec_cmd = exec_search_by_id (argv[i]); if (ptr_exec_cmd) { if (ptr_exec_cmd->hook) { weechat_printf (NULL, _("%s%s: command with id \"%s\" is still " "running"), weechat_prefix ("error"), EXEC_PLUGIN_NAME, argv[i]); } else { exec_free (ptr_exec_cmd); weechat_printf (NULL, _("Command \"%s\" removed"), argv[i]); } } else { weechat_printf (NULL, _("%s%s: command id \"%s\" not found"), weechat_prefix ("error"), EXEC_PLUGIN_NAME, argv[i]); } } } return WEECHAT_RC_OK; } return exec_command_run (buffer, argc, argv, argv_eol, 1); }