Subversion Repositories Kolibri OS

Rev

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

  1. ;14.04.2009 - a macros for code load library the box_lib.obj from '/sys/lib/' or current dirrectory.
  2. ; The macros for load any library/libraries:
  3. ; Copyright (c) 2009, <Lrz>
  4. ; All rights reserved.
  5. ;
  6. ; Redistribution and use in source and binary forms, with or without
  7. ; modification, are permitted provided that the following conditions are met:
  8. ;       * Redistributions of source code must retain the above copyright
  9. ;       notice, this list of conditions and the following disclaimer.
  10. ;       * Redistributions in binary form must reproduce the above copyright
  11. ;       notice, this list of conditions and the following disclaimer in the
  12. ;       documentation and/or other materials provided with the distribution.
  13. ;       * Neither the name of the <organization> nor the
  14. ;       names of its contributors may be used to endorse or promote products
  15. ;       derived from this software without specific prior written permission.
  16. ;
  17. ; THIS SOFTWARE IS PROVIDED BY Alexey Teplov aka <Lrz> ''AS IS'' AND ANY
  18. ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. ; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  21. ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. ;*****************************************************************************
  28. ; This macros based on source code:
  29. ; <Lrz> - Alexey Teplov / Àëåêñåé Òåïëîâ
  30. ; Mario79, Mario - Marat Zakiyanov / Ìàðàò Çàêèÿíîâ
  31. ; Diamondz - Evgeny Grechnikov / Åâãåíèé Ãðå÷íèêîâ
  32. ;------------------------
  33. ; DESCRIPTION
  34. ; Macro load_library
  35. ; Logick of work.
  36. ; A first time we must to check system path, where I belive find a system library. System path is "/sys/lib/".
  37. ; If I cannot found my library, i must to check second way. Second way is current dirrectory.
  38. ; If we cannot load library, we must show the error message:
  39. ; "I'm sorry,the programm cannot found system library box_lib.obj."
  40. ; "The find was make on 2 ways: /sys/lib/ and current dirrectory."
  41. ;
  42. ; ebx,library_name
  43. ; esi,cur_dir_path
  44. ; edi,library_path
  45. ;---------------------------------------------------------------------
  46. ; Macro test_load_library
  47. ; A first time we must to check own path in current dirrectory the program, where I belive find a system library.
  48. ; If I cannot found my library, i must to check second way. Second way is system path a "/sys/lib/".
  49. ; If we cannot load library, we must show the error message:
  50. ; "I'm sorry,the programm cannot found system library box_lib.obj."
  51. ; "The find was make on 2 ways: /sys/lib/ and current dirrectory."
  52.  
  53. macro load_library library_name, cur_dir_path, library_path, system_path, err_message_found_lib, head_f_l, myimport, err_message_import, head_f_i
  54. {
  55. local end_steep
  56. ;---------------------------------------------------------------------  
  57. ; loading Box_Lib library
  58.  
  59.         mcall   68,19,system_path   ; load of sys directory
  60.         test    eax,eax
  61.         jnz     end_steep
  62.  
  63.         mov     ebx,library_name
  64.         mov     esi,cur_dir_path
  65.         mov     edi,library_path
  66.  
  67.         copy_path       ;the macros making way /current pach a program/+ name system library
  68.        
  69.         mcall   68,19,library_path ; load of alternative
  70.         test    eax,eax
  71.         jnz     end_steep
  72.  
  73.         show_error_window  err_message_found_lib, head_f_l    ;show error message /create window
  74.  
  75. end_steep:
  76.  
  77.         import_boxlib myimport, err_message_import, head_f_i  ;import
  78. ;---------------------------------------------------------------------
  79. }
  80.  
  81.  
  82. macro test_load_library library_name, cur_dir_path, library_path, system_path, err_message_found_lib, head_f_l, myimport, err_message_import, head_f_i
  83. {
  84. local end_steep
  85. ;---------------------------------------------------------------------  
  86. ; loading Box_Lib library
  87.         mov     ebx,library_name
  88.         mov     esi,cur_dir_path
  89.         mov     edi,library_path
  90.  
  91.         copy_path       ;the macros making way /current pach a program/+ name system library
  92.  
  93.         mcall   68,19,library_path ; load of alternative
  94.         test    eax,eax
  95.         jnz     end_steep
  96.        
  97.         mcall   68,19,system_path ; load of sys directory
  98.         test    eax,eax
  99.         jnz     end_steep
  100.  
  101.         show_error_window  err_message_found_lib, head_f_l    ;show error message /create window
  102.  
  103. end_steep:
  104.  
  105.         import_boxlib myimport, err_message_import, head_f_i  ;import
  106. ;---------------------------------------------------------------------
  107. }
  108.  
  109. macro load_libraries library_name, cur_dir_path, library_path, system_path, err_message_found_lib, head_f_l, myimport, err_message_import, head_f_i
  110. {
  111. local end_steep
  112. ;---------------------------------------------------------------------  
  113. ; loading Box_Lib library
  114.  
  115.         mcall   68,19,system_path   ; load of sys directory
  116.         test    eax,eax
  117.         jnz     end_steep
  118.  
  119.         mov     ebx,library_name
  120.         mov     esi,cur_dir_path
  121.         mov     edi,library_path
  122.  
  123.         copy_path       ;the macros making way /current pach a program/+ name system library
  124.        
  125.         mcall   68,19,library_path ; load of alternative
  126.         test    eax,eax
  127.         jnz     end_steep
  128.  
  129.         show_error_window  err_message_found_lib, head_f_l    ;show error message /create window
  130.  
  131. end_steep:
  132.  
  133.         import_boxlib myimport, err_message_import, head_f_i  ;import
  134. ;---------------------------------------------------------------------
  135. }
  136.  
  137.  
  138.  
  139.  
  140. macro copy_path
  141. {
  142. local copy_path
  143. ;---------------------------------------------------------------------
  144. ;        mov     ebx,library_name
  145. ;        mov     esi,cur_dir_path
  146. ;        mov     edi,library_path
  147.  
  148. copy_path:
  149.         xor     eax,eax
  150.         cld
  151. .lp1:
  152.         lodsb
  153.         stosb
  154.         test    eax,eax
  155.         jnz     .lp1
  156.         mov     esi,edi
  157.  
  158.         std
  159. .lp2:
  160.         lodsb
  161.         cmp     al,'/'
  162.         jnz     .lp2
  163.         mov     edi,esi
  164.         mov     esi,ebx
  165.         add     edi,2
  166.  
  167.  
  168.         cld
  169. .lp3:
  170.         lodsb
  171.         stosb
  172.         test    eax,eax
  173.         jnz     .lp3
  174. ;---------------------------------------------------------------------
  175. }
  176.  
  177. macro show_error_window  err_message, head
  178. {
  179. local red_win
  180. local still
  181. local button
  182.  
  183.         mcall   40,0x5         ;set mask on events rewraw window and get id button.
  184. red_win:
  185. ;draw_window:
  186.         mcall 12, 1
  187.         mcall 0, <0,300>, <0,100>, 0x33AABBCC, 0x805080D0, head
  188.         mcall 4, <10,10>, 0x90000000, err_message; _found_lib
  189.         mcall 12, 2
  190. align 4
  191. still:                          ;main loop
  192.         mcall   10              ;wait event
  193.         dec  eax
  194.         jz   red_win
  195.        
  196.         sub  eax,2
  197.         jnz  still   ;go to main loop
  198. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  199. button:
  200.         mcall   17      ;get id button
  201.         test    ah,ah      ;if in ah 0, then go to still
  202.         jz      still
  203.         mcall   -1
  204. }
  205.  
  206. macro import_boxlib myimport, err_message_import, head_f_i
  207. {
  208. local import_loop
  209. local import_find
  210. local lp
  211. local import_find_next
  212. local import_found
  213. local import_done
  214. local exit
  215. ; initialize import
  216.         mov     edx, eax
  217.         mov     esi,myimport
  218. import_loop:
  219.         lodsd
  220.         test    eax, eax
  221.         jz      import_done
  222.         push    edx
  223. import_find:
  224.         mov     ebx, [ds:edx]
  225.         test    ebx, ebx
  226.         jz      exit   ;import_not_found
  227.         push    eax
  228. lp:
  229.         mov     cl, [ds:eax]
  230.         cmp     cl, [ds:ebx]
  231.         jnz     import_find_next
  232.         test    cl, cl
  233.         jz      import_found
  234.         inc     eax
  235.         inc     ebx
  236.         jmp     lp
  237. import_find_next:
  238.         pop     eax
  239.         add     edx, 8
  240.         jmp     import_find
  241. import_found:
  242.         pop     eax
  243.         mov     eax, [ds:edx+4]
  244.         mov     [esi-4], eax
  245.         pop     edx
  246.         jmp     import_loop
  247. exit:
  248.         add     esp,4
  249.  
  250.         show_error_window  err_message_import, head_f_i    ;show error message /create window
  251.  
  252. import_done:
  253. ;---------------------------------------------------------------------
  254. }