Metropoli BBS
VIEWER: fgets.asm MODE: TEXT (ASCII)
;****************************************************************************
; Filename: FGETS.ASM
;   Author: Adam Seychell
;  Version: 0.0
;  Created: 1995.April.29
;  Updated: -
;****************************************************************************
; Copyright Peter Andersson, 1994-1995.
; All rights reserved.
;****************************************************************************
; Function: char* @fgets(char *s, int n, FILE *stream);
;  Comment: gets a string from I/O
;    Input: Eax = destination of string
;			Edx = max number of character to get
;			Ecx = pointer of FILE stream
;   Output: Eax = pointer of string, of EOF on error
;****************************************************************************

		Include STDDEF.INC

		Codeseg

Proc fgets , 3
		Push	Edi
		Push	Ecx
		Push	Edx
		Mov		Edi,Eax
		TestZ	Edx
		jz      @@Exit01
@@loop01:
		Mov		Eax,[Esp+4]
		call	@fgetc
		Cmp		Eax,EOF
		Je @@error
		Mov		[Edi],al
		Inc		Edi
		Cmp		al,0
		je		@@Exit01
		Cmp		al,10
		je      @@Exit01
		Dec		[Dword Esp]
		Jz 		@@loop01

@@Exit01:
		Mov		[Byte Edi],0			; append nul terminating
		Add		Esp,8
		Pop		Edi
		Mov		Eax,Edi
		Ret
@@error:
		Pop		Ecx
		Pop		Ebx
		Pop		Edi
		Ret
Endp
		End

[ RETURN TO DIRECTORY ]