#!/usr/bin/env perl use POSIX; use File::Basename; use Net::FTP; $commondir = "language/hyph-utf8/tex/generic/hyph-utf8/patterns/txt"; # You may want do adjust these values. $host = "mirrors.dotsrc.org"; $dir = "/ctan/$commondir"; #$host = "ctan.org"; #$dir = "/tex-archive/$commondir"; #$host = "ftp.dante.de"; #$dir = "/pub/tex/$commondir"; $help = 0; if (@ARGV == 0) { $help = 1; } else { foreach $arg (@ARGV) { if ($arg eq '-?' || $arg eq '--?' || $arg eq '-h' || $arg eq '--h' || $arg eq '-help' || $arg eq '--help') { $arg = 1; } } } if ($help) { print "Usage: $0 [ ...]\n\n"; print <.pat.txt"), you must specify the respective part of the filename, e. g. "en-gb" or "en-us". In this case, the extra part ("-gb" or "-us") is automatically removed. If you are not sure, simply specify the language code ("en" in this example); you will then given a list of existing pattern files. EOT } else { # 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. $prefix = ""; $makefile = (dirname $0) . "/Makefile"; open MF, $makefile or die "Cannot open $makefile: $!"; while () { if (/^\s*prefix\s*=\s*(.*)\s*$/) { $prefix = $1; } } close MF; if ($prefix eq "") { die "Prefix not defined in $makefile."; } $patterdir = "$prefix/lib/dillo/hyphenation"; if (!-e $patterdir) { mkdir $patterdir or die "Cannot create directory $patterdir: $!"; print "Created $patterdir.\n"; } # Connect to CTAN FTP server, change to the directory where the # patterns lie, and read files list (which may be useful later). $ftp = Net::FTP->new($host,Timeout=>240) or die "Cannot connect to $host: $!"; $ftp->login() or die "Cannot login: $!"; $ftp->cwd($dir) or die "Cannot change to directory $dir: $!"; @files = $ftp->ls or die "Cannot read directory: $!"; # Finally, read pattern files. foreach $arg (@ARGV) { if ($arg =~ /^([a-z]+)-.*$/) { # More files per language, e. g. "en-gb". $lang = $1; } else { # One file per language, e. g. "ru". $lang = $arg; } # First, donwload the pattern file to a temporary file. $tmppat = tmpnam(); if ($ftp->get ("hyph-$arg.pat.txt", $tmppat)) { printf ("Successfully downloaded pattern file for \"$arg\".\n"); # Search for a licence file. (Only a warning, when it does # not exist.) $tmplic = tmpnam(); $licfound = 0; if ($ftp->get ("hyph-$arg.lic.txt", $tmplic)) { $licfound = 1; } else { print "Warning: Cannot download license file for \"$arg\": $!\n"; } # Combine both, licence and pattern, to the final pattern # file. $outfile = "$patterdir/$lang.pat"; open OUT, "> $outfile" or die "Cannot open $outfile: $!"; if ($licfound) { print OUT "% Licence from ftp://$host$dir/hyph-$arg.lic.txt\n"; print OUT "%\n"; open IN, $tmplic or die "Cannot open $tmplic: $!"; while () { # Each line from the licence file must be a comment. if (!/^%/) { print OUT "% "; } print OUT; } close IN; unlink $tmplic; print OUT "%\n"; } print OUT "% Patterns from ftp://$host$dir/hyph-$arg.pat.txt\n"; print OUT "%\n"; open IN, $tmppat or die "Cannot open $tmppat: $!"; while () { print OUT; } close IN; unlink $tmppat; close OUT; } else { # Not found. If a single language was specified (e. g. "en"), # search for possibilities. print "Error: Cannot download pattern file for \"$arg\": $!\n"; if ($lang eq $arg) { print "Try one of these:\n"; foreach(@files) { if (/^hyph-($lang-.*)\.pat\.txt$/) { print " $1\n"; } } } } } $ftp->quit; }