home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl502b.zip / lib / auto / DynaLoader / dl_findfile.al < prev   
Text File  |  1996-02-20  |  3KB  |  81 lines

  1. # NOTE: Derived from lib/DynaLoader.pm.  Changes made here will be lost.
  2. package DynaLoader;
  3.  
  4. sub dl_findfile {
  5.     # Read ext/DynaLoader/DynaLoader.doc for detailed information.
  6.     # This function does not automatically consider the architecture
  7.     # or the perl library auto directories.
  8.     my (@args) = @_;
  9.     my (@dirs,  $dir);   # which directories to search
  10.     my (@found);         # full paths to real files we have found
  11.     my $dl_so = $Config::Config{'so'};    # suffix for shared libraries
  12.  
  13.     print STDERR "dl_findfile(@args)\n" if $dl_debug;
  14.  
  15.     # accumulate directories but process files as they appear
  16.     arg: foreach(@args) {
  17.         #  Special fast case: full filepath requires no search
  18.         if ($Is_VMS && m%[:>/\]]% && -f $_) {
  19.         push(@found,dl_expandspec(VMS::Filespec::vmsify($_)));
  20.         last arg unless wantarray;
  21.         next;
  22.         }
  23.         elsif (m:/: && -f $_ && !$do_expand) {
  24.         push(@found,$_);
  25.         last arg unless wantarray;
  26.         next;
  27.     }
  28.  
  29.         # Deal with directories first:
  30.         #  Using a -L prefix is the preferred option (faster and more robust)
  31.         if (m:^-L:) { s/^-L//; push(@dirs, $_); next; }
  32.  
  33.         #  Otherwise we try to try to spot directories by a heuristic
  34.         #  (this is a more complicated issue than it first appears)
  35.         if (m:/: && -d $_) {   push(@dirs, $_); next; }
  36.  
  37.         # VMS: we may be using native VMS directry syntax instead of
  38.         # Unix emulation, so check this as well
  39.         if ($Is_VMS && /[:>\]]/ && -d $_) {   push(@dirs, $_); next; }
  40.  
  41.         #  Only files should get this far...
  42.         my(@names, $name);    # what filenames to look for
  43.         if (m:-l: ) {          # convert -lname to appropriate library name
  44.             s/-l//;
  45.             push(@names,"lib$_.$dl_so");
  46.             push(@names,"lib$_.a");
  47.         } else {                # Umm, a bare name. Try various alternatives:
  48.             # these should be ordered with the most likely first
  49.             push(@names,"$_.$dl_so")     unless m/\.$dl_so$/o;
  50.             push(@names,"lib$_.$dl_so")  unless m:/:;
  51.             push(@names,"$_.o")          unless m/\.(o|$dl_so)$/o;
  52.             push(@names,"$_.a")          if !m/\.a$/ and $dlsrc eq "dl_dld.xs";
  53.             push(@names, $_);
  54.         }
  55.         foreach $dir (@dirs, @dl_library_path) {
  56.             next unless -d $dir;
  57.             chop($dir = VMS::Filespec::unixpath($dir)) if $Is_VMS;
  58.             foreach $name (@names) {
  59.         my($file) = "$dir/$name";
  60.                 print STDERR " checking in $dir for $name\n" if $dl_debug;
  61.         $file = _check_file($file);
  62.         if ($file) {
  63.                     push(@found, $file);
  64.                     next arg; # no need to look any further
  65.                 }
  66.             }
  67.         }
  68.     }
  69.     if ($dl_debug) {
  70.         foreach(@dirs) {
  71.             print STDERR " dl_findfile ignored non-existent directory: $_\n" unless -d $_;
  72.         }
  73.         print STDERR "dl_findfile found: @found\n";
  74.     }
  75.     return $found[0] unless wantarray;
  76.     @found;
  77. }
  78.  
  79.  
  80. 1;
  81.