dvitomp fix from Akira
[mplib] / src / texk / kpathsea / mktexnam
1 #!/bin/sh
2 # maketexnam -- find PK and TFM names.
3 # te@dbs.uni-hannover.de, kb@mail.tug.org, and infovore@xs4all.nl.
4 # Public domain.
5
6 version='$Id: mktexnam,v 1.30 2004/12/28 20:55:56 olaf Exp $'
7 usage="Usage: $0 NAME [DPI MODE] [DESTDIR].
8   Output the PK, TFM, and MF names for a font NAME."
9 mt_max_args=4
10
11 # Common code for all scripts.
12 : ${MT_TEXMFMAIN=`kpsewhich --expand-path='$TEXMFMAIN'`}
13 : ${MT_MKTEX_OPT=`kpsewhich --format='web2c files' mktex.opt`}
14 test -n "$MT_MKTEX_OPT" || MT_MKTEX_OPT="$MT_TEXMFMAIN/web2c/mktex.opt"
15 if test ! -f "$MT_MKTEX_OPT"; then
16   echo "$0: Cannot find mktex.opt; check your installation." >&2
17   exit 1
18 fi
19
20 . "$MT_MKTEX_OPT"
21
22 NAME=$1
23 case $# in
24   1|2) DPI=$BDPI; DEST=$2;;
25   3|4) DPI=$2; MODE=$3; DEST=$4;;
26     *) help;;
27 esac
28
29 : ${MT_PKDESTDIR='$MT_DESTROOT/$MT_PKDESTREL'}
30 : ${MT_TFMDESTDIR='$MT_DESTROOT/$MT_TFMDESTREL'}
31 : ${MT_MFDESTDIR='$MT_DESTROOT/$MT_MFDESTREL'}
32 : ${MT_PKBASE='$NAME.${DPI}pk'}
33 : ${MT_TFMBASE='$NAME.tfm'}
34 : ${MT_MFBASE='$NAME.mf'}
35 : ${MT_DEFAULT_SUPPLIER=unknown}
36 : ${MT_DEFAULT_TYPEFACE=unknown}
37 : ${MT_DEFAULT_NAMEPART='$MT_SUPPLIER/$MT_TYPEFACE'}
38 : ${MT_DEFAULT_PKDESTREL='pk/modeless/$MT_NAMEPART'}
39 : ${MT_DEFAULT_TFMDESTREL='tfm/$MT_NAMEPART'}
40 : ${MT_DEFAULT_MFDESTREL='source/$MT_NAMEPART'}
41 : ${MT_DEFAULT_DESTROOT=$KPSE_DOT}
42
43 # Find the font: test tfm first, then mf, then possible sauterized mf.
44 fullname=`kpsewhich "$NAME.tfm" 2>/dev/null`
45 test -z "$fullname" && fullname=`kpsewhich "$NAME.mf" 2>/dev/null`
46 if test -z "$fullname"; then
47   rootname=`echo $NAME | sed 's/[0-9]*$//'`
48   fullname=`kpsewhich "b-$rootname.mf" 2>/dev/null`
49   # LH fonts get special treatment:
50   if test -z "$fullname"; then
51     case $rootname in
52       # Czech/Slovak fonts get special treatment:
53       cs*|lcsss*|icscsc*|icstt*|ilcsss*)
54            fullname=`kpsewhich cscode.mf`
55            ;;
56       # LH fonts get special treatment:
57       wn[bcdfirstuv]*|rx[bcdfiorstuvx][bcfhilmostx]|l[abcdhl][bcdfiorstuvx]*)
58            lhprefix=`echo $NAME | sed 's/^\(..\).*/\1/'`
59            fullname=`kpsewhich "${lhprefix}codes.mf" 2>/dev/null`;;
60       *)   fullname=`kpsewhich "$rootname.mf" 2>/dev/null`
61            ;;
62     esac
63   fi
64 fi
65
66 # After all this, do we _have_ a font?
67 if test -z "$fullname"; then
68   : ${MT_DESTROOT="$MT_VARTEXFONTS"}
69 else
70   # Normalize $fullname.
71   fullname=`echo "$fullname" | sed 's%//*%/%g'`
72   # See if $fullname comes from a standard location.
73   OIFS=$IFS;IFS=$SEP
74   set x `kpsewhich --expand-path='$TEXMF/fonts'"$SEP$MT_VARTEXFONTS"`
75   shift; IFS=$OIFS
76   for i
77   do
78     test -z "$i" && continue
79     case "$fullname" in
80       $i/*)
81          # We now have a preliminary value for the destination root.
82          : ${MT_DESTROOT="$i"}
83          # When we're done, relfmt contains one of these:
84          # "/source/$MT_NAMEPART/"
85          # "/$MT_NAMEPART/source/"
86          # while namepart contains the actual namepart.
87          relfmt=`echo "$fullname" | \
88            sed -e 's%^'"$i"'\(/.*/\)[^/]*$%\1%' \
89                -e 's%^/tfm/%/source/%' \
90                -e 's%/tfm/$%/source/%'`
91          namepart=`echo "$relfmt" | sed -e 's%/source/%/%'`
92          # See if namepart is empty.
93          if test "$namepart" != "/"; then
94            relfmt=`echo "$relfmt" | \
95              sed -e 's%'"$namepart"'%/$MT_NAMEPART/%'`
96          else
97            # Assume TDS.
98            relfmt='/source/$MT_NAMEPART/'
99            namepart=''
100          fi
101          # Determine supplier and typeface from namepart.  If there is
102          # only one part in the namepart, we take it to be the typeface.
103          MT_SUPPLIER=`echo $namepart | sed 's%^/\([^/]*\)/\(.*\)$%\1%'`
104          MT_TYPEFACE=`echo $namepart | sed 's%^/\([^/]*\)/\(.*\)$%\2%'`
105          if test -z "$MT_TYPEFACE"; then
106            MT_TYPEFACE="$MT_SUPPLIER";
107            MT_SUPPLIER=''
108          fi
109          # Phew.  Now we create the relative paths for pk, tfm and source.
110          : ${MT_NAMEPART='$MT_SUPPLIER/$MT_TYPEFACE'}
111          : ${MT_PKDESTREL=`echo "$relfmt" | sed 's%/source/%/pk/$MT_MODE/%'`}
112          : ${MT_TFMDESTREL=`echo "$relfmt" | sed 's%/source/%/tfm/%'`}
113          : ${MT_MFDESTREL=`echo "$relfmt"`}
114          break
115     esac
116   done
117 fi
118
119 # In case some variables remain unset.
120 : ${MT_SUPPLIER=$MT_DEFAULT_SUPPLIER}
121 : ${MT_TYPEFACE=$MT_DEFAULT_TYPEFACE}
122 : ${MT_NAMEPART=$MT_DEFAULT_NAMEPART}
123 : ${MT_PKDESTREL=$MT_DEFAULT_PKDESTREL}
124 : ${MT_TFMDESTREL=$MT_DEFAULT_TFMDESTREL}
125 : ${MT_MFDESTREL=$MT_DEFAULT_MFDESTREL}
126
127 # We have found nothing, so force using the fontmaps as a last resort.
128 # This also means mktexnam can be queried for advice on where to
129 # place fonts.
130 if test "x$MT_SUPPLIER" = xunknown \
131   || test "x$MT_TYPEFACE" = xunknown; then
132     MT_FEATURES="$MT_FEATURES:fontmaps"
133 fi
134
135 # Handle the options.
136 test -n "$MT_MKTEXNAM_OPT" && . "$MT_MKTEXNAM_OPT"
137
138 # Adjust MT_DESTROOT, if necessary.
139 if test -n "${MT_DESTROOT}"; then
140   # We distinguish system trees from the rest.
141   systexmf="`kpsewhich --expand-path='{$SYSTEXMF}/fonts'`$SEP$MT_VARTEXFONTS"
142   case "$SEP$systexmf$SEP" in
143     *$SEP$MT_DESTROOT$SEP*) # A system tree.
144       # If the texmfvar option is set, use TEXMFVAR tree.
145       # Some additional uglyness handles the case where $TEXMFVAR exists
146       # but $TEXMFVAR/fonts doesn't (yet).
147       if test "x$USE_TEXMFVAR" = x1; then
148         : ${MT_TEXMFVAR=`kpsewhich --var-value=TEXMFVAR`}
149         MT_DESTROOT=$MT_TEXMFVAR/fonts
150         if test -z "$MT_TEXMFVAR"; then
151           # Path expansion of $TEXMFVAR was empty.
152           FALLBACK=1
153         elif test -d "$MT_DESTROOT"; then
154           # Do we have write access and permission?
155           kpseaccess -w "$MT_DESTROOT" || FALLBACK=1
156           test -w "$MT_DESTROOT" || FALLBACK=1
157         elif test -d "$MT_TEXMFVAR"; then
158           # De we have write access and permission?
159           kpseaccess -w "$MT_TEXMFVAR" || FALLBACK=1
160           test -w "$MT_TEXMFVAR" || FALLBACK=1
161         elif test -e "$MT_TEXMFVAR"; then
162           # TEXMFVAR defined and exists, but it is not a directory?
163           FALLBACK=1
164         else
165           # TEXMFVAR defined but does not exist, try to create it
166           MT_FEATURES=none "$MT_MKTEXDIR" "$MT_TEXMFVAR" || FALLBACK=1
167         fi
168       else
169         # Do we have write access and permission?
170         kpseaccess -w "$MT_DESTROOT" || FALLBACK=1
171         test -w "$MT_DESTROOT" || FALLBACK=1
172       fi
173       # Fall back on VARTEXFONTS if the varfonts option is set, or
174       # we cannot write in the given tree.
175       if test "x$USE_VARTEXFONTS" = x1 || test "x$FALLBACK" = x1; then
176         MT_DESTROOT=$MT_VARTEXFONTS
177       fi ;;
178     *) # A non-system tree.
179       # Do we have write access and permission?
180       kpseaccess -w "$MT_DESTROOT" || FALLBACK=1
181       test -w "$MT_DESTROOT" || FALLBACK=1
182       # If we cannot write fall back of defaults.
183       test "x$FALLBACK" = x1 && MT_DESTROOT=;;
184   esac
185 fi
186
187 if test -z "$MT_DESTROOT"; then
188   MT_DESTROOT=$MT_DEFAULT_DESTROOT
189   MT_PKDESTDIR=$MT_DEFAULT_DESTROOT
190   MT_TFMDESTDIR=$MT_DEFAULT_DESTROOT
191   MT_MFDESTDIR=$MT_DEFAULT_DESTROOT
192 fi
193
194 case "$DEST" in
195   "") ;;
196   /* | [A-z]:/*) # Absolute, explicit destdir => use it.
197       MT_PKDESTDIR=$DEST
198       MT_TFMDESTDIR=$DEST
199       MT_MFDESTDIR=$DEST
200       MT_NAMEPART=;;
201    *) # Relative destdir => append to the default.
202       MT_NAMEPART=$DEST;;
203 esac
204
205 eval MT_MODE=\"$MODE\"
206 eval MT_NAMEPART=\"$MT_NAMEPART\"
207 eval MT_DESTROOT=\"$MT_DESTROOT\"
208 eval MT_PKDESTREL=\"$MT_PKDESTREL\"
209 eval MT_TFMDESTREL=\"$MT_TFMDESTREL\"
210 eval MT_MFDESTREL=\"$MT_MFDESTREL\"
211 eval MT_PKDESTDIR=\"$MT_PKDESTDIR\"
212 eval MT_TFMDESTDIR=\"$MT_TFMDESTDIR\"
213 eval MT_MFDESTDIR=\"$MT_MFDESTDIR\"
214 eval MT_PKNAME=\"$MT_PKDESTDIR/$MT_PKBASE\"
215 eval MT_TFMNAME=\"$MT_TFMDESTDIR/$MT_TFMBASE\"
216 eval MT_MFNAME=\"$MT_MFDESTDIR/$MT_MFBASE\"
217
218 echo "$MT_PKNAME$SEP$MT_TFMNAME$SEP$MT_MFNAME" | sed 's%//*%/%g'
219