
*	StringLib.asm (of PCQ Pascal runtime library)
*	Copyright (c) 1989 Patrick Quaid

*	This module just defines a few string handling routines.
*	Note that I gave them all different names so that you could use
*	them however you want.

	SECTION	One,CODE

	XREF	_p%new
	XREF	_p%dispose

	XDEF	_STREQ
	XDEF	_streq
_STREQ:
_streq:
	move.l	4(sp),a1
	move.l	8(sp),a0
1$:
	move.b	(a1)+,d0
	bsr	_INUP
	move.b	d0,d1
	move.b	(a0)+,d0
	bsr	_INUP
	cmp.b	d0,d1
	bne.s	2$
	tst.b	d1
	bne	1$
	moveq	#-1,d0
	rts
2$:
	moveq	#0,d0
	rts
3$:
	moveq	#-1,d0
	rts

	XDEF	_STRCMP
	XDEF	_strcmp
_STRCMP:
_strcmp:
	move.l	4(sp),a1
	move.l	8(sp),a0
1$:
	move.b	(a0)+,d0
	bsr	_INUP
	move.b	d0,d1
	move.b	(a1)+,d0
	bsr	_INUP
	cmp.b	d0,d1
	blt.s	2$
	bgt.s	3$
	tst.b	d0
	beq.s	4$
	bra	1$
2$:
	moveq	#-1,d0
	rts
3$:
	moveq	#1,d0
	rts
4$:
	moveq	#0,d0
	rts

	XDEF	_STRLEN
	XDEF	_strlen
_STRLEN:
_strlen:
	move.l	4(sp),d1
	move.l	d1,a0
1$:
	tst.b	(a0)+
	bne.s	1$
	move.l	a0,d0
	sub.l	d1,d0
	subq	#1,d0
	rts

	XDEF	_strcpy
	XDEF	_STRCPY
_strcpy
_STRCPY
	move.l	8(sp),a0
	move.l	4(sp),a1
1$
	move.b	(a0)+,d0
	move.b	d0,(a1)+
	bne	1$
	rts

	XDEF	_strcat
	XDEF	_STRCAT
_strcat
_STRCAT
	move.l	8(sp),a0
	move.l	4(sp),a1
1$	move.b	(a0)+,d0
	bne	1$
	subq.l	#1,a0
2$	move.b	(a1)+,d0
	move.b	d0,(a0)+
	bne	2$
	rts

	XDEF	_RAISE
	XDEF	_raise
_RAISE:
_raise:
	move.w	4(sp),d0
	and.b	#255,d0
_INUP	cmp.b	#'a',d0
	blt.s	1$
	cmp.b	#'z',d0
	bgt.s	1$
	sub.b	#32,d0
1$:	rts

	XDEF	_ALLOCSTRING
	XDEF	_AllocString
	XDEF	_allocstring
_ALLOCSTRING:
_AllocString:
_allocstring:
	jsr	_p%new
	rts

	XDEF	_FREESTRING
	XDEF	_FreeString
	XDEF	_freestring
_FREESTRING:
_FreeString:
_freestring:
	move.l	4(sp),d0
	jsr	_p%dispose
	rts

   end
