1
  V   ˆl–Ðz¾”j_)% õÀ;q§”Å£’þBVl²„,�7  ´ÞÍ_óÂ{‹„„-i[D<†ªoZƒ›Ù«Ã‚_‹I|¥Žƒî4ÃVŸÃÂ  Ï    ‹      u�»Â0Eçæ+,1´H´¡•è ‚o``CQ1ÅR›ÇAHˆ'€x,¬>>××ið^˜IJ�ƒ¸5SOBg„%0ž1f)ú\\>¼‘F_MËY:Ž–Öpü\klz““dk„œ5]á¸}�«ºÒu1Õ#�MÌúD)Õ»}è°ÀËàX|¼z¶yè°ù–ÉÈAÆpU	 3Ü†­ø¢CÛÊVP>aÂ(�íï/ug[îbñä¦þ.G|[¨;>'p¡    6   ˆl–äY>””ÔD¨ J7ÝÆYS�ÿ�þDÛ²,ÙG$€yÆ�#@þÆƒ}·ÝÅÄÃ  7   	ˆl–Ü4ý( ©¤ýÔâ�rãA¸TÅ£‘äÇò 8à@:å|Qÿ?Çƒh¹ÆÅÄ %}    #!/usr/bin/perl
# update-language --- Generate language.dat* from a set of files
# Copyright (C) 2015 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.


$^W = 1;
use strict;

my $version = "0.1";

use File::Basename;
use Getopt::Long;
use Text::ParseWords;

my $mode = 'all';

# for each file in /var/lib/tex-common/hyphen-cnf/
# plus the config file /etc/texmf/web2c/local-hyphen.cnf

my $localconf = '/etc/texmf/web2c/local-hyphen.cnf';
my $default_output_dir = '/var/lib/texmf/tex/generic/config';
my %data;
my $progname = basename($0);

my $opt_conf_file = "";
my $opt_output    = "";
my $opt_outdir    = "";
my $opt_checks = 0;
my $opt_quiet  = 0;
my $opt_help   = 0;
my $opt_version = 0;

my %defaults = (
  'latex' => {
    'output' => 'language.dat',
    'func'   => \&make_latex_line,
    'head'   => '/usr/share/texlive/texmf-dist/tex/generic/config/language.us',
    'post'   => '',
  },
  'etex' => {
    'output' => 'language.def',
    'func'   => \&make_etex_line,
    'head'   => '/usr/share/texlive/texmf-dist/tex/generic/config/language.us.def',
    'post'   => "\n\\uselanguage \{USenglish\}  \%\%\% This MUST be the last line of the file.\n",
  },
  'luatex' => {
    'output' => 'language.dat.lua',
    'func'   => \&make_luatex_line,
    'head'   => '/usr/share/texlive/texmf-dist/tex/generic/config/language.us.lua',
    'post'   => "\}\n",
  }
);

&main();

# from here on only sub definitions!

sub main {
  GetOptions(
    "conf-file|c=s"     => \$opt_conf_file,
    "output-file|o=s"   => \$opt_output,
    "output-dir|d=s"    => \$opt_outdir,
    "checks"            => \$opt_checks,
    "quiet|q"           => \$opt_quiet,
    "help|h|?"          => \$opt_help,
    "version|v"         => \$opt_version) or usage();

  if ($progname eq "update-language") {
    $mode = "all";
  } elsif ($progname eq "update-language-dat") {
    $mode = "latex";
  } elsif ($progname eq "update-language-def") {
    $mode = "etex";
  } elsif ($progname eq "update-language-lua") {
    $mode = "luatex";
  } else {
    die "Please call me as update-language(-dat,-def,-lua).";
  }

  if ($opt_help) {
    usage();
    exit 0;
  }
  if ($opt_version) {
    version();
    exit 0;
  }

  # if texlive-base is not properly installed, we do nothing
  my $stat = `dpkg-query -W -f=\'\${Status}\' texlive-base:all 2>/dev/null`;
  if ($stat ne "install ok installed") {
    printf "$progname: texlive-base not installed and configured, doing nothing!\n";
    exit 0;
  }


  update_conffiles($mode);
}


sub update_conffiles {
  my $mode = shift;
  my @todo;

  if ($mode eq 'all') {
    push @todo, keys(%defaults);
  } else {
    push @todo, $mode;
  }

  read_data();

  for my $t (@todo) {
    my $of = ($opt_output ? $opt_output : 
      ( $opt_outdir ? "$opt_outdir/$defaults{$t}{'output'}" :
        "$default_output_dir/$defaults{$t}{'output'}"));
    open(FOO, ">$of") || die "Cannot open $of: $!";

    if (-r $defaults{$t}{'head'}) {
      open BAR, "<", $defaults{$t}{'head'} || die(