|
Post by Stefan on Apr 23, 2019 13:53:58 GMT -5
Hi Guys,
I observed this in versions 10.1.9014 and 10.2.19107. I didn't try this with prior versions.
I often used the following approach in ISP/PDF macros (here loosely converted to Thinbasic)
SPF_Cmd("FIND 'whatever' FIRST") WHILE Get_RC = 0 ...process the found line(s) as required... SPF_Cmd("FIND 'whatever' NEXT") WEND
However this does not stop the loop after the last occurence of 'whatever' has been found. Nor does recoding the loop with src = SPF_Cmd("FIND 'whatever' FIRST") WHILE src = 0
ISREDIT would issue/pass through a non-zero Return Code to the macro if the primary command completed unsuccessfully.
Coding the loop with WHILE Get_Lnum(Get_Find_Lptr) > 0 does work, but is rather clumsy.
The above behaviour is demonstrated with the FIND command but may also apply to other primary commands.
On a related topic, I also note that the label .ZCSR is unreliable in macros. I'm not completely certain, but I think ISREDIT("FIND...") would position the cursor at the found line and thus label the line with .ZCSR. If other interactions (like Get_Line$(<pointer>) ) do not move the 'cursor' either, that could explain why .ZCSR remains unreliable.
Many thanks advance for looking into this.
|
|
|
Post by mueh on Apr 24, 2019 11:57:29 GMT -5
Hi George ! Finding's of test i did . RC is set for RFIND . MSG$ is Always correct . if FIND PREV is done after FIND LAST only the last Match in same Line is found . Here a test case which might help if you Change the commented lines . Execute the macro against the macro to find CHECK string .
' MUT.macro
SPF_Loop_check(OFF) ' check string check
' SPF_Cmd("FIND 'check' last")
SPF_Cmd("FIND 'check' first")
WHILE Get_RC = 0 ' okay for RFIND
' WHILE Get_Lnum(Get_Find_Lptr) > 0
' WHILE EndsWith(Get_Msg$," of data reached") = 0
MSGBOX(0,Get_MSG$+" "+Get_LNum(Get_Csr_LPtr)+" "+Get_Csr_Col+" "+Get_LNum(Get_Find_LPtr)+" "+Get_Find_col)
SPF_Cmd("RFIND") ' okay
' SPF_Cmd("FIND 'check' prev") ' check fails finds only last match in line
' SPF_Cmd("FIND 'check' next") ' check okay
WEND
MSGBOX(0,Get_RC+" "+Get_MSG$)
/*
;c "find 'check'" "CHANGE 'check' 'checc'" all .1 .14
;c RFIND RCHANGE all .1 .14
;replace MUTc.macro .zf .zl
*/
|
|
|
Post by mueh on Apr 25, 2019 6:32:04 GMT -5
All methods which use " of data reached" string use nmac(%eFail) code except pCmdFIND and one occurence in pCmdRFIND .
METHOD pCmdCHANGE(pCmd AS STRING) METHOD pCmdDELETE(pCmd AS STRING) METHOD pCmdEXCLFLIPSHOW(pCmd AS STRING, cmd AS STRING, msgname AS STRING) METHOD pCmdFIND(pCmd AS STRING) scError(%eNone, IIF$(IsCfNext, "Bottom of data reached", "Top of data reached")) METHOD pCmdJOIN(pCmd AS STRING) METHOD pCmdLOCATE(pCmd AS STRING) METHOD pCmdNFIND(pCmd AS STRING) METHOD pCmdRCHANGE(pCmd AS STRING) METHOD pCmdRDelete(pCmd AS STRING) METHOD pCmdRFIND(pCmd AS STRING) scError(nmac(%eFail), IIF$(IsCfNext, "Top of data reached", "Bottom of data reached")) scError(nmac(%eFail), IIF$(IsCfNext, "Bottom of data reached", "Top of data reached")) scError(%eNone, IIF$(IsCfNext, "Bottom of data reached", "Top of data reached")) METHOD pCmdRJOIN(pCmd AS STRING) METHOD pCmdRLOC(pCmd AS STRING) METHOD pCmdRNFIND(pCmd AS STRING) METHOD pCmdRSPLIT(pCmd AS STRING) METHOD pCmdSPLIT(pCmd AS STRING) METHOD pCmdTAG(pCmd AS STRING)
Hope this helps
|
|
|
Post by George on Apr 25, 2019 13:56:18 GMT -5
Stefan: Mueh: First, thanks Mueh for scanning the code for the error, I've corrected them for the next release.
Here's the macro I was using to test with, It just lists the found lines to the debug console.
' TRY.macro dim txt as string dim RetC as long RetC = SPF_Cmd("FIND 'fred' FIRST") WHILE RetC = 0 txt = Get_Line$(Get_Find_Lptr) SPF_Debug(format$(Get_LNum(Get_Find_LPtr), "000000") + " " + txt) RetC = SPF_Cmd("RFIND") ' Temp way works now ' RetC = SPF_Cmd("FIND 'fred' NEXT") ' Original way will work next release WEND halt(8)
and with the fixed release it could be done with just
' TRY.macro dim txt as string SPF_Cmd("TOP") WHILE SPF_Cmd("FIND 'fred' NEXT") = 0 txt = Get_Line$(Get_Find_Lptr) SPF_Debug(format$(Get_LNum(Get_Find_LPtr), "000000") + " " + txt) WEND halt(0)
George
|
|
|
Post by Stefan on May 3, 2019 12:15:24 GMT -5
Excellent. Thank you both.
I'll play around some more with label .ZCSR. Can't seem to get that to work in the way I thought it did back in my mainframe days. But then again, could be my memory is buggy :-(
|
|
|
Post by George on May 3, 2019 12:28:02 GMT -5
Stefan: I looked in the code just to be sure it was still there, and .ZCSR should get you the current cursor line. Make sure you are clear on the difference between Line Pointers (lPtr) and Line Numbers (lNum) in the macros. Check exactly what type the various functions ask for. And if you are building command strings to pass to SPFLite_Cmd, remember everything on a command line is a line NUMBER, not a line pointer. You may have to convert a pointer into a line number. See Get_LPtr and GET_LNum for converting between the two.
George
|
|