Exemple #1
0
void
gui_chat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...)
{
    struct t_gui_line *ptr_line;
    int i, num_lines_to_add;

    if (!gui_buffer_valid (buffer))
        return;

    if (gui_init_ok)
    {
        if (!buffer)
            buffer = gui_buffer_search_main ();

        if (!buffer || buffer->closing)
            return;

        if (buffer->type != GUI_BUFFER_TYPE_FREE)
            buffer = gui_buffers;

        if (buffer->type != GUI_BUFFER_TYPE_FREE)
            return;
    }

    weechat_va_format (message);
    if (!vbuffer)
        return;

    utf8_normalize (vbuffer, '?');

    /* no message: delete line */
    if (!vbuffer[0])
    {
        if (gui_init_ok && (y >= 0))
        {
            for (ptr_line = buffer->own_lines->first_line; ptr_line;
                 ptr_line = ptr_line->next_line)
            {
                if (ptr_line->data->y >= y)
                    break;
            }
            if (ptr_line && (ptr_line->data->y == y))
            {
                if (ptr_line->next_line)
                    gui_line_clear (ptr_line);
                else
                    gui_line_free (buffer, ptr_line);
                gui_buffer_ask_chat_refresh (buffer, 2);
            }
        }
    }
    else
    {
        if (gui_init_ok)
        {
            /* if y is negative, add a line -N lines after the last line */
            if (y < 0)
            {
                y = (buffer->own_lines && buffer->own_lines->last_line) ?
                    buffer->own_lines->last_line->data->y - y : (-1 * y) - 1;
            }
            /* compute the number of lines to add before y */
            if (buffer->own_lines && buffer->own_lines->last_line)
                num_lines_to_add = y - buffer->own_lines->last_line->data->y - 1;
            else
                num_lines_to_add = y;
            if (num_lines_to_add > 0)
            {
                /*
                 * add empty line(s) before asked line, to ensure there is at
                 * least "y" lines in buffer, and then be able to scroll
                 * properly buffer page by page
                 */
                for (i = y - num_lines_to_add; i < y; i++)
                {
                    gui_line_add_y (buffer, i, "");
                }
            }
            gui_line_add_y (buffer, y, vbuffer);
            gui_buffer_ask_chat_refresh (buffer, 1);
        }
        else
            string_fprintf (stdout, "%s\n", vbuffer);
    }

    free (vbuffer);
}
Exemple #2
0
void
gui_chat_printf_date_tags (struct t_gui_buffer *buffer, time_t date,
                           const char *tags, const char *message, ...)
{
    time_t date_printed;
    int display_time, length, at_least_one_message_printed, msg_discarded;
    char *pos, *pos_prefix, *pos_tab, *pos_end, *pos_lines;
    char *modifier_data, *new_msg, *ptr_msg, *lines_waiting;
    struct t_gui_line *ptr_line;

    if (!message)
        return;

    if (!gui_buffer_valid (buffer))
        return;

    if (gui_init_ok)
    {
        if (!buffer)
            buffer = gui_buffer_search_main ();

        if (!buffer || buffer->closing)
            return;

        if (buffer->type != GUI_BUFFER_TYPE_FORMATTED)
            buffer = gui_buffers;

        if (buffer->type != GUI_BUFFER_TYPE_FORMATTED)
            return;
    }

    /* if mute is enabled for buffer (or all buffers), then just return */
    if ((gui_chat_mute == GUI_CHAT_MUTE_ALL_BUFFERS)
        || ((gui_chat_mute == GUI_CHAT_MUTE_BUFFER)
            && (gui_chat_mute_buffer == buffer)))
        return;

    weechat_va_format (message);
    if (!vbuffer)
        return;

    utf8_normalize (vbuffer, '?');

    date_printed = time (NULL);
    if (date <= 0)
        date = date_printed;

    at_least_one_message_printed = 0;

    pos = vbuffer;
    while (pos)
    {
        /* display until next end of line */
        pos_end = strchr (pos, '\n');
        if (pos_end)
            pos_end[0] = '\0';

        /* call modifier for message printed ("weechat_print") */
        new_msg = NULL;
        msg_discarded = 0;
        if (buffer)
        {
            length = strlen (gui_buffer_get_plugin_name (buffer)) + 1 +
                strlen (buffer->name) + 1 + ((tags) ? strlen (tags) : 0) + 1;
            modifier_data = malloc (length);
            if (modifier_data)
            {
                snprintf (modifier_data, length, "%s;%s;%s",
                          gui_buffer_get_plugin_name (buffer),
                          buffer->name,
                          (tags) ? tags : "");
                new_msg = hook_modifier_exec (NULL,
                                              "weechat_print",
                                              modifier_data,
                                              pos);
                free (modifier_data);
                if (new_msg)
                {
                    if (!new_msg[0] && pos[0])
                    {
                        /*
                         * modifier returned empty message, then we'll not
                         * print anything
                         */
                        free (new_msg);
                        new_msg = NULL;
                        msg_discarded = 1;
                    }
                    else if (strcmp (message, new_msg) == 0)
                    {
                        /* no changes in new message */
                        free (new_msg);
                        new_msg = NULL;
                    }
                }
            }
        }

        if (!msg_discarded)
        {
            pos_prefix = NULL;
            display_time = 1;
            ptr_msg = (new_msg) ? new_msg : pos;

            /* space followed by tab => prefix ignored */
            if ((ptr_msg[0] == ' ') && (ptr_msg[1] == '\t'))
            {
                ptr_msg += 2;
            }
            else
            {
                /* if two first chars are tab, then do not display time */
                if ((ptr_msg[0] == '\t') && (ptr_msg[1] == '\t'))
                {
                    display_time = 0;
                    ptr_msg += 2;
                }
                else
                {
                    /* if tab found, use prefix (before tab) */
                    pos_tab = strchr (ptr_msg, '\t');
                    if (pos_tab)
                    {
                        pos_tab[0] = '\0';
                        pos_prefix = ptr_msg;
                        ptr_msg = pos_tab + 1;
                    }
                }
            }

            if (gui_init_ok)
            {
                ptr_line = gui_line_add (buffer, (display_time) ? date : 0,
                                         date_printed, tags, pos_prefix, ptr_msg);
                if (ptr_line)
                {
                    if (buffer && buffer->print_hooks_enabled)
                        hook_print_exec (buffer, ptr_line);
                    if (ptr_line->data->displayed)
                        at_least_one_message_printed = 1;
                }
            }
            else
            {
                length = ((pos_prefix) ? strlen (pos_prefix) + 1 : 0) +
                    strlen (ptr_msg) + 1;
                if (gui_chat_lines_waiting_buffer)
                {
                    length += strlen (gui_chat_lines_waiting_buffer) + 1;
                    lines_waiting = realloc (gui_chat_lines_waiting_buffer, length);
                    if (lines_waiting)
                    {
                        gui_chat_lines_waiting_buffer = lines_waiting;
                    }
                    else
                    {
                        free (gui_chat_lines_waiting_buffer);
                        gui_chat_lines_waiting_buffer = NULL;
                    }
                }
                else
                {
                    gui_chat_lines_waiting_buffer = malloc (length);
                    if (gui_chat_lines_waiting_buffer)
                        gui_chat_lines_waiting_buffer[0] = '\0';
                }
                if (gui_chat_lines_waiting_buffer)
                {
                    pos_lines = gui_chat_lines_waiting_buffer +
                        strlen (gui_chat_lines_waiting_buffer);
                    if (pos_lines > gui_chat_lines_waiting_buffer)
                    {
                        pos_lines[0] = '\n';
                        pos_lines++;
                    }
                    if (pos_prefix)
                    {
                        memcpy (pos_lines, pos_prefix, strlen (pos_prefix));
                        pos_lines += strlen (pos_prefix);
                        pos_lines[0] = '\t';
                        pos_lines++;
                    }
                    memcpy (pos_lines, ptr_msg, strlen (ptr_msg) + 1);
                }
            }
        }

        if (new_msg)
            free (new_msg);

        pos = (pos_end && pos_end[1]) ? pos_end + 1 : NULL;
    }

    if (gui_init_ok && at_least_one_message_printed)
        gui_buffer_ask_chat_refresh (buffer, 1);

    free (vbuffer);
}
Exemple #3
0
struct t_infolist *
plugin_api_infolist_get_internal (void *data, const char *infolist_name,
                                  void *pointer, const char *arguments)
{
    struct t_infolist *ptr_infolist;
    struct t_gui_bar *ptr_bar;
    struct t_gui_bar_item *ptr_bar_item;
    struct t_gui_bar_window *ptr_bar_window;
    struct t_gui_buffer *ptr_buffer;
    struct t_gui_line *ptr_line;
    struct t_gui_history *ptr_history;
    struct t_gui_filter *ptr_filter;
    struct t_gui_window *ptr_window;
    struct t_gui_hotlist *ptr_hotlist;
    struct t_gui_key *ptr_key;
    struct t_weechat_plugin *ptr_plugin;
    struct t_proxy *ptr_proxy;
    struct t_gui_layout *ptr_layout;
    int context, number, i;
    char *error;

    /* make C compiler happy */
    (void) data;

    if (!infolist_name || !infolist_name[0])
        return NULL;

    if (string_strcasecmp (infolist_name, "bar") == 0)
    {
        /* invalid bar pointer ? */
        if (pointer && (!gui_bar_valid (pointer)))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (pointer)
            {
                /* build list with only one bar */
                if (!gui_bar_add_to_infolist (ptr_infolist, pointer))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
                return ptr_infolist;
            }
            else
            {
                /* build list with all bars matching arguments */
                for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
                {
                    if (!arguments || !arguments[0]
                        || string_match (ptr_bar->name, arguments, 0))
                    {
                        if (!gui_bar_add_to_infolist (ptr_infolist, ptr_bar))
                        {
                            infolist_free (ptr_infolist);
                            return NULL;
                        }
                    }
                }
                return ptr_infolist;
            }
        }
    }
    else if (string_strcasecmp (infolist_name, "bar_item") == 0)
    {
        /* invalid bar item pointer ? */
        if (pointer && (!gui_bar_item_valid (pointer)))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (pointer)
            {
                /* build list with only one bar item */
                if (!gui_bar_item_add_to_infolist (ptr_infolist, pointer))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
                return ptr_infolist;
            }
            else
            {
                /* build list with all bar items matching arguments */
                for (ptr_bar_item = gui_bar_items; ptr_bar_item;
                     ptr_bar_item = ptr_bar_item->next_item)
                {
                    if (!arguments || !arguments[0]
                        || string_match (ptr_bar_item->name, arguments, 0))
                    {
                        if (!gui_bar_item_add_to_infolist (ptr_infolist, ptr_bar_item))
                        {
                            infolist_free (ptr_infolist);
                            return NULL;
                        }
                    }
                }
                return ptr_infolist;
            }
        }
    }
    else if (string_strcasecmp (infolist_name, "bar_window") == 0)
    {
        /* invalid bar window pointer ? */
        if (pointer && (!gui_bar_window_valid (pointer)))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (pointer)
            {
                /* build list with only one bar window */
                if (!gui_bar_window_add_to_infolist (ptr_infolist, pointer))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
                return ptr_infolist;
            }
            else
            {
                /* build list with all bar windows (from root and window bars) */
                for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
                {
                    if (ptr_bar->bar_window)
                    {
                        if (!gui_bar_window_add_to_infolist (ptr_infolist, ptr_bar->bar_window))
                        {
                            infolist_free (ptr_infolist);
                            return NULL;
                        }
                    }
                }
                for (ptr_window = gui_windows; ptr_window;
                     ptr_window = ptr_window->next_window)
                {
                    for (ptr_bar_window = ptr_window->bar_windows;
                         ptr_bar_window;
                         ptr_bar_window = ptr_bar_window->next_bar_window)
                    {
                        if (!gui_bar_window_add_to_infolist (ptr_infolist, ptr_bar_window))
                        {
                            infolist_free (ptr_infolist);
                            return NULL;
                        }
                    }
                }
                return ptr_infolist;
            }
        }
    }
    else if (string_strcasecmp (infolist_name, "buffer") == 0)
    {
        /* invalid buffer pointer ? */
        if (pointer && (!gui_buffer_valid (pointer)))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (pointer)
            {
                /* build list with only one buffer */
                if (!gui_buffer_add_to_infolist (ptr_infolist, pointer))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
                return ptr_infolist;
            }
            else
            {
                /* build list with all buffers matching arguments */
                for (ptr_buffer = gui_buffers; ptr_buffer;
                     ptr_buffer = ptr_buffer->next_buffer)
                {
                    if (!arguments || !arguments[0]
                        || string_match (ptr_buffer->full_name, arguments, 0))
                    {
                        if (!gui_buffer_add_to_infolist (ptr_infolist, ptr_buffer))
                        {
                            infolist_free (ptr_infolist);
                            return NULL;
                        }
                    }
                }
                return ptr_infolist;
            }
        }
    }
    else if (string_strcasecmp (infolist_name, "buffer_lines") == 0)
    {
        if (!pointer)
            pointer = gui_buffers;
        else
        {
            /* invalid buffer pointer ? */
            if (!gui_buffer_valid (pointer))
                return NULL;
        }

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            for (ptr_line = ((struct t_gui_buffer *)pointer)->own_lines->first_line;
                 ptr_line; ptr_line = ptr_line->next_line)
            {
                if (!gui_line_add_to_infolist (ptr_infolist,
                                               ((struct t_gui_buffer *)pointer)->own_lines,
                                               ptr_line))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "filter") == 0)
    {
        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            for (ptr_filter = gui_filters; ptr_filter;
                 ptr_filter = ptr_filter->next_filter)
            {
                if (!arguments || !arguments[0]
                    || string_match (ptr_filter->name, arguments, 0))
                {
                    if (!gui_filter_add_to_infolist (ptr_infolist, ptr_filter))
                    {
                        infolist_free (ptr_infolist);
                        return NULL;
                    }
                }
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "history") == 0)
    {
        /* invalid buffer pointer ? */
        if (pointer && (!gui_buffer_valid (pointer)))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            for (ptr_history = (pointer) ?
                     ((struct t_gui_buffer *)pointer)->history : gui_history;
                 ptr_history; ptr_history = ptr_history->next_history)
            {
                if (!gui_history_add_to_infolist (ptr_infolist, ptr_history))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "hook") == 0)
    {
        /* invalid hook pointer ? */
        if (pointer && !hook_valid (pointer))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (!hook_add_to_infolist (ptr_infolist, pointer, arguments))
            {
                infolist_free (ptr_infolist);
                return NULL;
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "hotlist") == 0)
    {
        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            for (ptr_hotlist = gui_hotlist; ptr_hotlist;
                 ptr_hotlist = ptr_hotlist->next_hotlist)
            {
                if (!gui_hotlist_add_to_infolist (ptr_infolist, ptr_hotlist))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "key") == 0)
    {
        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (arguments && arguments[0])
                context = gui_key_search_context (arguments);
            else
                context = GUI_KEY_CONTEXT_DEFAULT;
            if (context >= 0)
            {
                for (ptr_key = gui_keys[context]; ptr_key;
                     ptr_key = ptr_key->next_key)
                {
                    if (!gui_key_add_to_infolist (ptr_infolist, ptr_key))
                    {
                        infolist_free (ptr_infolist);
                        return NULL;
                    }
                }
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "layout") == 0)
    {
        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            for (ptr_layout = gui_layouts; ptr_layout;
                 ptr_layout = ptr_layout->next_layout)
            {
                if (!gui_layout_add_to_infolist (ptr_infolist,ptr_layout))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "nicklist") == 0)
    {
        /* invalid buffer pointer ? */
        if (!pointer || (!gui_buffer_valid (pointer)))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (!gui_nicklist_add_to_infolist (ptr_infolist, pointer, arguments))
            {
                infolist_free (ptr_infolist);
                return NULL;
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "option") == 0)
    {
        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (!config_file_add_to_infolist (ptr_infolist, arguments))
            {
                infolist_free (ptr_infolist);
                return NULL;
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "plugin") == 0)
    {
        /* invalid plugin pointer ? */
        if (pointer && (!plugin_valid (pointer)))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (pointer)
            {
                /* build list with only one plugin */
                if (!plugin_add_to_infolist (ptr_infolist, pointer))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
                return ptr_infolist;
            }
            else
            {
                /* build list with all plugins matching arguments */
                for (ptr_plugin = weechat_plugins; ptr_plugin;
                     ptr_plugin = ptr_plugin->next_plugin)
                {
                    if (!arguments || !arguments[0]
                        || string_match (ptr_plugin->name, arguments, 0))
                    {
                        if (!plugin_add_to_infolist (ptr_infolist, ptr_plugin))
                        {
                            infolist_free (ptr_infolist);
                            return NULL;
                        }
                    }
                }
                return ptr_infolist;
            }
        }
    }
    else if (string_strcasecmp (infolist_name, "proxy") == 0)
    {
        /* invalid proxy pointer ? */
        if (pointer && (!proxy_valid (pointer)))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (pointer)
            {
                /* build list with only one proxy */
                if (!proxy_add_to_infolist (ptr_infolist, pointer))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
                return ptr_infolist;
            }
            else
            {
                /* build list with all proxies matching arguments */
                for (ptr_proxy = weechat_proxies; ptr_proxy;
                     ptr_proxy = ptr_proxy->next_proxy)
                {
                    if (!arguments || !arguments[0]
                        || string_match (ptr_proxy->name, arguments, 0))
                    {
                        if (!proxy_add_to_infolist (ptr_infolist, ptr_proxy))
                        {
                            infolist_free (ptr_infolist);
                            return NULL;
                        }
                    }
                }
                return ptr_infolist;
            }
        }
    }
    else if (string_strcasecmp (infolist_name, "url_options") == 0)
    {
        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            for (i = 0; url_options[i].name; i++)
            {
                if (!weeurl_option_add_to_infolist (ptr_infolist, &url_options[i]))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
            }
            return ptr_infolist;
        }
    }
    else if (string_strcasecmp (infolist_name, "window") == 0)
    {
        /* invalid window pointer ? */
        if (pointer && (!gui_window_valid (pointer)))
            return NULL;

        ptr_infolist = infolist_new ();
        if (ptr_infolist)
        {
            if (pointer)
            {
                /* build list with only one window */
                if (!gui_window_add_to_infolist (ptr_infolist, pointer))
                {
                    infolist_free (ptr_infolist);
                    return NULL;
                }
                return ptr_infolist;
            }
            else
            {
                if (arguments && arguments[0])
                {
                    if ((string_strcasecmp (arguments, "current") == 0))
                    {
                        if (gui_current_window)
                        {
                            if (!gui_window_add_to_infolist (ptr_infolist,
                                                             gui_current_window))
                            {
                                infolist_free (ptr_infolist);
                                return NULL;
                            }
                            return ptr_infolist;
                        }
                        return NULL;
                    }
                    /* check if argument is a window number */
                    error = NULL;
                    number = (int)strtol (arguments, &error, 10);
                    if (error && !error[0])
                    {
                        ptr_window = gui_window_search_by_number (number);
                        if (ptr_window)
                        {
                            if (!gui_window_add_to_infolist (ptr_infolist,
                                                             ptr_window))
                            {
                                infolist_free (ptr_infolist);
                                return NULL;
                            }
                            return ptr_infolist;
                        }
                    }
                    return NULL;
                }
                else
                {
                    /* build list with all windows */
                    for (ptr_window = gui_windows; ptr_window;
                         ptr_window = ptr_window->next_window)
                    {
                        if (!gui_window_add_to_infolist (ptr_infolist,
                                                         ptr_window))
                        {
                            infolist_free (ptr_infolist);
                            return NULL;
                        }
                    }
                    return ptr_infolist;
                }
            }
        }
    }

    /* infolist not found */
    return NULL;
}
Exemple #4
0
int
input_data (struct t_gui_buffer *buffer, const char *data)
{
    char *pos, *buf, str_buffer[128], *new_data, *buffer_full_name;
    const char *ptr_data, *ptr_data_for_buffer;
    int length, char_size, first_command, rc;

    rc = WEECHAT_RC_OK;

    if (!buffer || !gui_buffer_valid (buffer)
        || !data || !data[0] || (data[0] == '\r') || (data[0] == '\n'))
    {
        return WEECHAT_RC_ERROR;
    }

    buffer_full_name = strdup (buffer->full_name);
    if (!buffer_full_name)
        return WEECHAT_RC_ERROR;

    /* execute modifier "input_text_for_buffer" */
    snprintf (str_buffer, sizeof (str_buffer),
              "0x%lx", (long unsigned int)buffer);
    new_data = hook_modifier_exec (NULL,
                                   "input_text_for_buffer",
                                   str_buffer,
                                   data);

    /* data was dropped? */
    if (new_data && !new_data[0])
        goto end;

    first_command = 1;
    ptr_data = (new_data) ? new_data : data;
    while (ptr_data && ptr_data[0])
    {
        /*
         * if the buffer pointer is not valid any more (or if it's another
         * buffer), use the current buffer for the next command
         */
        if (!first_command
            && (!gui_buffer_valid (buffer)
                || (strcmp (buffer->full_name, buffer_full_name) != 0)))
        {
            if (!gui_current_window || !gui_current_window->buffer)
                break;
            buffer = gui_current_window->buffer;
            free (buffer_full_name);
            buffer_full_name = strdup (buffer->full_name);
            if (!buffer_full_name)
                break;
        }

        pos = strchr (ptr_data, '\n');
        if (pos)
            pos[0] = '\0';

        ptr_data_for_buffer = string_input_for_buffer (ptr_data);
        if (ptr_data_for_buffer)
        {
            /*
             * input string is NOT a command, send it to buffer input
             * callback
             */
            if (string_is_command_char (ptr_data_for_buffer))
            {
                char_size = utf8_char_size (ptr_data_for_buffer);
                length = strlen (ptr_data_for_buffer) + char_size + 1;
                buf = malloc (length);
                if (buf)
                {
                    memcpy (buf, ptr_data_for_buffer, char_size);
                    snprintf (buf + char_size, length - char_size,
                              "%s", ptr_data_for_buffer);
                    input_exec_data (buffer, buf);
                    free (buf);
                }
            }
            else
                input_exec_data (buffer, ptr_data_for_buffer);
        }
        else
        {
            /* input string is a command */
            rc = input_exec_command (buffer, 1, buffer->plugin, ptr_data);
        }

        if (pos)
        {
            pos[0] = '\n';
            ptr_data = pos + 1;
        }
        else
            ptr_data = NULL;

        first_command = 0;
    }

end:
    if (new_data)
        free (new_data);
    if (buffer_full_name)
        free (buffer_full_name);

    return rc;
}
Exemple #5
0
void
gui_chat_printf_date_tags (struct t_gui_buffer *buffer, time_t date,
                           const char *tags, const char *message, ...)
{
    va_list argptr;
    time_t date_printed;
    int display_time, length, at_least_one_message_printed;
    char *pos, *pos_prefix, *pos_tab, *pos_end;
    char *modifier_data, *new_msg, *ptr_msg;
    struct t_gui_line *ptr_line;
    
    if (!gui_buffer_valid (buffer))
        return;
    
    if (!message)
        return;
    
    if (gui_init_ok)
    {
        if (!buffer)
            buffer = gui_buffer_search_main ();

        if (!buffer)
            return;
        
        if (buffer->type != GUI_BUFFER_TYPE_FORMATTED)
            buffer = gui_buffers;
        
        if (buffer->type != GUI_BUFFER_TYPE_FORMATTED)
            return;
    }
    
    if (!gui_chat_buffer)
        gui_chat_buffer = malloc (GUI_CHAT_BUFFER_PRINTF_SIZE);
    if (!gui_chat_buffer)
        return;
    
    va_start (argptr, message);
    vsnprintf (gui_chat_buffer, GUI_CHAT_BUFFER_PRINTF_SIZE, message, argptr);
    va_end (argptr);
    
    utf8_normalize (gui_chat_buffer, '?');
    
    date_printed = time (NULL);
    if (date <= 0)
        date = date_printed;
    
    at_least_one_message_printed = 0;
    
    pos = gui_chat_buffer;
    while (pos)
    {
        /* display until next end of line */
        pos_end = strchr (pos, '\n');
        if (pos_end)
            pos_end[0] = '\0';
        
        /* call modifier for message printed ("weechat_print") */
        new_msg = NULL;
        if (buffer)
        {
            length = strlen (plugin_get_name (buffer->plugin)) + 1 +
                strlen (buffer->name) + 1 + ((tags) ? strlen (tags) : 0) + 1;
            modifier_data = malloc (length);
            if (modifier_data)
            {
                snprintf (modifier_data, length, "%s;%s;%s",
                          plugin_get_name (buffer->plugin),
                          buffer->name,
                          (tags) ? tags : "");
                new_msg = hook_modifier_exec (NULL,
                                              "weechat_print",
                                              modifier_data,
                                              pos);
                /* no changes in new message */
                if (new_msg && (strcmp (message, new_msg) == 0))
                {
                    free (new_msg);
                    new_msg = NULL;
                }
                free (modifier_data);
            }
        }
        
        pos_prefix = NULL;
        display_time = 1;
        ptr_msg = (new_msg) ? new_msg : pos;
        
        /* space followed by tab => prefix ignored */
        if ((ptr_msg[0] == ' ') && (ptr_msg[1] == '\t'))
        {
            ptr_msg += 2;
        }
        else
        {
            /* if two first chars are tab, then do not display time */
            if ((ptr_msg[0] == '\t') && (ptr_msg[1] == '\t'))
            {
                display_time = 0;
                ptr_msg += 2;
            }
            else
            {
                /* if tab found, use prefix (before tab) */
                pos_tab = strchr (ptr_msg, '\t');
                if (pos_tab)
                {
                    pos_tab[0] = '\0';
                    pos_prefix = ptr_msg;
                    ptr_msg = pos_tab + 1;
                }
            }
        }
        
        if (gui_init_ok)
        {
            ptr_line = gui_line_add (buffer, (display_time) ? date : 0,
                                     (display_time) ? date_printed : 0,
                                     tags, pos_prefix, ptr_msg);
            if (ptr_line)
            {
                if (buffer->print_hooks_enabled)
                    hook_print_exec (buffer, ptr_line);
                if (ptr_line->data->displayed)
                    at_least_one_message_printed = 1;
            }
        }
        else
        {
            if (pos_prefix)
                string_iconv_fprintf (stdout, "%s ", pos_prefix);
            string_iconv_fprintf (stdout, "%s\n", ptr_msg);
        }
        
        if (new_msg)
            free (new_msg);
        
        pos = (pos_end && pos_end[1]) ? pos_end + 1 : NULL;
    }
    
    if (gui_init_ok && at_least_one_message_printed)
        gui_buffer_ask_chat_refresh (buffer, 1);
}