;
; $VER: Askq.a V1.0 written by Mauro Panigada
;
; Started: 03/14/1996 (month/day/year)
;
; (FREEWARE) It needs OS2.0+ (#36)
;
; PURPOSE: simple and useful "remake" of dos command 'ask', written
; in 100% assembly.
;
; USAGE: Askq "Text" "Gadget(s)" "Title" "Envar"
; Type "Askq ?" for a dos-like help.
;
; Askq ?
; TEXT/A,GADGET,TITLE,VAR:
;
; Only TEXT is needed. Default gadget is "Yes|No" and title "Request".
; For gadgets you can specify "gad1|gad2|gad3|..." like EasyRequestArgs,
; which I use for request. VAR is a name of a var where the result
; will be stored; if it is not given, result will be stored in an envar
; named "ENVARC:AskqAnswer" as standard.
;
; NOTE: There is also Request by Stefano Reksten and it is copyrighted.
; Now, my program (freeware, tieh`!) IS NOT COPIED from it. NO PART
; OF CODE ARE USED OR STOLEN in this my own version. Maybe only the IDEA
; is got, but do we want to close our minds? No: the "ideas" is free.
; NOTE that I store result in a variable... It is better than put it only
; in D0!
;

		incdir	"dh0:progr/assem/include/"
		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	"intuition/intuition.i"
		include	"intuition/intuition_lib.i"
		include	"dos/var.i"

LIBVERSION	EQU	36

CALL		MACRO
		jsr	_LVO\1(a6)
		ENDM


		bra.s	start

		dc.b	"$VER: Askq V1.0 (03/14/1996) "
		dc.b	"written by Mauro Panigada"
		dc.b	0
		even

start		movea.l	4.w,a6
		lea	dosname(pc),a1
		moveq	#LIBVERSION,d0
		CALL	OpenLibrary
		move.l	d0,a4
		tst.l	d0
		beq	exit
		lea	intname(pc),a1
		moveq	#LIBVERSION,d0
		CALL	OpenLibrary
		move.l	d0,a5
		tst.l	d0
		beq	exit
		move.l	a4,a6

		move.l	#template,d1
		move.l	#array,d2
		moveq	#0,d3
		CALL	ReadArgs
		move.l	d0,d7
		beq	argerror

main		lea	array(pc),a0
		tst.l	(a0)
		beq	argerror
		lea	ers(pc),a1
		move.l	(a0),es_TextFormat(a1)
		tst.l	4(a0)
		bne.s	okarg0
		move.l	#standardgadget,4(a0)
okarg0		move.l	4(a0),es_GadgetFormat(a1)
		tst.l	8(a0)
		bne.s	okarg1
		move.l	#standardtitle,8(a0)
okarg1		move.l	8(a0),es_Title(a1)
		suba.l	a2,a2
		suba.l	a3,a3
		suba.l	a0,a0
		exg	a5,a6
		CALL	EasyRequestArgs
		move.l	d0,d6
		lea	array(pc),a0
		tst.l	12(a0)
		bne.s	okarg2
		move.l	#varname,12(a0)
okarg2		move.l	d6,stream
		bsr	convert
		move.l	12(a0),d1
		move.l	#cbuf,d2
		moveq	#-1,d3
		move.l	#GVF_GLOBAL_ONLY,d4
		exg	a5,a6
		CALL	SetVar
			; ignore possible but rare (I hope) errors...
exit0		move.l	d7,d1
		beq.s	exit
		CALL	FreeArgs

exit		move.l	a4,a1
		movea.l	4.w,a6
		CALL	CloseLibrary
		move.l	a5,a1
		CALL	CloseLibrary
		move.l	d6,d0
		rts

argerror	move.l	#helpscr,d1
		CALL	PutStr
		bra.s	exit0

convert		movem.l	a0/a6,-(sp)
		movea.l	4.w,a6
		lea	formatstr(pc),a0
		lea	stream(pc),a1
		lea	proc(pc),a2
		lea	cbuf(pc),a3
		CALL	RawDoFmt
		movem.l	(sp)+,a0/a6
		rts
proc		move.b	d0,(a3)+
		rts

;=========================================================================
dosname		dc.b	"dos.library",0
		even
intname		dc.b	"intuition.library",0
		even
ers		dc.l	EasyStruct_SIZEOF
		dc.l	0
		dc.l	0,0,0
standardgadget	dc.b	"Yes|No",0
		even
standardtitle	dc.b	"Request",0
		even
varname		dc.b	"ENVARC:AskqAnswer",0
		even
template	dc.b	"TEXT/A,GADGET,TITLE,VAR",0
		even
formatstr	dc.b	"%ld",0
array		dc.l	0,0,0,0
cbuf		dc.l	0
stream		dc.l	0
helpscr		dc.b	"Askq V1.0 by Mauro Panigada",10
		dc.b	"USAGE: Askq TEXT [GADGETS] [TITLE] [VAR]",10
		dc.b	0

		END