diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | TODO | 8 | ||||
-rw-r--r-- | src/common/history.c | 47 | ||||
-rw-r--r-- | src/common/weeconfig.c | 4 | ||||
-rw-r--r-- | src/gui/gui-common.c | 55 | ||||
-rw-r--r-- | src/gui/gui.h | 3 | ||||
-rw-r--r-- | weechat/ChangeLog | 5 | ||||
-rw-r--r-- | weechat/TODO | 8 | ||||
-rw-r--r-- | weechat/src/common/history.c | 47 | ||||
-rw-r--r-- | weechat/src/common/weeconfig.c | 4 | ||||
-rw-r--r-- | weechat/src/gui/gui-common.c | 55 | ||||
-rw-r--r-- | weechat/src/gui/gui.h | 3 |
12 files changed, 200 insertions, 44 deletions
@@ -1,9 +1,12 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2004-06-05 +ChangeLog - 2004-06-13 +Version 0.0.7 (under dev!): + * added history limit (text buffer & commands) + Version 0.0.6 (2004-06-05): * improved channel highlight (priority to message vs join/part) * fixed bug when opened private win and remote user changes his nick @@ -1,7 +1,7 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -TODO - 2004-06-05 +TODO - 2004-06-13 Legend: # done @@ -10,7 +10,7 @@ Legend: ? is this really necessary? -v0.0.6: +v0.0.7: ------ * General: @@ -18,15 +18,13 @@ v0.0.6: + Solaris version * IRC protocol: - # "/mode" command: change the user/channels modes + "/dcc" command (for chat and sending/receiving files) - # "/query" command: start private conversation * Interface: + internationalization (traduce WeeChat in many languages) - # display current channel modes (example : #weechat(+nt)) * Configuration: + # history limit (text buffer & commands) + add missing options for config file - add key bindings to config file diff --git a/src/common/history.c b/src/common/history.c index 4f49028a6..c930de452 100644 --- a/src/common/history.c +++ b/src/common/history.c @@ -29,11 +29,14 @@ #include "weechat.h" #include "history.h" +#include "weeconfig.h" #include "../gui/gui.h" t_history *history_general = NULL; +t_history *history_general_last = NULL; t_history *history_general_ptr = NULL; +int num_history_general = 0; /* @@ -43,25 +46,63 @@ t_history *history_general_ptr = NULL; void history_add (void *window, char *string) { - t_history *new_history; + t_history *new_history, *ptr_history; + /* add history to general history */ new_history = (t_history *)malloc (sizeof (t_history)); if (new_history) { new_history->text = strdup (string); - /* add history to general history */ if (history_general) history_general->prev_history = new_history; + else + history_general_last = new_history; new_history->next_history = history_general; new_history->prev_history = NULL; history_general = new_history; + num_history_general++; + + /* remove one command if necessary */ + if ((cfg_history_max_commands > 0) + && (num_history_general > cfg_history_max_commands)) + { + ptr_history = history_general_last->prev_history; + history_general_last->prev_history->next_history = NULL; + if (history_general_last->text) + free (history_general_last->text); + free (history_general_last); + history_general_last = ptr_history; + num_history_general--; + } + } + + /* add history to local history */ + new_history = (t_history *)malloc (sizeof (t_history)); + if (new_history) + { + new_history->text = strdup (string); - /* add history to local history */ if (((t_gui_window *)(window))->history) ((t_gui_window *)(window))->history->prev_history = new_history; + else + ((t_gui_window *)(window))->last_history = new_history; new_history->next_history = ((t_gui_window *)(window))->history; new_history->prev_history = NULL; ((t_gui_window *)window)->history = new_history; + ((t_gui_window *)(window))->num_history++; + + /* remove one command if necessary */ + if ((cfg_history_max_commands > 0) + && (((t_gui_window *)(window))->num_history > cfg_history_max_commands)) + { + ptr_history = ((t_gui_window *)window)->last_history->prev_history; + ((t_gui_window *)window)->last_history->prev_history->next_history = NULL; + if (((t_gui_window *)window)->last_history->text) + free (((t_gui_window *)window)->last_history->text); + free (((t_gui_window *)window)->last_history); + ((t_gui_window *)window)->last_history = ptr_history; + ((t_gui_window *)(window))->num_history++; + } } } diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index 6b1f6b0df..5216bae93 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -1258,8 +1258,8 @@ config_write (char *config_name) if ((i != CONFIG_SECTION_ALIAS) && (i != CONFIG_SECTION_SERVER)) { fprintf (file, "\n[%s]\n", config_sections[i].section_name); - if ((i == CONFIG_SECTION_HISTORY) || (i == CONFIG_SECTION_LOG) || - (i == CONFIG_SECTION_DCC) || (i == CONFIG_SECTION_PROXY)) + if ((i == CONFIG_SECTION_LOG) || (i == CONFIG_SECTION_DCC) || + (i == CONFIG_SECTION_PROXY)) fprintf (file, "# WARNING!!! Options for section \"%s\" are not developed!\n", config_sections[i].section_name); diff --git a/src/gui/gui-common.c b/src/gui/gui-common.c index b9b036e17..4da80b9e9 100644 --- a/src/gui/gui-common.c +++ b/src/gui/gui-common.c @@ -34,6 +34,7 @@ #include "../common/weechat.h" #include "gui.h" +#include "../../common/weeconfig.h" #include "../irc/irc.h" @@ -92,6 +93,7 @@ gui_window_new (void *server, void *channel, int switch_to_window /* init lines */ new_window->lines = NULL; new_window->last_line = NULL; + new_window->num_lines = 0; new_window->first_line_displayed = 1; new_window->sub_lines = 0; new_window->line_complete = 1; @@ -110,7 +112,9 @@ gui_window_new (void *server, void *channel, int switch_to_window /* init history */ new_window->history = NULL; + new_window->last_history = NULL; new_window->ptr_history = NULL; + new_window->num_history = 0; /* switch to new window */ if (switch_to_window) @@ -161,6 +165,7 @@ gui_window_clear (t_gui_window *window) window->lines = NULL; window->last_line = NULL; + window->num_lines = 0; window->first_line_displayed = 1; window->sub_lines = 0; window->line_complete = 1; @@ -240,6 +245,26 @@ gui_infobar_remove () } /* + * gui_line_free: delete a line from a window + */ + +void +gui_line_free (t_gui_line *line) +{ + t_gui_message *ptr_message; + + while (line->messages) + { + ptr_message = line->messages->next_message; + if (line->messages->message) + free (line->messages->message); + free (line->messages); + line->messages = ptr_message; + } + free (line); +} + +/* * gui_window_free: delete a window */ @@ -247,7 +272,6 @@ void gui_window_free (t_gui_window *window) { t_gui_line *ptr_line; - t_gui_message *ptr_message; int create_new; create_new = (window->server || window->channel); @@ -261,15 +285,7 @@ gui_window_free (t_gui_window *window) while (window->lines) { ptr_line = window->lines->next_line; - while (window->lines->messages) - { - ptr_message = window->lines->messages->next_message; - if (window->lines->messages->message) - free (window->lines->messages->message); - free (window->lines->messages); - window->lines->messages = ptr_message; - } - free (window->lines); + gui_line_free (window->lines); window->lines = ptr_line; } if (window->input_buffer) @@ -301,7 +317,7 @@ gui_window_free (t_gui_window *window) t_gui_line * gui_new_line (t_gui_window *window) { - t_gui_line *new_line; + t_gui_line *new_line, *ptr_line; if ((new_line = (t_gui_line *) malloc (sizeof (struct t_gui_line)))) { @@ -317,12 +333,29 @@ gui_new_line (t_gui_window *window) new_line->prev_line = window->last_line; new_line->next_line = NULL; window->last_line = new_line; + window->num_lines++; } else { wee_log_printf (_("%s not enough memory for new line!\n")); return NULL; } + + /* remove one line if necessary */ + if ((cfg_history_max_lines > 0) + && (window->num_lines > cfg_history_max_lines)) + { + if (window->last_line == window->lines) + window->last_line = NULL; + ptr_line = window->lines->next_line; + gui_line_free (window->lines); + window->lines = ptr_line; + ptr_line->prev_line = NULL; + window->num_lines--; + if (window->first_line_displayed) + gui_redraw_window_chat (window); + } + return new_line; } diff --git a/src/gui/gui.h b/src/gui/gui.h index 019acc00d..478b0f989 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -168,6 +168,7 @@ struct t_gui_window /* chat content (lines, line is composed by many messages) */ t_gui_line *lines; /* lines of chat window */ t_gui_line *last_line; /* last line of chat window */ + int num_lines; /* number of lines in the window */ int first_line_displayed; /* = 1 if first line is displayed */ int sub_lines; /* if > 0 then do not display until end */ int line_complete; /* current line complete ? (\n ending) */ @@ -185,7 +186,9 @@ struct t_gui_window /* history */ t_history *history; /* commands history */ + t_history *last_history; /* last command in history */ t_history *ptr_history; /* current command in history */ + int num_history; /* number of commands in history */ /* link to next window */ t_gui_window *prev_window; /* link to previous window */ diff --git a/weechat/ChangeLog b/weechat/ChangeLog index 6dd41e0b4..f31a1ed83 100644 --- a/weechat/ChangeLog +++ b/weechat/ChangeLog @@ -1,9 +1,12 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2004-06-05 +ChangeLog - 2004-06-13 +Version 0.0.7 (under dev!): + * added history limit (text buffer & commands) + Version 0.0.6 (2004-06-05): * improved channel highlight (priority to message vs join/part) * fixed bug when opened private win and remote user changes his nick diff --git a/weechat/TODO b/weechat/TODO index be25773ee..e98aa88d8 100644 --- a/weechat/TODO +++ b/weechat/TODO @@ -1,7 +1,7 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -TODO - 2004-06-05 +TODO - 2004-06-13 Legend: # done @@ -10,7 +10,7 @@ Legend: ? is this really necessary? -v0.0.6: +v0.0.7: ------ * General: @@ -18,15 +18,13 @@ v0.0.6: + Solaris version * IRC protocol: - # "/mode" command: change the user/channels modes + "/dcc" command (for chat and sending/receiving files) - # "/query" command: start private conversation * Interface: + internationalization (traduce WeeChat in many languages) - # display current channel modes (example : #weechat(+nt)) * Configuration: + # history limit (text buffer & commands) + add missing options for config file - add key bindings to config file diff --git a/weechat/src/common/history.c b/weechat/src/common/history.c index 4f49028a6..c930de452 100644 --- a/weechat/src/common/history.c +++ b/weechat/src/common/history.c @@ -29,11 +29,14 @@ #include "weechat.h" #include "history.h" +#include "weeconfig.h" #include "../gui/gui.h" t_history *history_general = NULL; +t_history *history_general_last = NULL; t_history *history_general_ptr = NULL; +int num_history_general = 0; /* @@ -43,25 +46,63 @@ t_history *history_general_ptr = NULL; void history_add (void *window, char *string) { - t_history *new_history; + t_history *new_history, *ptr_history; + /* add history to general history */ new_history = (t_history *)malloc (sizeof (t_history)); if (new_history) { new_history->text = strdup (string); - /* add history to general history */ if (history_general) history_general->prev_history = new_history; + else + history_general_last = new_history; new_history->next_history = history_general; new_history->prev_history = NULL; history_general = new_history; + num_history_general++; + + /* remove one command if necessary */ + if ((cfg_history_max_commands > 0) + && (num_history_general > cfg_history_max_commands)) + { + ptr_history = history_general_last->prev_history; + history_general_last->prev_history->next_history = NULL; + if (history_general_last->text) + free (history_general_last->text); + free (history_general_last); + history_general_last = ptr_history; + num_history_general--; + } + } + + /* add history to local history */ + new_history = (t_history *)malloc (sizeof (t_history)); + if (new_history) + { + new_history->text = strdup (string); - /* add history to local history */ if (((t_gui_window *)(window))->history) ((t_gui_window *)(window))->history->prev_history = new_history; + else + ((t_gui_window *)(window))->last_history = new_history; new_history->next_history = ((t_gui_window *)(window))->history; new_history->prev_history = NULL; ((t_gui_window *)window)->history = new_history; + ((t_gui_window *)(window))->num_history++; + + /* remove one command if necessary */ + if ((cfg_history_max_commands > 0) + && (((t_gui_window *)(window))->num_history > cfg_history_max_commands)) + { + ptr_history = ((t_gui_window *)window)->last_history->prev_history; + ((t_gui_window *)window)->last_history->prev_history->next_history = NULL; + if (((t_gui_window *)window)->last_history->text) + free (((t_gui_window *)window)->last_history->text); + free (((t_gui_window *)window)->last_history); + ((t_gui_window *)window)->last_history = ptr_history; + ((t_gui_window *)(window))->num_history++; + } } } diff --git a/weechat/src/common/weeconfig.c b/weechat/src/common/weeconfig.c index 6b1f6b0df..5216bae93 100644 --- a/weechat/src/common/weeconfig.c +++ b/weechat/src/common/weeconfig.c @@ -1258,8 +1258,8 @@ config_write (char *config_name) if ((i != CONFIG_SECTION_ALIAS) && (i != CONFIG_SECTION_SERVER)) { fprintf (file, "\n[%s]\n", config_sections[i].section_name); - if ((i == CONFIG_SECTION_HISTORY) || (i == CONFIG_SECTION_LOG) || - (i == CONFIG_SECTION_DCC) || (i == CONFIG_SECTION_PROXY)) + if ((i == CONFIG_SECTION_LOG) || (i == CONFIG_SECTION_DCC) || + (i == CONFIG_SECTION_PROXY)) fprintf (file, "# WARNING!!! Options for section \"%s\" are not developed!\n", config_sections[i].section_name); diff --git a/weechat/src/gui/gui-common.c b/weechat/src/gui/gui-common.c index b9b036e17..4da80b9e9 100644 --- a/weechat/src/gui/gui-common.c +++ b/weechat/src/gui/gui-common.c @@ -34,6 +34,7 @@ #include "../common/weechat.h" #include "gui.h" +#include "../../common/weeconfig.h" #include "../irc/irc.h" @@ -92,6 +93,7 @@ gui_window_new (void *server, void *channel, int switch_to_window /* init lines */ new_window->lines = NULL; new_window->last_line = NULL; + new_window->num_lines = 0; new_window->first_line_displayed = 1; new_window->sub_lines = 0; new_window->line_complete = 1; @@ -110,7 +112,9 @@ gui_window_new (void *server, void *channel, int switch_to_window /* init history */ new_window->history = NULL; + new_window->last_history = NULL; new_window->ptr_history = NULL; + new_window->num_history = 0; /* switch to new window */ if (switch_to_window) @@ -161,6 +165,7 @@ gui_window_clear (t_gui_window *window) window->lines = NULL; window->last_line = NULL; + window->num_lines = 0; window->first_line_displayed = 1; window->sub_lines = 0; window->line_complete = 1; @@ -240,6 +245,26 @@ gui_infobar_remove () } /* + * gui_line_free: delete a line from a window + */ + +void +gui_line_free (t_gui_line *line) +{ + t_gui_message *ptr_message; + + while (line->messages) + { + ptr_message = line->messages->next_message; + if (line->messages->message) + free (line->messages->message); + free (line->messages); + line->messages = ptr_message; + } + free (line); +} + +/* * gui_window_free: delete a window */ @@ -247,7 +272,6 @@ void gui_window_free (t_gui_window *window) { t_gui_line *ptr_line; - t_gui_message *ptr_message; int create_new; create_new = (window->server || window->channel); @@ -261,15 +285,7 @@ gui_window_free (t_gui_window *window) while (window->lines) { ptr_line = window->lines->next_line; - while (window->lines->messages) - { - ptr_message = window->lines->messages->next_message; - if (window->lines->messages->message) - free (window->lines->messages->message); - free (window->lines->messages); - window->lines->messages = ptr_message; - } - free (window->lines); + gui_line_free (window->lines); window->lines = ptr_line; } if (window->input_buffer) @@ -301,7 +317,7 @@ gui_window_free (t_gui_window *window) t_gui_line * gui_new_line (t_gui_window *window) { - t_gui_line *new_line; + t_gui_line *new_line, *ptr_line; if ((new_line = (t_gui_line *) malloc (sizeof (struct t_gui_line)))) { @@ -317,12 +333,29 @@ gui_new_line (t_gui_window *window) new_line->prev_line = window->last_line; new_line->next_line = NULL; window->last_line = new_line; + window->num_lines++; } else { wee_log_printf (_("%s not enough memory for new line!\n")); return NULL; } + + /* remove one line if necessary */ + if ((cfg_history_max_lines > 0) + && (window->num_lines > cfg_history_max_lines)) + { + if (window->last_line == window->lines) + window->last_line = NULL; + ptr_line = window->lines->next_line; + gui_line_free (window->lines); + window->lines = ptr_line; + ptr_line->prev_line = NULL; + window->num_lines--; + if (window->first_line_displayed) + gui_redraw_window_chat (window); + } + return new_line; } diff --git a/weechat/src/gui/gui.h b/weechat/src/gui/gui.h index 019acc00d..478b0f989 100644 --- a/weechat/src/gui/gui.h +++ b/weechat/src/gui/gui.h @@ -168,6 +168,7 @@ struct t_gui_window /* chat content (lines, line is composed by many messages) */ t_gui_line *lines; /* lines of chat window */ t_gui_line *last_line; /* last line of chat window */ + int num_lines; /* number of lines in the window */ int first_line_displayed; /* = 1 if first line is displayed */ int sub_lines; /* if > 0 then do not display until end */ int line_complete; /* current line complete ? (\n ending) */ @@ -185,7 +186,9 @@ struct t_gui_window /* history */ t_history *history; /* commands history */ + t_history *last_history; /* last command in history */ t_history *ptr_history; /* current command in history */ + int num_history; /* number of commands in history */ /* link to next window */ t_gui_window *prev_window; /* link to previous window */ |