texlive[61249] Master/tlpkg/TeXLive/TLConfFile.pm: TLConfFile: make
commits+preining at tug.org
commits+preining at tug.org
Wed Dec 8 07:07:21 CET 2021
Revision: 61249
http://tug.org/svn/texlive?view=revision&revision=61249
Author: preining
Date: 2021-12-08 07:07:21 +0100 (Wed, 08 Dec 2021)
Log Message:
-----------
TLConfFile: make strict ready - fix many stupid bugs
Modified Paths:
--------------
trunk/Master/tlpkg/TeXLive/TLConfFile.pm
Modified: trunk/Master/tlpkg/TeXLive/TLConfFile.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLConfFile.pm 2021-12-08 00:48:25 UTC (rev 61248)
+++ trunk/Master/tlpkg/TeXLive/TLConfFile.pm 2021-12-08 06:07:21 UTC (rev 61249)
@@ -4,6 +4,9 @@
# This file is licensed under the GNU General Public License version 2
# or any later version.
+use strict;
+use warnings;
+
package TeXLive::TLConfFile;
use TeXLive::TLUtils;
@@ -23,13 +26,13 @@
{
my $class = shift;
my ($fn, $cc, $sep, $typ) = @_;
- my $self = {} ;
- $self{'file'} = $fn;
- $self{'cc'} = $cc;
- $self{'sep'} = $sep;
+ my $self = () ;
+ $self->{'file'} = $fn;
+ $self->{'cc'} = $cc;
+ $self->{'sep'} = $sep;
if (defined($typ)) {
if ($typ eq 'last-win' || $typ eq 'first-win' || $typ eq 'multiple') {
- $self{'type'} = $typ;
+ $self->{'type'} = $typ;
} else {
printf STDERR "Unknown type of conffile: $typ\n";
printf STDERR "Should be one of: last-win first-win multiple\n";
@@ -37,7 +40,7 @@
}
} else {
# default type for backward compatibility is last-win
- $self{'type'} = 'last-win';
+ $self->{'type'} = 'last-win';
}
bless $self, $class;
return $self->reparse;
@@ -49,20 +52,20 @@
my %config = parse_config_file($self->file, $self->cc, $self->sep);
my $lastkey = undef;
my $lastkeyline = undef;
- $self{'keyvalue'} = ();
- $self{'confdata'} = \%config;
- $self{'changed'} = 0;
+ $self->{'keyvalue'} = ();
+ $self->{'confdata'} = \%config;
+ $self->{'changed'} = 0;
my $in_postcomment = 0;
for my $i (0..$config{'lines'}) {
if ($config{$i}{'type'} eq 'comment') {
$lastkey = undef;
$lastkeyline = undef;
- $is_postcomment = 0;
+ $in_postcomment = 0;
} elsif ($config{$i}{'type'} eq 'data') {
$lastkey = $config{$i}{'key'};
$lastkeyline = $i;
- $self{'keyvalue'}{$lastkey}{$i}{'value'} = $config{$i}{'value'};
- $self{'keyvalue'}{$lastkey}{$i}{'status'} = 'unchanged';
+ $self->{'keyvalue'}{$lastkey}{$i}{'value'} = $config{$i}{'value'};
+ $self->{'keyvalue'}{$lastkey}{$i}{'status'} = 'unchanged';
if (defined($config{$i}{'postcomment'})) {
$in_postcomment = 1;
} else {
@@ -71,11 +74,11 @@
} elsif ($config{$i}{'type'} eq 'empty') {
$lastkey = undef;
$lastkeyline = undef;
- $is_postcomment = 0;
+ $in_postcomment = 0;
} elsif ($config{$i}{'type'} eq 'continuation') {
if (defined($lastkey)) {
if (!$in_postcomment) {
- $self{'keyvalue'}{$lastkey}{$lastkeyline}{'value'} .=
+ $self->{'keyvalue'}{$lastkey}{$lastkeyline}{'value'} .=
$config{$i}{'value'};
}
}
@@ -90,45 +93,45 @@
sub file
{
my $self = shift;
- return($self{'file'});
+ return($self->{'file'});
}
sub cc
{
my $self = shift;
- return($self{'cc'});
+ return($self->{'cc'});
}
sub sep
{
my $self = shift;
- return($self{'sep'});
+ return($self->{'sep'});
}
sub type
{
my $self = shift;
- return($self{'type'});
+ return($self->{'type'});
}
sub key_present
{
my ($self, $key) = @_;
- return defined($self{'keyvalue'}{$key});
+ return defined($self->{'keyvalue'}{$key});
}
sub keys
{
my $self = shift;
- return keys(%{$self{'keyvalue'}});
+ return keys(%{$self->{'keyvalue'}});
}
sub keyvaluehash
{
my $self = shift;
- return \%{$self{'keyvalue'}};
+ return \%{$self->{'keyvalue'}};
}
sub confdatahash
{
my $self = shift;
- return $self{'confdata'};
+ return $self->{'confdata'};
}
sub by_lnr
@@ -147,8 +150,8 @@
my ($self, $key, $value, @restvals) = @_;
my $t = $self->type;
if (defined($value)) {
- if (defined($self{'keyvalue'}{$key})) {
- my @key_lines = sort by_lnr CORE::keys %{$self{'keyvalue'}{$key}};
+ if (defined($self->{'keyvalue'}{$key})) {
+ my @key_lines = sort by_lnr CORE::keys %{$self->{'keyvalue'}{$key}};
if ($t eq 'multiple') {
my @newval = ( $value, @restvals );
my $newlen = $#newval;
@@ -156,7 +159,7 @@
# we assign to the first n elements, delete superficial
# or add new ones if necessary
# $value should be a reference to an array of values
- my $listp = $self{'keyvalue'}{$key};
+ my $listp = $self->{'keyvalue'}{$key};
my $oldlen = $#key_lines;
my $minlen = ($newlen < $oldlen ? $newlen : $oldlen);
for my $i (0..$minlen) {
@@ -165,7 +168,7 @@
if ($listp->{$key_lines[$i]}{'status'} ne 'new') {
$listp->{$key_lines[$i]}{'status'} = 'changed';
}
- $self{'changed'} = 1;
+ $self->{'changed'} = 1;
}
}
if ($minlen < $oldlen) {
@@ -174,7 +177,7 @@
for my $i (($minlen+1)..$oldlen) {
$listp->{$key_lines[$i]}{'status'} = 'deleted';
}
- $self{'changed'} = 1;
+ $self->{'changed'} = 1;
}
if ($minlen < $newlen) {
# we have new values
@@ -188,20 +191,20 @@
$listp->{$ll}{'value'} = $newval[$i];
$ll--;
}
- $self{'changed'} = 1;
+ $self->{'changed'} = 1;
}
} else {
# select element based on first-win or last-win type
my $ll = $key_lines[($t eq 'first-win' ? 0 : $#key_lines)];
#print "lastwin = $ll\n";
- if ($self{'keyvalue'}{$key}{$ll}{'value'} ne $value) {
- $self{'keyvalue'}{$key}{$ll}{'value'} = $value;
+ if ($self->{'keyvalue'}{$key}{$ll}{'value'} ne $value) {
+ $self->{'keyvalue'}{$key}{$ll}{'value'} = $value;
# as long as the key/value pair is not new,
# we set its status to changed
- if ($self{'keyvalue'}{$key}{$ll}{'status'} ne 'new') {
- $self{'keyvalue'}{$key}{$ll}{'status'} = 'changed';
+ if ($self->{'keyvalue'}{$key}{$ll}{'status'} ne 'new') {
+ $self->{'keyvalue'}{$key}{$ll}{'status'} = 'changed';
}
- $self{'changed'} = 1;
+ $self->{'changed'} = 1;
}
}
} else { # all new key
@@ -208,21 +211,21 @@
my @newval = ( $value, @restvals );
my $newlen = $#newval;
for my $i (0..$newlen) {
- $self{'keyvalue'}{$key}{-($i+1)}{'value'} = $value;
- $self{'keyvalue'}{$key}{-($i+1)}{'status'} = 'new';
+ $self->{'keyvalue'}{$key}{-($i+1)}{'value'} = $value;
+ $self->{'keyvalue'}{$key}{-($i+1)}{'status'} = 'new';
}
- $self{'changed'} = 1;
+ $self->{'changed'} = 1;
}
}
# $self->dump_myself();
- if (defined($self{'keyvalue'}{$key})) {
- my @key_lines = sort by_lnr CORE::keys %{$self{'keyvalue'}{$key}};
+ if (defined($self->{'keyvalue'}{$key})) {
+ my @key_lines = sort by_lnr CORE::keys %{$self->{'keyvalue'}{$key}};
if ($t eq 'first-win') {
- return $self{'keyvalue'}{$key}{$key_lines[0]}{'value'};
+ return $self->{'keyvalue'}{$key}{$key_lines[0]}{'value'};
} elsif ($t eq 'last-win') {
- return $self{'keyvalue'}{$key}{$key_lines[$#key_lines]}{'value'};
+ return $self->{'keyvalue'}{$key}{$key_lines[$#key_lines]}{'value'};
} elsif ($t eq 'multiple') {
- return map { $self{'keyvalue'}{$key}{$_}{'value'} } @key_lines;
+ return map { $self->{'keyvalue'}{$key}{$_}{'value'} } @key_lines;
} else {
die "That should not happen: wrong type: $!";
}
@@ -233,12 +236,12 @@
sub delete_key
{
my ($self, $key) = @_;
- %config = %{$self{'confdata'}};
- if (defined($self{'keyvalue'}{$key})) {
- for my $l (CORE::keys %{$self{'keyvalue'}{$key}}) {
- $self{'keyvalue'}{$key}{$l}{'status'} = 'deleted';
+ my %config = %{$self->{'confdata'}};
+ if (defined($self->{'keyvalue'}{$key})) {
+ for my $l (CORE::keys %{$self->{'keyvalue'}{$key}}) {
+ $self->{'keyvalue'}{$key}{$l}{'status'} = 'deleted';
}
- $self{'changed'} = 1;
+ $self->{'changed'} = 1;
}
}
@@ -245,19 +248,19 @@
sub rename_key
{
my ($self, $oldkey, $newkey) = @_;
- %config = %{$self{'confdata'}};
+ my %config = %{$self->{'confdata'}};
for my $i (0..$config{'lines'}) {
if (($config{$i}{'type'} eq 'data') &&
($config{$i}{'key'} eq $oldkey)) {
$config{$i}{'key'} = $newkey;
- $self{'changed'} = 1;
+ $self->{'changed'} = 1;
}
}
- if (defined($self{'keyvalue'}{$oldkey})) {
- $self{'keyvalue'}{$newkey} = $self{'keyvalue'}{$oldkey};
- delete $self{'keyvalue'}{$oldkey};
- $self{'keyvalue'}{$newkey}{'status'} = 'changed';
- $self{'changed'} = 1;
+ if (defined($self->{'keyvalue'}{$oldkey})) {
+ $self->{'keyvalue'}{$newkey} = $self->{'keyvalue'}{$oldkey};
+ delete $self->{'keyvalue'}{$oldkey};
+ $self->{'keyvalue'}{$newkey}{'status'} = 'changed';
+ $self->{'changed'} = 1;
}
}
@@ -264,7 +267,7 @@
sub is_changed
{
my $self = shift;
- return $self{'changed'};
+ return $self->{'changed'};
}
sub save
@@ -275,7 +278,7 @@
# unless $outarg is defined or we are changed, return immediately
return if (! ( defined($outarg) || $self->is_changed));
#
- %config = %{$self{'confdata'}};
+ my %config = %{$self->{'confdata'}};
#
# determine where to write to
my $out = $outarg;
@@ -324,9 +327,9 @@
} elsif ($config{$i}{'type'} eq 'data') {
$current_key_value_is_changed = 0;
# we have to check whether the original data has been changed!!
- if ($self{'keyvalue'}{$config{$i}{'key'}}{$i}{'status'} eq 'changed') {
+ if ($self->{'keyvalue'}{$config{$i}{'key'}}{$i}{'status'} eq 'changed') {
$current_key_value_is_changed = 1;
- print $fhout "$config{$i}{'key'} $config{'sep'} $self{'keyvalue'}{$config{$i}{'key'}}{$i}{'value'}";
+ print $fhout "$config{$i}{'key'} $config{'sep'} $self->{'keyvalue'}{$config{$i}{'key'}}{$i}{'value'}";
if (defined($config{$i}{'postcomment'})) {
print $fhout $config{$i}{'postcomment'};
}
@@ -333,7 +336,7 @@
# if a value is changed, we do not print out multiline stuff
# as keys are not split
print $fhout "\n";
- } elsif ($self{'keyvalue'}{$config{$i}{'key'}}{$i}{'status'} eq 'deleted') {
+ } elsif ($self->{'keyvalue'}{$config{$i}{'key'}}{$i}{'status'} eq 'deleted') {
$current_key_value_is_changed = 1;
} else {
$current_key_value_is_changed = 0;
@@ -351,10 +354,10 @@
}
#
# save new keys
- for my $k (CORE::keys %{$self{'keyvalue'}}) {
- for my $l (CORE::keys %{$self{'keyvalue'}{$k}}) {
- if ($self{'keyvalue'}{$k}{$l}{'status'} eq 'new') {
- print $fhout "$k $config{'sep'} $self{'keyvalue'}{$k}{$l}{'value'}\n";
+ for my $k (CORE::keys %{$self->{'keyvalue'}}) {
+ for my $l (CORE::keys %{$self->{'keyvalue'}{$k}}) {
+ if ($self->{'keyvalue'}{$k}{$l}{'status'} eq 'new') {
+ print $fhout "$k $config{'sep'} $self->{'keyvalue'}{$k}{$l}{'value'}\n";
}
}
}
@@ -491,12 +494,12 @@
sub dump_myself {
my $self = shift;
print "======== DUMPING SELF =============\n";
- dump_config_data($self{'confdata'});
+ dump_config_data($self->{'confdata'});
print "DUMPING KEY VALUES\n";
- for my $k (CORE::keys %{$self{'keyvalue'}}) {
+ for my $k (CORE::keys %{$self->{'keyvalue'}}) {
print "key = $k\n";
- for my $l (sort CORE::keys %{$self{'keyvalue'}{$k}}) {
- print " line =$l= value =", $self{'keyvalue'}{$k}{$l}{'value'}, "= status =", $self{'keyvalue'}{$k}{$l}{'status'}, "=\n";
+ for my $l (sort CORE::keys %{$self->{'keyvalue'}{$k}}) {
+ print " line =$l= value =", $self->{'keyvalue'}{$k}{$l}{'value'}, "= status =", $self->{'keyvalue'}{$k}{$l}{'status'}, "=\n";
}
}
print "=========== END DUMP ==============\n";
More information about the tex-live-commits
mailing list.