From bdf77ac6b06ea9f7588ab8935385a1ea1cfdc543 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 2 Jun 2009 12:47:36 +0000 Subject: factor out the parsing of AddFormat and AddHyphen lines to separate function in TLUtils, use this function in TLPOBJ, and reuse this function in check-execute_consistency to check the format execute consistency git-svn-id: svn://tug.org/texlive/trunk@13577 c570f23f-e606-0410-a88d-b1316a301751 --- Master/tlpkg/TeXLive/TLPOBJ.pm | 89 +++++---------------------- Master/tlpkg/TeXLive/TLUtils.pm | 96 ++++++++++++++++++++++++++++++ Master/tlpkg/bin/check-execute-consistency | 79 ++++++++++++++++++++---- 3 files changed, 177 insertions(+), 87 deletions(-) diff --git a/Master/tlpkg/TeXLive/TLPOBJ.pm b/Master/tlpkg/TeXLive/TLPOBJ.pm index b192442f415..9e1bd093fa7 100644 --- a/Master/tlpkg/TeXLive/TLPOBJ.pm +++ b/Master/tlpkg/TeXLive/TLPOBJ.pm @@ -918,6 +918,7 @@ sub make_return_hash_from_executes { + # # execute stuff # @@ -928,51 +929,16 @@ sub fmtutil_cnf_lines { my $pkg = $obj->name; foreach my $e ($obj->executes) { if ($e =~ m/AddFormat\s+(.*)\s*/) { - my $name; - my $engine; - my $patterns = "-"; - my $options = ""; - my $mode = ""; + 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; } - for my $p (&TeXLive::TLUtils::quotewords('\s+', 0, "$1")) { - my ($a, $b); - if ($p =~ m/^(name|engine|mode|patterns|options)=(.*)$/) { - $a = $1; - $b = $2; - } else { - die "Unknown format directive $p in $pkg (line=$e)"; - } - if ($a eq "name") { - die "AddFormat line needs name=something: $pkg, $e" unless $b; - $name = $b; next; - } - if ($a eq "engine") { - die "AddFormat line needs engine=something: $pkg, $e" unless $b; - $engine = $b; next; - } - if ($a eq "patterns") { - $patterns = ( $b ? $b : "-"); - next; - } - if ($a eq "mode") { - if ($b eq "disabled") { - $mode = "#! "; - } else { - $mode = ""; - } - next; - } - if ($a eq "options") { - $options = ( $b ? $b : ""); - next; - } - # should not be reached at all - die "Unknown language directive in $pkg: $e"; - } - push @fmtlines, "$mode$name $engine $patterns $options\n"; + my $mode = ($r{"mode"} ? "" : "#! "); + push @fmtlines, "$mode$r{'name'} $r{'engine'} $r{'patterns'} $r{'options'}\n"; } } return @fmtlines; @@ -1045,43 +1011,18 @@ sub _parse_hyphen_execute { my $first = 1; foreach my $e ($obj->executes) { if ($e =~ m/AddHyphen\s+(.*)\s*/) { - my $name; - my $lefthyphenmin; - my $righthyphenmin; - my $file; - my @synonyms; + my %r = TeXLive::TLUtils::parse_AddHyphen_line("$1"); + if (defined($r{"error"})) { + die "$r{'error'}, package $pkg, execute $e"; + } if ($first) { push @langlines, "% from $pkg:\n"; $first = 0; } - foreach my $p (split(' ', $1)) { - my ($a, $b) = split /=/, $p; - if ($a eq "name") { - die "$0: AddHyphen line needs name=something: $pkg, $e" unless $b; - $name = $b; next; - } - if ($a eq "lefthyphenmin") { - # lefthyphenmin default to 3 - $lefthyphenmin = ( $b ? $b : 2 ); - next; - } - if ($a eq "righthyphenmin") { - $righthyphenmin = ( $b ? $b : 3); - next; - } - if ($a eq "file") { - die "$0: AddHyphen line needs file=something: $pkg, $e" unless $b; - $file = $b; - next; - } - if ($a eq "synonyms") { - @synonyms = split /,/, $b; - next; - } - die "$0: Unknown language directive in $pkg: $e"; - } - my @foo = &$coderef ($name, $lefthyphenmin, $righthyphenmin, - $file, @synonyms); + my @syns; + @syns = @{$r{"synonyms"}} if (defined($r{"synonyms"})); + my @foo = &$coderef ($r{"name"}, $r{"lefthyphenmin"}, + $r{"righthyphenmin"}, $r{"file"}, @syns); push @langlines, @foo; } } diff --git a/Master/tlpkg/TeXLive/TLUtils.pm b/Master/tlpkg/TeXLive/TLUtils.pm index 08f6ceab3f9..ff97d02f6a9 100644 --- a/Master/tlpkg/TeXLive/TLUtils.pm +++ b/Master/tlpkg/TeXLive/TLUtils.pm @@ -102,6 +102,8 @@ BEGIN { &create_updmap &create_language_dat &create_language_def + &parse_AddFormat_line + &parse_AddHyphen_line &sort_uniq &push_uniq &texdir_check @@ -1955,6 +1957,100 @@ sub _create_config_files { } } +sub parse_AddHyphen_line { + my $line = shift; + my %ret; + my $default_lefthyphenmin = 2; + my $default_righthyphenmin = 3; + $ret{"lefthyphenmin"} = $default_lefthyphenmin; + $ret{"righthyphenmin"} = $default_righthyphenmin; + for my $p (split(' ', $line)) { + 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 "synonyms") { + @{$ret{"synonyms"}} = split /,/, $b; + next; + } + # should not be reached at all + $ret{"error"} = "Unknown language directive $e"; + return %ret; + } + return %ret; +} + + +sub parse_AddFormat_line { + my $line = shift; + my %ret; + $ret{"options"} = ""; + $ret{"patterns"} = "-"; + $ret{"mode"} = 1; + for my $p (quotewords('\s+', 0, "$line")) { + my ($a, $b); + if ($p =~ m/^(name|engine|mode|patterns|options)=(.*)$/) { + $a = $1; + $b = $2; + } else { + $ret{"error"} = "Unknown format directive $p"; + return %ret; + } + if ($a eq "name") { + if (!$b) { + $ret{"error"} = "AddFormat line needs name=something"; + return %ret; + } + $ret{"name"} = $b; + next; + } + if ($a eq "engine") { + if (!$b) { + $ret{"error"} = "AddFormat line needs engine=something"; + return %ret; + } + $ret{"engine"} = $b; + next; + } + if ($a eq "patterns") { + $ret{"patterns"} = ( $b ? $b : "-" ); + next; + } + if ($a eq "mode") { + $ret{"mode"} = ( $b eq "disabled" ? 0 : 1 ); + next; + } + if ($a eq "options") { + $ret{"options"} = ( $b ? $b : "" ); + next; + } + # should not be reached at all + $ret{"error"} = "Unknown format directive $p"; + return %ret; + } + return %ret; +} =back diff --git a/Master/tlpkg/bin/check-execute-consistency b/Master/tlpkg/bin/check-execute-consistency index 5d9eb3aa4be..9b45d2df2cb 100755 --- a/Master/tlpkg/bin/check-execute-consistency +++ b/Master/tlpkg/bin/check-execute-consistency @@ -39,7 +39,7 @@ sub main chomp (my $Master = `cd $mydir/../.. && pwd`); # xx TLPDB should default my $tlpdb = TeXLive::TLPDB->new ("root" => "$Master"); die("Cannot find tlpdb in $Master!\n") unless defined($tlpdb); - my (%maps,%langcodes,%fmtcodes); + my (%maps,%langcodes,%fmtlines); for my $pkg ($tlpdb->list_packages) { for my $e ($tlpdb->get_package($pkg)->executes) { if ($e =~ m/add(Mixed)?Map\s+(.*)$/) { @@ -49,7 +49,7 @@ sub main } elsif ($e =~ m/AddFormat\s+(.*)$/) { my $foo = $1; chomp($foo); - push @{$fmtcodes{$foo}}, $pkg; + push @{$fmtlines{$foo}}, $pkg; } elsif ($e =~ m/AddHyphen\s+.*\s+file=(\S+)\s*$/) { my $foo = $1; chomp($foo); @@ -122,17 +122,70 @@ sub main # - rework the format definition that we have inifile=pdflatex.ini # isn't the * unnecessary? tlwarn("checking of AddFormat lines disabled!\n"); - my %badfmtcodes; - #foreach my $lc (keys %fmtcodes) { - # my @found = $tlpdb->find_file("texmf/fmtutil/format.$lc.cnf"); - # if ($#found < 0) { - # $badfmtcodes{$lc} = $fmtcodes{$lc}; - # } - #} - if (keys %badfmtcodes) { - print "mentioned fmt codes without fmtutil.XXX.cnf:\n"; - foreach my $mf (keys %badfmtcodes) { - print "\t$mf (execute in @{$badfmtcodes{$mf}})\n"; + my %missingbins; + my %missingengines; + my %missinginis; + for (keys %fmtlines) { + my %r = TeXLive::TLUtils::parse_AddFormat_line("$_"); + if (defined($r{"error"})) { + die "$r{'error'}, parsing $_, package(s) @{$fmtlines{$_}}"; + } + my $opt = $r{"options"}; + my $engine = $r{"engine"}; + my $name = $r{"name"}; + my $mode = $r{"mode"}; + # we check that the name exist in bin/$arch + for my $a ($tlpdb->available_architectures) { + if (! -r "$Master/bin/$a/$name") { + if (($a eq "win32") || ($a eq "i386-cygwin")) { + if (! -r "$Master/bin/$a/$name.exe") { + push @{$missingbins{$_}}, "bin/$a/$name" if $mode; + } + } else { + push @{$missingbins{$_}}, "bin/$a/$name" if $mode; + } + } + if (! -r "$Master/bin/$a/$engine") { + if (($a eq "win32") || ($a eq "i386-cygwin")) { + if (! -r "$Master/bin/$a/$engine.exe") { + push @{$missingengines{$_}}, "bin/$a/$engine" if $mode; + } + } else { + push @{$missingengines{$_}}, "bin/$a/$engine" if $mode; + } + } + } + # check for the existence of the .ini file + # by using the last word in the options value + my $inifile = $opt; + # $inifile now contains "bla bla bla *file.ini" + # strip initial and trailing " + $inifile =~ s/^"(.*)"$/$1/; + # remove everything before the last space + $inifile =~ s/^.* ([^ ]*)$/$1/; + # remove the optional leading * + $inifile =~ s/^\*//; + my @found = $tlpdb->find_file("$inifile"); + if ($#found < 0) { + $missinginis{$_} = "$inifile"; + } + } + if (keys %missinginis) { + print "mentioned ini files that cannot be found:\n"; + for my $i (keys %missinginis) { + print "\t $missinginis{$i} (execute: $i)\n"; + } + } + if (keys %missingengines) { + print "mentioned engine files that cannot be found:\n"; + for my $i (keys %missingengines) { + print "\t @{$missingengines{$i}}\n"; + } + } + if (keys %missingbins) { + print "mentioned bin files that cannot be found:\n"; + for my $i (keys %missingbins) { + print "\t @{$missingbins{$i}}\n"; } } } -- cgit v1.2.3