#! /usr/bin/perl

# texname: program to convert all foundry fontnames to TeX-names
# using the foundry map-file (e.g. adobe.map)
#
# put this with the font-files, together with the relevant
# map file from CTAN info/fontname
#
# usage: perl texname

# Fulko van Westrenen
# 1 May 1999
#
# http://www.umantec.nl/varia/

# originally accepted only adobe.map
# hacked by Robin Fairbairns to accept multiple map-files
# 27 March 2003


# retreive the directory
$dir = `ls`;
$dir =~ s/\n/ /g;
@dir = split(/ +/, $dir);

# find map files
@mapfiles = map { glob($_) } "*.map";

# repeat for each foundry map we have
foreach $map (@mapfiles) {

#retrieve the namelist from the map
    open (IN, "<$map") || die "cannot find $map: $_ \n";
    while (<IN>){
	chomp $_;
	@array = split (//, $_);
	if (($array[0] ne '@') && (@array > 10)) {
	    $s = $_;
	    $s =~ s/ +/ /g;
	    @s = split (/ /,$s);
# the script assumes that the file is named after the old adobe standard
# if the naming is modern, replace the '4' by '2'
	    $name{$s[4]} = $s[0];
	}
    }
    close (IN);
}

# rename all files that are in the conglomerate namelist
foreach $fn (@dir){
    $fnsh = $fn;
    $fnsh =~ s/\..*//; # get the generic name
    $fnsuf = $fn;
    $fnsuf =~ s/^.*?\.//; # get the suffix 
    if ($name{$fnsh}){
	rename ($fn, $name{$fnsh} . "." . $fnsuf);
    }
}

