include	doszip/doszip.inc
include	keyb.inc
include	dos.inc
include	dir.inc
include	ini.inc
include	iost.inc
include	io.inc
include	string.inc
include	conio.inc
include	mouse.inc
include	errno.inc
include	disk.inc

	public	cmpsizeup	; Alt-Up
	public	cmpsizedn	; Alt-Down
	public	cmupdir
	public	cmsubdir
	public	cmrename
	public	cmcopycell
	public	cmpath0
	public	cmpath1
	public	cmpath2
	public	cmpath3
	public	cmpath4
	public	cmpath5
	public	cmpath6
	public	cmpath7
	public	cmpath8
	public	cmpath9
	public	cmalong
	public	cmblong
	public	cmclong
	public	cmadetail
	public	cmcdetail
	public	cmbdetail
	public	cmahidden
	public	cmchidden
	public	cmbhidden
	public	cmamini
	public	cmbmini
	public	cmcmini
	public	cmvolinfo
	public	cmavolinfo
	public	cmbvolinfo
	public	cmanosort
	public	cmbnosort
	public	cmcnosort
	public	cmadate
	public	cmbdate
	public	cmcdate
	public	cmatype
	public	cmbtype
	public	cmctype
	public	cmasize
	public	cmbsize
	public	cmcsize
	public	cmaname
	public	cmbname
	public	cmcname
	public	cmachdrv
	public	cmbchdrv
	public	cmtoggleon
	public	cmatoggle
	public	cmbtoggle
	public	cmtogglesz
	public	cmtogglehz
	public	cmaupdate
	public	cmbupdate
	public	cmcupdate
	public	cmselect
	public	cmdeselect
	public	cminvert
	public	cmswap
	public	cmawideview
	public	cmbwideview
	public	cmcwideview
	public	cmhomedir

	extrn	cp_selectmask:byte
	extrn	panel_toggleact:near

_DATA	SEGMENT

cp_selectdrv	db 'Select disk Panel '
cp_selectdrv_X	db 'A',0

_DATA	ENDS

_DZIP	SEGMENT

ccedit	proc	; rename or copy current file to a new name
	push bp
	push si
	push di
	mov bp,ax
	mov ax,cpanel
	.if func(panel_curobj)
	    mov si,dx
	    mov di,bx
	    .if !(cx & _A_UPDIR or _A_ROOTDIR)
		.if cx & _A_ARCHIVE
		  ifdef __DLL__
		    .if cx & _A_ARCHEXT
			mov bx,cpanel
			mov bx,word ptr [bx.pn_wsub]
			mov dx,si
			mov cx,di
			mov ah,_DLL_RENAME
			int DLL
		    .else
			call notsup
		    .endif
		  else
		    call notsup
		  endif
		.else
		  ifdef __LFN__
		    invoke wlongname, dx::ax, 0
		  endif
		    invoke strcpy, addr __srcfile, dx::ax
		    invoke strcpy, addr __outfile, dx::ax
		    .if __outfile
			mov bx,cpanel
			mov bx,word ptr [bx.pn_xl]
			mov dx,word ptr [bx.xl_rect+2]
			mov bx,word ptr [bx.xl_rect]
			mov cl,dl
			mov ch,0
			mov ax,0720h
			call @scputw
			invoke dledit, addr __outfile, dx::bx, WMAXPATH-1, 0
			.if ax != KEY_ESC
			    .if func(strcmp, addr __outfile, addr __srcfile)
				.if __outfile
				    .if bp
					mov es,si
					mov ax,es:[di]
					.if !(ax & _A_ARCHIVE)
					    invoke copyfile,
						es:[di.fb_size],
						es:[di.fb_date],
						es:[di.fb_time], ax
					.endif
				    .else
					invoke rename,
					    addr __srcfile,
					    addr __outfile
				    .endif
				    mov ax,cpanel
				    call panel_reread
				.endif
			    .endif
			.endif
		    .endif
		    mov bx,cpanel
		    .if func(dlclose, [bx.pn_xl])
			mov ax,cpanel
			call pcell_show
		    .endif
		    mov ax,1
		.endif
	    .else
		sub ax,ax
	    .endif
	.endif
	pop di
	pop si
	pop bp
	ret
ccedit	endp

cmrename proc dist
	xor ax,ax
	call ccedit
	ret
cmrename endp

cmcopycell proc dist
	mov ax,1
	call ccedit
	ret
cmcopycell endp

cmpsizeup proc dist
	mov bx,panela
	mov bx,word ptr [bx.pn_dialog]
	mov al,9
	.if cflag & _C_HORIZONTAL
	    dec al
	.endif
	.if [bx+7] != al
	    inc byte ptr config.c_panelsize
	    call redraw_panels
	.endif
	ret
cmpsizeup endp

cmpsizedn proc dist
	xor ax,ax
	.if al != config.c_panelsize
	    dec byte ptr config.c_panelsize
	    call redraw_panels
	.endif
	ret
cmpsizedn endp

cmupdir	proc dist
	.if func(panel_event, cpanel, KEY_HOME)
	    invoke panel_event, cpanel, KEY_ENTER
	.endif
	ret
cmupdir endp

cmsubdir proc dist
	mov ax,cpanel
	.if func(panel_curobj)
	    .if cx & _A_SUBDIR
	    	invoke panel_event, cpanel, KEY_ENTER
	    .endif
	.endif
	ret
cmsubdir endp

cmpath proc pascal uses si di ini_id:word
local	path[WMAXPATH]:byte
	mov ax,cpanel
	.if func(panel_state)
	    .if func(inientryid, addr cp_directory, ini_id)
		mov es,dx
		mov bx,ax
		.if word ptr es:[bx] != '><'
		    .if func(strchr, dx::ax, ',')
			inc ax
			invoke strstart, dx::ax
			mov cx,ax
			invoke strncpy, addr path, dx::cx, WMAXPATH
			invoke expand_environ, dx::ax
			.if path != '['
			    mov dx,ss
			    lea ax,path
			    call cpanel_setpath
			.endif
		    .endif
		.endif
	    .endif
	.endif
	ret
cmpath	endp

cmpathp	macro q
cmpath&q proc dist
	invoke cmpath, q
	ret
cmpath&q endp
	endm

cmpathp 0
cmpathp 1
cmpathp 2
cmpathp 3
cmpathp 4
cmpathp 5
cmpathp 6
cmpathp 7
cmpathp 8
cmpathp 9

cmlfn proc dist
      ifdef __LFN__
	push bx
	mov bx,[bx]
	mov ax,[bx]
	.if ax & _W_LONGNAME
	    and ax,not _W_LONGNAME
	.elseif _ifsmgr
	    or ax,_W_LONGNAME
	.endif
	mov [bx],ax
	pop ax
	call panel_update
      endif
	ret
cmlfn endp

cmalong	proc dist
	mov bx,panela
	jmp cmlfn
cmalong	endp

cmblong	proc dist
	mov bx,panelb
	jmp cmlfn
cmblong	endp

cmclong	proc dist
	mov bx,cpanel
	jmp cmlfn
cmclong	endp

cmdetail proc
	mov bx,dx
	mov ax,[bx.pn_flag]
	and ax,not _P_WIDEVIEW
	xor ax,_P_DETAIL
	mov [bx.pn_flag],ax
	mov ax,dx
	call panel_redraw
	ret
cmdetail endp

cmadetail proc dist
	mov dx,panela
	call cmdetail
	ret
cmadetail endp

cmcdetail proc dist
	mov ax,panela
	cmp ax,cpanel
	je cmadetail
cmcdetail endp

cmbdetail proc dist
	mov dx,panelb
	call cmdetail
	ret
cmbdetail endp

cmwideview proc
	mov bx,dx
	mov ax,[bx.pn_flag]
	and ax,not _P_DETAIL
	xor ax,_P_WIDEVIEW
	mov [bx.pn_flag],ax
	mov ax,bx
	call panel_redraw
	ret
cmwideview endp

cmawideview proc dist
	mov dx,panela
	call cmwideview
	ret
cmawideview endp

cmbwideview proc dist
	mov dx,panelb
	call cmwideview
	ret
cmbwideview endp

cmcwideview proc dist
	mov dx,cpanel
	call cmwideview
	ret
cmcwideview endp

cmahidden proc dist
	xor path_a.wp_flag,_W_HIDDEN
	mov ax,panela
	call panel_update
	ret
cmahidden endp

cmchidden proc dist
	mov ax,panela
	cmp ax,cpanel
	je cmahidden
cmchidden endp

cmbhidden proc dist
	xor path_b.wp_flag,_W_HIDDEN
	mov ax,panelb
	call panel_update
	ret
cmbhidden endp

cmamini	proc dist
	mov ax,panela
	call panel_xormini
	ret
cmamini	endp

cmbmini	proc dist
	mov ax,panelb
	call panel_xormini
	ret
cmbmini	endp

cmcmini	proc dist
	mov ax,cpanel
	call panel_xormini
	ret
cmcmini	endp

cmvolinfo proc dist
	mov ax,cpanel
	call panel_xorinfo
	ret
cmvolinfo endp

cmavolinfo proc	dist
	mov ax,panela
	call panel_xorinfo
	ret
cmavolinfo endp

cmbvolinfo proc	dist
	mov ax,panelb
	call panel_xorinfo
	ret
cmbvolinfo endp

cm_sort	proc pascal uses si di	; AX: OFFSET panel, DX: sort flag
local	path[WMAXPATH]:byte
	mov si,dx
	.if func(panel_state)
	    mov cx,si
	    mov si,bx
	    mov di,dx
	    mov bx,word ptr [bx.ws_flag]
	    mov ax,[bx.wp_flag]
	    and ax,not (_W_SORTSIZE or _W_NOSORT)
	    or ax,cx
	    mov [bx.wp_flag],ax
	    mov ax,di
	    .if func(panel_curobj)
		lea cx,path
		invoke strcpy, ss::cx, dx::ax
		invoke wssort, ss::si
		.if func(wsearch, ss::si, addr path) != -1
		    push ax
		    push di
		    invoke dlclose, [di.pn_xl]
		    pop ax
		    pop dx
		    call panel_setid
		    .if di == cpanel
			mov ax,di
			call pcell_show
		    .endif
		.endif
	    .endif
	    invoke panel_putitem, di, 0
	    mov ax,1
	.endif
	ret
cm_sort	endp

cm_nosort proc
	push ax
	call panel_state
	pop ax
	.if !ZERO?
	    push dx
	    push 0
	    mov bx,word ptr [bx.ws_flag]
	    or [bx.wp_flag],_W_NOSORT
	    call panel_read
	    call panel_putitem
	    mov ax,1
	.endif
	ret
cm_nosort endp

cmanosort proc dist
	mov ax,panela
	call cm_nosort
	ret
cmanosort endp

cmbnosort proc dist
	mov ax,panelb
	call cm_nosort
	ret
cmbnosort endp

cmcnosort proc dist
	mov ax,cpanel
	call cm_nosort
	ret
cmcnosort endp

cmadate	proc dist
	mov ax,panela
	mov dx,_W_SORTDATE
	call cm_sort
	ret
cmadate	endp

cmbdate	proc dist
	mov ax,panelb
	mov dx,_W_SORTDATE
	call cm_sort
	ret
cmbdate	endp

cmcdate	proc dist
	mov ax,cpanel
	mov dx,_W_SORTDATE
	call cm_sort
	ret
cmcdate	endp

cmatype	proc dist
	mov ax,panela
	mov dx,_W_SORTTYPE
	call cm_sort
	ret
cmatype	endp

cmbtype	proc dist
	mov ax,panelb
	mov dx,_W_SORTTYPE
	call cm_sort
	ret
cmbtype	endp

cmctype	proc dist
	mov ax,cpanel
	mov dx,_W_SORTTYPE
	call cm_sort
	ret
cmctype	endp

cmasize	proc dist
	mov ax,panela
	mov dx,_W_SORTSIZE
	call cm_sort
	ret
cmasize	endp

cmbsize	proc dist
	mov ax,panelb
	mov dx,_W_SORTSIZE
	call cm_sort
	ret
cmbsize	endp

cmcsize	proc dist
	mov ax,cpanel
	mov dx,_W_SORTSIZE
	call cm_sort
	ret
cmcsize	endp

cmaname	proc dist
	mov ax,panela
	mov dx,_W_SORTNAME
	call cm_sort
	ret
cmaname	endp

cmbname	proc dist
	mov ax,panelb
	mov dx,_W_SORTNAME
	call cm_sort
	ret
cmbname	endp

cmcname	proc dist
	mov ax,cpanel
	mov dx,_W_SORTNAME
	call cm_sort
	ret
cmcname	endp

cmchdrv	proc
	push si
	mov si,ax
	.if func(panel_state)
	    mov errno,0
	    .if func(_disk_select, addr cp_selectdrv)
		push ax
		dec ax
		invoke panel_sethdd, si, ax
		call msloop
		pop ax
	    .endif
	.endif
	pop si
	ret
cmchdrv	endp

cmachdrv proc dist
	mov ax,panela
	mov cp_selectdrv_X,'A'
	call cmchdrv
	ret
cmachdrv endp

cmbchdrv proc dist
	mov ax,panelb
	mov cp_selectdrv_X,'B'
	call cmchdrv
	ret
cmbchdrv endp

cmatoggle proc dist
	mov ax,panela
	call panel_toggle
	ret
cmatoggle endp

cmbtoggle proc dist
	mov ax,panelb
	call panel_toggle
	ret
cmbtoggle endp

cmaupdate proc dist
	mov ax,panela
	call panel_reread
	ret
cmaupdate endp

cmbupdate proc dist
	mov ax,panelb
	call panel_reread
	ret
cmbupdate endp

cmcupdate proc dist
	mov ax,cpanel
	call panel_reread
	ret
cmcupdate endp

select proc
	mov ax,cpanel
	.if func(panel_state)
	    push si
	    push di
	    mov si,dx
	    mov di,word ptr [si.pn_wsub]
	    mov cx,[si.pn_fcb_count]
	    mov si,word ptr [di.ws_fcb+2]
	    mov di,word ptr [di.ws_fcb]
	    .while cx
		mov es,si
		les bx,es:[di]
		push cx
		.if func(cmpwarg, addr es:[bx.fb_name], addr cp_selectmask)
		    mov es,si
		    invoke fblk_select, es:[di]
		.endif
		add di,4
		pop cx
		dec cx
	    .endw
	    invoke panel_putitem, cpanel, 0
	    mov ax,1
	    pop di
	    pop si
	.endif
	ret
select endp

cmselect proc dist
	.if !cp_selectmask
	    invoke strcpy, addr cp_selectmask, addr cp_stdmask
	.endif
	.if func(tgetline, addr cp_select, addr cp_selectmask, 12, 32+8000h)
	    .if cp_selectmask
		call select
	    .endif
	.endif
	ret
cmselect endp

deselect proc
	mov ax,cpanel
	.if func(panel_state)
	    push si
	    push di
	    mov si,dx
	    mov di,word ptr [si.pn_wsub]
	    mov cx,[si.pn_fcb_count]
	    mov si,word ptr [di.ws_fcb+2]
	    mov di,word ptr [di.ws_fcb]
	    .repeat
		mov es,si
		push cx
		lodm es:[di]
		add ax,fb_name
		.if func(cmpwarg, dx::ax, addr cp_selectmask)
		    mov es,si
		    les bx,es:[di]
		    and es:[bx.fb_flag],not _A_SELECTED
		.endif
		add di,4
		pop cx
	    .untilcxz
	    invoke panel_putitem, cpanel, 0
	    mov ax,1
	    pop di
	    pop si
	.endif
	ret
deselect endp

cmdeselect proc	dist
	.if !cp_selectmask
	    invoke strcpy, addr cp_selectmask, addr cp_stdmask
	.endif
	.if func(tgetline, addr cp_deselect, addr cp_selectmask, 12, 32+8000h)
	    .if cp_selectmask
		call deselect
	    .endif
	.endif
	ret
cmdeselect endp

cminvert proc dist
	mov ax,cpanel
	.if func(panel_state)
	    push si
	    push di
	    mov si,dx
	    mov di,word ptr [si.pn_wsub]
	    mov cx,[si.pn_fcb_count]
	    mov si,word ptr [di.ws_fcb+2]
	    mov di,word ptr [di.ws_fcb]
	    .repeat
		mov es,si
		invoke fblk_invert, es:[di]
		add di,4
	    .untilcxz
	    invoke panel_putitem, cpanel, 0
	    mov ax,1
	    pop di
	    pop si
	.endif
	ret
cminvert endp

cmswap	proc dist
	.if func(panel_stateab)
	    push si
	    push di
	    mov si,flaga
	    mov di,flagb
	    mov ax,panela
	    call panel_close
	    mov ax,panelb
	    call panel_close
	    mov ax,offset config.c_fcb_indexa
	    mov dx,offset config.c_fcb_indexb
	    invoke memxchg, ds::ax, ds::dx, 4
	    mov ax,offset spanela.pn_fcb_index
	    mov dx,offset spanelb.pn_fcb_index
	    invoke memxchg, ds::ax, ds::dx, 4
	    invoke memxchg, addr path_a, addr path_b, SIZE S_PATH
	    xor si,_P_PANELID
	    xor di,_P_PANELID
	    mov flaga,di
	    mov flagb,si
	    xor cflag,_C_PANELID
	    call prect_open_ab
	    call panel_open_ab
	    call panel_toggleact
	    mov ax,1
	    pop di
	    pop si
	.endif
	ret
cmswap	endp

cmtoggleon proc	dist
	push si
	push di
	mov ax,panela
	call panel_state
	mov si,ax
	mov ax,panelb
	call panel_state
	mov di,ax
	.if ax != si
	    .if si
		call cmatoggle
	    .else
		call cmbtoggle
	    .endif
	.elseif ax
	    mov ax,cpanel
	    .if ax != panelb
		push panelb
    	    .else
		push panela
	    .endif
	    call panel_hide
	    pop ax
	    call panel_hide
	.else
	    mov ax,cpanel
	    push ax
	    push ax
	    .if ax == panelb
		mov ax,panela
    	    .else
		mov ax,panelb
	    .endif
	    call panel_show
	    pop ax
	    call panel_show
	    pop ax
	    call panel_setactive
	.endif
	xor ax,ax
	pop di
	pop si
	ret
cmtoggleon endp

cmtogglesz proc	dist
	xor ax,ax
	.if al == config.c_panelsize
	    mov al,_scrrow
	    shr al,1
	    dec al
	.endif
	mov config.c_panelsize,al
	call redraw_panels
	ret
cmtogglesz endp

cmtogglehz proc	dist
	mov al,config.c_panelsize
	mov cx,cflag
	.if cx & _C_WIDEVIEW && cx & _C_HORIZONTAL
	    and cx,not _C_WIDEVIEW
	    shl al,1
	.elseif cx & _C_HORIZONTAL
	    and cx,not _C_HORIZONTAL
	    shl al,1
	.else
	    or cx,_C_WIDEVIEW or _C_HORIZONTAL
	.endif
	mov cflag,cx
	mov config.c_panelsize,al
	call redraw_panels
	ret
cmtogglehz endp

cmhomedir proc dist
	mov ax,cpanel
	.if func(panel_state)
	    mov bx,cpanel
	    mov bx,[bx]
	    mov ax,[bx]
	    or ax,_W_ROOTDIR
	    and ax,not _W_ARCHIVE
	    mov [bx],ax
	    mov [bx.wp_arch],0
	    mov ax,cpanel
	    call panel_read
	    invoke panel_putitem, cpanel, 0
	.endif
	ret
cmhomedir endp

_DZIP	ENDS

	END
