summaryrefslogtreecommitdiff
path: root/src/common/history.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/history.c')
-rw-r--r--src/common/history.c128
1 files changed, 69 insertions, 59 deletions
diff --git a/src/common/history.c b/src/common/history.c
index 980b0d1e5..4f1113eec 100644
--- a/src/common/history.c
+++ b/src/common/history.c
@@ -73,67 +73,77 @@ void
history_add (void *buffer, char *string)
{
t_history *new_history, *ptr_history;
-
- /* add history to global history */
- new_history = (t_history *)malloc (sizeof (t_history));
- if (new_history)
- {
- new_history->text = strdup (string);
- if (cfg_log_hide_nickserv_pwd)
- history_hide_password (new_history->text);
-
- if (history_global)
- history_global->prev_history = new_history;
- else
- history_global_last = new_history;
- new_history->next_history = history_global;
- new_history->prev_history = NULL;
- history_global = new_history;
- num_history_global++;
-
- /* remove one command if necessary */
- if ((cfg_history_max_commands > 0)
- && (num_history_global > cfg_history_max_commands))
- {
- ptr_history = history_global_last->prev_history;
- history_global_last->prev_history->next_history = NULL;
- if (history_global_last->text)
- free (history_global_last->text);
- free (history_global_last);
- history_global_last = ptr_history;
- num_history_global--;
- }
+
+ if ( !history_global
+ || ( history_global
+ && ascii_strcasecmp (history_global->text, string) != 0))
+ {
+ /* add history to global history */
+ new_history = (t_history *)malloc (sizeof (t_history));
+ if (new_history)
+ {
+ new_history->text = strdup (string);
+ if (cfg_log_hide_nickserv_pwd)
+ history_hide_password (new_history->text);
+
+ if (history_global)
+ history_global->prev_history = new_history;
+ else
+ history_global_last = new_history;
+ new_history->next_history = history_global;
+ new_history->prev_history = NULL;
+ history_global = new_history;
+ num_history_global++;
+
+ /* remove one command if necessary */
+ if ((cfg_history_max_commands > 0)
+ && (num_history_global > cfg_history_max_commands))
+ {
+ ptr_history = history_global_last->prev_history;
+ history_global_last->prev_history->next_history = NULL;
+ if (history_global_last->text)
+ free (history_global_last->text);
+ free (history_global_last);
+ history_global_last = ptr_history;
+ num_history_global--;
+ }
+ }
}
- /* add history to local history */
- new_history = (t_history *)malloc (sizeof (t_history));
- if (new_history)
- {
- new_history->text = strdup (string);
- if (cfg_log_hide_nickserv_pwd)
- history_hide_password (new_history->text);
-
- if (((t_gui_buffer *)(buffer))->history)
- ((t_gui_buffer *)(buffer))->history->prev_history = new_history;
- else
- ((t_gui_buffer *)(buffer))->last_history = new_history;
- new_history->next_history = ((t_gui_buffer *)(buffer))->history;
- new_history->prev_history = NULL;
- ((t_gui_buffer *)buffer)->history = new_history;
- ((t_gui_buffer *)(buffer))->num_history++;
-
- /* remove one command if necessary */
- if ((cfg_history_max_commands > 0)
- && (((t_gui_buffer *)(buffer))->num_history > cfg_history_max_commands))
- {
- ptr_history = ((t_gui_buffer *)buffer)->last_history->prev_history;
- ((t_gui_buffer *)buffer)->last_history->prev_history->next_history = NULL;
- if (((t_gui_buffer *)buffer)->last_history->text)
- free (((t_gui_buffer *)buffer)->last_history->text);
- free (((t_gui_buffer *)buffer)->last_history);
- ((t_gui_buffer *)buffer)->last_history = ptr_history;
- ((t_gui_buffer *)(buffer))->num_history++;
- }
+ if ( !((t_gui_buffer *)(buffer))->history
+ || ( ((t_gui_buffer *)(buffer))->history
+ && ascii_strcasecmp (((t_gui_buffer *)(buffer))->history->text, string) != 0))
+ {
+ /* add history to local history */
+ new_history = (t_history *)malloc (sizeof (t_history));
+ if (new_history)
+ {
+ new_history->text = strdup (string);
+ if (cfg_log_hide_nickserv_pwd)
+ history_hide_password (new_history->text);
+
+ if (((t_gui_buffer *)(buffer))->history)
+ ((t_gui_buffer *)(buffer))->history->prev_history = new_history;
+ else
+ ((t_gui_buffer *)(buffer))->last_history = new_history;
+ new_history->next_history = ((t_gui_buffer *)(buffer))->history;
+ new_history->prev_history = NULL;
+ ((t_gui_buffer *)buffer)->history = new_history;
+ ((t_gui_buffer *)(buffer))->num_history++;
+
+ /* remove one command if necessary */
+ if ((cfg_history_max_commands > 0)
+ && (((t_gui_buffer *)(buffer))->num_history > cfg_history_max_commands))
+ {
+ ptr_history = ((t_gui_buffer *)buffer)->last_history->prev_history;
+ ((t_gui_buffer *)buffer)->last_history->prev_history->next_history = NULL;
+ if (((t_gui_buffer *)buffer)->last_history->text)
+ free (((t_gui_buffer *)buffer)->last_history->text);
+ free (((t_gui_buffer *)buffer)->last_history);
+ ((t_gui_buffer *)buffer)->last_history = ptr_history;
+ ((t_gui_buffer *)(buffer))->num_history++;
+ }
+ }
}
}