Hmm... Well that isn't the actual code, just a simplified version for illistration and maybe that's the problem, that it's something in the actual code causing it. So...
In main file:
Code: Select all
;/ CRC Test file generator
Global BuffLen.l
Global BuffOffset.l
Global FileOffset.l
Global *IBuff.b
XIncludeFile "Common.pb"
XIncludeFile "Functions.pb"
*IBuff=AllocateMemory(0,65536,0)
If Not(*IBuff)
DisplayError("Could not allocate buffer memory.")
End
Else
ClearBuff()
EndIf
Open_winMain()
SetGadgetText(#strIFName,"G:\FFA\UPCD\20020509\UPDATA.TXT")
SetGadgetText(#strOFName,"G:\FFA\UPCD\20020509\UPDATA.OUT")
;DebugLevel 2
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #btnIFNBrowse
SetGadgetText(#strIFName,OpenFileRequester("Choose test file","","Text files (*.txt)|*.txt|All files (*.*|*.*",1))
ElseIf GadgetID = #btnOFNBrowse
SetGadgetText(#strOFName,SaveFileRequester("Save test data file","","Output files (*.out)|*.out|Text files (*.txt)|*.txt|All files (*.*|*.*",1))
ElseIf GadgetID = #btnStart
If ReadFile(0,GetGadgetText(#strIFName))
CallDebugger
ReadLine(0)
If CreateFile(1,GetGadgetText(#strOFName))
DisableGadget(#btnStart,1)
LineNum=0
OBuff.s=""
SetGadgetText(#strLines,StrU(LineNum,#Long))
While BuffOffset<BuffLen And ~Eof(0)
UseFile(0)
Debug "Percent done "+StrF(Loc()/Lof()*100),1
SetGadgetState(#barProgress,Round(Loc()/Lof()*100,1))
ILine.s=ReadLine(0)
Debug ILine,2
If Len(ILine)
OLine.s=CleanUPRecord(ILine)
If Len(OLine)
OBuff+RSet(Hex(CRC32Fingerprint(@OLine,Len(OLine))),8,"0")+Chr(13)+Chr(10)
If Len(OBuff)>60000
UseFile(1)
WriteString(OBuff)
OBuff=""
EndIf
EndIf
LineNum+1
EndIf
If MOD(LineNum,100)=0
SetGadgetText(#strLines,StrU(LineNum,#Long))
EndIf
DoEvents()
Wend
CloseFile(0)
CloseFile(1)
End
Else
DisplayError("Could not create output file.")
CloseFile(0)
EndIf
Else
DisplayError("Could not open input file.")
EndIf
EndIf
EndIf
Until Event = #PB_EventCloseWindow
FreeMemory(0)
End
In Functions.pb:
Code: Select all
Procedure.b LoadBuffer(FNum.l)
ClearBuff()
If ~Eof(FNum)
UseFile(FNum)
FileSeek(FileOffset)
BuffLen=ReadData(*IBuff,65536)
If BuffLen=65536
BuffLen=TruncateBuff()
EndIf
FileOffset+BuffLen
BuffOffset=0
ClearCRLF()
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure.s ReadLine(FNum.l)
If BuffOffset>=BuffLen Or Not(BuffLen)
If Not(LoadBuffer(FNum))
ProcedureReturn ""
EndIf
EndIf
Debug *IBuff
Result.s=PeekS(*IBuff+BuffOffset)
BuffOffset+Len(Result)
While BuffOffset<BuffLen And Not(PeekB(*IBuff+BuffOffset))
BuffOffset+1
Wend
ProcedureReturn Result
EndProcedure
Here's the problem I'm having. LoadBuff. But when it finishes and returns to ReadLine, BuffLen no longer has the value that LoadBuff gave it. And BuffLen's value never gets back to the main program.
ClearBuff just fills the buffer with zeros. TruncateBuff searches for the last occurance of either CR or LF and sets the buffer length to that. ClearCRLF searches the buffer and replaces all occurances of CR and LF with zeros (makes using PeekS easier).
It's as if the variables are defaulting to Protected which is not what I want.
Any help would be appreaciated.