Subversion Repositories Kolibri OS

Rev

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