Historical question: LF vs. CR\LF in text files

Tom Almy toma at tekgvs.LABS.TEK.COM
Thu May 31 01:42:01 AEST 1990


In article <952 at ashton.UUCP> tomr at ashton.UUCP (Tom Rombouts) writes:
>Forgive the bandwidth, but seeing that others beside myself are
>having occassional problems relating to the differences between
>UNIX vs. DOS (and CP/M, correct?) in handling end of lines, I am
>wondering how this started.  Since UNIX came first, I am going to
>guess that at some time, somewhere someone said "Hey - let's add
>a carriage return!"  Does anyone know the (possibly amusing?) story
>behind this?  What was the essential rationale?

Turning back the clock, one delt with "records" where typically one
record equaled one line. There were no "carriage returns" or "line feeds".
But then (ignoring Flexowriters and other early terminals I never had the
chance to use) along came ASCII and the Teletype Model 33. ASCII defined
separate codes for the carriage return (which actually returned the print
head on the model 33, but at least it was a mechanical motion) and line
feed (which actually fed paper). The early *pre-UNIX* operating systems
tended to have these two characters represent the end of line because that
is what it took to run the printer.

Of course things weren't completely simple because one didn't want to hit
both the carriage return and line feed keys on the Teletype to enter lines
(you had to do this if you were in Off-Line mode) so carriage returns were
converted to cr/lf pairs on input. Also the extra byte did waste precious
storage.

I had used some systems that compressed the eol sequence to a single character
before UNIX existed (more later...).

UNIX didn't say "lets get rid of the carriage return and just use the line
feed". It invented a new code "new line". It just so happens to be internally
represented with the same code as the ASCII line feed. The TTY driver has
the responsibility of translating CR->NL on input and NL->CR/LF on output.
Note that the driver allows turning the translation off. About 10 years ago
I wrote a terminal emulator program that emulated a "UNIX" terminal -- the
carriage return key sent a "New Line", and the receipt of a "New Line" caused
a carriage return/line feed operation. This didn't last long because of
all the programs that ended up switching to RAW mode to bypass the conversion
behaved very poorly!

I have used several systems that went the single character route using the
Carriage Return. This is probably the most sensible because input conversion
is not necessary. Also standard typewriter practice is that the carriage
return operation (either key or lever on a manual typewriter (remember those?))
would also advance the line, but yet line advance could be independently
performed (with the knob on the end of the carriage).

I know that the net is full of UNIX-myopic people, but UNIX was not first nor
did it make the best move on this one.

Tom Almy
toma at tekgvs.labs.tek.com
Standard Disclaimers Apply



More information about the Comp.unix.questions mailing list