On Monday, August 20, 2001, at 08:47 AM, Gunnar Farnebddck wrote:
Dave wrote:
AFAIK VC is doing the correct thing : \n is defined to expand to whatever line ending is appropriate for the platform.
[...]
I think I did mention this feature of \n | \r, and pointed out that any portable implementations of GTP code should use \012 explicitly if they mean a LF character.
[...]
And on mac, \n is CR
\012 is probably safest if you really mean a LF character
I'm almost, but not completely, certain that you are somewhat wrong here. What follows is my understanding, which also could be wrong. It's correct that the C standard doesn't say what numerical value '\n' should have, although ascii LF is a common choice, at least on unix platforms. I'm pretty certain that '\n' does NOT expand to anything like CRLF on dos/windows platforms simply because that is not a single character. It's possible that '\n' has the value ascii CR on MacOS, but that is more than I know about.
Perl on Windows outputs CRLF for \n. Just read this last night in the Perl Cookbook. So if we want twogtp to work on Windows, the gtp protocol has to deal with CRLF at the minimum. Mac perl probably spits out a CR, so the same goes there, except on Mac OS X, which is really unix...
Someone could write a quick C program to find out what Windows does in C with \n for sure on that platform.
"A newline is a indicated by a single LF. Possible occurences of CR should be discarded on input."
would be difficult to handle. This is in any case the newline convention I would prefer for GTP.
Then it won't work on CR platforms...
There are three cases: CR, LF, CRLF.
If we want to handle all three, we need an or clause to deal with the CR vs LF case. It seems to me our choices are:
1. Handle LF. 2. Handle CRLF by ignoring CRs. 3. Handle all three by looking for CR | LF and ignoring any extra LF.
I think #2 is worse, because it will mysteriously not work on some platforms. YMMV.
#3 doesn't really seem much more difficult then #2 but it does mean we can't use things like fgets.
Pierce