diff options
author | Norbert Preining <preining@logic.at> | 2009-06-02 12:47:36 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2009-06-02 12:47:36 +0000 |
commit | bdf77ac6b06ea9f7588ab8935385a1ea1cfdc543 (patch) | |
tree | e7853793294e0dc8317e549e954f7a4286bedac5 /Master/tlpkg/TeXLive | |
parent | 953d46c5ce6c881f05f8a33d5ba3b9b5366a2389 (diff) |
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
Diffstat (limited to 'Master/tlpkg/TeXLive')
-rw-r--r-- | Master/tlpkg/TeXLive/TLPOBJ.pm | 89 | ||||
-rw-r--r-- | Master/tlpkg/TeXLive/TLUtils.pm | 96 |
2 files changed, 111 insertions, 74 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 |