udfFileSetEOLToCRLF
int udfFileSetEOLToCRLF (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileSetEOLToCRLF (strFilename)
intBBSize = FileSize (strFilename)
If !intBBSize Then Return 0 ; Nothing to do.
intMax = intBBSize - 1
hdlBB = BinaryAlloc (intBBSize)
BinaryRead (hdlBB, strFilename)
intAdd =     -2 * BinaryStrCnt (hdlBB, 0, intMax, @CRLF)
intAdd = intAdd + BinaryStrCnt (hdlBB, 0, intMax, @CR)
intAdd = intAdd + BinaryStrCnt (hdlBB, 0, intMax, @LF)
hdlBB = BinaryFree (hdlBB)
If !intAdd Then Return intBBSize ; Nothing to do.
intBBSize = intBBSize + intAdd
hdlBB = BinaryAlloc (intBBSize)
BinaryRead (hdlBB, strFilename)
BinaryReplace (hdlBB, @CRLF, @LF, @TRUE)
BinaryReplace (hdlBB, @CR, @LF, @TRUE)
BinaryReplace (hdlBB, @LF, @CRLF, @TRUE)
intBBSize = BinaryWrite (hdlBB, strFilename)
hdlBB = BinaryFree (hdlBB)
Return intBBsize
;..........................................................................................................................................
; This UDF udfFileSetEOLtoCRLF normalizes the End-Of-Line sequences of a given textfile
; by setting the End-Of-Line sequences to the standard DOS EOL char sequence @CRLF.
; All single @CR or @LF chars will be changed to char sequence @CRLF.
;
; On success the function returns the new filesize otherwise zero.
;..........................................................................................................................................
; Detlev Dalitz.20010722.20020715.20090427.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strFilenameFrom = IntControl (1004, 0, 0, 0, 0) ; We use a copy of this file as test input.
strFilename = FileMapName (strFilenameFrom, Environment ("TEMP"))
blnResult = FileCopy (strFilenameFrom, strFilename, @FALSE)
strBrowser = StrCat (DirHome (), "Browser.exe")

intResult = udfFileSetEOLToCRLF (strFilename)
RunWait (strBrowser, strFilename)

blnResult = FileDelete (strFilename)
Exit
;------------------------------------------------------------------------------------------------------------------------------------------