include	clib.inc
include	dos.inc
include	fblk.inc
include	string.inc
include	filter.inc

	public	filter
	public	filter_fblk
	public	filter_wblk

_TEXT	SEGMENT

binary	PROC	; CX = flag, AX = date, BX:DX = size
	mov	si,word ptr filter
	test	si,si
	jz	binary_ok
	cmp	ax,[si].of_min_date
	jb	binary_fail
	cmp	[si].of_max_date,0
	je	binary_min
	cmp	ax,[si].of_max_date
	ja	binary_fail
    binary_min:
      ifdef __386__
	cmp	edx,[si].of_min_size
      else
	cmp	bx,word ptr [si].of_min_size[2]
	jb	binary_fail
	ja	binary_max
	mov	ax,dx
	cmp	ax,word ptr [si].of_min_size
      endif
	jb	binary_fail
    binary_max:
      ifdef __386__
	mov	eax,[si].of_max_size
	test	eax,eax
	jz	binary_03
	cmp	edx,eax
      else
	mov	ax,word ptr [si].of_max_size[2]
	test	ax,ax
	jz	binary_02
	cmp	bx,ax
	ja	binary_fail
	jb	binary_03
    binary_02:
	mov	ax,word ptr [si].of_max_size
	test	ax,ax
	jz	binary_03
	cmp	dx,ax
      endif
	ja	binary_fail
    binary_03:
	mov	ax,cx
	and	ax,[si]
	cmp	ax,cx
	jne	binary_fail
    binary_ok:
	xor	ax,ax
	inc	ax
    binary_end:
	ret
    binary_fail:
	xor	ax,ax
	jmp	binary_end
binary	ENDP

string	PROC
	xor	ax,ax
	cmp	al,[si].of_include
	je	string_01
    string_00:
	push	es
	push	bx
	add	si,of_include
	invoke	cmpwargs, es::bx, ds::si
	pop	cx
	pop	dx
	jz	string_02
	xor	ax,ax
	sub	si,of_include
    string_01:
	cmp	al,[si].of_exclude
	je	string_03
	add	si,of_exclude
	invoke	cmpwargs, dx::cx, ds::si
	jz	string_03
    string_02:
	xor	ax,ax
	ret
    string_03:
	xor	ax,ax
	inc	ax
	ret
string	ENDP

_TEXT	ENDS

PPROC	filter_fblk, fb:dword
	push	si
	les	bx,fb
	mov	ax,es:[bx].fb_date
	mov	cx,es:[bx].fb_flag
      ifdef __386__
	mov	edx,es:[bx].fb_size
      else
	mov	dx,word ptr es:[bx].fb_size
	mov	bx,word ptr es:[bx].fb_size[2]
      endif
	call	binary
	jz	filter_fblk_00
	test	si,si
	jz	filter_fblk_00
	mov	bx,word ptr fb
	add	bx,fb_name
	call	string
    filter_fblk_00:
	test	ax,ax
	pop	si
	ret
PEND	filter_fblk

PPROC	filter_wblk, wf:dword
	push	si
	MLES	bx,wf
	mov	ax,es:[bx].wf_datemodified
	mov	cx,es:[bx].wf_attrib
      ifdef __386__
	mov	edx,es:[bx].wf_sizeax
      else
	mov	dx,word ptr es:[bx].wf_sizeax
	mov	bx,word ptr es:[bx].wf_sizeax[2]
      endif
	call	binary
	jz	filter_wblk_00
	test	si,si
	jz	filter_wblk_00
	mov	bx,word ptr wf
	add	bx,wf_name
	call	string
    filter_wblk_00:
	test	ax,ax
	pop	si
	ret
PEND	filter_wblk

_DATA	SEGMENT

filter	dd 0

_DATA	ENDS

	END
