Subversion Repositories Kolibri OS

Rev

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

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