beta-0.89.2
[luatex.git] / source / texk / web2c / web2c / convert
blob36c5c13c94c310b9da7b9c850016c5316bc8376f
1 #!/bin/sh
2 # Convert WEB programs not needing special treatment to C.
4 : ${srcdir=.}
6 usage="Usage: $0 BASE
8 BASE is the root part of the file to be converted; it is extended with
9 .p to make the name of the (input) Pascal file, and extended with .c and
10 .h to make the name of the main (output) C files. Additional files
11 BASEini.c, BASEd.h, BASEcoerce.h are created for the larger programs.
14 basefile=
15 while test $# -gt 0; do
16 case $1 in
17 -*) echo "$1?" >&2; echo "$usage" >&2; exit 1;;
18 *) if test -n "$basefile"; then
19 echo "$1?" >&2; echo "$usage" >&2; exit 1; fi
20 basefile=$1;;
21 esac
22 shift
23 done
24 if test -z "$basefile"; then
25 echo "$0: missing base (Pascal) file argument." >&2
26 echo "$usage" >&2
27 exit 1
30 pascalfile=$basefile.p
31 cfile=$basefile.c
33 # This is for tangleboot if the build and source directories are different.
34 test -r $pascalfile || pascalfile=$srcdir/$pascalfile
36 # We use cpascal.h by default instead of config.h because straight C
37 # routines can only be confused by the definitions for `chr', etc.
38 hfile=cpascal.h
39 more_defines=
40 web2c_options=-c$basefile
41 precmd=
42 midcmd=
43 fixwrites_options=
44 # This used to have various values to control the number of *tex[0-9].c files.
45 # We now avoid to split the C code for MF and all TeX-like engines.
46 splitup_options="-i -l 65000"
47 postcmd=
48 output="> $cfile"
49 output_files="$cfile $basefile.h"
51 case $basefile in
52 pbibtex|pdvitype|ppltotf|ptftopl)
53 more_defines="$srcdir/ptexdir/ptex.defines"
54 hfile=ptexdir/kanji.h
56 upbibtex|updvitype|uppltotf|uptftopl)
57 more_defines="$srcdir/uptexdir/uptex.defines"
58 hfile=uptexdir/kanji.h
60 esac
62 case $basefile in
63 bibtex|pbibtex|upbibtex)
64 midcmd="| sed -f $srcdir/web2c/cvtbib.sed"
67 mf|mflua|mfluajit|tex|aleph|etex|pdftex|ptex|eptex|euptex|uptex|xetex)
68 case $basefile in
69 mf*)
70 more_defines="$srcdir/web2c/texmf.defines $srcdir/web2c/mfmp.defines"
71 precmd="| sed -f $srcdir/web2c/cvtmf1.sed"
72 web2c_options="-m -c${basefile}coerce"
73 midcmd="| sed -f $srcdir/web2c/cvtmf2.sed"
77 more_defines="$srcdir/web2c/texmf.defines $srcdir/synctexdir/synctex.defines"
78 web2c_options="-t -c${basefile}coerce"
79 fixwrites_options=-t
81 esac
82 prog_defines="$srcdir/${basefile}dir/$basefile.defines"
83 if test -f $prog_defines; then
84 more_defines="$more_defines $prog_defines"
86 hfile=texmfmp.h
87 postcmd="| ./web2c/splitup $splitup_options $basefile"
88 cfile=${basefile}0.c # last output file, or thereabouts
89 output=
90 output_files="$basefile[0-9].c ${basefile}ini.c ${basefile}d.h \
91 ${basefile}coerce.h"
93 esac
95 # Do it.
96 #set -x
97 eval "cat $srcdir/web2c/common.defines $more_defines $pascalfile \
98 $precmd \
99 | ./web2c/web2c -h$hfile $web2c_options \
100 $midcmd \
101 | ./web2c/fixwrites $fixwrites_options $basefile \
102 $postcmd \
103 $output"
105 # Using the above pipeline as the condition of an if does no good, since
106 # typical sh's use the status of the first command as the pipeline result.
107 # So check for an empty output file, or one with the error marker we put in.
108 if test ! -s $cfile || grep @error@ $output_files >/dev/null; then
109 : ${TMPDIR=/tmp}
110 # Don't just delete it, since it may be useful for debugging.
111 echo "$0: conversion of $pascalfile failed, moving dregs:" >&2
112 cmd="mv $output_files $TMPDIR"
113 (cd $TMPDIR && rm -f $output_files)
114 echo "$0: $cmd" >&2
115 $cmd
116 exit 1
119 case $basefile in
120 bibtex|pbibtex|upbibtex)
121 sed -e 's/(buftype)//g' -e 's/(pdstype)//g' <$basefile.h >x$basefile.h
122 mv x$basefile.h $basefile.h
124 mf|mflua|mfluajit|tex|aleph|etex|pdftex|ptex|eptex|euptex|uptex|xetex)
125 sleep 2 # so timestamps are definitely later, to avoid make weirdness
126 cat $srcdir/web2c/coerce.h >>${basefile}coerce.h
127 touch ${basefile}d.h
129 esac
131 exit 0