summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2010-05-28 11:55:26 +0000
committerNorbert Preining <preining@logic.at>2010-05-28 11:55:26 +0000
commit6a603a72de517acee6c82d4d1334a4fc45041091 (patch)
treef88969144774008b2a5b956757eb50cd456febba /Master
parenta0cb3ae37b51b9af9b271a199f241fc0a2f92c6e (diff)
- make TLConfFile behave like kpathsea in the way that continuations of
comment lines are not supported - make tlmgr use TLConfFile for reading and writing the configuration file, this way we can now have arbitrary comments in it - TLConfFile: If a line cannot be parsed it is saved as comment and written out as is, but a big fat warning is issued git-svn-id: svn://tug.org/texlive/trunk@18550 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rwxr-xr-xMaster/texmf/scripts/texlive/tlmgr.pl77
-rw-r--r--Master/tlpkg/TeXLive/TLConfFile.pm20
2 files changed, 48 insertions, 49 deletions
diff --git a/Master/texmf/scripts/texlive/tlmgr.pl b/Master/texmf/scripts/texlive/tlmgr.pl
index d6dd8f77d69..b85677d825d 100755
--- a/Master/texmf/scripts/texlive/tlmgr.pl
+++ b/Master/texmf/scripts/texlive/tlmgr.pl
@@ -22,6 +22,7 @@ our $ismain;
our $loadmediasrcerror;
our $packagelogfile;
our $packagelogged;
+our $tlmgr_config_file;
BEGIN {
$^W = 1;
@@ -4417,62 +4418,46 @@ sub load_config_file
chomp (my $TEXMFCONFIG = `kpsewhich -var-value=TEXMFCONFIG`);
my $fn = "$TEXMFCONFIG/tlmgr/config";
- if (-r $fn) {
- if (!open(TLC, "<$fn")) {
- tlwarn("Cannot open $fn: $!");
- return;
- }
- while (<TLC>) {
- if (m/^\s*$/) { next; }
- if (m/^\s*#/) { next; }
- if (m/^\s*([\w-]+)\s*=\s*(.*)\s*$/) {
- my $key = $1;
- my $val = $2;
- if ($key eq "gui_expertmode") {
- if ($val eq "0") {
- $config{"gui_expertmode"} = 0;
- } elsif ($val eq "1") {
- $config{"gui_expertmode"} = 1;
- } else {
- tlwarn("Unknown value $val for gui_expertmode in $fn\n");
- }
- } elsif ($key eq "persistent-downloads") {
- if (($val eq "0") || ($val eq "1")) {
- $config{'persistent-downloads'} = $val;
- } else {
- tlwarn("Unknown value $val for persistent-downloads in $fn\n");
- }
- } else {
- tlwarn("Unknown key $key in $fn\n");
- }
- next;
+ $tlmgr_config_file = TeXLive::TLConfFile->new($fn, "#", "=");
+ for my $key ($tlmgr_config_file->keys) {
+ my $val = $tlmgr_config_file->value($key);
+ if ($key eq "gui_expertmode") {
+ if ($val eq "0") {
+ $config{"gui_expertmode"} = 0;
+ } elsif ($val eq "1") {
+ $config{"gui_expertmode"} = 1;
+ } else {
+ tlwarn("Unknown value >$val< for gui_expertmode in $fn\n");
}
- tlwarn("I cannot understand the following line in $fn:\n$_\n");
- next;
+ } elsif ($key eq "persistent-downloads") {
+ if (($val eq "0") || ($val eq "1")) {
+ $config{'persistent-downloads'} = $val;
+ } else {
+ tlwarn("Unknown value $val for persistent-downloads in $fn\n");
+ }
+ } else {
+ tlwarn("Unknown key $key in $fn\n");
}
- close(TLC);
}
}
sub write_config_file
{
- chomp (my $TEXMFCONFIG = `kpsewhich -var-value=TEXMFCONFIG`);
- my $dn = "$TEXMFCONFIG/tlmgr";
- my $fn = "$dn/config";
- if (! -d $dn) {
- TeXLive::TLUtils::mkdirhier($dn);
- }
- if (!open(TLC, ">$fn")) {
- tlwarn("Cannot open $fn for writing: $!");
- return;
+ if (!defined($tlmgr_config_file)) {
+ chomp (my $TEXMFCONFIG = `kpsewhich -var-value=TEXMFCONFIG`);
+ my $dn = "$TEXMFCONFIG/tlmgr";
+ my $fn = "$dn/config";
+ # create a new one
+ $tlmgr_config_file = TeXLive::TLConfFile->new($fn, "#", "=");
}
- print TLC "# tlmgr/config file\n";
- print TLC "# written by tlmgr\n";
- print TLC "# all comments will be deleted\n";
for my $k (keys %config) {
- print TLC "$k = $config{$k}\n";
+ # it doesn't hurt to save all config settings as we check in TLConfFile
+ # if the value has actually changed
+ $tlmgr_config_file->value($k, $config{$k});
+ }
+ if ($tlmgr_config_file->is_changed) {
+ $tlmgr_config_file->save;
}
- close(TLC);
}
# if the packagelog variable is set then write to PACKAGELOG filehandle
diff --git a/Master/tlpkg/TeXLive/TLConfFile.pm b/Master/tlpkg/TeXLive/TLConfFile.pm
index 01567d602b2..a85913da003 100644
--- a/Master/tlpkg/TeXLive/TLConfFile.pm
+++ b/Master/tlpkg/TeXLive/TLConfFile.pm
@@ -270,6 +270,11 @@ sub parse_config_file {
next;
}
}
+ # ignore continuation after comments, that is the behaviour the
+ # kpathsea library is using, so we follow it here
+ if ($data[$l] =~ m/$cc/) {
+ $data[$l] =~ s/\\$//;
+ }
# continuation line
if ($data[$l] =~ m/^(.*)\\$/) {
$cont_running = 1;
@@ -296,12 +301,15 @@ sub parse_config_file {
}
# mind that the .*? is making the .* NOT greedy, ie matching as few as
# possible. That way we can get rid of the comments at the end of lines
- if ($data[$l] =~ m/^\s*([^\s$sep]+)\s*$sep\s*(.*?)(\s*$cc.*)?$/) {
+ if ($data[$l] =~ m/^\s*([^\s$sep]+)\s*$sep\s*(.*?)(\s*)?($cc.*)?$/) {
$config{$l}{'type'} = 'data';
$config{$l}{'key'} = $1;
$config{$l}{'value'} = $2;
if (defined($3)) {
my $postcomment = $3;
+ if (defined($4)) {
+ $postcomment .= $4;
+ }
# check that there is actually a comment in the second part of the
# line. Otherwise we might add the continuation lines of that
# line to the value
@@ -312,9 +320,15 @@ sub parse_config_file {
next;
}
# if we are still here, that means we cannot evaluate the config file
+ # give a BIG FAT WARNING but save the line as comment and continue
+ # anyway
+ warn("WARNING WARNING WARNING\n");
warn("Cannot parse config file $file ($cc, $sep)\n");
- warn("Line $l = $data[$l]\n");
- return;
+ warn("The following line (l.$l) seems to be wrong:\n");
+ warn(">>> $data[$l]\n");
+ warn("We will treat this line as a comment!\n");
+ $config{$l}{'type'} = 'comment';
+ $config{$l}{'value'} = $data[$l];
}
# save the number of lines in the config hash
$config{'lines'} = $lines;