Subversion Repositories Kolibri OS

Rev

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