home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl501m.zip / lib / auto / DynaLoader / dl_findfile.al < prev   
Text File  |  1995-07-03  |  3KB  |  73 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 ($vms) = ($Config{'osname'} eq 'VMS');
  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 (m:/: && -f $_ && !$do_expand){
  19.         push(@found,$_);
  20.         last arg unless wantarray;
  21.         next;
  22.     }
  23.  
  24.         # Deal with directories first:
  25.         #  Using a -L prefix is the preferred option (faster and more robust)
  26.         if (m:^-L:){ s/^-L//; push(@dirs, $_); next; }
  27.         #  Otherwise we try to try to spot directories by a heuristic
  28.         #  (this is a more complicated issue than it first appears)
  29.         if (m:/: && -d $_){   push(@dirs, $_); next; }
  30.         # VMS: we may be using native VMS directry syntax instead of
  31.         # Unix emulation, so check this as well
  32.         if ($vms && /[:>\]]/ && -d $_){   push(@dirs, $_); next; }
  33.  
  34.         #  Only files should get this far...
  35.         my(@names, $name);    # what filenames to look for
  36.         if (m:-l: ){          # convert -lname to appropriate library name
  37.             s/-l//;
  38.             push(@names,"lib$_.$dl_so");
  39.             push(@names,"lib$_.a");
  40.         }else{                # Umm, a bare name. Try various alternatives:
  41.             # these should be ordered with the most likely first
  42.             push(@names,"$_.$dl_so")     unless m/\.$dl_so$/o;
  43.             push(@names,"lib$_.$dl_so")  unless m:/:;
  44.             push(@names,"$_.o")          unless m/\.(o|$dl_so)$/o;
  45.             push(@names,"$_.a")          unless m/\.a$/;
  46.             push(@names, $_);
  47.         }
  48.         foreach $dir (@dirs, @dl_library_path) {
  49.             next unless -d $dir;
  50.             foreach $name (@names) {
  51.         my($file) = "$dir/$name";
  52.                 print STDERR " checking in $dir for $name\n" if $dl_debug;
  53.         $file = _check_file($file);
  54.         if ($file){
  55.                     push(@found, $file);
  56.                     next arg; # no need to look any further
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     if ($dl_debug) {
  62.         foreach(@dirs) {
  63.             print STDERR " dl_findfile ignored non-existent directory: $_\n" unless -d $_;
  64.         }
  65.         print STDERR "dl_findfile found: @found\n";
  66.     }
  67.     return $found[0] unless wantarray;
  68.     @found;
  69. }
  70.  
  71.  
  72. 1;
  73.