#!/usr/bin/perl # # 'open.pl' v1.0 # # Fri Jan 3 14:36:57 EST 2003 # # a simple little script that makes migrating from OS X # back to solaris a little easier. # # it checks each argument with the command "file" and then the # file extension to see if it knows what to do with it. # # the result from running 'file' on the file %filehash = ( 'ascii text' => 'more', 'JPEG file' => 'xv', 'JPG file' => 'xv', 'tiff format image' => 'xv', 'PBM ascii file' => 'xv', 'PGM ascii file' => 'xv', 'PPM ascii file' => 'xv', 'PBM raw file' => 'xv', 'PGM raw file' => 'xv', 'PPM raw file' => 'xv', 'TIFF file, big-endian' => 'xv', 'TIFF file, little-endian' => 'xv', 'GIF file, v87' => 'xv', 'GIF file, v89' => 'xv', 'IFF ILBM file' => 'xv', 'PostScript document' => 'gs', 'Adobe Portable Document Format (PDF) v1.0' => 'acroread', 'Adobe Portable Document Format (PDF) v1.1' => 'acroread', 'Adobe Portable Document Format (PDF) v1.2' => 'acroread' ); # for "text" or "data": %exthash = ( 'txt' => 'more', 'pl' => 'more', 'cgi' => 'more', 'mp3' => 'mpg123', 'pdf' => 'acroread', 'ps' => 'gs' ); $arg = ""; while( $arg ne $ARGV[-1] ) { $arg = $ARGV[$ac++]; if (!-e $arg) { # doesn't exist printf "No such file: %s\n", $arg; } elsif (-d $arg) { # is a directory printf "Directory: %s\n", $arg; } else { # check 'file' type $result = `file $arg`; # name:\ttype\n; $type= (split /:/, $result)[-1]; $type =~ s/^\s+//g; $type =~ s/\s+$//g; if (defined $filehash{$type}) { # it's in the `file` hash $command = $filehash{$type} . " " . $arg; system( $command ); } else { # check the extension $extension = (split /\./, $arg)[-1]; printf "extension = %s\n", $extension; if ( defined $exthash{$extension} ) { # it's in the extension hash! $command = $exthash{$extension} . " " . $arg; system( $command ); } else { printf "Unknown type: %s\n", $arg; } } } }