view bin/old-cek @ 682:88888f40c628

[vimrc] Disable indent plugin Less predictable behavior with it enabled.
author nanaya <me@nanaya.pro>
date Fri, 24 Jun 2022 22:50:19 +0900
parents 5bafb912837e
children
line wrap: on
line source

#!/usr/bin/perl

use warnings;
use strict;
use String::CRC32;
use File::Basename;

unless($#ARGV+1>0) {
	print("Usage: ", basename($0), " file1 ... fileN\n");
	exit(1);
}

my @files = @ARGV;
#or print("Usage: ", basename($0), " file1 ... fileN\n") && exit(1);
    # print usage message if called without arguments

foreach (@files) {
	my $filename = $_;
	my ($input, $name_checksum, $real_checksum, $checksum);
	unless((-r $filename) && (-f $filename)) {
		print(qq("$filename" is not a file or unreadable, skipping\n));
		next();
	}
	#print(qq(Could not find file "$filename", skipping\n)) and next() unless -r $filename;
	#print(qq("$filename" is not a file, skipping\n)) and next() unless -f $filename;

	open(FILE,$filename);
	$real_checksum = sprintf("%08X",crc32(*FILE));
	close(FILE);

	if ( /(\[|\()([0-9A-F]{8})(\]|\))/i ) { # does it have a checksum?
		$name_checksum = $2;
		if (lc($real_checksum) eq lc($name_checksum)) {
			print("${filename}: $real_checksum - OK!\n");
			next();
		}
        else {
            print("${filename}: $real_checksum - NOT OK! Should be ${name_checksum}!\n");
            next();
        }
    }
    else { # can't find checksum in filename, just print filename + generated checksum and let the user do the thinking
        print("${filename}: $real_checksum\n");
        next();
	}
}

exit(0);