home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / whichd11.zip / whichdll.cmd < prev    next >
OS/2 REXX Batch file  |  1997-11-22  |  3KB  |  115 lines

  1. /*          
  2.  * whichdll.cmd
  3.  * Which DLL is used?
  4.  * 1997-10-26
  5.  */
  6.  
  7.  
  8. parse arg opt
  9. topt = translate( opt )
  10.  
  11. RET_NO_ERR = 0
  12. RET_NO_DLL = 1
  13. RET_NO_LIBPATH = 2
  14. RET_HELP = 4
  15. RET_NO_CONFIGSYS = 5
  16.  
  17. /* Help */
  18. if ('' = opt) | (pos('-H',topt) <> 0)  then
  19.   do
  20.   say ''
  21.   say 'whichdll -- V1.1, 1997-11-22, Rolf Lochbuehler <rolobue@ibm.net>'
  22.   say 'Purpose:'
  23.   say '  Determine which DLL is actually used because it resides in a directory'
  24.   say '  that is listed before others in the LIBPATH search path.'
  25.   say 'Usage:'
  26.   say '  whichdll [-h]'
  27.   say '  whichdll [-b DRIVE] [DLL]'
  28.   say 'Arguments:'
  29.   say '  (none)     Print this information'
  30.   say '  -b DRIVE   Letter of bootdrive (default: -b C)'
  31.   say '  -h         Print this information'
  32.   say '  DLL        Name of the DLL file to search for'
  33.   say 'Examples:'
  34.   say '  whichdll rexxutil'
  35.   say '  whichdll pmgpi.dll'
  36.   exit RET_HELP
  37.   end
  38.  
  39. /* Boot drive */
  40. i = pos( '-B', topt )
  41. if i <> 0 then
  42.   do
  43.   bootdrive = word( opt, i+1 )
  44.   dllfile = word( opt, i+2 )
  45.   end
  46. else
  47.   do
  48.   bootdrive = 'C'
  49.   dllfile = opt
  50.   end
  51.  
  52. /* Add file name extension if necessary */
  53. if 0 = pos('.DLL',dllfile) then
  54.   dllfile = dllfile'.DLL'
  55.  
  56. call rxfuncadd 'sysfiletree', 'rexxutil', 'sysfiletree'
  57.  
  58. /* Read value of LIBPATH from CONFIG.SYS */
  59. configsys = bootdrive':\config.sys'
  60. if '' = stream(configsys,'command','query exists') then
  61.   signal configsyserr
  62. call stream configsys, 'command', 'open read'
  63. do until pos('LIBPATH',translate(ln))
  64.   ln = linein( configsys )
  65.   if 0 = lines(configsys) then
  66.     do
  67.     call stream configsys, 'command', 'close'
  68.     signal libpatherr
  69.     end
  70. end
  71. call stream configsys, 'command', 'close'
  72.  
  73. /* Strip "LIBPATH = " */
  74. ln = strip( ln )
  75. ln = delstr( ln, 1, 7 )
  76. ln = strip( ln, 'leading' )
  77. ln = delstr( ln, 1, 1 )
  78. ln = strip( ln, 'leading' )
  79. ln = translate( ln, ' ', ';' )
  80.  
  81. /* Parse LIBPATH and search for DLL file */
  82. dlldir.0 = words( ln )
  83. do i = 1 to dlldir.0
  84.   dlldir.i = word( ln, i )
  85. end
  86. found = 0
  87. do i = 1 to dlldir.0 while 0 = found
  88.   file = dlldir.i || '\'dllfile
  89.   if 0 < length(stream(file,'command','query exist')) then
  90.     do
  91.     say file
  92.     found = 1
  93.     end
  94. end
  95. if 0 = found then
  96.   signal dllerr
  97.  
  98. exit RET_NO_ERR
  99.  
  100.  
  101. /* Error handling */
  102.  
  103. libpatherr:
  104.   say 'No LIBPATH variable found in' configsys'.'
  105.   exit RET_NO_LIBPATH
  106.  
  107. dllerr:
  108.   say 'No' dllfile 'found in' ln'.'
  109.   exit RET_NO_DLL
  110.  
  111. configsyserr:
  112.   say 'There is no' configsys'.'
  113.   exit RET_NO_CONFIGSYS
  114.  
  115.