; Wildstar 1.0 : Makes * equal to #? in filepatterns
; by Kyzer/CSG
;
	incdir	include:
	include	lvo.i
	include	dos/dosextens.i

stackframe=-28
retcode=-28
arg1=-24
arg2=-20
rdargs=-16
swon=-12
swoff=-8
swtoggle=-4

print	MACRO
	lea	\1,a4
	move.l	a4,d1
	IFC	'\2',''
	moveq	#0,d2
	ELSEIF
	lea	\2,a4
	move.l	a4,d2
	ENDC
	jsr	_LVOVPrintf(a6)
	ENDM

	move.l	4.w,a6
	lea	dosname(pc),a1	; dos.library v37+
	moveq.l	#37,d0
	jsr	_LVOOpenLibrary(a6)
	tst.l	d0
	bne.s	start
	moveq	#10,d0
	rts
start	move.l	d0,a6
	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	.badargs

	move.l	swon(a5),d0
	add.l	swoff(a5),d0
	add.l	swtoggle(a5),d0
	tst.l	d0
	beq.s	.noargs
	cmp.b	#-1,d0
	beq.s	.parse
	print	onlyone(pc)
	bra.s	.noargs
.parse	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	.noargs
	bchg.b	#RNB_WILDSTAR-24,rn_Flags(a3)

.noargs	move.l	rdargs(a5),d1
	jsr	_LVOFreeArgs(a6)
.badargs
	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
onlyone	dc.b	"only one of ON, OFF or TOGGLE allowed",10,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

