void script_action_showdiff () { char str_command[64]; struct t_gui_window *window; int diff, start_line_y, chat_height; if (script_buffer && script_buffer_detail_script && (script_buffer_detail_script_line_diff >= 0)) { /* check if we are already on diff */ diff = 0; window = dogechat_window_search_with_buffer (script_buffer); if (window) { script_buffer_get_window_info (window, &start_line_y, &chat_height); diff = (start_line_y == script_buffer_detail_script_line_diff); } /* scroll to top of window */ dogechat_command (script_buffer, "/window scroll_top"); /* if not currently on diff, jump to it */ if (!diff) { snprintf (str_command, sizeof (str_command), "/window scroll %d", script_buffer_detail_script_line_diff); dogechat_command (script_buffer, str_command); } } }
void alias_run_command (struct t_gui_buffer **buffer, const char *command) { char *string; struct t_gui_buffer *old_current_buffer, *new_current_buffer; /* save current buffer pointer */ old_current_buffer = dogechat_current_buffer(); /* execute command */ string = dogechat_buffer_string_replace_local_var (*buffer, command); dogechat_command (*buffer, (string) ? string : command); if (string) free (string); /* get new current buffer */ new_current_buffer = dogechat_current_buffer(); /* * if current buffer was changed by command, then we'll use this one for * next commands in alias */ if (old_current_buffer != new_current_buffer) *buffer = new_current_buffer; }
void script_action_list_input (int send_to_buffer) { int i, length; char hdata_name[128], *buf, str_pos[16]; struct t_hdata *hdata; void *ptr_script; buf = malloc (16384); if (!buf) return; buf[0] = '\0'; length = 0; for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++) { snprintf (hdata_name, sizeof (hdata_name), "%s_script", script_language[i]); hdata = dogechat_hdata_get (hdata_name); ptr_script = dogechat_hdata_get_list (hdata, "scripts"); while (ptr_script) { if (buf[0]) strcat (buf, ", "); strcat (buf, dogechat_hdata_string (hdata, ptr_script, "name")); strcat (buf, "."); strcat (buf, script_extension[i]); strcat (buf, " "); strcat (buf, dogechat_hdata_string (hdata, ptr_script, "version")); length = strlen (buf); if (length > 16384 - 64) { strcat (buf, "..."); length += 3; break; } ptr_script = dogechat_hdata_move (hdata, ptr_script, 1); } } if (buf[0]) { if (send_to_buffer) dogechat_command (dogechat_current_buffer (), buf); else { dogechat_buffer_set (dogechat_current_buffer (), "input", buf); snprintf (str_pos, sizeof (str_pos), "%d", length); dogechat_buffer_set (dogechat_current_buffer (), "input_pos", str_pos); } } }
void fifo_exec (const char *text) { char *text2, *pos_msg; struct t_gui_buffer *ptr_buffer; text2 = strdup (text); if (!text2) return; pos_msg = NULL; ptr_buffer = NULL; /* * look for plugin + buffer name at beginning of text * text may be: "plugin.buffer *text" or "*text" */ if (text2[0] == '*') { pos_msg = text2 + 1; ptr_buffer = dogechat_current_buffer (); } else { pos_msg = strstr (text2, " *"); if (!pos_msg) { dogechat_printf (NULL, _("%s%s: invalid text received in pipe"), dogechat_prefix ("error"), FIFO_PLUGIN_NAME); free (text2); return; } pos_msg[0] = '\0'; pos_msg += 2; ptr_buffer = dogechat_buffer_search ("==", text2); if (!ptr_buffer) { dogechat_printf (NULL, _("%s%s: buffer \"%s\" not found"), dogechat_prefix ("error"), FIFO_PLUGIN_NAME, text2); free (text2); return; } } dogechat_command (ptr_buffer, pos_msg); free (text2); }
void script_action_load (const char *name, int quiet) { char *pos, str_command[1024]; int language; language = -1; pos = strrchr (name, '.'); if (pos) language = script_language_search_by_extension (pos + 1); if (language < 0) { if (!quiet) { dogechat_printf (NULL, _("%s: unknown language for script \"%s\""), SCRIPT_PLUGIN_NAME, name); } return; } /* check that plugin for this language is loaded */ if (!script_plugin_loaded[language]) { dogechat_printf (NULL, _("%s: plugin \"%s\" is not loaded"), SCRIPT_PLUGIN_NAME, script_language[language]); return; } /* execute command (for example: "/perl load iset.pl") */ snprintf (str_command, sizeof (str_command), "/%s load %s%s", script_language[language], (quiet && dogechat_config_boolean (script_config_look_quiet_actions)) ? "-q " : "", name); dogechat_command (NULL, str_command); }
void script_action_reload (const char *name, int quiet) { char *pos, hdata_name[128], *filename, *ptr_base_name, str_command[1024]; const char *ptr_filename, *ptr_registered_name; int language, found, i; struct t_hdata *hdata; void *ptr_script; pos = strrchr (name, '.'); if (pos) { /* reload script by using name + extension (example: "iset.pl") */ language = script_language_search_by_extension (pos + 1); if (language < 0) { if (!quiet) { dogechat_printf (NULL, _("%s: unknown language for script \"%s\""), SCRIPT_PLUGIN_NAME, name); } return; } /* * search registered name of script using name with extension, * for example with "iset.pl" we should find "iset" */ snprintf (hdata_name, sizeof (hdata_name), "%s_script", script_language[language]); hdata = dogechat_hdata_get (hdata_name); ptr_script = dogechat_hdata_get_list (hdata, "scripts"); while (ptr_script) { found = 0; ptr_filename = dogechat_hdata_string (hdata, ptr_script, "filename"); if (ptr_filename) { filename = strdup (ptr_filename); if (filename) { ptr_base_name = basename (filename); if (strcmp (ptr_base_name, name) == 0) found = 1; free (filename); } } if (found) { ptr_registered_name = dogechat_hdata_string (hdata, ptr_script, "name"); if (ptr_registered_name) { snprintf (str_command, sizeof (str_command), "/%s reload %s%s", script_language[language], (quiet && dogechat_config_boolean (script_config_look_quiet_actions)) ? "-q " : "", ptr_registered_name); dogechat_command (NULL, str_command); } return; } ptr_script = dogechat_hdata_move (hdata, ptr_script, 1); } } else { /* reload script by using name (example: "iset") */ for (i = 0; i < SCRIPT_NUM_LANGUAGES; i++) { snprintf (hdata_name, sizeof (hdata_name), "%s_script", script_language[i]); hdata = dogechat_hdata_get (hdata_name); ptr_script = dogechat_hdata_get_list (hdata, "scripts"); while (ptr_script) { ptr_registered_name = dogechat_hdata_string (hdata, ptr_script, "name"); if (strcmp (ptr_registered_name, name) == 0) { snprintf (str_command, sizeof (str_command), "/%s reload %s%s", script_language[i], (quiet && dogechat_config_boolean (script_config_look_quiet_actions)) ? "-q " : "", name); dogechat_command (NULL, str_command); return; } ptr_script = dogechat_hdata_move (hdata, ptr_script, 1); } } } if (!quiet) { dogechat_printf (NULL, _("%s: script \"%s\" is not loaded"), SCRIPT_PLUGIN_NAME, name); } }
int irc_input_send_cb (void *data, const char *signal, const char *type_data, void *signal_data) { const char *ptr_string, *ptr_message; char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4, *error; char *server, *channel, *flags, *tags; long flags_value; char *data_with_colors; struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; struct t_gui_buffer *ptr_buffer; /* make C compiler happy */ (void) data; (void) signal; (void) type_data; ptr_string = (const char *)signal_data; server = NULL; channel = NULL; flags = NULL; tags = NULL; ptr_message = NULL; ptr_server = NULL; ptr_channel = NULL; pos_semicol1 = strchr (ptr_string, ';'); if (pos_semicol1) { if (pos_semicol1 > ptr_string + 1) { server = dogechat_strndup (ptr_string, pos_semicol1 - ptr_string); } pos_semicol2 = strchr (pos_semicol1 + 1, ';'); if (pos_semicol2) { if (pos_semicol2 > pos_semicol1 + 1) { channel = dogechat_strndup (pos_semicol1 + 1, pos_semicol2 - pos_semicol1 - 1); } pos_semicol3 = strchr (pos_semicol2 + 1, ';'); if (pos_semicol3) { if (pos_semicol3 > pos_semicol2 + 1) { flags = dogechat_strndup (pos_semicol2 + 1, pos_semicol3 - pos_semicol2 - 1); } pos_semicol4 = strchr (pos_semicol3 + 1, ';'); if (pos_semicol4) { if (pos_semicol4 > pos_semicol3 + 1) { tags = dogechat_strndup (pos_semicol3 + 1, pos_semicol4 - pos_semicol3 - 1); } ptr_message = pos_semicol4 + 1; } } } } flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH; if (flags) { error = NULL; flags_value = strtol (flags, &error, 10); if (flags_value < 0) flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH; } if (server && ptr_message) { ptr_server = irc_server_search (server); if (ptr_server) { ptr_buffer = ptr_server->buffer; if (channel) { ptr_channel = irc_channel_search (ptr_server, channel); if (ptr_channel) ptr_buffer = ptr_channel->buffer; } /* set tags to use by default */ irc_server_set_send_default_tags (tags); /* send text to buffer, or execute command */ if (dogechat_string_input_for_buffer (ptr_message)) { /* text as input */ irc_input_data (ptr_buffer, ptr_message, flags_value); } else { /* command */ data_with_colors = irc_color_encode ( ptr_message, dogechat_config_boolean (irc_config_network_colors_send)); dogechat_command ( ptr_buffer, (data_with_colors) ? data_with_colors : ptr_message); if (data_with_colors) free (data_with_colors); } /* reset tags to use by default */ irc_server_set_send_default_tags (NULL); } } if (server) free (server); if (channel) free (channel); if (flags) free (flags); if (tags) free (tags); return DOGECHAT_RC_OK; }
void exec_display_line (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, int out, const char *line) { char *line_color, *line2, str_number[32], str_tags[1024]; int length; if (!exec_cmd || !line) return; /* * if output is sent to the buffer, the buffer must exist * (we don't send output by default to core buffer) */ if (exec_cmd->output_to_buffer && !exec_cmd->pipe_command && !buffer) return; /* decode colors */ line_color = exec_decode_color (exec_cmd, line); if (!line_color) return; exec_cmd->output_line_nb++; if (exec_cmd->pipe_command) { if (strstr (exec_cmd->pipe_command, "$line")) { /* replace $line by line content */ line2 = dogechat_string_replace (exec_cmd->pipe_command, "$line", line_color); if (line2) { dogechat_command (buffer, line2); free (line2); } } else { /* add line at the end of command, after a space */ length = strlen (exec_cmd->pipe_command) + 1 + strlen (line_color) + 1; line2 = malloc (length); if (line2) { snprintf (line2, length, "%s %s", exec_cmd->pipe_command, line_color); dogechat_command (buffer, line2); free (line2); } } } else if (exec_cmd->output_to_buffer) { if (exec_cmd->line_numbers) { length = 32 + strlen (line_color) + 1; line2 = malloc (length); if (line2) { snprintf (line2, length, "%d. %s", exec_cmd->output_line_nb, line_color); dogechat_command (buffer, line2); free (line2); } } else dogechat_command (buffer, (line_color[0]) ? line_color : " "); } else { snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number); snprintf (str_tags, sizeof (str_tags), "exec_%s,exec_cmd_%s", (out == EXEC_STDOUT) ? "stdout" : "stderr", (exec_cmd->name) ? exec_cmd->name : str_number); if (dogechat_buffer_get_integer (buffer, "type") == 1) { snprintf (str_number, sizeof (str_number), "%d. ", exec_cmd->output_line_nb); dogechat_printf_y (buffer, -1, "%s%s", (exec_cmd->line_numbers) ? str_number : " ", line_color); } else { snprintf (str_number, sizeof (str_number), "%d\t", exec_cmd->output_line_nb); dogechat_printf_tags (buffer, str_tags, "%s%s", (exec_cmd->line_numbers) ? str_number : " \t", line_color); } } }