[Smaug] CR/LF and so on

Peter Belew peterbe at sonic.net
Thu, 13 Jun 2002 13:14:52 -0700 (PDT)

Regarding the CR/LF issue:

Originally, mechanical terminals (teletypes etc.) returned
their printheads to the left with a CR character, and the LF
character advanced the paper. 

Whatever a filesystem used to indicate the end of a line (CR,
LF, another character, a byte  or character count), the
CR-LF sequence (and somettimes some additional characters which
did  nothing but provide time for the printhead to return)
had to be sent to the teleprinter.
Most 'dumb' terminals and most terminal emulators for ASCII
emulate this convention.

Unix uses a LF ('\n') character to end lines in plain text

Some other OSes used to use CR to end lines, and in fact the
non-Unix Mac systems do so.

Some old DEC or Data General OSes used the CR-LF sequence
to end lines, and this was used by Gary KilDdall's CP/M
system. It was also the convention in Microsoft BASIC -
actually the  normal line termination was CR-LF, while
continuation lines in BASIC programs were separated with
LF alone. Because of this convention, and for compatibility
with some other  CP/M software, BillG decided to use CR-LF
in MS-DOS.

For this reason, '\n' - supposed to be just a linefeed -
is handled specially in Microsoft C. MS-C opens files
either in 'text' or 'binary' mode (you can make this
specification in Unix C, but it makes no difference).
In 'text' mode, LF characters  on file output are expanded
into CR-LF. CR is represented in C and related languages
as '\m'.  (There are some cases in the Microsoft
programming world where you may have to explicitly
write "\n\r" or "\r\n" - such as in text written to some
GUI widgets).

(I  may have some typos above - I am ssh-ing from a newly-installed
FreeBSD to my ISP, and the terminal emulation is annoying!).

(some configuration remains to be done!)

 -- Peter