On 07/12/10 16:57, Albrecht Schlosser wrote: > 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.
Indeed - it was a while ago, but I think I was also "sniffing" the raw binary if it looked suspiscious, and that did seem to work. Opening the files in MS in just "rw" mode, you get the CR/LF conversion on any lines that have CR/LF, but lines that are LF only seem to broadly unmolested... > 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). Well, for my editor I had the files open in "rw" mode anyway (discussion of whether that was wise or not for another time!) so I'd have to explicitly close and re-open the file "wb" if I wanted that mode. Forcing the MS _fmode flag did what I needed for files that were open as "text". >> 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 ;-) Indeed - in my code it was ifdef'd for WIN32 only. But MS platforms are the only ones where it mattered - on all other platforms, I found the tools were generally tolerant of line-ending variations (indeed even on WIN32 they seem more tolerant these days - though notepad is still rubbish!) _______________________________________________ fltk-dev mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk-dev
