include	doszip/doszip.inc
include	dir.inc
include	string.inc
include	conio.inc
include	tinfo.inc

	public	cmedit
ifdef __TE__
	public	cmtmodal
	extrn	editzip:near
	extrn	topensession: dist
endif

_DZIP	SEGMENT

load_tedit proc	pascal public uses si file:dword, etype:word
local path[WMAXPATH]:byte
	invoke strcpy, addr path, file
	mov si,ax
	.if !func(strchr, dx::ax, '.')
	    invoke strcat, ss::si, addr ds:[cp_dotdot+1]
	.endif
	invoke loadiniproc, addr cstr("Edit"), ss::si, etype
	test ax,ax
      ifdef __TE__
	.if ZERO?
	    call clrcmdl
	    mov ax,cpanel
	    .if func(panel_findnext)
		mov bx,cpanel
		mov bx,word ptr [bx].pn_wsub
		invoke wedit, [bx].ws_fcb, [bx].ws_count
	    .else
		invoke tedit, ss::si, 0
		call cmcupdate
		sub ax,ax
	    .endif
	.endif
      endif
	ret
load_tedit endp

rereadab proc
	push	ax
	mov	ax,panela
	call	panel_reread
	mov	ax,panelb
	call	panel_reread
	pop	ax
	ret
rereadab endp

cmedit	proc dist
	call	cm_loadfblk
	jz	cmedit_end
  ifdef __DLL__
	cmp	cx,4
	je	cmedit_ext
  endif
  ifdef __TE__
	cmp	cx,2
	je	cmedit_zip
  endif
	dec	cx
	jnz	cmedit_end
	cmp	di,cx
	jne	@F
	mov	di,4
    @@:
	invoke	load_tedit, dx::ax, di
    cmedit_end:
	add	sp,WMAXPATH
	call	rereadab
	pop	di
	pop	si
	pop	bp
	ret
  ifdef __TE__
    cmedit_zip:
	call	editzip
	jmp	cmedit_end
  endif
  ifdef __DLL__
    cmedit_ext:
	mov	cx,bx
	mov	bx,cpanel
	mov	bx,word ptr [bx].pn_wsub
	mov	ah,_DLL_EDIT
	int	DLL
	jmp	cmedit_end
  endif
cmedit	endp

ifdef __TE__
cmtmodal proc dist
	push si
	mov si,tinfo
	.if si && [si].S_TINFO.ti_flag & _T_MALLOC or _T_EMMBUF
	    call tmodal
	.else
	    call topensession
	.endif
	call rereadab
	pop si
	ret
cmtmodal endp
endif

_DZIP	ENDS

_DATA	SEGMENT

cp_section_edit	db 'Edit',0

_DATA	ENDS

	END
