Subversion Repositories Kolibri OS

Rev

Rev 617 | Blame | Last modification | View Log | Download | RSS feed

  1. diff16 'tp-files.asm',0,$
  2.  
  3. ;-----------------------------------------------------------------------------
  4. proc save_file ;//////////////////////////////////////////////////////////////
  5. ;-----------------------------------------------------------------------------
  6.         mov     esi,tb_opensave.text
  7.         mov     edi,f_info.path
  8.         movzx   ecx,[tb_opensave.length]
  9.         mov     [f_info.length],ecx
  10.         cld
  11.         rep     movsb
  12.         mov     byte[edi],0
  13.  
  14.         mov     esi,[cur_editor.Lines]
  15.  
  16.         xor     ebx,ebx
  17.         mov     ecx,[cur_editor.Lines.Count]
  18.     @@: call    get_real_length
  19.         add     ebx,eax
  20.         movzx   eax,word[esi]
  21.         lea     esi,[esi+eax+4]
  22.         loop    @b
  23.         mov     eax,[cur_editor.Lines.Count]
  24.         shl     eax,1
  25.         lea     eax,[eax+ebx+1024]
  26.         stdcall mem.Alloc,eax
  27.         push    eax
  28.         mov     esi,[cur_editor.Lines]
  29.         mov     edi,eax
  30.  
  31.   .new_string:
  32.         call    save_string
  33.         cmp     dword[esi],0
  34.         jne     .new_string
  35.         pop     eax
  36.         sub     edi,eax
  37.         add     edi,-2                  ; minus last CRLF
  38.  
  39.   .systree_save:
  40.         mov     [f_info70+0],2
  41.         mov     [f_info70+12],edi
  42.         mov     [f_info70+16],eax
  43.         mov     byte[f_info70+20],0
  44.         mov     [f_info70+21],f_info.path
  45.         mcall   70,f_info70
  46.  
  47.         call    set_status_fs_error
  48.  
  49.         or      eax,eax
  50.         jnz     .exit.2
  51.  
  52.   .exit:
  53.         mov     [cur_editor.Modified],0
  54.         clc
  55.         ret
  56.  
  57.   .exit.2:
  58.         stc
  59.         ret
  60. endp
  61.  
  62. ;-----------------------------------------------------------------------------
  63. proc save_string ;////////////////////////////////////////////////////////////
  64. ;-----------------------------------------------------------------------------
  65.         movzx   ecx,word[esi]
  66.         test    dword[esi],0x00010000
  67.         jz      @f
  68.         or      dword[esi],0x00020000
  69.     @@: add     esi,4
  70.  
  71.     @@: cmp     byte[esi+ecx-1],' '
  72.         jne     @f
  73.         loop    @b
  74.     @@: jecxz   .endcopy
  75.         xor     edx,edx
  76.         mov     ebx,edx
  77.         mov     ah,dl
  78.  
  79.   .next_char:
  80.         mov     al,[esi+ebx]
  81.         inc     ebx
  82.         test    [options],OPTS_OPTIMSAVE
  83.         jz      .put
  84.         test    ah,00000001b
  85.         jnz     .char
  86.         cmp     al,'"'
  87.         jne     @f
  88.         xor     ah,00000100b
  89.         jmp     .char
  90.     @@: cmp     al,"'"
  91.         jne     @f
  92.         xor     ah,00000010b
  93.         jmp     .char
  94.     @@: test    ah,00000110b
  95.         jnz     .char
  96.         cmp     al,';'
  97.         jne     @f
  98.         test    ah,00000001b
  99.         jnz     .char
  100.         xor     ah,00000001b
  101.         jmp     .char
  102.     @@: cmp     al,' '
  103.         jne     .char
  104.         inc     edx
  105.         test    ebx,ATABW-1
  106.         jnz     @f
  107.         dec     edx
  108.         jle     .put
  109.         mov     al,9
  110.         xor     edx,edx
  111.         jmp     .put
  112.   .char:
  113.         or      edx,edx
  114.         jz      .put
  115.         push    ecx eax
  116.         mov     ecx,edx
  117.         mov     al,' '
  118.         rep     stosb
  119.         pop     eax ecx
  120.         xor     edx,edx
  121.   .put:
  122.         stosb
  123.     @@: loop    .next_char
  124.  
  125.   .endcopy:
  126.         mov     eax,0x0A0D
  127.         stosw
  128.         movzx   eax,word[esi-4]
  129.         add     esi,eax;[esi-4]
  130.         ret
  131. endp
  132.  
  133. proc set_status_fs_error
  134.         push    eax
  135.         mov     esi,s_fs_error
  136.     @@: dec     eax
  137.         js      @f
  138.         movzx   ecx,byte[esi]
  139.         lea     esi,[esi+ecx+1]
  140.         jmp     @b
  141.     @@: inc     esi
  142.         mov     [s_status],esi
  143.         pop     eax
  144.         call    draw_statusbar
  145.         ret
  146. endp
  147.  
  148. ;-----------------------------------------------------------------------------
  149. proc load_file ;//////////////////////////////////////////////////////////////
  150. ;-----------------------------------------------------------------------------
  151.         cmp     [tb_opensave.length],0
  152.         jne     @f
  153.         stc
  154.         ret
  155.  
  156.     @@: mov     esi,tb_opensave.text
  157.         mov     edi,f_info.path
  158.         movzx   ecx,[tb_opensave.length]
  159.         mov     [f_info.length],ecx
  160.         cld
  161.         rep     movsb
  162.         mov     byte[edi],0
  163.  
  164.         xor     eax,eax
  165.         mov     [f_info70+0],5
  166.         mov     [f_info70+4],eax
  167.         mov     [f_info70+8],eax
  168.         mov     [f_info70+12],eax
  169.         mov     [f_info70+16],file_info
  170.         mov     byte[f_info70+20],al
  171.         mov     [f_info70+21],f_info.path
  172.         mcall   70,f_info70
  173.         mov     [f_info70+0],0
  174.         mov     eax,dword[file_info.Size]
  175.         mov     [f_info70+12],eax
  176.         stdcall mem.Alloc,eax
  177.         mov     [f_info70+16],eax
  178.         mcall   70,f_info70
  179.  
  180.         call    set_status_fs_error
  181.  
  182.         mov     esi,[f_info70+16]
  183.  
  184.         xchg    eax,ebx
  185.         test    ebx,ebx
  186.         je      .file_found
  187.         cmp     ebx,6            ;// ATV driver fix (6 instead of 5)
  188.         je      .file_found
  189.  
  190.         stdcall mem.Free,[f_info70+16]
  191.         stc
  192.         ret
  193.  
  194.   .file_found:
  195.         mov     ecx,eax
  196.         cmp     [tab_bar.Items.Count],1
  197.         jne     @f
  198.         cmp     [cur_editor.FilePath],0
  199.         jne     @f
  200.         cmp     [cur_editor.Modified],0
  201.         jne     @f
  202.         mov     ebp,cur_editor
  203.         jmp     .lp1
  204.     @@: inc     [do_not_draw]
  205.         call    create_tab
  206.         dec     [do_not_draw]
  207.   .lp1: push    ecx esi edi
  208.         mov     esi,tb_opensave.text
  209.         lea     edi,[ebp+TABITEM.Editor.FilePath]
  210.         movzx   ecx,[tb_opensave.length]
  211.         cld
  212.         rep     movsb
  213.         mov     byte[edi],0
  214.         lea     edi,[ebp+TABITEM.Editor.FilePath]
  215.         movzx   ecx,[tb_opensave.length]
  216.         inc     ecx
  217.     @@: dec     ecx
  218.         jz      @f
  219.         cmp     byte[edi+ecx-1],'/'
  220.         jne     @b
  221.     @@: mov     [ebp+TABITEM.Editor.FileName],ecx
  222.         call    flush_cur_tab
  223.         pop     edi esi ecx
  224.         call    load_from_memory
  225.         stdcall mem.Free,[f_info70+16]
  226.  
  227.         xor     eax,eax
  228.         mov     [cur_editor.TopLeft.Y],eax
  229.         mov     [cur_editor.TopLeft.X],eax
  230.         mov     [cur_editor.Caret.X],eax
  231.         mov     [cur_editor.Caret.Y],eax
  232.         mov     [cur_editor.SelStart.X],eax
  233.         mov     [cur_editor.SelStart.Y],eax
  234.         mov     [cur_editor.Modified],al
  235.         mov     [cur_editor.AsmMode],al
  236.  
  237.         lea     ebx,[cur_editor.FilePath]
  238.         mov     eax,ebx
  239.         call    strlen
  240.         mov     ecx,dword[ebx+eax-3]
  241.         or      ecx,0x202020
  242.         cmp     ecx,'asm'
  243.         jne     @f
  244.         inc     [cur_editor.AsmMode]
  245.         jmp     .nocol
  246.     @@: cmp     ecx,'inc'
  247.         jne     .nocol
  248.         inc     [cur_editor.AsmMode]
  249.     .nocol:
  250.         call    update_caption
  251.  
  252.         clc
  253.         ret
  254. endp
  255.  
  256. ;-----------------------------------------------------------------------------
  257. proc load_from_memory ;///////////////////////////////////////////////////////
  258. ;-----------------------------------------------------------------------------
  259. ; ECX = data length
  260. ; ESI = data pointer
  261. ; EBP = EDITOR*
  262. ;-----------------------------------------------------------------------------
  263.         call    get_lines_in_file
  264.         mov     [ebp+EDITOR.Lines.Count],eax
  265.         lea     edx,[ebx+ecx]
  266.         imul    ebx,eax,14
  267.         add     ebx,edx
  268.         mov     [ebp+EDITOR.Lines.Size],ebx
  269.         stdcall mem.ReAlloc,[ebp+EDITOR.Lines],ebx
  270.         mov     [ebp+EDITOR.Lines],eax
  271.  
  272.         mov     [ebp+EDITOR.Columns.Count],0
  273.         mov     edi,eax
  274.         mov     edx,ecx
  275.  
  276.   .next_line:
  277.         mov     ebx,edi
  278.         add     edi,4
  279.   .next_char:
  280.         or      edx,edx
  281.         jle     .exit
  282.         lodsb
  283.         dec     edx
  284.         cmp     al,13
  285.         je      .CR
  286.         cmp     al,10
  287.         je      .LF
  288.         cmp     al,9
  289.         je      .TB
  290.         cmp     al,0
  291.         je      .exit
  292.         stosb
  293.         jmp     .next_char
  294.  
  295.   .exit:
  296.         mov     ecx,10
  297.         mov     al,' '
  298.         rep     stosb
  299.         lea     eax,[edi-4]
  300.         sub     eax,ebx
  301.         mov     [ebx],eax
  302.         mov     dword[ebx+eax+4],0
  303.         sub     eax,10
  304.         jnz     @f
  305.         inc     eax
  306.     @@: cmp     eax,[ebp+EDITOR.Columns.Count]
  307.         jbe     @f
  308.         mov     [ebp+EDITOR.Columns.Count],eax
  309.     @@: mov     [ebp+EDITOR.Modified],0
  310.         ret
  311.  
  312.   .CR:  cmp     byte[esi],10
  313.         jne     .LF
  314.         lodsb
  315.         dec     edx
  316.   .LF:  mov     ecx,10
  317.         mov     al,' '
  318.         rep     stosb
  319.         lea     eax,[edi-4]
  320.         sub     eax,ebx
  321.         mov     [ebx],eax
  322.         add     eax,-10
  323.         cmp     eax,[ebp+EDITOR.Columns.Count]
  324.         jbe     .next_line
  325.         mov     [ebp+EDITOR.Columns.Count],eax
  326.         jmp     .next_line
  327.  
  328.   .TB:  lea     eax,[edi-4]
  329.         sub     eax,ebx
  330.         mov     ecx,eax
  331.         add     ecx,ATABW
  332.         and     ecx,not(ATABW-1)
  333.         sub     ecx,eax
  334.         mov     al,' '
  335.         rep     stosb
  336.         jmp     .next_char
  337. endp
  338.