100
  7   ˆl–äY>””ÔD¨ J7ÝÆYS�ÿ�þZvG–l£’@<ã@‘ ?¿„Ì¾/ÂÆÅ ?÷     #!/usr/bin/perl -w
# dh_installtex --- register Type 1 fonts, languages, or formats with TeX
# Copyright (C) 2006, 2007 Florent Rougon
# Copyright (C) 2006, 2007 Frank KÃ¼ster
# Copyright (C) 2006-2017 Norbert Preining
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA  02110-1301 USA.
#


use strict;
use Debian::Debhelper::Dh_Lib;

our $VERSION = "1";

init(options => { "flavor=s" => \$dh{FLAVOR} });




#
# GLOBAL VARIABLES
#
my $flavor;		
my $mapdoconfig =  0;	  # doconfig depending map/subflavor
my $doallformats = 0;	  # depending on flavor format:build_all
my $dofulllsr = 0;        # do include texmf-texlive in lsr making
my @addbuildformats = (); # additional formats to be build
my $doformatlinks = 1;
my $texmftree = "texmf";
my %cmdlineargs;
my %cmdlinefiles;

#
# definitions for the different flavors
#
# extension of package files debian/$package.formats and/or debian/formats etc
my %pkgfileext = ( 
	hyphen 		=> "hyphens", 
	format 		=> "formats", 
	map 		=> "maps" );
# extension of the config files
my %configfileext = ( 
	hyphen	 	=> "cnf", 
	format 		=> "cnf", 
	map 		=> "cfg" );
# comment char for magic header
my %commentchar = ( 
	hyphen	 	=> '%', 
	format 		=> '#', 
	map 		=> '#' );
# directory under /etc/texmf/ where files are installed
my %configdir = ( 
	hyphen	 	=> "hyphen.d", 
	format 		=> "fmt.d", 
	map 		=> "updmap.d" );
# directory under /var/lib/tex-common where list files are installed
my %managedir = ( 
	hyphen	 	=> "hyphen-cnf", 
	format 		=> "fmtutil-cnf", 
	map 		=> "fontmap-cfg" );
#
# dummy loop variables
my $i;
my $bn;
my $pr;
my $dofilen;

#
# collect data
# This function is used to extract certain information from the respective
# config files. Up to now we have to do the following:
# for config file for maps
# 	if we select to generate all dvips config files
# 	(with map:config_for_active_maps or map:config_for_all_maps)
# 	we collect the map files
# for config file for formats
# 	we extract format\tengine for
# 		- generation with fmtutil-sys --byfmt
# 		- creation of links /usr/bin/format -> /usr/bin/engine
sub collect_data {
	my ($type,$dataref,$entry) = @_;
	my $m;

	if ($type eq "map") {
		if ($m = extract_map($entry, $mapdoconfig)) { push @$dataref, $m; }
	} elsif ($type eq "format") {
		if ($m = extract_format($entry)) { push @$dataref, $m; }
	} 
	# TODO should we do something with hypehn here!????
}

sub extract_format {
	my ($line) = @_;
	if ($line =~ m/^([^#\s]\S+)\s*(\S*)\s+/) {
		return "$1\t$2";
	}
}

sub extract_map {
	my ($line,$mapdoconfig) = @_;
	if ($mapdoconfig == 0) { return ""; }
	if ($line =~ m/^[[:space:]]*([#[:space:]]*)[[:space:]]*(Mixed|Kanji)?Map[[:space:]]*(.*\.map)[[:space:]]*(#.*)?$/) {
		my $comment = $1;
		my $map = $3;
		if (($comment eq "") || ($mapdoconfig == 2)) {
			return $map;
		}
	}
	return "";
}

#
# build_line
# used to create a correct config file entry from a cmd-line specification
sub build_line {
	my ($type,$line) = @_;
	if ($type eq "map") {
		if ($line =~ m/^(Map|MixedMap|KanjiMap),(.*)$/) {
			return("$1 $2");
		} else {
			error("$line is neither of the form Map filename.map, nor MixedMap filename.map.");
		}
	} elsif ($type eq "format") {
		my ($format,$engine,$pat,@rest) = split(",",$line);
		my $ret = "$format\t$engine\t$pat\t" . join(",",@rest);
		return($ret);
	} elsif ($type eq "hyphen") {
		my ($lang,$loader,$pat,@rest) = split(",",$line);
		my $ret="name=