CR/LF translation


I changed mc to support CR/LF translation, patch is attached.
It is very useful for cygwin and also useful under unixes if it is
necessary to edit files in dos encoding.
There is some old code in mc for CR/LF translation, but it is slow and based
on FILE stdio.h interface, whereas editor now uses  open/read/write
I wrote new code, which
1. reads file into buffer
2. determines  type of file: dos or Unix, sets a new flag in WEdit structure
3. if file is dos, we allocate new buffer and copy the contents of first
buffer to new buffer with conversion to Unix
4. status line now shows type of file
5. while saving file translate it back to dos , if it was dos
There is an  assumption that we are running on some decent 32 bit hardware
because we are reading whole file into buffer for further translation. If 16
bit hardware detected, we just don't do translation.

The second part of the patch fixes problems with CR in case if we are not
using translation or if we have CR embedded in text . It works like vi with
dos files:  it shows CR as ^M. The
original mc code handles CR very badly, it completely messes up files in dos

Third part of patch fixes problem with dos text files on volumes mounted in
text mode under cygwin.
This problem is actually very dangerous because mc corrupts files in this
case. Solution is to open all files in binary mode and do CR/LF translation.
There was one instance of opening file with some strange MY_O_TEXT flag, I
had to remove it because otherwise it  may conflict with O_BINARY flag.


Attachment: CR_LF.patch
Description: Binary data

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]