Subversion Repositories Kolibri OS

Rev

Rev 814 | Rev 1122 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. virtual at 0
  2. viewer_data:
  3.         .hPlugin        dd      ?
  4.         .hFile          dd      ?
  5.         .buf_start      dq      ?
  6.         .cur_pos        dq      ?
  7.         .filesize       dq      ?
  8.         .buf_pos        dd      ?
  9.         .buf_size       dd      ?
  10.         .col            dq      ?
  11.         .hWorkFile      dd      ?
  12.         .encoding       db      ?
  13.         .flags          db      ?       ; & 1: hex mode
  14.                                         ; & 2: unwrap
  15.                                         ; & 4: big-endian unicode
  16.         .bEofReached    db      ?
  17.                         rb      1
  18.         .selected_start dq      ?
  19.         .selected_len   dq      ?
  20.         align 200h
  21.         .filename       rb      1024
  22.         .hostname       rb      1024
  23.         .buf            rb      16384
  24.         .size = $
  25. end virtual
  26.  
  27. view_file:
  28.         push    eax ecx
  29.         mov     ecx, viewer_data.size
  30.         mov     edx, viewer_vtable
  31.         call    new_screen
  32.         pop     ecx
  33.         test    eax, eax
  34.         pop     eax
  35.         jnz     @f
  36.         ret
  37. @@:
  38.         test    eax, eax
  39.         jz      .frompanel
  40.         and     dword [ebp+viewer_data.hPlugin], 0
  41.         and     dword [ebp+viewer_data.hFile], 0
  42.         mov     byte [ebp+viewer_data.hostname], 0
  43.         lea     edi, [ebp+viewer_data.filename]
  44.         push    edi
  45. @@:
  46.         lodsb
  47.         stosb
  48.         test    al, al
  49.         jnz     @b
  50.         jmp     .namecopied
  51. .frompanel:
  52.         mov     eax, dword [esi+panel1_hPlugin-panel1_dir]
  53.         mov     [ebp+viewer_data.hPlugin], eax
  54.         test    eax, eax
  55.         jz      .nocopyhostname
  56.         lea     edi, [ebp+viewer_data.hostname]
  57.         push    esi
  58.         mov     eax, dword [esi+panel1_parents-panel1_dir]
  59.         mov     esi, dword [esi+panel1_parents_sz-panel1_dir]
  60.         add     esi, eax
  61. @@:
  62.         dec     esi
  63.         cmp     byte [esi-1], 0
  64.         jz      @f
  65.         cmp     byte [esi-1], '/'
  66.         jnz     @b
  67. @@:
  68.         lodsb
  69.         stosb
  70.         test    al, al
  71.         jnz     @b
  72.         pop     esi
  73. .nocopyhostname:
  74.         mov     eax, dword [esi+panel1_hFile-panel1_dir]
  75.         mov     [ebp+viewer_data.hFile], eax
  76.         lea     edi, [ebp+viewer_data.filename]
  77.         push    edi
  78. @@:
  79.         lodsb
  80.         test    al, al
  81.         jz      @f
  82.         stosb
  83.         jmp     @b
  84. @@:
  85.         lea     esi, [ecx+40]
  86.         cmp     byte [edi-1], '/'
  87.         jz      @f
  88.         mov     al, '/'
  89.         stosb
  90. @@:
  91.         lodsb
  92.         stosb
  93.         test    al, al
  94.         jnz     @b
  95. .namecopied:
  96.         xor     eax, eax
  97.         mov     [ebp+viewer_data.encoding], al ;encodings.cp866 = 0
  98.         mov     [ebp+viewer_data.flags], al
  99.         mov     dword [ebp+viewer_data.col], eax
  100.         mov     dword [ebp+viewer_data.col+4], eax
  101.         call    viewer_clear_selection
  102.         pop     eax
  103.         push    eax
  104.         mov     ebx, attrinfo
  105.         mov     [ebx+21], eax
  106. .attr_retry:
  107.         mov     edx, [ebp+viewer_data.hPlugin]
  108.         test    edx, edx
  109.         jz      .attr_native
  110.         push    ebp
  111.         push    dword [ebx+16]
  112.         push    eax
  113.         push    [ebp+viewer_data.hFile]
  114.         call    [edx+PluginInfo.getattr]
  115.         pop     ebp
  116.         jmp     .attr_common
  117. .attr_native:
  118.         push    70
  119.         pop     eax
  120.         int     40h
  121. .attr_common:
  122.         test    eax, eax
  123.         jz      @f
  124.         lea     ebx, [ebp+viewer_data.filename]
  125.         push    ebx
  126.         push    aCannotReadFile
  127.         call    get_error_msg
  128.         push    eax
  129.         mov     eax, esp
  130.         push    RetryOrCancelBtn
  131.         push    2
  132.         push    eax
  133.         push    3
  134.         call    SayErr
  135.         add     esp, 3*4
  136.         mov     ebx, attrinfo
  137.         test    eax, eax
  138.         jz      .attr_retry
  139.         pop     eax
  140.         jmp     delete_active_screen
  141. @@:
  142.         mov     eax, dword [attrinfo.attr+32]
  143.         mov     dword [ebp+viewer_data.filesize], eax
  144.         mov     eax, dword [attrinfo.attr+36]
  145.         mov     dword [ebp+viewer_data.filesize+4], eax
  146.         mov     ebx, readinfo
  147.         xor     eax, eax
  148.         mov     dword [ebx+readinfo.first-readinfo], eax
  149.         mov     dword [ebx+readinfo.first+4-readinfo], eax
  150.         mov     dword [ebp+viewer_data.buf_start], eax
  151.         mov     dword [ebp+viewer_data.buf_start+4], eax
  152.         mov     dword [ebp+viewer_data.cur_pos], eax
  153.         mov     dword [ebp+viewer_data.cur_pos+4], eax
  154.         mov     [ebx+readinfo.size-readinfo], 16384
  155.         lea     eax, [ebp+viewer_data.buf]
  156.         mov     [readinfo.data], eax
  157.         mov     [ebp+viewer_data.buf_pos], eax
  158.         pop     dword [readinfo.name]
  159.         mov     eax, [ebp+viewer_data.hPlugin]
  160.         test    eax, eax
  161.         jz      .retry
  162.         push    ebx ebp
  163.         push    O_READ
  164.         push    dword [readinfo.name]
  165.         push    [ebp+viewer_data.hFile]
  166.         call    [eax+PluginInfo.open]
  167.         pop     ebp ebx
  168.         mov     [ebp+viewer_data.hWorkFile], eax
  169.         test    eax, eax
  170.         jnz     .retry
  171. ..openerr_in_screen:
  172.         push    ContinueBtn
  173.         push    1
  174.         push    aCannotOpenFile_ptr
  175.         push    1
  176.         call    SayErr
  177.         jmp     delete_active_screen
  178. .retry:
  179.         mov     eax, [ebp+viewer_data.hPlugin]
  180.         test    eax, eax
  181.         jz      .read_native
  182.         push    ebp
  183.         push    16384
  184.         push    [ebx+readinfo.data-readinfo]
  185.         push    [ebp+viewer_data.hWorkFile]
  186.         call    [eax+PluginInfo.read]
  187.         pop     ebp
  188.         cmp     eax, -1
  189.         jz      .readok         ; let's hope that plugin says error itself
  190.         mov     [ebp+viewer_data.buf_size], eax
  191.         mov     ebx, eax
  192.         jmp     .readok
  193. .read_native:
  194.         push    70
  195.         pop     eax
  196.         int     40h
  197.         mov     [ebp+viewer_data.buf_size], ebx
  198.         test    eax, eax
  199.         jz      .readok
  200.         cmp     eax, 6
  201.         jz      .readok
  202. .readerr:
  203.         lea     ebx, [ebp+viewer_data.filename]
  204.         push    ebx
  205.         push    aCannotReadFile
  206.         call    get_error_msg
  207.         push    eax
  208.         mov     eax, esp
  209.         push    RetryOrCancelBtn
  210.         push    2
  211.         push    eax
  212.         push    3
  213.         call    SayErr
  214.         add     esp, 3*4
  215.         mov     ebx, readinfo
  216.         test    eax, eax
  217.         jz      .attr_retry
  218.         jmp     delete_active_screen
  219. .readok:
  220.         cmp     ebx, 2
  221.         jb      .nounicode
  222.         cmp     word [ebp+viewer_data.buf], 0xFEFF
  223.         jz      @f
  224.         cmp     word [ebp+viewer_data.buf], 0xFFFE
  225.         jnz     .nounicode
  226.         or      byte [ebp+viewer_data.flags], 4
  227. @@:
  228.         mov     [ebp+viewer_data.encoding], encodings.unicode
  229. .nounicode:
  230. viewer_OnRedraw:
  231.         or      [cursor_x], -1
  232.         or      [cursor_y], -1
  233.         call    viewer_set_keybar
  234.         call    viewer_draw_text
  235.         ret
  236.  
  237. viewer_skip_unicode_marker:
  238.         cmp     [ebp+viewer_data.encoding], encodings.unicode
  239.         jnz     @f
  240.         cmp     [bForHex], 0
  241.         jnz     @f
  242.         cmp     dword [ebp+viewer_data.buf_start], 0
  243.         jnz     @f
  244.         cmp     dword [ebp+viewer_data.buf_start+4], 0
  245.         jnz     @f
  246.         lea     eax, [ebp+viewer_data.buf]
  247.         cmp     eax, [ebp+viewer_data.buf_pos]
  248.         jnz     @f
  249.         cmp     word [eax], 0xFFFE
  250.         jz      .skip
  251.         cmp     word [eax], 0xFEFF
  252.         jnz     @f
  253. .skip:
  254.         add     [ebp+viewer_data.buf_pos], 2
  255. @@:
  256.         ret
  257.  
  258. viewer_load_next:
  259.         mov     eax, dword [ebp+viewer_data.buf_start]
  260.         add     eax, 8192
  261.         mov     dword [ebp+viewer_data.buf_start], eax
  262.         mov     edx, dword [ebp+viewer_data.buf_start+4]
  263.         adc     edx, 0
  264.         mov     dword [ebp+viewer_data.buf_start+4], edx
  265.         add     eax, 16384-8192
  266.         adc     edx, 0
  267.         mov     dword [readinfo.first], eax
  268.         mov     dword [readinfo.first+4], edx
  269.         mov     dword [readinfo.size], 8192
  270.         lea     edi, [ebp+viewer_data.buf]
  271.         lea     esi, [edi+8192]
  272.         mov     ecx, (16384-8192)/4
  273.         rep     movsd
  274.         mov     [readinfo.data], edi
  275.         lea     eax, [ebp+viewer_data.filename]
  276.         mov     [readinfo.name], eax
  277. .readretry:
  278.         mov     ebx, readinfo
  279.         mov     eax, [ebp+viewer_data.hPlugin]
  280.         test    eax, eax
  281.         jz      .native
  282.         push    ecx ebp
  283.         push    8192
  284.         push    [ebx+readinfo.data-readinfo]
  285.         push    [ebp+viewer_data.hWorkFile]
  286.         call    [eax+PluginInfo.read]
  287.         pop     ebp ecx
  288.         mov     ebx, eax
  289.         cmp     eax, -1
  290.         jnz     .readok
  291.         xor     ebx, ebx
  292.         jmp     .readok
  293. .native:
  294.         push    70
  295.         pop     eax
  296.         int     40h
  297.         test    eax, eax
  298.         jz      .readok
  299.         cmp     eax, 6
  300.         jz      .readok
  301. .readerr:
  302.         call    ask_retry_ignore
  303.         jz      .readretry
  304. .readok:
  305.         sub     [ebp+viewer_data.buf_pos], 8192
  306.         add     ebx, 16384-8192
  307.         mov     [ebp+viewer_data.buf_size], ebx
  308.         mov     eax, [ebp+viewer_data.buf_pos]
  309.         cmp     ebx, 16384-8192
  310.         ret
  311.  
  312. viewer_get_next_char:
  313.         pusha
  314.         call    viewer_skip_unicode_marker
  315.         mov     eax, [ebp+viewer_data.buf_pos]
  316.         lea     ecx, [ebp+viewer_data.buf]
  317.         add     ecx, [ebp+viewer_data.buf_size]
  318.         cmp     eax, ecx
  319.         jb      .buffered
  320.         mov     al, ' '
  321.         sub     ecx, ebp
  322.         cmp     ecx, viewer_data.buf + 16384
  323.         jb      .err
  324.         call    viewer_load_next
  325.         jnz     .buffered
  326. .err:
  327.         stc
  328.         popa
  329.         ret
  330. .buffered:
  331.         cmp     [ebp+viewer_data.encoding], encodings.unicode
  332.         jz      .unicode
  333.         mov     al, [eax]
  334. .done:
  335.         mov     [esp+28], al
  336.         inc     [ebp+viewer_data.buf_pos]
  337.         clc
  338.         popa
  339.         ret
  340.  
  341. .unicode:
  342.         inc     [ebp+viewer_data.buf_pos]
  343.         cmp     [bForHex], 0
  344.         jnz     @f
  345.         call    read_unicode_char
  346.         jmp     .done
  347. @@:
  348.         mov     ax, [eax]
  349.         mov     [esp+29], ah
  350.         jmp     .done
  351.  
  352. viewer_get_prev_char:
  353.         pusha
  354.         lea     ecx, [ebp+viewer_data.buf]
  355.         cmp     [ebp+viewer_data.buf_pos], ecx
  356.         ja      .buffered
  357.         mov     eax, dword [ebp+viewer_data.buf_start]
  358.         mov     edx, dword [ebp+viewer_data.buf_start+4]
  359.         test    eax, eax
  360.         jnz     @f
  361.         test    edx, edx
  362.         jnz     @f
  363.         stc
  364.         jmp     .ret
  365. @@:
  366.         sub     eax, 8192
  367.         sbb     edx, 0
  368.         jnc     @f
  369.         xor     eax, eax
  370.         xor     edx, edx
  371. @@:
  372.         call    viewer_seek
  373.         add     [ebp+viewer_data.buf_pos], 8192
  374. .buffered:
  375.         mov     eax, [ebp+viewer_data.buf_pos]
  376.         dec     eax
  377.         cmp     [ebp+viewer_data.encoding], encodings.unicode
  378.         jz      .unicode
  379.         mov     [ebp+viewer_data.buf_pos], eax
  380.         mov     al, [eax]
  381.         mov     [esp+28], al
  382. .done:
  383.         clc
  384. .ret:
  385.         popa
  386.         ret
  387.  
  388. .unicode:
  389.         dec     eax
  390.         mov     [ebp+viewer_data.buf_pos], eax
  391.         call    read_unicode_char
  392.         jmp     .done
  393.  
  394. read_unicode_char:
  395.         mov     ax, [eax]
  396. uni2ansi_char:
  397.         test    [ebp+viewer_data.flags], 4
  398.         jz      @f
  399.         xchg    al, ah
  400. @@:
  401.         cmp     ax, 0x80
  402.         jb      .ret
  403.         cmp     ax, 0x401
  404.         jz      .yo1
  405.         cmp     ax, 0x451
  406.         jz      .yo2
  407.         cmp     ax, 0x410
  408.         jb      .unk
  409.         cmp     ax, 0x440
  410.         jb      .rus1
  411.         cmp     ax, 0x450
  412.         jb      .rus2
  413. .unk:
  414.         mov     al, ' '
  415. .ret:
  416.         ret
  417. .yo1:
  418.         mov     al, 'ð'
  419.         ret
  420. .yo2:
  421.         mov     al, 'ñ'
  422.         ret
  423. .rus1:
  424. ; 0x410-0x43F -> 0x80-0xAF
  425.         add     al, 0x70
  426.         ret
  427. .rus2:
  428. ; 0x440-0x44F -> 0xE0-0xEF
  429.         add     al, 0xA0
  430.         ret
  431.  
  432. viewer_clear_selection:
  433.         and     dword [ebp+viewer_data.selected_start], 0
  434.         and     dword [ebp+viewer_data.selected_start+4], 0
  435.         and     dword [ebp+viewer_data.selected_len], 0
  436.         and     dword [ebp+viewer_data.selected_len+4], 0
  437.         ret
  438.  
  439. fld_uint64:
  440.         fild    qword [eax]
  441.         test    byte [eax+7], 80h
  442.         jz      .ret
  443.         fadd    [@f]
  444. .ret:
  445.         ret
  446. @@      dq      18446744073709551616.0 ;0x10000000000000000
  447.  
  448. viewer_draw_text:
  449.         call    viewer_seek_to_current
  450.         xor     eax, eax
  451.         xor     edx, edx
  452.         call    get_console_ptr
  453.         mov     ah, [view_status_color]
  454.         mov     ecx, [cur_width]
  455.         sub     ecx, 44
  456.         cmp     ecx, 20
  457.         jae     @f
  458.         mov     cl, 20
  459. @@:
  460.         call    viewedit_draw_filename
  461.         add     ecx, 11
  462.         rep     stosw
  463.         movzx   esi, [ebp+viewer_data.encoding]
  464.         lea     esi, [encodings.names+esi*8]
  465.         push    edi esi
  466.         dec     edi
  467.         dec     edi
  468.         std
  469.         add     esi, 8
  470. @@:
  471.         dec     esi
  472.         cmp     byte [esi], ' '
  473.         jz      @b
  474. @@:
  475.         lodsb
  476.         stosw
  477.         cmp     esi, [esp]
  478.         jae     @b
  479.         cld
  480.         pop     esi edi
  481.         mov     al, ' '
  482.         mov     cl, 13
  483.         rep     stosw
  484.         std
  485.         push    edi
  486.         mov     edx, dword [ebp+viewer_data.filesize+4]
  487.         mov     eax, dword [ebp+viewer_data.filesize]
  488.         mov     cl, 10
  489. @@:
  490.         push    eax
  491.         mov     eax, edx
  492.         xor     edx, edx
  493.         div     ecx
  494.         xchg    eax, [esp]
  495.         div     ecx
  496.         xchg    eax, edx
  497.         add     al, '0'
  498.         mov     ah, [view_status_color]
  499.         stosw
  500.         xchg    eax, edx
  501.         pop     edx
  502.         test    eax, eax
  503.         jnz     @b
  504.         test    edx, edx
  505.         jnz     @b
  506.         mov     al, ' '
  507.         mov     ah, [view_status_color]
  508.         stosw
  509.         cld
  510.         pop     edi
  511.         inc     edi
  512.         inc     edi
  513.         mov     al, ' '
  514.         mov     cl, 5
  515.         rep     stosw
  516. if lang eq ru
  517.         mov     al, 'Š'
  518.         stosw
  519.         mov     al, '®'
  520.         stosw
  521.         mov     al, '«'
  522.         stosw
  523. else
  524.         mov     al, 'C'
  525.         stosw
  526.         mov     al, 'o'
  527.         stosw
  528.         mov     al, 'l'
  529.         stosw
  530. end if
  531.         mov     al, ' '
  532.         stosw
  533.         push    edi
  534.         mov     eax, dword [ebp+viewer_data.col]
  535.         mov     edx, dword [ebp+viewer_data.col+4]
  536.         test    edx, edx
  537.         jnz     .col_big
  538.         cmp     eax, 100000
  539.         jae     .col_big
  540.         mov     cl, 10
  541.         push    -'0'
  542. @@:
  543.         div     ecx
  544.         push    edx
  545.         xor     edx, edx
  546.         test    eax, eax
  547.         jnz     @b
  548. @@:
  549.         pop     eax
  550.         add     eax, '0'
  551.         jz      .col_done
  552.         mov     ah, [view_status_color]
  553.         stosw
  554.         jmp     @b
  555. .col_big:
  556.         push    eax
  557.         mov     al, '.'
  558.         mov     ah, [view_status_color]
  559.         stosw
  560.         stosw
  561.         stosw
  562.         xor     eax, eax
  563.         xchg    eax, edx
  564.         mov     cl, 100
  565.         div     ecx
  566.         pop     eax
  567.         div     ecx
  568.         mov     cl, 10
  569.         xor     eax, eax
  570.         xchg    eax, edx
  571.         div     ecx
  572.         add     al, '0'
  573.         mov     ah, [view_status_color]
  574.         stosw
  575.         mov     al, dl
  576.         add     al, '0'
  577.         stosw
  578. .col_done:
  579.         pop     ecx
  580.         add     ecx, 10*2
  581.         sub     ecx, edi
  582.         shr     ecx, 1
  583.         mov     al, ' '
  584.         mov     ah, [view_status_color]
  585.         rep     stosw
  586.         finit
  587.         fldcw   [fpu_cw]
  588.         mov     [tmp], 100
  589.         lea     eax, [ebp+viewer_data.filesize]
  590.         cmp     dword [eax], 0
  591.         jnz     @f
  592.         cmp     dword [eax+4], 0
  593.         jz      .size_zero
  594. @@:
  595.         call    fld_uint64
  596.         lea     eax, [ebp+viewer_data.cur_pos]
  597.         call    fld_uint64
  598.         fdivrp
  599.         fimul   [_100d]
  600.         fistp   [tmp]
  601. .size_zero:
  602.         mov     byte [edi-2], '%'
  603.         sub     edi, 4
  604.         mov     eax, [tmp]
  605.         mov     cl, 10
  606. @@:
  607.         xor     edx, edx
  608.         div     ecx
  609.         xchg    eax, edx
  610.         add     al, '0'
  611.         mov     [edi], al
  612.         sub     edi, 2
  613.         xchg    eax, edx
  614.         test    eax, eax
  615.         jnz     @b
  616.         xor     eax, eax
  617.         push    1
  618.         pop     edx
  619.         call    get_console_ptr
  620.         test    [ebp+viewer_data.flags], 1
  621.         jnz     .DrawHex
  622.         push    2
  623.         pop     edx
  624.         xor     ecx, ecx
  625.         mov     dword [scrpos], ecx
  626.         mov     dword [scrpos+4], ecx
  627.         mov     dword [viewer_right_side], ecx
  628.         mov     dword [viewer_right_side+4], ecx
  629. .1:
  630.         call    viewer_get_next_char
  631.         jc      .done
  632. .2:
  633.         cmp     al, 0xD
  634.         jz      .newline
  635.         cmp     al, 0xA
  636.         jz      .newline
  637.         cmp     ecx, [cur_width]
  638.         jb      .no_newline
  639.         test    [ebp+viewer_data.flags], 2
  640.         jnz     .no_newline
  641. .newline:
  642.         push    eax
  643.         mov     ecx, dword [scrpos]
  644.         mov     eax, dword [scrpos+4]
  645.         sub     ecx, dword [ebp+viewer_data.col]
  646.         sbb     eax, dword [ebp+viewer_data.col+4]
  647.         ja      .line_filled
  648.         jb      .line_full
  649.         cmp     ecx, [cur_width]
  650.         ja      .line_filled
  651.         jmp     @f
  652. .line_full:
  653.         xor     ecx, ecx
  654. @@:
  655.         test    ecx, ecx
  656.         jnz     @f
  657.         mov     eax, dword [scrpos]
  658.         or      eax, dword [scrpos+4]
  659.         jz      @f
  660.         inc     ecx
  661. @@:
  662.         sub     ecx, [cur_width]
  663.         neg     ecx
  664.         mov     al, ' '
  665.         mov     ah, [view_normal_color]
  666.         rep     stosw
  667. .line_filled:
  668.         mov     eax, dword [scrpos]
  669.         sub     eax, dword [viewer_right_side]
  670.         mov     eax, dword [scrpos+4]
  671.         sbb     eax, dword [viewer_right_side+4]
  672.         jb      @f
  673.         mov     eax, dword [scrpos]
  674.         mov     dword [viewer_right_side], eax
  675.         mov     eax, dword [scrpos+4]
  676.         mov     dword [viewer_right_side+4], eax
  677. @@:
  678.         xor     ecx, ecx
  679.         mov     dword [scrpos], ecx
  680.         mov     dword [scrpos+4], ecx
  681.         inc     edx
  682.         pop     eax
  683.         cmp     edx, [cur_height]
  684.         jae     .done
  685. .no_newline:
  686.         cmp     al, 0xD
  687.         jz      .3
  688.         cmp     al, 0xA
  689.         jz      .3
  690. .4:
  691.         test    al, al
  692.         jns     @f
  693.         movzx   esi, [ebp+viewer_data.encoding]
  694.         cmp     esi, encodings.unicode
  695.         jz      @f
  696.         shl     esi, 7
  697.         movzx   eax, al
  698.         mov     al, [encodings.tables-80h+esi+eax]
  699. @@:
  700.         cmp     al, 9
  701.         jz      .tab
  702.         call    .write_char
  703.         inc     ecx
  704.         jns     .1
  705.         push    edx
  706.         mov     eax, ecx
  707.         xor     edx, edx
  708.         div     [viewer_tabsize]
  709.         mov     ecx, edx
  710.         pop     edx
  711.         jmp     .1
  712. .3:
  713.         mov     bl, al
  714.         call    viewer_get_next_char
  715.         jc      .done
  716.         xor     bl, al
  717.         cmp     bl, 0xA xor 0xD
  718.         jz      .1
  719.         jmp     .2
  720. .tab:
  721.         push    edx
  722.         push    ecx
  723.         mov     eax, ecx
  724.         mov     ecx, [viewer_tabsize]
  725.         xor     edx, edx
  726.         div     ecx
  727.         pop     eax
  728.         sub     ecx, edx
  729.         pop     edx
  730.         add     eax, ecx
  731.         test    [ebp+viewer_data.flags], 2
  732.         jnz     @f
  733.         cmp     eax, [cur_width]
  734.         jbe     @f
  735.         sub     eax, [cur_width]
  736.         sub     ecx, eax
  737.         mov     eax, [cur_width]
  738. @@:
  739.         push    eax
  740.         mov     al, ' '
  741. @@:
  742.         call    .write_char
  743.         loop    @b
  744.         pop     ecx
  745.         jmp     .1
  746. .done:
  747.         setc    [ebp+viewer_data.bEofReached]
  748. .done2:
  749.         inc     edx
  750.         cmp     edx, [cur_height]
  751.         jnc     @f
  752.         mov     eax, dword [ebp+viewer_data.cur_pos]
  753.         or      eax, dword [ebp+viewer_data.cur_pos+4]
  754.         jz      @f
  755.         call    viewer_seek_to_current
  756.         call    viewer_prev_newline
  757.         jmp     viewer_draw_text
  758. @@:
  759.         push    edi
  760.         xor     eax, eax
  761.         mov     edx, [cur_height]
  762.         dec     edx
  763.         call    get_console_ptr
  764.         mov     ecx, edi
  765.         pop     edi
  766.         sub     ecx, edi
  767.         shr     ecx, 1
  768.         mov     al, ' '
  769.         mov     ah, [view_normal_color]
  770.         rep     stosw
  771.         cmp     [ebp+viewer_data.bEofReached], 0
  772.         jz      @f
  773.         xor     edx, edx
  774.         mov     eax, [cur_width]
  775.         sub     eax, 4
  776.         call    get_console_ptr
  777.         mov     ah, [view_status_color]
  778.         mov     al, '1'
  779.         stosw
  780.         mov     al, '0'
  781.         stosw
  782.         stosw
  783. @@:
  784.         call    draw_image
  785.         ret
  786. .DrawHex:
  787.         xor     esi, esi
  788.         mov     [ebp+viewer_data.bEofReached], 0
  789. .line:
  790.         mov     al, ' '
  791.         mov     ah, [view_normal_color]
  792.         push    edi
  793.         mov     ecx, [cur_width]
  794.         rep     stosw
  795.         mov     ebx, edi
  796.         pop     edi
  797.         mov     [bForHex], 1
  798.         call    viewer_get_next_char
  799.         mov     [bForHex], 0
  800.         jc      .hexdone
  801.         push    eax
  802.         push    edi
  803.         add     edi, 36*2
  804.         mov     al, 0xB3
  805.         mov     ah, [view_normal_color]
  806.         call    .safechar
  807.         pop     edi
  808.         mov     eax, dword [ebp+viewer_data.cur_pos]
  809.         mov     edx, dword [ebp+viewer_data.cur_pos+4]
  810.         push    esi
  811.         shl     esi, 4
  812.         add     eax, esi
  813.         adc     edx, 0
  814.         pop     esi
  815.         push    eax
  816.         mov     al, dl
  817.         shr     eax, 4
  818.         and     al, 0xF
  819.         call    .hex_digit
  820.         mov     al, dl
  821.         and     al, 0xF
  822.         call    .hex_digit
  823.         pop     eax
  824.         push    8
  825.         pop     ecx
  826.         add     edi, 7*2
  827.         std
  828. @@:
  829.         push    eax
  830.         and     al, 0xF
  831.         call    .hex_digit
  832.         pop     eax
  833.         shr     eax, 4
  834.         loop    @b
  835.         cld
  836.         add     edi, 9*2
  837.         mov     al, ':'
  838.         mov     ah, [view_normal_color]
  839.         stosw
  840.         mov     al, ' '
  841.         stosw
  842.         xor     ecx, ecx
  843.         pop     eax
  844.         jmp     @f
  845. .hexchar:
  846.         mov     [bForHex], 1
  847.         call    viewer_get_next_char
  848.         mov     [bForHex], 0
  849.         jc      .hexdone
  850. @@:
  851.         cmp     [ebp+viewer_data.encoding], encodings.unicode
  852.         jz      .hexchar_unicode
  853.         push    eax
  854.         shr     al, 4
  855.         call    .hex_digit
  856.         pop     eax
  857.         push    eax
  858.         and     al, 0xF
  859.         call    .hex_digit
  860.         mov     al, ' '
  861.         call    .safechar
  862.         pop     eax
  863.         push    edi
  864.         add     edi, 48*2
  865.         push    ecx
  866.         shl     ecx, 2
  867.         sub     edi, ecx
  868.         pop     ecx
  869.         cmp     ecx, 8
  870.         jb      @f
  871.         sub     edi, 4
  872. @@:
  873.         test    al, al
  874.         jns     @f
  875.         movzx   edx, [ebp+viewer_data.encoding]
  876.         shl     edx, 7
  877.         movzx   eax, al
  878.         mov     al, [encodings.tables+eax+edx-80h]
  879.         mov     ah, [view_normal_color]
  880. @@:
  881.         call    .safechar
  882.         pop     edi
  883.         inc     ecx
  884.         cmp     ecx, 8
  885.         jnz     @f
  886.         mov     al, 0xB3
  887.         call    .safechar
  888.         mov     al, ' '
  889.         call    .safechar
  890. @@:
  891.         cmp     ecx, 16
  892.         jnz     .hexchar
  893.         jmp     .hexchar_nextline
  894. .hexchar_unicode:
  895.         push    eax
  896.         shr     eax, 12
  897.         call    .hex_digit
  898.         pop     eax
  899.         push    eax
  900.         shr     eax, 8
  901.         and     al, 0xF
  902.         call    .hex_digit
  903.         pop     eax
  904.         push    eax
  905.         shr     al, 4
  906.         call    .hex_digit
  907.         pop     eax
  908.         push    eax
  909.         and     al, 0xF
  910.         call    .hex_digit
  911.         mov     al, ' '
  912.         mov     ah, [view_normal_color]
  913.         call    .safechar
  914.         pop     eax
  915.         push    edi
  916.         add     edi, 38*2
  917.         push    ecx
  918.         shl     ecx, 3
  919.         sub     edi, ecx
  920.         pop     ecx
  921.         cmp     ecx, 4
  922.         jb      @f
  923.         sub     edi, 4
  924. @@:
  925.         call    uni2ansi_char
  926.         mov     ah, [view_normal_color]
  927.         call    .safechar
  928.         pop     edi
  929.         inc     ecx
  930.         cmp     ecx, 4
  931.         jnz     @f
  932.         mov     al, 0xB3
  933.         call    .safechar
  934.         mov     al, ' '
  935.         call    .safechar
  936. @@:
  937.         cmp     ecx, 8
  938.         jnz     .hexchar
  939. .hexchar_nextline:
  940.         mov     edi, ebx
  941.         add     esi, 3
  942.         mov     edx, esi
  943.         cmp     esi, [cur_height]
  944.         jae     .done2
  945.         dec     esi
  946.         dec     esi
  947.         jmp     .line
  948. .hexdone:
  949.         mov     [ebp+viewer_data.bEofReached], 1
  950.         mov     edi, ebx
  951.         lea     edx, [esi+2]
  952.         jmp     .done2
  953.  
  954. .hex_digit:
  955.         push    eax
  956.         cmp     al, 10
  957.         sbb     al, 69h
  958.         das
  959.         mov     ah, [view_normal_color]
  960.         call    .safechar
  961.         pop     eax
  962.         ret
  963. .safechar:
  964.         cmp     edi, ebx
  965.         jae     @f
  966.         stosw
  967. @@:
  968.         ret
  969. .write_char:
  970.         push    ecx eax
  971.         mov     ecx, dword [scrpos]
  972.         mov     eax, dword [scrpos+4]
  973.         sub     ecx, dword [ebp+viewer_data.col]
  974.         sbb     eax, dword [ebp+viewer_data.col+4]
  975.         jb      .left
  976.         ja      .skip
  977.         test    ecx, ecx
  978.         jnz     @f
  979.         mov     eax, dword [scrpos]
  980.         or      eax, dword [scrpos+4]
  981.         jnz     .skip
  982. @@:
  983.         cmp     ecx, [cur_width]
  984.         ja      .skip
  985.         jb      .do
  986.         mov     al, '>'
  987.         mov     [edi-2], al
  988.         mov     al, [view_arrows_color]
  989.         mov     [edi-1], al
  990.         jmp     .skip
  991. .left:
  992.         mov     eax, dword [scrpos]
  993.         or      eax, dword [scrpos+4]
  994.         jnz     .skip
  995.         mov     al, '<'
  996.         mov     ah, [view_arrows_color]
  997.         stosw
  998.         jmp     .skip
  999. .do:
  1000.         mov     al, [esp]
  1001.         mov     ah, [view_normal_color]
  1002.         push    edx
  1003.         mov     ecx, [ebp+viewer_data.buf_pos]
  1004.         sub     ecx, ebp
  1005.         sub     ecx, viewer_data.buf + 1
  1006.         xor     edx, edx
  1007.         add     ecx, dword [ebp+viewer_data.buf_start]
  1008.         adc     edx, dword [ebp+viewer_data.buf_start+4]
  1009.         sub     ecx, dword [ebp+viewer_data.selected_start]
  1010.         sbb     edx, dword [ebp+viewer_data.selected_start+4]
  1011.         cmp     edx, dword [ebp+viewer_data.selected_len+4]
  1012.         ja      .color_ok
  1013.         jb      @f
  1014.         cmp     ecx, dword [ebp+viewer_data.selected_len]
  1015.         jae     .color_ok
  1016. @@:
  1017.         mov     ah, [view_selected_color]
  1018. .color_ok:
  1019.         pop     edx
  1020.         stosw
  1021. .skip:
  1022.         pop     eax ecx
  1023.         add     dword [scrpos], 1
  1024.         adc     dword [scrpos+4], 0
  1025.         ret
  1026.  
  1027. viewedit_draw_filename:
  1028.         lea     esi, [ebp+viewer_data.filename]
  1029.         xor     edx, edx
  1030.         cmp     [ebp+viewer_data.hPlugin], edx
  1031.         mov     dl, 3
  1032.         jz      .5
  1033.         mov     dl, 1
  1034. .5:
  1035.         lodsb
  1036.         cmp     al, '/'
  1037.         jnz     @f
  1038.         dec     edx
  1039.         jz      .6
  1040. @@:
  1041.         stosw
  1042.         loop    .5
  1043. .6:
  1044.         dec     ecx
  1045.         stosw
  1046.         push    esi
  1047. @@:
  1048.         inc     esi
  1049.         cmp     byte [esi-1], 0
  1050.         jnz     @b
  1051.         sub     esi, [esp]
  1052.         dec     esi
  1053.         cmp     ecx, esi
  1054.         jae     .7
  1055.         mov     al, '.'
  1056.         stosw
  1057.         stosw
  1058.         stosw
  1059.         sub     ecx, 3
  1060.         sub     esi, ecx
  1061.         add     [esp], esi
  1062. .7:
  1063.         pop     esi
  1064. @@:
  1065.         lodsb
  1066.         test    al, al
  1067.         jz      @f
  1068.         dec     ecx
  1069.         stosw
  1070.         jmp     @b
  1071. @@:
  1072.         mov     al, ' '
  1073.         ret
  1074.  
  1075. viewer_seek_to_current:
  1076.         mov     eax, dword [ebp+viewer_data.cur_pos]
  1077.         mov     edx, dword [ebp+viewer_data.cur_pos+4]
  1078. viewer_seek:
  1079.         push    eax edx
  1080.         sub     eax, dword [ebp+viewer_data.buf_start]
  1081.         sbb     edx, dword [ebp+viewer_data.buf_start+4]
  1082.         jb      .prev
  1083.         ja      .next
  1084.         cmp     eax, 16384
  1085.         jae     .next
  1086.         lea     eax, [ebp+viewer_data.buf+eax]
  1087.         mov     [ebp+viewer_data.buf_pos], eax
  1088.         pop     edx eax
  1089.         ret
  1090. .prev:
  1091.         inc     edx
  1092.         jnz     .read_full
  1093.         and     eax, not 511
  1094.         cmp     eax, -16384
  1095.         jbe     .read_full
  1096.         lea     edi, [ebp+viewer_data.buf+16384-4]
  1097.         lea     esi, [edi+eax]
  1098.         lea     ecx, [eax+16384]
  1099.         push    ecx
  1100.         shr     ecx, 2
  1101.         std
  1102.         rep     movsd
  1103.         cld
  1104.         pop     ecx
  1105.         add     dword [ebp+viewer_data.buf_start], eax
  1106.         adc     dword [ebp+viewer_data.buf_start+4], -1
  1107.         neg     eax
  1108.         cmp     dword [ebp+viewer_data.buf_size], ecx
  1109.         jb      .doread
  1110.         mov     dword [ebp+viewer_data.buf_size], ecx
  1111.         jmp     .doread
  1112. .read_full:
  1113.         pop     edx eax
  1114.         push    eax edx
  1115.         and     eax, not 511
  1116.         sub     eax, 8192-512
  1117.         sbb     edx, 0
  1118.         jnc     @f
  1119.         xor     eax, eax
  1120.         xor     edx, edx
  1121. @@:
  1122.         mov     dword [ebp+viewer_data.buf_start], eax
  1123.         mov     dword [ebp+viewer_data.buf_start+4], edx
  1124.         and     dword [ebp+viewer_data.buf_size], 0
  1125.         mov     eax, 16384
  1126. .doread:
  1127.         mov     ebx, readinfo
  1128.         push    dword [ebp+viewer_data.buf_start]
  1129.         pop     dword [ebx+4]
  1130.         push    dword [ebp+viewer_data.buf_start+4]
  1131.         pop     dword [ebx+8]
  1132.         mov     [ebx+12], eax
  1133.         lea     eax, [ebp+viewer_data.buf]
  1134.         mov     [ebx+16], eax
  1135.         lea     eax, [ebp+viewer_data.filename]
  1136.         mov     [ebx+21], eax
  1137.         call    .q
  1138.         cmp     ebx, [readinfo.size]
  1139.         jnz     @f
  1140.         add     ebx, [ebp+viewer_data.buf_size]
  1141. @@:
  1142. .ret:
  1143.         mov     [ebp+viewer_data.buf_size], ebx
  1144.         pop     edx eax
  1145.         sub     eax, dword [ebp+viewer_data.buf_start]
  1146.         lea     eax, [ebp+eax+viewer_data.buf]
  1147.         mov     [ebp+viewer_data.buf_pos], eax
  1148.         ret
  1149. .next:
  1150.         or      eax, 511
  1151.         sub     eax, 16384-1
  1152.         sbb     edx, 0
  1153.         jnz     .read_full
  1154.         cmp     eax, 16384
  1155.         jae     .read_full
  1156.         cmp     [ebp+viewer_data.buf_size], 16384
  1157.         jb      .read_full
  1158.         lea     edi, [ebp+viewer_data.buf]
  1159.         lea     esi, [edi+eax]
  1160.         mov     ecx, 16384
  1161.         sub     ecx, eax
  1162.         shr     ecx, 2
  1163.         rep     movsd
  1164.         add     dword [ebp+viewer_data.buf_start], eax
  1165.         adc     dword [ebp+viewer_data.buf_start+4], 0
  1166.         mov     ebx, readinfo
  1167.         mov     [ebx+16], edi
  1168.         sub     edi, ebp
  1169.         sub     edi, viewer_data.buf
  1170.         mov     edx, dword [ebp+viewer_data.buf_start]
  1171.         add     edx, edi
  1172.         mov     [ebx+4], edx
  1173.         mov     edx, dword [ebp+viewer_data.buf_start+4]
  1174.         adc     edx, 0
  1175.         mov     [ebx+8], edx
  1176.         mov     [ebx+12], eax
  1177.         lea     eax, [ebp+viewer_data.filename]
  1178.         mov     [ebx+21], eax
  1179.         call    .q
  1180.         sub     ebx, [readinfo.size]
  1181.         add     ebx, 16384
  1182.         jmp     .ret
  1183.  
  1184. .q:
  1185.         mov     ebx, readinfo
  1186.         mov     eax, [ebp+viewer_data.hPlugin]
  1187.         test    eax, eax
  1188.         jz      .native
  1189.         push    ebp
  1190.         push    dword [ebx+12]
  1191.         push    dword [ebx+16]
  1192.         push    [ebp+viewer_data.hWorkFile]
  1193.         push    eax
  1194.         push    dword [ebx+8]
  1195.         push    dword [ebx+4]
  1196.         push    [ebp+viewer_data.hWorkFile]
  1197.         call    [eax+PluginInfo.setpos]
  1198.         pop     eax
  1199.         call    [eax+PluginInfo.read]
  1200.         pop     ebp
  1201.         mov     ebx, eax
  1202.         cmp     eax, -1
  1203.         jnz     @f
  1204.         xor     ebx, ebx
  1205. @@:
  1206.         ret
  1207. .native:
  1208.         push    70
  1209.         pop     eax
  1210.         int     40h
  1211.         test    eax, eax
  1212.         jz      .readok
  1213.         cmp     eax, 6
  1214.         jz      .readok
  1215. .readerr:
  1216.         call    ask_retry_ignore
  1217.         jz      .q
  1218. .readok:
  1219.         ret
  1220.  
  1221. ask_retry_ignore:
  1222.         push    esi
  1223.         lea     esi, [ebp+viewer_data.filename]
  1224.         push    esi
  1225.         push    aCannotReadFile
  1226.         call    get_error_msg
  1227.         push    eax
  1228.         mov     eax, esp
  1229.         push    RetryOrIgnoreBtn
  1230.         push    2
  1231.         push    eax
  1232.         push    3
  1233.         call    SayErr
  1234.         add     esp, 3*4
  1235.         pop     esi
  1236.         test    eax, eax
  1237.         ret
  1238.  
  1239. viewer_set_curpos:
  1240.         mov     eax, [ebp+viewer_data.buf_pos]
  1241.         sub     eax, ebp
  1242.         sub     eax, viewer_data.buf
  1243.         xor     edx, edx
  1244.         add     eax, dword [ebp+viewer_data.buf_start]
  1245.         adc     edx, dword [ebp+viewer_data.buf_start+4]
  1246.         mov     dword [ebp+viewer_data.cur_pos], eax
  1247.         mov     dword [ebp+viewer_data.cur_pos+4], edx
  1248.         ret
  1249.  
  1250. viewer_next_newline:
  1251.         test    [ebp+viewer_data.flags], 1
  1252.         jz      .nohex
  1253.         push    8
  1254.         pop     ecx
  1255.         cmp     [ebp+viewer_data.encoding], encodings.unicode
  1256.         jz      @f
  1257.         add     ecx, ecx
  1258. @@:
  1259.         call    viewer_get_next_char
  1260.         jc      @f
  1261.         loop    @b
  1262.         call    viewer_set_curpos
  1263.         clc
  1264. @@:     ret
  1265. .nohex:
  1266.         xor     ecx, ecx
  1267. @@:
  1268.         call    viewer_get_next_char
  1269.         jc      .ret
  1270.         cmp     al, 0xD
  1271.         jz      .1
  1272.         cmp     al, 0xA
  1273.         jz      .1
  1274.         cmp     al, 9
  1275.         jz      .tab
  1276.         inc     ecx
  1277. .next:
  1278.         test    [ebp+viewer_data.flags], 2
  1279.         jnz     @b
  1280.         cmp     ecx, [cur_width]
  1281.         jbe     @b
  1282.         call    viewer_get_prev_char
  1283.         jmp     .2
  1284. .tab:
  1285.         push    ecx
  1286.         mov     eax, ecx
  1287.         mov     ecx, [viewer_tabsize]
  1288.         xor     edx, edx
  1289.         div     ecx
  1290.         sub     ecx, edx
  1291.         add     [esp], ecx
  1292.         pop     ecx
  1293.         jmp     .next
  1294. .1:
  1295.         mov     cl, al
  1296.         call    viewer_get_next_char
  1297.         jc      .ret
  1298.         xor     cl, al
  1299.         cmp     cl, 0xD xor 0xA
  1300.         jz      .2
  1301.         dec     [ebp+viewer_data.buf_pos]
  1302.         cmp     [ebp+viewer_data.encoding], encodings.unicode
  1303.         jnz     .2
  1304.         dec     [ebp+viewer_data.buf_pos]
  1305. .2:
  1306.         clc
  1307. .ret:
  1308.         pushf
  1309.         call    viewer_set_curpos
  1310.         popf
  1311.         ret
  1312.  
  1313. viewer_prev_newline:
  1314.         test    [ebp+viewer_data.flags], 1
  1315.         jz      .nohex
  1316.         push    8
  1317.         pop     ecx
  1318.         cmp     [ebp+viewer_data.encoding], encodings.unicode
  1319.         jz      @f
  1320.         add     ecx, ecx
  1321. @@:
  1322.         call    viewer_get_prev_char
  1323.         jc      @f
  1324.         loop    @b
  1325. @@:     call    viewer_set_curpos
  1326.         ret
  1327. .nohex:
  1328.         mov     eax, 8192
  1329.         push    eax
  1330.         cdq
  1331.         div     [cur_width]
  1332.         pop     eax
  1333.         sub     eax, edx
  1334.         mov     edx, eax
  1335.         call    viewer_get_prev_char
  1336.         jc      .0
  1337.         dec     edx
  1338.         cmp     al, 0xD
  1339.         jz      .2
  1340.         cmp     al, 0xA
  1341.         jnz     .3
  1342. .2:
  1343.         mov     cl, al
  1344.         call    viewer_get_prev_char
  1345.         jc      .0
  1346.         dec     edx
  1347.         xor     cl, al
  1348.         cmp     cl, 0xD xor 0xA
  1349.         jnz     .3
  1350. @@:
  1351.         call    viewer_get_prev_char
  1352.         jc      .0
  1353.         dec     edx
  1354.         jz      .0
  1355. .3:
  1356.         cmp     al, 0xD
  1357.         jz      .1
  1358.         cmp     al, 0xA
  1359.         jnz     @b
  1360. .1:
  1361.         call    viewer_get_next_char
  1362. .0:
  1363.         push    dword [ebp+viewer_data.cur_pos+4]
  1364.         push    dword [ebp+viewer_data.cur_pos]
  1365.         call    viewer_set_curpos
  1366. @@:
  1367.         push    dword [ebp+viewer_data.cur_pos+4]
  1368.         push    dword [ebp+viewer_data.cur_pos]
  1369.         call    viewer_next_newline
  1370.         jc      .ret3
  1371.         mov     eax, dword [ebp+viewer_data.cur_pos]
  1372.         mov     edx, dword [ebp+viewer_data.cur_pos+4]
  1373.         sub     eax, [esp+8]
  1374.         sbb     edx, [esp+12]
  1375.         jae     .ret3
  1376.         pop     eax
  1377.         pop     eax
  1378.         jmp     @b
  1379. .ret3:
  1380.         pop     dword [ebp+viewer_data.cur_pos]
  1381.         pop     dword [ebp+viewer_data.cur_pos+4]
  1382. .ret:
  1383.         pop     eax
  1384.         pop     eax
  1385.         jmp     viewer_seek_to_current
  1386.  
  1387. viewer_set_keybar:
  1388.         mov     eax, keybar_viewer
  1389. if lang eq ru
  1390.         test    [ebp+viewer_data.flags], 1
  1391.         jnz     .hex
  1392.         mov     dword [eax+(4-1)*6], 'Š®¤ '
  1393.         mov     word [eax+(4-1)*6+4], '  '
  1394.         jmp     @f
  1395. .hex:
  1396.         mov     dword [eax+(4-1)*6], '’¥ªá'
  1397.         mov     word [eax+(4-1)*6+4], 'â '
  1398. @@:
  1399.         test    [ebp+viewer_data.flags], 2
  1400.         jnz     .unwrap
  1401.         mov     dword [eax+6], ' §¢'
  1402.         mov     word [eax+6+4], '¥à'
  1403.         jmp     @f
  1404. .unwrap:
  1405.         mov     dword [eax+6], '‘¢¥à'
  1406.         mov     word [eax+6+4], '­ '
  1407. @@:
  1408. else
  1409.         test    [ebp+viewer_data.flags], 1
  1410.         jnz     .hex
  1411.         mov     dword [eax+(4-1)*6], 'Hex '
  1412. ;        mov     word [eax+(4-1)*6+4], '  '
  1413.         jmp     @f
  1414. .hex:
  1415.         mov     dword [eax+(4-1)*6], 'Text'
  1416. ;        mov     word [eax+(4-1)*6+4], '  '
  1417. @@:
  1418.         test    [ebp+viewer_data.flags], 2
  1419.         jnz     .unwrap
  1420.         mov     dword [eax+6], 'Unwr'
  1421.         mov     word [eax+6+4], 'ap'
  1422.         jmp     @f
  1423. .unwrap:
  1424.         mov     dword [eax+6], 'Wrap'
  1425.         mov     word [eax+6+4], '  '
  1426. @@:
  1427. end if
  1428.         movzx   esi, [ebp+viewer_data.encoding]
  1429.         dec     esi
  1430.         jz      @f
  1431.         push    1
  1432.         pop     esi
  1433. @@:
  1434.         lea     esi, [encodings.names+esi*8]
  1435.         lea     edi, [eax+keybar_cp-keybar_viewer]
  1436.         movsd
  1437.         movsw
  1438.         jmp     draw_keybar
  1439.  
  1440. viewer_OnExit:
  1441.         mov     edx, [ebp+viewer_data.hPlugin]
  1442.         test    edx, edx
  1443.         jz      @f
  1444.         and     [ebp+viewer_data.hPlugin], 0
  1445.         push    edx ebp
  1446.         push    [ebp+viewer_data.hWorkFile]
  1447.         call    [edx+PluginInfo.close]
  1448.         pop     ebp edx
  1449.         mov     ebx, [ebp+viewer_data.hFile]
  1450.         call    close_handle_if_unused
  1451. @@:
  1452.         ret
  1453.  
  1454. viewer_IsHandleUsed:
  1455. editor_IsHandleUsed:
  1456.         cmp     edx, [ebp+viewer_data.hPlugin]
  1457.         jnz     @f
  1458.         cmp     ebx, [ebp+viewer_data.hFile]
  1459. @@:
  1460.         ret
  1461.  
  1462. viewer_OnKey:
  1463.         mov     esi, viewer_ctrlkeys
  1464.         jmp     process_ctrl_keys
  1465. .exit:
  1466.         call    viewer_OnExit
  1467.         jmp     delete_active_screen
  1468. .down:
  1469.         cmp     [ebp+viewer_data.bEofReached], 0
  1470.         jnz     .ret
  1471.         call    viewer_seek_to_current
  1472.         call    viewer_next_newline
  1473.         jc      .ret
  1474.         call    viewer_draw_text
  1475.         ret
  1476. .pgdn:
  1477.         cmp     [ebp+viewer_data.bEofReached], 0
  1478.         jnz     .ret
  1479.         call    viewer_seek_to_current
  1480.         mov     ebx, [cur_height]
  1481.         sub     ebx, 3
  1482. @@:
  1483.         call    viewer_next_newline
  1484.         jc      .ret
  1485.         dec     ebx
  1486.         jnz     @b
  1487.         call    viewer_draw_text
  1488.         ret
  1489. .up:
  1490.         call    viewer_seek_to_current
  1491.         call    viewer_prev_newline
  1492.         call    viewer_draw_text
  1493.         ret
  1494. .pgup:
  1495.         call    viewer_seek_to_current
  1496.         mov     ebx, [cur_height]
  1497.         sub     ebx, 3
  1498. @@:
  1499.         call    viewer_prev_newline
  1500.         dec     ebx
  1501.         jnz     @b
  1502. .done_redraw:
  1503.         call    viewer_draw_text
  1504. .ret:
  1505.         ret
  1506. .f8:
  1507.         movzx   esi, [ebp+viewer_data.encoding]
  1508.         dec     [ebp+viewer_data.encoding]
  1509.         jz      .done_redraw_keybar
  1510.         mov     [ebp+viewer_data.encoding], 1
  1511.         jmp     .done_redraw_keybar
  1512. .f2:
  1513.         xor     [ebp+viewer_data.flags], 2
  1514. .done_redraw_keybar:
  1515.         call    viewer_set_keybar
  1516.         jmp     .done_redraw
  1517. .f4:
  1518.         xor     [ebp+viewer_data.flags], 1
  1519.         pushf
  1520.         call    viewer_set_keybar
  1521.         popf
  1522.         jnz     .tohex
  1523.         push    1
  1524.         pop     eax
  1525.         cmp     [ebp+viewer_data.encoding], encodings.unicode
  1526.         jnz     @f
  1527.         add     eax, eax
  1528. @@:
  1529.         add     dword [ebp+viewer_data.cur_pos], eax
  1530.         adc     dword [ebp+viewer_data.cur_pos+4], 0
  1531.         call    viewer_seek_to_current
  1532.         call    viewer_prev_newline
  1533.         jmp     .done_redraw
  1534. .tohex:
  1535.         and     byte [ebp+viewer_data.cur_pos], 0xF0
  1536.         jmp     .done_redraw
  1537. .home:
  1538.         xor     eax, eax
  1539.         mov     dword [ebp+viewer_data.cur_pos], eax
  1540.         mov     dword [ebp+viewer_data.cur_pos+4], eax
  1541.         mov     dword [ebp+viewer_data.col], eax
  1542.         mov     dword [ebp+viewer_data.col+4], eax
  1543.         jmp     .done_redraw
  1544. .end:
  1545.         mov     eax, dword [ebp+viewer_data.filesize]
  1546.         mov     edx, dword [ebp+viewer_data.filesize+4]
  1547.         and     al, 0xF0
  1548.         mov     dword [ebp+viewer_data.cur_pos], eax
  1549.         mov     dword [ebp+viewer_data.cur_pos+4], edx
  1550.         and     dword [ebp+viewer_data.col], 0
  1551.         and     dword [ebp+viewer_data.col+4], 0
  1552.         jmp     .done_redraw
  1553. .right:
  1554.         add     dword [ebp+viewer_data.col], 1
  1555.         adc     dword [ebp+viewer_data.col+4], 0
  1556.         jnc     .done_redraw
  1557.         sub     dword [ebp+viewer_data.col], 1
  1558.         sbb     dword [ebp+viewer_data.col+4], 0
  1559.         ret
  1560. .left:
  1561.         sub     dword [ebp+viewer_data.col], 1
  1562.         sbb     dword [ebp+viewer_data.col+4], 0
  1563.         jnc     .done_redraw
  1564.         add     dword [ebp+viewer_data.col], 1
  1565.         adc     dword [ebp+viewer_data.col+4], 0
  1566.         ret
  1567. .ctrl_left:
  1568.         test    [ebp+viewer_data.flags], 1
  1569.         jnz     .ctrl_left_hex
  1570.         sub     dword [ebp+viewer_data.col], 20
  1571.         sbb     dword [ebp+viewer_data.col+4], 0
  1572.         jnc     .done_redraw
  1573. .ctrl_shift_left:
  1574.         and     dword [ebp+viewer_data.col], 0
  1575.         and     dword [ebp+viewer_data.col+4], 0
  1576.         jmp     .done_redraw
  1577. .ctrl_left_hex:
  1578.         call    viewer_seek_to_current
  1579.         call    viewer_get_prev_char
  1580.         jc      @f
  1581.         call    viewer_set_curpos
  1582.         jmp     .done_redraw
  1583. .ctrl_right:
  1584.         test    [ebp+viewer_data.flags], 1
  1585.         jnz     .ctrl_right_hex
  1586.         add     dword [ebp+viewer_data.col], 20
  1587.         adc     dword [ebp+viewer_data.col+4], 0
  1588.         jnc     .done_redraw
  1589.         sub     dword [ebp+viewer_data.col], 20
  1590.         sbb     dword [ebp+viewer_data.col+4], 0
  1591. @@:     ret
  1592. .ctrl_right_hex:
  1593.         call    viewer_seek_to_current
  1594.         call    viewer_get_next_char
  1595.         call    viewer_set_curpos
  1596.         jmp     .done_redraw
  1597. .ctrl_shift_right:
  1598.         test    [ebp+viewer_data.flags], 1
  1599.         jnz     @b
  1600.         mov     eax, dword [viewer_right_side]
  1601.         mov     edx, dword [viewer_right_side+4]
  1602.         sub     eax, [cur_width]
  1603.         sbb     edx, 0
  1604.         jnc     @f
  1605.         xor     eax, eax
  1606.         xor     edx, edx
  1607. @@:
  1608.         mov     dword [ebp+viewer_data.col], eax
  1609.         mov     dword [ebp+viewer_data.col+4], edx
  1610.         jmp     .done_redraw
  1611. .shift_f8:
  1612.         mov     ecx, encodings.menu.1
  1613.         mov     al, [ebp+viewer_data.encoding]
  1614. @@:
  1615.         cmp     byte [ecx-1], al
  1616.         jz      @f
  1617.         mov     ecx, [ecx]
  1618.         jmp     @b
  1619. @@:
  1620.         push    1
  1621.         push    aTables
  1622.         push    ecx
  1623.         call    menu
  1624.         cmp     eax, -1
  1625.         jz      .ret
  1626.         mov     al, [eax-1]
  1627.         mov     [ebp+viewer_data.encoding], al
  1628.         cmp     al, encodings.unicode
  1629.         jnz     .done_redraw_keybar
  1630.         add     dword [ebp+viewer_data.cur_pos], 1
  1631.         adc     dword [ebp+viewer_data.cur_pos+4], 0
  1632.         and     dword [ebp+viewer_data.cur_pos], not 1
  1633.         jmp     .done_redraw_keybar
  1634. .f7:
  1635.         call    viewer_clear_selection
  1636.         call    find_in_file_dlg
  1637.         jz      .shift_f7
  1638. .ret2:
  1639.         ret
  1640. .shift_f7:
  1641. ; search string SearchString in file starting from current position
  1642.         cmp     byte [SearchString], 0
  1643.         jz      .ret2
  1644.         mov     eax, dword [ebp+viewer_data.selected_start]
  1645.         mov     edx, dword [ebp+viewer_data.selected_start+4]
  1646.         inc     eax
  1647.         jnz     @f
  1648.         inc     edx
  1649. @@:
  1650.         cmp     dword [ebp+viewer_data.selected_len], 0
  1651.         jnz     @f
  1652.         cmp     dword [ebp+viewer_data.selected_len+4], 0
  1653.         jnz     @f
  1654.         mov     eax, dword [ebp+viewer_data.cur_pos]
  1655.         mov     edx, dword [ebp+viewer_data.cur_pos+4]
  1656. @@:
  1657.         call    viewer_clear_selection
  1658.         call    viewer_seek
  1659.         call    viewer_skip_unicode_marker
  1660.         mov     esi, tolower_table
  1661.         test    [find_in_file_dlgdata.flags_case], 10h
  1662.         jz      @f
  1663.         mov     esi, identical_table
  1664. @@:
  1665.         mov     ebx, SearchString
  1666.         test    [find_in_file_dlgdata.flags_whole], 10h
  1667.         setnz   al
  1668.         push    eax
  1669.         push    dword [ebp+viewer_data.encoding]
  1670.         call    search_string_pre
  1671.         mov     esi, [ebp+viewer_data.buf_pos]
  1672.         lea     ebx, [ebp+viewer_data.buf]
  1673.         add     ebx, [ebp+viewer_data.buf_size]
  1674.         mov     edi, edx
  1675.         cmp     esi, ebx
  1676.         jb      @f
  1677.         sub     ebx, ebp
  1678.         cmp     ebx, viewer_data.buf + 16384
  1679.         jnz     .f7.notfound
  1680.         pusha
  1681.         call    viewer_load_next
  1682.         popa
  1683.         jz      .f7.notfound
  1684.         mov     esi, [ebp+viewer_data.buf_pos]
  1685.         lea     ebx, [ebp+viewer_data.buf]
  1686.         add     ebx, [ebp+viewer_data.buf_size]
  1687. @@:
  1688.         test    [find_in_file_dlgdata.flags_whole], 10h
  1689.         jz      .search_loop
  1690.         cmp     dword [ebp+viewer_data.buf_start], 0
  1691.         jnz     @f
  1692.         cmp     dword [ebp+viewer_data.buf_start+4], 0
  1693.         jnz     @f
  1694.         lea     eax, [ebp+viewer_data.buf]
  1695.         cmp     [ebp+viewer_data.buf_pos], eax
  1696.         jz      .f7.startspace
  1697. @@:
  1698.         xor     eax, eax
  1699.         call    viewer_get_prev_char
  1700.         inc     esi
  1701.         cmp     [isspace_table+eax], 0
  1702.         jz      .search_loop
  1703. .f7.startspace:
  1704.         add     edi, 256
  1705. .search_loop:
  1706. ; edx -> FSM, ecx = last state, edi = current state,
  1707. ; esi = buf_pos, ebx = end of buffer
  1708. ; get current symbol
  1709.         movzx   eax, byte [esi]
  1710. ; calculate next state
  1711.         movzx   edi, byte [edi+eax]
  1712. ; done?
  1713.         cmp     edi, ecx
  1714.         jz      .f7.found
  1715. .search_loop_next:
  1716. ; no; proceed to next symbol
  1717.         shl     edi, 8
  1718.         add     esi, 1
  1719.         add     edi, edx
  1720.         cmp     esi, ebx
  1721.         jb      .search_loop
  1722.         sub     ebx, ebp
  1723.         cmp     ebx, viewer_data.buf + 16384
  1724.         jnz     .f7.notfound
  1725.         mov     [ebp+viewer_data.buf_pos], esi
  1726.         pusha
  1727.         call    viewer_load_next
  1728.         popa
  1729.         jz      .f7.notfoundt
  1730.         mov     esi, [ebp+viewer_data.buf_pos]
  1731.         lea     ebx, [ebp+viewer_data.buf]
  1732.         add     ebx, [ebp+viewer_data.buf_size]
  1733.         jmp     .search_loop
  1734. .f7.notfoundt:
  1735. ; last chance - if we are looking for a whole word, EOF is ok for last symbol
  1736.         test    [find_in_file_dlgdata.flags_whole], 10h
  1737.         jz      .f7.notfound
  1738.         movzx   edi, byte [edi+' ']
  1739.         inc     esi
  1740.         cmp     edi, ecx
  1741.         jz      .f7.found
  1742. .f7.notfound:
  1743.         call    search_failed
  1744.         jmp     .done_redraw
  1745. .f7.found:
  1746.         push    ecx
  1747.         mov     ecx, edx
  1748.         call    pgfree
  1749.         mov     [ebp+viewer_data.buf_pos], esi
  1750.         call    viewer_set_curpos
  1751.         pop     ecx
  1752.         mov     dword [ebp+viewer_data.selected_len], ecx
  1753.         and     dword [ebp+viewer_data.selected_len+4], 0
  1754.         dec     ecx
  1755.         sub     eax, ecx
  1756.         sbb     edx, 0
  1757.         mov     dword [ebp+viewer_data.selected_start], eax
  1758.         mov     dword [ebp+viewer_data.selected_start+4], edx
  1759.         inc     eax
  1760.         jnz     @f
  1761.         inc     edx
  1762. @@:
  1763.         test    [find_in_file_dlgdata.flags_whole], 10h
  1764.         jz      @f
  1765.         sub     dword [ebp+viewer_data.selected_len], 2
  1766.         sbb     dword [ebp+viewer_data.selected_len+4], 0
  1767.         mov     dword [ebp+viewer_data.selected_start], eax
  1768.         mov     dword [ebp+viewer_data.selected_start+4], edx
  1769.         inc     eax
  1770.         jnz     @f
  1771.         inc     edx
  1772. @@:
  1773.         mov     dword [ebp+viewer_data.cur_pos], eax
  1774.         mov     dword [ebp+viewer_data.cur_pos+4], edx
  1775.         call    viewer_seek
  1776.         call    viewer_prev_newline
  1777.         jmp     .done_redraw
  1778.  
  1779. search_failed:
  1780.         mov     ecx, edx
  1781.         call    pgfree
  1782.         mov     eax, SearchString-1
  1783.         push    dword [eax-3]
  1784.         push    eax
  1785.         mov     byte [eax], '"'
  1786. @@:
  1787.         inc     eax
  1788.         cmp     byte [eax], 0
  1789.         jnz     @b
  1790.         mov     word [eax], '"'
  1791.         xchg    eax, [esp]
  1792.         push    eax
  1793.         push    aStringNotFound
  1794.         mov     eax, esp
  1795.         push    ContinueBtn
  1796.         push    1
  1797.         push    eax
  1798.         push    2
  1799.         push    aSearch
  1800.         call    SayErrTitle
  1801.         pop     eax
  1802.         pop     eax
  1803.         pop     ecx
  1804.         mov     byte [ecx], 0
  1805.         pop     dword [eax-3]
  1806.         ret
  1807.  
  1808. viewer_getname:
  1809. if lang eq ru
  1810.         mov     eax, 'à®á'
  1811.         stosd
  1812.         mov     eax, '¬®âà'
  1813.         stosd
  1814.         mov     eax, '    '
  1815.         stosd
  1816.         stosb
  1817. else
  1818.         mov     eax, 'View'
  1819.         stosd
  1820.         mov     eax, '    '
  1821.         stosd
  1822.         stosd
  1823.         stosb
  1824. end if
  1825.         jmp     viewedit_getname
  1826. editor_getname:
  1827. if lang eq ru
  1828.         mov     eax, '¥¤ '
  1829.         stosd
  1830.         mov     eax, 'ªâ®à'
  1831.         stosd
  1832.         mov     eax, '    '
  1833.         stosd
  1834.         stosb
  1835. else
  1836.         mov     eax, 'Edit'
  1837.         stosd
  1838.         mov     eax, '    '
  1839.         stosd
  1840.         stosd
  1841.         stosb
  1842. end if
  1843. viewedit_getname:
  1844.         sub     ecx, 13
  1845.         cmp     [ebp+viewer_data.hPlugin], 0
  1846.         jz      .native
  1847.         lea     esi, [ebp+viewer_data.hostname]
  1848.         push    ecx edi
  1849.         shr     ecx, 1
  1850. @@:
  1851.         lodsb
  1852.         test    al, al
  1853.         jz      @f
  1854.         stosb
  1855.         loop    @b
  1856. @@:
  1857.         sub     edi, [esp]
  1858.         sub     [esp+4], edi
  1859.         add     [esp], edi
  1860.         pop     edi ecx
  1861.         lea     esi, [ebp+viewer_data.filename]
  1862.         jmp     .main
  1863. .native:
  1864.         lea     esi, [ebp+viewer_data.filename]
  1865.         push    3
  1866.         pop     edx
  1867. @@:
  1868.         lodsb
  1869.         stosb
  1870.         dec     ecx
  1871.         test    al, al
  1872.         jz      .ret
  1873.         cmp     al, '/'
  1874.         jnz     @b
  1875.         dec     edx
  1876.         jnz     @b
  1877. .main:
  1878.         push    esi
  1879. @@:
  1880.         lodsb
  1881.         test    al, al
  1882.         jnz     @b
  1883.         sub     esi, [esp]
  1884.         dec     esi
  1885.         cmp     esi, ecx
  1886.         jbe     @f
  1887.         mov     al, '.'
  1888.         stosb
  1889.         stosb
  1890.         stosb
  1891.         sub     ecx, 3
  1892.         sub     esi, ecx
  1893.         add     [esp], esi
  1894. @@:
  1895.         pop     esi
  1896. @@:
  1897.         lodsb
  1898.         stosb
  1899.         test    al, al
  1900.         jnz     @b
  1901. .ret:
  1902.         ret
  1903.