In    -
Out   Scanfile
Type  Memory
Ver   1.00c

Pre
#COND testing Is this a test
End Pre

; External interface to scanforstring
; > r0=pointer to block of regs (as scanforstring)
; < r0=found (-1=yes, 0=no)
;   block updated
.scanexternal
   STMFD   (sp)!,{r1-r5,link}            ; Stack registers
   MOV     r5,r0                         ; r5=block stored in
   LDMIA   r5,{r0-r4}                    ; get params
   BL      scanforstring                 ; do scan
   ADD     r5,r5,#4                      ; r5=miss out string ptr
   STMIA   r5,{r1-r4}                    ; store back in block
   LDMFD   (sp)!,{r1-r5,pc}              ; Return from call

; Scan a block of memory for a string (insensitive)
; > r0 = search string
;   r1 = start location
;   r2 = end location
;   r3 = current line number
;   r4 = start of current line
; < r0 = found ? -1=TRUE, 0=FALSE
;   r1 = next location
;   r2 = end location
;   r3 = current line number
;   r4 = start of current line
.scanforstring
   STMFD   (sp)!,{r5-r7,link}            ; Stack registers
   LDRB    r5,[r0],#1                    ; get first byte and inc r0
   BL      converttocases
$loop
   CMP     r1,r2                         ; have we finished ?
   BGE     $exitwithoutfind              ; if so, exit
   LDRB    r7,[r1],#1                    ; get current byte and inc r1
   CMP     r7,r5                         ; is it same as lower case ?
   CMPNE   r7,r6                         ; if not, what about upper case ?
#COND OF testing
   BLEQ    cmpwildcardi2                 ; jump to testing checker
#COND ELSE
   BLEQ    cmpwildcardi                  ; jump to routine to check
#COND ENDIF
   BEQ     $exitwithfind                 ; if returned and still EQ, is found
   CMP     r7,#32                        ; is this EOL ?
   ADDLT   r3,r3,#1                      ; if so, inc line number
   MOVLT   r4,r1                         ; and r4=start of line pointer
   B       $loop                         ; back to start of loop for more
$exitwithfind
   MVN     r0,#NOT -1                    ; r0=-1 for find
   LDMFD   (sp)!,{r5-r7,pc}              ; Return from call
$exitwithoutfind
   MOV     r0,#0                         ; r0=0 for no find
   LDMFD   (sp)!,{r5-r7,pc}              ; Return from call

; convert character in r5 to lower in r5 and upper in r6
.converttocases
   STMFD   (sp)!,{r0,link}               ; Stack registers
   XSWI    "Territory_LowerCaseTable",-1 ; Get the lower case table
   LDRB    r5,[r0,r5]                    ; get the lower case version
   XSWI    "Territory_UpperCaseTable",-1 ; Get the lower case table
   LDRB    r6,[r0,r5]                    ; get the upper case version
   LDMFD   (sp)!,{r0,pc}                 ; Return from call

#COND OF testing
.cmpwildcardi2
   STMFD   (sp)!,{r0-r5,link}            ; Stack registers
   REM     "Checking against : %$1"
   BL      cmpwildcardi
   LDMFD   (sp)!,{r0-r5,pc}              ; Return from call
#COND ENDIF

#LIBRARY "Strings",#cmpwildcardi

#Post
#Capture
DIM block 20
stringptr=block
startloc=block+4
endloc=block+8
curline=block+12
startofline=block+16
f$="Justin:.Computer.Docs.Cookbook.Cook5":len=61093
DIM m% len
SYS "OS_File",255,f$,m%
s$="aPcS*"
DIM d% 256
$d%=s$
!startloc=m%
!endloc=m%+len
!curline=1
!startofline=m%
t=TIME
!stringptr=d%
REPEAT
 A%=stringptr
 result=USR scanexternal
 IF result THENPRINT "Found on line : ";!curline
UNTIL result=0
P."Total time = ";TIME-t
