#!/bin/sh
#
# Chose a set of hyphenation-pattern to include in
# an initex-run for all default formats (i.e. tex and latex)
#
# Made for the debian-distribution of TeX by Nils Rennebarth
# May be freely copied
#
DIALOG=dialog

if [ "`whoami`" != root ]; then
   echo "You need to be root to change TeX's system files"
   exit 1
fi

trap "rm -f /tmp/checklist.tmp.$$ /tmp/language.dat.$$" 0 1 2 15

COMMAND="\
$DIALOG --separate-output \
	--backtitle \"Debian-TeX installation\" \
	--title     \"Hyphenation\" \
	--checklist \"Select one or more languages to include\" \
	20 76 13 " 

COMMAND=$COMMAND`(cd /usr/lib/texmf/tex/generic/hyphen; ls -l --full-time hyphen.*) |	\
   awk 'BEGIN {
          while ((getline < "/usr/lib/texmf/tex/generic/hyphen/language.dat") >0) {
            if (substr($0,1,1) != "%") {
               old[$1]=1 
            }
          }
        }
        {
          print  substr($11,8)
          printf "\"%5i",$5
          printf " bytes, from %s %2i %s\" ",$7,$8,$10 
          if (substr($11,8) in old) print  "on"; else print "off"
        }'`

COMMAND="$COMMAND 2> /tmp/checklist.tmp.$$"

if ! eval $COMMAND; then
   exit
fi

cat <<EOF >/tmp/language.dat.$$
% This is language.dat, automatically generated by the
% texconfhyphen script of debian-TeX
%
% It specifies all languages preloaded by TeX's format files.
% Every non-comment line is a pair of LANGUAGE FILENAME pairs,
% separated by blanks.
EOF

awk '{ printf "%s hyphen.%s\n",$1,$1 }' /tmp/checklist.tmp.$$ >> /tmp/language.dat.$$

mv /tmp/language.dat.$$ /usr/lib/texmf/tex/generic/hyphen/language.dat

