home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / orx8.zip / routine_find_file.cmd < prev    next >
OS/2 REXX Batch file  |  1997-07-21  |  4KB  |  94 lines

  1. /******************************************************************************/
  2. /*
  3. program:   routine_find_file.cmd
  4. type:      Object REXX, REXXSAA 6.0
  5. purpose:   filters a string to contain English alphanumeric chars only; embedded non-alphanum chars are
  6.            translated into an underscore ("_")
  7. version:   1.0
  8. date:      1997-04-15
  9. changed:   ---
  10.  
  11. author:    Rony G. Flatscher
  12.            Rony.Flatscher@wu-wien.ac.at
  13.            (Wirtschaftsuniversitaet Wien, University of Economics and Business
  14.            Administration, Vienna/Austria/Europe)
  15. needs:     ---
  16.  
  17. usage:     call or require & see code, resp. comments
  18.            (also, you might copy & paste the code to the desired module, given its size)
  19.  
  20. comments:  prepared for the "8th International Rexx Symposium 1997", April 1997, Heidelberg/Germany
  21.  
  22.  
  23. All rights reserved and copyrighted 1995-1997 by the author, no guarantee that
  24. it works without errors, etc.  etc.
  25.  
  26. You are granted the right to use this module under the condition that you don't charge money for this module (as you didn't write
  27. it in the first place) or modules directly derived from this module, that you document the original author (to give appropriate
  28. credit) with the original name of the module and that you make the unaltered, original source-code of this module available on
  29. demand.  If that holds, you may even bundle this module (either in source or compiled form) with commercial software.
  30.  
  31. If you find an error, please send me the description (preferably a *very* short example);
  32. I'll try to fix it and re-release it to the net.
  33. */
  34.  
  35.  
  36.  
  37. /*                                                                            */
  38. /* name:    Find_File( name[, env_var] [, extensions] )                       */
  39. /*                                                                            */
  40. /* purpose: find file and return fully qualified name                         */
  41. /*                                                                            */
  42. /* returns: .nil if not found, fully qualified name else                      */
  43. /*                                                                            */
  44. /* remarks: "env_var" ... environment variable containing list of paths,      */
  45. /*                        default: "path"                                     */
  46. /*                                                                            */
  47. /*          "extensions" ... blank delimited list of extensions to be added,  */
  48. /*                        if file was not found; default: ".cmd .orx .rex"    */
  49. /*                                                                            */
  50. /* needs:   ---                                                               */
  51. /*          rgf, 96-09-17                                                     */
  52.  
  53. :: ROUTINE Find_File     PUBLIC
  54.   USE ARG file_name, path, extensions
  55.  
  56.   IF \ VAR( "path" )       THEN path = ".;" || VALUE( "path", , "ENVIRONMENT" )
  57.   IF \ VAR( "extensions" ) THEN extensions = ".cmd .orx .rex .cls"
  58.  
  59.   name = FILESPEC("Name", file_name)    /* retrieve filename itself     */
  60.  
  61.   IF name = "" THEN                     /* indicate file not found      */
  62.      RETURN .nil
  63.  
  64.   foundName = search_path( name, path )
  65.   IF foundName = .nil THEN              /* not found so far             */
  66.   DO
  67.      DO WHILE extensions <> ""
  68.         PARSE VAR extensions tmpExtension extensions
  69.  
  70.         foundName = search_path( name || tmpExtension, path )
  71.         IF foundName <> .nil THEN       /* file found                   */
  72.            RETURN foundName
  73.      END
  74.  
  75.      RETURN .nil
  76.   END
  77.   ELSE
  78.      RETURN foundName
  79.  
  80. SEARCH_PATH : PROCEDURE
  81.   USE ARG name, path
  82.  
  83.   DO WHILE path <> ""           /* loop thru paths, try to find file */
  84.      PARSE VAR path cur_path ";" path
  85.  
  86.      IF RIGHT( cur_path, 1 ) = "\" THEN tmp_file = cur_path || name
  87.                                    ELSE tmp_file = cur_path || "\" || name
  88.      tmp_file = STREAM(tmp_file, "C", "QUERY EXISTS")
  89.      IF tmp_file <> "" THEN
  90.         RETURN tmp_file
  91.   END
  92.   RETURN .nil                   /* file not found               */
  93. /******************************************************************************/
  94.