From 786be3b985a2f97c9d970f8e9acdbf1981584ae1 Mon Sep 17 00:00:00 2001 From: Sebastian Geerken Date: Fri, 8 Mar 2013 14:36:09 +0100 Subject: Renamed install-hyphen to dillo-install-hyphen and made it installable. --- dillo-install-hyphenation | 163 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100755 dillo-install-hyphenation (limited to 'dillo-install-hyphenation') diff --git a/dillo-install-hyphenation b/dillo-install-hyphenation new file mode 100755 index 00000000..2a37f86a --- /dev/null +++ b/dillo-install-hyphenation @@ -0,0 +1,163 @@ +#!/usr/bin/env perl +use POSIX; +use File::Basename; +use Net::FTP; +use Getopt::Long; + +$host = "mirrors.dotsrc.org"; +$basesourcedir = "/ctan"; +$sourcedir = ""; + +# Determine ${prefix}, for the default target directory for pattern +# files. Two different strategies ... +$makefile = (dirname $0) . "/Makefile"; +if (-e $makefile) { + # 1. Makefile exists in the same directory, so it can be assumed + # that this script is not yet installed, but called from the source + # directory. Search Makefile for prexix. + 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."; + } +} else { + # 2. Assume that this is script is installed, so its path contains + # the prefix. + if ($0 =~ /(.*)\/bin\/[^\/]+$/) { + $prefix = $1; + } else { + die "Failed to determine prefix from $0."; + } +} + +$targetdir = "$prefix/lib/dillo/hyphenation"; + +if (!GetOptions ("host=s" => \$host, + "basesourcedir=s" => \$basesourcedir, + "sourcedir=s" => \$sourcedir, + "targetdir=s" => \$targetdir) + || @ARGV == 0) { + print "Usage: $0 [OPTIONS] LANG [LANG ...]\n\n"; + print <new($host,Timeout=>240) + or die "Cannot connect to $host: $!"; + $ftp->login() or die "Cannot login: $!"; + $ftp->cwd($sourcedir) or die "Cannot change to directory $sourcedir: $!"; + @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 = "$targetdir/$lang.pat"; + open OUT, "> $outfile" or die "Cannot open $outfile: $!"; + + if ($licfound) { + print OUT + "% Licence from ftp://$host$sourcedir/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$sourcedir/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; +} -- cgit v1.2.3