#! /usr/bin/perl

use Digest::MD5;
use File::Basename;
use Getopt::Std;

use constant SALT_1 => "Quidquid latine dictum";
use constant SALT_2 => " sit altum viditur";

$ME = basename( $0 );

getopts( 'l:' );
unless ( $opt_l =~ /^(?:objective-)?c$/ ) {
    die "$ME: -l must be 'c' or 'objective-c'\n";
}
usage() if $#ARGV == -1;

$at = '@' if $opt_l eq 'objective-c';

for ( @ARGV ) {
    my $ctx = Digest::MD5->new();
    $ctx->add( SALT_1 );
    open( FILE, $_ ) or die "$ME: could not open $_\n";
    binmode( FILE );
    $ctx->addfile( FILE );
    close( FILE );
    $ctx->add( SALT_2 );
    my $digest = $ctx->hexdigest();

    my $jar = basename( $_ );
    $jar =~ tr/!-~/P-~!-O/;             # ROT-47
    $jar =~ s/(["\\])/\\\1/g;           # escape " and \
    print "$at\"$jar\", $at\"$digest\",\n";
}

sub usage {
    die "usage: $ME -l {c|objective-c} files ...\n";
}

# vim:set et sw=4 ts=4:
