Getting line endings straight.

David Bovill david at vaudevillecourt.tv
Fri Oct 1 09:24:38 EDT 2010


Most of the time we don;t need to worry about line endings - Rev handles
them for us transparently. However, sometimes when workign with external
sources you can get bitten. I thought I'd post this to make sure I've got
things straight, and hopefully clarify things for others. My understanding
is as follows:

   1. LiveCode uses the unix flavoured line ending character internally.
   That is LF or numtochar(10) in LiveCode
   2. LiveCode translates text for you in the background when you use "file
   url's", and open driver, open file, or open processcommands in text mode.
   For example when you use the normal "file" url syntax - ie "put someText
   into url 'file:some.txt'"
   3. On OSX and Linux this is the same as LiveCode's internal line ending
   char = LF or numtochar(10)
   4. On Windows LiveCode would translate the line endings to CRLF =
   numtochar(13) & numtochar(10)
   5. On older Mac Classic systems the line ending character is CR =
   numtochar(13)

Some gotcha's:

   - A carriage return is numtochar(13) - however LiveCode internally thinks
   that CR = LF = numtochar(10)
   - On OSX LiveCode does not write out text using the systems native line
   endings - it uses the older Mac Classic line endings (presumably for easier
   compatability)!

The last one I did not know. Personally I think it is bad behavior, though
most OSX applications handle either form of text file absolutely fine - some
command line tools expect the native unix style line endings (LF). If you
want to use these tools - don't use "file" - for writing out text - use
"binfile".

You can test this on your OSX system using the following in the message box:

put "Hello" & CR & "World" into someText
> put the tempname & ".txt" into someFile
> put someText into url ("file:" & someFile)
> put url ("binfile:" & someFile) contains numtochar(10)
>

Have I got something wrong here - or should we really be asking RunRev to
make it easy for us to read and write text files in native LF mode? Perhaps
there should be an IDE property which we could set base on "the platform",
or perhaps they can tweek their background translation code to keep backward
compatibility, while giving us native line endings on OSX?



More information about the Use-livecode mailing list