Subversion Repositories Kolibri OS

Rev

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

  1. ;-----------------------------------------------------------------------------
  2. proc 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.         stdcall mem.Alloc,eax
  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. endp
  59.  
  60. ;-----------------------------------------------------------------------------
  61. proc 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. endp
  130.  
  131. proc 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. endp
  145.  
  146. ;-----------------------------------------------------------------------------
  147. proc load_file ;//////////////////////////////////////////////////////////////
  148. ;-----------------------------------------------------------------------------
  149.         cmp     [tb_opensave.length],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.         stdcall mem.Alloc,eax
  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.         stdcall mem.Free,[f_info70+16]
  189.         stc
  190.         ret
  191.  
  192.   .file_found:
  193.         mov     ecx,eax
  194.         cmp     [tab_bar.Items.Count],1
  195.         jne     @f
  196.         cmp     [cur_editor.FilePath],0
  197.         jne     @f
  198.         cmp     [cur_editor.Modified],0
  199.         jne     @f
  200.         mov     ebp,cur_editor
  201.         jmp     .lp1
  202.     @@: inc     [do_not_draw]
  203.         call    create_tab
  204.         dec     [do_not_draw]
  205.   .lp1: push    ecx esi edi
  206.         mov     esi,tb_opensave.text
  207.         lea     edi,[ebp+TABITEM.Editor.FilePath]
  208.         movzx   ecx,[tb_opensave.length]
  209.         cld
  210.         rep     movsb
  211.         mov     byte[edi],0
  212.         lea     edi,[ebp+TABITEM.Editor.FilePath]
  213.         movzx   ecx,[tb_opensave.length]
  214.         inc     ecx
  215.     @@: dec     ecx
  216.         jz      @f
  217.         cmp     byte[edi+ecx-1],'/'
  218.         jne     @b
  219.     @@: mov     [ebp+TABITEM.Editor.FileName],ecx
  220.         call    flush_cur_tab
  221.         pop     edi esi ecx
  222.         call    load_from_memory
  223.         stdcall mem.Free,[f_info70+16]
  224.  
  225.         xor     eax,eax
  226.         mov     [cur_editor.TopLeft.Y],eax
  227.         mov     [cur_editor.TopLeft.X],eax
  228.         mov     [cur_editor.Caret.X],eax
  229.         mov     [cur_editor.Caret.Y],eax
  230.         mov     [cur_editor.SelStart.X],eax
  231.         mov     [cur_editor.SelStart.Y],eax
  232.         mov     [cur_editor.Modified],al
  233.         mov     [cur_editor.AsmMode],al
  234.  
  235.         lea     ebx,[cur_editor.FilePath]
  236.         mov     eax,ebx
  237.         call    strlen
  238.         mov     ecx,dword[ebx+eax-3]
  239.         or      ecx,0x202020
  240.         cmp     ecx,'asm'
  241.         jne     @f
  242.         inc     [cur_editor.AsmMode]
  243.         jmp     .nocol
  244.     @@: cmp     ecx,'inc'
  245.         jne     .nocol
  246.         inc     [cur_editor.AsmMode]
  247.     .nocol:
  248.         call    update_caption
  249.  
  250.         clc
  251.         ret
  252. endp
  253.  
  254. ;-----------------------------------------------------------------------------
  255. proc load_from_memory ;///////////////////////////////////////////////////////
  256. ;-----------------------------------------------------------------------------
  257. ; ECX = data length
  258. ; ESI = data pointer
  259. ; EBP = EDITOR*
  260. ;-----------------------------------------------------------------------------
  261.         call    get_lines_in_file
  262.         mov     [ebp+EDITOR.Lines.Count],eax
  263.         lea     edx,[ebx+ecx]
  264.         imul    ebx,eax,14
  265.         add     ebx,edx
  266.         mov     [ebp+EDITOR.Lines.Size],ebx
  267.         stdcall mem.ReAlloc,[ebp+EDITOR.Lines],ebx
  268.         mov     [ebp+EDITOR.Lines],eax
  269.  
  270.         mov     [ebp+EDITOR.Columns.Count],0
  271.         mov     edi,eax
  272.         mov     edx,ecx
  273.  
  274.   .next_line:
  275.         mov     ebx,edi
  276.         add     edi,4
  277.   .next_char:
  278.         or      edx,edx
  279.         jle     .exit
  280.         lodsb
  281.         dec     edx
  282.         cmp     al,13
  283.         je      .CR
  284.         cmp     al,10
  285.         je      .LF
  286.         cmp     al,9
  287.         je      .TB
  288.         cmp     al,0
  289.         je      .exit
  290.         stosb
  291.         jmp     .next_char
  292.  
  293.   .exit:
  294.         mov     ecx,10
  295.         mov     al,' '
  296.         rep     stosb
  297.         lea     eax,[edi-4]
  298.         sub     eax,ebx
  299.         mov     [ebx],eax
  300.         mov     dword[ebx+eax+4],0
  301.         sub     eax,10
  302.         jnz     @f
  303.         inc     eax
  304.     @@: cmp     eax,[ebp+EDITOR.Columns.Count]
  305.         jbe     @f
  306.         mov     [ebp+EDITOR.Columns.Count],eax
  307.     @@: mov     [ebp+EDITOR.Modified],0
  308.         ret
  309.  
  310.   .CR:  cmp     byte[esi],10
  311.         jne     .LF
  312.         lodsb
  313.         dec     edx
  314.   .LF:  mov     ecx,10
  315.         mov     al,' '
  316.         rep     stosb
  317.         lea     eax,[edi-4]
  318.         sub     eax,ebx
  319.         mov     [ebx],eax
  320.         add     eax,-10
  321.         cmp     eax,[ebp+EDITOR.Columns.Count]
  322.         jbe     .next_line
  323.         mov     [ebp+EDITOR.Columns.Count],eax
  324.         jmp     .next_line
  325.  
  326.   .TB:  lea     eax,[edi-4]
  327.         sub     eax,ebx
  328.         mov     ecx,eax
  329.         add     ecx,ATABW
  330.         and     ecx,not(ATABW-1)
  331.         sub     ecx,eax
  332.         mov     al,' '
  333.         rep     stosb
  334.         jmp     .next_char
  335. endp
  336.