; Wildstar 1.1 : Makes * equal to #? in filepatterns
; by Kyzer/CSG
; $VER: Wildstar.asm 1.1 (08.04.98)
;
	incdir	include:
	include	lvo/exec_lib.i
	include	lvo/dos_lib.i
	include	dos/dosextens.i

stackf	MACRO	; stack_symbol, stackelement_symbol
	IFND	\1
\1	set	0
	ENDC
\1	set	\1-4
\2	equ	\1
	ENDM

print	MACRO
	lea	\1,a4
	move.l	a4,d1
	IFNC	'\2',''
	lea	\2,a4
	move.l	a4,d2
	ENDC
	jsr	_LVOVPrintf(a6)
	ENDM

	stackf	stackframe, swtoggle
	stackf	stackframe, swoff
	stackf	stackframe, swon
	stackf	stackframe, rdargs
	stackf	stackframe, arg2
	stackf	stackframe, arg1
	stackf	stackframe, retcode	

	move.l	4.w,a6
	lea	dosname(pc),a1	; dos.library v37+
	moveq.l	#37,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,a6
	tst.l	d0
	bne.s	start
	moveq	#10,d0
	rts
start	move.l	dl_Root(a6),a3
	link	a5,#stackframe

	lea	st_curr(pc),a0
	move.l	a0,arg1(a5)

	lea	templat(pc),a0
	move.l	a0,d1
	lea	swon(a5),a0	; to fill swon, swoff and swtoggle
	move.l	a0,d2
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	moveq	#0,d3
	jsr	_LVOReadArgs(a6)
	move.l	d0,rdargs(a5)
	beq.s	.noargs

	moveq	#0,d1
	tst.l	swon(a5)
	beq.s	.n1
	addq	#1,d1
.n1	tst.l	swoff(a5)
	beq.s	.n2
	addq	#1,d1
.n2	tst.l	swtoggle(a5)
	beq.s	.n3
	addq	#1,d1
.n3	cmp.b	#1,d1	; exactly one of on, off or toggle
	beq.s	.run
	moveq	#ERROR_TOO_MANY_ARGS,d1
	jsr	_LVOSetIoErr(a6)
	bra.s	.done

.run	lea	st_now(pc),a0
	move.l	a0,arg1(a5)
.try1	tst.l	swon(a5)
	beq.s	.try2
	bset.b	#RNB_WILDSTAR-24,rn_Flags(a3)
.try2	tst.l	swoff(a5)
	beq.s	.try3
	bclr.b	#RNB_WILDSTAR-24,rn_Flags(a3)
.try3	tst.l	swtoggle(a5)
	beq.s	.done
	bchg.b	#RNB_WILDSTAR-24,rn_Flags(a3)

.done	move.l	rdargs(a5),d1
	jsr	_LVOFreeArgs(a6)
.noargs
	lea	offword(pc),a0
	move.l	a0,arg2(a5)
	move.l	#0,retcode(a5)
	btst.b	#RNB_WILDSTAR-24,rn_Flags(a3)
	beq.s	.noton
	lea	onword(pc),a0
	move.l	a0,arg2(a5)
	move.l	#5,retcode(a5)
.noton	print	status(pc),arg1(a5)
.exit	move.l	a6,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
	move.l	retcode(a5),d0
	unlk	a5
	rts

dosname	dc.b	"dos.library",0
status	dc.b	"Recognition of '*' in pattern matching is %s %s.",10,0
st_curr	dc.b	"currently",0
st_now	dc.b	"now",0
onword	dc.b	"ON",0
offword	dc.b	"OFF",0
templat	dc.b	"ON/S,OFF/S,TOGGLE/S",0
