include	clib.inc
include	dir.inc
include	string.inc

_TEXT	SEGMENT

strxchg proc dist pascal public uses ds si di strb:dword,
	ostr:dword, nstr:dword, olen:word
	local convb[1024]:byte
    strxchg_00:
	les di,strb
	lds si,ostr
	sub al,al
	cmp al,[si]
	je strxchg_03
    strxchg_01:
	mov al,[si]
	mov ah,al
	sub al,'A'
	cmp al,'Z' - 'A' + 1
	sbb al,al
	and al,'a' - 'A'
	xor ah,al
    strxchg_02:
	mov al,es:[di]
	test al,al
	jz strxchg_03
	mov dl,al
	sub al,'A'
	cmp al,'Z' - 'A' + 1
	sbb al,al
	and al,'a' - 'A'
	xor dl,al
	mov al,dl
	inc di
	cmp al,ah
	jne strxchg_02
	inc si
	call strcmpi
	mov si,word ptr ostr
	jnz strxchg_01
	mov dx,es
	mov ax,di
	dec ax
	jmp strxchg_04
    strxchg_03:
	sub ax,ax
	mov dx,es
	mov ax,word ptr strb
    strxchg_04:
	jnz strxchg_05
	ret
    strxchg_05:
	mov si,ax
	mov byte ptr es:[si],0
	invoke strcpy, addr convb, strb
	invoke strcat, dx::ax, nstr
	mov cx,word ptr strb+2
	add si,olen
	invoke strcat, dx::ax, cx::si
	mov si,ax
	add si,WMAXPATH-1
	mov byte ptr ss:[si],0
	invoke strcpy, strb, dx::ax
	jmp strxchg_00
strxchg endp

_TEXT	ENDS

	END
