From c1fce6235de5cb6181e568f362d280a2ffb0cd4f Mon Sep 17 00:00:00 2001 From: "Evgeny Grechnikov (Diamond)" Date: Wed, 2 Jul 2008 20:27:47 +0000 Subject: [PATCH] KFar 0.5: built-in editor, first steps git-svn-id: svn://kolibrios.org@814 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/fs/kfar/trunk/build_ru.bat | 1 - programs/fs/kfar/trunk/dialogs.inc | 464 +++--- programs/fs/kfar/trunk/editor.inc | 2294 +++++++++++++++++++++++++++ programs/fs/kfar/trunk/kfar.asm | 726 ++++++++- programs/fs/kfar/trunk/kfar.ini | 49 +- programs/fs/kfar/trunk/kfar.txt | 91 ++ programs/fs/kfar/trunk/viewer.inc | 155 +- 7 files changed, 3472 insertions(+), 308 deletions(-) create mode 100644 programs/fs/kfar/trunk/editor.inc create mode 100644 programs/fs/kfar/trunk/kfar.txt diff --git a/programs/fs/kfar/trunk/build_ru.bat b/programs/fs/kfar/trunk/build_ru.bat index 866d87c409..c5ffa6ecd9 100644 --- a/programs/fs/kfar/trunk/build_ru.bat +++ b/programs/fs/kfar/trunk/build_ru.bat @@ -1,7 +1,6 @@ @erase lang.inc @echo lang fix ru >lang.inc @fasm kfar.asm kfar -mtappack kfar @erase lang.inc @kpack kfar @pause \ No newline at end of file diff --git a/programs/fs/kfar/trunk/dialogs.inc b/programs/fs/kfar/trunk/dialogs.inc index 779794b366..a821adf22c 100644 --- a/programs/fs/kfar/trunk/dialogs.inc +++ b/programs/fs/kfar/trunk/dialogs.inc @@ -8,6 +8,7 @@ dlgtemplate: ; ЎЁв 1: ЁбЇ®«м§®ў вм бв ­¤ ав­лҐ жўҐв  ЇаҐ¤гЇаҐ¦¤Ґ­Ёп/®иЁЎЄЁ ; (Ґб«Ё «оЎ®© Ё§ нвЁе ЎЁв®ў гбв ­®ў«Ґ­, Ї®«п main_color,border_color,header_color ; ЁЈ­®аЁаговбп) +; ЎЁв 2: ­Ґ аЁб®ў вм ⥭м .flags dd ? .x dd ? .y dd ? @@ -20,10 +21,137 @@ dlgtemplate: .border_color db ? .header_color db ? db ? ; align +.dataptr dd ? ; used internally, ignored on input .size = $ end virtual GenericBox: + push [cursor_x] + push [cursor_y] + push dword [esp+8+8] + push dword [esp+8+8] + call ShowGenericBox + test eax, eax + jz @f + pop [cursor_y] + pop [cursor_x] + ret +@@: + pushad +; message loop +.event: + push 10 + pop eax + int 40h + dec eax + jz .redraw + dec eax + jz .key + jmp exit +.redraw: + call draw_window + jmp .event +.key: + mov al, 2 + int 40h + shr eax, 8 + cmp al, 0xE0 + jnz @f + mov [bWasE0], 1 + jmp .event +@@: + xchg ah, [bWasE0] + cmp al, 0x1D + jz .ctrl_down + cmp al, 0x9D + jz .ctrl_up + cmp al, 0x2A + jz .lshift_down + cmp al, 0xAA + jz .lshift_up + cmp al, 0x36 + jz .rshift_down + cmp al, 0xB6 + jz .rshift_up + cmp al, 0x38 + jz .alt_down + cmp al, 0xB8 + jz .alt_up + mov ebx, [esp+24h+8] + mov ecx, [esp+28h+8] + push 0 + push eax + push 2 + push ebx + call ecx + test eax, eax + jz .event + mov [esp+28], eax + jmp .exit +.ctrl_down: + test ah, ah + jnz .rctrl_down + or [ctrlstate], 4 + jmp .event +.rctrl_down: + or [ctrlstate], 8 + jmp .event +.ctrl_up: + test ah, ah + jnz .rctrl_up + and [ctrlstate], not 4 + jmp .event +.rctrl_up: + and [ctrlstate], not 8 + jmp .event +.lshift_down: + test ah, ah + jnz @f + or [ctrlstate], 1 +@@: jmp .event +.lshift_up: + test ah, ah + jnz @b + and [ctrlstate], not 1 + jmp @b +.rshift_down: + or [ctrlstate], 2 + jmp .event +.rshift_up: + and [ctrlstate], not 2 + jmp .event +.alt_down: + test ah, ah + jnz .ralt_down + or [ctrlstate], 0x10 + jmp .event +.ralt_down: + or [ctrlstate], 0x20 + jmp .event +.alt_up: + test ah, ah + jnz .ralt_up + and [ctrlstate], not 0x10 + jmp .event +.ralt_up: + and [ctrlstate], not 0x20 + jmp .event +.exit: + popad + push eax + push 0 + push dword [esp+12+8] + call HideGenericBox + pop eax + pop [cursor_y] + pop [cursor_x] + pushad + call draw_image + popad + ret 8 + +; int __stdcall ShowGenericBox(DLGTEMPLATE* dlg, void* DlgProc); +ShowGenericBox: pushad mov ebx, [esp+20h+4] ; center window if required @@ -86,7 +214,7 @@ GenericBox: @@: ; allocate memory for data under dialog ; for 'No memory' dialog use static data area - mov ebp, nomem_dlgsavearea + mov eax, nomem_dlgsavearea cmp ebx, nomem_dlgdata jz .allocated mov eax, [ebx+dlgtemplate.width] @@ -99,7 +227,7 @@ GenericBox: add edx, [ebx+dlgtemplate.border_size_y] inc edx mul edx - lea ecx, [eax*2] + lea ecx, [eax*2+8] call xpgalloc test eax, eax jnz @f @@ -109,8 +237,11 @@ GenericBox: or eax, -1 ret 8 @@: - mov ebp, eax .allocated: + mov [ebx+dlgtemplate.dataptr], eax + pop dword [eax+4] + pop dword [eax] + lea ebp, [eax+8] ; save data mov eax, [ebx+dlgtemplate.y] add eax, [ebx+dlgtemplate.height] @@ -131,12 +262,13 @@ GenericBox: push eax call save_console_data ; draw shadow + test byte [ebx+dlgtemplate.flags], 4 + jnz .noshadow mov eax, [ebx+dlgtemplate.x] sub eax, [ebx+dlgtemplate.border_size_x] ja @f xor eax, eax @@: - push eax ; save real window left inc eax inc eax mov edx, [ebx+dlgtemplate.y] @@ -144,7 +276,6 @@ GenericBox: ja @f xor edx, edx @@: - push edx ; save real window top inc edx call get_console_ptr mov ecx, [ebx+dlgtemplate.y] @@ -185,9 +316,29 @@ GenericBox: add edi, [cur_width] dec edx jnz .shadow_loop +.noshadow: + popad + push dword [esp+8] + push dword [esp+8] + call DrawGenericBox + xor eax, eax + ret 8 + +; void __stdcall DrawGenericBox(DLGDATA* dlg, void* DlgProc) +DrawGenericBox: + pushad + mov ebx, [esp+24h] ; draw area background - pop edx - pop eax + mov eax, [ebx+dlgtemplate.x] + sub eax, [ebx+dlgtemplate.border_size_x] + ja @f + xor eax, eax +@@: + mov edx, [ebx+dlgtemplate.y] + sub edx, [ebx+dlgtemplate.border_size_y] + ja @f + xor edx, edx +@@: call get_console_ptr mov ecx, [ebx+dlgtemplate.x] add ecx, [ebx+dlgtemplate.width] @@ -302,117 +453,24 @@ GenericBox: dec edx jnz @b ; send redraw message - mov eax, [esp+28h+8] - push ebx ebp + mov eax, [esp+28h] push 0 push 0 push 1 push ebx call eax call draw_image - pop ebp ebx -; message loop -.event: - push 10 - pop eax - int 40h - dec eax - jz .redraw - dec eax - jz .key - jmp exit -.redraw: - push ebx ebp - call draw_window - pop ebp ebx - jmp .event -.key: - mov al, 2 - int 40h - shr eax, 8 - cmp al, 0xE0 - jnz @f - mov [bWasE0], 1 - jmp .event -@@: - xchg ah, [bWasE0] - cmp al, 0x1D - jz .ctrl_down - cmp al, 0x9D - jz .ctrl_up - cmp al, 0x2A - jz .lshift_down - cmp al, 0xAA - jz .lshift_up - cmp al, 0x36 - jz .rshift_down - cmp al, 0xB6 - jz .rshift_up - cmp al, 0x38 - jz .alt_down - cmp al, 0xB8 - jz .alt_up - mov ecx, [esp+28h+8] - push ebx ebp - push 0 - push eax - push 2 - push ebx - call ecx - pop ebp ebx - test eax, eax - jz .event - mov [esp+8+28], eax - jmp .exit -.ctrl_down: - test ah, ah - jnz .rctrl_down - or [ctrlstate], 4 - jmp .event -.rctrl_down: - or [ctrlstate], 8 - jmp .event -.ctrl_up: - test ah, ah - jnz .rctrl_up - and [ctrlstate], not 4 - jmp .event -.rctrl_up: - and [ctrlstate], not 8 - jmp .event -.lshift_down: - test ah, ah - jnz @f - or [ctrlstate], 1 -@@: jmp .event -.lshift_up: - test ah, ah - jnz @b - and [ctrlstate], not 1 - jmp @b -.rshift_down: - or [ctrlstate], 2 - jmp .event -.rshift_up: - and [ctrlstate], not 2 - jmp .event -.alt_down: - test ah, ah - jnz .ralt_down - or [ctrlstate], 0x10 - jmp .event -.ralt_down: - or [ctrlstate], 0x20 - jmp .event -.alt_up: - test ah, ah - jnz .ralt_up - and [ctrlstate], not 0x10 - jmp .event -.ralt_up: - and [ctrlstate], not 0x20 - jmp .event -.exit: + popad + ret 8 + +; void __stdcall HideGenericBox(DLGTEMPLATE* dlg, int bRedrawWindow); +HideGenericBox: +; void __stdcall HideDialogBox(DLGDATA* dlg, int bRedrawWindow); +HideDialogBox: + pushad + mov ebx, [esp+24h] + mov ebp, [ebx+dlgtemplate.dataptr] + add ebp, 8 ; restore data mov eax, [ebx+dlgtemplate.y] add eax, [ebx+dlgtemplate.height] @@ -433,16 +491,21 @@ GenericBox: push eax call restore_console_data call draw_keybar - cmp ebx, nomem_dlgdata - jz @f - mov ecx, ebp - call pgfree -@@: + lea ecx, [ebp-8] + push dword [ecx] + push dword [ecx+4] pop [ebx+dlgtemplate.y] pop [ebx+dlgtemplate.x] + cmp ebx, nomem_dlgdata + jz @f + call pgfree +@@: or [cursor_x], -1 or [cursor_y], -1 + cmp dword [esp+28h], 0 + jz @f call draw_image +@@: popad ret 8 @@ -555,13 +618,13 @@ menu: ; void* variants, const char* title, unsigned flags); menu_centered_in: pushad - mov ecx, 56 -; 36 bytes for dlgtemplate + additional: -; +36: dd cur_variant -; +40: dd num_variants -; +44: dd begin_variant -; +48: dd end_variant -; +52: dd cur_variant_idx + mov ecx, 60 +; 40 bytes for dlgtemplate + additional: +; +40: dd cur_variant +; +44: dd num_variants +; +48: dd begin_variant +; +52: dd end_variant +; +56: dd cur_variant_idx call xpgalloc test eax, eax jnz @f @@ -584,16 +647,16 @@ menu_centered_in: xor eax, eax xor ecx, ecx mov esi, [esp+20h+20] - mov [ebx+36], esi - and dword [ebx+52], 0 + mov [ebx+40], esi + and dword [ebx+56], 0 @@: cmp dword [esi+4], 0 jz .find_width mov esi, [esi+4] - inc dword [ebx+52] + inc dword [ebx+56] jmp @b .find_width: - mov [ebx+44], esi + mov [ebx+48], esi add esi, 8 push esi xor edx, edx @@ -628,7 +691,7 @@ menu_centered_in: sub eax, [ebx+dlgtemplate.border_size_x] mov [ebx+dlgtemplate.width], eax mov [ebx+dlgtemplate.height], ecx - mov [ebx+40], ecx + mov [ebx+44], ecx sub eax, [esp+20h+12] neg eax sar eax, 1 @@ -677,8 +740,8 @@ menu_centered_in: mov [ebx+dlgtemplate.y], 3 .small_height: mov ecx, [ebx+dlgtemplate.height] - mov eax, [ebx+36] - mov [ebx+44], eax + mov eax, [ebx+40] + mov [ebx+48], eax dec ecx jz .skip push ecx @@ -688,13 +751,13 @@ menu_centered_in: mov eax, [eax+4] loop @b @@: - mov [ebx+44], eax + mov [ebx+48], eax pop ecx .loop: mov eax, [eax] loop .loop .skip: - mov [ebx+48], eax + mov [ebx+52], eax mov eax, [esp+20h+24] mov [ebx+dlgtemplate.title], eax mov al, [menu_normal_color] @@ -723,25 +786,25 @@ MenuDlgProc: call .dodraw ret 16 .prev: - mov eax, [ebx+36] + mov eax, [ebx+40] cmp dword [eax+4], 0 jz .end call .line_prev .posret: - mov [ebx+36], eax + mov [ebx+40], eax .redraw: call .dodraw call draw_image xor eax, eax ret 16 .next: - mov eax, [ebx+36] + mov eax, [ebx+40] cmp dword [eax], 0 jz .home call .line_next jmp .posret .pgdn: - mov eax, [ebx+36] + mov eax, [ebx+40] mov ecx, [ebx+dlgtemplate.height] .pgdnl: cmp dword [eax], 0 @@ -775,7 +838,7 @@ MenuDlgProc: jz .ins cmp al, 0x53 jz .del - mov edx, [ebx+36] + mov edx, [ebx+40] @@: cmp dword [edx+4], 0 jz @f @@ -803,7 +866,7 @@ MenuDlgProc: xor eax, eax ret 16 .pgup: - mov eax, [ebx+36] + mov eax, [ebx+40] mov ecx, [ebx+dlgtemplate.height] .pgupl: cmp dword [eax+4], 0 @@ -812,14 +875,14 @@ MenuDlgProc: loop .pgupl jmp .posret .home: - mov eax, [ebx+36] + mov eax, [ebx+40] @@: cmp dword [eax+4], 0 jz @f mov eax, [eax+4] jmp @b @@: - mov [ebx+44], eax + mov [ebx+48], eax push eax mov ecx, [ebx+dlgtemplate.height] dec ecx @@ -828,19 +891,19 @@ MenuDlgProc: mov eax, [eax] loop .h2 .h1: - mov [ebx+48], eax + mov [ebx+52], eax pop eax - and dword [ebx+52], 0 + and dword [ebx+56], 0 jmp .posret .end: - mov eax, [ebx+36] + mov eax, [ebx+40] @@: cmp dword [eax], 0 jz @f mov eax, [eax] jmp @b @@: - mov [ebx+48], eax + mov [ebx+52], eax push eax mov ecx, [ebx+dlgtemplate.height] dec ecx @@ -849,17 +912,17 @@ MenuDlgProc: mov eax, [eax+4] loop .e2 .e1: - mov [ebx+44], eax - mov eax, [ebx+40] + mov [ebx+48], eax + mov eax, [ebx+44] dec eax - mov [ebx+52], eax + mov [ebx+56], eax pop eax jmp .posret .esc: or eax, -1 ret 16 .enter: - mov eax, [ebx+36] + mov eax, [ebx+40] ret 16 .ins: push 5 @@ -869,7 +932,7 @@ MenuDlgProc: push 4 pop edx @@: - mov eax, [ebx+36] + mov eax, [ebx+40] cmp byte [eax+8], '/' jnz @f cmp word [eax+9], 'cd' @@ -885,41 +948,41 @@ MenuDlgProc: ret 16 .line_prev: - cmp eax, [ebx+44] - jnz @f - mov edx, [ebx+44] - mov edx, [edx+4] - mov [ebx+44], edx - mov edx, [ebx+48] - mov edx, [edx+4] - mov [ebx+48], edx -@@: - mov eax, [eax+4] - dec dword [ebx+52] - ret -.line_next: cmp eax, [ebx+48] jnz @f - mov edx, [ebx+44] - mov edx, [edx] - mov [ebx+44], edx + mov edx, [ebx+48] + mov edx, [edx+4] + mov [ebx+48], edx + mov edx, [ebx+52] + mov edx, [edx+4] + mov [ebx+52], edx +@@: + mov eax, [eax+4] + dec dword [ebx+56] + ret +.line_next: + cmp eax, [ebx+52] + jnz @f mov edx, [ebx+48] mov edx, [edx] mov [ebx+48], edx + mov edx, [ebx+52] + mov edx, [edx] + mov [ebx+52], edx @@: mov eax, [eax] - inc dword [ebx+52] + inc dword [ebx+56] ret .dodraw: mov eax, [ebx+dlgtemplate.x] mov edx, [ebx+dlgtemplate.y] call get_console_ptr - mov esi, [ebx+44] + mov esi, [ebx+48] .0: xor edx, edx mov ah, [menu_selected_color] - cmp esi, [ebx+36] + cmp esi, [ebx+40] jz @f mov ah, [menu_normal_color] @@: @@ -947,7 +1010,7 @@ MenuDlgProc: mov ah, [menu_selected_highlight_color] push ecx mov ecx, [esp+8] - cmp ecx, [ebx+36] + cmp ecx, [ebx+40] pop ecx jz .amp1 mov ah, [menu_highlight_color] @@ -973,7 +1036,7 @@ MenuDlgProc: pop esi edi add edi, [cur_width] add edi, [cur_width] - cmp esi, [ebx+48] + cmp esi, [ebx+52] jz @f mov esi, [esi] test esi, esi @@ -981,13 +1044,13 @@ MenuDlgProc: @@: ; ‹Ё­Ґ©Є  Їа®ЄагвЄЁ mov ecx, [ebx+dlgtemplate.height] - cmp ecx, [ebx+40] + cmp ecx, [ebx+44] jz .noscrollbar sub ecx, 2 jbe .noscrollbar - mov eax, [ebx+52] + mov eax, [ebx+56] mul ecx - div dword [ebx+40] + div dword [ebx+44] push eax mov eax, [ebx+dlgtemplate.x] add eax, [ebx+dlgtemplate.width] @@ -1015,6 +1078,25 @@ MenuDlgProc: .noscrollbar: ret +get_ascii_char: +; query keyboard layout + pushad + mov al, [ctrlstate] + and al, 3 + xor ecx, ecx + cmp al, 1 + sbb ecx, -2 + push 26 + pop eax + push 2 + pop ebx + mov edx, layout + int 0x40 + popad +; translate scancode to ASCII + movzx eax, byte [layout+eax] + ret + virtual at 0 dlgitemtemplate: ; ќ«Ґ¬Ґ­вл: @@ -1060,6 +1142,20 @@ DialogBox: call GenericBox ret 4 +; int __stdcall ShowDialogBox(DLGDATA* dlg); +ShowDialogBox: + push ManagerDlgProc + push dword [esp+8] + call ShowGenericBox + ret 4 + +; void __stdcall DrawDialogBox(DLGDATA* dlg); +DrawDialogBox: + push ManagerDlgProc + push dword [esp+8] + call DrawGenericBox + ret 4 + ManagerDlgProc: mov ebp, ebx mov eax, [esp+8] @@ -1255,21 +1351,8 @@ ManagerDlgProc: .editor_char: test [ctrlstate], 0x3C jnz .ret_draw -; query keyboard layout - pushad - push 26 - pop eax - push 2 - pop ebx - xor ecx, ecx - cmp [ctrlstate], 1 - sbb ecx, -2 - mov edx, layout - int 0x40 - popad -; translate scancode to ASCII movzx eax, al - movzx eax, byte [layout+eax] + call get_ascii_char push eax ; insert entered symbol xor eax, eax @@ -1482,6 +1565,10 @@ SayErr: pop eax push aError push eax +; int __stdcall SayErrTitle(const char* title, +; int num_strings, const char* strings[], +; int num_buttons, const char* buttons[]); +SayErrTitle: push 2 jmp @f @@ -1571,6 +1658,7 @@ Message: stosd ; dlgtemplate.title xor eax, eax stosd ; (ignored) + stosd ; (ignored) stosd ; DlgProc stosd ; userdata mov eax, [esp+32+8] diff --git a/programs/fs/kfar/trunk/editor.inc b/programs/fs/kfar/trunk/editor.inc new file mode 100644 index 0000000000..b132b12587 --- /dev/null +++ b/programs/fs/kfar/trunk/editor.inc @@ -0,0 +1,2294 @@ +virtual at 0 +editor_data: + .hPlugin dd ? + .hFile dd ? +if (.hPlugin <> viewer_data.hPlugin) | (.hFile <> viewer_data.hFile) +error in viewer_IsHandleUsed/editor_IsHandleUsed +end if + .memsize dd ? + .encoding db ? + .flags db ? ; & 0x80: modified + ; & 0x40: file is locked + ; & 0x20: next key as a symbol + ; & 0x10: replace mode (vs insert) + .eol db ? + rb 1 + .first_block dd ? + .last_block dd ? + .numfree dd ? + .freeblocks dd ? + .numlines dd ? + .curline dd ? + .curcol dd ? + ;.curpos_block dd ? + ;.curpos_offs dd ? + .cur_block dd ? + .cur_offs dd ? + .cur_delta dd ? + .cursor_x dd ? + .cursor_y dd ? + align 200h + .filename rb 1024 + .hostname rb 1024 +if (.filename <> viewer_data.filename) | (.hostname <> viewer_data.hostname) +error in viewer_getname/editor_getname +end if + .buf rb 16384 ; all I/O operations use this buffer + .basesize = $ + .linedata_start: +end virtual + +virtual at 0 +editor_line: + .block dd ? + .offs dw ? + ;.length dd ? + .plugdata: +end virtual + +; when a file is loaded into the editor, this file is fragmented to blocks +; each block has RESERVE_IN_BLOCK empty bytes to allow quick inserting +; must be dword-aligned! +edit.RESERVE_IN_BLOCK = 16 +edit.eol_dos = 1 ; DOS/Win EOLn style (0D 0A) +edit.eol_unix = 2 ; Unix EOLn style (0A) +edit.eol_mac = 3 ; MacOS EOLn style (0D) + +virtual at 0 +edit_block_header: + .next dd ? + .prev dd ? + .limit dd ? + .size = $ ; must be dword-aligned +end virtual + +edit_file: + mov eax, [ebp + panel1_files - panel1_data] + mov ecx, [eax+ecx*4] + test byte [ecx], 10h + jz .file + ret +.file: +; calculate required memory size + cmp dword [ecx+36], 0 + jnz .nomemory +; block size = 4096 +; block header: edit_block_header.size bytes +; some plugin-specific data can follow +; reserve RESERVE_IN_BLOCK free bytes in the end of block + mov ebx, 4096 + mov eax, [EditPlugInfo] + add eax, edit_block_header.size + mov [EditBlockStart], eax + sub ebx, eax + sub ebx, edit.RESERVE_IN_BLOCK + mov [EditBlockSize], ebx +; now ebx = size of file data in each block + mov eax, [ecx+32] +; if eax == 0, set eax = 1 + sub eax, 1 + adc eax, 1 + xor edx, edx + div ebx + sub edx, 1 + sbb eax, -1 + add eax, [EditDataSize] +; eax = number of blocks + memory for editor_data structure + cmp eax, 0x80000000 shr 12 + jb .memok +.nomemory: + push aEditNoMemory + mov eax, esp + push ContinueBtn + push 1 + push eax + push 1 + call SayErr + pop eax + ret +.memok: + lea esi, [ebp + panel1_dir - panel1_data] + push eax + push ecx + mov ecx, eax + shl ecx, 12 + mov edx, editor_vtable + call new_screen + pop ecx + pop ebx + test eax, eax + jnz @f + ret +@@: + mov [ebp + editor_data.memsize], ebx + mov al, [EditEOLStyle] + mov [ebp + editor_data.eol], al + mov eax, [esi + panel1_hPlugin - panel1_data] + mov [ebp + editor_data.hPlugin], eax + test eax, eax + jz .nocopyhostname + lea edi, [ebp + editor_data.hostname] + push esi + mov eax, dword [esi + panel1_parents - panel1_dir] + mov esi, dword [esi + panel1_parents_sz - panel1_dir] + add esi, eax +@@: + dec esi + cmp byte [esi-1], 0 + jz @f + cmp byte [esi-1], '/' + jnz @b +@@: + lodsb + stosb + test al, al + jnz @b + pop esi +.nocopyhostname: + mov eax, dword [esi + panel1_hFile - panel1_dir] + mov [ebp + editor_data.hFile], eax + mov [ebp + editor_data.encoding], encodings.cp866 + xor eax, eax + mov [ebp + editor_data.flags], al + inc eax + mov [ebp + editor_data.numlines], eax + lea edi, [ebp + editor_data.filename] + mov ebx, readinfo + mov [ebx+21], edi +@@: + lodsb + test al, al + jz @f + stosb + jmp @b +@@: + lea esi, [ecx+40] + mov al, '/' + cmp byte [edi-1], al + jz @f + stosb +@@: + lodsb + stosb + test al, al + jnz @b +; load file into memory + mov esi, [ebp + editor_data.memsize] + mov edi, [EditDataSize] + sub esi, edi ; esi = number of blocks + shl edi, 12 + ;mov [ebp + editor_data.curpos_block], edi + mov [ebp + editor_data.first_block], edi + mov [ebp + editor_data.cur_block], edi + add edi, ebp ; edi -> first block + mov [ebp + editor_data.linedata_start + editor_line.block], edi + xor eax, eax + mov [ebx+4], eax + mov [ebx+8], eax + mov dword [ebx+12], 16384 + lea eax, [ebp + editor_data.buf] + mov [ebx+16], eax + mov edx, [ebp + editor_data.hPlugin] + test edx, edx + jz @f + pushad + push O_READ + push dword [ebx+21] + push [ebp + editor_data.hFile] + call [edx + PluginInfo.open] + popad + test eax, eax + jz ..openerr_in_screen + mov ebx, eax +@@: +.readloop: + mov edx, [ebp + editor_data.hPlugin] + test edx, edx + jz .readnative + pushad + push 16384 + push [readinfo.data] + push ebx + call [edx + PluginInfo.read] + popad + cmp eax, -1 + jnz .readok +; let us hope that plugin says error itself + push ebp + push ebx + call [edx + PluginInfo.close] + pop ebp + jmp .readfailed +.readnative: + push ebx + push 70 + pop eax + int 40h + mov edx, ebx + xchg eax, edx + pop ebx + add dword [ebx+4], eax + adc dword [ebx+8], 0 + test edx, edx + jz .readok + cmp edx, 6 + jz .readok + push dword [ebx+21] + push aCannotReadFile + xchg eax, edx + call get_error_msg + push eax + mov eax, esp + push RetryOrCancelBtn + push 2 + push eax + push 3 + call SayErr + add esp, 3*4 + test eax, eax + jz .readnative +.readfailed: + jmp delete_active_screen +.readok: +; eax = number of bytes read + test eax, eax + jnz @f + mov ecx, edi + sub ecx, ebp + cmp ecx, [ebp + editor_data.first_block] + jnz .readdone +@@: + push eax ebx + mov ebx, [ebx+16] +.loadloop: + mov ecx, [EditBlockSize] + cmp eax, ecx + ja @f + mov ecx, eax +@@: + sub eax, ecx + push eax + dec esi + jns .hasblock + push ecx + add [ebp + editor_data.memsize], 8 + add esi, 8 + mov ecx, [ebp + editor_data.memsize] + cmp ecx, 80000000h shr 12 + jb @f +.nomemory2: + pop ecx eax ebx eax + call .nomemory + jmp .readfailed +@@: + sub edi, ebp + shl ecx, 12 + mov edx, ebp + call xpgrealloc + test eax, eax + jz .nomemory2 + mov ebp, eax + add edi, eax + pop ecx +.hasblock: + lea eax, [edi + 0x1000] + push eax + sub eax, ebp + stosd ; edit_block_header.next + sub eax, 0x2000 + stosd ; edit_block_header.prev + mov eax, [EditBlockStart] + add eax, ecx + stosd ; edit_block_header.limit + push ecx + mov ecx, [EditPlugInfo] + inc ecx + jz @f + dec ecx +@@: + xor eax, eax + rep stosb ; info for plugins: zeroed + pop ecx + push esi edi ecx + mov esi, ebx + add ecx, 3 + shr ecx, 2 + rep movsd + mov ebx, esi + pop ecx edi +; calculate number of lines in this block + mov esi, edi + xor edx, edx + test ecx, ecx + jz .4 +.1: + lodsb + cmp al, 13 + jz @f + cmp al, 10 + jz @f + mov dl, 0 + jmp .3 +@@: + cmp al, dl + mov dl, 0 + jz .3 + inc [ebp + editor_data.numlines] + cmp al, 10 + jz .3 + mov dl, 10 +.3: + loop .1 +.4: + pop esi + pop edi + pop eax + test eax, eax + jnz .loadloop + pop ebx eax + cmp eax, 16384 + jz .readloop +.readdone: + xor eax, eax + mov ecx, edi + sub ecx, ebp + mov edx, ecx + shr ecx, 12 + sub ecx, [ebp + editor_data.memsize] + neg ecx + mov [ebp + editor_data.numfree], ecx + jz .nofree + mov [ebp + editor_data.freeblocks], edx + push edi +.addfree: + add edx, 1000h + mov [edi], edx + add edi, 1000h + loop .addfree + mov [edi-1000h], eax + pop edi +.nofree: + sub edi, 1000h + mov [edi + edit_block_header.next], eax + sub edi, ebp + mov [ebp + editor_data.last_block], edi + mov ecx, [EditDataSize] + shl ecx, 12 + mov [ecx + ebp + edit_block_header.prev], eax + mov [ebp + editor_data.curline], eax + mov [ebp + editor_data.curcol], eax + mov [ebp + editor_data.cursor_x], eax + inc eax + mov [ebp + editor_data.cursor_y], eax + mov eax, [EditBlockStart] + ;mov [ebp + editor_data.curpos_offs], eax + mov [ebp + editor_data.linedata_start + editor_line.offs], ax + mov [ebp + editor_data.cur_offs], eax + mov ecx, [ebp + editor_data.first_block] + cmp [ecx + edit_block_header.limit], eax + setz cl + movzx ecx, cl + dec ecx + mov [ebp + editor_data.cur_delta], ecx + call editor_init_lines +editor_OnRedraw: + mov eax, [ebp + editor_data.cursor_x] + mov [cursor_x], eax + mov eax, [ebp + editor_data.cursor_y] + mov [cursor_y], eax + test [ebp + editor_data.flags], 10h + jz @f + mov [cursor_size], cursor_big_size +@@: + call editor_test_cursor_x + call editor_test_cursor_y + call editor_set_keybar + call editor_draw_text + ret + +editor_save: + cmp [ebp + editor_data.hPlugin], 0 + jz .native + push aCannotSaveToPlugin + mov eax, esp + push ContinueBtn + push 1 + push eax + push 1 + call SayErr + pop eax + ret +.native: + call editor_calc_filesize + mov ebx, writeinfo + mov [ebx+4], eax + xor eax, eax + mov [ebx+8], eax + mov [ebx+12], eax + mov [ebx+16], eax + lea eax, [ebp + editor_data.filename] + mov [ebx+21], eax +.setsize_retry: + mov byte [ebx], 4 + push 70 + pop eax + push ebx + int 0x40 + pop ebx + mov byte [ebx], 3 + test eax, eax + jz .sizeok + push dword [ebx+21] + push aCannotWriteFile + call get_error_msg + push eax + mov eax, esp + push RetryOrCancelBtn + push 2 + push eax + push 3 + call SayErr + add esp, 12 + test eax, eax + jz .setsize_retry +.ret: + ret +.sizeok: + and dword [ebx+4], 0 + mov esi, [ebp + editor_data.first_block] + add esi, ebp + mov ebx, [EditBlockStart] + call editor_normalize_offs + jnc .writeok + lea edi, [ebp + editor_data.buf] +.loop: + mov ecx, 16384 + call editor_get_data + test eax, eax + jz .done + push ebx + mov ebx, writeinfo + mov [ebx+12], eax + mov [ebx+16], edi +.write_retry: + push 70 + pop eax + push ebx + int 0x40 + pop ebx + test eax, eax + jz .writeok + push dword [ebx+21] + push aCannotWriteFile + call get_error_msg + push eax + mov eax, esp + push RetryOrCancelBtn + push 2 + push eax + push 3 + call SayErr + add esp, 12 + test eax, eax + jz .write_retry + ret +.writeok: + mov eax, [ebx+12] + add [ebx+4], eax + adc dword [ebx+8], 0 + pop ebx + jmp .loop +.done: + and [ebp + editor_data.flags], not 0x80 + ret + +editor_calc_filesize: + xor eax, eax + push esi + mov esi, [ebp + editor_data.first_block] +@@: + add esi, ebp + add eax, [esi + edit_block_header.limit] + sub eax, [EditBlockStart] + mov esi, [esi + edit_block_header.next] + test esi, esi + jnz @b + pop ebx + ret + +editor_get_data: + push edi + test esi, esi + jz .ret +.loop: + mov edx, [esi + edit_block_header.limit] + sub edx, ebx + push ecx + cmp ecx, edx + jb @f + mov ecx, edx +@@: + push esi + add esi, ebx + add ebx, ecx + add eax, ecx + rep movsb + pop esi + pop ecx + sub ecx, edx + jb .ret + mov esi, [esi + edit_block_header.next] + mov ebx, [EditBlockStart] + test esi, esi + jz .ret + add esi, ebp + jmp .loop +.ret: + mov eax, edi + pop edi + sub eax, edi + ret + +editor_get_pos: + ;mov esi, [ebp + editor_data.curpos_block] + ;mov ebx, [ebp + editor_data.curpos_offs] + mov esi, [ebp + editor_data.linedata_start + editor_line.block] + sub esi, ebp + movzx ebx, [ebp + editor_data.linedata_start + editor_line.offs] +@@: + test esi, esi + jz @f + add esi, ebp + cmp ebx, [esi + edit_block_header.limit] + jb @f + mov esi, [esi + edit_block_header.next] + mov ebx, [EditBlockStart] + jmp @b +@@: + ret + +editor_curline_start: + mov edx, [EditPlugInfo] + add edx, editor_line.plugdata + mov eax, [ebp + editor_data.cursor_y] + dec eax + imul eax, edx + lea edi, [ebp + eax + editor_data.linedata_start] + mov esi, [edi + editor_line.block] + movzx ebx, [edi + editor_line.offs] + ret + +editor_step_forward: +; in: esi = block (must be nonzero), ebx = offset in block +; out: esi = block (zero iff EOF reached), ebx = offset in block +; out: CF=1 iff EOF NOT reached + inc ebx +editor_normalize_offs: + cmp ebx, [esi + edit_block_header.limit] + jb @f + mov esi, [esi + edit_block_header.next] + mov ebx, [EditBlockStart] + test esi, esi + jz @f + add esi, ebp + stc +@@: + ret + +editor_step_backward: +; in: esi = block (must be nonzero), ebx = offset in block +; out: esi = block (zero iff input was at the beginning), ebx = offset in block +; out: CF=1 iff start of file reached + dec ebx + cmp ebx, [EditBlockStart] + jae @f + mov esi, [esi + edit_block_header.prev] + test esi, esi + stc + jz @f + add esi, ebp + mov ebx, [esi + edit_block_header.limit] + dec ebx +@@: + ret + +editor_get_string: +; read string up to the end of line +; in: esi = block, ebx = offset in block +; in: edi = destination, ecx = maximum number of bytes to copy, edx = number of bytes to skip +; out: esi = block, ebx = offset in block +; out: ecx = number of rest bytes (ecx_in - ecx_out = number of copied characters) + mov ah, [edit_normal_color] + cmp ebx, [esi + edit_block_header.limit] + jz .retnp + push 0 ; current position in line +.loop: + test ecx, ecx + jz .ret + mov al, [esi + ebx] + cmp al, 13 + jz .ret + cmp al, 10 + jz .ret + cmp al, 9 + jz .tab + inc dword [esp] + dec edx + jns .4 + xor edx, edx + stosw + dec ecx +.4: + call editor_step_forward + jc .loop +.ret: + pop edx +.retnp: + ret +.tab: + push eax edx + mov eax, [esp+8] + xor edx, edx + div [editor_tabsize] + sub edx, [editor_tabsize] + neg edx + add [esp+8], edx + sub [esp], edx + pop edx eax + jns .4 + mov al, ' ' +@@: + stosw + dec ecx + jz .ret + inc edx + jnz @b + jmp .4 + +editor_find_newline: +; in: esi = block, ebx = offset in block +; out: esi = block, ebx = offset in block, ecx = line length + xor ecx, ecx + test esi, esi + jz .ret0 + cmp ebx, [esi + edit_block_header.limit] + jb .1 + xor esi, esi +.ret0: + ret +.1: + mov al, [esi + ebx] + inc ecx + call editor_step_forward + cmp al, 13 + jz .2 + cmp al, 10 + jz .2 + test esi, esi + jnz .1 +.ret1: + mov esi, [ebp + editor_data.last_block] + add esi, ebp + mov ebx, [esi + edit_block_header.limit] + ret +.2: + dec ecx + test esi, esi + jz .ret1 + cmp al, 13 + jnz .ret + cmp byte [esi + ebx], 10 + jnz .ret + call editor_step_forward + jnc .ret1 +.ret: + ret + +editor_prev_newline: + xor ecx, ecx + test esi, esi + jnz @f + mov esi, [ebp + editor_data.last_block] + add esi, ebp + mov ebx, [esi + edit_block_header.limit] +@@: + call editor_step_backward + jc .ret + mov al, [esi + ebx] + call editor_step_backward + jc .ret + cmp al, 10 + jnz .1 + cmp byte [esi + ebx], 13 + jnz .1 +@@: + call editor_step_backward + jc .ret +.1: + inc ecx + mov al, [esi + ebx] + cmp al, 13 + jz @f + cmp al, 10 + jnz @b +@@: + dec ecx + inc ebx + cmp ebx, [esi + edit_block_header.limit] + jb .ret + mov esi, [esi + edit_block_header.next] + mov ebx, [EditBlockStart] + test esi, esi + jz .ret + add esi, ebp +.ret: + test esi, esi + jnz @f + mov esi, [ebp + editor_data.first_block] + mov ebx, [EditBlockStart] + add esi, ebp +@@: + ret + +editor_init_lines: + call editor_get_pos + test esi, esi + jnz @f + mov esi, [ebp + editor_data.last_block] + add esi, ebp + mov ebx, [esi + edit_block_header.limit] +@@: + mov ecx, max_height + lea edi, [ebp + editor_data.linedata_start] +.1: + mov eax, esi + stosd ; editor_line.block + mov eax, ebx + stosw ; editor_line.offs + push ecx + call editor_find_newline + ;mov eax, ecx + ;stosd ; editor_line.length + xor eax, eax + mov ecx, [EditPlugInfo] + rep stosb + pop ecx + loop .1 + ret + +editor_draw_status: + lea edi, [ebp + editor_data.buf] + mov ah, [edit_status_color] + mov ecx, [cur_width] + sub ecx, 56 + cmp ecx, 25 + jge @f + push 25 + pop ecx +@@: + call viewedit_draw_filename + inc ecx + rep stosw + test [ebp + editor_data.flags], 80h + jz @f + mov al, '*' +@@: + stosw + mov al, ' ' + test [ebp + editor_data.flags], 40h + jz @f + mov al, '-' +@@: + stosw + mov al, ' ' + test [ebp + editor_data.flags], 20h + jz @f + mov al, '"' +@@: + stosw + mov al, ' ' + mov cl, 10 + rep stosw + movzx esi, [ebp+editor_data.encoding] + lea esi, [encodings.names+esi*8] + push edi esi + dec edi + dec edi + std + add esi, 8 +@@: + dec esi + cmp byte [esi], ' ' + jz @b +@@: + lodsb + stosw + cmp esi, [esp] + jae @b + cld + pop esi edi + mov esi, aLine + mov cl, 8 +@@: + lodsb + stosw + loop @b + mov cl, 13 + mov al, ' ' + rep stosw + std + push edi + dec edi + dec edi + push eax + mov eax, [ebp + editor_data.numlines] + mov cl, 10 +@@: + xor edx, edx + div ecx + xchg eax, edx + add al, '0' + mov ah, [edit_status_color] + stosw + xchg eax, edx + test eax, eax + jnz @b + mov al, '/' + mov ah, [edit_status_color] + stosw + mov eax, [ebp + editor_data.curline] + add eax, [ebp + editor_data.cursor_y] +@@: + xor edx, edx + div ecx + xchg eax, edx + add al, '0' + mov ah, [edit_status_color] + stosw + xchg eax, edx + test eax, eax + jnz @b + pop eax + stosw + cld + pop edi + mov ah, [edit_status_color] + mov esi, aCol + mov cl, 7 +@@: + lodsb + stosw + loop @b + mov eax, [ebp + editor_data.curcol] + add eax, [ebp + editor_data.cursor_x] + inc eax + mov cl, 10 + push -'0' +@@: + xor edx, edx + div ecx + push edx + test eax, eax + jnz @b +@@: + pop eax + mov ah, [edit_status_color] + add al, '0' + jz @f + stosw + jmp @b +@@: + mov al, ' ' + mov cl, 13 + rep stosw + xor eax, eax + xor edx, edx + call get_console_ptr + lea esi, [ebp + editor_data.buf] + mov ecx, [cur_width] + shr ecx, 1 + rep movsd + adc ecx, ecx + rep movsw + cmp [ebp + editor_data.cur_delta], -1 + jnz .a + mov al, ' ' + mov byte [edi-4*2], al + mov byte [edi-3*2], al + mov byte [edi-2*2], al + mov byte [edi-1*2], al + mov eax, [ebp + editor_data.cur_block] + add eax, ebp + add eax, [ebp + editor_data.cur_offs] + movzx eax, byte [eax] + mov cl, 100 + ;xor edx, edx ; edx=0 already + div ecx + test al, al + jz @f + add al, '0' + mov [edi-3*2], al +@@: + xchg eax, edx + aam + test ah, ah + jnz .b + cmp byte [edi-3*2], ' ' + jz @f +.b: + add ah, '0' + mov [edi-2*2], ah +@@: + add al, '0' + mov [edi-1*2], al +.a: + ret + +editor_draw_line: + push ecx + mov ecx, [cur_width] + test esi, esi + jz .2 + lea edi, [ebp + editor_data.buf] + push edx edi + mov edx, [ebp + editor_data.curcol] + call editor_get_string + mov al, ' ' + rep stosw + pop esi edx + xor eax, eax + call get_console_ptr + mov ecx, [cur_width] + shr ecx, 1 + rep movsd + adc ecx, ecx + rep movsw + pop ecx + ret +.2: + xor eax, eax + call get_console_ptr + mov al, ' ' + mov ah, [edit_normal_color] + rep stosw + pop ecx + ret + +editor_draw_text: + call editor_draw_status + push 1 + pop edx + lea ecx, [ebp + editor_data.linedata_start] +.1: + mov esi, [ecx + editor_line.block] + movzx ebx, [ecx + editor_line.offs] + add ecx, editor_line.plugdata + add ecx, [EditPlugInfo] + call editor_draw_line + inc edx + mov eax, [cur_height] + dec eax + cmp edx, eax + jb .1 + jmp draw_image + +editor_set_keybar: + mov eax, keybar_editor + movzx esi, [ebp+editor_data.encoding] + dec esi + jz @f + push 1 + pop esi +@@: + lea esi, [encodings.names+esi*8] + lea edi, [eax+keybar_cp2-keybar_editor] + movsd + movsw + jmp draw_keybar + +editor_up_scroll: + push ecx + sub [ebp + editor_data.curline], ecx + mov edx, [EditPlugInfo] + add edx, editor_line.plugdata + imul eax, edx, max_height + imul ecx, edx + sub ecx, eax + neg ecx + lea esi, [ebp + ecx + editor_data.linedata_start - 4] + lea edi, [ebp + eax + editor_data.linedata_start - 4] + shr ecx, 2 + std + rep movsd + cld + jnc @f + mov cx, [esi+2] + mov [edi+2], cx + sub edi, 2 +@@: + pop ecx + add edi, 4 + movzx ebx, [edi + editor_line.offs] + mov esi, [edi + editor_line.block] +@@: + push ecx + call editor_prev_newline + sub edi, edx + push edi + mov eax, esi + stosd ; editor_line.offs + mov eax, ebx + stosw ; editor_line.block + ;mov eax, ecx + ;stosd ; editor_line.length + mov ecx, [EditPlugInfo] + xor eax, eax + rep stosb + pop edi + pop ecx + loop @b +; fall through to editor_update_cur + +editor_update_cur: + mov ecx, [ebp + editor_data.cursor_x] + add ecx, [ebp + editor_data.curcol] + call editor_curline_start + xor edx, edx ; current position in the line + cmp ebx, [esi + edit_block_header.limit] + jz .notfound +.scan: + mov al, [esi+ebx] + cmp al, 13 + jz .notfound + cmp al, 10 + jz .notfound + test ecx, ecx + jz .found + cmp al, 9 + jz .tab + inc edx + dec ecx + call editor_step_forward + jc .scan +.notfound: + test esi, esi + jnz @f + mov esi, [ebp + editor_data.last_block] + add esi, ebp + mov ebx, [esi + edit_block_header.limit] +@@: + mov [ebp + editor_data.cur_delta], ecx + xor eax, eax + jmp .reta +.found: + xor eax, eax +.founda: + or [ebp + editor_data.cur_delta], -1 +.reta: + sub esi, ebp + mov [ebp + editor_data.cur_block], esi + mov [ebp + editor_data.cur_offs], ebx + ret +.tab: + push edx + mov eax, edx + xor edx, edx + div [editor_tabsize] + sub edx, [editor_tabsize] + neg edx + add [esp], edx + cmp ecx, edx + jb .curintab + sub ecx, edx + pop edx + call editor_step_forward + jnc .notfound + test ecx, ecx + jz .found + jmp .scan +.curintab: + sub [esp], edx + pop edx + cmp edx, [ebp + editor_data.curcol] + setc al + jae @f + mov [ebp + editor_data.curcol], edx +@@: + sub edx, [ebp + editor_data.curcol] + mov [ebp + editor_data.cursor_x], edx + mov [cursor_x], edx + jmp .founda + +editor_down_scroll: + push ecx + lea edi, [ebp + editor_data.linedata_start] + mov edx, [EditPlugInfo] + add edx, editor_line.plugdata + imul ecx, edx + lea esi, [edi + ecx] + imul eax, edx, max_height + sub eax, ecx + mov ecx, eax + shr ecx, 2 + rep movsd + adc ecx, ecx + rep movsw +@@: + mov esi, edi + sub esi, edx + movzx ebx, [esi + editor_line.offs] + mov esi, [esi + editor_line.block] + pop ecx + jecxz .ret +@@: + push ecx + call editor_find_newline + mov eax, esi + stosd ; editor_line.block + mov eax, ebx + stosw ; editor_line.offs + ;mov eax, ecx + ;stosd ; editor_line.length + mov ecx, [EditPlugInfo] + xor eax, eax + rep stosb + pop ecx + loop @b +.ret: + ret + +editor_end_scroll: + call editor_curline_start +; calculate visible length of the line (it differs from the real length if tabulations are present) + xor ecx, ecx + cmp ebx, [esi + edit_block_header.limit] + jz .calcdone +.calcloop: + mov al, [esi+ebx] + cmp al, 10 + jz .calcdone + cmp al, 13 + jz .calcdone + cmp al, 9 + jz .calctab + inc ecx +.calcnext: + call editor_step_forward + jc .calcloop + jmp .calcdone +.calctab: + mov eax, ecx + xor edx, edx + div [editor_tabsize] + sub edx, [editor_tabsize] + sub ecx, edx + jmp .calcnext +.calcdone: + test esi, esi + jnz @f + mov esi, [ebp + editor_data.last_block] + add esi, ebp + mov ebx, [esi + edit_block_header.limit] +@@: + sub esi, ebp + mov [ebp + editor_data.cur_block], esi + mov [ebp + editor_data.cur_offs], ebx + and [ebp + editor_data.cur_delta], 0 +; ecx = number of symbols in the line +; calculate new position of view range + mov eax, [ebp + editor_data.curcol] + cmp ecx, eax + jb .toleft + add eax, [cur_width] + cmp ecx, eax + jae .toright + sub ecx, [ebp + editor_data.curcol] + mov [ebp + editor_data.cursor_x], ecx + mov [cursor_x], ecx + ret +.toleft: + mov [ebp + editor_data.curcol], ecx + and [ebp + editor_data.cursor_x], 0 + and [cursor_x], 0 + stc + ret +.toright: + mov eax, [cur_width] + dec eax + sub ecx, eax + mov [ebp + editor_data.curcol], ecx + mov [ebp + editor_data.cursor_x], eax + mov [cursor_x], eax + stc + ret + +editor_move_linestart: +; in: esi = block, ebx = start offset, ecx = delta + lea edi, [ebp + editor_data.linedata_start] + mov edx, max_height +.0: + cmp [edi + editor_line.block], esi + jnz .1 + movzx eax, [edi + editor_line.offs] + cmp eax, ebx + ja .2 +; push eax +; add eax, [edi + editor_line.length] +; cmp eax, ebx +; jb @f +; add [edi + editor_line.length], ecx +;@@: +; pop eax + cmp eax, [esi + edit_block_header.limit] + jb .1 + push esi ebx + mov ebx, eax + jmp .3 +.2: + push esi ebx + mov ebx, eax + add ebx, ecx +.3: + cmp ebx, [esi + edit_block_header.limit] + jb .4 + cmp [esi + edit_block_header.next], 0 + jz .4 + sub ebx, [esi + edit_block_header.limit] + mov esi, [esi + edit_block_header.next] + add esi, ebp + add ebx, [EditBlockStart] + jmp .3 +.4: + mov [edi + editor_line.block], esi + mov [edi + editor_line.offs], bx + pop ebx esi +.1: + add edi, editor_line.plugdata + add edi, [EditPlugInfo] + dec edx + jnz .0 + ;lea edx, [ebp + editor_data.curpos_block] + ;call .5 + ;add edx, editor_data.cur_block - editor_data.curpos_block + lea edx, [ebp + editor_data.cur_block] +; call .5 +; ret +.5: + mov eax, [edx] + add eax, ebp + cmp eax, esi + jnz .6 + cmp [edx+4], ebx + jbe @f + add [edx+4], ecx +@@: + mov eax, [edx+4] + sub eax, [esi + edit_block_header.limit] + jb .6 + push ecx + mov ecx, [esi + edit_block_header.next] + add ecx, ebp + add eax, [EditBlockStart] + mov [edx], ecx + mov [edx+4], eax + pop ecx +.6: + ret + +editor_reserve_symbol: + push 1 + pop ecx + +editor_reserve_space: +; ‚бв ў«пҐв Їгб⮥ ¬Ґбв® ў­гвам 楯®зЄЁ Ў«®Є®ў +; in: ecx = number of symbols to add, esi = block, ebx = offset + mov eax, [esi + edit_block_header.limit] + add eax, ecx + cmp eax, 4096 + ja .add + mov [esi + edit_block_header.limit], eax + push esi ecx + sub eax, ecx + lea esi, [esi + eax - 1] + lea edi, [esi + ecx] + sub eax, ebx + mov ecx, eax + std + rep movsb + cld + pop ecx esi + call editor_move_linestart + clc + ret +.add: + push ecx + mov eax, [esi + edit_block_header.limit] + sub eax, [EditBlockStart] + add eax, ecx + push eax + xor edx, edx + div [EditBlockSize] + push eax + sub eax, [ebp + editor_data.numfree] + jbe .norealloc + mov edx, [ebp + editor_data.memsize] + push eax edx + add eax, edx + mov ecx, eax + shl ecx, 12 + mov edx, ebp + call xpgrealloc + pop edx ecx + test eax, eax + jz .nomem + add [ebp + editor_data.memsize], ecx + sub eax, ebp + add ebp, eax + add esi, eax + push ecx + mov ecx, max_height + lea edi, [ebp + editor_data.linedata_start] +@@: + add [edi + editor_line.block], eax + add edi, editor_line.plugdata + add edi, [EditPlugInfo] + loop @b + pop ecx + shl edx, 12 + add [ebp + editor_data.numfree], ecx + lea edi, [edx + ebp] + mov eax, [ebp + editor_data.freeblocks] + mov [ebp + editor_data.freeblocks], edx +@@: + add edx, 1000h + mov [edi], edx + add edi, 1000h + loop @b + mov [edi-1000h], eax +.norealloc: + pop edx + push [esi + edit_block_header.next] + push esi + sub [ebp + editor_data.numfree], edx + mov edi, [ebp + editor_data.freeblocks] +@@: + mov [esi + edit_block_header.next], edi + add edi, ebp + push edi + push dword [edi] + stosd ; edit_block_header.next - will be filled later + mov eax, esi + sub eax, ebp + stosd ; edit_block_header.prev + mov eax, 4096 - edit.RESERVE_IN_BLOCK + stosd ; edit_block_header.limit + mov eax, [EditBlockSize] + sub [esp+16], eax + xor eax, eax + mov ecx, [EditPlugInfo] + rep stosb + pop edi + pop esi + dec edx + jnz @b + mov [ebp + editor_data.freeblocks], edi + mov edi, esi + pop esi + pop [edi + edit_block_header.next] + pop ecx + add ecx, [EditBlockSize] + mov edx, ecx + shr edx, 1;2 + mov eax, ecx + sub eax, edx + cmp eax, [EditBlockSize] + jb @f + mov eax, [EditBlockSize] + mov edx, ecx + sub edx, eax +@@: + add eax, [EditBlockStart] + add edx, [EditBlockStart] + mov ecx, [esi + edit_block_header.limit] + mov [esi + edit_block_header.limit], eax + mov [edi + edit_block_header.limit], edx + sub ecx, ebx + push ecx + push esi edi ecx + add esi, ecx + add esi, ebx + push edx + sub edx, [EditBlockStart] + cmp ecx, edx + jb @f + mov ecx, edx +@@: + pop edx + sub [esp], ecx + add edi, edx + sub esi, ecx + sub edi, ecx + rep movsb + pop ecx edi esi + push esi edi + lea edi, [esi + eax - 1] + add esi, ebx + lea esi, [esi + ecx - 1] + std + rep movsb + cld + pop edi esi + pop ecx + mov ecx, ebx + sub ecx, eax + jb @f + push esi edi + add esi, eax + add edi, [EditBlockStart] + rep movsb + pop edi esi +@@: + push esi edi + sub esi, ebp + sub edi, ebp + cmp [ebp + editor_data.last_block], esi + jnz @f + mov [ebp + editor_data.last_block], edi +@@: + pop edi esi + pop ecx + call editor_move_linestart + cmp ebx, [esi + edit_block_header.limit] + jb @f + sub ebx, [esi + edit_block_header.limit] + mov esi, [esi + edit_block_header.next] + add esi, ebp + add ebx, [EditBlockStart] +@@: + clc + ret +.nomem: + pop eax + pop ecx + pop ecx + add esi, ebp + stc + ret + +editor_delete_symbol: + push 1 + pop ecx + +editor_delete_space: +; “¤ «пҐв ecx Ў ©в Ё§ ⥪бв , ­ зЁ­ п б esi:ebx +; ecx, esi, ebx а §аги овбп + mov eax, [esi + edit_block_header.limit] + sub eax, ebx + cmp eax, ecx + jb .more1 + push esi + sub [esi + edit_block_header.limit], ecx + sub eax, ecx + lea edi, [esi+ebx] + lea esi, [edi+ecx] + mov ecx, eax + rep movsb + pop esi +.done: + call .collapse_prev + call .collapse_next + call editor_init_lines + jmp editor_update_cur +.more1: + mov [esi + edit_block_header.limit], ebx + sub ecx, eax +@@: + mov esi, [esi + edit_block_header.next] + add esi, ebp + mov eax, [esi + edit_block_header.limit] + sub eax, [EditBlockStart] + sub ecx, eax + jb @f + call .delete_block + jmp @b +@@: + add ecx, eax + push esi + mov eax, [esi + edit_block_header.limit] + sub [esi + edit_block_header.limit], ecx + add eax, esi + add esi, [EditBlockStart] + mov edi, esi + add esi, ecx + sub eax, esi + mov ecx, esi + rep movsb + pop esi + call .collapse_next + mov esi, [esi + edit_block_header.prev] + add esi, ebp + jmp .done + +.delete_block: + mov eax, [esi + edit_block_header.next] + mov edx, [esi + edit_block_header.prev] + test eax, eax + jz .dbfirst + mov [eax + ebp + edit_block_header.prev], edx + jmp @f +.dbfirst: + mov [ebp + editor_data.first_block], edx +@@: + test edx, edx + jz .dblast + mov [edx + ebp + edit_block_header.next], eax + jmp @f +.dblast: + mov [ebp + editor_data.last_block], eax +@@: + mov eax, [ebp + editor_data.freeblocks] + mov [esi], eax + sub esi, ebp + mov [ebp + editor_data.freeblocks], esi + inc [ebp + editor_data.numfree] + ret + +.collapse_prev: + mov eax, [esi + edit_block_header.prev] + test eax, eax + jz .cpno + add eax, ebp + mov edx, [esi + edit_block_header.limit] + sub edx, [EditBlockStart] + add edx, [eax + edit_block_header.limit] + cmp edx, 4096 - edit.RESERVE_IN_BLOCK + ja .cpno + mov edi, eax +.collapse: ; (edi) + (esi) -> (edi) + push edi + push esi + mov ecx, [esi + edit_block_header.limit] + sub ecx, [EditBlockStart] + add esi, [EditBlockStart] + mov eax, [edi + edit_block_header.limit] + add [edi + edit_block_header.limit], ecx + add edi, eax + rep movsb + pop esi + call .delete_block + pop esi +.cpno: + ret +.collapse_next: + mov eax, [esi + edit_block_header.next] + test eax, eax + jz .cpno + add eax, ebp + mov edx, [esi + edit_block_header.limit] + sub edx, [EditBlockStart] + add edx, [eax + edit_block_header.limit] + cmp edx, 4096 - edit.RESERVE_IN_BLOCK + ja .cpno + mov edi, esi + mov esi, eax + jmp .collapse + +editor_OnKey: + test al, 80h + jnz .ret + test [ebp + editor_data.flags], 20h + jnz .symbol + mov esi, editor_ctrlkeys + call process_ctrl_keys + jnc .ret +.symbol: + and [ebp + editor_data.flags], not 20h + test [ebp + editor_data.flags], 40h + jnz .ret + or [ebp + editor_data.flags], 80h + movzx eax, al + call get_ascii_char + mov esi, [ebp + editor_data.cur_block] + add esi, ebp + mov ebx, [ebp + editor_data.cur_offs] + cmp al, 10 + jz .insert_newline + cmp al, 13 + jz .insert_newline + cmp [ebp + editor_data.cur_delta], -1 + jnz .insert_after_eol + test [ebp + editor_data.flags], 10h + jnz .replace_symbol + push eax + call editor_reserve_symbol + pop eax + jc .ret +.replace_symbol: + cmp ebx, [esi + edit_block_header.limit] + jnz @f + mov esi, [esi + edit_block_header.next] + add esi, ebp + mov ebx, [EditBlockStart] +@@: + mov [esi + ebx], al +.symb_inserted: + call .redraw_curline + jmp .right +.redraw_curline: + call editor_curline_start + mov edx, [cursor_y] + call editor_draw_line +.ret: + ret +.insert_after_eol: + mov ecx, [ebp + editor_data.cur_delta] + inc ecx + push eax + call editor_reserve_space + pop eax + jc .ret + push eax + mov edx, ecx +.2: + mov ecx, [esi + edit_block_header.limit] + sub ecx, ebx + lea edi, [esi + ebx] + cmp ecx, edx + jb @f + mov ecx, edx +@@: + add ebx, ecx + sub edx, ecx + mov al, ' ' + rep stosb + jz @f + mov esi, [esi + edit_block_header.next] + add esi, ebp + mov ebx, [EditBlockStart] + jmp .2 +@@: + pop eax + mov [edi-1], al + dec ebx + sub esi, ebp + mov [ebp + editor_data.cur_block], esi + mov [ebp + editor_data.cur_offs], ebx + or [ebp + editor_data.cur_delta], -1 + jmp .symb_inserted +.insert_newline: + push 1 + pop ecx + cmp [ebp + editor_data.eol], 2 + adc ecx, 0 + call editor_reserve_space + jc .ret +; Џа®бв® в Є ўбв ў«пвм бЁ¬ў®« ­®ў®© бва®ЄЁ зॢ в® - Ё§-§  бгйҐбвў®ў ­Ёп ¤ўгеЎ ©в®ўле Є®¬ЎЁ­ жЁ© ЇҐаҐў®¤  бва®ЄЁ +; бв ал© бЁ¬ў®« ¬®¦Ґв б«Ёвмбп б ­®ўл¬. ‚ в Є®¬ б«гз Ґ ЇаЁ¤свбп § ­Ё¬ вмбп Є®а४вЁа®ўЄ®©. +; Џа®Ў«Ґ¬  Ўлў Ґв ў ¤ўге б«гз пе: +; Ґб«Ё । Єв®а ­ бв஥­ ­  Unix-бвЁ«м Ё ­®ўл© ЇҐаҐў®¤ бва®ЄЁ ўбв ў«пҐвбп ­ҐЇ®б।б⢥­­® Ї®б«Ґ +; ЇҐаҐў®¤  бва®ЄЁ ў Mac-бвЁ«Ґ; +; Ґб«Ё । Єв®а ­ бв஥­ ­  Mac-бвЁ«м Ё ­®ўл© ЇҐаҐў®¤ бва®ЄЁ ўбв ў«пҐвбп ­ҐЇ®б।б⢥­­® ЇҐаҐ¤ +; ЇҐаҐў®¤®¬ бва®ЄЁ ў Unix-бвЁ«Ґ. +; ‚ нвЁе б«гз пе д®абЁа㥬 ЇҐаҐў®¤ бва®ЄЁ ў ⥪г饬 бвЁ«Ґ д ©« . + mov al, [ebp + editor_data.eol] + cmp al, edit.eol_dos + jz .insert_eol_dos + cmp al, edit.eol_mac + jz .insert_eol_mac + mov al, 10 ; Unix-style for end-of-line + push esi ebx + call editor_step_backward + jc @f + cmp byte [esi+ebx], 13 + jnz @f + mov al, 13 ; force Mac-style to avoid collapse +@@: + pop ebx esi + mov [esi+ebx], al + jmp .eol_correct +.insert_eol_mac: + mov al, 13 ; Mac-style for end-of-line + push esi ebx + call editor_step_forward + jnc @f + cmp byte [esi+ebx], 10 + jnz @f + mov al, 10 ; force Unix-style to avoid collapse +@@: + pop ebx esi + mov [esi+ebx], al + jmp .eol_correct +.insert_eol_dos: + mov byte [esi+ebx], 13 + call editor_step_forward + mov byte [esi+ebx], 10 +.eol_correct: + call editor_step_forward + test esi, esi + jnz @f + mov esi, [ebp + editor_data.last_block] + add esi, ebp + mov ebx, [esi + edit_block_header.limit] +@@: + and [ebp + editor_data.cur_delta], 0 + cmp ebx, [esi + edit_block_header.limit] + jz @f + mov al, [esi+ebx] + cmp al, 10 + jz @f + cmp al, 13 + jz @f + dec [ebp + editor_data.cur_delta] +@@: +; ­г зв® ¦Ґ, ў ⥪бв ­г¦­лҐ бЁ¬ў®«л ўбв ўЁ«Ё, ⥯Ґам ­ ¤® бЄ®а४вЁа®ў вм Ё­д®а¬ жЁо ® ­ з «Ґ бва®Є ­  нЄа ­Ґ + mov edi, [ebp + editor_data.cursor_y] + mov ecx, max_height-1 + sub ecx, edi + dec edi + mov eax, [EditPlugInfo] + add eax, editor_line.plugdata + imul edi, eax, max_height + imul ecx, eax + lea edi, [ebp + edi + editor_data.linedata_start - 2] + push esi + mov esi, edi + sub esi, eax + shr ecx, 1 + std + rep movsw + cld + pop esi + add edi, 2 + sub edi, eax + push esi + mov esi, edi + sub esi, eax + pop eax + stosd ; editor_line.block + sub eax, ebp + mov [ebp + editor_data.cur_block], eax + mov eax, ebx + stosw ; editor_line.offs + mov [ebp + editor_data.cur_offs], eax + ;mov eax, ecx + ;stosd ; editor_line.length + mov ecx, [EditPlugInfo] + xor eax, eax + rep stosb +; ­  ®¤­г бва®Єг бв «® Ў®«миҐ + inc [ebp + editor_data.numlines] +; Єгаб®а ®Є ¦Ґвбп ў ­ з «Ґ бва®ЄЁ + mov [ebp + editor_data.cursor_x], eax + mov [ebp + editor_data.curcol], eax + mov [cursor_x], eax +; Ё ЇҐаҐ¤ўЁ­Ґвбп ­  бва®Єг ­Ё¦Ґ + mov eax, [ebp + editor_data.cursor_y] + inc eax + mov edx, [cur_height] + dec edx + cmp eax, edx + jae .down_scroll + mov [ebp + editor_data.cursor_y], eax + mov [cursor_y], eax + jmp editor_draw_text + +.exit_confirm: + test [ebp + editor_data.flags], 80h + jz .exit + push aFileModified + mov eax, esp + push EditorExitBtn + push 3 + push eax + push 1 + push aEditorTitle + call SayErrTitle + pop ecx + test eax, eax + jz .save + dec eax + jz .exit + ret +.exit_save: + test [ebp + editor_data.flags], 80h + jz .exit +.save: + call editor_save +.exit: + call editor_OnExit + jmp delete_active_screen +.f2: + call editor_save + jmp .redraw_status + +.up_scroll: + cmp [ebp + editor_data.curline], 0 + jz .ret + push 1 + pop ecx + call editor_up_scroll + jmp editor_draw_text +.up: + mov eax, [ebp + editor_data.cursor_y] + dec eax + jz .up_scroll +.set_cursor_y: + mov [ebp + editor_data.cursor_y], eax + mov [cursor_y], eax + call editor_update_cur + test al, al + jnz editor_draw_text +.redraw_status: + call editor_draw_status + jmp draw_image +.down: + mov eax, [ebp + editor_data.cursor_y] + inc eax + push eax + add eax, [ebp + editor_data.curline] + cmp eax, [ebp + editor_data.numlines] + pop eax + ja .ret + mov edx, [cur_height] + dec edx + cmp eax, edx + jnz .set_cursor_y +.down_scroll: + inc [ebp + editor_data.curline] + lea edi, [ebp + editor_data.linedata_start] + mov eax, [EditPlugInfo] + add eax, editor_line.plugdata + lea esi, [edi + eax] + imul ecx, eax, max_height-1 + shr ecx, 2 + rep movsd + adc ecx, ecx + rep movsw + sub esi, eax + sub esi, eax + movzx ebx, [esi + editor_line.offs] + mov esi, [esi + editor_line.block] + call editor_find_newline + mov eax, esi + stosd ; editor_line.block + mov eax, ebx + stosw ; editor_line.offs + ;mov eax, ecx + ;stosd ; editor_line.length + mov ecx, [EditPlugInfo] + xor eax, eax + rep stosb + jmp .ret2 + +.pgup: + mov ecx, [cur_height] + sub ecx, 3 + mov edx, [ebp + editor_data.curline] + mov eax, edx + push edx + sub edx, ecx + jnc @f + xor edx, edx +@@: + mov [ebp + editor_data.curline], edx + add eax, [ebp + editor_data.cursor_y] + dec eax + sub eax, ecx + jnc @f + xor eax, eax +@@: + sub eax, edx + inc eax + mov [ebp + editor_data.cursor_y], eax + mov [cursor_y], eax + pop ecx + sub ecx, edx + push ecx + mov edx, [EditPlugInfo] + add edx, editor_line.plugdata + imul ecx, edx + imul eax, edx, max_height + lea edi, [ebp + editor_data.linedata_start + eax - 2] + mov esi, edi + sub esi, ecx + sub eax, ecx + mov ecx, eax + shr ecx, 1 + std + rep movsw + cld + pop ecx + jecxz .ret2 + inc edi + inc edi + mov esi, [edi + editor_line.block] + movzx ebx, [edi + editor_line.offs] +@@: + push ecx + call editor_prev_newline + sub edi, edx + push edi + mov eax, esi + stosd ; editor_line.block + mov eax, ebx + stosw ; editor_line.offs + ;mov eax, ecx + ;stosd ; editor_line.length + mov ecx, [EditPlugInfo] + xor eax, eax + rep stosb + pop edi + pop ecx + loop @b +.ret2: + call editor_update_cur + jmp editor_draw_text +.pgdn: + mov edx, [cur_height] + sub edx, 2 + mov ecx, [ebp + editor_data.curline] + push ecx + lea ecx, [edx + ecx - 1] + mov eax, [ebp + editor_data.numlines] + sub eax, edx + jnc @f + xor eax, eax +@@: + cmp ecx, eax + jb @f + mov ecx, eax +@@: + mov [ebp + editor_data.curline], ecx + pop eax + push eax + add eax, [ebp + editor_data.cursor_y] + lea eax, [eax + edx - 1] + cmp eax, [ebp + editor_data.numlines] + jb @f + mov eax, [ebp + editor_data.numlines] +@@: + sub eax, ecx + mov [ebp + editor_data.cursor_y], eax + mov [cursor_y], eax + pop edx + sub ecx, edx + call editor_down_scroll + jmp .ret2 + +.left: + call editor_cursor_left + jc .redraw_status + jmp editor_draw_text +.ret3: + ret + +.right: + cmp [ebp + editor_data.cur_delta], -1 + jz .right_in_text + cmp [ebp + editor_data.curcol], 0x80000000 - 0x1000 + jae .ret3 + inc [ebp + editor_data.cur_delta] + push 1 + pop edx + jmp .right_char +.right_in_text: + mov esi, [ebp + editor_data.cur_block] + add esi, ebp + mov ebx, [ebp + editor_data.cur_offs] + mov al, [esi + ebx] + push eax + call editor_step_forward + test esi, esi + jz .right_eol0 + mov al, [esi + ebx] + cmp al, 10 + jz .right_eol + cmp al, 13 + jz .right_eol + jmp .right_ok +.right_eol0: + mov esi, [ebp + editor_data.last_block] + add esi, ebp + mov ebx, [esi + edit_block_header.limit] +.right_eol: + inc [ebp + editor_data.cur_delta] +.right_ok: + sub esi, ebp + mov [ebp + editor_data.cur_block], esi + mov [ebp + editor_data.cur_offs], ebx + pop eax + push 1 + pop edx + cmp al, 9 + jnz .right_char + mov eax, [ebp + editor_data.curcol] + add eax, [ebp + editor_data.cursor_x] + xor edx, edx + div [editor_tabsize] + sub edx, [editor_tabsize] + neg edx +.right_char: + mov eax, [ebp + editor_data.cursor_x] + add eax, edx + cmp eax, [cur_width] + jb .set_cursor_x + add eax, [ebp + editor_data.curcol] + mov edx, [cur_width] + dec edx + sub eax, edx + mov [ebp + editor_data.cursor_x], edx + mov [cursor_x], edx + mov [ebp + editor_data.curcol], eax + jmp editor_draw_text +.set_cursor_x: + mov [ebp + editor_data.cursor_x], eax + mov [cursor_x], eax + jmp .redraw_status + +.home: + call editor_curline_start + and [ebp + editor_data.cur_delta], 0 + cmp ebx, [esi + edit_block_header.limit] + jz @f + mov al, [esi+ebx] + cmp al, 10 + jz @f + cmp al, 13 + jz @f + dec [ebp + editor_data.cur_delta] +@@: + sub esi, ebp + mov [ebp + editor_data.cur_block], esi + mov [ebp + editor_data.cur_offs], ebx + xor eax, eax + mov [ebp + editor_data.cursor_x], eax + mov [cursor_x], eax + xchg eax, [ebp + editor_data.curcol] + test eax, eax + jnz editor_draw_text + jmp .redraw_status + +.end: + call editor_end_scroll + jc editor_draw_text + jmp .redraw_status + +.ins: + xor [ebp + editor_data.flags], 10h + mov eax, cursor_normal_size + test [ebp + editor_data.flags], 10h + jz @f + mov eax, cursor_big_size +@@: + mov [cursor_size], eax + jmp draw_image + +.backspace: + cmp [ebp + editor_data.cur_delta], -1 + jz @f + cmp [ebp + editor_data.cur_delta], 0 + jnz .left +@@: + test [ebp + editor_data.flags], 40h + jnz .ret3 + mov esi, [ebp + editor_data.cur_block] + add esi, ebp + mov ebx, [ebp + editor_data.cur_offs] + call editor_step_backward + jc .ret3 + push esi ebx + call editor_cursor_left + pop ebx esi + setc al + push eax + push esi ebx + cmp byte [esi+ebx], 10 + jnz @f + call editor_step_backward + jc @f + cmp byte [esi+ebx], 13 + jnz @f + pop eax eax + jmp .del_char +@@: + pop ebx esi + jmp .del_char +.del: + test [ebp + editor_data.flags], 40h + jnz .ret3 + mov esi, [ebp + editor_data.cur_block] + add esi, ebp + mov ebx, [ebp + editor_data.cur_offs] + call editor_normalize_offs + jnc .ret3 + push 0 +.del_char: + or [ebp + editor_data.flags], 80h + mov al, [esi+ebx] + push 1 + pop ecx + push eax + push esi ebx + cmp al, 13 + jnz @f + call editor_step_forward + jnc @f + cmp byte [esi+ebx], 10 + jnz @f + inc ecx +@@: + pop ebx esi + call editor_delete_space + pop eax + cmp al, 13 + jz @f + cmp al, 10 + jz @f + pop eax + test al, al + jnz .del1 + call .redraw_curline + jmp .redraw_status +@@: + pop eax + dec [ebp + editor_data.numlines] + call editor_test_cursor_y +.del1: + jmp editor_draw_text + +editor_cursor_left: + cmp [ebp + editor_data.cur_delta], -1 + jz .in_text + dec [ebp + editor_data.cur_delta] + cmp [ebp + editor_data.cur_delta], -1 + jnz .left_cursor +.in_text: + mov esi, [ebp + editor_data.cur_block] + add esi, ebp + mov ebx, [ebp + editor_data.cur_offs] + call editor_step_backward + jc .ret_clc + mov al, [esi + ebx] + cmp al, 13 + jz .eol + cmp al, 10 + jz .eol2 + cmp al, 9 + jz .tab + sub esi, ebp + mov [ebp + editor_data.cur_block], esi + mov [ebp + editor_data.cur_offs], ebx +.left_cursor: + mov eax, [ebp + editor_data.cursor_x] + test eax, eax + jz @f + dec eax +.set_cursor_x: + mov [ebp + editor_data.cursor_x], eax + mov [cursor_x], eax +.ret_clc: + clc + ret +@@: + dec [ebp + editor_data.curcol] + jmp .ret_stc +.tab: + mov eax, [ebp + editor_data.cursor_x] + test eax, eax + jz @f + dec eax + mov [ebp + editor_data.cursor_x], eax + mov [cursor_x], eax + call editor_update_cur + test al, al + jz .ret_clc +.ret_stc: + stc + ret +@@: + dec [ebp + editor_data.curcol] + call editor_update_cur + jmp .ret_stc +.eol2: + push esi ebx + call editor_step_backward + jc @f + cmp byte [esi + ebx], 13 + jnz @f + pop eax eax + push esi ebx +@@: + pop ebx esi +.eol: + mov eax, [ebp + editor_data.cursor_y] + dec eax + jz .scroll_left_toup + push 0 ; no full redraw + mov [ebp + editor_data.cursor_y], eax + mov [cursor_y], eax + jmp .scroll_left_toend +.scroll_left_toup: + push 1 + pop ecx + call editor_up_scroll + push 1 ; full redraw required +.scroll_left_toend: + call editor_end_scroll + pop eax + adc al, 0 + jnz .ret_stc + jmp .ret_clc + +editor_test_cursor_x: + mov ecx, [cur_width] + dec ecx + mov eax, [ebp + editor_data.cursor_x] + sub eax, ecx + jbe @f + add [ebp + editor_data.curcol], eax + mov [ebp + editor_data.cursor_x], ecx + mov [cursor_x], ecx +@@: + ret + +editor_test_cursor_y: + mov ecx, [ebp + editor_data.cursor_y] + mov edx, [cur_height] + dec edx + dec edx + sub ecx, edx + ja .scroll_down + mov ecx, [ebp + editor_data.curline] + add ecx, edx + sub ecx, [ebp + editor_data.numlines] + ja .scroll_up +.clc_ret: + clc + ret +.scroll_down: + add [ebp + editor_data.curline], ecx + sub [ebp + editor_data.cursor_y], ecx + sub [cursor_y], ecx + call editor_down_scroll + stc + ret +.scroll_up: + cmp ecx, [ebp + editor_data.curline] + jb @f + mov ecx, [ebp + editor_data.curline] +@@: + jecxz .clc_ret + add [ebp + editor_data.cursor_y], ecx + add [cursor_y], ecx + call editor_up_scroll + stc + ret + +editor_OnExit: + mov edx, [ebp+editor_data.hPlugin] + test edx, edx + jz @f + mov ebx, [ebp+editor_data.hFile] + call close_handle_if_unused +@@: + ret diff --git a/programs/fs/kfar/trunk/kfar.asm b/programs/fs/kfar/trunk/kfar.asm index 9e3b16d4d6..5c573051a5 100644 --- a/programs/fs/kfar/trunk/kfar.asm +++ b/programs/fs/kfar/trunk/kfar.asm @@ -7,8 +7,13 @@ memsize dd mem dd stacktop dd 0, app_path -version equ '0.42' -version_dword equ 0*10000h + 42 +version equ '0.5' +version_dword equ 0*10000h + 50 + +min_width = 54 +max_width = 255 +min_height = 8 +max_height = 255 include 'lang.inc' include 'font.inc' @@ -16,9 +21,13 @@ include 'sort.inc' include 'kglobals.inc' include 'dialogs.inc' include 'viewer.inc' +include 'editor.inc' include 'tools.inc' include 'filetool.inc' +cursor_normal_size = (font_height*15+50)/100 +cursor_big_size = font_height + start: mov edi, tolower_table push 'A' @@ -82,9 +91,9 @@ start: mov [panel2_files], eax test eax, eax jz exit - cmp [panel1_files], 0 - jz exit xor eax, eax + cmp [panel1_files], eax + jz exit mov [panel1_hPlugin], eax mov [panel1_parents], eax mov [panel1_parents_sz], eax @@ -154,6 +163,24 @@ start: ja @f mov [panel2_colmode], eax @@: + push nullstr + push 512 + push saved_file_name + push aEolStyle + push aEditor + push app_path + call [ini.get_str] + mov cl, edit.eol_dos + mov al, [saved_file_name] + or al, 20h + cmp al, 'd' + jz @f + mov cl, edit.eol_mac + cmp al, 'm' + jz @f + mov cl, edit.eol_unix +@@: + mov [EditEOLStyle], cl mov ecx, 0x1000 call xpgalloc test eax, eax @@ -240,6 +267,38 @@ start: push aPlugins push app_path call [ini.enum_keys] +; calculate info for editor + xor ebx, ebx + mov ecx, [num_plugins] + mov esi, [plugins] +@@: + dec ecx + js @f + mov [esi+PluginInfo.EditInfoOffs], ebx + add ebx, [esi+PluginInfo.EditInfoSize] + jnc @f + sbb ebx, ebx +@@: +; Ї®бЄ®«мЄг а §¬Ґа Ў«®Є  ў । Єв®аҐ ®Ја ­ЁзҐ­, в® Ё а §¬Ґа Ї ¬пвЁ, १ҐаўЁа㥬®© ¤«п Ї« ЈЁ­®ў, ®Ја ­ЁзҐ­ +; 512 - ЈагЎ п ўҐае­пп ®жҐ­Є , Ј а ­вЁагой п а Ў®вг । Єв®а , ॠ«м­® Ї« ЈЁ­л ¤®«¦­л вॡ®ў вм ¬Ґ­миҐ + cmp ebx, 512 + jb @f + or ebx, -1 + mov [EditPlugInfo], ebx ; disable plugins for editor + push ContinueBtn + push 1 + push EditConfigErr_ptr + push 2 + call SayErr +@@: + add ebx, 3 + and ebx, not 3 + mov [EditPlugInfo], ebx + add ebx, editor_line.plugdata + imul ebx, max_height + add ebx, editor_data.basesize + 0xFFF + shr ebx, 12 + mov [EditDataSize], ebx .noini: mov esi, def_left_dir mov edi, panel1_dir @@ -404,14 +463,14 @@ redraw: cdq mov esi, font_width div esi - cmp eax, 54 + cmp eax, min_width jae @f - mov al, 54 + mov al, min_width mov ch, 1 @@: - cmp eax, 255 + cmp eax, max_width jbe @f - mov eax, 255 + mov eax, max_width mov ch, 1 @@: cmp eax, [cur_width] @@ -431,14 +490,14 @@ redraw: cdq mov esi, font_height div esi - cmp eax, 8 + cmp eax, min_height jae @f - mov al, 8 + mov al, min_height mov cl, 1 @@: - cmp eax, 255 + cmp eax, max_height jbe @f - mov eax, 255 + mov eax, max_height mov cl, 1 @@: mov [fill_height], edx @@ -475,6 +534,7 @@ redraw: call draw_keybar mov ebp, [active_screen_data] mov eax, [active_screen_vtable] + mov [cursor_size], cursor_normal_size call dword [eax+screen_vtable.OnRedraw] jmp event @@: @@ -868,8 +928,8 @@ enum_plugins_callback: jnc @f xor eax, eax @@: -MIN_INTERFACE_VER = 2 -MAX_INTERFACE_VER = 2 +MIN_INTERFACE_VER = 3 +MAX_INTERFACE_VER = 3 cmp eax, MIN_INTERFACE_VER jb @f cmp eax, MAX_INTERFACE_VER @@ -1019,6 +1079,7 @@ change_screen: mov [active_screen_vtable], eax mov [active_screen_data], ebp call draw_keybar + mov [cursor_size], cursor_normal_size call [eax+screen_vtable.OnRedraw] popa ret @@ -1105,13 +1166,133 @@ F12: jmp change_screen panels_OnKey: +; restore screen hidden by quick search box + cmp [bDisplayQuickSearch], 0 + jz @f + mov [bDisplayQuickSearch], 0 + push 0 + push QuickSearchDlg + call HideDialogBox +@@: mov ebp, [active_panel] mov ecx, [ebp + panel1_index - panel1_data] mov edx, [ebp + panel1_start - panel1_data] mov ebx, [ebp + panel1_colst - panel1_data] add ebx, edx mov esi, panels_ctrlkeys - jmp process_ctrl_keys + call process_ctrl_keys + jc .nostdkey + mov [bQuickSearchMode], 0 + ret +.leaveqsmode: + mov [bQuickSearchMode], 0 + call draw_image + ret +.keepqsmode: + push QuickSearchDlg + call ShowDialogBox + mov [bDisplayQuickSearch], 1 + ret +.nostdkey: + cmp [bQuickSearchMode], 0 + jz .noqsmode + test al, al + js .keepqsmode + cmp al, 40h + jae .leaveqsmode + cmp al, 0Eh + jz .qsbackspace + cmp al, 1Ch + jz .test_enter + movzx eax, al + cmp byte [scan2ascii+eax], 0 + jz .leaveqsmode + call get_ascii_char + mov ecx, dword [quick_search_buf + 4] + cmp ecx, quicksearch_maxlen + jae .keepqsmode + mov byte [quick_search_buf + 12 + ecx], al + mov byte [quick_search_buf + 12 + ecx + 1], 0 + push ecx + call quick_find + pop ecx + jnc @f + mov byte [quick_search_buf + 12 + ecx], 0 + jmp .keepqsmode +@@: + inc dword [quick_search_buf + 4] + sub ecx, 16 + jae @f + xor ecx, ecx +@@: + mov dword [quick_search_buf + 8], ecx + jmp .keepqsmode +.qsbackspace: + mov ecx, dword [quick_search_buf + 4] + jecxz .keepqsmode2 + dec ecx + mov byte [quick_search_buf + 12 + ecx], 0 + dec dword [quick_search_buf + 4] +.keepqsmode2: + jmp .keepqsmode +.test_enter: + test [ctrlstate], 0Ch ; LCtrl or RCtrl pressed? + jz .keepqsmode2 + test [ctrlstate], 3 ; Shift pressed? + jnz @f + call quick_find_next + jmp .keepqsmode2 +@@: + call quick_find_prev + jmp .keepqsmode2 +.noqsmode: +; handle Alt+ combinations for quick search + test [ctrlstate], 30h ; LAlt or RAlt pressed? + jz .noalt ; no => skip + test [ctrlstate], 0Ch ; LCtrl or RCtrl pressed? + jnz .noalt ; yes => skip + cmp al, 40h + jae .noalt + movzx eax, al + cmp byte [scan2ascii+eax], 0 + jz .noalt + call get_ascii_char + mov edi, quick_search_buf + 12 + mov dword [edi-12], quicksearch_maxlen-1 + mov dword [edi-8], 1 + and dword [edi-4], 0 + stosb + mov byte [edi], 0 + call quick_find + jnc @f + mov byte [quick_search_buf + 12], 0 + and dword [quick_search_buf + 4], 0 +@@: + mov ebx, QuickSearchDlg + mov eax, [ebp + panel1_left - panel1_data] + add eax, 10 + mov edx, [cur_width] + sub edx, 21 + cmp eax, edx + jb @f + mov eax, edx +@@: + mov [ebx + dlgtemplate.x], eax + mov eax, [ebp + panel1_top - panel1_data] + add eax, [ebp + panel1_height - panel1_data] + mov edx, [cur_height] + sub edx, 2 + cmp eax, edx + jb @f + mov eax, edx +@@: + mov [ebx + dlgtemplate.y], eax + push ebx + call ShowDialogBox + mov [bQuickSearchMode], 1 + mov [bDisplayQuickSearch], 1 +.find_letter_done: +.noalt: .ret: ret .up: @@ -1261,6 +1442,10 @@ panels_OnKey: mov [ebp + panel1_start - panel1_data], eax jmp .done_redraw .enter: + cmp [bQuickSearchMode], 0 + jz @f + call draw_image +@@: call get_curfile_folder_entry test byte [ecx], 10h jnz .enter_folder @@ -1441,6 +1626,27 @@ panels_OnKey: mov [execptr], execdata and [execparams], 0 .dorun: + lea esi, [ebp + panel1_dir - panel1_data] + mov edi, execdata +@@: + lodsb + test al, al + jz @f + stosb + cmp edi, execdataend-1 + jae .bigfilename + jmp @b +@@: + lea esi, [ecx+40] + mov al, '/' + stosb +@@: + lodsb + stosb + cmp edi, execdataend + ja .bigfilename + test al, al + jnz @b ; for fasm call - special handling, because ; 1) fasm command line convention is different : fasm infile,outfile[,path] rather than tinypad infile ; 2) fasm will probably create new file in directory, so we want to reload panel data @@ -1935,16 +2141,6 @@ panels_OnKey: jz .f5_2 ret .f5_2: - mov eax, [ebp + panel1_hPlugin - panel1_data] - mov [source_hModule], eax - mov eax, [ebp + panel1_hFile - panel1_data] - mov [source_hPlugin], eax - mov eax, left_dotdot_entry - cmp ebp, panel1_data - jz @f - add eax, right_dotdot_entry-left_dotdot_entry -@@: - mov [default_attr], eax add esi, panel1_dir - panel1_data mov edi, CopyDestEditBuf mov eax, CopyDestEditBuf.length @@ -1965,6 +2161,16 @@ panels_OnKey: mov al, '/' stosb .f5_common: + mov eax, [ebp + panel1_hPlugin - panel1_data] + mov [source_hModule], eax + mov eax, [ebp + panel1_hFile - panel1_data] + mov [source_hPlugin], eax + mov eax, left_dotdot_entry + cmp ebp, panel1_data + jz @f + add eax, right_dotdot_entry-left_dotdot_entry +@@: + mov [default_attr], eax mov byte [edi], 0 sub edi, edx mov [edx-8], edi @@ -2354,6 +2560,9 @@ end if call view_file .ret2: ret +.f4: + call edit_file + ret .f8_has_selected: mov edi, saved_file_name+511 mov byte [edi], 0 @@ -2427,6 +2636,11 @@ end if cmp [ebp + panel1_selected_num - panel1_data], 0 jnz .f8_has_selected call get_curfile_folder_entry + cmp word [ecx+40], '..' + jnz @f + cmp byte [ecx+42], 0 + jz .f8_not_allowed +@@: cmp [bConfirmDelete], 0 jz .f8_allowed lea eax, [ecx+40] @@ -2459,6 +2673,7 @@ end if add esp, 8 test eax, eax jz .f8_allowed +.f8_not_allowed: ret .f8_allowed: mov [del_bSkipAll], 0 @@ -3049,6 +3264,8 @@ panels_OnExit: ret panels_OnRedraw: + or [cursor_x], -1 + or [cursor_y], -1 call draw_cmdbar mov ebp, panel1_data call calc_colwidths @@ -3103,6 +3320,95 @@ get_curfile_name: add ecx, 40 ret +quick_find: + cmp [ebp + panel1_numfiles - panel1_data], 0 + jz .nof + mov ecx, [ebp + panel1_index - panel1_data] +.scanloop: + mov edi, ecx + shl edi, 2 + add edi, [ebp + panel1_files - panel1_data] + mov edi, [edi] + add edi, 40 + mov esi, quick_search_buf + 12 +@@: + lodsb + test al, al + jz .ok + call match_symbol + jnz .no + inc edi + jmp @b +.no: + inc ecx + cmp ecx, [ebp + panel1_numfiles - panel1_data] + jb @f + xor ecx, ecx +@@: + cmp ecx, [ebp + panel1_index - panel1_data] + jnz .scanloop +.nof: + stc + ret +.ok: + cmp ecx, [ebp + panel1_index - panel1_data] + jz .ret + mov [ebp + panel1_index - panel1_data], ecx + mov eax, [ebp + panel1_height - panel1_data] + shr eax, 1 + sub ecx, eax + jae @f + xor ecx, ecx +@@: + mov eax, [ebp + panel1_numfiles - panel1_data] + sub eax, [ebp + panel1_colst - panel1_data] + jnc @f + xor eax, eax + xor ecx, ecx +@@: + cmp ecx, eax + jb @f + mov ecx, eax +@@: + mov [ebp + panel1_start - panel1_data], ecx + call draw_panel +.ret: + clc + ret + +quick_find_next: + cmp [ebp + panel1_numfiles - panel1_data], 0 + jz quick_find.nof + mov ecx, [ebp + panel1_index - panel1_data] + jmp quick_find.no + +quick_find_prev: + cmp [ebp + panel1_numfiles - panel1_data], 0 + jz quick_find.nof + mov ecx, [ebp + panel1_index - panel1_data] +.scanloop: + dec ecx + jns @f + mov ecx, [ebp + panel1_numfiles - panel1_data] + dec ecx +@@: + cmp ecx, [ebp + panel1_index - panel1_data] + jz quick_find.nof + mov edi, ecx + shl edi, 2 + add edi, [ebp + panel1_files - panel1_data] + mov edi, [edi] + add edi, 40 + mov esi, quick_search_buf + 12 +@@: + lodsb + test al, al + jz quick_find.ok + call match_symbol + jnz .scanloop + inc edi + jmp @b + panels_getname: if lang eq ru mov eax, 'Џ ­Ґ' @@ -3336,6 +3642,7 @@ draw_image: mov [MemForImage], eax mov [bMemForImageValidData], byte 0 .allocated: + push ebp and [max_x], 0 or [min_x], -1 and [max_y], 0 @@ -3464,14 +3771,14 @@ end if mov edx, [cur_width] imul edx, font_width neg edx - mov ecx, (font_height*15+50)/100 + mov ecx, [cursor_size] .cursor_loop: push ecx mov ecx, font_width add eax, edx push eax @@: -; add byte [eax-1], 0x10 +;; add byte [eax-1], 0x10 xor byte [eax-1], 7 sub eax, 1 loop @b @@ -3518,6 +3825,7 @@ end if pop esi int 40h .nodraw: + pop ebp ret get_console_ptr: @@ -3636,6 +3944,11 @@ draw_keybar: mov ah, [keybar_name_color] rep stosw .done: + cmp [bDisplayQuickSearch], 0 + jz @f + push QuickSearchDlg + call DrawDialogBox +@@: popad ret @@ -4452,17 +4765,36 @@ draw_name_column: cmp ebp, panel1_data jnz .ret2 ; —Ёб«® нЄа ­®ў - mov eax, [num_screens] - dec eax +; calculate number of viewer and editor screens + xor ebx, ebx + xor edx, edx + mov ecx, [num_screens] + mov esi, [screens] +.3: + lodsd + cmp eax, viewer_vtable + jnz @f + inc ebx +@@: + cmp eax, editor_vtable + jnz @f + inc edx +@@: + lodsd + loop .3 + mov eax, ebx + mov esi, edx + or eax, edx jz .ret2 - push eax xor eax, eax xor edx, edx call get_console_ptr - mov ah, [panel_nscreens_color] mov al, '[' - stosw - pop eax + stosb + mov al, [panel_nscreens_color] + stosb + xchg eax, ebx +.5: push -'0' @@: xor edx, edx @@ -4474,10 +4806,21 @@ draw_name_column: pop eax add eax, '0' jz @f - mov ah, [panel_nscreens_color] - stosw + stosb + mov al, bl + stosb jmp @b @@: + test esi, esi + jz .4 + mov al, '+' + stosb + mov al, bl + stosb + xor eax, eax + xchg eax, esi + jmp .5 +.4: mov al, ']' mov ah, [panel_nscreens_color] stosw @@ -6106,6 +6449,9 @@ def_right_dir db '/hd0/1',0 bSilentFolderMode db 1 +bQuickSearchMode db 0 +bDisplayQuickSearch db 0 + if lang eq ru aFolder db 'Џ ЇЄ ' .size = $-aFolder @@ -6469,6 +6815,177 @@ keybar_cp: times 12 db ' ' ; Alt+Ctrl+Shift times 12 db ' ' +end if + +keybar_editor: +if lang eq ru +; ЎҐ§ Є« ўЁи-¬®¤ЁдЁЄ в®а®ў + db 'Џ®¬®йм' + db '‘®еа ­' + db ' ' + db ' ' + db ' ' + db 'Џа®б¬ ' + db 'Џ®ЁбЄ ' +keybar_cp2: + db 'cp1251' + db ' ' + db '‚л室 ' + db 'Њ®¤г«Ё' + db 'ќЄа ­л' +; Shift + db ' ' + db '‘®еа.ў' + db ' ' + db 'ђҐ¤ Є.' + db ' ' + db ' ' + db '„ «миҐ' + db '’ Ў«Ёж' + db ' ' + db '‘еа‚ле' + db ' ' + db ' ' +; Ctrl + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db '‡ ¬Ґ­ ' + db ' ' + db ' ' + db 'Џ®§Ёж ' + db ' ' + db ' ' +; Ctrl+Shift + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' +; Alt + db ' ' + db ' ' + db ' ' + db ' ' + db 'ЏҐз вм' + db ' ' + db ' ' + db '‘ва®Є ' + db '‚Ё¤Ґ® ' + db ' ' + db '€бвЏа ' + db ' ' +; Alt+Shift + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db 'Љ®­дЁЈ' + db ' ' + db ' ' + db ' ' +; Alt+Ctrl +times 12 db ' ' +; Alt+Ctrl+Shift +times 12 db ' ' +else +; No modificators + db 'Help ' + db 'Save ' + db ' ' + db ' ' + db ' ' + db 'View ' + db 'Search' +keybar_cp2: + db 'cp1251' + db ' ' + db 'Quit ' + db 'Plugin' + db 'Screen' +; Shift + db ' ' + db 'SaveAs' + db ' ' + db 'Edit..' + db ' ' + db ' ' + db 'Next ' + db 'Table ' + db ' ' + db 'SaveQ ' + db ' ' + db ' ' +; Ctrl + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db 'Replac' + db ' ' + db ' ' + db 'GoFile' + db ' ' + db ' ' +; Ctrl+Shift + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' +; Alt + db ' ' + db ' ' + db ' ' + db ' ' + db 'Print ' + db ' ' + db ' ' + db 'Goto ' + db 'Video ' + db ' ' + db 'ViewHs' + db ' ' +; Alt+Shift + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db ' ' + db 'Config' + db ' ' + db ' ' + db ' ' +; Alt+Ctrl +times 12 db ' ' +; Alt+Ctrl+Shift +times 12 db ' ' end if align 4 @@ -6484,6 +7001,7 @@ console_data_ptr dd 0 cursor_x dd -1 cursor_y dd -1 +cursor_size dd cursor_normal_size cur_cursor_pos dd -1 old_cursor_pos dd -1 @@ -6546,6 +7064,14 @@ viewer_vtable: dd viewer_OnExit dd viewer_IsHandleUsed +editor_vtable: + dd editor_OnRedraw + dd editor_OnKey + dd keybar_editor + dd editor_getname + dd editor_OnExit + dd editor_IsHandleUsed + ; additions to this table require changes in tools.inc::get_error_msg errors1: dd error0msg @@ -6632,7 +7158,8 @@ end if db '&Unicode',0 active_screen dd 0 -tabsize dd 8 +viewer_tabsize dd 8 +editor_tabsize dd 8 ascii2scan: times 32 db 0 @@ -6648,6 +7175,11 @@ ascii2scan: times 48 db 0 db 0x23,0x2E,0x31,0x12,0x1E,0x1A,0x11,0x2D,0x17,0x18,0x1B,0x1F,0x32,0x28,0x34,0x2C db 0x29,0x29,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 +scan2ascii: + db 0,0,'1234567890-=',0,0 + db 'qwertyuiop[]',0,0,'as' + db 'dfghjkl;',27h,'`',0,'\zxcv' + db 'bnm,./',0,0,0,' ',0,0,0,0,0,0 ; Љ« ўЁи­лҐ б®зҐв ­Ёп ; db scancode, reserved @@ -6682,6 +7214,8 @@ panels_ctrlkeys: dd panels_OnKey.enter dw 0x3D, 0 dd panels_OnKey.f3 + dw 0x3E, 0 + dd panels_OnKey.f4 dw 0x3F, 0 dd panels_OnKey.f5 dw 0x3F, 1 @@ -6777,6 +7311,43 @@ viewer_ctrlkeys: dd alt_f9 db 0 +editor_ctrlkeys: + dw 1, 0 + dd editor_OnKey.exit_confirm + dw 0x0E, 0 + dd editor_OnKey.backspace + dw 0x3C, 0 + dd editor_OnKey.f2 + dw 0x43, 0x100 + dd alt_f9 + dw 0x44, 0 + dd editor_OnKey.exit_confirm + dw 0x44, 1 + dd editor_OnKey.exit_save + dw 0x47, 0 + dd editor_OnKey.home + dw 0x48, 0 + dd editor_OnKey.up + dw 0x49, 0 + dd editor_OnKey.pgup + dw 0x4B, 0 + dd editor_OnKey.left + dw 0x4D, 0 + dd editor_OnKey.right + dw 0x4F, 0 + dd editor_OnKey.end + dw 0x50, 0 + dd editor_OnKey.down + dw 0x51, 0 + dd editor_OnKey.pgdn + dw 0x52, 0 + dd editor_OnKey.ins + dw 0x53, 0 + dd editor_OnKey.del + dw 0x58, 0 + dd F12 + db 0 + dirinfo: dd 1 .first dd 0 @@ -6887,6 +7458,9 @@ cmdbar_prefix_color db 7 view_normal_color db 1Bh view_status_color db 30h view_arrows_color db 1Eh +; ђҐ¤ Єв®а +edit_normal_color db 1Bh +edit_status_color db 30h ; Џ®¤бўҐвЄ  д ©«®ў highlight_num_groups dd 10 @@ -6932,11 +7506,11 @@ highlight_group3: highlight_group4: db 0 db 1Ah, 3Ah, 0, 0 - db '*.exe,*.com,*.bat,*.cmd',0 + db '*.exe,*.com,*.bat,*.cmd,*.kex',0 highlight_group5: db 0 db 1Ah, 3Ah, 0, 0 - db '*|*.*',0 + db '*|*.*,readme,makefile',0 highlight_group6: db 0 db 1Dh, 3Dh, 0, 0 @@ -6981,7 +7555,7 @@ nomem_dlgdata: dd 1 dd 1 dd aError - rb 4 + rb 8 dd 0 dd 0 dd 2 @@ -7010,6 +7584,7 @@ copy_dlgdata: .border_color db ? .header_color db ? db 0 + dd ? dd 0 dd 0 dd 4 @@ -7052,7 +7627,7 @@ mkdir_dlgdata: .height dd 4 dd 4, 2 dd aMkDirCaption - dd ? + dd ?, ? dd 0 dd 0 dd 4 @@ -7093,7 +7668,7 @@ mark_dlgdata: dd 37, 1 dd 4, 2 .title dd ? - dd ? + dd ?, ? dd 0, 0 dd 1 ; Ї®«Ґ । ЄвЁа®ў ­Ёп @@ -7102,6 +7677,23 @@ mark_dlgdata: dd enter_string_buf .flags dd ? +; ¤Ё «®Ј Ўлбва®Ј® Ї®ЁбЄ  ў Ї ­Ґ«Ё (Alt+ЎгЄўл) +QuickSearchDlg: + dd 5 +.x dd ? +.y dd ? + dd 20, 1 + dd 1, 1 + dd aSearch + dd ?, ? + dd 0, 0 + dd 1 +; Ї®«Ґ । ЄвЁа®ў ­Ёп + dd 3 + dd 1, 0, 18, 0 + dd quick_search_buf + dd 1Ch + RetryOrCancelBtn: dd aRetry dd a_Cancel @@ -7122,7 +7714,15 @@ DeleteErrorBtn: ContinueBtn: dd aContinue +EditorExitBtn: + dd aSave + dd aDontSave + dd aContinueEdit + aCannotOpenFile_ptr dd aCannotOpenFile +EditConfigErr_ptr: + dd aEditConfigErr1 + dd aEditConfigErr2 if lang eq ru aDeleteCaption db '“¤ «Ґ­ЁҐ',0 aConfirmDeleteText db '‚л е®вЁвҐ г¤ «Ёвм',0 @@ -7194,6 +7794,18 @@ aSelect db ' aDeselect db '‘­пвм',0 aCannotOpenFile db 'ЋиЁЎЄ  ЇаЁ ®вЄалвЁЁ д ©« ',0 aCannotSetFolder db 'ЌҐ ¬®Јг § ©вЁ ў Ї ЇЄг',0 +aSearch db 'Џ®ЁбЄ',0 +aEditConfigErr1 db 'ЋиЁЎЄ  ў Є®­дЁЈга жЁЁ Ї« ЈЁ­®ў ¤«п । Єв®а .',0 +aEditConfigErr2 db 'Џ®Їа®Ўг©вҐ гЎа вм «Ёи­ЁҐ Ї« ЈЁ­л.',0 +aEditNoMemory db '” ©« б«ЁиЄ®¬ ўҐ«ЁЄ ¤«п § Јаг§ЄЁ ў । Єв®а.',0 +aLine db ' ‘ва®Є ' +aCol db ' Љ®« ' +aEditorTitle db 'ђҐ¤ Єв®а',0 +aFileModified db '” ©« Ўл« Ё§¬Ґ­с­',0 +aSave db '‘®еа ­Ёвм',0 +aDontSave db 'ЌҐ б®еа ­пвм',0 +aContinueEdit db 'Џа®¤®«¦Ёвм । ЄвЁа®ў ­ЁҐ',0 +aCannotSaveToPlugin db '‘®еа ­Ґ­ЁҐ д ©«®ў ­  Ї ­Ґ«пе Ї« ЈЁ­®ў ­Ґ Ї®¤¤Ґа¦Ёў Ґвбп',0 else aDeleteCaption db 'Delete',0 aConfirmDeleteText db 'Do you wish to delete',0 @@ -7269,6 +7881,17 @@ aSelect db 'Select',0 aDeselect db 'Deselect',0 aCannotOpenFile db 'Cannot open the file',0 aCannotSetFolder db 'Cannot enter to folder',0 +aSearch db 'Search',0 +aEditConfigErr1 db 'Error in configuration of plugins for the editor.',0 +aEditConfigErr2 db 'Try to remove unnecessary plugins.',0 +aLine db ' Line' +aCol db ' Col ' +aEditorTitle db 'Editor',0 +aFileModified db 'File has been modified',0 +aSave db 'Save',0 +aDontSave db 'Do not save',0 +aContinueEdit db 'Continue editing',0 +aCannotSaveToPlugin db 'Saving is not supported for plugin panels',0 end if aOk db 'OK',0 @@ -7301,6 +7924,7 @@ aSetFolder db 'SetFolder',0 aGetOpenPluginInfo db 'GetOpenPluginInfo',0 aGetPanelTitle db 'GetPanelTitle',0 aGetFiles db 'GetFiles',0 +aEditInfoSize db 'EditInfoSize',0 aConfirmations db 'Confirmations',0 aConfirmDelete db 'Delete',0 @@ -7310,6 +7934,9 @@ aPanels db 'Panels',0 aLeftViewMode db 'LeftViewMode',0 aRightViewMode db 'RightViewMode',0 +aEditor db 'Editor',0 +aEolStyle db 'EOLStyle',0 + aAssociations db 'Associations',0 aPlugins db 'Plugins',0 aMenu db 'Menu',0 @@ -7339,6 +7966,7 @@ plugin_exported: dd aGetOpenPluginInfo dd aGetPanelTitle dd aGetFiles + dd aEditInfoSize dd 0 plugin_exported_default: dd plugin_unload_default @@ -7354,6 +7982,7 @@ plugin_exported_default: dd GetOpenPluginInfo_default dd GetPanelTitle_default dd GetFiles_default + dd 0 ; default value for EditInfoSize kfar_info: dd .size @@ -7386,6 +8015,9 @@ plugins dd 0 num_plugins dd 0 alloc_plugins dd 0 +EditPlugInfo dd 0 +EditEOLStyle db edit.eol_unix + virtual at 0 PluginInfo: .unload dd ? @@ -7401,6 +8033,8 @@ PluginInfo: .GetOpenPluginInfo dd ? .GetPanelTitle dd ? .GetFiles dd ? +.EditInfoSize dd ? +.EditInfoOffs dd ? .size = $ end virtual @@ -7576,7 +8210,11 @@ panel2_dir rb 1024 ;console_data rb max_width*max_height*2 -nomem_dlgsavearea rb (12+4)*(3+3)*2 +nomem_dlgsavearea rb 8 + (12+4)*(3+3)*2 + +quicksearch_savearea rb 22*3*2 +quicksearch_maxlen = 64 +quick_search_buf rb 12 + quicksearch_maxlen cur_header rb max_width tmp dd ? @@ -7604,6 +8242,10 @@ last_column_index dd ? scrpos dq ? viewer_right_side dq ? +EditDataSize dd ? +EditBlockStart dd ? +EditBlockSize dd ? + saved_file_name: procinfo rb 1024 lower_file_name = procinfo + 512 diff --git a/programs/fs/kfar/trunk/kfar.ini b/programs/fs/kfar/trunk/kfar.ini index e07888fe0f..fc47063b24 100644 --- a/programs/fs/kfar/trunk/kfar.ini +++ b/programs/fs/kfar/trunk/kfar.ini @@ -1,31 +1,38 @@ [Associations] -asm=/rd/1/TinyPad; AsmMenu1,AsmMenu2 -inc=/rd/1/TinyPad -ini=/rd/1/TinyPad -txt=/rd/1/TinyPad -jpg=/rd/1/JpegView -jpeg=/rd/1/JpegView -gif=/rd/1/GIFVIEW; GifMenu1,MenuAnimage -wav=/rd/1/AC97SND -mp3=/rd/1/AC97SND -mid=/rd/1/MIDAMP -bmp=/rd/1/MV; BmpMenu1,MenuAnimage -png=/rd/1/@rcher -rtf=/rd/1/RtfRead -3ds=/rd/1/3d/view3ds -lif=/rd/1/demos/life2 -skn=/rd/1/desktop +asm=/sys/TinyPad; AsmMenu1,AsmMenu2 +inc=/sys/TinyPad +ini=/sys/TinyPad +txt=/sys/TinyPad +jpg=/sys/JpegView +jpeg=/sys/JpegView +gif=/sys/GIFVIEW; GifMenu1,MenuAnimage +wav=/sys/AC97SND +mp3=/sys/AC97SND +mid=/sys/MIDAMP +bmp=/sys/MV; BmpMenu1,MenuAnimage +png=/sys/@rcher +rtf=/sys/RtfRead +3ds=/sys/3d/view3ds +lif=/sys/demos/life2 +skn=/sys/desktop [Menu] -AsmMenu1=&ђҐ¤ Єв®а,/rd/1/TinyPad -AsmMenu2=&Љ®¬ЇЁ«Ёа®ў вм,/rd/1/develop/fasm -GifMenu1=&Џа®б¬®ва,/rd/1/GIFVIEW -BmpMenu1=&Џа®б¬®ва,/rd/1/MV -MenuAnimage=&ђҐ¤ Єв®а,/rd/1/animage +AsmMenu1=&ђҐ¤ Єв®а,/sys/TinyPad +AsmMenu2=&Љ®¬ЇЁ«Ёа®ў вм,/sys/develop/fasm +GifMenu1=&Џа®б¬®ва,/sys/GIFVIEW +BmpMenu1=&Џа®б¬®ва,/sys/MV +MenuAnimage=&ђҐ¤ Єв®а,/sys/animage [Panels] LeftViewMode=2 RightViewMode=2 + +[Editor] +# ‘Ё¬ў®«л Є®­ж  бва®ЄЁ, Є®в®алҐ Ўг¤Ґв ўбв ў«пвм +# । Єв®а kfar ЇаЁ ¤®Ў ў«Ґ­ЁЁ ­®ў®© бва®ЄЁ: +# DOS - ­ Ї®¤®ЎЁҐ DOS/Win (0D 0A), Unix - ­ Ї®¤®ЎЁҐ Unix (0A), +# Mac - ­ Ї®¤®ЎЁҐ Mac (0D) +EOLStyle=Unix [FolderShortcuts] # Њ®¦­® ®ЇаҐ¤Ґ«Ёвм ¤® ¤ҐбпвЁ ббл«®Є ­  Ї ЇЄЁ Shortcut0...Shortcut9, diff --git a/programs/fs/kfar/trunk/kfar.txt b/programs/fs/kfar/trunk/kfar.txt new file mode 100644 index 0000000000..6751c4deda --- /dev/null +++ b/programs/fs/kfar/trunk/kfar.txt @@ -0,0 +1,91 @@ +Управляющие сочетания клавиш в KFar. +В панелях: +стрелки, Home, End - перемещение курсора по активной панели +Tab - изменение активной панели +Enter - вход в папку или запуск программы, на которую указывает курсор +F3 - переход к просмотру файла под курсором +F5 - копирование выделенных элементов или элемента под курсором на другую панель +Shift+F5 - копирование выделенных элементов или элемента под курсором + на текущую панель + (нужно будет задать другое имя; для F5 это также можно сделать) +F7 - создание папки +F8 - удаление выделенных элементов или элемента под курсором +F10 - выход +Alt+F1/Alt+F2 - смена диска, отображаемого на левой/правой панели +Alt+F9 - разворачивание окна к максимально возможным размерам и + восстановление размеров +Ctrl+F3 - сортировать файлы/папки на активной панели по имени +Ctrl+F4 - сортировка по расширению +Ctrl+F5 - сортировка по дате/времени последней модификации +Ctrl+F6 - сортировка по размеру +Ctrl+F7 - не сортировать (отображать в том же порядке, что и на диске) +Ctrl+F8 - сортировка по дате/времени создания +Ctrl+F9 - сортировка по дате/времени последнего обращения +F12 - вызов меню экранов +Ctrl+R - перечитать содержимое активной панели +Menu - вызвать контекстное меню для файла под курсором +LeftCtrl+1/2/3/4 - выбрать режим панели (краткий/средний/полный/широкий) +RightCtrl+0..9 - перейти к папке, указанной в разделе [FolderShortcuts] + в ini-файле под именем Shortcut0..9 соответственно +Insert - выделить/снять выделение с текущего файла/папки +Grey[+] - выделить файлы и папки по маске +Grey[-] - снять выделение с файлов и папок по маске +Маска имеет вид типа "*.asm,*.inc|template.asm" (пример задаёт все файлы +с расширениями ASM и INC за исключением template.asm): одна или больше +элементарная маска включения со стандартным значением символов '*' и '?', +разделённых ',' или ';', после чего можно поставить '|' и одну или больше +масок исключения. Маска "*.*" задаёт все файлы с точкой в имени (т.е. +файлы с любым непустым расширением); чтобы задать все файлы, используйте "*". +Grey[*] - инвертировать выделение +Alt+<буква или цифра> - позиционирование курсора на имени файла/папки, +начинающемся на указанную букву или цифру; вызывает окно быстрого поиска, +в котором можно вводить дальнейшие символы имени файла для уточнения, +а также Ctrl+Enter/Shift+Ctrl+Enter для перемещения к следующему/предыдущему +элементу панели, имя которого начинается с введённых букв + +В просмотрщике: +Esc = F3 = F10 = Numpad5 - выход +Down - строку вниз +PgDn - страницу вниз +Up - строку вверх +PgUp - страницу вверх +Home - в начало файла +End - в конец файла +Left - символ влево +Right - символ вправо +Ctrl+Left - в режиме Text 20 символов влево; + в режиме Hex байт влево +Ctrl+Right - в режиме Text 20 символов вправо; + в режиме Hex байт вправо +Ctrl+Shift+Left - в начало строк на экране +Ctrl+Shift+Right - в конец строк на экране +F2 - включение/выключение переноса строк +F4 - переключение просмотра Text <-> Hex +F8 - переключение кодировки cp866 (DOS) <-> cp1251 (Win) +Shift+F8 - меню выбора кодировки +F12 - вызов меню экранов +Alt+F9 - разворачивание окна к максимально возможным размерам и + восстановление размеров + +В редакторе: +Esc = F10 - выход; если файл был модифицирован, последует вопрос о + необходимости сохранения +Shift+F10 - выход с сохранением +F2 - сохранить файл +Down - строку вниз +PgDn - страницу вниз +Up - строку вверх +PgUp - страницу вверх +Left - предыдущий символ +Right - символ вправо +Home - в начало строки +End - в конец строки +Backspace - удалить символ перед курсором +Del - удалить символ под курсором +Ins - переключить режим вставки/замены при вводе +F12 - вызов меню экранов +Alt+F9 - разворачивание окна к максимально возможным размерам и + восстановление размеров + + diamond + mailto:diamondz@land.ru diff --git a/programs/fs/kfar/trunk/viewer.inc b/programs/fs/kfar/trunk/viewer.inc index af0678f742..1f61f5299f 100644 --- a/programs/fs/kfar/trunk/viewer.inc +++ b/programs/fs/kfar/trunk/viewer.inc @@ -1,20 +1,21 @@ virtual at 0 viewer_data: + .hPlugin dd ? + .hFile dd ? .buf_start dq ? .cur_pos dq ? .filesize dq ? .buf_pos dd ? .buf_size dd ? .col dq ? - .hPlugin dd ? - .hFile dd ? .hWorkFile dd ? .encoding db ? - .bEofReached db ? .flags db ? ; & 1: hex mode ; & 2: unwrap ; & 4: big-endian unicode + .bEofReached db ? rb 1 + align 200h .filename rb 1024 .hostname rb 1024 .buf rb 16384 @@ -154,6 +155,7 @@ view_file: mov [ebp+viewer_data.hWorkFile], eax test eax, eax jnz .retry +..openerr_in_screen: push ContinueBtn push 1 push aCannotOpenFile_ptr @@ -212,6 +214,9 @@ view_file: @@: mov [ebp+viewer_data.encoding], encodings.unicode .nounicode: +viewer_OnRedraw: + or [cursor_x], -1 + or [cursor_y], -1 call viewer_set_keybar call viewer_draw_text ret @@ -418,63 +423,35 @@ viewer_draw_text: xor edx, edx call get_console_ptr mov ah, [view_status_color] - lea esi, [ebp+viewer_data.filename] - mov dl, 3 mov ecx, [cur_width] sub ecx, 44 cmp ecx, 20 - jae .5 + jae @f mov cl, 20 -.5: - lodsb - cmp al, '/' - jnz @f - dec edx - jz .6 @@: - stosw - loop .5 -.6: - dec ecx - stosw - push esi -@@: - inc esi - cmp byte [esi-1], 0 - jnz @b - sub esi, [esp] - dec esi - cmp ecx, esi - jae .7 - mov al, '.' - stosw - stosw - stosw - sub ecx, 3 - sub esi, ecx - add [esp], esi -.7: - pop esi -@@: - lodsb - test al, al - jz @f - dec ecx - stosw - jmp @b -@@: - mov al, ' ' - add ecx, 8 + call viewedit_draw_filename + add ecx, 11 rep stosw movzx esi, [ebp+viewer_data.encoding] lea esi, [encodings.names+esi*8] - mov cl, 8 + push edi esi + dec edi + dec edi + std + add esi, 8 +@@: + dec esi + cmp byte [esi], ' ' + jz @b @@: lodsb stosw - loop @b + cmp esi, [esp] + jae @b + cld + pop esi edi mov al, ' ' - mov cl, 8 + mov cl, 13 rep stosw std push edi @@ -700,7 +677,7 @@ end if push edx mov eax, ecx xor edx, edx - div [tabsize] + div [viewer_tabsize] mov ecx, edx pop edx jmp .1 @@ -716,7 +693,7 @@ end if push edx push ecx mov eax, ecx - mov ecx, [tabsize] + mov ecx, [viewer_tabsize] xor edx, edx div ecx pop eax @@ -1001,6 +978,54 @@ end if adc dword [scrpos+4], 0 ret +viewedit_draw_filename: + lea esi, [ebp+viewer_data.filename] + xor edx, edx + cmp [ebp+viewer_data.hPlugin], edx + mov dl, 3 + jz .5 + mov dl, 1 +.5: + lodsb + cmp al, '/' + jnz @f + dec edx + jz .6 +@@: + stosw + loop .5 +.6: + dec ecx + stosw + push esi +@@: + inc esi + cmp byte [esi-1], 0 + jnz @b + sub esi, [esp] + dec esi + cmp ecx, esi + jae .7 + mov al, '.' + stosw + stosw + stosw + sub ecx, 3 + sub esi, ecx + add [esp], esi +.7: + pop esi +@@: + lodsb + test al, al + jz @f + dec ecx + stosw + jmp @b +@@: + mov al, ' ' + ret + viewer_seek_to_current: mov eax, dword [ebp+viewer_data.cur_pos] mov edx, dword [ebp+viewer_data.cur_pos+4] @@ -1213,7 +1238,7 @@ viewer_next_newline: .tab: push ecx mov eax, ecx - mov ecx, [tabsize] + mov ecx, [viewer_tabsize] xor edx, edx div ecx sub ecx, edx @@ -1232,8 +1257,11 @@ viewer_next_newline: jnz .2 dec [ebp+viewer_data.buf_pos] .2: + clc .ret: + pushf call viewer_set_curpos + popf ret viewer_prev_newline: @@ -1363,11 +1391,6 @@ end if movsw jmp draw_keybar -viewer_OnRedraw: - call viewer_set_keybar - call viewer_draw_text - ret - viewer_OnExit: mov edx, [ebp+viewer_data.hPlugin] test edx, edx @@ -1383,6 +1406,7 @@ viewer_OnExit: ret viewer_IsHandleUsed: +editor_IsHandleUsed: cmp edx, [ebp+viewer_data.hPlugin] jnz @f cmp ebx, [ebp+viewer_data.hFile] @@ -1579,6 +1603,25 @@ else stosd stosb end if + jmp viewedit_getname +editor_getname: +if lang eq ru + mov eax, 'ђҐ¤ ' + stosd + mov eax, 'Єв®а' + stosd + mov eax, ' ' + stosd + stosb +else + mov eax, 'Edit' + stosd + mov eax, ' ' + stosd + stosd + stosb +end if +viewedit_getname: sub ecx, 13 cmp [ebp+viewer_data.hPlugin], 0 jz .native