Matthias Melcher wrote:

On 07.12.2010, at 14:42, Albrecht Schlosser wrote:

On 07.12.2010, at 00:25, [email protected] wrote:
Author: matt
Date: 2010-12-06 15:25:52 -0800 (Mon, 06 Dec 2010)
New Revision: 7968
Log:
Ooops, Fl_Text_Buffer::insertfile must read in binary format, or it will screw 
up line endings! (Actually, this could be debated, but by reading and writing 
in binary format, the file integrity would remain)

Hmm, sorry, no, that doesn't work. :-(

[...]

OK. I will revert this then.

Unfortunately that alone doesn't help. See attached file
textbuffer_binary.diff for a working example how to modify
the code. Please feel free to modify it, and/or remove the
test printf statements. With these statements, you can see
what happens:

./editor editor.cxx
filesize = 21853
rsize = 21042

i.e. the read size is less than the file size, because all the
cr's have been stripped.

Now, this works, but the *written* file is still in U*ix (lf-only)
format. I didn't investigate further, but it should probably also
be changed to write in text (not binary) format. But (just looking
at Fl_Text_Buffer::outputfile()) there seems to be the same problem
if we write in text format (line 1559: if (r != n) ...).

Sorry, no solution, but I hope it may help a little bit.

Albrecht
Index: src/Fl_Text_Buffer.cxx
===================================================================
--- src/Fl_Text_Buffer.cxx      (revision 7968)
+++ src/Fl_Text_Buffer.cxx      (working copy)
@@ -1521,17 +1521,20 @@
 int Fl_Text_Buffer::insertfile(const char *file, int pos, int /*buflen*/)
 {
   FILE *fp;
-  if (!(fp = fl_fopen(file, "rb")))
+  if (!(fp = fl_fopen(file, "r")))
     return 1;
   fseek(fp, 0, SEEK_END);
   size_t filesize = ftell(fp);
+  // printf ("filesize = %d\n",filesize); fflush(stdout);
   fseek(fp, 0, SEEK_SET);  
   if (!filesize) return 0;
   char *buffer = new char[filesize+1];
-  if (fread(buffer, 1, filesize, fp)==filesize) {
-    buffer[filesize] = (char) 0;
+  size_t rsize = 0;
+  if ((rsize = fread(buffer, 1, filesize, fp)) > 0 /* ==filesize */ ) {
+    buffer[rsize] = (char) 0;
     insert(pos, buffer);
   }
+  // printf ("rsize = %d\n",rsize); fflush(stdout);
   int e = ferror(fp) ? 2 : 0;
   fclose(fp);
   delete[]buffer;
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to