Subversion Repositories Kolibri OS

Rev

Rev 543 | Rev 750 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;-------------------------------------------------------------------------
  2. ;
  3. ;  File path partial substitution (according to configuration)
  4. ;
  5. ;
  6. ;     SPraid
  7. ;
  8. ;-------------------------------------------------------------------------
  9.  
  10. $Revision: 593 $
  11.  
  12.  
  13. iglobal
  14. ; pointer to memory for path replace table,
  15. ; size of one record is 128 bytes: 64 bytes for search pattern + 64 bytes for replace string
  16.  
  17. ; start with one entry: sys -> <sysdir>
  18. full_file_name_table dd sysdir_name
  19. .size           dd      1
  20.  
  21. tmp_file_name_size dd   1
  22. endg
  23.  
  24. uglobal
  25. ; Parser_params will initialize: sysdir_name = "sys", sysdir_path = <sysdir>
  26. sysdir_name     rb      64
  27. sysdir_path     rb      64
  28. tmp_file_name_table dd  ?
  29. endg
  30.  
  31. ; use bx_from_load and init system directory /sys
  32. proc Parser_params
  33. locals
  34.   buff db 4 dup(?)              ; for test cd
  35. endl
  36.   mov eax,[OS_BASE+0x10000+bx_from_load]
  37.   mov ecx,sysdir_path
  38.   mov [ecx-64],dword 'sys'
  39.   cmp al,'r' ; if ram disk
  40.   jnz @f
  41.   mov [ecx],dword 'RD/?'
  42.   mov [ecx+3],byte ah
  43.   mov [ecx+4],byte 0
  44.   ret
  45. @@:
  46.   cmp al,'m' ; if ram disk
  47.   jnz @f
  48.   mov [ecx],dword 'CD?/'        ; if cd disk {m}
  49.   mov [ecx+4],byte '1'
  50.   mov [ecx+5],dword '/KOL'
  51.   mov [ecx+9],dword 'IBRI'
  52.   mov [ecx+13],byte 0
  53. .next_cd:
  54.   mov [ecx+2],byte ah
  55.   inc ah
  56.   cmp ah,'5'
  57.   je  .not_found_cd
  58.   lea edx,[buff]
  59.   pushad
  60.   stdcall read_file,read_firstapp,edx,0,4
  61.   popad
  62.   cmp [edx],dword 'MENU'
  63.   jne .next_cd
  64.   jmp .ok
  65.  
  66. @@:
  67.   sub al,49
  68.   mov [ecx],dword 'HD?/'        ; if hard disk
  69.   mov [ecx+2],byte al
  70.   mov [ecx+4],byte ah
  71.   mov [ecx+5],dword '/KOL'
  72.   mov [ecx+9],dword 'IBRI'
  73.   mov [ecx+13],byte 0
  74. .ok:
  75. .not_found_cd:
  76.   ret
  77. endp
  78.  
  79. proc load_file_parse_table
  80.   stdcall kernel_alloc,0x1000
  81.   mov [tmp_file_name_table],eax
  82.   mov edi,eax
  83.   mov esi,sysdir_name
  84.   mov ecx,128/4
  85.   rep movsd
  86.  
  87.   invoke ini.enum_keys,conf_fname,conf_path_sect,get_every_key
  88.  
  89.   mov eax,[tmp_file_name_table]
  90.   mov [full_file_name_table],eax
  91.   mov eax,[tmp_file_name_size]
  92.   mov [full_file_name_table.size],eax
  93.   ret
  94. endp
  95.  
  96. uglobal
  97. def_val_1 db 0
  98. endg
  99.  
  100. proc get_every_key stdcall, f_name, sec_name, key_name
  101.         mov     esi, [key_name]
  102.         mov     ecx, esi
  103.         cmp     byte [esi], '/'
  104.         jnz     @f
  105.         inc     esi
  106. @@:
  107.         mov     edi, [tmp_file_name_size]
  108.         shl     edi, 7
  109.         cmp     edi, 0x1000
  110.         jae     .stop_parse
  111.         add     edi, [tmp_file_name_table]
  112.         lea     ebx, [edi+64]
  113. @@:
  114.         cmp     edi, ebx
  115.         jae     .skip_this_key
  116.         lodsb
  117.         test    al, al
  118.         jz      @f
  119.         or      al, 20h
  120.         stosb
  121.         jmp     @b
  122. @@:
  123.         stosb
  124.  
  125.         invoke  ini.get_str, [f_name],[sec_name],ecx,ebx,64,def_val_1
  126.  
  127.         cmp     byte [ebx], '/'
  128.         jnz     @f
  129.         lea     esi, [ebx+1]
  130.         mov     edi, ebx
  131.         mov     ecx, 63
  132.         rep     movsb
  133. @@:
  134.         push    ebp
  135.         mov     ebp, [tmp_file_name_table]
  136.         mov     ecx, [tmp_file_name_size]
  137.         jecxz   .noreplace
  138.         mov     eax, ecx
  139.         dec     eax
  140.         shl     eax, 7
  141.         add     ebp, eax
  142. .replace_loop:
  143.         mov     edi, ebx
  144.         mov     esi, ebp
  145. @@:
  146.         lodsb
  147.         test    al, al
  148.         jz      .doreplace
  149.         mov     dl, [edi]
  150.         inc     edi
  151.         test    dl, dl
  152.         jz      .replace_loop_cont
  153.         or      dl, 20h
  154.         cmp     al, dl
  155.         jz      @b
  156.         jmp     .replace_loop_cont
  157. .doreplace:
  158.         cmp     byte [edi], 0
  159.         jz      @f
  160.         cmp     byte [edi], '/'
  161.         jnz     .replace_loop_cont
  162. @@:
  163.         lea     esi, [ebp+64]
  164.         call    .replace
  165.         jc      .skip_this_key2
  166. .replace_loop_cont:
  167.         sub     ebp, 128
  168.         loop    .replace_loop
  169. .noreplace:
  170.         pop     ebp
  171.  
  172.         inc     [tmp_file_name_size]
  173. .skip_this_key:
  174.         xor     eax, eax
  175.         inc     eax
  176.         ret
  177. .skip_this_key2:
  178.         pop     ebp
  179.         jmp     .skip_this_key
  180. .stop_parse:
  181.         xor     eax, eax
  182.         ret
  183. endp
  184.  
  185. proc get_every_key.replace
  186. ; in: ebx->destination, esi->first part of name, edi->second part of name
  187. ; maximum length is 64 bytes
  188. ; out: CF=1 <=> overflow
  189. ; 1) allocate temporary buffer in stack
  190.         sub     esp, 64
  191. ; 2) save second part of name to temporary buffer
  192.         push    esi
  193.         lea     esi, [esp+4]    ; esi->tmp buffer
  194.         xchg    esi, edi        ; edi->tmp buffer, esi->source
  195. @@:
  196.         lodsb
  197.         stosb
  198.         test    al, al
  199.         jnz     @b
  200. ; 3) copy first part of name to destination
  201.         pop     esi
  202.         mov     edi, ebx
  203. @@:
  204.         lodsb
  205.         test    al, al
  206.         jz      @f
  207.         stosb
  208.         jmp     @b
  209. @@:
  210. ; 4) restore second part of name from temporary buffer to destination
  211. ; (may cause overflow)
  212.         lea     edx, [ebx+64]   ; limit of destination
  213.         mov     esi, esp
  214. @@:
  215.         cmp     edi, edx
  216.         jae     .overflow
  217.         lodsb
  218.         stosb
  219.         test    al, al
  220.         jnz     @b
  221. ; all is OK
  222.         add     esp, 64         ; CF is cleared
  223.         ret
  224. .overflow:
  225. ; name is too long
  226.         add     esp, 64
  227.         stc
  228.         ret
  229. endp
  230.