history patch (was Re: portable snprintf implementation)

RenE J.V. Bertin rjvbertin@hotmail.com
Wed, 10 Jul 2002 16:35:20 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_3896_5dbc_cfa
Content-Type: text/plain; format=flowed

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

------=_NextPart_000_3896_5dbc_cfa
Content-Type: application/octet-stream; name="RJVB-20020709.patch"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="RJVB-20020709.patch"

IyMgQSBjb3VwbGUgb2YgJ2RpZmYgLWMnIHBhdGNoZXMgd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nMuLi4gKi8KISAJCQlnX3JldHVybl9p
Zl9mYWlsKCBoaXN0b3J5X2J1ZiE9TlVMTCApOwohIAkJCXN0cm5jcHkgKGhp
c3RvcnlfYnVmLCB0ZXh0X2NoYXJzLCB0ZXJtX3B0ciAtIHRleHRfY2hhcnMg
KyAxKTsKISAKISAJCQlHVEtfQ09OU09MRSAob2JqZWN0KS0+aGlzdG9yeSA9
CiEgCQkJCWdfbGlzdF9wcmVwZW5kIChHVEtfQ09OU09MRSAob2JqZWN0KS0+
aGlzdG9yeSwgaGlzdG9yeV9idWYpOwohIAkJCUdUS19DT05TT0xFIChvYmpl
Y3QpLT5oaXN0b3J5X251bV9pdGVtcysrOwohIAkJfQogICAgICB9CiAgCiAg
ICBnX2ZyZWUgKHRleHRfY2hhcnMpOwo=


------=_NextPart_000_3896_5dbc_cfa--

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._