This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch-readline] history file reading



Eli Zaretskii wrote:


Date: Thu, 16 Mar 2006 14:44:38 +0100
From: Denis PILAT <denis.pilat@st.com>

On minGW host, history file are open in text mode, that's imply windows specific
carriage return to be inserted ( \n -> \r\n conversion performed) and prevents windows history file to be compliant with linux one's.
When using current history file for windows, "^M" appears at each end of line.


This patch fixes this problem.



Thanks.


However, I think there's a better fix: teach readline to always remove
any CRs before an LF character, even on Posix platforms.  That way,
even if the history file was edited by some Windows editor that
doesn't honor the end-of-line format, it can still be read on any OS.
And as a bonus, we might get a cleaner code, without ugly OS-dependent
#ifdef's.

Unless Chet and others disagree, would you like to prepare a patch
along these lines?



This new version of my patch changes the way we read history files to allow "\r\n" in end-of-line.
I don't change any more the way we write history files.


--
Denis


2006-03-21 Denis Pilat <denis.pilat@st.com>


* histfile.c (read_history_range): remove '\r' character from history lines
to allow reading files with Windows like end-of-line on unix host.




Index: histfile.c
===================================================================
--- histfile.c	(revision 386)
+++ histfile.c	(working copy)
@@ -228,7 +228,11 @@
   for (line_end = line_start; line_end < bufend; line_end++)
     if (*line_end == '\n')
       {
-	*line_end = '\0';
+	/* allow reading files with Windows like end-of-line */
+	if ( line_end - 1 >= line_start && *( line_end - 1 ) =='\r' )
+	  *( line_end - 1 )  = '\0';
+	else
+	  *line_end = '\0';
 
 	if (*line_start)
 	  add_history (line_start);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]