home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / loccmds2.zip / locl.cmd < prev    next >
OS/2 REXX Batch file  |  1998-08-25  |  3KB  |  85 lines

  1. /* LocL - REXX program to search all paths of the 'PATH' statement for possible
  2.           resolutions to the specified argument (program).
  3.  
  4.    RRC 02/11/97 initial version - Note: should look for '.cmd' & '.exe'
  5. */
  6.  
  7. call RxFuncAdd SysLoadFuncs, RexxUtil, SysLoadFuncs
  8. call SysLoadFuncs
  9.  
  10. '@echo off'
  11.  
  12. PARSE ARG FileName .
  13.  
  14. if FileName = "" then
  15. do
  16.     say 'No arguments given.'
  17.     say ''
  18.     say 'LocL FileName'
  19.     say ''
  20.     say 'Locate where in your "libpath" string a file exists.  Requires one parameter.'
  21.     say 'The first parameter must be the first few letters of a filename to search for.'
  22.     say ''
  23.     exit
  24. end
  25.  
  26.      /* get boot drive letter from environment */
  27.      /* Other candidates for the env string to get the boot drive from:
  28.           ULSPATH, EPMPATH, DMIPATH, I18NDIR, MMBASE    */
  29. BootDrive=left(value('GLOSSARY',,'OS2ENVIRONMENT'),2)
  30. ProdConfig=BootDrive || '\CONFIG.SYS'
  31. rc = SysFileSearch('LIBPATH', ProdConfig, 'libp.')
  32. /* If file was found, set rc to 0 iff there was at least one occurrence of
  33.    the search string (note that rc = logical compare of libp.0 = 0) */
  34. if rc = 0 then rc = libp.0 = 0
  35. if rc <> 0 then do
  36.         say "Cannot find a libpath statement in "ProdConfig
  37.         pause
  38.         exit
  39. end
  40.  
  41. lix = libp.0                            /* Point to last occurrence           */
  42. DO FOREVER                              /* Until we find a real one           */
  43.  
  44.   PARSE UPPER VALUE libp.lix WITH LPCmd '=' CmdTail
  45.   IF LPCmd = 'LIBPATH' THEN DO          /* If this is a LIBPATH command       */
  46.     LEAVE                               /* This was the final LIBPATH -- done */
  47.   END
  48.  
  49.   lix = lix-1                           /* Check for an earlier statement     */
  50.   IF lix = 0 THEN DO                    /* If we just ran out of candidates   */
  51.     say "Cannot find a legitimate libpath statement in "ProdConfig
  52.     pause
  53.     exit
  54.   END
  55. END
  56.  
  57. /* CmdTail is everything past the '=' sign in CAPs, libp.lix is original line */
  58. WorkPath=CmdTail
  59.  
  60.  
  61. do FOREVER                              /* Until 'exit'                       */
  62.  
  63.   PARSE VAR WorkPath SearchPath';'WorkPath  /* Pull consecutive 'path's       */
  64.  
  65.   if SearchPath = '' THEN DO            /* If we've run out                   */
  66.  
  67.     exit 0                              /* And done                           */
  68.   END
  69.  
  70.   SearchPath = STRIP(SearchPath)        /* Remove blanks (should not be!)     */
  71.   if RIGHT( SearchPath, 1 ) = '\'       /* If this path ends in bs            */
  72.   THEN SearchPath = LEFT(SearchPath, LENGTH(SearchPath)-1)  /* Strip it       */
  73.  
  74.   rc = SysFileTree( SearchPath||'\'||FileName||'*', 'MatchList', 'F' )
  75.   if rc <> 0 then do
  76.     say 'Serious error: insufficient memory to run SysFileTree.  Error 'rc
  77.     exit 3
  78.   END
  79.  
  80.   DO ii=1 to MatchList.0
  81.     say MatchList.ii
  82.   END
  83.  
  84. END
  85.