#!/usr/bin/perl # # $Id: showhdr,v 1.1 1998/01/30 20:42:20 vogelke Exp $ # # NAME: # showhdr # # SYNOPSIS: # showhdr [-v] files # # DESCRIPTION: # "showhdr" is a program to display the first 8 bytes from each file; # we can use to figure out the filetype. # # OPTIONS: # "-v" prints the current version and exits. # # EXAMPLE: # % showhdr *.doc # chklst.doc: 0xd0cf11e0 d0cf 11e0 a1b1 1ae1 # datetest.doc: 0xd0cf11e0 d0cf 11e0 a1b1 1ae1 # netver21.doc: 0xd0cf11e0 d0cf 11e0 a1b1 1ae1 # nyconfsm.doc: 0xdba52d00 dba5 2d00 0000 0904 # phases.doc: 0xd0cf11e0 d0cf 11e0 a1b1 1ae1 # readines.doc: 0xd0cf11e0 d0cf 11e0 a1b1 1ae1 # vendrev.doc: 0xd0cf11e0 d0cf 11e0 a1b1 1ae1 # y2ktools.doc: 0x31be0000 31be 0000 00ab 0000 # # AUTHOR: # Karl Vogel # Sumaria Systems, Inc. eval 'exec perl -S $0 ${1+"$@"}' # If the shell can't handle "#!", if 0; # fire up perl directly. require "getopts.pl"; # command line args. $ENV{"PATH"} = "/bin:/usr/sbin:/usr/local/bin"; $tmp = "/tmp/showhdr.$$"; ($myname) = split(/\//, reverse($0)); $myname = reverse($myname); # script basename. # # Trap most common signals. Handle command line arguments (if any). # $SIG{'HUP'} = 'sigcatcher'; $SIG{'INT'} = 'sigcatcher'; $SIG{'QUIT'} = 'sigcatcher'; $SIG{'TERM'} = 'sigcatcher'; &usage unless &Getopts('v'); &version if $opt_v; while ($file = shift(@ARGV)) { open(IN, "$file") || die "$file: $!\n"; read(IN, $buf, 8); close(IN); @s = unpack("H4" x 4, $buf); $first = unpack("H8", $buf); print "$file:\t0x$first\t@s\n"; } &exit(0); #--------------------------------------------------------------------- # Print a short usage message from the comment header and exit. # sub usage { if (open(PROG, "$myname")) { while () { last if /^# NAME:/; } print STDERR " NAME:\n"; while () { last if /^\s*$/; last if /^# AUTHOR:/; s/^#//; print STDERR; } close(PROG); } else { print STDERR "No usage information available.\n"; } &exit(1); } #--------------------------------------------------------------------- # Do something if we get a signal. # sub sigcatcher { local ($sig) = @_; &exit(2, "caught signal SIG$sig -- shutting down.\n"); } #--------------------------------------------------------------------- # Print the current version and exit. # sub version { $_ = '$RCSfile: showhdr,v $ $Revision: 1.1 $ ' . '$Date: 1998/01/30 20:42:20 $'; s/RCSfile: //; s/.Date: //; s/,v . .Revision: / v/; s/\$//g; print "$_\n"; exit(0); } #--------------------------------------------------------------------- # Clean up. # sub exit { local ($code, $msg) = @_; unlink($tmp); warn "$myname: $msg\n" if $msg; exit($code); }