> 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.

(I don't have a solution, but a few things that *might* help perhaps.)

I still can't find the source files for my old editor, but I think what 
I did was this:

- If the file was originally in "DOS-mode" when I read it in (determined 
by sniffing the raw binary for CR/LF pairs or, as Albrecht pointed out, 
checking the size - note that the file size is short by  the number 
lines in the file, which I took as a "robust" indication that the CR's 
had been stripped) then I set a flag in the edit class that recorded 
that the file was in "DOS-mode"

- On saving the file back out, I check the flag, and if "DOS-mode" was 
needed I made a local copy of _fmode, set _fmode = O_TEXT; then save the 
file, then restore _fmode to the stored value.
If the file is *not* in "DOS-mode", then I did the same but forced 
_fmode = O_BINARY; before writing the file out.

That, IIRC, did the Right Thing, but was a bit of a fiddle.
It had the sometimes useful side-effect that I could then explicitly 
change the DOS-mode flag and use this convert unix-to-dos or dos-to-unix 
on saving, which used to matter, as a lot of the tools back then could 
not cope with all the variant line endings as well as they do now!

-- 
Ian



_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to