[m-dev.] Porposal: Support reading/writing either dos/unix file endings on any platform
novalazy at gmail.com
Tue Nov 12 15:04:16 AEDT 2013
On Tue, 12 Nov 2013 14:30:31 +1100, Paul Bone <paul at bone.id.au> wrote:
> On Tue, Nov 12, 2013 at 01:03:10PM +1100, Peter Wang wrote:
> > >
> > > Thoughts?
> > I think you should specify whether you want CRLF->LF translation for
> > input streams, and LF->CRLF for output streams (defaulting to, e.g.
> > "yes" for input and "host" for output). I'm not keen on the automatic
> > detection. If it's limited to checking if/what type of newline
> > translation was required in the input stream *so far* then that's
> > probably ok. output_stream_line_ending_style seems pointless.
> The automatic detection is useful when the programmer doesn't care which
> format is used, but wants to provide a consistency for the user. This is
> true for the 'error' program.
Sure, you just left the mechanism ambiguous. I would object to anything
that requires pre-reading any part of the file. If you just set a flag
after seeing CR/LF then at least that's well defined.
> Regarding CRLF->LF translation for input streams. Are you saying that when
> a programmer reads from an input streams that, as a programmer, they should
> only have to expect LF characters? Is this too unix centric? I haven't
> done programming on windows for a very long time, what would a windows
> programmer expect?
The C standard I/O library does what I'm proposing. A FILE stream
opened in text mode (fopen with "rt", "wt") translates CRLF into '\n'
and via versa. In binary mode ("rb", "wb") there is no translation.
> > A related problem is file encodings, and the "UTF-8 BOM".
> Yep, I'm no expert here.
The solution should leave open the possibility for other settings, e.g.
:- type stream_params. % abstract
:- func default_stream_params = stream_params.
:- pred set_line_ending_stream_param(line_ending::in,
stream_params::in, stream_params::out) is det.
:- pred open_output(string::in, stream_params::in,
io.res(io.output_stream)::out, io::di, io::uo) is det.
More information about the developers