include	clib.inc
include	io.inc
include	iost.inc
include	stdio.inc

ifndef	__f__
	ax?	textequ <ax>
	cx?	textequ <cx>
	size_t	textequ <word>
else
	ax?	textequ <eax>
	cx?	textequ <ecx>
	size_t	textequ <dword>
endif

_TEXT	segment

ogetl	proc _CType public filename:dword, buffer:dword, bsize:size_t
    ifdef __f__
	mov STDI.ios_bp,offset _bufin
    else
	mov word ptr STDI.ios_bp+2,ds
	mov word ptr STDI.ios_bp,offset _bufin
    endif
	mov STDI.ios_size,1000h
	mov STDI.ios_flag,IO_STRINGB
	mov ax?,bsize
	mov STDI.ios_l,ax?
	mov STDI.ios_c,0
	mov STDI.ios_i,0
	movmx STDI.ios_bb,buffer
	.if func(osopen,filename,0,M_RDONLY,A_OPEN) != -1
	    mov STDI.ios_file,ax?
	.else
	    sub ax?,ax?
	.endif
	test ax?,ax?
	ret
ogetl	endp

ogets	proc _CType public
local	p:dword
	movmx	p,STDI.ios_bb
	mov	cx?,STDI.ios_l
	sub	cx?,2
	call	ogetc
	jz	ogets_end
      @@:
	cmp	al,0Dh
	je	ogets_0Dh
	cmp	al,0Ah
	je	ogets_eol
	test	al,al
	jz	ogets_end
      ifndef __f__
	les	bx,p
	mov	es:[bx],al
	inc	word ptr p
      else
	mov	edx,p
	mov	[edx],al
	inc	p
      endif
	dec	cx?
	jz	ogets_eol
	call	ogetc
	jnz	@B
    ogets_eol:
	inc	al
	jmp	ogets_end
    ogets_0Dh:
	call	ogetc
    ogets_end:
      ifndef __f__
	les bx,p
	mov byte ptr es:[bx],0
	.if !ZERO?
	    mov dx,word ptr STDI.ios_bb+2
	    mov ax,word ptr STDI.ios_bb
	.else
	    sub ax,ax
	    cwd
	.endif
      else
	mov edx,p
	mov byte ptr [edx],0
	.if !ZERO?
	    mov eax,STDI.ios_bb
	.else
	    sub eax,eax
	.endif
      endif
	ret
ogets	endp

_TEXT	ends

	END


