##########################################################################
#
# fontmap.pl v1.0
#
# Copyright 1997 by Evan Leibovitch <evan@telly.org>
# May be distributed under the terms of the GNU Public Licence, V2
#
# This Perl script corrects a problem when installing HylaFAX on a
# systems using newer versions of Ghostscript. The problem was
# encountered, and this script written, on Caldera OpenLinux 1.1
# (based on Linux 2.0.29) using HylaFAX 4.0pl1 and Ghostscript 3.33.
#
# The HylaFAX 'textfmt' program expects to find the Ghostscript
# font metric information in files named after the font itself,
# ie "Courier.afm". However, the new ghostscript doesn't use this
# filenaming convention anymore; it uses filenames like "n019003l.afm"
# and depends on a file called "Fontmap" to map these filenames to
# PostScript font names. On these systems, 'textfmt' will break.
#
# One solution is to download the 'afm-tar.Z' file from ftp.sgi.com,
# but these font-metric files may no longer be in sync with your actual
# fonts. This script creates the necessary symbolic links to allow
# 'textfmt' to see the proper font metric files. It must be run by
# whatever user owns the Ghostscript font files, usually root. (if they
# are located elsewhere than /usr/lib/ghostscript, change the first line
# to the proper location.)
#
##########################################################################

chdir "/usr/lib/ghostscript/fonts";

open(FONTLIST,"Fontmap") || die "Can not open Fontmap: $!\n";
while (<FONTLIST>)
	{
	chop;
	@f=split(/\s+/);
	next unless substr(@f[0],0,1) eq "/";
	@l=split(/\./,@f[1]);
	chop(@l[1]);
	$fname = substr(@l[0],1,40) . ".afm";
	$font = substr(@f[0],1,40) . ".afm";
	if (( @l[1] eq "pfb") || (substr(@l[0],0,1) eq "/"))
		{
		if ( -r $fname)
			{
			system ("ln","-s",$fname,$font);
			print "Linking " . $fname . " to " . $font . "\n";
			}
		else
			{
			print "Skipping " . $fname . ": no such file\n";
			}
		}
	}
