; GrepMem v1.2 : hunts through memory for (exact) string matches
; by Kyzer/CSG
; $VER: GrepMem 1.2 (09.04.98)
;
	incdir	include:
	include	lvo/exec_lib.i
	include	lvo/dos_lib.i
	include	exec/execbase.i
	include	dos/dos.i
	include	dos/dosasl.i

error	MACRO
	IFLT	ERROR_\1 - 127
	moveq	#ERROR_\1,d1
	ELSE
	move.l	#ERROR_\1,d1
	ENDC
	jsr	_LVOSetIoErr(a6)
	ENDM

print	MACRO
	lea	\1,a0
	move.l	a0,d1
	IFNC	'\2',''
	lea	\2,a0
	move.l	a0,d2
	ENDC
;	move.l	dosbase(a5),a6
	jsr	_LVOVPrintf(a6)
	ENDM

stackf	MACRO	; stack_symbol, stackelement_symbol
	IFND	\1
\1	set	0
	ENDC
\1	set	\1-4
\2	equ	\1
	ENDM

	stackf	stk, dosbase	; DOSBase

	stackf	stk, padzero	;
	stackf	stk, endaddr	; these 4 filled by ReadArgs
	stackf	stk, begaddr	; ^
	stackf	stk, searchstr	; | This way up
	stackf	stk, rdargs
args=searchstr

	stackf	stk, end	; end address
	stackf	stk, start	; start address 
	stackf	stk, address	; current search address
	stackf	stk, hitcnt	; number of matches
	stackf	stk, column	; current printout column
str=address

	link	a5,#stk

	move.l	4.w,a6
	lea	dosname(pc),a1
	moveq	#37,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,dosbase(a5)
	beq.s	.nodos
	move.l	d0,a6

	print	title(pc)

	lea	templat(pc),a0
	move.l	a0,d1
	lea	args(a5),a0
	move.l	a0,d2
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	moveq	#0,d3
	jsr	_LVOReadArgs(a6)
	move.l	d0,rdargs(a5)
	beq.s	.noargs

	bsr.s	Init	; Init will call Search if appropriate

	move.l	rdargs(a5),d1
	jsr	_LVOFreeArgs(a6)
.noargs	jsr	_LVOIoErr(a6)
	move.l	d0,d1
	moveq	#0,d2
	jsr	_LVOPrintFault(a6)
	move.l	a6,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
.nodos	unlk	a5
	moveq	#0,d0
	rts

	include	search.asm

	dc.b	'$VER: '
title	dc.b	'GrepMem 1.2 (09.04.98) by Kyzer/CSG',10,0
templat	dc.b	'STRING/A,START,END,PADZERO/S',0
dosname	dc.b	'dos.library',0
