;
; $VER: RequestString.a v39.2 (c) 1998 by Mauro Panigada
;
; Started:  1998.07.20
; Finished: 1998.07.20
;
; Requirements: OS2.1 (#37), 020+ and reqtools.library v38
; Purpose: replace the known RequestString (by Thomas Kessler)
; Note: PURE
;
; Template: TITLE/A,BODY/A,STRING/K,PUBSCREEN/K,NOLINE/S,NOQUOTE/S,NOEMPTY/S,PASSWORD/S,
;   REQPOS/N/K
;
; Just to say: my rs is shorter, even if the $VER string is longer and also the
; template (about this, Kessler's RS has surely a bug)
;


		incdir	"inc:"
		include	"exec/types.i"
		include	"exec/memory.i"
		include	"exec/libraries.i"
		include	"exec/exec_lib.i"
		include	"dos/dos.i"
		include	"dos/dosextens.i"
		include	"dos/dos_lib.i"
		include	"reqtools/reqtools.i"
		include	"reqtools/reqtools_lib.i"


CALL		MACRO
		jsr	(_LVO\1,a6)
		ENDM

	STRUCTURE internal,0
		LONG	dosbase
		LONG	reqtoolsbase

		LABEL	array
		LONG	title
		LONG	body
		LONG	string
		LONG	pubscreen
		LONG	noline
		LONG	noquote
		LONG	noempty
		LONG	password
		LONG	reqpos

		LONG	oldstack

		WORD	garce
		WORD	returncode

		STRUCT	buffer,40

		LABEL	s_size


		opt	p=68020		; try with new style

LIBVERSION	EQU	37

REQTOOLSVER	EQU	38


	SECTION	reqfile,CODE

		bra.s	start

		dc.b	"$VER: RequestString 39.2 [020+] (1998.07.20) "
		dc.b	"by Mauro Panigada",13,10,0
		even

start		
		move.l	sp,a0
		move.w	#(s_size/2)-1,d0
lup		clr.w	-(sp)
		dbf	d0,lup
		move.l	sp,a5
		move.l	a0,(oldstack,a5)

		move.b	#20,(returncode+1,a5)
		move.l	(4).w,a6
		lea	(dosname,pc),a1
		moveq	#LIBVERSION,d0
		CALL	OpenLibrary
		move.l	d0,(a5)
		beq	exit0
		lea	(reqtoolsname,pc),a1
		moveq	#REQTOOLSVER,d0
		CALL	OpenLibrary
		move.l	d0,(reqtoolsbase,a5)
		beq	exit0

		move.l	(a5),a6
		lea	(template,pc),a0
		move.l	a0,d1
		move.l	a5,d2
		addq.l	#array,d2
		moveq	#0,d3
		CALL	ReadArgs
		move.l	d0,d7			; d7 = readargs
		beq	doserror

		move.l	(reqtoolsbase,a5),a6

		move.l	sp,a4			; old stack (medio)
		clr.l	-(sp)			; tag_end
		moveq	#0,d0
		bset	#GSREQB_CENTERTEXT,d0
		move.l	d0,-(sp)
		move.l	#RTGS_Flags,-(sp)
		move.l	(noempty,a5),-(sp)
		not.l	(sp)
		move.l	#RTGS_AllowEmpty,-(sp)
		move.l	(body,a5),-(sp)
		move.l	#RTGS_TextFmt,-(sp)
		move.l	(pubscreen,a5),d0
		beq.s	nopubscreen
		move.l	d0,-(sp)
		move.l	#RT_PubScrName,-(sp)
nopubscreen	move.l	(password,a5),-(sp)
		move.l	#RTGS_Invisible,-(sp)
		move.l	(reqpos,a5),d0
		beq.s	noreqpos
		move.l	(d0.l),-(sp)
		move.l	#RT_ReqPos,-(sp)
noreqpos
		tst.l	(string,a5)
		beq.s	nostring

		lea	(buffer,a5),a1
		move.l	(string,a5),a0
		moveq	#37,d0
loop1		move.b	(a0)+,(a1)+
		tst.b	-1(a0)
		dbeq	d0,loop1

nostring	move.b	#5,(returncode+1,a5)
		move.l	sp,a0
		lea	(buffer,a5),a1
		moveq	#38,d0
		move.l	(title,a5),a2
		suba.l	a3,a3
		CALL	rtGetStringA
		move.l	a4,sp
		tst.l	d0
		beq	exit

		clr.b	(returncode+1,a5)
		lea	(replacet,pc),a0
		tst.l	(noquote,a5)
		beq.s	yesquote
		lea	(replacet0,pc),a0
yesquote	move.l	a0,d1
		lea	(buffer,a5),a0
		move.l	a0,-(sp)
		move.l	sp,d2
		move.l	(a5),a6
		CALL	VPrintf
		addq.l	#4,sp

		tst.l	(noline,a5)
		bne.s	exit

		lea	(accapo,pc),a0
		move.l	a0,d1
		CALL	PutStr

exit
		move.l	d7,d1
		move.l	(dosbase,a5),a6
		CALL	FreeArgs
exit0
		move.l	(4).w,a6
		move.l	(a5),a1
		CALL	CloseLibrary
		move.l	(reqtoolsbase,a5),a1
		CALL	CloseLibrary
		move.l	(oldstack,a5),sp
		move.l	(returncode-2,a5),d0
		rts

doserror
		CALL	IoErr
		move.l	d0,d1
		moveq	#0,d2
		CALL	PrintFault
frega0		move.b	#20,(returncode+1,a5)
		bra.s	exit0


;====================================================================================

template
		dc.b	"TITLE/A,BODY/A,STRING/K,PUBSCREEN/K,NOLINE/S,NOQUOTE/S,NOEMPTY/S,PASSWORD/S,REQPOS/N/K",0

dosname		dc.b	"dos.library",0
reqtoolsname	dc.b	"reqtools.library",0

replacet	dc.b	'"%s"',0
replacet0	dc.b	'%s',0
accapo		dc.b	10,0


		END