On 07.12.2010, at 17:15, [email protected] wrote: > 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"
Interesting approach. But I wonder if this is 'safe'. As for the line count, this is only right if the complete file is in DOS mode (no mixing of some lines in DOS mode, others lf-only). But I think that these details wouldn't matter. > - 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. Wouldn't it be enough to open the file with 'wb' or 'w', depending on the flag? That's what I always did in the Windows world. The only difference would be if the file was already open, and you changed the mode for this open file (I don't know if this is possible, it's just a guess). > That, IIRC, did the Right Thing, but was a bit of a fiddle. Yep ;-) > 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! I can imagine that we might add an option to Fl_Text_Buffer::outputfile() to do just this: select the writing mode. Or we could set the flag with another method on the Fl_Text_Buffer, so that it is known when writing. But this would only work on Windows (because Windows does it for us). On all other systems we would have to add the cr's ourselves. Ooh, that seems like a bad idea, forget it ;-) Albrecht _______________________________________________ fltk-dev mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk-dev
