/[weechat]/weechat/src/common/history.c
ViewVC logotype

Diff of /weechat/src/common/history.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by kolter, Sun Nov 13 16:59:40 2005 UTC revision 1.12 by flashcode, Tue Dec 6 18:21:01 2005 UTC
# Line 66  history_hide_password (char *string) Line 66  history_hide_password (char *string)
66  }  }
67    
68  /*  /*
69   * history_add: add a text/command to history   * history_buffer_add: add a text/command to buffer's history
70   */   */
71    
72  void  void
73  history_add (void *buffer, char *string)  history_buffer_add (void *buffer, char *string)
74  {  {
75      t_history *new_history, *ptr_history;      t_history *new_history, *ptr_history;
   
     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--;  
             }  
         }  
     }  
76            
77      if ( !((t_gui_buffer *)(buffer))->history      if ( !((t_gui_buffer *)(buffer))->history
78           || ( ((t_gui_buffer *)(buffer))->history           || ( ((t_gui_buffer *)(buffer))->history
79                && ascii_strcasecmp (((t_gui_buffer *)(buffer))->history->text, string) != 0))                && ascii_strcasecmp (((t_gui_buffer *)(buffer))->history->text, string) != 0))
80      {        {  
         /* add history to local history */  
81          new_history = (t_history *)malloc (sizeof (t_history));          new_history = (t_history *)malloc (sizeof (t_history));
82          if (new_history)          if (new_history)
83          {          {
# Line 129  history_add (void *buffer, char *string) Line 92  history_add (void *buffer, char *string)
92              new_history->next_history = ((t_gui_buffer *)(buffer))->history;              new_history->next_history = ((t_gui_buffer *)(buffer))->history;
93              new_history->prev_history = NULL;              new_history->prev_history = NULL;
94              ((t_gui_buffer *)buffer)->history = new_history;              ((t_gui_buffer *)buffer)->history = new_history;
95              ((t_gui_buffer *)(buffer))->num_history++;              ((t_gui_buffer *)buffer)->num_history++;
96                            
97              /* remove one command if necessary */              /* remove one command if necessary */
98              if ((cfg_history_max_commands > 0)              if ((cfg_history_max_commands > 0)
# Line 145  history_add (void *buffer, char *string) Line 108  history_add (void *buffer, char *string)
108              }              }
109          }          }
110      }      }
111    }
112    
113    /*
114     * history_global_add: add a text/command to buffer's history
115     */
116    
117    void
118    history_global_add (char *string)
119    {
120        t_history *new_history, *ptr_history;
121    
122        if (!history_global
123            || (history_global
124                && ascii_strcasecmp (history_global->text, string) != 0))
125        {    
126            new_history = (t_history *)malloc (sizeof (t_history));
127            if (new_history)
128            {
129                new_history->text = strdup (string);
130                if (cfg_log_hide_nickserv_pwd)
131                    history_hide_password (new_history->text);
132                
133                if (history_global)
134                    history_global->prev_history = new_history;
135                else
136                    history_global_last = new_history;
137                new_history->next_history = history_global;
138                new_history->prev_history = NULL;
139                history_global = new_history;
140                num_history_global++;
141                
142                /* remove one command if necessary */
143                if ((cfg_history_max_commands > 0)
144                    && (num_history_global > cfg_history_max_commands))
145                {
146                    ptr_history = history_global_last->prev_history;
147                    history_global_last->prev_history->next_history = NULL;
148                    if (history_global_last->text)
149                        free (history_global_last->text);
150                    free (history_global_last);
151                    history_global_last = ptr_history;
152                    num_history_global--;
153                }
154            }
155        }
156  }  }
157    
158  /*  /*

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26