Re: Mac text files and gets()

new topic     » topic index » view thread      » older message » newer message

Pete Lomax wrote:
> 
> CChris wrote:
> > 
> > Pete Lomax wrote:
> > > 
> > > this whole thread is probably moot anyway...
> > > 
> > 
> > Actually, the mod as I implemented it works fine under DOS/Windows, because
> > the OS takes care of removing the \r.
> I see, so the mod you suggested does nothing to fix the problem you reported.

It does, because isolated \r's are not removed by the OS.

> 
> > If we are to avoid this, then it looks like, under Linux/BSD, we'd need a
> > one
> > char lookahead buffer for gets(). Its contents would be needed so as to
> > recoginse
> > \r\n as \n, eliminating both the trailing \r and the spurious empty ine. 
> 
> You obviously did not read the rest of my post:
> <a
> href="http://www.openeuphoria.org/EUforum/m16613.html">http://www.openeuphoria.org/EUforum/m16613.html</a>
> 
> Pete

I had. But your change doesn't remove the need to read an extra character after
a \r has been read, since you don't know whether it is a DOS (\r\n) or Mac (\r)
file.

An alternative to the lookahead buffer would be the following: on opening a file
in "r" mode, fetch the first 256 (say) bytes of the file, and look for the first
\r or \n there. You can then assess the file format and use this info to process
\r right and not need to look ahead.

This also answers to Rob. "r" and "rb" are different strungs, so you may expect
a slightly different result from them, even under Linux. Or are you saying that
people use "r" indiscriminately when using a Unix-like filesystem? If so, and if
the practice is condoned, then the mod would have to be restricted to Windows, or
not be there at all - there have been requests for a Windows-specific Eu anyway
in the past.

CChris
CChris

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu