home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / auto / DynaLoader / dl_findfile.al < prev   
Text File  |  1998-04-04  |  4KB  |  110 lines

  1. # NOTE: Derived from wintermute:Development:MacPerl:perl: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_ext= $Config::Config{'dlext'}; # suffix for perl extensions
  12.     my $dl_so = $Config::Config{'so'};  # suffix for shared libraries
  13.  
  14.     print STDERR "dl_findfile(@args)\n" if $dl_debug;
  15.  
  16.     # accumulate directories but process files as they appear
  17.     arg: foreach(@args) {
  18.         #  Special fast case: full filepath requires no search
  19.         if ($Is_VMS && m%[:>/\]]% && -f $_) {
  20.             push(@found,dl_expandspec(VMS::Filespec::vmsify($_)));
  21.             last arg unless wantarray;
  22.             next;
  23.         }
  24.         elsif ($Is_MacOS && m/:/ && -f $_) {
  25.             push(@found,$_);
  26.             last arg unless wantarray;
  27.             next;
  28.         }
  29.         elsif (m:/: && -f $_ && !$do_expand) {
  30.             push(@found,$_);
  31.             last arg unless wantarray;
  32.             next;
  33.         }
  34.  
  35.         # Deal with directories first:
  36.         #  Using a -L prefix is the preferred option (faster and more robust)
  37.         if (m:^-L:) { s/^-L//; push(@dirs, $_); next; }
  38.  
  39.         if ($Is_MacOS) {
  40.              #  Otherwise we try to try to spot directories by a heuristic
  41.              #  (this is a more complicated issue than it first appears)
  42.              if (m/:/ && -d $_) {   push(@dirs, $_); next; }
  43.  
  44.             #  Only files should get this far...
  45.             my(@names, $name);    # what filenames to look for
  46.             if (m:-l: ) {          # convert -lname to appropriate library name
  47.                 s/-l//;
  48.                 push(@names,"$_");
  49.             } else {                # Umm, a bare name. Try various alternatives:
  50.                 push(@names, $_);
  51.             }
  52.             foreach $dir (@dirs, @dl_library_path) {
  53.                 next unless -d $dir;
  54.                 $dir =~ s/:$//;
  55.                 $dir =~ s/^([^:]+)$/:$1/;
  56.                 foreach $name (@names) {
  57.                     my($file) = "$dir:$name";
  58.                     print STDERR " checking in $dir for $name\n" if $dl_debug;
  59.                     if (-f $file) {
  60.                         push(@found, $file);
  61.                         next arg; # no need to look any further
  62.                     }
  63.                 }
  64.             }
  65.         } else {
  66.             #  Otherwise we try to try to spot directories by a heuristic
  67.             #  (this is a more complicated issue than it first appears)
  68.             if (m:/: && -d $_) {   push(@dirs, $_); next; }
  69.  
  70.             #  Only files should get this far...
  71.             my(@names, $name);    # what filenames to look for
  72.             if (m:-l: ) {          # convert -lname to appropriate library name
  73.                 s/-l//;
  74.                 push(@names,"lib$_.$dl_so");
  75.                 push(@names,"lib$_.a");
  76.            } else {                # Umm, a bare name. Try various alternatives:
  77.                 # these should be ordered with the most likely first
  78.                 push(@names,"$_.$dl_ext")    unless m/\.$dl_ext$/o;
  79.                 push(@names,"$_.$dl_so")     unless m/\.$dl_so$/o;
  80.                 push(@names,"lib$_.$dl_so")  unless m:/:;
  81.                 push(@names,"$_.a")          if !m/\.a$/ and $dlsrc eq "dl_dld.xs";
  82.                 push(@names, $_);
  83.             }
  84.             foreach $dir (@dirs, @dl_library_path) {
  85.                 next unless -d $dir;
  86.                 chop($dir = VMS::Filespec::unixpath($dir)) if $Is_VMS;
  87.                 foreach $name (@names) {
  88.                     my($file) = "$dir/$name";
  89.                     print STDERR " checking in $dir for $name\n" if $dl_debug;
  90.                     $file = _check_file($file);
  91.                     if ($file) {
  92.                         push(@found, $file);
  93.                         next arg; # no need to look any further
  94.                     }
  95.                 }
  96.             }
  97.         }
  98.     }
  99.     if ($dl_debug) {
  100.         foreach(@dirs) {
  101.             print STDERR " dl_findfile ignored non-existent directory: $_\n" unless -d $_;
  102.         }
  103.         print STDERR "dl_findfile found: @found\n";
  104.     }
  105.     return $found[0] unless wantarray;
  106.     @found;
  107. }
  108.  
  109. 1;
  110.