1. Re: Mac text files and gets()
CChris wrote:
>
> CChris wrote:
> >
> > I happened to have a text file with \r line terminators on my HD, and wanted
> > to process it using gets(). It didn't work the expected way.
> >
> > I ran the following test:
> > }}}
<eucode>
> > integer fh
> > fh=open("test.txt","wb")
> > puts(fh,{65,10,66,26})
> > close(fh)
> > fh=open("test.txt","r")
> > ?gets(fh) -- {65,10}
> > ?gets(fh) -- {66}
> > ?gets(fh) -- -1
> > ?machine_func(26,0)
> > </eucode>
{{{
> >
> > This shows that a Unix style file can be read properly.
> > Now replace 10 by 13 in the puts() sequence (this is how a Mac file would
> > look
> > like), and the output is
> > {65,66}
> > -1
> > -1
> > Not the expected thing.
> >
> > Since it is about as likely, under Windows, to have Unix files or Mac files
> > on one's HD, isn't fixing/extending gets() to handle both formats a good
> > idea?
> > No need to modify the behaviour of EGets() for stdin, so changing lines
> > 2668-72
> > in be_runtime.c from
> > if (c <= '\n') {
> > if (c == '\n') {
> > break;
> > }
> >
> > to
> > if (c <= '\r') {
> > if (c == '\n') {
> > break;
> > }
> > if (c == '\r') {
> > c = '\n';
> > break;
> > }
> > should be enough. The extra test is taken only if a character in the 0.13
> > range
> > (a control charatcter) is read, so the impact should be nil on text files.
> >
> > Did I miss some ripple effect?
> >
> > CChris
>
> Since there were exactly zero comments regarding this earler post, I'll update
> the backend and the doc for gets() this weekend, unless there is a late
> outcry.
I don't think this is a good idea.
> Addiionally, I'll consider changing the second test to "<=", so that VT and
> FF are also treated as EOL by gets(). This can be useful when importing files
> output by mainframe computers, and is already implemented in the D language.
I don't think this is a good idea either.
You will break some existing Euphoria for Windows/DOS programs
in the name of added convenience in reading Mac files, an O/S
that currently is not supported by Euphoria. Wait until there
is a Mac version of Euphoria.
I'm sure there are other Euphoria programs, such as ed,
and possibly other places in the interpreter,
that also assume DOS/Windows (or sometimes) Linux,
line terminators, so your "enhancement" will not be complete,
and will just cause confusion.
There's already enough confusion in DOS/Windows
due to the silly distinction Microsoft makes between
"text" and "binary" files. Don't make it even more confusing.
Regards,
Rob Craig
Rapid Deployment Software
http://www.RapidEuphoria.com