#! /usr/bin/perl -w use strict; =head1 Notices Originally developed for Perforce by VIZIM (www.vizim.com) Copyright (c) 2014 Perforce Software, Inc. and VIZIM Worldwide, Inc. All rights reserved. Please see LICENSE.txt in top-level folder of this distribution for license information =cut use Digest::MD5; use v5.14.0; # Earliest version testing was performed against my $APPNAME = 'FileDetails.pl'; my $APPWHAT = 'Generate file details; version 1.01'; my $APPNOTICES = "Copyright (c) 2014 Perforce Software, Inc. and VIZIM Worldwide, Inc. All rights reserved. See LICENSE.txt for license information."; =head1 File details Tool that generates details for a file using the same technology as the import coordination and profile tools. Details include BOM information and MD5 signature. =cut my $file = $ARGV[0]; if( ! defined $file || $ARGV[0] =~ m!\-+(h|\?)! ) { print "$APPWHAT $APPNOTICES Usage: $APPNAME -V $APPNAME [-h|-?] $APPNAME file\n"; exit 1; } if( $ARGV[0] =~ m!\-+V! ) { print "$APPWHAT\n"; exit 0; } if( ! -e $file ) { print "Does not exist: $file\n"; exit 1; } if( ! -f $file ) { print "Not a file: $file\n"; exit 1; } if( -z $file ) { print "EMPTY\n"; exit 0; } my $hLocal; if( ! open( $hLocal, '<:bytes', $file ) ) { print "Can't open $file $!\n"; exit 1; } my $header = ''; read $hLocal, $header, 3, 0; if( $header =~ m!^\xEF\xBB\xBF! ) { print "UTF8 "; } elsif( $header =~ m!^\xFE\xFF! ) { print "UTF16BE "; } elsif( $header =~ m!^\xFF\xFE! ) { print "UTF16LE "; } else { print "NOBOM "; } seek $hLocal, 0, 0; my $ctx = Digest::MD5->new; $ctx->reset(); $ctx->addfile( $hLocal ); close( $hLocal ); print uc $ctx->hexdigest(); print "\n"; exit 0;