StepThough.....
Ok, well I confirmed your test. I can acutally open the file seperately, and rip through it. I get all teh ## lines etc. So then I edited the ReplaceInFile's central function called RIP... as you see...I have inserted an output test of the initial parameters, and alerts if any of the preceeding items throw errors. This should enter into its search and hit us with 1000 annoying message boxes as it rips through each line in the file.... however... that doesn't happen. We exit with the first alert, and dump to close because of the errors being set.
What determines the EOF for the FileRead function?
Is there ANY other reason that FileRead would return with the error flag set other than reaching the end of file? Its returning both Empty and Errors set.... indicating the end of file...
But if we manually open the file and read a line we get one.... is there something about being in the macro???
Function RIF
ClearErrors ; want to be a newborn
Exch $0 ; REPLACEMENT
Exch
Exch $1 ; SEARCH_TEXT
Exch 2
Exch $2 ; SOURCE_FILE
Push $R0 ; SOURCE_FILE file handle
Push $R1 ; temporary file handle
Push $R2 ; unique temporary file name
Push $R3 ; a line to sar/save
Push $R4 ; shift puffer
Push $R5 ; byteHolder
Push $R6 ; buffer counter
MessageBox MB_OK "Data before open read. $0 , $1 , $2"
IfFileExists $2 +1 RIF_error ; knock-knock
ifErrors 0 +2
MessageBox MB_OK "Errors existed before open read. $0 , $1 , $2"
ClearErrors
FileOpen $R0 $2 "r" ; open the door
ifErrors 0 +2
MessageBox MB_OK "Errors existed after open read. $2"
ClearErrors
GetTempFileName $R2 ; who's new?
FileOpen $R1 $R2 "w" ; the escape, please!
ifErrors 0 +2
MessageBox MB_OK "Errors existed after open write $2"
ClearErrors
RIF_loop: ; round'n'round we go
FileRead $R0 $R3 ; read one line
MessageBox MB_OK "$R3"
ifErrors RIF_leaveLoop
RIF_sar: ; sar - search and replace
Push "$R3" ; (hair)stack
Push "$1" ; needle
Push "$0" ; blood
Call StrReplace ; do the bartwalk
StrCpy $R4 "$R3" ; remember previous state
Pop $R3 ; gimme s.th. back in return!
StrCmp "$R3" "$R4" +1 RIF_sar ; loop, might change again!
FileWrite $R1 "$R3" ; save the newbie
Goto RIF_loop ; gimme more
RIF_leaveloop: ; over'n'out, Sir!
FileClose $R1 ; S'rry, Ma'am - clos'n now
FileClose $R0 ; me 2
;MessageBox MB_OK "Files Closed. $R1 , $R0"
Delete "$2.old" ; go away, Sire
;MessageBox MB_OK "Deleete $2.old"
Rename "$2" "$2.old" ; step aside, Ma'am
;MessageBox MB_OK "Rename $2 to $2.old"
Rename "$R2" "$2" ; hi, baby!
;MessageBox MB_OK "Rename $R2 to $2"
Delete "$2.old"
ClearErrors ; now i AM a newborn
Goto RIF_out ; out'n'away
RIF_error: ; ups - s.th. went wrong...
SetErrors ; ...so cry, boy!
RIF_out: ; your wardrobe?
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $2
Pop $0
Pop $1
FunctionEnd