include	clib.inc

; strfcat(b,0,f) == strcat(b,"\\") + strcat(b,f)
; strfcat(b,s,f) == strcpy(b,s) + strfcat(b,0,f)

_TEXT	SEGMENT

strfcat proc dist pascal public uses ds si di s1:dword, s2:dword, s3:dword
	cld
	sub al,al
	les di,s1
	mov dx,di
	mov cx,-1
	.if word ptr s2 ; path
	    les di,s2
	    repne scasb
	    les di,s1
	    lds si,s2
	    not cx
	    rep movsb
	.else
	    repne scasb
	.endif
	dec di
	.if di != dx
	    mov byte ptr es:[di],'\'
	    mov al,es:[di-1]
	    .if al == '\' || al == '/'
		dec di
	    .endif
	    inc di
	.endif
	lds si,s3
      @@:
	mov al,[si]
	mov es:[di],al
	inc di
	inc si
	test al,al
	jnz @B
	mov es:[di],al
	mov ax,word ptr s1
	mov dx,word ptr s1+2
	ret
strfcat endp

_TEXT	ENDS

	END
