Subversion Repositories Kolibri OS

Rev

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

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