1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 09:45:41 +02:00

Use of hashtable for local variables of buffers

This commit is contained in:
Sebastien Helleu
2010-07-05 17:05:49 +02:00
parent cb18bdb10b
commit 94fbbc0a7f
10 changed files with 186 additions and 172 deletions
+2 -1
View File
@@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
v0.3.3-dev, 2010-06-18
v0.3.3-dev, 2010-07-05
Version 0.3.3 (under dev!)
@@ -16,6 +16,7 @@ Version 0.3.3 (under dev!)
* core: fix crash with hook_process (when timer is called on a deleted hook
process)
* core: fix display bug with attributes like underlined in bars (bug #29889)
* core: add hashtables with new functions in plugin API
* api: add function "string_expand_home", fix bug with replacement of home in
paths
* irc: use empty real name by default in config, instead of reading real name
+27 -10
View File
@@ -39,6 +39,7 @@
#include "wee-config.h"
#include "wee-config-file.h"
#include "wee-debug.h"
#include "wee-hashtable.h"
#include "wee-hook.h"
#include "wee-input.h"
#include "wee-list.h"
@@ -495,6 +496,28 @@ command_bar (void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_ERROR;
}
/*
* command_buffer_display_localvar: display local variable for a buffer
*/
void
command_buffer_display_localvar (void *data,
struct t_hashtable *hashtable,
const void *key, const void *value)
{
/* make C compiler happy */
(void) data;
(void) hashtable;
if (key && value)
{
gui_chat_printf (NULL,
" %s: \"%s\"",
(const char *)key,
(const char *)value);
}
}
/*
* command_buffer: manage buffers
*/
@@ -504,7 +527,6 @@ command_buffer (void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol)
{
struct t_gui_buffer *ptr_buffer;
struct t_gui_buffer_local_var *ptr_local_var;
long number, number1, number2;
char *error, *value, *pos, *str_number1, *pos_number2;
int i, target_buffer;
@@ -789,19 +811,14 @@ command_buffer (void *data, struct t_gui_buffer *buffer,
/* display local variables on buffer */
if (string_strcasecmp (argv[1], "localvar") == 0)
{
if (buffer->local_variables)
if (buffer->local_variables
&& (buffer->local_variables->items_count > 0))
{
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, _("Local variables for buffer \"%s\":"),
buffer->name);
for (ptr_local_var = buffer->local_variables; ptr_local_var;
ptr_local_var = ptr_local_var->next_var)
{
gui_chat_printf (NULL,
" %s: \"%s\"",
ptr_local_var->name,
ptr_local_var->value);
}
hashtable_map (buffer->local_variables,
&command_buffer_display_localvar, NULL);
}
else
{
File diff suppressed because it is too large Load Diff
+4
View File
@@ -21,6 +21,7 @@
#define __WEECHAT_HASHTABLE_H 1
struct t_hashtable;
struct t_infolist_item;
typedef unsigned int (t_hashtable_hash_key)(struct t_hashtable *hashtable,
const void *key);
@@ -114,6 +115,9 @@ extern void hashtable_map (struct t_hashtable *hashtable,
void *callback_map_data);
extern int hashtable_get_integer (struct t_hashtable *hashtable,
const char *property);
extern int hashtable_add_to_infolist (struct t_hashtable *hashtable,
struct t_infolist_item *infolist_item,
const char *prefix);
extern void hashtable_remove (struct t_hashtable *hashtable, const void *key);
extern void hashtable_remove_all (struct t_hashtable *hashtable);
extern void hashtable_free (struct t_hashtable *hashtable);
+1 -1
View File
@@ -32,7 +32,7 @@
#include "wee-list.h"
#include "wee-log.h"
#include "wee-string.h"
#include "../plugins/weechat-plugin.h"
#include "../plugins/plugin.h"
/*
+6 -4
View File
@@ -31,6 +31,7 @@
#include "../core/weechat.h"
#include "../core/wee-config.h"
#include "../core/wee-hashtable.h"
#include "../core/wee-hook.h"
#include "../core/wee-infolist.h"
#include "../core/wee-log.h"
@@ -593,7 +594,7 @@ char *
gui_bar_item_default_input_prompt (void *data, struct t_gui_bar_item *item,
struct t_gui_window *window)
{
struct t_gui_buffer_local_var *local_var_nick;
const char *nick;
/* make C compiler happy */
(void) data;
@@ -602,11 +603,12 @@ gui_bar_item_default_input_prompt (void *data, struct t_gui_bar_item *item,
if (!window)
window = gui_current_window;
local_var_nick = gui_buffer_local_var_search (window->buffer, "nick");
if (!local_var_nick || !local_var_nick->value)
nick = (const char *)hashtable_get (window->buffer->local_variables,
"nick");
if (!nick)
return NULL;
return strdup (local_var_nick->value);
return strdup (nick);
}
/*
+52 -138
View File
File diff suppressed because it is too large Load Diff
+2 -12
View File
@@ -20,6 +20,7 @@
#ifndef __WEECHAT_GUI_BUFFER_H
#define __WEECHAT_GUI_BUFFER_H 1
struct t_hashtable;
struct t_gui_window;
struct t_infolist;
@@ -49,14 +50,6 @@ enum t_gui_buffer_notify
/* buffer structures */
struct t_gui_buffer_local_var
{
char *name; /* variable name */
char *value; /* value */
struct t_gui_buffer_local_var *prev_var; /* link to previous variable */
struct t_gui_buffer_local_var *next_var; /* link to next variable */
};
struct t_gui_input_undo
{
char *data; /* content of input buffer */
@@ -176,8 +169,7 @@ struct t_gui_buffer
int keys_count; /* number of keys in buffer */
/* local variables */
struct t_gui_buffer_local_var *local_variables; /* local variables */
struct t_gui_buffer_local_var *last_local_var; /* last local variable */
struct t_hashtable *local_variables; /* local variables */
/* link to previous/next buffer */
struct t_gui_buffer *prev_buffer; /* link to previous buffer */
@@ -208,8 +200,6 @@ extern char *gui_buffer_properties_set[];
/* buffer functions */
extern struct t_gui_buffer_local_var *gui_buffer_local_var_search (struct t_gui_buffer *buffer,
const char *name);
extern void gui_buffer_notify_set_all ();
extern struct t_gui_buffer *gui_buffer_new (struct t_weechat_plugin *plugin,
const char *name,
+1
View File
@@ -527,6 +527,7 @@ plugin_load (const char *filename)
new_plugin->hashtable_get = &hashtable_get;
new_plugin->hashtable_map = &hashtable_map;
new_plugin->hashtable_get_integer = &hashtable_get_integer;
new_plugin->hashtable_add_to_infolist = &hashtable_add_to_infolist;
new_plugin->hashtable_remove = &hashtable_remove;
new_plugin->hashtable_remove_all = &hashtable_remove_all;
new_plugin->hashtable_free = &hashtable_free;
+9
View File
@@ -34,6 +34,7 @@ struct t_gui_bar;
struct t_gui_bar_item;
struct t_gui_completion;
struct t_infolist;
struct t_infolist_item;
struct t_weelist;
struct t_hashtable;
struct timeval;
@@ -272,6 +273,9 @@ struct t_weechat_plugin
void *callback_map_data);
int (*hashtable_get_integer) (struct t_hashtable *hashtable,
const char *property);
int (*hashtable_add_to_infolist) (struct t_hashtable *hashtable,
struct t_infolist_item *infolist_item,
const char *prefix);
void (*hashtable_remove) (struct t_hashtable *hashtable, const void *key);
void (*hashtable_remove_all) (struct t_hashtable *hashtable);
void (*hashtable_free) (struct t_hashtable *hashtable);
@@ -882,6 +886,11 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->hashtable_map(__hashtable, __cb_map, __cb_map_data)
#define weechat_hashtable_get_integer(__hashtable, __property) \
weechat_plugin->hashtable_get_integer(__hashtable, __property)
#define weechat_hashtable_add_to_infolist(__hashtable, __infolist_item, \
__prefix) \
weechat_plugin->hashtable_add_to_infolist(__hashtable, \
__infolist_item, \
__prefix)
#define weechat_hashtable_remove(__hashtable, __key) \
weechat_plugin->hashtable_remove(__hashtable, __key)
#define weechat_hashtable_remove_all(__hashtable) \