#!/usr/bin/env perl
# $Id: commonchars,v 1.3 2002/09/14 21:07:03 euske Exp $
#
# usage: commonchars bdf1-1 bdf1-2 ... bdf1-n : ... : bdfn-1 bdfn-2 ... bdfn-n
#
# list charcodes every given BDF files share.
#
#	2002/2/3, by 1@2ch
#	* public domain *
#

sub usage() {
    print "usage: commonchars bdf1-1 bdf1-2 ... bdf1-n : ... : bdfn-1 bdfn-2 ... bdfn-n\n";
    exit 1;
}

$ARGV[0] || usage();

%enc = ();

$n = 0;
foreach $f (@ARGV) {
    if ($f eq ':') {
	$n++; next;
    }
    open(IN, $f) || die("open: $f: $!");
    while(<IN>) {
	chop;
	if (/^ENCODING\s+(\d+)/) {
	    $enc{$1}++;
	}
    }
    close(IN);
}

$i = 1;
foreach my $k (sort {$a<=>$b} keys(%enc)) {
    # kludge: filtered out
    if (0x100 <= $k ||
	(0x20 <= $k && $k <= 0x7f) ||
	(0xa0 <= $k && $k <= 0xdf)) {
	if ($enc{$k} == $n) {
	    printf "0x%04lx\t%d\n", $k, $i;
	    $i++;
	}
    }
}
