diff options
author | Sebastian Geerken <devnull@localhost> | 2013-01-28 12:44:00 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2013-01-28 12:44:00 +0100 |
commit | 90090d77dac8387ea576e67c9f9f5ae0a0215fcd (patch) | |
tree | 9a6fb3ab39c6c6cb42ce66c58651a83aed06aa0b /install-hyphenation | |
parent | 5eee444eaefbdcd3fb459c2a65376ef1fa873056 (diff) |
Script for downloading and adjusting pattern files.
Diffstat (limited to 'install-hyphenation')
-rwxr-xr-x | install-hyphenation | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/install-hyphenation b/install-hyphenation new file mode 100755 index 00000000..7ee90602 --- /dev/null +++ b/install-hyphenation @@ -0,0 +1,116 @@ +#!/usr/bin/env perl + +use POSIX; +use File::Basename; + +sub getpattendir () { + # Extract pattern directory from Makefile, in the same directory as + # this script. A complete interpretation of the Makefiles would be + # too complicated, so only ${prefix} is read, which is (hopefully) + # defined as constant. + + my $mf = (dirname $0) . "/Makefile", $prefix = ""; + open MF, $mf or die "Cannot open $mf for reading: $!"; + while (<MF>) { + if (/^\s*prefix\s*=\s*(.*)\s*$/) { + $prefix = $1; + } + } + + close MF; + + if ($prefix eq "") { + die "prefix not defined in $mf"; + } + + return "$prefix/lib/dillo/hyphenation"; +} + + +sub printhelp { + print " Syntax: install-hyphenation <lang1> [<lang2> ...]\n"; + print "\n"; + print " If there are multiple pattern files for a language, and so the file name\n"; + print " is not \"hyph-<lang>.tex\", you can specify the origin by using a colon:\n"; + print " \"<src-lang>:<dest-lang>\", eg. \"de-1996:de\". If both are identical, the\n"; + print " colon can be committed; \"ru\" is equivalent to \"ru:ru\".\n"; + +} + +sub trpatfile { + # Extract the data needed by dillo from the TeX file, based on two + # rules: + # + # 1. Extract the argument of the "\pattern" sequence, i. e. + # anything between "\pattern{" and the next "}". + # 2. As an exception, comments are always preserved. + + my $url = $_[0], $in = $_[1], $out = $_[2]; + + open IN, $in or die die "Cannot open $in for reading: $!"; + open OUT, "> $out" or die "Cannot open $out for writing: $!"; + + printf OUT "%% The original file was downloaded from\n"; + printf OUT "%%\n"; + printf OUT "%% $url\n"; + printf OUT "%%\n"; + printf OUT "%% and automatically translated into this format. The original comments,\n"; + printf OUT "%% including the original copyright notice, are preserved.\n"; + printf OUT "%%\n"; + printf OUT "%% -----------------------------------------------------------------------------\n"; + printf OUT "%%\n"; + + $inpatterns = 0; + while (<IN>) { + if (/^%/) { + # Adopt all comments + print OUT; + } elsif (!$inpatterns) { + if (/\\patterns\s*{/) { + $inpatterns = 1; + } + } else { + if (/}/) { + $inpatterns = 0; + } else { + print OUT; + } + } + } + + close IN; + close OUT; + + printf "Wrote pattern file: $out\n"; +} + +sub dlpatfile { + my $lang = $_[0], $destdir = $_[1], $lang1, $lang2; + if ($lang =~ /(.*):(.*)/) { + $lang1 = $1; + $lang2 = $2; + } else { + $lang1 = $lang2 = $lang; + } + + my $url = "ftp://ftp.mpi-sb.mpg.de/pub/tex/mirror/ftp.dante.de/pub/tex/language/hyph-utf8/tex/generic/hyph-utf8/patterns/tex/hyph-$lang1.tex"; + my $tmp = tmpnam(); + if (system("wget -O $tmp $url") == 0) { + my $out = "$destdir/$lang2.pat"; + trpatfile $url, $tmp, $out; + unlink $tmp; + } else { + print "Error downloading patterns for language $lang1. See messages above for details.\n" + } +} + +$destdir = getpattendir; + +foreach $lang (@ARGV) { + if ($lang eq '-?' || $lang eq '--?' || $lang eq '-h' || + $lang eq '--h' || $lang eq '-help' || $lang eq '--help') { + printhelp; + } else { + dlpatfile $lang, $destdir; + } +} |