RenE J.V. Bertin
2002-Jul-10 14:35 UTC
history patch (was Re: portable snprintf implementation)
Here's the patch. It looks like it does what I want it to do, but I
haven't
yet tried it with multiple-line entries and the like. Please let me know if
anything turns up that I should look into (I attached it too, in case
hotmail wraps).
RenE J.V. Bertin
College de France/LPPA
11, place Marcelin Berthelot
75005 Paris, France
## A couple of 'diff -c' patches to modify the history system such that
subsequent identical lines are only entered once.
*** src/unix/sys-std.c.orig Sat Jun 29 19:16:31 2002
--- src/unix/sys-std.c Wed Jul 10 16:23:59 2002
***************
*** 324,331 ****
return;
if (line[0]) {
# ifdef HAVE_READLINE_HISTORY_H
! if (strlen(line) && readline_addtohistory)
! add_history(line);
# endif
l = (((readline_len-2) > strlen(line))?
strlen(line): (readline_len-2));
--- 324,353 ----
return;
if (line[0]) {
# ifdef HAVE_READLINE_HISTORY_H
! if (strlen(line) && readline_addtohistory){
! static char called=0;
! /* RJVB: Only add lines that are not identical to the previous line.
This is a very cheap
! \ way to reduce the history size, and to reduce the time the user may
spent searching it!
! \ For this to work properly, we (apparently) need to initialise the
history mechanism with
! \ the call to using_history().
! */
! HIST_ENTRY *prev= current_history();
! if( !called ){
! using_history();
! called= TRUE;
! }
! if( !prev ){
! /* It is possible that current_history() returns NULL while there
is a history. In that case,
! \ back up one entry, and if that succeeds, inch forward again.
! */
! if( (prev= previous_history()) ){
! next_history();
! }
! }
! if( !prev || strcmp(line, prev->line) ){
! add_history(line);
! }
! }
# endif
l = (((readline_len-2) > strlen(line))?
strlen(line): (readline_len-2));
*** src/modules/gnome/gtkconsole.c.orig Wed Mar 20 18:24:41 2002
--- src/modules/gnome/gtkconsole.c Wed Jul 10 16:21:30 2002
***************
*** 299,312 ****
/* add command to history */
term_ptr = strchr (text_chars, '\n');
if ((add_to_history == TRUE) && (term_ptr != NULL) &&
(*text_chars !=
'\n'))
! {
! history_buf = g_malloc (term_ptr - text_chars + 1);
! *term_ptr = '\0';
! strncpy (history_buf, text_chars, term_ptr - text_chars + 1);
! GTK_CONSOLE (object)->history ! g_list_prepend (GTK_CONSOLE
(object)->history, history_buf);
! GTK_CONSOLE (object)->history_num_items++;
}
g_free (text_chars);
--- 299,329 ----
/* add command to history */
term_ptr = strchr (text_chars, '\n');
if ((add_to_history == TRUE) && (term_ptr != NULL) &&
(*text_chars !=
'\n'))
! { GList *prev = NULL;
! /* RJVB: I don't like it when a repeated command is put into the
history every time...
! \ For this, we have to disregard object->history_cur; it will be NULL
when we come
! \ here after entering a new line, but it will point to the selected
history line when
! \ we come here after "wandering" through the history, and
selecting a
previously entered
! \ command. I think that we do want to enter that command anew into
the history!
! */
! prev = object->history;
! if( prev ){
! *term_ptr = '\0';
! if( !strncmp( text_chars, (char*) prev->data, term_ptr - text_chars )
){
! add_to_history= FALSE;
! }
! }
! if( add_to_history ){
! history_buf = g_malloc (term_ptr - text_chars + 1);
! /* RJVB: sh*t happens... */
! g_return_if_fail( history_buf!=NULL );
! strncpy (history_buf, text_chars, term_ptr - text_chars + 1);
!
! GTK_CONSOLE (object)->history ! g_list_prepend (GTK_CONSOLE
(object)->history, history_buf);
! GTK_CONSOLE (object)->history_num_items++;
! }
}
g_free (text_chars);
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
Possibly Parallel Threads
- after_create and after_save
- overzealous help-links.sh script! (PR#1682)
- [LLVMdev] assert when mixing static and non-static members with an external AST source
- [LLVMdev] assert when mixing static and non-static members with an external AST source
- settings headers in mechanize
