This file is indexed.

/usr/sbin/update-language is in tex-common 6.06.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#!/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 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("Cannot open head file $defaults{$t}{'head'}: $!");

      for (<BAR>) { print FOO $_; }
      close BAR;
    } else {
      die("Missing head file $defaults{$t}{'head'}: $!");
    }
    for my $n (keys %data) {
      print FOO &{$defaults{$t}{'func'}}($n);
    }
    print FOO $defaults{$t}{'post'};
    close FOO;
  }
}

# should have been in TLUtils, but the actual code is hidden
# in TLPOBJ.pm, bad!
sub make_latex_line {
  my $n = shift;
  my $ret = "$n " . $data{$n}{'file'} . "\n";
  if ($data{$n}{'synonyms'}) {
    for my $s (@{$data{$n}{'synonyms'}}) {
      $ret .= "=$s\n";
    }
  }
  return $ret;
}
sub make_etex_line {
  my $n = shift;
  my $file = $data{$n}{'file'};
  my $lhm  = $data{$n}{'lefthyphenmin'};
  my $rhm  = $data{$n}{'righthyphenmin'};
  my $ret = "\\addlanguage\{$n\}\{$file\}\{\}\{$lhm\}\{$rhm\}\n";
  return $ret;
}
sub make_luatex_line {
  my $n = shift;
  my $file = $data{$n}{'file'};
  my $exc  = $data{$n}{'file_exceptions'};
  my $lhm  = $data{$n}{'lefthyphenmin'};
  my $rhm  = $data{$n}{'righthyphenmin'};
  my $patt = $data{$n}{'file_patterns'};
  my $special = $data{$n}{'luaspecial'};
  my $syns = '';
  if ($data{$n}{'synonyms'}) {
    my @syn = (@{$data{$n}{'synonyms'}});
    map { $_ = "'$_'" } @syn;
    $syns = join(', ', @syn);
  }
  my $ret = <<"EOF"
  [\'$n\'] = {
    loader = \'$file\',
    lefthyphenmin = $lhm,
    righthyphenmin = $rhm,
    synonyms = { $syns },
EOF
  ;
  $ret .= "    patterns = \'$patt\',\n" if defined $patt;
  $ret .= "    hyphenation = \'$exc\',\n" if defined $exc;
  $ret .= "    special = \'$special\',\n" if defined $special;
  $ret .= "  },\n";
  return $ret;
}

sub parse_hyphen_line {
  my $line = shift;
  my %ret;
  my $default_lefthyphenmin = 2;
  my $default_righthyphenmin = 3;
  $ret{"lefthyphenmin"} = $default_lefthyphenmin;
  $ret{"righthyphenmin"} = $default_righthyphenmin;
  $ret{"synonyms"} = [];
  my @parsed = Text::ParseWords::parse_line('\s+', 0, $line);
  for my $p (@parsed) {
    my ($a, $b) = split(/=/, $p);
    if ($a eq "name") {
      if (!$b) {
        $ret{"error"} = "AddHyphen line needs name=something";
        return %ret;
      }
      $ret{"name"} = $b;
      next;
    }
    if ($a eq "lefthyphenmin") {
      $ret{"lefthyphenmin"} = ( $b ? $b : $default_lefthyphenmin );
      next;
    }
    if ($a eq "righthyphenmin") {
      $ret{"righthyphenmin"} = ( $b ? $b : $default_righthyphenmin );
      next;
    }
    if ($a eq "file") {
      if (!$b) {
        $ret{"error"} = "AddHyphen line needs file=something";
        return %ret;
      }
      $ret{"file"} = $b;
      next;
    }
    if ($a eq "file_patterns") {
        $ret{"file_patterns"} = $b;
        next;
    }
    if ($a eq "file_exceptions") {
        $ret{"file_exceptions"} = $b;
        next;
    }
    if ($a eq "luaspecial") {
        $ret{"luaspecial"} = $b;
        next;
    }
    if ($a eq "databases") {
      @{$ret{"databases"}} = split /,/, $b;
      next;
    }
    if ($a eq "synonyms") {
      @{$ret{"synonyms"}} = split /,/, $b;
      next;
    }
    if ($a eq "comment") {
        $ret{"comment"} = $b;
        next;
    }
    # should not be reached at all
    $ret{"error"} = "Unknown language directive $a";
    return %ret;
  }
  # this default value couldn't be set earlier
  if (not defined($ret{"databases"})) {
    if (defined $ret{"file_patterns"} or defined $ret{"file_exceptions"}
        or defined $ret{"luaspecial"}) {
      @{$ret{"databases"}} = qw(dat def lua);
    } else {
      @{$ret{"databases"}} = qw(dat def);
    }
  }
  return %ret;
}


sub read_one_file {
  my $f = shift;
  my $do_warn = shift;
  open FOO, "<$f" || die ("Cannot read file $f: $!");
  while (<FOO>) {
    chomp;
    next if /^\s*%/;
    next if /^\s*$/;
    my %r = parse_hyphen_line($_);
    if (defined($r{"error"})) {
      die ("Cannot parse $_ in $f: $r{'error'}");
    }
    my $n = $r{'name'};
    if (defined($data{$n})) {
      if ($do_warn == 2) {
        printf STDERR "TeX Live internal double defined hyphenations pattern found: $n\n";
      } elsif ($do_warn == 1) {
        printf STDERR "double defined hyphenations pattern found: $n\n";
      } 
    }
    for my $k (keys %r) {
      next if ($k eq "name");
      $data{$n}{$k} = $r{$k};
    }
  }
  close FOO;
}

sub read_data {
  if (-d '/var/lib/tex-common/hyphen-cnf/texlive/') {
    for my $f (</var/lib/tex-common/hyphen-cnf/texlive/*.cnf>) {
      read_one_file($f, 2);
    }
  }
  if (-d '/var/lib/tex-common/hyphen-cnf/texmf/') {
    for my $f (</var/lib/tex-common/hyphen-cnf/texmf/*.cnf>) {
      read_one_file($f, 1);
    }
  }
  if (-r $localconf) {
    read_one_file($localconf, 0);
  }
}

sub version {
  print "$progname $version\n";
}

sub usage () {
  print <<"EOF"
Usage: $progname(-dat,-def,-lua) [OPTIONS ...]
Generate hyphenation configuration files language.dat, .def, .dat.lua

When called as update-language, all three configurations files are
generated. Otherwise only the selected one.

Options:
  -c, --conf-file=FILE   file giving additional hyphen specifications
  -o, --output-file=FILE file to write the output to
  -d, --output-dir=DIR   directory where files are written
      --checks           perform sanity checks on the generated config file
  -q, --quiet            don't write anything to the standard output during
                         normal operation
  -h, -?, --help         display this help message and exit
      --version          output version information and exit

Files:

The default output directory is
  $default_output_dir

The default output files are
  for update-language-dat  $defaults{'latex'}{'output'}
  for update-language-def  $defaults{'etex'}{'output'}
  for update-language-lua  $defaults{'luatex'}{'output'}

If -o/--output-file is given, it overrides all defaults.

EOF
;
}

### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #