home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / LRTLSRC.RAR / LNXRES.PAS < prev   
Pascal/Delphi Source File  |  2000-08-15  |  3KB  |  126 lines

  1. {█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
  2. {█                                                       █}
  3. {█      Virtual Pascal for Linux                         █}
  4. {█      Resource support layer                           █}
  5. {█      ─────────────────────────────────────────────────█}
  6. {█      Copyright (C) 2000 vpascal.com                   █}
  7. {█      Copyright (C) 1999 Veit Kannegieser              █}
  8. {█                                                       █}
  9. {▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}
  10.  
  11. {$IFNDEF Linux}
  12.   Compile/Target Platform: Linux
  13. {$ENDIF}
  14. {$S-}
  15.  
  16. unit LnxRes;
  17.  
  18. interface
  19.  
  20. type
  21.   TLinux_Resource_Anchor = packed record
  22.     fPointer   : Pointer;
  23.     fLength    : Longint;
  24.     fSignature : Array[0..3] of Char;
  25.   end;
  26.  
  27.   // PE2LE:RESKONV.PAS:d32_reso_kopf
  28.   TLinux_Resource_Block = packed record
  29.     fLength    : Longint;
  30.     fType      : SmallWord;
  31.     fId        : SmallWord;
  32.   end;
  33.  
  34.   TLinux_Resource_Types = ( rt_ResourceString, rt_Binary );
  35.  
  36.   PLinux_Resource_String = ^TLinux_Resource_String;
  37.   TLinux_Resource_String = packed record
  38.     fLength    : SmallWord;
  39.     fStr       : Array[0..High(SmallWord)] of Char;
  40.   end;
  41.  
  42. const
  43.   Linux_Resource_Anchor : TLinux_Resource_Anchor = (
  44.     fPointer   : Ptr($b582cc18);
  45.     fLength    : $467a1d0e;
  46.     fSignature : 'RES?' );
  47.  
  48. function LnxGetResourceAddress(_Name, _Type: SmallWord): Pointer;
  49. function LnxGetResourceStringAddress(_Name: SmallWord) : PLinux_Resource_String;
  50.  
  51. implementation
  52.  
  53. function LnxGetResourceAddress(_Name, _Type: SmallWord): Pointer;
  54.   assembler; {$Frame-} {&Uses esi,edi}
  55. asm
  56.       sub   eax,eax // not found
  57.       cmp   [Linux_Resource_Anchor.fSignature],'OSER' // 'RESO'
  58.       jne   @Ret
  59.  
  60.       mov   esi,[Linux_Resource_Anchor.fPointer]
  61.       mov   edi,[Linux_Resource_Anchor.fLength]
  62.       add   edi,esi
  63.  
  64.       mov   dx,[_Name]
  65.       shl   edx,16
  66.       mov   dx,[_Type]
  67.  
  68.       jmp   @BeginSearch
  69.  
  70.     @ContinueSearch:
  71.       add   esi,[esi+TLinux_Resource_Block.fLength]
  72.  
  73.     @BeginSearch:
  74.       // End of Resource ?
  75.       cmp   esi,edi
  76.       je    @Ret
  77.  
  78.       // Longint containing both type and id
  79.       cmp   edx,[esi+TLinux_Resource_Block.fType].Longint
  80.       jne   @ContinueSearch
  81.  
  82.       // Found: Return address
  83.       lea   eax,[esi+type TLinux_Resource_Block]
  84.  
  85.     @Ret:
  86. end;
  87.  
  88. function LnxGetResourceStringAddress(_Name: SmallWord) : PLinux_Resource_String;
  89.   assembler; {&Frame-} {&Uses None}
  90. asm
  91.       movzx eax,[_Name]
  92.       shr   eax,4   // div 16
  93.       push  eax
  94.       push  rt_ResourceString
  95.       call  LnxGetResourceAddress
  96.  
  97.       test  eax,eax
  98.       jz    @Ret
  99.  
  100.       movzx ecx,[_Name]
  101.       and   ecx,15  // mod 16
  102.       test  ecx,ecx
  103.       jmp   @@1
  104.  
  105.     @SearchLoop:
  106.  
  107.       movzx edx,[eax].SmallWord
  108.       lea   eax,[eax+2+edx]
  109.       sub   ecx,1
  110.     @@1:
  111.       jnz   @SearchLoop
  112.  
  113.       cmp [eax].SmallWord,0
  114.       jne @ret
  115.  
  116.       // string with length 0 -> nil
  117.       sub eax,eax
  118.  
  119.     @ret:
  120. end;
  121.  
  122. initialization
  123.   if Linux_Resource_Anchor.fSignature = 'RES?' then
  124.     // Nothing; prevent smart linking
  125. end.
  126.