	.title	rpos	Position file on key
	.ident	"V02.00"
;+
; Index		Position file on key
;
; Usage
;
;	rpos(stream, keybuf, keysize, options [, kor])
;	int stream;	/* Stream number returned by open */
;	char *keybuf;	/* Key to search on */
;	int keysize;	/* Size of key */
;	char *options;	/* String of options */
;	int kor;	/* New key-of-reference number */
;			/* (if "s" option was given) */
;
; Description
;
;	rpos() sets the stream position in a file, given a key value.
;	It may be issued only for relative and indexed files. It returns
;	0 on error and 1 on success. The options available with the
;	rpos() function are as follows:
;
; 		Options:
;	     	   g  - position greater than key
;	     	   n  - position greater than or equal to key
;	     	   s  - set key of reference
;-
; Edit History
; V02.00 19-Oct-82 TTC		Rework of old CS library
;

	.MCALL	FSDEF$
	FSDEF$

	.psect	c$strn
;
; Options.
;
gt:	.asciz	"g"
ge:	.asciz	"n"
skr:	.asciz	"s"
	.even

	.psect	c$data

posopt:	.word	gt,	O.PGT
	.word	ge,	O.PGE
	.word	skr,	O.SKR  	; (** IF THIS CHANGES, LOOK OUT BELOW **)
	.word	0

	.psect	c$code
rpos::
	mov	10(sp),r0		; r0 -> list of passed options
	mov	#posopt,r1		; r1 -> option table
	call	option			; check options
	tst	r0			; Error?
	beq	20$			; (Yes)
	bit	#O.SKR,r1		; SKR? (*** HARDWIRED ***)
	beq	10$			; (No)
	swab	r1			; (Yes), pit KOR number into hi byte
	bisb	12(sp),r1
	swab	r1
10$:	mov	#FS.POS,fsqio+q.iofn	; Function: FS.POS
	mov	r1,-(sp)		; Save option word
	mov	#fsqio+q.iopl,r1	; r1 --> qio param list
	mov	sp,r0			; r0 --> function parameter list
	add	#4,r0
	mov	(r0)+,(r1)+		; Parameter #1: Stream Number
	clr	(r1)+			; Clear parameters 2 and 3
	clr	(r1)+
	mov	(r0)+,(r1)+		; Parameter #4: Key buffer addr
	mov	(r0),(r1)+		; Parameter #5: Key size
	mov	(sp)+,(r1)		; Parameter #6: Incl-or of opts
	mov	#fsqio,r0		; r0 must = qio for xqiow
	call	.xqiow			; execute qiow
	mov	#1,r0			; Assume successful
	cmp	$dsw,#is.suc		; How'd it go
	blo	20$			; Not so good
	cmpb	f.iosb,#is.suc
	beq	30$
20$:	clr	r0			; Branch here if error, r0 = 0
30$:	return
	.end
