	name	OPENED

	title	OPENED -- program to find who has a file open
;
START	segment	word public 'CODE'
	assume	CS:START,DS:START,SS:START,ES:START

	org	100h
begin:
	jmp	past_name
	db	'OPENED V1.0'
past_name:
;
;	First move to command tail to the request buffer and do the request
;
	mov	si,81h		; location of tail
	mov	di,offset file_name	; file name within command
	mov	cx,1		; byte counter
move_loop:
	lodsb			; get next character
	cmp	al,13
	je	end_of_name
	cmp	al,' '
	jz	move_loop
	cmp	al,08
	jz	move_loop
	inc	cl
	stosb
	jmp	move_loop
end_of_name:
	mov	file_name_length,cl
	add	cl,(7-2)	; add length of buffer header - 2
	mov	si,offset get_conn_req
	mov	word ptr [si],cx			; record buffer length		
	mov	al,0		; terminate with a zero
	stosb			; add to file name
	mov	ah,0e3h		; request function code
	mov	di,offset get_conn_rep
	int	21h
;
;	Check for correct return code
;
	or	al,al
	jz	found_file
	mov	dx,offset error_msg
	mov	ah,9
	int	21h
	jmp	done
;
;	Put up the basic information
;
found_file:
	mov	si,offset get_conn_rep
	mov	al,[si+3]	; in use count
	call	to_ascii
	mov	using_num,ax
;
	mov	al,[si+5]	; open count
	call	to_ascii
	mov	open_num,ax
;
	mov	ah,9
	mov	dx,offset using
	int 21h			; put up used message
	mov	ah,9
	mov	dx,offset open
	int 21h			; put up opened message
;
;	Go through all the connections and get their names
;
	mov	cl,records
	cmp	cl,0
	je	done
	mov	ch,0		; get the number of records
	mov	si,offset get_name_req
	mov	di,offset get_name_rep
	mov	bx,offset get_conn_rep+19	; first connection number
	mov	dx,offset get_name_rep+8	; user name
;
conn_loop:
	mov	al,byte ptr [bx]	; get connection number
	mov	conn_out,al		; load connection number
	mov	ah,0e3h
	int	21h			; request connections information
;
	mov	word ptr[di+54],0a0dh	; CRLF
	mov	byte ptr[di+56],'$'	; terminate name for function 9
	mov	ah,9
	int	21h			; print the name
;
	add	bx,6			; jump to next connection
	loop	conn_loop
;
done:
	mov	ah,0
	int	21h
;
;------------------------------------------------------------------------------
;TO_ASCII Translates the byte in al into two ascii digits in AX
;------------------------------------------------------------------------------
to_ascii	proc near
	mov	ah,0		;just to be sure
to_ascii_5:
	sub	al,10
	jc	to_ascii_10
	inc	ah
	jmp	to_ascii_5
;
to_ascii_10:
	add	al,10
	add	ax,3030h
;
	xchg	al,ah
	cmp	al,30h
	jne	to_ascii_20
	mov	al,' '
to_ascii_20:
	ret
to_ascii	endp
;
;	Message strings
;
using:	db	13,10,'File use count:  '
using_num	label word
	db	'00$'
open:	db	13,10,'File open count: '
open_num	label word
	db	'00',13,10,'$'
;
;	Get connection buffers
;
get_conn_req:
	dw	?		; req buffer len
	db	0dch		; function code
	dw	0		; last record
	db	0		; directory handle
file_name_length:
	db	?		; file name length
file_name:
	db 	256 dup(?)	; file name
;
get_conn_rep:
	dw	512		; rep buffer length
	dw	?		; use count
	dw	?		; open count
	dw	?		; open for read count
	dw	?		; open for write count
	dw	?		; deny read count
	dw	?		; deny write count
	dw	?		; next request record
	db	?		; locked
records:
	db	?		; records
;
	db	500 dup(?)	; remainder of records
;
get_name_req:
	dw	3		; buffer length - 2
	db	16h
conn_out:
	db	?
;
get_name_rep:
	dw	get_name_len	; buffer length - 2
	dd	?		; object ID
	dw	?		; object type
	db	48 dup (?)	; object name
	db	7 dup (?)	; object login time
get_name_len = ($-get_name_req)-2

error_msg:
	db	13,10,'Unable to open file',13,10,
	db	13,10,13,10,'Did you give the netware volume?',13,10,'$'
START	ends

	end	begin



	
