udfFileAppendStr
int udfFileAppendStr (str, str, int)
int udfFileAppendStrV2 (str, str, str)
;------------------------------------------------------------------------------------------------------------------------------------------
; udfFileAppendStr (strString, strFilename, intMode)
; udfFileAppendStrV2 (strString, strFilename, strTerm)
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileAppendStr (strFilename, strString, intMode)
IntControl (53, Min (4, Max (0, intMode)), 0, 0, 0)
hdlFW = FileOpen (strFilename, "APPEND")
FileWrite (hdlFW, strString)
hdlFW = FileClose (hdlFW)
Return FileSize (strFilename)
;..........................................................................................................................................
; This UDF "udfFileAppendStr" appends a given "strString" at the end of file "strFilename",
; and lets you select a different line terminator, or none at all, as specified by "intMode".
; intMode=0 ... No line terminator
; intMode=1 ... CR/LF (DOS) (default)
; intMode=2 ... LF (UNIX)
; intMode=3 ... CR (Macintosh)
; intMode=4 ... Tab
;
; Return value is the new FileSize.
;
; Detlev Dalitz.20020724.20090424.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileAppendStrV2 (strFilename, strString, strTerm)
IntControl (53, 0, 0, 0, 0) ; ; p1=0 ... No line terminator
hdlFW = FileOpen (strFilename, "APPEND")
FileWrite (hdlFW, strString)
FileWrite (hdlFW, strTerm)
hdlFW = FileClose (hdlFW)
Return FileSize (strFilename)
;..........................................................................................................................................
; This Function "udfFileAppendStrV2" appends a given "strString" at the end of file "strFilename",
; and lets you append any string as a line terminator as specified by "strTerm".
;
; Return value is the new FileSize.
;
; Detlev Dalitz.20020724.20090424.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------



; Test.

strFilename = FileCreateTemp ("TMP")

:Test1
intSize = udfFileAppendStr (strFilename, "xxx"     , 0) ; intMode=0 ... No line terminator
intSize = udfFileAppendStr (strFilename, "tab"     , 4) ; intMode=4 ... Tab
intSize = udfFileAppendStr (strFilename, "mac_cr"  , 3) ; intMode=3 ... CR (Macintosh)
intSize = udfFileAppendStr (strFilename, "unix_lf" , 2) ; intMode=2 ... LF (UNIX)
intSize = udfFileAppendStr (strFilename, "dos_crlf", 1) ; intMode=1 ... CR/LF (DOS) (default)

RunWait (StrCat (DirHome (), "browser.exe"), strFilename)
;-----------------------------------------------------------------------------------------------------
; Output
;   xxxtab@TABmac_cr@CRunix_lf@LFdos_crlf@CRLF
;-----------------------------------------------------------------------------------------------------
;   xxxtab@TABmac_cr@CR
;   unix_lf@LF
;   dos_crlf@CRLF
;-----------------------------------------------------------------------------------------------------
;   000000  78787874 6162096D 61635F63 720D756E  xxxtab¤mac_cr·un
;   000010  69785F6C 660A646F 735F6372 6C660D0A  ix_lf·dos_crlf··
;-----------------------------------------------------------------------------------------------------


:Test2
intSize = udfFileAppendStrV2 (strFilename, "xxx"     , ""   )
intSize = udfFileAppendStrV2 (strFilename, "tab"     , @TAB )
intSize = udfFileAppendStrV2 (strFilename, "mac_cr"  , @CR  )
intSize = udfFileAppendStrV2 (strFilename, "unix_lf" , @LF  )
intSize = udfFileAppendStrV2 (strFilename, "dos_crlf", @CRLF)
intSize = udfFileAppendStrV2 (strFilename, '"SSV"'   , ";"  ) ; Writing "SSV semicolon separated value" file.
intSize = udfFileAppendStrV2 (strFilename, '"SSV"'   , ";"  )
intSize = udfFileAppendStrV2 (strFilename, '"SSV"'   , ""   )
intSize = udfFileAppendStrV2 (strFilename, @CRLF     , ""   )
intSize = udfFileAppendStrV2 (strFilename, '"CSV"'   , ", " ) ; Writing "CSV comma separated value" file.
intSize = udfFileAppendStrV2 (strFilename, '"CSV"'   , ", " )
intSize = udfFileAppendStrV2 (strFilename, '"CSV"'   , ""   )
intSize = udfFileAppendStrV2 (strFilename, @CRLF     , ""   )
intSize = udfFileAppendStrV2 (strFilename, Num2Char (26), "") ; Writing "EndOfFile" terminator.

RunWait (StrCat (DirHome (), "browser.exe"), strFilename)
;-----------------------------------------------------------------------------------------------------
; Output
;   xxxtab@TABmac_cr@CRunix_lf@LFdos_crlf@CRLF"SSV";"SSV";"SSV"@CRLF"CSV", "CSV", "CSV"@CRLF@CRLF@EOF
;-----------------------------------------------------------------------------------------------------
;   xxxtab@TABmac_cr@CR
;   unix_lf@LF
;   dos_crlf@CRLF
;   "SSV";"SSV";"SSV"@CRLF
;   "CSV", "CSV", "CSV"@CRLF
;   @EOF
;-----------------------------------------------------------------------------------------------------
;   000000  78787874 6162096D 61635F63 720D756E  xxxtab¤mac_cr·un
;   000010  69785F6C 660A646F 735F6372 6C660D0A  ix_lf·dos_crlf··
;   000020  22535356 223B2253 5356223B 22535356  "SSV";"SSV";"SSV
;   000030  220D0A22 43535622 2C202243 5356222C  "··"CSV", "CSV",
;   000040  20224353 56220D0A 1A                  "CSV"···
;-----------------------------------------------------------------------------------------------------

FileDelete (strFilename)
Exit
;------------------------------------------------------------------------------------------------------------------------------------------