예제 #1
0
void
script_buffer_get_window_info (struct t_gui_window *window,
                               int *start_line_y, int *chat_height)
{
    struct t_hdata *hdata_window, *hdata_window_scroll, *hdata_line;
    struct t_hdata *hdata_line_data;
    void *window_scroll, *start_line, *line_data;

    hdata_window = weechat_hdata_get ("window");
    hdata_window_scroll = weechat_hdata_get ("window_scroll");
    hdata_line = weechat_hdata_get ("line");
    hdata_line_data = weechat_hdata_get ("line_data");
    *start_line_y = 0;
    window_scroll = weechat_hdata_pointer (hdata_window, window, "scroll");
    if (window_scroll)
    {
        start_line = weechat_hdata_pointer (hdata_window_scroll, window_scroll,
                                            "start_line");
        if (start_line)
        {
            line_data = weechat_hdata_pointer (hdata_line, start_line, "data");
            if (line_data)
            {
                *start_line_y = weechat_hdata_integer (hdata_line_data,
                                                       line_data, "y");
            }
        }
    }
    *chat_height = weechat_hdata_integer (hdata_window, window,
                                          "win_chat_height");
}
void
relay_weechat_nicklist_add_item (struct t_relay_weechat_nicklist *nicklist,
                                 char diff, struct t_gui_nick_group *group,
                                 struct t_gui_nick *nick)
{
    struct t_relay_weechat_nicklist_item *new_items, *ptr_item;
    struct t_hdata *hdata;
    const char *str;
    int i;

    /*
     * check if the last "parent_group" (with diff = '^') of items is the same
     * as this one: if yes, don't add this parent group
     */
    if ((diff == RELAY_WEECHAT_NICKLIST_DIFF_PARENT)
        && (nicklist->items_count > 0))
    {
        for (i = nicklist->items_count - 1; i >= 0; i--)
        {
            if (nicklist->items[i].diff == RELAY_WEECHAT_NICKLIST_DIFF_PARENT)
            {
                if (nicklist->items[i].pointer == group)
                    return;
                break;
            }
        }
    }

    new_items = realloc (nicklist->items,
                         (nicklist->items_count + 1) * sizeof (new_items[0]));
    if (!new_items)
        return;

    nicklist->items = new_items;
    ptr_item = &(nicklist->items[nicklist->items_count]);
    if (group)
    {
        hdata = weechat_hdata_get ("nick_group");
        ptr_item->pointer = group;
    }
    else
    {
        hdata = weechat_hdata_get ("nick");
        ptr_item->pointer = nick;
    }
    ptr_item->diff = diff;
    ptr_item->group = (group) ? 1 : 0;
    ptr_item->visible = weechat_hdata_integer (hdata, ptr_item->pointer, "visible");
    ptr_item->level = (group) ? weechat_hdata_integer (hdata, ptr_item->pointer, "level") : 0;
    str = weechat_hdata_string (hdata, ptr_item->pointer, "name");
    ptr_item->name = (str) ? strdup (str) : NULL;
    str = weechat_hdata_string (hdata, ptr_item->pointer, "color");
    ptr_item->color = (str) ? strdup (str) : NULL;
    str = weechat_hdata_string (hdata, ptr_item->pointer, "prefix");
    ptr_item->prefix = (str) ? strdup (str) : NULL;
    str = weechat_hdata_string (hdata, ptr_item->pointer, "prefix_color");
    ptr_item->prefix_color = (str) ? strdup (str) : NULL;

    nicklist->items_count++;
}
예제 #3
0
int
relay_weechat_msg_add_nicklist_buffer (struct t_relay_weechat_msg *msg,
                                       struct t_gui_buffer *buffer,
                                       struct t_relay_weechat_nicklist *nicklist)
{
    int count, i;
    struct t_hdata *ptr_hdata_group, *ptr_hdata_nick;
    struct t_gui_nick_group *ptr_group;
    struct t_gui_nick *ptr_nick;

    count = 0;

    if (nicklist)
    {
        /* send nicklist diffs */
        for (i = 0; i < nicklist->items_count; i++)
        {
            relay_weechat_msg_add_pointer (msg, buffer);
            relay_weechat_msg_add_pointer (msg, nicklist->items[i].pointer);
            relay_weechat_msg_add_char (msg, nicklist->items[i].diff);
            relay_weechat_msg_add_char (msg, nicklist->items[i].group);
            relay_weechat_msg_add_char (msg, nicklist->items[i].visible);
            relay_weechat_msg_add_int (msg, nicklist->items[i].level);
            relay_weechat_msg_add_string (msg, nicklist->items[i].name);
            relay_weechat_msg_add_string (msg, nicklist->items[i].color);
            relay_weechat_msg_add_string (msg, nicklist->items[i].prefix);
            relay_weechat_msg_add_string (msg, nicklist->items[i].prefix_color);
            count++;
        }
    }
    else
    {
        /* send full nicklist */
        ptr_hdata_group = weechat_hdata_get ("nick_group");
        ptr_hdata_nick = weechat_hdata_get ("nick");

        ptr_group = NULL;
        ptr_nick = NULL;
        weechat_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
        while (ptr_group || ptr_nick)
        {
            if (ptr_nick)
            {
                relay_weechat_msg_add_pointer (msg, buffer);
                relay_weechat_msg_add_pointer (msg, ptr_nick);
                relay_weechat_msg_add_char (msg, 0); /* group */
                relay_weechat_msg_add_char (msg,
                                            (char)weechat_hdata_integer(ptr_hdata_nick,
                                                                        ptr_nick,
                                                                        "visible"));
                relay_weechat_msg_add_int (msg, 0); /* level */
                relay_weechat_msg_add_string (msg,
                                              weechat_hdata_string (ptr_hdata_nick,
                                                                    ptr_nick,
                                                                    "name"));
                relay_weechat_msg_add_string (msg,
                                              weechat_hdata_string (ptr_hdata_nick,
                                                                    ptr_nick,
                                                                    "color"));
                relay_weechat_msg_add_string (msg,
                                              weechat_hdata_string (ptr_hdata_nick,
                                                                    ptr_nick,
                                                                    "prefix"));
                relay_weechat_msg_add_string (msg,
                                              weechat_hdata_string (ptr_hdata_nick,
                                                                    ptr_nick,
                                                                    "prefix_color"));
                count++;
            }
            else
            {
                relay_weechat_msg_add_pointer (msg, buffer);
                relay_weechat_msg_add_pointer (msg, ptr_group);
                relay_weechat_msg_add_char (msg, 1); /* group */
                relay_weechat_msg_add_char (msg,
                                            (char)weechat_hdata_integer(ptr_hdata_group,
                                                                        ptr_group,
                                                                        "visible"));
                relay_weechat_msg_add_int (msg,
                                           weechat_hdata_integer (ptr_hdata_group,
                                                                  ptr_group,
                                                                  "level"));
                relay_weechat_msg_add_string (msg,
                                              weechat_hdata_string (ptr_hdata_group,
                                                                    ptr_group,
                                                                    "name"));
                relay_weechat_msg_add_string (msg,
                                              weechat_hdata_string (ptr_hdata_group,
                                                                    ptr_group,
                                                                    "color"));
                relay_weechat_msg_add_string (msg, NULL); /* prefix */
                relay_weechat_msg_add_string (msg, NULL); /* prefix_color */
                count++;
            }
            weechat_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick);
        }
    }

    return count;
}
예제 #4
0
int
relay_weechat_msg_add_hdata_path (struct t_relay_weechat_msg *msg,
                                  char **list_path,
                                  int index_path,
                                  void **path_pointers,
                                  struct t_hdata *hdata,
                                  void *pointer,
                                  char **list_keys)
{
    int num_added, i, j, count, count_all, var_type, array_size, max_array_size;
    int length;
    char *pos, *pos2, *str_count, *error, *name;
    void *sub_pointer;
    struct t_hdata *sub_hdata;
    const char *sub_hdata_name;

    num_added = 0;

    count_all = 0;
    count = 0;
    pos = strchr (list_path[index_path], '(');
    if (pos)
    {
        pos2 = strchr (pos + 1, ')');
        if (pos2 && (pos2 > pos + 1))
        {
            str_count = weechat_strndup (pos + 1, pos2 - (pos + 1));
            if (str_count)
            {
                if (strcmp (str_count, "*") == 0)
                    count_all = 1;
                else
                {
                    error = NULL;
                    count = (int)strtol (str_count, &error, 10);
                    if (error && !error[0])
                    {
                        if (count > 0)
                            count--;
                        else if (count < 0)
                            count++;
                    }
                    else
                        count = 0;
                }
                free (str_count);
            }
        }
    }

    while (pointer)
    {
        path_pointers[index_path] = pointer;

        if (list_path[index_path + 1])
        {
            /* recursive call with next path */
            pos = strchr (list_path[index_path + 1], '(');
            if (pos)
                pos[0] = '\0';
            sub_pointer = weechat_hdata_pointer (hdata, pointer, list_path[index_path + 1]);
            sub_hdata_name = weechat_hdata_get_var_hdata (hdata, list_path[index_path + 1]);
            if (pos)
                pos[0] = '(';
            if (sub_pointer && sub_hdata_name)
            {
                sub_hdata = weechat_hdata_get (sub_hdata_name);
                if (sub_hdata)
                {
                    num_added += relay_weechat_msg_add_hdata_path (msg,
                                                                   list_path,
                                                                   index_path + 1,
                                                                   path_pointers,
                                                                   sub_hdata,
                                                                   sub_pointer,
                                                                   list_keys);
                }
            }
        }
        else
        {
            /* last path? then get pointer + values and fill message with them */
            for (i = 0; list_path[i]; i++)
            {
                relay_weechat_msg_add_pointer (msg, path_pointers[i]);
            }
            for (i = 0; list_keys[i]; i++)
            {
                var_type = weechat_hdata_get_var_type (hdata, list_keys[i]);
                if ((var_type >= 0) && (var_type != WEECHAT_HDATA_OTHER))
                {
                    max_array_size = 1;
                    array_size = weechat_hdata_get_var_array_size (hdata,
                                                                   pointer,
                                                                   list_keys[i]);
                    if (array_size >= 0)
                    {
                        switch (var_type)
                        {
                            case WEECHAT_HDATA_CHAR:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_CHAR);
                                break;
                            case WEECHAT_HDATA_INTEGER:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_INT);
                                break;
                            case WEECHAT_HDATA_LONG:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_LONG);
                                break;
                            case WEECHAT_HDATA_STRING:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
                                break;
                            case WEECHAT_HDATA_POINTER:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_POINTER);
                                break;
                            case WEECHAT_HDATA_TIME:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_TIME);
                                break;
                            case WEECHAT_HDATA_HASHTABLE:
                                relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_HASHTABLE);
                                break;
                        }
                        relay_weechat_msg_add_int (msg, array_size);
                        max_array_size = array_size;
                    }
                    length = 16 + strlen (list_keys[i]) + 1;
                    name = malloc (length);
                    if (name)
                    {
                        for (j = 0; j < max_array_size; j++)
                        {
                            snprintf (name, length, "%d|%s", j, list_keys[i]);
                            switch (var_type)
                            {
                                case WEECHAT_HDATA_CHAR:
                                    relay_weechat_msg_add_char (msg,
                                                                weechat_hdata_char (hdata,
                                                                                    pointer,
                                                                                    name));
                                    break;
                                case WEECHAT_HDATA_INTEGER:
                                    relay_weechat_msg_add_int (msg,
                                                               weechat_hdata_integer (hdata,
                                                                                      pointer,
                                                                                      name));
                                    break;
                                case WEECHAT_HDATA_LONG:
                                    relay_weechat_msg_add_long (msg,
                                                                weechat_hdata_long (hdata,
                                                                                    pointer,
                                                                                    name));
                                    break;
                                case WEECHAT_HDATA_STRING:
                                    relay_weechat_msg_add_string (msg,
                                                                  weechat_hdata_string (hdata,
                                                                                        pointer,
                                                                                        name));
                                    break;
                                case WEECHAT_HDATA_POINTER:
                                    relay_weechat_msg_add_pointer (msg,
                                                                   weechat_hdata_pointer (hdata,
                                                                                          pointer,
                                                                                          name));
                                    break;
                                case WEECHAT_HDATA_TIME:
                                    relay_weechat_msg_add_time (msg,
                                                                weechat_hdata_time (hdata,
                                                                                    pointer,
                                                                                    name));
                                    break;
                                case WEECHAT_HDATA_HASHTABLE:
                                    relay_weechat_msg_add_hashtable (msg,
                                                                     weechat_hdata_hashtable (hdata,
                                                                                              pointer,
                                                                                              name));
                                    break;
                            }
                        }
                        free (name);
                    }
                }
            }
            num_added++;
        }
        if (count_all)
        {
            pointer = weechat_hdata_move (hdata, pointer, 1);
        }
        else if (count == 0)
            pointer = NULL;
        else if (count > 0)
        {
            pointer = weechat_hdata_move (hdata, pointer, 1);
            count--;
        }
        else
        {
            pointer = weechat_hdata_move (hdata, pointer, -1);
            count++;
        }
        if (!pointer)
            break;
    }

    return num_added;
}