udfFileSetEOL
int udfFileSetEOL (str, str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileSetEOL (strFilename, strEOL)
intBBSize = FileSize (strFilename)
If !intBBSize Then Return 0 ; Nothing to do.
If strEOL != @CRLF Then If strEOL != @CR Then If strEOL != @LF 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)
intBBSize = intBBSize + intAdd
hdlBB = BinaryAlloc (intBBSize)
BinaryRead (hdlBB, strFilename)
BinaryReplace (hdlBB, @CRLF, @LF, @TRUE)
BinaryReplace (hdlBB, @CR, @LF, @TRUE)
BinaryReplace (hdlBB, @LF, @CRLF, @TRUE)
If strEOL != @CRLF Then BinaryReplace (hdlBB, @CRLF, strEOL, @TRUE)
intBBSize = BinaryWrite (hdlBB, strFilename)
hdlBB = BinaryFree (hdlBB)
Return intBBSize
;..........................................................................................................................................
; This UDF udfFileSetEOL normalizes the End-Of-Line sequences of a given textfile
; by setting the End-Of-Line sequences to the given strEOL parameter, which can be @CRLF or @CR or @LF.
;
; On success the function returns the new filesize otherwise zero.
;..........................................................................................................................................
; Detlev Dalitz.20010713.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")

strEOL = @TAB ; No change, @TAB is not a valid value for the parameter strEOL.
intFileSize = udfFileSetEOL (strFilename, strEOL)
RunWait (strBrowser, strFilename)

strEOL = @CR
intFileSize = udfFileSetEOL (strFilename, strEOL)
RunWait (strBrowser, strFilename)

strEOL = @LF
intFileSize = udfFileSetEOL (strFilename, strEOL)
RunWait (strBrowser, strFilename)

strEOL = @CRLF
intFileSize = udfFileSetEOL (strFilename, strEOL)
RunWait (strBrowser, strFilename)

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