	.title	matchc
;
; matchc -- routine to see if a byte string matched
;
;	call:
;		istat=matchc(buff1,len1,buff2,len2,ifound)
;
;		where 
;			buff1 and buff2 are addresses of byte arrays
;			len1 and len2 are addresses of words giving lengths
;			ifound is byte position found at of first byte
;			
;			buff1 is searched for buff2
;
;		returns 0 if match occurred
;
	.entry	matchc,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
	movl	4(ap),r5				; get array address
	movl	@8(ap),r6				; get array length
	movl	r6,r11
	movl	12(ap),r7				; get search address
	movl	@16(ap),r8				; get search length
	clrl	r9					; clear pointer	
	clrl	r4					; flag to test end

	cmpl	r6,#65535				; see if array too big
	bleq	continue				; no, go try search
	movl	#65535,r11				; set up max length
	
continue:
	addl3	r5,r9,r10
	matchc	r8,(r7),r11,(r10)
	tstl	r0					; match?
	bneq	10$					; no, kick out

	subl3	4(ap),r3,r4
	subl2	r8,r4					; figure out byte count
	addl2	#1,r4
	movl	r4,@20(ap)
	brb	20$					; found so kick out

10$:	cmpl	r6,#65535				; see if we kick out
	bleq	20$					; yes

	tstl	r4					; enough searching?
	bneq	20$					; yes, kick out

	addl2	#65535,r9				; no, increment add pnt
	addl3	r9,#65535,r10
	cmpl	r6,r10					; too big?
	bleq	30$					; yes, reset to max add
	
	movl	#65535,r11				; no, do another cmp
	brb	continue
	
30$:	subl2	r6,r10					; get correct length of
	subl3	r10,#65535,r11				; rest of array to search
	movl	#-1,r4					; mark end of search
	brb	continue				; next go around
	
20$:	ret

	.end
