summaryrefslogtreecommitdiff
path: root/Master/bin/mipsel-linux/mktextfm
blob: bc65668e92e78d5e7aed59a7f4c8a1e2565205fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
# original mktextfm -- make a new TFM file, because one wasn't found.
# 
# (If you change or delete the word `original' on the previous line,
# installation won't write this script over yours.)
# 
# Primarily written by Thomas Esser, Karl Berry, and Olaf Weber.
# Public domain.

version='$Id: mktextfm 16497 2009-12-24 18:38:47Z karl $'
progname=`echo $0 | sed 's%.*/%%'`
usage="Usage: $progname [--destdir DESTDIR] FONT.

Makes a TFM file for FONT, if possible. Use DESTDIR for the root of where
to install into, either the absolute directory name to use (if it starts
with a /) or relative to the default DESTDIR (if not)."

# Handle non-positional options, except for --version/--help
while test $# -gt 0; do
  case "$1" in
    --destdir) shift; DEST="$1"; shift ;;
    --destdir=*) DEST=`echo "$1" | sed 's/--destdir=//'`; shift ;;
    --version|-version) break ;;
    --help|-help) break ;;
    *) break ;;
  esac
done

# Common code for all scripts.
: ${MT_TEXMFMAIN=`kpsewhich --expand-path='$TEXMFMAIN'`}
: ${MT_MKTEX_OPT=`kpsewhich --format='web2c files' mktex.opt`}
test -n "$MT_MKTEX_OPT" || MT_MKTEX_OPT="$MT_TEXMFMAIN/web2c/mktex.opt"
if test ! -f "$MT_MKTEX_OPT"; then
  echo "$progname: Cannot find mktex.opt; check your installation." >&2
  exit 1
fi

. "$MT_MKTEX_OPT"

# Where do potential mf driver files go?
case "$MT_FEATURES" in
  *nomfdrivers*)
     : ${MT_MFDESTDIR=`pwd`}
     export MT_MFDESTDIR;;
esac

# start of redirection stdout -> stderr, stdin <- /dev/null
(

NAME=`basename "$1" .tfm`
MAG=1  # mag=0 fails with larm1000.mf
#DEST="$2"
DPI=$BDPI

OIFS=$IFS; IFS=$SEP
set x `"$MT_MKTEXNAM" $NAME $DPI $MODE $DEST`; shift
IFS=$OIFS

PKDEST="$1"
TFMDEST="$2"
PKDESTDIR=`echo "$PKDEST" | sed 's%/[^/][^/]*$%%'` # can't rely on dirname
TFMDESTDIR=`echo "$TFMDEST" | sed 's%/[^/][^/]*$%%'`
PKNAME=`basename "$PKDEST"`
TFMNAME=$NAME.tfm
GFNAME=$NAME.$DPI'gf'

if test -r "$TFMDESTDIR/$TFMNAME"; then
  echo "$progname: $TFMDESTDIR/$TFMNAME already exists." >&2
  echo "$TFMDESTDIR/$TFMNAME" >$STDOUT
  "$MT_MKTEXUPD" "$TFMDESTDIR" $TFMNAME
  exit
fi

# Try to create the destdir first. Do not create fonts, if this fails.
"$MT_MKTEXDIR" "$TFMDESTDIR"
if test ! -d "$TFMDESTDIR"; then
  echo "$progname: mktexdir $TFMDESTDIR failed."
  exit 1
fi

# Check if this font is supported by hbf2gf else use metafont.
if (hbf2gf -q -t $NAME) >/dev/null 2>&1; then
  cmd="hbf2gf -g $NAME $DPI"
else
  # determine the progname of metafont to use; prefer mf-nowin.
  if (mf-nowin --version) >/dev/null 2>&1; then
    MF="mf-nowin -progname=mf"
  else
    MF=mf
  fi

  cmd="$MF \mode:=$MODE; mag:=$MAG; nonstopmode; input $NAME"
fi

echo "$progname: Running $cmd"
$cmd </dev/null || {
  # Don't abort if only "Strange path", "bad pos" or "angle(0,0)"
  # errors occurr.
  grep '^!' $NAME.log | sort >$$.errs 2>/dev/null
  grep '^! Strange path' $$.errs >$$.strange 2>/dev/null
  grep '^! bad pos.' $$.errs >$$.badpos 2>/dev/null
  grep '^! angle(0,0) is taken as zero.' $$.errs >$$.angle 2>/dev/null
  cat $$.badpos $$.strange $$.angle | sort > $$.errs_accept
  if cmp $$.errs $$.errs_accept >/dev/null 2>&1; then
    test -s $$.strange >/dev/null 2>&1 \
      && echo "$progname: warning: \`$cmd' caused strange path errors." >&2
    test -s $$.badpos >/dev/null 2>&1 \
      && echo "$progname: warning: \`$cmd' caused bad pos errors." >&2
    test -s $$.angle >/dev/null 2>&1 \
      && echo "$progname: warning: \`$cmd' caused angle(0,0) errors." >&2
  else
    echo "$progname: \`$cmd' failed." >&2
    test -s $NAME.log && mv -f $NAME.log "$KPSE_DOT"
    exit 1;
  fi
}

# hbf2gf just produces a .pl file:
test -r ./$NAME.pl && pltotf ./$NAME.pl $TFMNAME
test -r $TFMNAME || { echo "$progname: \`$cmd' failed to make $TFMNAME."; exit 1; }

# Install the TFM file carefully, since others may be working simultaneously.
# Use cp when mv fails, since DOS will fail mv for deeply-nested directories.
mv $TFMNAME "$TFMDESTDIR/tfm$$.tmp" 2>/dev/null \
  || cp $TFMNAME "$TFMDESTDIR/tfm$$.tmp" || exit 1
cd "$TFMDESTDIR" || exit 1
chmod `kpsestat -xst,go-w .` tfm$$.tmp
test -r $TFMNAME || mv tfm$$.tmp $TFMNAME || exit 1

# OK, success with the TFM.
"$MT_MKTEXUPD" "$TFMDESTDIR" $TFMNAME
echo "$TFMDESTDIR/$TFMNAME" >$STDOUT
echo "$progname: $TFMDESTDIR/$TFMNAME: successfully generated." >&2

# Since we probably made a GF(->PK) file, too, may as well install it if
# it's needed.
cd $TEMPDIR
if test -r $GFNAME && test ! -f "$PKDESTDIR/$PKNAME"; then
  gftopk ./$GFNAME $PKNAME || exit 1
  "$MT_MKTEXDIR" "$PKDESTDIR"
  mv $PKNAME "$PKDESTDIR/pk$$.tmp" 2>/dev/null \
    || cp $PKNAME "$PKDESTDIR/pk$$.tmp" || exit 1
  cd "$PKDESTDIR" || exit 1
  if test -f $PKNAME; then
    rm -f pk$$.tmp
  else
    chmod `kpsestat -xst,go-w .` pk$$.tmp
    mv pk$$.tmp $PKNAME
    "$MT_MKTEXUPD" "$PKDESTDIR" $PKNAME
  fi
fi
) 1>&2 </dev/null