ùúùú  Ò  †ÿìHÏÿìHÏÿìHÏÿìHÏÿìHÏÿìHÏÿìHÏ
;**************************************
;*                                    *
;* program:   LhAReq 1.0              *
;* author:    ScoTT/Inferno           *
;*            (Marcin Ochocki)        *
;* version:   1.0                     *
;* date:      14.02.96                *
;* short:     this program has been   *
;*            written to fast & easy  *
;*            extracting files from   *
;*            LhA archives using      *
;*            file requesters         *
;* thanx:     Stefan Boberg (LhA)     *
;*            Nico Francois and       *
;*            Magnus Holmgren         *
;*            (reqtools.library)      *
;* greetz:    all Inferno and blabla  *
;*            members and all my      *
;*            friends !!!             *
;*                                    *
;**************************************

Exec		=	4
OpenLib		=	-552
CloseLib	=	-414
rtFileRequestA	=	-54
rtAllocRequestA	=	-30
rtFreeRequest	=	-36
rtTagBase	=	$80000000
RTFI_Flags	=	rtTagbase+40
FREQF_NOFILES	=	$8


	movem.l	d0/a0,-(sp)
	clr.l	returnMsg

	movea.l	4.w,a6
	suba.l	a1,a1
	jsr	-294(a6)		;FindTask
	move.l	d0,a4
	tst.l	$AC(a4)
	beq.s	fromWorkbench
	bra	end_startup
fromWorkbench
	move.l	#-1,byicon
	lea	$5C(a4),a0
	jsr	-384(a6)		;WaitPort
	lea	$5C(a4),a0
	jsr	-372(a6)		;GetMsg
	move.l	d0,returnMsg
	nop

end_startup
	movem.l	(sp)+,d0/a0
	bsr.s	OpenReqtools

	tst.l	returnMsg
	beq.s	exitToDOS
		
	move.l	d0,-(sp)
	jsr	-132(a6)		;Forbid
	move.l	returnMsg(pc),a1
	jsr	-378(a6)		;ReplyMsg

	move.l	(sp)+,d0

exitToDOS
	rts

	even

OpenReqtools
	lea	reqname,a1
	move.l	Exec,a6	
	jsr	OpenLib(a6)
	move.l	d0,reqbase
	tst.l	d0
	beq	error

	move.l	d0,a6
	moveq	#0,d0
	lea	0,a0
	jsr	rtAllocRequestA(a6)

	move.l	d0,filereq
	lea	def_dir,a4

	move.l	filereq,a2
	move.l	$10(a2),a2
loop
	move.b	(a4)+,(a2)+
	bne.s	loop
	move.b	#0,(a2)

	jsr	Pick_file

	lea	rt_filename,a4
	move.l	rt_file_point,a2
loop1
	move.b	(a4)+,(a2)+
	bne.s	loop1
	move.b	#0,(a2)+

	jsr	Pick_dir

	move.l	filereq,a1
	jsr	rtFreeRequest(a6)

	lea	src_patch,a4
	lea	parametr,a2
loop4
	move.b	(a4)+,(a2)+
	bne.s	loop4
	subi	#1,a2
	move.b	#'"',(a2)+
	move.b	#' ',(a2)+
	move.b	#'"',(a2)+

	lea	dest_patch,a4
loop5
	move.b	(a4)+,(a2)+
	bne.s	loop5
	subi	#2,a2
	cmp.b	#':',(a2)
	beq	dest_device
	addi	#1,a2
	move.b	#'/',(a2)+
	bra	dest_dir
dest_device
	addi	#1,a2
dest_dir
	move.b	#'"',(a2)+
	move.b	#0,(a2)+

	jsr	Execute

CloseReqtools
	move.l	Exec,a6
	move.l	reqbase,a1
	jsr	CloseLib(a6)
error
	rts


;Procedures

Pick_file
	move.l	filereq,a1
	lea	rt_filename,a2
	clr.b	(a2)
	lea	arch_text,a3
	lea	0,a0
	jsr	rtFileRequestA(a6)
	tst.l	d0
	beq.s	Pick_File

	lea	src_patch,a2
	move.l	filereq,a4
	move.l	$10(a4),a4

loop3
	move.b	(a4)+,(a2)+
	bne.s	loop3
	subi	#2,a2
	cmp.b	#':',(a2)
	beq	src_device
	addi	#1,a2
	move.b	#'/',(a2)+
	bra	src_dir
src_device
	addi	#1,a2
src_dir
	move.l	a2,rt_file_point
	rts

Pick_dir
	move.l	filereq,a1
	lea	rt_filename,a2
	clr.b	(a2)
	lea	dir_text,a3
	lea	tags,a0
	jsr	rtFileRequestA(a6)
	tst.l	d0
	beq.s	Pick_dir

	lea	dest_patch,a2
	move.l	filereq,a4
	move.l	$10(a4),a4
loop2
	move.b	(a4)+,(a2)+
	bne.s	loop2
	move.b	#0,(a2)
	rts
	
Execute
	movea.l	4,a6
	lea	dosname,a1
	clr.l	d0
	jsr	OpenLib(a6)
	tst.l	d0
	beq	CloseDOS
	move.l	d0,dosbase

	move.l	dosbase,a6
	
	move.l	#nil,d1
	move.l	#1004,d2
	jsr	-30(a6)
	tst.l	d0
	beq	CloseDOS
	move.l	d0,filehandle
	move.l	byicon,d0
	tst.l	d0
	bne	wb

	jsr	-60(a6)
	tst.l	d0
	beq	CloseDOS
	move.l	d0,out

	move.l	#stext,d2
	move.l	#etext-stext,d3
	move.l	dosbase,a6
	move.l	out,d1
	jsr	-48(a6)
	bra	cli
wb
	move	filehandle,out
cli	
	move.l	#filename,d1
	move.l	#0,d2
	move.l	out,d3
	jsr	-222(a6)		;execute

	move.l	filehandle,d1
	jsr	-36(a6)
CloseDOS:
	movea.l	4,a6
	move.l	dosbase,a1
	jsr	CloseLib(a6)
	rts

ByIcon		dc.l	0
returnMsg	dc.l	0
ReqName		dc.b	'reqtools.library',0,0
ReqBase		dc.l	0
dosname		dc.b	'dos.library',0
dosbase		dc.l	0

Def_dir		dc.b	'ram:',0,0
filereq		ds.l	1
rt_filename	blk.b	34,0
tags	dc.l	RTFI_Flags,FREQF_NOFILES
	dc.l	0

src_patch	blk.b	256,0
dest_patch	blk.b	256,0
arch_text	dc.b	"Choose archived file",0
dir_text	dc.b	"Choose destination dir",0

rt_file_point	dc.l	0	
filehandle	dc.l	0
out		dc.l	0
nil		dc.b	'NIL:',0
filename	dc.b	'c:lha x "'
parametr	blk.b	256,0
stext:		dc.b	$0A
		dc.b	$0a,$1b,'[33mLhAReq 1.0',$1b,'[0m (c) 1996 by ScoTT/Inferno'
		dc.b	$0A
		dc.b	$0A
		dc.b	'Trying to execute LhA...',$0A,$0A
etext:
