[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Errors 1 and 2 with my code



I'm trying to write a utility to give me the version numbers of all
applications in a given folder or volume.  I've included the code below.
The problem is that if I run the program on any folder with a "sufficiently
high" number of files in it, not necessarily a high number of apps, MacPerl
dies horribly with either an error of type 1 or type 2.  Smaller folders
work as expected.  One time I saw the cursor corrupt before the script died.

I'm using MacPerl 5.1.9r4 and System 7.5.5.  Could someone please tell me
what I've done wrong?  Atdhvaannkcse.

=========================================================================
#! perl -w

use strict;

use Mac::Files;
use Mac::Resources;
use Mac::Memory;
use Mac::StandardFile;
use File::Find;

my $root = $ARGV[0];
my $rootlen = length $root;
my @files = ();

sub addFile
{
  my ($theFolder, $theFile) = ($File::Find::dir, $_);
  if (! -l $theFile) {
    if (-f $theFile) {
      my $vers = "";
      my ($creator, $type) = MacPerl::GetFileInfo ($theFile);
      if ($type eq "APPL") {
        $vers = '?';
        if (defined (OpenResFile ($theFolder.$theFile))) {
          $vers = '??';
          my $id = Get1Resource ('vers', 1);
          if (defined $id) {
            $vers = '???';
            my $nvers = $id->get();
            $vers = unpack("H4", substr($nvers,0,2));
            $vers =~ s/0*(.+)(.)(.)/$1.$2.$3/;
	    ReleaseResource $id;
            $id->dispose();
          }
          CloseResFile(CurResFile());
        }
        push @files, [ $theFile, substr($theFolder, $rootlen),
                       $creator, $type, $vers ];
        #print ".";
      }
    }
    elsif (-d $theFile) {
      print OUTPUT "$theFolder$theFile\n";
    }
  }
  $_ = $theFile;
}

my $output = StandardPutFile ("Write version info to file:", "versions");
exit(0) unless $output->sfGood();
$output = $output->sfFile();
open OUTPUT,">$output" or die "Couldn't open $output: $!\n";

print "Processing folders...\n";
find (\&addFile, $root);

print "Sorting...\n";
@files = sort { $a->[0] cmp $b->[0] } @files;

print "Writing output...";
print OUTPUT "\nSoftware versions found in $root:\n";
foreach my $fileref (@files) {
  printf OUTPUT "%-32s    %-4s %-4s  %s\n  %s\n",
         $fileref->[0], $fileref->[2], $fileref->[3], $fileref->[4],
         $fileref->[1];
}
close OUTPUT;

print "Done.\n";

=========================================================================



--
Mark Meyer                                            mmeyer@dseg.ti.com
Raytheon TI Systems, Inc.  Plano, TX



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch