home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.0 (User) / OS_user_4.0.iso / usr / lib / perl5 / auto / DynaLoader / dl_findfile.al < prev    next >
Encoding:
Text File  |  1996-04-30  |  2.7 KB  |  75 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.  
  28.         #  Otherwise we try to try to spot directories by a heuristic
  29.         #  (this is a more complicated issue than it first appears)
  30.         if (m:/: && -d $_){   push(@dirs, $_); next; }
  31.  
  32.         # VMS: we may be using native VMS directry syntax instead of
  33.         # Unix emulation, so check this as well
  34.         if ($vms && /[:>\]]/ && -d $_){   push(@dirs, $_); next; }
  35.  
  36.         #  Only files should get this far...
  37.         my(@names, $name);    # what filenames to look for
  38.         if (m:-l: ){          # convert -lname to appropriate library name
  39.             s/-l//;
  40.             push(@names,"lib$_.$dl_so");
  41.             push(@names,"lib$_.a");
  42.         }else{                # Umm, a bare name. Try various alternatives:
  43.             # these should be ordered with the most likely first
  44.             push(@names,"$_.$dl_so")     unless m/\.$dl_so$/o;
  45.             push(@names,"lib$_.$dl_so")  unless m:/:;
  46.             push(@names,"$_.o")          unless m/\.(o|$dl_so)$/o;
  47.             push(@names,"$_.a")          unless m/\.a$/;
  48.             push(@names, $_);
  49.         }
  50.         foreach $dir (@dirs, @dl_library_path) {
  51.             next unless -d $dir;
  52.             foreach $name (@names) {
  53.         my($file) = "$dir/$name";
  54.                 print STDERR " checking in $dir for $name\n" if $dl_debug;
  55.         $file = _check_file($file);
  56.         if ($file){
  57.                     push(@found, $file);
  58.                     next arg; # no need to look any further
  59.                 }
  60.             }
  61.         }
  62.     }
  63.     if ($dl_debug) {
  64.         foreach(@dirs) {
  65.             print STDERR " dl_findfile ignored non-existent directory: $_\n" unless -d $_;
  66.         }
  67.         print STDERR "dl_findfile found: @found\n";
  68.     }
  69.     return $found[0] unless wantarray;
  70.     @found;
  71. }
  72.  
  73.  
  74. 1;
  75.