[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: LF/CR conversion
> If the former, should it have wildcard support for bulk conversions
> (this would add some work so would probably have to wait for version
> two). Should it attempt to auto-identify the type of the source file?
> What if anything should be done with "naked" CR (missing the following
> LF) characters in a DOS file?
I think the best general-purpose approach is to look for a CR or a LF
and see if there is a corresponding LF or CR next to it, if any. The
only thing you have to be cautious for is if you have two EOL's in a
row (e.g. an empty line). Here's a pseudo-code variant of this idea
which might work. I've moved some stuff around so that it might lend
itself to more compact assembler.
Loop:
source = address of read position
target = address of write position
:char
// CR and LF mean that the corresponding escape character was
encountered most recently and a newline should be output at some point
in the near future...
CR=LF=false
:char2
char = (source)
if char == cr
if CR
call writeNewline
goto char
else
CR = true
if LF
call writeNewline
goto char2
if char == lf
if LF
call writeNewline
goto char
else
LF = true
if CR
call writeNewline
goto char2
else //if char != cr && char != lf
if (CR||LF) call writeNewline
write(source, ++target)
goto char
:newline
write('\n', ++target) // where \n corresponds to the proper
newline character(s)
return