Subversion Repositories Kolibri OS

Rev

Rev 280 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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