<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># $Id: TLPOBJ.pm 65965 2023-02-20 17:26:54Z karl $
# TeXLive::TLPOBJ.pm - module for using tlpobj files
# Copyright 2007-2023 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.

use strict; use warnings;

package TeXLive::TLPOBJ;

my $svnrev = '$Revision: 65965 $';
my $_modulerevision = ($svnrev =~ m/: ([0-9]+) /) ? $1 : "unknown";
sub module_revision { return $_modulerevision; }

use TeXLive::TLConfig qw($DefaultCategory $CategoriesRegexp 
                         $MetaCategoriesRegexp $InfraLocation 
                         %Compressors $DefaultCompressorFormat
                         $RelocPrefix $RelocTree);
use TeXLive::TLCrypto;
use TeXLive::TLTREE;
use TeXLive::TLUtils;

our $_tmp;
my $_containerdir;


sub new {
  my $class = shift;
  my %params = @_;
  my $self = {
    name        =&gt; $params{'name'},
    category    =&gt; defined($params{'category'}) ? $params{'category'} : $DefaultCategory,
    shortdesc   =&gt; $params{'shortdesc'},
    longdesc    =&gt; $params{'longdesc'},
    catalogue   =&gt; $params{'catalogue'},
    relocated   =&gt; $params{'relocated'},
    runfiles    =&gt; defined($params{'runfiles'}) ? $params{'runfiles'} : [],
    runsize     =&gt; $params{'runsize'},
    srcfiles    =&gt; defined($params{'srcfiles'}) ? $params{'srcfiles'} : [],
    srcsize     =&gt; $params{'srcsize'},
    docfiles    =&gt; defined($params{'docfiles'}) ? $params{'docfiles'} : [],
    docsize     =&gt; $params{'docsize'},
    executes    =&gt; defined($params{'executes'}) ? $params{'executes'} : [],
    postactions =&gt; defined($params{'postactions'}) ? $params{'postactions'} : [],
    # note that binfiles is a HASH with keys of $arch!
    binfiles    =&gt; defined($params{'binfiles'}) ? $params{'binfiles'} : {},
    binsize     =&gt; defined($params{'binsize'}) ? $params{'binsize'} : {},
    depends     =&gt; defined($params{'depends'}) ? $params{'depends'} : [],
    revision    =&gt; $params{'revision'},
    cataloguedata =&gt; defined($params{'cataloguedata'}) ? $params{'cataloguedata'} : {},
  };
  $_containerdir = $params{'containerdir'} if defined($params{'containerdir'});
  bless $self, $class;
  return $self;
}


sub copy {
  my $self = shift;
  my $bla = {};
  %$bla = %$self;
  bless $bla, "TeXLive::TLPOBJ";
  return $bla;
}


sub from_file {
  my $self = shift;
  if (@_ != 1) {
    die("TLPOBJ:from_file: Need a filename for initialization");
  }
  open(TMP,"&lt;$_[0]") || die("Cannot open tlpobj file: $_[0]");
  $self-&gt;from_fh(\*TMP);
}

sub from_fh {
  my ($self,$fh,$multi) = @_;
  my $started = 0;
  my $lastcmd = "";
  my $arch;
  my $size;

  while (my $line = &lt;$fh&gt;) {
    # we do not worry about whitespace at the end of a line;
    # that would be a bug in the db creation, and it takes some
    # noticeable time to get rid of it.  So just chomp.
    chomp($line);
    
    # we call tllog only when something will be logged, to speed things up.
    # this is the inner loop bounding the time to read tlpdb.
    dddebug("reading line: &gt;&gt;&gt;$line&lt;&lt;&lt;\n") if ($::opt_verbosity &gt;= 3);
    $line =~ /^#/ &amp;&amp; next;          # skip comment lines
    if ($line =~ /^\s*$/) {
      if (!$started) { next; }
      if (defined($multi)) {
        # we may read from a tldb file
        return 1;
      } else {
        # we are reading one tldb file, nothing else allowed
        die("No empty line allowed within tlpobj files!");
      }
    }

    my ($cmd, $arg) = split(/\s+/, $line, 2);
    # first command must be name
    $started || $cmd eq 'name'
      or die("First directive needs to be 'name', not $line");

    # now the big switch, ordered by decreasing number of occurences
    if ($cmd eq '') {
      if ($lastcmd eq "runfiles" || $lastcmd eq "srcfiles") {
        push @{$self-&gt;{$lastcmd}}, $arg;
      } elsif ($lastcmd eq "docfiles") {
        my ($f, $rest) = split(' ', $arg, 2);
        push @{$self-&gt;{'docfiles'}}, $f;
        # docfiles can have tags, but the parse_line function is so
        # time intense that we try to call it only when necessary
        if (defined $rest) {
          # parse_line has problems with double quotes in double quotes
          # my @words = &amp;TeXLive::TLUtils::parse_line('\s+', 0, $rest);
          # do manual parsing
          # this is not optimal, but since we support only two tags there
          # are not so many cases
          # Warning: need tp check the double cases first!!!
          if ($rest =~ m/^language="(.*)"\s+details="(.*)"\s*$/) {
            $self-&gt;{'docfiledata'}{$f}{'details'} = $2;
            $self-&gt;{'docfiledata'}{$f}{'language'} = $1;
          } elsif ($rest =~ m/^details="(.*)"\s+language="(.*)"\s*$/) {
            $self-&gt;{'docfiledata'}{$f}{'details'} = $1;
            $self-&gt;{'docfiledata'}{$f}{'language'} = $2;
          } elsif ($rest =~ m/^details="(.*)"\s*$/) {
            $self-&gt;{'docfiledata'}{$f}{'details'} = $1;
          } elsif ($rest =~ m/^language="(.*)"\s*$/) {
            $self-&gt;{'docfiledata'}{$f}{'language'} = $1;
          } else {
            tlwarn("$0: Unparsable tagging in TLPDB line: $line\n");
          }
        }
      } elsif ($lastcmd eq "binfiles") {
        push @{$self-&gt;{'binfiles'}{$arch}}, $arg;
      } else {
        die("Continuation of $lastcmd not allowed, please fix tlpobj: line = $line!\n");
      }
    } elsif ($cmd eq "longdesc") {
      my $desc = defined $arg ? $arg : '';
      if (defined($self-&gt;{'longdesc'})) {
        $self-&gt;{'longdesc'} .= " $desc";
      } else {
        $self-&gt;{'longdesc'} = $desc;
      }
    } elsif ($cmd =~ /^catalogue-(.+)$/o) {
      $self-&gt;{'cataloguedata'}{$1} = $arg if defined $arg;
    } elsif ($cmd =~ /^(doc|src|run)files$/o) {
      my $type = $1;
      for (split ' ', $arg) {
        my ($k, $v) = split('=', $_, 2);
        if ($k eq 'size') {
        $self-&gt;{"${type}size"} = $v;
        } else {
          die "Unknown tag: $line";
        }
      }
    } elsif ($cmd eq 'containersize' || $cmd eq 'srccontainersize'
        || $cmd eq 'doccontainersize') {
      $arg =~ /^[0-9]+$/ or die "Invalid size value: $line!";
      $self-&gt;{$cmd} = $arg;
    } elsif ($cmd eq 'containermd5' || $cmd eq 'srccontainermd5'
        || $cmd eq 'doccontainermd5') {
      $arg =~ /^[a-f0-9]{32}$/ or die "Invalid md5 value: $line!";
      $self-&gt;{$cmd} = $arg;
    } elsif ($cmd eq 'containerchecksum' || $cmd eq 'srccontainerchecksum'
        || $cmd eq 'doccontainerchecksum') {
      $arg =~ /^[a-f0-9]{$TeXLive::TLConfig::ChecksumLength}$/
        or die "Invalid checksum value: $line!";
      $self-&gt;{$cmd} = $arg;
    } elsif ($cmd eq 'name') {
      $arg =~ /^([-.\w]+)$/ or die("Invalid name: $line!");
      $self-&gt;{'name'} = $arg;
      $started &amp;&amp; die("Cannot have two name directives: $line!");
      $started = 1;
    } elsif ($cmd eq 'category') {
      $self-&gt;{'category'} = $arg;
      if ($self-&gt;{'category'} !~ /^$CategoriesRegexp/o) {
        tlwarn("Unknown category " . $self-&gt;{'category'} . " for package "
          . $self-&gt;name . " found.\nPlease update texlive.infra.\n");
      }
    } elsif ($cmd eq 'revision') {
      $self-&gt;{'revision'} = $arg;
    } elsif ($cmd eq 'shortdesc') {
      $self-&gt;{'shortdesc'} .= defined $arg ? $arg : ' ';
    } elsif ($cmd eq 'execute' || $cmd eq 'postaction'
        || $cmd eq 'depend') {
      push @{$self-&gt;{$cmd . 's'}}, $arg if defined $arg;
    } elsif ($cmd eq 'binfiles') {
      for (split ' ', $arg) {
        my ($k, $v) = split('=', $_, 2);
        if ($k eq 'arch') {
          $arch = $v;
        } elsif ($k eq 'size') {
          $size = $v;
        } else {
          die "Unknown tag: $line";
        }
      }
      if (defined($size)) {
        $self-&gt;{'binsize'}{$arch} = $size;
      }
    } elsif ($cmd eq 'relocated') {
      ($arg eq '0' || $arg eq '1') or die "Invalid value: $line!";
      $self-&gt;{'relocated'} = $arg;
    } elsif ($cmd eq 'catalogue') {
      $self-&gt;{'catalogue'} = $arg;
    } else {
      die("Unknown directive ...$line... , please fix it!");
    }
    $lastcmd = $cmd unless $cmd eq '';
  }
  return $started;
}

sub recompute_revision {
  my ($self,$tltree, $revtlpsrc) = @_;
  my @files = $self-&gt;all_files;
  my $filemax = 0;
  $self-&gt;revision(0);
  foreach my $f (@files) {
    $filemax = $tltree-&gt;file_svn_lastrevision($f);
    $self-&gt;revision(($filemax &gt; $self-&gt;revision) ? $filemax : $self-&gt;revision);
  }
  if (defined($revtlpsrc)) {
    if ($self-&gt;revision &lt; $revtlpsrc) {
      $self-&gt;revision($revtlpsrc);
    }
  }
}

sub recompute_sizes {
  my ($self,$tltree) = @_;
  $self-&gt;{'docsize'} = $self-&gt;_recompute_size("doc",$tltree);
  $self-&gt;{'srcsize'} = $self-&gt;_recompute_size("src",$tltree);
  $self-&gt;{'runsize'} = $self-&gt;_recompute_size("run",$tltree);
  foreach $a ($tltree-&gt;architectures) {
    $self-&gt;{'binsize'}{$a} = $self-&gt;_recompute_size("bin",$tltree,$a);
  }
}


sub _recompute_size {
  my ($self,$type,$tltree,$arch) = @_;
  my $nrivblocks = 0;
  if ($type eq "bin") {
    my %binfiles = %{$self-&gt;{'binfiles'}};
    if (defined($binfiles{$arch})) {
      foreach my $f (@{$binfiles{$arch}}) {
        my $s = $tltree-&gt;size_of($f);
        $nrivblocks += int($s/$TeXLive::TLConfig::BlockSize);
        $nrivblocks++ if (($s%$TeXLive::TLConfig::BlockSize) &gt; 0);
      }
    }
  } else {
    if (defined($self-&gt;{"${type}files"}) &amp;&amp; (@{$self-&gt;{"${type}files"}})) {
      foreach my $f (@{$self-&gt;{"${type}files"}}) {
        my $s = $tltree-&gt;size_of($f);
        if (defined($s)) {
          $nrivblocks += int($s/$TeXLive::TLConfig::BlockSize);
          $nrivblocks++ if (($s%$TeXLive::TLConfig::BlockSize) &gt; 0);
        } else {
        tlwarn("$0: (TLPOBJ::_recompute_size) size of $type $f undefined?!\n");
        }
      }
    }
  }
  return $nrivblocks;
}

sub writeout {
  my $self = shift;
  my $fd = (@_ ? $_[0] : *STDOUT);
  print $fd "name ", $self-&gt;name, "\n";
  print $fd "category ", $self-&gt;category, "\n";
  defined($self-&gt;{'revision'}) &amp;&amp; print $fd "revision $self-&gt;{'revision'}\n";
  defined($self-&gt;{'catalogue'}) &amp;&amp; print $fd "catalogue $self-&gt;{'catalogue'}\n";
  defined($self-&gt;{'shortdesc'}) &amp;&amp; print $fd "shortdesc $self-&gt;{'shortdesc'}\n";
  defined($self-&gt;{'license'}) &amp;&amp; print $fd "license $self-&gt;{'license'}\n";
  defined($self-&gt;{'relocated'}) &amp;&amp; $self-&gt;{'relocated'} &amp;&amp; print $fd "relocated 1\n";
  # don't want to use FileHandle.pm; see man perlform
  #format_name $fd "multilineformat";
  select((select($fd),$~ = "multilineformat")[0]);
  $fd-&gt;format_lines_per_page (99999); # no pages in this format
  if (defined($self-&gt;{'longdesc'})) {
    $_tmp = "$self-&gt;{'longdesc'}";
    write $fd;  # use that multilineformat
  }
  if (defined($self-&gt;{'depends'})) {
    foreach (sort @{$self-&gt;{'depends'}}) {
      print $fd "depend $_\n";
    }
  }
  if (defined($self-&gt;{'executes'})) {
    foreach (sort @{$self-&gt;{'executes'}}) {
      print $fd "execute $_\n";
    }
  }
  if (defined($self-&gt;{'postactions'})) {
    foreach (sort @{$self-&gt;{'postactions'}}) {
      print $fd "postaction $_\n";
    }
  }
  if (defined($self-&gt;{'containersize'})) {
    print $fd "containersize $self-&gt;{'containersize'}\n";
  }
  if (defined($self-&gt;{'containermd5'})) {
    print $fd "containermd5 $self-&gt;{'containermd5'}\n";
  }
  if (defined($self-&gt;{'containerchecksum'})) {
    print $fd "containerchecksum $self-&gt;{'containerchecksum'}\n";
  }
  if (defined($self-&gt;{'doccontainersize'})) {
    print $fd "doccontainersize $self-&gt;{'doccontainersize'}\n";
  }
  if (defined($self-&gt;{'doccontainermd5'})) {
    print $fd "doccontainermd5 $self-&gt;{'doccontainermd5'}\n";
  }
  if (defined($self-&gt;{'doccontainerchecksum'})) {
    print $fd "doccontainerchecksum $self-&gt;{'doccontainerchecksum'}\n";
  }
  if (defined($self-&gt;{'docfiles'}) &amp;&amp; (@{$self-&gt;{'docfiles'}})) {
    print $fd "docfiles size=$self-&gt;{'docsize'}\n";
    foreach my $f (sort @{$self-&gt;{'docfiles'}}) {
      print $fd " $f";
      if (defined($self-&gt;{'docfiledata'}{$f}{'details'})) {
        my $tmp = $self-&gt;{'docfiledata'}{$f}{'details'};
        #$tmp =~ s/\"/\\\"/g;
        print $fd ' details="', $tmp, '"';
      }
      if (defined($self-&gt;{'docfiledata'}{$f}{'language'})) {
        my $tmp = $self-&gt;{'docfiledata'}{$f}{'language'};
        #$tmp =~ s/\"/\\\"/g;
        print $fd ' language="', $tmp, '"';
      }
      print $fd "\n";
    }
  }
  if (defined($self-&gt;{'srccontainersize'})) {
    print $fd "srccontainersize $self-&gt;{'srccontainersize'}\n";
  }
  if (defined($self-&gt;{'srccontainermd5'})) {
    print $fd "srccontainermd5 $self-&gt;{'srccontainermd5'}\n";
  }
  if (defined($self-&gt;{'srccontainerchecksum'})) {
    print $fd "srccontainerchecksum $self-&gt;{'srccontainerchecksum'}\n";
  }
  if (defined($self-&gt;{'srcfiles'}) &amp;&amp; (@{$self-&gt;{'srcfiles'}})) {
    print $fd "srcfiles size=$self-&gt;{'srcsize'}\n";
    foreach (sort @{$self-&gt;{'srcfiles'}}) {
      print $fd " $_\n";
    }
  }
  if (defined($self-&gt;{'runfiles'}) &amp;&amp; (@{$self-&gt;{'runfiles'}})) {
    print $fd "runfiles size=$self-&gt;{'runsize'}\n";
    foreach (sort @{$self-&gt;{'runfiles'}}) {
      print $fd " $_\n";
    }
  }
  foreach my $arch (sort keys %{$self-&gt;{'binfiles'}}) {
    if (@{$self-&gt;{'binfiles'}{$arch}}) {
      print $fd "binfiles arch=$arch size=", $self-&gt;{'binsize'}{$arch}, "\n";
      foreach (sort @{$self-&gt;{'binfiles'}{$arch}}) {
        print $fd " $_\n";
      }
    }
  }
  # writeout all the catalogue keys
  foreach my $k (sort keys %{$self-&gt;cataloguedata}) {
    next if $k eq "date";
    print $fd "catalogue-$k ", $self-&gt;cataloguedata-&gt;{$k}, "\n";
  }
}

sub writeout_simple {
  my $self = shift;
  my $fd = (@_ ? $_[0] : *STDOUT);
  print $fd "name ", $self-&gt;name, "\n";
  print $fd "category ", $self-&gt;category, "\n";
  if (defined($self-&gt;{'depends'})) {
    foreach (sort @{$self-&gt;{'depends'}}) {
      print $fd "depend $_\n";
    }
  }
  if (defined($self-&gt;{'executes'})) {
    foreach (sort @{$self-&gt;{'executes'}}) {
      print $fd "execute $_\n";
    }
  }
  if (defined($self-&gt;{'postactions'})) {
    foreach (sort @{$self-&gt;{'postactions'}}) {
      print $fd "postaction $_\n";
    }
  }
  if (defined($self-&gt;{'docfiles'}) &amp;&amp; (@{$self-&gt;{'docfiles'}})) {
    print $fd "docfiles\n";
    foreach (sort @{$self-&gt;{'docfiles'}}) {
      print $fd " $_\n";
    }
  }
  if (defined($self-&gt;{'srcfiles'}) &amp;&amp; (@{$self-&gt;{'srcfiles'}})) {
    print $fd "srcfiles\n";
    foreach (sort @{$self-&gt;{'srcfiles'}}) {
      print $fd " $_\n";
    }
  }
  if (defined($self-&gt;{'runfiles'}) &amp;&amp; (@{$self-&gt;{'runfiles'}})) {
    print $fd "runfiles\n";
    foreach (sort @{$self-&gt;{'runfiles'}}) {
      print $fd " $_\n";
    }
  }
  foreach my $arch (sort keys %{$self-&gt;{'binfiles'}}) {
    if (@{$self-&gt;{'binfiles'}{$arch}}) {
      print $fd "binfiles arch=$arch\n";
      foreach (sort @{$self-&gt;{'binfiles'}{$arch}}) {
        print $fd " $_\n";
      }
    }
  }
}

sub as_json {
  my $self = shift;
  my %addargs = @_;
  my %foo = %{$self};
  # set the additional args
  for my $k (keys %addargs) {
    if (defined($addargs{$k})) {
      $foo{$k} = $addargs{$k};
    } else {
      delete($foo{$k});
    }
  }
  # make sure numbers are encoded as numbers
  for my $k (qw/revision runsize docsize srcsize containersize lrev rrev
                srccontainersize doccontainersize runcontainersize/) {
    $foo{$k} += 0 if exists($foo{$k});
  }
  for my $k (keys %{$foo{'binsize'}}) {
    $foo{'binsize'}{$k} += 0;
  }
  # encode boolean as boolean flags
  if (exists($foo{'relocated'})) {
    if ($foo{'relocated'}) {
      $foo{'relocated'} = TeXLive::TLUtils::True();
    } else {
      $foo{'relocated'} = TeXLive::TLUtils::False();
    }
  }
  # adjust the docfiles entry to the specification in JSON-formats
  my @docf = $self-&gt;docfiles;
  my $dfd = $self-&gt;docfiledata;
  my @newdocf;
  for my $f ($self-&gt;docfiles) {
    my %newd;
    $newd{'file'} = $f;
    if (defined($dfd-&gt;{$f})) {
      # "details" and "language" keys now, but more could be added any time.
      # (Such new keys would have to be added in update_from_catalogue.)
      for my $k (keys %{$dfd-&gt;{$f}}) {
        $newd{$k} = $dfd-&gt;{$f}-&gt;{$k};
      }
    }
    push @newdocf, \%newd;
  }
  $foo{'docfiles'} = [ @newdocf ];
  delete($foo{'docfiledata'});
  #
  my $utf8_encoded_json_text = TeXLive::TLUtils::encode_json(\%foo);
  return $utf8_encoded_json_text;
}


sub cancel_reloc_prefix {
  my $self = shift;
  my @docfiles = $self-&gt;docfiles;
  for (@docfiles) { s:^$RelocPrefix/::; }
  $self-&gt;docfiles(@docfiles);
  my @runfiles = $self-&gt;runfiles;
  for (@runfiles) { s:^$RelocPrefix/::; }
  $self-&gt;runfiles(@runfiles);
  my @srcfiles = $self-&gt;srcfiles;
  for (@srcfiles) { s:^$RelocPrefix/::; }
  $self-&gt;srcfiles(@srcfiles);
  # if there are bin files they have definitely NOT the
  # texmf-dist prefix, so we cannot cancel it anyway
}

sub replace_reloc_prefix {
  my $self = shift;
  my @docfiles = $self-&gt;docfiles;
  for (@docfiles) { s:^$RelocPrefix/:$RelocTree/:; }
  $self-&gt;docfiles(@docfiles);
  my @runfiles = $self-&gt;runfiles;
  for (@runfiles) { s:^$RelocPrefix/:$RelocTree/:; }
  $self-&gt;runfiles(@runfiles);
  my @srcfiles = $self-&gt;srcfiles;
  for (@srcfiles) { s:^$RelocPrefix/:$RelocTree/:; }
  $self-&gt;srcfiles(@srcfiles);
  # docfiledata needs to be adapted too
  my $data = $self-&gt;docfiledata;
  my %newdata;
  while (my ($k, $v) = each %$data) {
    $k =~ s:^$RelocPrefix/:$RelocTree/:;
    $newdata{$k} = $v;
  }
  $self-&gt;docfiledata(%newdata);
  # if there are bin files they have definitely NOT the
  # texmf-dist prefix, so no reloc to replace
}

sub cancel_common_texmf_tree {
  my $self = shift;
  my @docfiles = $self-&gt;docfiles;
  for (@docfiles) { s:^$RelocTree/:$RelocPrefix/:; }
  $self-&gt;docfiles(@docfiles);
  my @runfiles = $self-&gt;runfiles;
  for (@runfiles) { s:^$RelocTree/:$RelocPrefix/:; }
  $self-&gt;runfiles(@runfiles);
  my @srcfiles = $self-&gt;srcfiles;
  for (@srcfiles) { s:^$RelocTree/:$RelocPrefix/:; }
  $self-&gt;srcfiles(@srcfiles);
  # docfiledata needs to be adapted too
  my $data = $self-&gt;docfiledata;
  my %newdata;
  while (my ($k, $v) = each %$data) {
    $k =~ s:^$RelocTree/:$RelocPrefix/:;
    $newdata{$k} = $v;
  }
  $self-&gt;docfiledata(%newdata);
  # if there are bin files they have definitely NOT the
  # texmf-dist prefix, so we cannot cancel it anyway
}

sub common_texmf_tree {
  my $self = shift;
  my $tltree;
  my $dd = 0;
  my @files = $self-&gt;all_files;
  foreach ($self-&gt;all_files) {
    my $tmp;
    ($tmp) = split m@/@;
    if (defined($tltree) &amp;&amp; ($tltree ne $tmp)) {
      return;
    } else {
      $tltree = $tmp;
    }
  }
  # if there are no files then it is by default relocatable, so 
  # return the right tree
  if (!@files) {
    $tltree = $RelocTree;
  }
  return $tltree;
}


sub make_container {
  my ($self, $type, $instroot, %other) = @_;
  my $destdir = ($other{'destdir'} || undef);
  my $containername = ($other{'containername'} || undef);
  my $relative = ($other{'relative'} || undef);
  my $user = ($other{'user'} || undef);
  my $copy_instead_of_link = ($other{'copy_instead_of_link'} || undef);
  if (!($type eq 'tar' ||
        TeXLive::TLUtils::member($type, @{$::progs{'working_compressors'}}))) {
    tlwarn "$0: TLPOBJ supports @{$::progs{'working_compressors'}} and tar containers, not $type\n";
    tlwarn "$0: falling back to $DefaultCompressorFormat as container type!\n";
    $type = $DefaultCompressorFormat;
  }

  if (!defined($containername)) {
    $containername = $self-&gt;name;
  }
  my @files = $self-&gt;all_files;
  my $compresscmd;
  my $tlpobjdir = "$InfraLocation/tlpobj";
  @files = TeXLive::TLUtils::sort_uniq(@files);
  # we do relative packages ONLY if the files do NOT span multiple
  # texmf trees. check this here
  my $tltree;
  if ($relative) {
    $tltree = $self-&gt;common_texmf_tree;
    if (!defined($tltree)) {
      die ("$0: package $containername spans multiple trees, "
           . "relative generation not allowed");
    }
    if ($tltree ne $RelocTree) {
      die ("$0: building $containername container relocatable but the common"
           . " prefix is not $RelocTree");
    } 
    s,^$RelocTree/,, foreach @files;
  }
  # load Cwd only if necessary ...
  require Cwd;
  my $cwd = &amp;Cwd::getcwd;
  if ("$destdir" !~ m@^(.:)?[/\\]@) {
    # we have an relative containerdir, so we have to make it absolute
    $destdir = "$cwd/$destdir";
  }
  &amp;TeXLive::TLUtils::mkdirhier("$destdir");
  chdir($instroot);
  # in the relative case we have to chdir to the respective tltree
  # and put the tlpobj into the root!
  my $removetlpkgdir = 0;
  if ($relative) {
    chdir("./$tltree");
    # in the relocatable case we will probably create the tlpkg dir
    # in texmf-dist/tlpkg and want to remove it afterwards.
    $removetlpkgdir = 1;
    # we don't need to change the $tlpobjdir because we put it in
    # all cases into tlpkg/tlpobj
    #$tlpobjdir = "./tlpkg/tlpobj";
  }
  # we add the .tlpobj into the .tlpobj directory
  my $removetlpobjdir = 0;
  if (! -d "$tlpobjdir") {
    &amp;TeXLive::TLUtils::mkdirhier("$tlpobjdir");
    $removetlpobjdir = 1;
  }
  open(TMP,"&gt;$tlpobjdir/$self-&gt;{'name'}.tlpobj") 
  || die "$0: create($tlpobjdir/$self-&gt;{'name'}.tlpobj) failed: $!";
  # when we do relative we have to cancel the prefix before writing out
  my $selfcopy = $self-&gt;copy;
  if ($relative) {
    $selfcopy-&gt;cancel_common_texmf_tree;
    $selfcopy-&gt;relocated($relative);
  }
  $selfcopy-&gt;writeout(\*TMP);
  close(TMP);
  push(@files, "$tlpobjdir/$self-&gt;{'name'}.tlpobj");
  # versioned containers
  my $tarname = "$containername.r" . $self-&gt;revision . ".tar";
  my $unversionedtar;
  $unversionedtar = "$containername.tar" if (! $user);

  # start the fun
  my $tar = $::progs{'tar'};
  if (!defined($tar)) {
    tlwarn("$0: programs not set up, trying \"tar\".\n");
    $tar = "tar";
  }

  $containername = $tarname;

  # Here we need to distinguish between making the master containers for
  # tlnet (where we can assume GNU tar) and making backups on a user's
  # machine (where we can assume nothing).  We determine this by whether
  # there's a revision suffix in the container name.
  # 
  # For the master containers, we want to set the owner/group, exclude
  # .svn directories, and force ustar format.  This last is for the sake
  # of packages such as pgf which have filenames long enough that they
  # overflow standard tar format and result in special things being
  # done.  We don't want the GNU-specific special things.
  #
  # We use versioned containers throughout, user mode is determined by
  # argument.
  my $is_user_container = $user;
  my @attrs
    = $is_user_container
      ? ()
      : ( "--owner", "0",  "--group", "0",  "--exclude", ".svn",
          "--format", "ustar" );
  my @cmdline = ($tar, "-cf", "$destdir/$tarname", @attrs);
  
  # Get list of files and symlinks to back up.  Nothing else should be
  # in the list.
  my @files_to_backup = ();
  for my $f (@files) {
    if (-f $f || -l $f) {
      push(@files_to_backup, $f);
    } elsif (! -e $f) {
      tlwarn("$0: (make_container $containername) $f does not exist\n");
    } else {
      tlwarn("$0: (make_container $containername) $f not file or symlink\n");
      if (! wndws()) {
        tlwarn("$0:   ", `ls -l $f 2&gt;&amp;1`);
      }
    }
  }
  
  my $tartempfile = "";
  if (wndws()) {
    # Since we provide our own (GNU) tar on Windows, we know it has -T.
    my $tmpdir = TeXLive::TLUtils::tl_tmpdir();
    $tartempfile = "$tmpdir/mc$$";
    open(TMP, "&gt;$tartempfile") || die "open(&gt;$tartempfile) failed: $!";
    print TMP map { "$_\n" } @files_to_backup;
    close(TMP) || warn "close(&gt;$tartempfile) failed: $!";
    push(@cmdline, "-T", $tartempfile);
  } else {
    # For Unix, we pass all the files on the command line, because there
    # is no portable (across different platforms and different tars)  way
    # to pass them on stdin.  Unfortunately, this can be too lengthy of
    # a command line -- our biggest package is tex4ht, which needs about
    # 200k.  CentOS 5.2, at least, starts complaining around 140k.
    # 
    # Therefore, if the command is likely to be too long, we call
    # our collapse_dirs routine; in practice, this eliminates
    # essentially all the individual files, leaving just a few
    # directories, which is no problem.  (For example, tex4ht collapses
    # down to five directories and one file.)
    # 
    # Although in principle we could do this in all cases, collapse_dirs
    # isn't the most thoroughly tested function in the world.  It seems
    # safer to only do it in the (few) potentially problematic cases.
    # 
    if (length ("@files_to_backup") &gt; 50000) {
      @files_to_backup = TeXLive::TLUtils::collapse_dirs(@files_to_backup);
      # A complication, as always.  collapse_dirs returns absolute paths.
      # We want to change them back to relative so that the backup tar
      # has the same structure.
      # In relative mode we have to remove the texmf-dist prefix, too.
      s,^$instroot/,, foreach @files_to_backup;
      if ($relative) {
        s,^$RelocTree/,, foreach @files_to_backup;
      }
    }
    push(@cmdline, @files_to_backup);
  }

  # Run tar. Unlink both here in case the container is also plain tar.
  unlink("$destdir/$tarname");
  unlink("$destdir/$unversionedtar") if (! $user);
  unlink("$destdir/$containername");
  xsystem(@cmdline);

  if ($type ne 'tar') {
    # compress it
    my $compressor = $::progs{$type};
    if (!defined($compressor)) {
      # fall back to $type as compressor, but that shouldn't happen
      tlwarn("$0: programs not set up, trying \"$type\".\n");
      $compressor = $type;
    }
    my @compressorargs = @{$Compressors{$type}{'compress_args'}};
    my $compressorextension = $Compressors{$type}{'extension'};
    $containername = "$tarname.$compressorextension";
    debug("selected compressor: $compressor with @compressorargs, "
          . "on $destdir/$tarname\n");
  
    # compress it.
    if (-r "$destdir/$tarname") {
      # system return 0 on success
      if (system($compressor, @compressorargs, "$destdir/$tarname")) {
        tlwarn("$0: Couldn't compress $destdir/$tarname\n");
        return (0,0, "");
      }
      # make sure we remove the original tar since old lz4 versions
      # cannot automatically delete it.
      # We remove the tar file only when the compressed file was
      # correctly created, something that should only happen in the
      # most strange cases.
      unlink("$destdir/$tarname")
        if ((-r "$destdir/$tarname") &amp;&amp; (-r "$destdir/$containername"));
      # in case of system containers also create the links to the 
      # versioned containers
      if (! $user) {
        my $linkname = "$destdir/$unversionedtar.$compressorextension";
        unlink($linkname) if (-r $linkname);
        if ($copy_instead_of_link) {
          TeXLive::TLUtils::copy("-f", "$destdir/$containername", $linkname)
        } else {
          if (!symlink($containername, $linkname)) {
            tlwarn("$0: Couldn't generate link $linkname -&gt; $containername?\n");
          }
        }
      }
    } else {
      tlwarn("$0: Couldn't find $destdir/$tarname to run $compressor\n");
      return (0, 0, "");
    }
  }
  
  # compute the size.
  if (! -r "$destdir/$containername") {
    tlwarn ("$0: Couldn't find $destdir/$containername\n");
    return (0, 0, "");
  }
  my $size = (stat "$destdir/$containername") [7];
  #
  # if we are creating a system container, or there is a way to
  # compute the checksums, do it
  my $checksum = "";
  if (!$is_user_container || $::checksum_method) {
    $checksum = TeXLive::TLCrypto::tlchecksum("$destdir/$containername");
  }
  
  # cleaning up
  unlink("$tlpobjdir/$self-&gt;{'name'}.tlpobj");
  unlink($tartempfile) if $tartempfile;
  rmdir($tlpobjdir) if $removetlpobjdir;
  rmdir($InfraLocation) if $removetlpkgdir;
  xchdir($cwd);

  debug(" done $containername, size $size, csum $checksum\n");
  return ($size, $checksum, "$destdir/$containername");
}



sub is_arch_dependent {
  my $self = shift;
  if (keys %{$self-&gt;{'binfiles'}}) {
    return 1;
  } else {
    return 0;
  }
}

# computes the total size of a package
# if no arguments are given this is
#   docsize + runsize + srcsize + max of binsize
sub total_size {
  my ($self,@archs) = @_;
  my $ret = $self-&gt;docsize + $self-&gt;runsize + $self-&gt;srcsize;
  if ($self-&gt;is_arch_dependent) {
    my $max = 0;
    my %foo = %{$self-&gt;binsize};
    foreach my $k (keys %foo) {
      $max = $foo{$k} if ($foo{$k} &gt; $max);
    }
    $ret += $max;
  }
  return($ret);
}


# update_from_catalogue($tlc)
# Update the current TLPOBJ object with the information from the
# corresponding entry in C&lt;$tlc-&gt;entries&gt;.
#
sub update_from_catalogue {
  my ($self, $tlc) = @_;
  my $tlcname = $self-&gt;name;
  if (defined($self-&gt;catalogue)) {
    $tlcname = $self-&gt;catalogue;
  } elsif ($tlcname =~ m/^bin-(.*)$/) {
    if (!defined($tlc-&gt;entries-&gt;{$tlcname})) {
      $tlcname = $1;
    }
  }
  $tlcname = lc($tlcname);
  if (defined($tlc-&gt;entries-&gt;{$tlcname})) {
    my $entry = $tlc-&gt;entries-&gt;{$tlcname};
    # Record the id of the catalogue entry if it's found.
    if ($entry-&gt;entry-&gt;{'id'} ne $tlcname) {
      $self-&gt;catalogue($entry-&gt;entry-&gt;{'id'});
    }
    if (defined($entry-&gt;license)) {
      $self-&gt;cataloguedata-&gt;{'license'} ||= $entry-&gt;license;
    }
    if (defined($entry-&gt;version) &amp;&amp; $entry-&gt;version ne "") {
      $self-&gt;cataloguedata-&gt;{'version'} ||= $entry-&gt;version;
    }
    if (defined($entry-&gt;ctan) &amp;&amp; $entry-&gt;ctan ne "") {
      $self-&gt;cataloguedata-&gt;{'ctan'} ||= $entry-&gt;ctan;
    }
    # TODO TODO TODO
    # we should rewrite the also fields to TeX Live package names ...
    # for now these are CTAN package names!
    # warning, we expect that cataloguedata entries are strings, 
    # so stringify these lists
    if (@{$entry-&gt;also}) {
      $self-&gt;cataloguedata-&gt;{'also'} ||= "@{$entry-&gt;also}";
    }
    if (@{$entry-&gt;alias}) {
      $self-&gt;cataloguedata-&gt;{'alias'} ||= "@{$entry-&gt;alias}";
    }
    if (@{$entry-&gt;topics}) {
      $self-&gt;cataloguedata-&gt;{'topics'} ||= "@{$entry-&gt;topics}";
    }
    if (%{$entry-&gt;contact}) {
      for my $k (keys %{$entry-&gt;contact}) {
        $self-&gt;cataloguedata-&gt;{"contact-$k"} ||= $entry-&gt;contact-&gt;{$k};
      }
    }
    #if (defined($entry-&gt;texlive)) {
    # $self-&gt;cataloguedata-&gt;{'texlive'} = $entry-&gt;texlive;
    #}
    #if (defined($entry-&gt;miktex)) {
    #  $self-&gt;cataloguedata-&gt;{'miktex'} = $entry-&gt;miktex;
    #}
    if (defined($entry-&gt;caption) &amp;&amp; $entry-&gt;caption ne "") {
      $self-&gt;{'shortdesc'} = $entry-&gt;caption unless $self-&gt;{'shortdesc'};
    }
    if (defined($entry-&gt;description) &amp;&amp; $entry-&gt;description ne "") {
      $self-&gt;{'longdesc'} = $entry-&gt;description unless $self-&gt;{'longdesc'};
    }
    #
    # we need to do the following:
    # - take the href entry for a documentation file entry in the TC
    # - remove the 'ctan:' prefix
    # - remove the &lt;ctan path='...'&gt; part
    # - match the rest against all docfiles in an intelligent way
    #
    # Example:
    # juramisc.xml contains:
    # &lt;documentation details='Package documentation' language='de'
    #   href='ctan:/macros/latex/contrib/juramisc/doc/jmgerdoc.pdf'/&gt;
    # &lt;ctan path='/macros/latex/contrib/juramisc'/&gt;
    my @tcdocfiles = keys %{$entry-&gt;docs};  # Catalogue doc files.
    my %tcdocfilebasenames;                 # basenames of those, as we go.
    my @tlpdocfiles = $self-&gt;docfiles;      # TL doc files.
    foreach my $tcdocfile (sort @tcdocfiles) {  # sort so shortest first
      #warn "looking at tcdocfile $tcdocfile\n";
      my $tcdocfilebasename = $tcdocfile;
      $tcdocfilebasename =~ s/^ctan://;  # remove ctan: prefix
      $tcdocfilebasename =~ s,.*/,,;     # remove all but the base file name
      #warn "  got basename $tcdocfilebasename\n";
      #
      # If we've already seen this basename, skip.  This is for the sake
      # of README files, which can exist in different directories but
      # get renamed into different files in TL for various annoying reasons;
      # e.g., ibygrk, rsfs, songbook.  In these cases, it turns out we
      # always prefer the first entry (top-level README).
      next if exists $tcdocfilebasenames{$tcdocfilebasename};
      $tcdocfilebasenames{$tcdocfilebasename} = 1;
      #
      foreach my $tlpdocfile (@tlpdocfiles) {
        #warn "considering merge into tlpdocfile $tlpdocfile\n";
        if ($tlpdocfile =~ m,/$tcdocfilebasename$,) {
          # update the language/detail tags from Catalogue if present.
          if (defined($entry-&gt;docs-&gt;{$tcdocfile}{'details'})) {
            my $tmp = $entry-&gt;docs-&gt;{$tcdocfile}{'details'};
            #warn "merging details for $tcdocfile: $tmp\n";
            # remove all embedded quotes, they are just a pain
            $tmp =~ s/"//g;
            $self-&gt;{'docfiledata'}{$tlpdocfile}{'details'} = $tmp;
          }
          if (defined($entry-&gt;docs-&gt;{$tcdocfile}{'language'})) {
            my $tmp = $entry-&gt;docs-&gt;{$tcdocfile}{'language'};
            #warn "merging lang for $tcdocfile: $tmp\n";
            $self-&gt;{'docfiledata'}{$tlpdocfile}{'language'} = $tmp;
          }
        }
      }
    }
  }
}

sub is_meta_package {
  my $self = shift;
  if ($self-&gt;category =~ /^$MetaCategoriesRegexp$/) {
    return 1;
  }
  return 0;
}

sub docfiles_package {
  my $self = shift;
  if (not($self-&gt;docfiles)) { return ; }
  my $tlp = new TeXLive::TLPOBJ;
  $tlp-&gt;name($self-&gt;name . ".doc");
  $tlp-&gt;shortdesc("doc files of " . $self-&gt;name);
  $tlp-&gt;revision($self-&gt;revision);
  $tlp-&gt;category($self-&gt;category);
  $tlp-&gt;add_docfiles($self-&gt;docfiles);
  $tlp-&gt;docsize($self-&gt;docsize);
  # $self-&gt;clear_docfiles();
  # $self-&gt;docsize(0);
  return($tlp);
}

sub srcfiles_package {
  my $self = shift;
  if (not($self-&gt;srcfiles)) { return ; }
  my $tlp = new TeXLive::TLPOBJ;
  $tlp-&gt;name($self-&gt;name . ".source");
  $tlp-&gt;shortdesc("source files of " . $self-&gt;name);
  $tlp-&gt;revision($self-&gt;revision);
  $tlp-&gt;category($self-&gt;category);
  $tlp-&gt;add_srcfiles($self-&gt;srcfiles);
  $tlp-&gt;srcsize($self-&gt;srcsize);
  # $self-&gt;clear_srcfiles();
  # $self-&gt;srcsize(0);
  return($tlp);
}

sub split_bin_package {
  my $self = shift;
  my %binf = %{$self-&gt;binfiles};
  my @retlist;
  foreach $a (keys(%binf)) {
    my $tlp = new TeXLive::TLPOBJ;
    $tlp-&gt;name($self-&gt;name . ".$a");
    $tlp-&gt;shortdesc("$a files of " . $self-&gt;name);
    $tlp-&gt;revision($self-&gt;revision);
    $tlp-&gt;category($self-&gt;category);
    $tlp-&gt;add_binfiles($a,@{$binf{$a}});
    $tlp-&gt;binsize( $a =&gt; $self-&gt;binsize-&gt;{$a} );
    push @retlist, $tlp;
  }
  if (keys(%binf)) {
    push @{$self-&gt;{'depends'}}, $self-&gt;name . ".ARCH";
  }
  $self-&gt;clear_binfiles();
  return(@retlist);
}


# Helpers.
#
sub add_files {
  my ($self,$type,@files) = @_;
  die("Cannot use add_files for binfiles, we need that arch!")
    if ($type eq "bin");
  &amp;TeXLive::TLUtils::push_uniq(\@{ $self-&gt;{"${type}files"} }, @files);
}

sub remove_files {
  my ($self,$type,@files) = @_;
  die("Cannot use remove_files for binfiles, we need that arch!")
    if ($type eq "bin");
  my @finalfiles;
  foreach my $f (@{$self-&gt;{"${type}files"}}) {
    if (not(&amp;TeXLive::TLUtils::member($f,@files))) {
      push @finalfiles,$f;
    }
  }
  $self-&gt;{"${type}files"} = [ @finalfiles ];
}

sub contains_file {
  my ($self,$fn) = @_;
  # if the filename already contains a / do not add it at the beginning
  my $ret = "";
  if ($fn =~ m!/!) {
    return(grep(m!$fn$!, $self-&gt;all_files));
  } else {
    return(grep(m!(^|/)$fn$!,$self-&gt;all_files));
  }
}

sub all_files {
  my ($self) = shift;
  my @ret = ();

  push (@ret, $self-&gt;docfiles);
  push (@ret, $self-&gt;runfiles);
  push (@ret, $self-&gt;srcfiles);
  push (@ret, $self-&gt;allbinfiles);

  return @ret;
}

sub allbinfiles {
  my $self = shift;
  my @ret = ();
  my %binfiles = %{$self-&gt;binfiles};

  foreach my $arch (keys %binfiles) {
    push (@ret, @{$binfiles{$arch}});
  }

  return @ret;
}

sub format_definitions {
  my $self = shift;
  my $pkg = $self-&gt;name;
  my @ret;
  for my $e ($self-&gt;executes) {
    if ($e =~ m/AddFormat\s+(.*)\s*/) {
      my %r = TeXLive::TLUtils::parse_AddFormat_line("$1");
      if (defined($r{"error"})) {
        die "$r{'error'}, package $pkg, execute $e";
      }
      push @ret, \%r;
    }
  }
  return @ret;
}

#
# execute stuff
#
sub fmtutil_cnf_lines {
  my $obj = shift;
  my @disabled = @_;
  my @fmtlines = ();
  my $first = 1;
  my $pkg = $obj-&gt;name;
  foreach my $e ($obj-&gt;executes) {
    if ($e =~ m/AddFormat\s+(.*)\s*/) {
      my %r = TeXLive::TLUtils::parse_AddFormat_line("$1");
      if (defined($r{"error"})) {
        die "$r{'error'}, package $pkg, execute $e";
      }
      if ($first) {
        push @fmtlines, "#\n# from $pkg:\n";
        $first = 0;
      }
      my $mode = ($r{"mode"} ? "" : "#! ");
      $mode = "#! " if TeXLive::TLUtils::member ($r{'name'}, @disabled);
      push @fmtlines, "$mode$r{'name'} $r{'engine'} $r{'patterns'} $r{'options'}\n";
    }
  }
  return @fmtlines;
}


sub updmap_cfg_lines {
  my $obj = shift;
  my @disabled = @_;
  my %maps;
  foreach my $e ($obj-&gt;executes) {
    if ($e =~ m/addMap (.*)$/) {
      $maps{$1} = 1;
    } elsif ($e =~ m/addMixedMap (.*)$/) {
      $maps{$1} = 2;
    } elsif ($e =~ m/addKanjiMap (.*)$/) {
      $maps{$1} = 3;
    }
    # others are ignored here
  }
  my @updmaplines;
  foreach (sort keys %maps) {
    next if TeXLive::TLUtils::member($_, @disabled);
    if ($maps{$_} == 1) {
      push @updmaplines, "Map $_\n";
    } elsif ($maps{$_} == 2) {
      push @updmaplines, "MixedMap $_\n";
    } elsif ($maps{$_} == 3) {
      push @updmaplines, "KanjiMap $_\n";
    } else {
      tlerror("Should not happen!\n");
    }
  }
  return(@updmaplines);
}


our @disabled; # global, should handle differently ...

sub language_dat_lines {
  my $self = shift;
  local @disabled = @_;  # we use @disabled in the nested sub
  my @lines = $self-&gt;_parse_hyphen_execute(\&amp;make_dat_lines, 'dat');
  return @lines;

  sub make_dat_lines {
    my ($name, $lhm, $rhm, $file, $syn) = @_;
    my @ret;
    return if TeXLive::TLUtils::member($name, @disabled);
    push @ret, "$name $file\n";
    foreach (@$syn) {
      push @ret, "=$_\n";
    }
    return @ret;
  }
}


sub language_def_lines {
  my $self = shift;
  local @disabled = @_;  # we use @disabled in the nested sub
  my @lines = $self-&gt;_parse_hyphen_execute(\&amp;make_def_lines, 'def');
  return @lines;

  sub make_def_lines {
    my ($name, $lhm, $rhm, $file, $syn) = @_;
    return if TeXLive::TLUtils::member($name, @disabled);
    my $exc = "";
    my @ret;
    push @ret, "\\addlanguage\{$name\}\{$file\}\{$exc\}\{$lhm\}\{$rhm\}\n";
    foreach (@$syn) {
      # synonyms in language.def ???
      push @ret, "\\addlanguage\{$_\}\{$file\}\{$exc\}\{$lhm\}\{$rhm\}\n";
      #debug("Ignoring synonym $_ for $name when creating language.def\n");
    }
    return @ret;
  }
}


sub language_lua_lines {
  my $self = shift;
  local @disabled = @_;  # we use @disabled in the nested sub
  my @lines = $self-&gt;_parse_hyphen_execute(\&amp;make_lua_lines, 'lua', '--');
  return @lines;

  sub make_lua_lines {
    my ($name, $lhm, $rhm, $file, $syn, $patt, $hyph, $special) = @_;
    return if TeXLive::TLUtils::member($name, @disabled);
    my @syn = (@$syn); # avoid modifying the original
    map { $_ = "'$_'" } @syn;
    my @ret;
    push @ret, "['$name'] = {", "\tloader = '$file',",
               "\tlefthyphenmin = $lhm,", "\trighthyphenmin = $rhm,",
               "\tsynonyms = { " . join(', ', @syn) . " },";
    push @ret, "\tpatterns = '$patt'," if defined $patt;
    push @ret, "\thyphenation = '$hyph'," if defined $hyph;
    push @ret, "\tspecial = '$special'," if defined $special;
    push @ret, '},';
    map { $_ = "\t$_\n" } @ret;
    return @ret;
  }
}


sub _parse_hyphen_execute {
  my ($obj, $coderef, $db, $cc) = @_;
  $cc ||= '%'; # default comment char
  my @langlines = ();
  my $pkg = $obj-&gt;name;
  my $first = 1;
  foreach my $e ($obj-&gt;executes) {
    if ($e =~ m/AddHyphen\s+(.*)\s*/) {
      my %r = TeXLive::TLUtils::parse_AddHyphen_line("$1");
      if (defined($r{"error"})) {
        die "$r{'error'}, package $pkg, execute $e";
      }
      if (not TeXLive::TLUtils::member($db, @{$r{"databases"}})) {
        next;
      }
      if ($first) {
        push @langlines, "$cc from $pkg:\n";
        $first = 0;
      }
      if ($r{"comment"}) {
          push @langlines, "$cc $r{comment}\n";
      }
      my @foo = &amp;$coderef ($r{"name"}, $r{"lefthyphenmin"},
                           $r{"righthyphenmin"}, $r{"file"}, $r{"synonyms"},
                           $r{"file_patterns"}, $r{"file_exceptions"},
                           $r{"luaspecial"});
      push @langlines, @foo;
    }
  }
  return @langlines;
}



# member access functions
#
sub _set_get_array_value {
  my $self = shift;
  my $key = shift;
  if (@_) { 
    if (defined($_[0])) {
      $self-&gt;{$key} = [ @_ ];
    } else {
      $self-&gt;{$key} = [ ];
    }
  }
  return @{ $self-&gt;{$key} };
}
sub name {
  my $self = shift;
  if (@_) { $self-&gt;{'name'} = shift }
  return $self-&gt;{'name'};
}
sub category {
  my $self = shift;
  if (@_) { $self-&gt;{'category'} = shift }
  return $self-&gt;{'category'};
}
sub shortdesc {
  my $self = shift;
  if (@_) { $self-&gt;{'shortdesc'} = shift }
  return $self-&gt;{'shortdesc'};
}
sub longdesc {
  my $self = shift;
  if (@_) { $self-&gt;{'longdesc'} = shift }
  return $self-&gt;{'longdesc'};
}
sub revision {
  my $self = shift;
  if (@_) { $self-&gt;{'revision'} = shift }
  return $self-&gt;{'revision'};
}
sub relocated {
  my $self = shift;
  if (@_) { $self-&gt;{'relocated'} = shift }
  return ($self-&gt;{'relocated'} ? 1 : 0);
}
sub catalogue {
  my $self = shift;
  if (@_) { $self-&gt;{'catalogue'} = shift }
  return $self-&gt;{'catalogue'};
}
sub srcfiles {
  _set_get_array_value(shift, "srcfiles", @_);
}
sub containersize {
  my $self = shift;
  if (@_) { $self-&gt;{'containersize'} = shift }
  return ( defined($self-&gt;{'containersize'}) ? $self-&gt;{'containersize'} : -1 );
}
sub srccontainersize {
  my $self = shift;
  if (@_) { $self-&gt;{'srccontainersize'} = shift }
  return ( defined($self-&gt;{'srccontainersize'}) ? $self-&gt;{'srccontainersize'} : -1 );
}
sub doccontainersize {
  my $self = shift;
  if (@_) { $self-&gt;{'doccontainersize'} = shift }
  return ( defined($self-&gt;{'doccontainersize'}) ? $self-&gt;{'doccontainersize'} : -1 );
}
sub containermd5 {
  my $self = shift;
  if (@_) { $self-&gt;{'containermd5'} = shift }
  if (defined($self-&gt;{'containermd5'})) {
    return ($self-&gt;{'containermd5'});
  } else {
    tlwarn("TLPOBJ: MD5 sums are no longer supported, please adapt your code!\n");
    return ("");
  }
}
sub srccontainermd5 {
  my $self = shift;
  if (@_) { $self-&gt;{'srccontainermd5'} = shift }
  if (defined($self-&gt;{'srccontainermd5'})) {
    return ($self-&gt;{'srccontainermd5'});
  } else {
    tlwarn("TLPOBJ: MD5 sums are no longer supported, please adapt your code!\n");
    return ("");
  }
}
sub doccontainermd5 {
  my $self = shift;
  if (@_) { $self-&gt;{'doccontainermd5'} = shift }
  if (defined($self-&gt;{'doccontainermd5'})) {
    return ($self-&gt;{'doccontainermd5'});
  } else {
    tlwarn("TLPOBJ: MD5 sums are no longer supported, please adapt your code!\n");
    return ("");
  }
}
sub containerchecksum {
  my $self = shift;
  if (@_) { $self-&gt;{'containerchecksum'} = shift }
  return ( defined($self-&gt;{'containerchecksum'}) ? $self-&gt;{'containerchecksum'} : "" );
}
sub srccontainerchecksum {
  my $self = shift;
  if (@_) { $self-&gt;{'srccontainerchecksum'} = shift }
  return ( defined($self-&gt;{'srccontainerchecksum'}) ? $self-&gt;{'srccontainerchecksum'} : "" );
}
sub doccontainerchecksum {
  my $self = shift;
  if (@_) { $self-&gt;{'doccontainerchecksum'} = shift }
  return ( defined($self-&gt;{'doccontainerchecksum'}) ? $self-&gt;{'doccontainerchecksum'} : "" );
}
sub srcsize {
  my $self = shift;
  if (@_) { $self-&gt;{'srcsize'} = shift }
  return ( defined($self-&gt;{'srcsize'}) ? $self-&gt;{'srcsize'} : 0 );
}
sub clear_srcfiles {
  my $self = shift;
  $self-&gt;{'srcfiles'} = [ ] ;
}
sub add_srcfiles {
  my ($self,@files) = @_;
  $self-&gt;add_files("src",@files);
}
sub remove_srcfiles {
  my ($self,@files) = @_;
  $self-&gt;remove_files("src",@files);
}
sub docfiles {
  _set_get_array_value(shift, "docfiles", @_);
}
sub clear_docfiles {
  my $self = shift;
  $self-&gt;{'docfiles'} = [ ] ;
}
sub docsize {
  my $self = shift;
  if (@_) { $self-&gt;{'docsize'} = shift }
  return ( defined($self-&gt;{'docsize'}) ? $self-&gt;{'docsize'} : 0 );
}
sub add_docfiles {
  my ($self,@files) = @_;
  $self-&gt;add_files("doc",@files);
}
sub remove_docfiles {
  my ($self,@files) = @_;
  $self-&gt;remove_files("doc",@files);
}
sub docfiledata {
  my $self = shift;
  my %newfiles = @_;
  if (@_) { $self-&gt;{'docfiledata'} = \%newfiles }
  return $self-&gt;{'docfiledata'};
}
sub binfiles {
  my $self = shift;
  my %newfiles = @_;
  if (@_) { $self-&gt;{'binfiles'} = \%newfiles }
  return $self-&gt;{'binfiles'};
}
sub clear_binfiles {
  my $self = shift;
  $self-&gt;{'binfiles'} = { };
}
sub binsize {
  my $self = shift;
  my %newsizes = @_;
  if (@_) { $self-&gt;{'binsize'} = \%newsizes }
  return $self-&gt;{'binsize'};
}
sub add_binfiles {
  my ($self,$arch,@files) = @_;
  &amp;TeXLive::TLUtils::push_uniq(\@{ $self-&gt;{'binfiles'}{$arch} }, @files);
}
sub remove_binfiles {
  my ($self,$arch,@files) = @_;
  my @finalfiles;
  foreach my $f (@{$self-&gt;{'binfiles'}{$arch}}) {
    if (not(&amp;TeXLive::TLUtils::member($f,@files))) {
      push @finalfiles,$f;
    }
  }
  $self-&gt;{'binfiles'}{$arch} = [ @finalfiles ];
}
sub runfiles {
  _set_get_array_value(shift, "runfiles", @_);
}
sub clear_runfiles {
  my $self = shift;
  $self-&gt;{'runfiles'} = [ ] ;
}
sub runsize {
  my $self = shift;
  if (@_) { $self-&gt;{'runsize'} = shift }
  return ( defined($self-&gt;{'runsize'}) ? $self-&gt;{'runsize'} : 0 );
}
sub add_runfiles {
  my ($self,@files) = @_;
  $self-&gt;add_files("run",@files);
}
sub remove_runfiles {
  my ($self,@files) = @_;
  $self-&gt;remove_files("run",@files);
}
sub depends {
  _set_get_array_value(shift, "depends", @_);
}
sub executes {
  _set_get_array_value(shift, "executes", @_);
}
sub postactions {
  _set_get_array_value(shift, "postactions", @_);
}
sub containerdir {
  my @self = shift;
  if (@_) { $_containerdir = $_[0] }
  return $_containerdir;
}
sub cataloguedata {
  my $self = shift;
  my %ct = @_;
  if (@_) { $self-&gt;{'cataloguedata'} = \%ct }
  return $self-&gt;{'cataloguedata'};
}

$: = " \n"; # don't break at -
format multilineformat =
longdesc ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;~~
$_tmp
.

1;
__END__


=head1 NAME

C&lt;TeXLive::TLPOBJ&gt; -- TeX Live Package Object (C&lt;.tlpobj&gt;) module

=head1 SYNOPSIS

  use TeXLive::TLPOBJ;

  my $tlpobj = TeXLive::TLPOBJ-&gt;new(name =&gt; "foobar");

=head1 DESCRIPTION

The L&lt;TeXLive::TLPOBJ&gt; module provide access to TeX Live Package Object
(C&lt;.tlpobj&gt;) files, which describe a self-contained TL package.

=head1 FILE SPECIFICATION

See L&lt;TeXLive::TLPSRC&gt; documentation for the general syntax and
specification. The differences are:

=over 4

=item The various C&lt;*pattern&gt; keys are invalid.

=item Instead, there are respective C&lt;*files&gt; keys described below.
All the C&lt;*files&gt; keys are followed by a list of files in the given
category, one per line, each line I&lt;indented&gt; by one space.

=item Several new keys beginning with C&lt;catalogue-&gt; specify information
automatically taken from the TeX Catalogue.

=item A new key C&lt;revision&gt; is defined (automatically computed),
which specifies the maximum of all the last-changed revisions of files
contained in the package, plus possible other changes. By default,
Catalogue-only changes do not change the revision.

=item A new key C&lt;relocated&gt;, either 0 or 1, which indicates that this
packages has been relocated, i.e., in the containers the initial
C&lt;texmf-dist&gt; directory has been stripped off and replaced with static
string C&lt;RELOC&gt;.

=back

=over 4

=item C&lt;srcfiles&gt;, C&lt;runfiles&gt;, C&lt;binfiles&gt;, C&lt;docfiles&gt;
each of these items contains addition the sum of sizes of the single
files (in units of C&lt;TeXLive::TLConfig::BlockSize&gt; blocks, currently 4k).

  srcfiles size=NNNNNN
  runfiles size=NNNNNN

=item C&lt;docfiles&gt;

The docfiles line itself is similar to the C&lt;srcfiles&gt; and C&lt;runfiles&gt; lines
above:

  docfiles size=NNNNNN

But the lines listing the files are allowed to have additional tags,
(which in practice come from the TeX Catalogue)

  /------- excerpt from achemso.tlpobj
  |...
  |docfiles size=220
  | texmf-dist/doc/latex/achemso/achemso.pdf details="Package documentation" language="en"
  |...

Currently only the tags C&lt;details&gt; and C&lt;language&gt; are supported. These
additional information can be accessed via the C&lt;docfiledata&gt; function
returning a hash with the respective files (including path) as key.

=item C&lt;binfiles&gt;

Since C&lt;binfiles&gt; can be different for different architectures, a single
C&lt;tlpobj&gt; file can, and typically does, contain C&lt;binfiles&gt; lines for
all available architectures. The architecture is specified on the
C&lt;binfiles&gt; using the C&lt;arch=&gt;I&lt;XXX&gt; tag. Thus, C&lt;binfiles&gt; lines look
like

  binfiles arch=XXXX size=NNNNN

=back

Here is an excerpt from the representation of the C&lt;dvipsk&gt; package,
with C&lt;|&gt; characters inserted to show the indentation:

  |name dvipsk
  |category TLCore
  |revision 52851
  |docfiles size=285
  | texmf-dist/doc/dvips/dvips.html
  | ...
  |runfiles size=93
  | texmf-dist/dvips/base/color.pro
  | ...
  | texmf-dist/scripts/pkfix/pkfix.pl
  |binfiles arch=i386-solaris size=87
  | bin/i386-solaris/afm2tfm
  | bin/i386-solaris/dvips
  |binfiles arch=windows size=51
  | bin/windows/afm2tfm.exe
  | bin/windows/dvips.exe
  |...

=head1 PACKAGE VARIABLES

TeXLive::TLPOBJ has one package-wide variable, C&lt;containerdir&gt;, which is
where generated container files are saved (if not otherwise specified).

  TeXLive::TLPOBJ-&gt;containerdir("path/to/container/dir");

=head1 MEMBER ACCESS FUNCTIONS

For any of the I&lt;keys&gt; a function

  $tlpobj-&gt;key

is available, which returns the current value when called without an argument,
and sets the respective value when called with an argument. For the
TeX Catalogue Data the function

  $tlpobj-&gt;cataloguedata

returns and takes as argument a hash.

Arguments and return values for C&lt;name&gt;, C&lt;category&gt;, C&lt;shortdesc&gt;,
C&lt;longdesc&gt;, C&lt;catalogue&gt;, C&lt;revision&gt; are single scalars.

Arguments and return values for C&lt;depends&gt;, C&lt;executes&gt; are lists.

Arguments and return values for C&lt;docfiles&gt;, C&lt;runfiles&gt;, C&lt;srcfiles&gt;
are lists.

Arguments and return values for C&lt;binfiles&gt; is a hash with the
architectures as keys.

Arguments and return values for C&lt;docfiledata&gt; is a hash with the
full file names of docfiles as key, and the value is again a hash.

The size values are handled with these functions:

  $tlpobj-&gt;docsize
  $tlpobj-&gt;runsize
  $tlpobj-&gt;srcsize
  $tlpobj-&gt;binsize("arch1" =&gt; size1, "arch2" =&gt; size2, ...)

which set or get the current value of the respective sizes. Note that also
the C&lt;binsize&gt; function returns (and takes as argument) a hash with the
architectures as keys, similar to the C&lt;runfiles&gt; functions (see above).

Futhermore, if the tlpobj is contained ina tlpdb which describes a media
where the files are distributed in packed format (usually as .tar.xz),
there are 6 more possible keys:

  $tlpobj-&gt;containersize
  $tlpobj-&gt;doccontainersize
  $tlpobj-&gt;srccontainersize
  $tlpobj-&gt;containerchecksum
  $tlpobj-&gt;doccontainerchecksum
  $tlpobj-&gt;srccontainerchecksum

describing the respective sizes and checksums in bytes and as hex string, resp.
The latter two are only present if src/doc file container splitting is
activated for that install medium.

=head1 OTHER FUNCTIONS

The following functions can be called for a C&lt;TLPOBJ&gt; object:

=over 4

=item C&lt;new&gt;

The constructor C&lt;new&gt; returns a new C&lt;TLPSRC&gt; object. The arguments
to the C&lt;new&gt; constructor can be in the usual hash representation for
the different keys above:

  $tlpobj=TLPOBJ-&gt;new(name =&gt; "foobar", shortdesc =&gt; "The foobar package");

=item C&lt;from_file("filename")&gt;

reads a C&lt;tlpobj&gt; file.

  $tlpobj = new TLPOBJ;
  $tlpobj-&gt;from_file("path/to/the/tlpobj/file");

=item C&lt;from_fh($filehandle[, $multi])&gt;

read the textual representation of a TLPOBJ from an already opened
file handle.  If C&lt;$multi&gt; is undef (i.e., not given) then multiple
tlpobj in the same file are treated as errors. If C&lt;$multi&gt; is defined,
then returns after reading one tlpobj.

Returns C&lt;1&gt; if it found a C&lt;tlpobj&gt;, otherwise C&lt;0&gt;.

=item C&lt;writeout&gt;

writes the textual representation of a C&lt;TLPOBJ&gt; object to C&lt;stdout&gt;,
or the filehandle if given:

  $tlpsrc-&gt;writeout;
  $tlpsrc-&gt;writeout(\*FILEHANDLE);

=item C&lt;writeout_simple&gt;

debugging function for comparison with C&lt;tpm&gt;/C&lt;tlps&gt;, will go away.

=item C&lt;as_json&gt;

returns the representation of the C&lt;TLPOBJ&gt; in JSON format.

=item C&lt;common_texmf_tree&gt;

if all files of the package are from the same texmf tree, this tree 
is returned, otherwise an undefined value. That is also a check
whether a package is relocatable.

=item C&lt;make_container($type,$instroot, [ destdir =&gt; $destdir, containername =&gt; $containername, relative =&gt; 0|1, user =&gt; 0|1 ])&gt;

creates a container file of the all files in the C&lt;TLPOBJ&gt;
in C&lt;$destdir&gt; (if not defined then C&lt;&lt; TLPOBJ-&gt;containerdir &gt;&gt; is used).

The C&lt;$type&gt; variable specifies the type of container to be used.
Currently only C&lt;zip&gt; or C&lt;xz&gt; are allowed, and generate
zip files and tar.xz files, respectively.

The file name of the created container file is C&lt;$containername.extension&gt;,
where extension is either C&lt;.zip&gt; or C&lt;.tar.xz&gt;, depending on the
setting of C&lt;$type&gt;. If no C&lt;$containername&gt; is specified the package name
is used.

All container files B&lt;also&gt; contain the respective
C&lt;TLPOBJ&gt; file in C&lt;tlpkg/tlpobj/$name.tlpobj&gt;.

The argument C&lt;$instroot&gt; specifies the root of the installation from
which the files should be taken.

If the argument C&lt;$relative&gt; is passed and true (perlish true) AND the
packages does not span multiple texmf trees (i.e., all the first path
components of all files are the same) then a relative packages is created,
i.e., the first path component is stripped. In this case the tlpobj file
is placed into the root of the installation.

This is used to distribute packages which can be installed in any arbitrary
texmf tree (of other distributions, too).

If user is present and true, no extra arguments for container generation are
passed to tar (to make sure that user tar doesn't break).

Return values are the size, the checksum, and the full name of the container.

=item C&lt;recompute_sizes($tltree)&gt;

recomputes the sizes based on the information present in C&lt;$tltree&gt;.

=item C&lt;recompute_revision($tltree [, $revtlpsrc ])&gt;

recomputes the revision based on the information present in C&lt;$tltree&gt;.
The optional argument C&lt;$rectlpsrc&gt; can be an additional revision number
which is taken into account. C&lt;$tlpsrc-&gt;make_tlpobj&gt; adds the revision
number of the C&lt;tlpsrc&gt; file here so that collections (which do not
contain files) also have revision number.

=item C&lt;update_from_catalogue($texcatalogue)&gt;

adds information from a C&lt;TeXCatalogue&gt; object
(currently license, version, url, and updates docfiles with details and
languages tags if present in the Catalogue).

=item C&lt;split_bin_package&gt;

splits off the binfiles of C&lt;TLPOBJ&gt; into new independent C&lt;TLPOBJ&gt; with
the original name plus ".arch" for every arch for which binfiles are present.
The original package is changed in two respects: the binfiles are removed
(since they are now in the single name.arch packages), and an additional
depend on "name.ARCH" is added. Note that the ARCH is a placeholder.

=item C&lt;srcfiles_package&gt;

=item C&lt;docfiles_package&gt;

splits off the srcfiles or docfiles of C&lt;TLPOBJ&gt; into new independent
C&lt;TLPOBJ&gt; with
the original name plus ".sources". The source/doc files are
B&lt;not&gt; removed from the original package, since these functions are only
used for the creation of split containers.

=item C&lt;is_arch_dependent&gt;

returns C&lt;1&gt; if there are C&lt;binfiles&gt;, otherwise C&lt;0&gt;.

=item C&lt;total_size&gt;

If no argument is given returns the sum of C&lt;srcsize&gt;, C&lt;docsize&gt;,
C&lt;runsize&gt;.

If arguments are given, they are assumed to be architecture names, and
it returns the above plus the sum of sizes of C&lt;binsize&gt; for those
architectures.

=item C&lt;is_meta_package&gt;

Returns true if the package is a meta package as defined in TLConfig
(Currently Collection and Scheme).

=item C&lt;clear_{src,run,doc,bin}files&gt;

Removes all the src/run/doc/binfiles from the C&lt;TLPOBJ&gt;.

=item C&lt;{add,remove}_{src,run,doc}files(@files)&gt;

adds or removes files to the respective list of files.

=item C&lt;{add,remove}_binfiles($arch, @files)&gt;

adds or removes files from the list of C&lt;binfiles&gt; for the given architecture.

=item C&lt;{add,remove}_files($type, $files)&gt;

adds or removes files for the given type (only for C&lt;run&gt;, C&lt;src&gt;, C&lt;doc&gt;).

=item C&lt;contains_file($filename)&gt;

returns the list of files matching $filename which are contained in
the package. If $filename contains a / the matching is only anchored
at the end with $. Otherwise it is prefix with a / and anchored at the end.

=item C&lt;all_files&gt;

returns a list of all files of all types.  However, binary files won't
be found until dependencies have been expanded via (most likely)
L&lt;TeXLive::TLPDB::expand_dependencies&gt;.  For a more or less standalone
example, see the C&lt;find_old_files&gt; function in the
script C&lt;Master/tlpkg/libexec/place&gt;.

=item C&lt;allbinfiles&gt;

returns a list of all binary files.

=item C&lt;&lt; $tlpobj-&gt;format_definitions  &gt;&gt;

The function C&lt;format_definitions&gt; returns a list of references to hashes
where each hash is a format definition.

=item C&lt;&lt; $tlpobj-&gt;fmtutil_cnf_lines &gt;&gt;

The function C&lt;fmtutil_cnf_lines&gt; returns the lines for fmtutil.cnf 
for this package.

=item C&lt;&lt; $tlpobj-&gt;updmap_cfg_lines &gt;&gt;

The function C&lt;updmap_cfg_lines&gt; returns the list lines for updmap.cfg
for the given package.

=item C&lt;&lt; $tlpobj-&gt;language_dat_lines &gt;&gt;

The function C&lt;language_dat_lines&gt; returns the list of all
lines for language.dat that can be generated from the tlpobj

=item C&lt;&lt; $tlpobj-&gt;language_def_lines &gt;&gt;

The function C&lt;language_def_lines&gt; returns the list of all
lines for language.def that can be generated from the tlpobj.

=item C&lt;&lt; $tlpobj-&gt;language_lua_lines &gt;&gt;

The function C&lt;language_lua_lines&gt; returns the list of all
lines for language.dat.lua that can be generated from the tlpobj.

=back

=head1 SEE ALSO

The other modules in C&lt;Master/tlpkg/TeXLive/&gt; (L&lt;TeXLive::TLConfig&gt; and
the rest), and the scripts in C&lt;Master/tlpkg/bin/&gt; (especially
C&lt;tl-update-tlpdb&gt;), the documentation in C&lt;Master/tlpkg/doc/&gt;, etc.

=head1 AUTHORS AND COPYRIGHT

This script and its documentation were written for the TeX Live
distribution (L&lt;https://tug.org/texlive&gt;) and both are licensed under the
GNU General Public License Version 2 or later.

=cut

### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #
</pre></body></html>