DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T U

⟦05f388831⟧ TextFile

    Length: 179811 (0x2be63)
    Types: TextFile
    Notes: Uncompressed file

Derivation

└─⟦060c9c824⟧ Bits:30007080 DKUUG TeX 2/12/89
    └─⟦2261db388⟧ »./tex82/Unsupported/MFpxl/P-mf84.shar.Z« 
└─⟦52210d11f⟧ Bits:30007239 EUUGD2: TeX 3 1992-12
    └─⟦beba6c409⟧ »unix3.0/Unsupported.tar.Z« 
        └─⟦25c524ae4⟧ 
            └─⟦2261db388⟧ »Unsupported/MFpxl/P-mf84.shar.Z« 
                └─⟦this⟧ 

TextFile

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#-----cut here-----cut here-----cut here-----cut here-----
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	mf84/Makefile.PYRAMID
#	mf84/Makefile.SUN_V2
#	mf84/Makefile.SUN_V3
#	mf84/Makefile.SYS_V
#	mf84/Makefile.VAX4_2
#	mf84/Makefile.VAX4_3
#	mf84/dist_inimf.BSD4_n.ch
#	mf84/dist_inimf.SYS_V.ch
#	mf84/dist_splitsource.BSD4_n
#	mf84/dist_to_ini.BSD4_n
#	mf84/dist_to_ini.SYS_V
#	mf84/dist_to_trap.BSD4_n
#	mf84/dist_to_trap.SYS_V
#	mf84/dist_to_vir.BSD4_n
#	mf84/dist_to_vir.SYS_V
#	mf84/makemf.SYS_V
#	mf84/mf_ext.BSD4_n.h
#	mf84/mf_ext.SYS_V.h
#	mf84/mf_window.BSD4_n.h
#	mf84/mf_window.SYS_V.h
#	mf84/mfsep.SYS_V.sed
# This archive created: Fri Jul 22 14:34:13 1988
cat << \SHAR_EOF > mf84/Makefile.PYRAMID

# $Header: Makefile.PYRAMID,v 1.0 86/01/31 16:54:45 richards Released $

#
# Makefile for Berkeley UNIX version of MetaFont
#
#	 	PYRAMID OSx 2.5 Version
#

# Configuration constants: defined by initial configuration setup
#	(since this makefile is generated, changes to it
#	 may disappear if the MF system is re-configured)
VERSION	= DIST
MACHINE	= PYRAMID

#
# local directory organization
#
BINDIR		= /usr/local
MF84DIR		= /usr/lib/mf
TEX82DIR	= /usr/lib/tex82
TEXSRCDIR	= ../tex82
MFLIBDIR	= MFlib
CONFIGDIR	= MFconfig

#
# utilities needed to generate and/or configure MF
#
FIXOTHERS	= cat
TANGLE		= tangle
DISTCHANGEFILE	= dist_inimf.ch

#
# compiler options -- the short "AF", "PF", etc. entries are to make
#			it easy to supplement the makefile defaults
#			where needed (i.e. to put compiler temporary
#			files in /usr/tmp, do "make PF='-t /usr/tmp'")
#
OPTIM	=

AS	= as
AF	=
AFLAGS	= -A32767 -u ${AF}

PC	= pascal
PF	=
PFLAGS	= -w ${PF} ${OPTIM}

LF	=
LDFLAGS	= -w ${LF}		# really for pc3

#
# libraries needed for linking MF
#
MFLIB		= ${MFLIBDIR}/mflib.a
MFLIBPROF	= ${MFLIBDIR}/mflib_p.a
LIBS	=
LIBSPROF=

#
# RCS checkout flags (for make systems that know about RCS)
#
COFLAGS	= -r${VERSION}

#-------------------- End of configuration definitions -------------------#

default:	inimf virmf

profiled:	inimf_p virmf_p

all:		inimf virmf trapmf

install:	default
	mv inimf virmf ${BINDIR}/.
	mv inimf.pool ${MF84DIR}/mf.pool

.SUFFIXES:
.SUFFIXES:	.web .web,v .ch .ch,v
.SUFFIXES:	_p.o .o _p.s .s _p.p .p _p.c .c

#
#   INIMF: The slow version of MetaFont which is able to make .base files
#

INIOBJS		= inimf.o
INIOBJSPROF	= inimf_p.o

inimf.ch: ${DISTCHANGEFILE} dist_to_ini ${MAKEFILE}
	dist_to_ini ${MACHINE} ${DISTCHANGEFILE} inimf.ch

# --- PYRAMID standard version

inimf: ${INIOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o inimf ${INIOBJS} ${MFLIB} ${LIBS}

inimf.o: inimf.s

inimf.s: inimf.p mf_ext.h

inimf.p: mf.web inimf.ch
	${TANGLE} mf.web inimf.ch
	${FIXOTHERS} mf.p > inimf.p
	mv mf.pool inimf.pool

# --- PYRAMID Profiled version (using gprof)

inimf_p: ${INIOBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o inimf_p ${INIOBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

inimf_p.o: inimf_p.s

inimf_p.s: inimf.p mf_ext.h

#
#   VIRMF: The fast version of MetaFont which relies on .base files to perform
#           the necessary initiations.
#

VIROBJS		= virmf.o
VIROBJSPROF	= virmf_p.o

virmf.ch: ${DISTCHANGEFILE} dist_to_vir ${MAKEFILE}
	dist_to_vir ${MACHINE} ${DISTCHANGEFILE} virmf.ch

virmf.p: mf.web virmf.ch
	${TANGLE} mf.web virmf.ch
	${FIXOTHERS} mf.p > virmf.p

# --- PYRAMID standard version

virmf: ${VIROBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o virmf ${VIROBJS} ${MFLIB} ${LIBS}

virmf.o: virmf.s

virmf.s: virmf.p mf_ext.h mf_window.h

# --- PYRAMID Profiled version (using gprof)

virmf_p: ${VIROBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o virmf_p ${VIROBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

virmf_p.o: virmf_p.s

virmf_p.s: virmf.p mf_ext.h

#
#   TRAPMF: The version of MetaFont with the constants set to the special values
#		needed when running the infamous and nefarious ``trap'' test.
#

TRAPOBJS	= trapmf.o

trapmf.ch: ${DISTCHANGEFILE} dist_to_trap ${MAKEFILE}
	dist_to_trap ${MACHINE} ${DISTCHANGEFILE} trapmf.ch

trapmf.p: mf.web trapmf.ch
	${TANGLE} mf.web trapmf.ch
	${FIXOTHERS} mf.p > trapmf.p
	mv mf.pool trapmf.pool

# --- PYRAMID standard version

trapmf: ${TRAPOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o trapmf ${TRAPOBJS} ${MFLIB} ${LIBS}

trapmf.o: trapmf.s

trapmf.s: trapmf.p mf_ext.h

#
# Implicit rules needed to compile host-specific versions
#

# --- PYRAMID Specific rules

.p.o:
	${PC} ${PFLAGS} -c $< 

.p.s:
	${PC} ${PFLAGS} -S $<

.p_p.o:
	${PC} -pg ${PFLAGS} -c $< ; mv $*.o $*_p.o

.p_p.s:
	${PC} -pg ${PFLAGS} -S $< ; mv $*.s $*_p.s

_p.s_p.o:
	${AS} ${AFLAGS} -o $*_p.o $<

.s.o:
	${AS} ${AFLAGS} -o $*.o $<

#
#   Miscellaneous stuff -- mflib.a, utilities
#

${MFLIB}: always
	@cd ${MFLIBDIR}; make mflib.a 

${MFLIBPROF}: always
	cd ${MFLIBDIR}; make mflib_p.a

always:

clean:
	rm -f inimf*.o virmf*.o trapmf*.o
	rm -f inimf*.s virmf*.s trapmf*.s
	rm -f inimf*.p virmf*.p trapmf*.p mf*.p
	rm -f inimf*.ch virmf*.ch trapmf*.ch
	rm -f inimf.pool virmf.pool core

cleanall:
	mfhome=`pwd`; for dir in . MFlib MFutils; do \
		cd $$mfhome/$$dir; make clean; done

SHAR_EOF
cat << \SHAR_EOF > mf84/Makefile.SUN_V2

# $Header: Makefile.SUN_V2,v 1.0 86/01/31 16:59:47 richards Released $

#
# Makefile for Berkeley UNIX version of MetaFont
#
#	 	SUN V2.x Version
#

# Configuration constants: defined by initial configuration setup
#	(since this makefile is generated, changes to it
#	 may disappear if the MF system is re-configured)
VERSION	= DIST
MACHINE	= SUN_V2

#
# local directory organization
#
BINDIR		= /usr/local
MF84DIR		= /usr/lib/mf
TEX82DIR	= /usr/lib/tex82
TEXSRCDIR	= ../tex82
MFLIBDIR	= MFlib
CONFIGDIR	= MFconfig

#
# utilities needed to generate and/or configure MF
#
# pxp is not needed if you are running O.S. 3.2 on a SUN 2
# FIXOTHERS	= pxp -O -f 
FIXOTHERS	= sed 's/others:/otherwise /g'
TANGLE		= tangle
DISTCHANGEFILE	= dist_inimf.ch

#
# compiler options -- the short "AF", "PF", etc. entries are to make
#			it easy to supplement the makefile defaults
#			where needed (i.e. to put compiler temporary
#			files in /usr/tmp, do "make PF='-temp=/usr/tmp'"
#			or "make PF='-t /usr/tmp'" if you are still
#			running O.S. 2.n or below.)
#
OPTIM	= -O

AS	= as
AF	=
AFLAGS	= ${AF}

PC	= pc
PF	=
PFLAGS	= -w ${PF} ${OPTIM}

LF	=
LDFLAGS	= -w ${LF}		# really for pc3

#
# libraries needed for linking MF
#
MFLIB		= ${MFLIBDIR}/mflib.a
MFLIBPROF	= ${MFLIBDIR}/mflib_p.a
LIBS		= -lsuntool -lsunwindow -lpixrect -lX
LIBSPROF	= -lsuntool -lsunwindow -lpixrect -lX

#
# RCS checkout flags (for make systems that know about RCS)
#
COFLAGS	= -r${VERSION}

#-------------------- End of configuration definitions -------------------#

default:	inimf virmf

profiled:	inimf_p virmf_p

all:		inimf virmf trapmf

install:	default
	mv inimf virmf ${BINDIR}/.
	mv inimf.pool ${MF84DIR}/mf.pool

.SUFFIXES:
.SUFFIXES:	.web .web,v .ch .ch,v
.SUFFIXES:	_p.o .o _p.s .s _p.p .p _p.c .c 

#
#   INIMF: The slow version of MetaFont which is able to make .base files
#

INIOBJS		= inimf.o
INIOBJSPROF	= inimf_p.o

inimf.ch: ${DISTCHANGEFILE} dist_to_ini ${MAKEFILE}
	dist_to_ini ${MACHINE} ${DISTCHANGEFILE} inimf.ch

# --- SUN standard version

inimf: ${INIOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o inimf ${INIOBJS} ${MFLIB} ${LIBS}

inimf.o: inimf.s

inimf.s: inimf.p mf_ext.h

inimf.p: mf.web inimf.ch
	${TANGLE} mf.web inimf.ch
	${FIXOTHERS} mf.p > inimf.p
	mv mf.pool inimf.pool

# --- SUN Profiled version (using gprof)

inimf_p: ${INIOBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o inimf_p ${INIOBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

inimf_p.o: inimf_p.s

inimf_p.s: inimf.p mf_ext.h

#
#   VIRMF: The fast version of MetaFont which relies on .base files to perform
#           the necessary initiations.
#

VIROBJS		= virmf.o
VIROBJSPROF	= virmf_p.o

virmf.ch: ${DISTCHANGEFILE} dist_to_vir ${MAKEFILE}
	dist_to_vir ${MACHINE} ${DISTCHANGEFILE} virmf.ch

virmf.p: mf.web virmf.ch
	${TANGLE} mf.web virmf.ch
	${FIXOTHERS} mf.p > virmf.p

# --- SUN standard version

virmf: ${VIROBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o virmf ${VIROBJS} ${MFLIB} ${LIBS}

virmf.o: virmf.s

virmf.s: virmf.p mf_ext.h mf_window.h

# --- SUN Profiled version (using gprof)

virmf_p: ${VIROBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o virmf_p ${VIROBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

virmf_p.o: virmf_p.s

virmf_p.s: virmf.p mf_ext.h

#
#   TRAPMF: The version of MetaFont with the constants set to the special values
#		needed when running the infamous and nefarious ``trap'' test.
#

TRAPOBJS	= trapmf.o

trapmf.ch: ${DISTCHANGEFILE} dist_to_trap ${MAKEFILE}
	dist_to_trap ${MACHINE} ${DISTCHANGEFILE} trapmf.ch

trapmf.p: mf.web trapmf.ch
	${TANGLE} mf.web trapmf.ch
	${FIXOTHERS} mf.p > trapmf.p
	mv mf.pool trapmf.pool

# --- SUN standard version

trapmf: ${TRAPOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o trapmf ${TRAPOBJS} ${MFLIB} ${LIBS}

trapmf.o: trapmf.s

trapmf.s: trapmf.p mf_ext.h

#
# Implicit rules needed to compile host-specific versions
#

# --- SUN Specific rules

.p.o:
	${PC} ${PFLAGS} -c $< 

.p.s:
	${PC} ${PFLAGS} -S $<

.p_p.o:
	${PC} -pg ${PFLAGS} -c $< ; mv $*.o $*_p.o

.p_p.s:
	${PC} -pg ${PFLAGS} -S $< ; mv $*.s $*_p.s

_p.s_p.o:
	${AS} ${AFLAGS} -o $*_p.o $<

.s.o:
	${AS} ${AFLAGS} -o $*.o $<

#
#   Miscellaneous stuff -- mflib.a, utilities
#

${MFLIB}: always
	@cd ${MFLIBDIR}; make mflib.a 

${MFLIBPROF}: always
	cd ${MFLIBDIR}; make mflib_p.a

always:

clean:
	rm -f inimf*.o virmf*.o trapmf*.o
	rm -f inimf*.s virmf*.s trapmf*.s
	rm -f inimf*.p virmf*.p trapmf*.p mf*.p
	rm -f inimf*.ch virmf*.ch trapmf*.ch
	rm -f inimf.pool virmf.pool core

cleanall:
	mfhome=`pwd`; for dir in . MFlib MFutils; do \
		cd $$mfhome/$$dir; make clean; done

SHAR_EOF
cat << \SHAR_EOF > mf84/Makefile.SUN_V3

# $Header: Makefile.SUN_V3,v 1.0 87/03/06 12:59:47 mackay Released $

#
# Makefile for Berkeley UNIX version of MetaFont
#
#	 	SUN V3.x Version
#

# Configuration constants: defined by initial configuration setup
#	(since this makefile is generated, changes to it
#	 may disappear if the MF system is re-configured)
VERSION	= DIST
MACHINE	= SUN_V3

#
# local directory organization
#
BINDIR		= /usr/local
MF84DIR		= /usr/lib/mf
TEX82DIR	= /usr/lib/tex82
TEXSRCDIR	= ../tex82
MFLIBDIR	= MFlib
CONFIGDIR	= MFconfig

#
# utilities needed to generate and/or configure MF
#
FIXOTHERS	= sed -e "s/others:/otherwise /g"
TANGLE		= tangle
DISTCHANGEFILE	= dist_inimf.ch

#
# compiler options -- the short "AF", "PF", etc. entries are to make
#			it easy to supplement the makefile defaults
#			where needed (i.e. to put compiler temporary
#			files in /usr/tmp, do "make PF='-t /usr/tmp'")
#
OPTIM	= -O

AS	= as
AF	=
AFLAGS	= ${AF}

PC	= pc
PF	=
PFLAGS	= -w ${PF} ${OPTIM}

LF	=
LDFLAGS	= -w ${LF}		# really for pc3

#
# libraries needed for linking MF
#
MFLIB		= ${MFLIBDIR}/mflib.a
MFLIBPROF	= ${MFLIBDIR}/mflib_p.a
LIBS		= -lsuntool -lsunwindow -lpixrect -lX
LIBSPROF	= -lsuntool -lsunwindow -lpixrect -lX

#
# RCS checkout flags (for make systems that know about RCS)
#
COFLAGS	= -r${VERSION}

#-------------------- End of configuration definitions -------------------#

default:	inimf virmf

profiled:	inimf_p virmf_p

all:		inimf virmf trapmf

install:	default
	mv inimf virmf ${BINDIR}/.
	mv inimf.pool ${MF84DIR}/mf.pool

.SUFFIXES:
.SUFFIXES:	.web .web,v .ch .ch,v
.SUFFIXES:	_p.o .o _p.s .s _p.p .p _p.c .c 

#
#   INIMF: The slow version of MetaFont which is able to make .base files
#

INIOBJS		= inimf.o
INIOBJSPROF	= inimf_p.o

inimf.ch: ${DISTCHANGEFILE} dist_to_ini ${MAKEFILE}
	dist_to_ini ${MACHINE} ${DISTCHANGEFILE} inimf.ch

# --- SUN standard version

inimf: ${INIOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o inimf ${INIOBJS} ${MFLIB} ${LIBS}

inimf.o: inimf.s

inimf.s: inimf.p mf_ext.h

inimf.p: mf.web inimf.ch
	${TANGLE} mf.web inimf.ch
	${FIXOTHERS} mf.p > inimf.p
	mv mf.pool inimf.pool

# --- SUN Profiled version (using gprof)

inimf_p: ${INIOBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o inimf_p ${INIOBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

inimf_p.o: inimf_p.s

inimf_p.s: inimf.p mf_ext.h

#
#   VIRMF: The fast version of MetaFont which relies on .base files to perform
#           the necessary initiations.
#

VIROBJS		= virmf.o
VIROBJSPROF	= virmf_p.o

virmf.ch: ${DISTCHANGEFILE} dist_to_vir ${MAKEFILE}
	dist_to_vir ${MACHINE} ${DISTCHANGEFILE} virmf.ch

virmf.p: mf.web virmf.ch
	${TANGLE} mf.web virmf.ch
	${FIXOTHERS} mf.p > virmf.p

# --- SUN standard version

virmf: ${VIROBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o virmf ${VIROBJS} ${MFLIB} ${LIBS}

virmf.o: virmf.s

virmf.s: virmf.p mf_ext.h mf_window.h

# --- SUN Profiled version (using gprof)

virmf_p: ${VIROBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o virmf_p ${VIROBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

virmf_p.o: virmf_p.s

virmf_p.s: virmf.p mf_ext.h

#
#   TRAPMF: The version of MetaFont with the constants set to the special values
#		needed when running the infamous and nefarious ``trap'' test.
#

TRAPOBJS	= trapmf.o

trapmf.ch: ${DISTCHANGEFILE} dist_to_trap ${MAKEFILE}
	dist_to_trap ${MACHINE} ${DISTCHANGEFILE} trapmf.ch

trapmf.p: mf.web trapmf.ch
	${TANGLE} mf.web trapmf.ch
	${FIXOTHERS} mf.p > trapmf.p
	mv mf.pool trapmf.pool

# --- SUN standard version

trapmf: ${TRAPOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o trapmf ${TRAPOBJS} ${MFLIB} ${LIBS}

trapmf.o: trapmf.s

trapmf.s: trapmf.p mf_ext.h

#
# Implicit rules needed to compile host-specific versions
#

# --- SUN Specific rules

.p.o:
	${PC} ${PFLAGS} -c $< 

.p.s:
	${PC} ${PFLAGS} -S $<

.p_p.o:
	${PC} -pg ${PFLAGS} -c $< ; mv $*.o $*_p.o

.p_p.s:
	${PC} -pg ${PFLAGS} -S $< ; mv $*.s $*_p.s

_p.s_p.o:
	${AS} ${AFLAGS} -o $*_p.o $<

.s.o:
	${AS} ${AFLAGS} -o $*.o $<

#
#   Miscellaneous stuff -- mflib.a, utilities
#

${MFLIB}: always
	@cd ${MFLIBDIR}; make mflib.a 

${MFLIBPROF}: always
	cd ${MFLIBDIR}; make mflib_p.a

always:

clean:
	rm -f inimf*.o virmf*.o trapmf*.o
	rm -f inimf*.s virmf*.s trapmf*.s
	rm -f inimf*.p virmf*.p trapmf*.p mf*.p
	rm -f inimf*.ch virmf*.ch trapmf*.ch
	rm -f inimf.pool virmf.pool core

cleanall:
	mfhome=`pwd`; for dir in . MFlib MFutils; do \
		cd $$mfhome/$$dir; make clean; done

SHAR_EOF
cat << \SHAR_EOF > mf84/Makefile.SYS_V

# $Header: Makefile.SUN_V2,v 1.0 86/01/31 16:59:47 richards Released $

#
# Makefile for System V UNIX version of MetaFont
#

# Configuration constants: defined by initial configuration setup
#	(since this makefile is generated, changes to it
#	 may disappear if the MF system is re-configured)
VERSION	= DIST
MACHINE	= U3B

#
# local directory organization
#
BINDIR		= /usr/local
MF84DIR		= /usr/local/lib/mf
TEX82DIR	= /usr/local/lib/tex
TEXSRCDIR	= ../tex82
MFLIBDIR	= MFlib
CONFIGDIR	= MFconfig

#
# utilities needed to generate and/or configure MF
#
FIXOTHERS	= pxp -O -f -L140
TANGLE		= tangle
DISTCHANGEFILE	= dist_inimf.ch

#
# compiler options -- the short "AF", "PF", etc. entries are to make
#			it easy to supplement the makefile defaults
#			where needed (i.e. to put compiler temporary
#			files in /usr/tmp, do "make PF='-t /usr/tmp'")
#
OPTIM	= -O

AS	= as
AF	=
AFLAGS	= ${AF}

PC	= pc
PF	=
PFLAGS	= -w ${PF} ${OPTIM}

LF	=
LDFLAGS	= -w ${LF}		# really for pc3

#
# libraries needed for linking MF
#
MFLIB		= ${MFLIBDIR}/mflib.a
MFLIBPROF	= ${MFLIBDIR}/mflib_p.a
LIBS		=
LIBSPROF	=

#
# RCS checkout flags (for make systems that know about RCS)
#
COFLAGS	= -r${VERSION}

#-------------------- End of configuration definitions -------------------#

default:	inimf virmf

profiled:	inimf_p virmf_p

all:		inimf virmf trapmf

install:	default
	mv inimf virmf ${BINDIR}/.
	mv inimf.pool ${MF84DIR}/mf.pool

.SUFFIXES:
.SUFFIXES:	.web .web,v .ch .ch,v
.SUFFIXES:	_p.o .o _p.s .s _p.p .p _p.c .c 

#
#   INIMF: The slow version of MetaFont which is able to make .base files
#

inimf.ch: ${DISTCHANGEFILE} dist_to_ini ${MAKEFILE}
	dist_to_ini ${MACHINE} ${DISTCHANGEFILE} inimf.ch

# --- UNIX standard version

inimf: inimf.p ${MFLIB}
	makemf inimf

inimf.p: mf.web inimf.ch
	${TANGLE} mf.web inimf.ch
	${FIXOTHERS} mf.p > inimf.p
	mv mf.pool inimf.pool

#
#   VIRMF: The fast version of MetaFont which relies on .base files to perform
#           the necessary initiations.
#

virmf.ch: ${DISTCHANGEFILE} dist_to_vir ${MAKEFILE}
	dist_to_vir ${MACHINE} ${DISTCHANGEFILE} virmf.ch

virmf.p: mf.web virmf.ch
	${TANGLE} mf.web virmf.ch
	${FIXOTHERS} mf.p > virmf.p

virmf: virmf.p ${MFLIB}
	makemf virmf

#
#   TRAPMF: The version of MetaFont with the constants set to the special values
#		needed when running the infamous and nefarious ``trap'' test.
#

trapmf.ch: ${DISTCHANGEFILE} dist_to_trap ${MAKEFILE}
	dist_to_trap ${MACHINE} ${DISTCHANGEFILE} trapmf.ch

trapmf.p: mf.web trapmf.ch
	${TANGLE} mf.web trapmf.ch
	${FIXOTHERS} mf.p > trapmf.p
	mv mf.pool trapmf.pool

trapmf: trapmf.p ${MFLIB}
	makemf trapmf

#
# Implicit rules needed to compile host-specific versions
#

.p.o:
	${PC} ${PFLAGS} -c $< 

.p.s:
	${PC} ${PFLAGS} -S $<

.p_p.o:
	${PC} -pg ${PFLAGS} -c $< ; mv $*.o $*_p.o

.p_p.s:
	${PC} -pg ${PFLAGS} -S $< ; mv $*.s $*_p.s

_p.s_p.o:
	${AS} ${AFLAGS} -o $*_p.o $<

.s.o:
	${AS} ${AFLAGS} -o $*.o $<

#
#   Miscellaneous stuff -- mflib.a, utilities
#

${MFLIB}: always
	@cd ${MFLIBDIR}; make mflib.a 

${MFLIBPROF}: always
	cd ${MFLIBDIR}; make mflib_p.a

always:

clean:
	rm -f inimf?.? virmf?.? trapmf?.?
	rm -f inimf*.ch virmf*.ch trapmf*.ch
	rm -f inimf.pool virmf.pool core

cleanall:
	mfhome=`pwd`; for dir in . MFlib MFutils; do \
		cd $$mfhome/$$dir; make clean; done
SHAR_EOF
cat << \SHAR_EOF > mf84/Makefile.VAX4_2
# $Header: Makefile.VAX4_2,v 1.0 86/01/31 16:51:06 richards Released $

#
# Makefile for Berkeley UNIX version of MetaFont
#
#	 	VAX 4.2 BSD Version
#

# Configuration constants: defined by initial configuration setup
#	(since this makefile is generated, changes to it
#	 may disappear if the MF system is re-configured)
VERSION	= DIST
MACHINE	= VAX4_2

#
# local directory organization
#
BINDIR		= /usr/local
MF84DIR		= /usr/lib/mf
TEXSRCDIR	= ../tex82
MFLIBDIR	= MFlib
CONFIGDIR	= MFconfig

#
# utilities needed to generate and/or configure MF
#
FIXOTHERS	= pxp -O -f
TANGLE		= tangle
DISTCHANGEFILE	= dist_inimf.ch

#
# compiler options -- the short "AF", "PF", etc. entries are to make
#			it easy to supplement the makefile defaults
#			where needed (i.e. to put compiler temporary
#			files in /usr/tmp, do "make PF='-t /usr/tmp'")
#
OPTIM	= 
#
# we would like to optimize, but it seems to produce buggy as code
#			at least on ULTRIX, which is all too common
#			these days.  Not much efficency seems to be
#			lost when the flag is abandoned.

AS	= as
AF	=
AFLAGS	= -J ${AF}

PC	= pc
PF	=
PFLAGS	= -w -J ${PF} ${OPTIM}

LF	=
LDFLAGS	= -w ${LF}		# really for pc3

#
# libraries needed for linking MF
#
MFLIB		= ${MFLIBDIR}/mflib.a
MFLIBPROF	= ${MFLIBDIR}/mflib_p.a
LIBS	=
LIBSPROF=

#
# RCS checkout flags (for make systems that know about RCS)
#
COFLAGS	= -r${VERSION}

#-------------------- End of configuration definitions -------------------#

default:	inimf virmf

profiled:	inimf_p virmf_p

all:		inimf virmf trapmf

install:	default
	mv inimf virmf ${BINDIR}/.
	mv inimf.pool ${MF84DIR}/mf.pool

.SUFFIXES:
.SUFFIXES:	.web .web,v .ch .ch,v
.SUFFIXES:	_p.o .o _p.s .s _p.p .p _p.c .c

#
#   INIMF: The slow version of MetaFont which is able to make .base files
#

INIOBJS		= inimf.o
INIOBJSPROF	= inimf_p.o

inimf.ch: ${DISTCHANGEFILE} dist_to_ini ${MAKEFILE}
	dist_to_ini ${MACHINE} ${DISTCHANGEFILE} inimf.ch

# --- VAX standard version

inimf: ${INIOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o inimf ${INIOBJS} ${MFLIB} ${LIBS}

inimf.o: inimf.s

inimf.s: inimf.p mf_ext.h

inimf.p: mf.web inimf.ch
	${TANGLE} mf.web inimf.ch
	${FIXOTHERS} mf.p > inimf.p
	mv mf.pool inimf.pool

# --- VAX Profiled version (using gprof)

inimf_p: ${INIOBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o inimf_p ${INIOBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

inimf_p.o: inimf_p.s

inimf_p.s: inimf.p mf_ext.h

#
#   VIRMF: The fast version of MetaFont which relies on .base files to perform
#           the necessary initiations.
#

VIROBJS		= virmf.o
VIROBJSPROF	= virmf_p.o

virmf.ch: ${DISTCHANGEFILE} dist_to_vir ${MAKEFILE}
	dist_to_vir ${MACHINE} ${DISTCHANGEFILE} virmf.ch

virmf.p: mf.web virmf.ch
	${TANGLE} mf.web virmf.ch
	${FIXOTHERS} mf.p > virmf.p

# --- VAX standard version

virmf: ${VIROBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o virmf ${VIROBJS} ${MFLIB} ${LIBS}

virmf.o: virmf.s

virmf.s: virmf.p mf_ext.h mf_window.h

# --- VAX Profiled version (using gprof)

virmf_p: ${VIROBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o virmf_p ${VIROBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

virmf_p.o: virmf_p.s

virmf_p.s: virmf.p mf_ext.h

#
#   TRAPMF: The version of MetaFont with the constants set to the special values
#		needed when running the infamous and nefarious ``trap'' test.
#

TRAPOBJS	= trapmf.o

trapmf.ch: ${DISTCHANGEFILE} dist_to_trap ${MAKEFILE}
	dist_to_trap ${MACHINE} ${DISTCHANGEFILE} trapmf.ch

trapmf.p: mf.web trapmf.ch
	${TANGLE} mf.web trapmf.ch
	${FIXOTHERS} mf.p > trapmf.p
	mv mf.pool trapmf.pool

# --- VAX standard version

trapmf: ${TRAPOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o trapmf ${TRAPOBJS} ${MFLIB} ${LIBS}

trapmf.o: trapmf.s

trapmf.s: trapmf.p mf_ext.h

#
# Implicit rules needed to compile host-specific versions
#

# --- VAX Specific rules

.p.o:
	${PC} ${PFLAGS} -c $< 

.p.s:
	${PC} ${PFLAGS} -S $<

.p_p.o:
	${PC} -pg ${PFLAGS} -c $< ; mv $*.o $*_p.o

.p_p.s:
	${PC} -pg ${PFLAGS} -S $< ; mv $*.s $*_p.s

_p.s_p.o:
	${AS} ${AFLAGS} -o $*_p.o $<

.s.o:
	${AS} ${AFLAGS} -o $*.o $<

#
#   Miscellaneous stuff -- mflib.a, utilities
#

${MFLIB}: always
	@cd ${MFLIBDIR}; make mflib.a 

${MFLIBPROF}: always
	cd ${MFLIBDIR}; make mflib_p.a

always:

clean:
	rm -f inimf*.o virmf*.o trapmf*.o
	rm -f inimf*.s virmf*.s trapmf*.s
	rm -f inimf*.p virmf*.p trapmf*.p mf*.p
	rm -f inimf*.ch virmf*.ch trapmf*.ch
	rm -f inimf.pool virmf.pool core

cleanall:
	mfhome=`pwd`; for dir in . MFlib MFutils; do \
		cd $$mfhome/$$dir; make clean; done

SHAR_EOF
cat << \SHAR_EOF > mf84/Makefile.VAX4_3
# $Header: Makefile.VAX4_3,v 1.0 86/01/31 16:57:16 richards Released $

#
# Makefile for Berkeley UNIX version of MetaFont
#
#	 	VAX 4.3 BSD Version
#

# Configuration constants: defined by initial configuration setup
#	(since this makefile is generated, changes to it
#	 may disappear if the MF system is re-configured)
VERSION	= DIST
MACHINE	= VAX4_2

#
# local directory organization
#
BINDIR		= /usr/local
MF84DIR		= /usr/lib/mf
TEX82DIR	= /usr/lib/tex82
TEXSRCDIR	= ../tex82
MFLIBDIR	= MFlib
CONFIGDIR	= MFconfig

#
# utilities needed to generate and/or configure MF
#
FIXOTHERS	= pxp -O -f
TANGLE		= tangle
DISTCHANGEFILE	= dist_inimf.ch

#
# compiler options -- the short "AF", "PF", etc. entries are to make
#			it easy to supplement the makefile defaults
#			where needed (i.e. to put compiler temporary
#			files in /usr/tmp, do "make PF='-t /usr/tmp'")
#
OPTIM	=

AS	= as
AF	=
AFLAGS	= -J ${AF}

PC	= pc
PF	=
PFLAGS	= -w -J ${PF} ${OPTIM}

LF	=
LDFLAGS	= -w ${LF}		# really for pc3

#
# libraries needed for linking MF
#
MFLIB		= ${MFLIBDIR}/mflib.a
MFLIBPROF	= ${MFLIBDIR}/mflib_p.a
LIBS	=
LIBSPROF=

#
# RCS checkout flags (for make systems that know about RCS)
#
COFLAGS	= -r${VERSION}

#-------------------- End of configuration definitions -------------------#

default:	inimf virmf

profiled:	inimf_p virmf_p

all:		inimf virmf trapmf

install:	default
	mv inimf virmf ${BINDIR}/.
	mv inimf.pool ${MF84DIR}/mf.pool

.SUFFIXES:
.SUFFIXES:	.web .web,v .ch .ch,v
.SUFFIXES:	_p.o .o _p.s .s _p.p .p _p.c .c

#
#   INIMF: The slow version of MetaFont which is able to make .base files
#

INIOBJS		= inimf.o
INIOBJSPROF	= inimf_p.o

inimf.ch: ${DISTCHANGEFILE} dist_to_ini ${MAKEFILE}
	dist_to_ini ${MACHINE} ${DISTCHANGEFILE} inimf.ch

# --- VAX standard version

inimf: ${INIOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o inimf ${INIOBJS} ${MFLIB} ${LIBS}

inimf.o: inimf.s

inimf.s: inimf.p mf_ext.h

inimf.p: mf.web inimf.ch
	${TANGLE} mf.web inimf.ch
	${FIXOTHERS} mf.p > inimf.p
	mv mf.pool inimf.pool

# --- VAX Profiled version (using gprof)

inimf_p: ${INIOBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o inimf_p ${INIOBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

inimf_p.o: inimf_p.s

inimf_p.s: inimf.p mf_ext.h

#
#   VIRMF: The fast version of MetaFont which relies on .base files to perform
#           the necessary initiations.
#

VIROBJS		= virmf.o
VIROBJSPROF	= virmf_p.o

virmf.ch: ${DISTCHANGEFILE} dist_to_vir ${MAKEFILE}
	dist_to_vir ${MACHINE} ${DISTCHANGEFILE} virmf.ch

virmf.p: mf.web virmf.ch
	${TANGLE} mf.web virmf.ch
	${FIXOTHERS} mf.p > virmf.p

# --- VAX standard version

virmf: ${VIROBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o virmf ${VIROBJS} ${MFLIB} ${LIBS}

virmf.o: virmf.s

virmf.s: virmf.p mf_ext.h mf_window.h

# --- VAX Profiled version (using gprof)

virmf_p: ${VIROBJSPROF} ${MFLIBPROF}
	${PC} ${LDFLAGS} -pg -o virmf_p ${VIROBJSPROF} \
					${MFLIBPROF} ${LIBSPROF}

virmf_p.o: virmf_p.s

virmf_p.s: virmf.p mf_ext.h

#
#   TRAPMF: The version of MetaFont with the constants set to the special values
#		needed when running the infamous and nefarious ``trap'' test.
#

TRAPOBJS	= trapmf.o

trapmf.ch: ${DISTCHANGEFILE} dist_to_trap ${MAKEFILE}
	dist_to_trap ${MACHINE} ${DISTCHANGEFILE} trapmf.ch

trapmf.p: mf.web trapmf.ch
	${TANGLE} mf.web trapmf.ch
	${FIXOTHERS} mf.p > trapmf.p
	mv mf.pool trapmf.pool

# --- VAX standard version

trapmf: ${TRAPOBJS} ${MFLIB}
	${PC} ${LDFLAGS} -o trapmf ${TRAPOBJS} ${MFLIB} ${LIBS}

trapmf.o: trapmf.s

trapmf.s: trapmf.p mf_ext.h

#
# Implicit rules needed to compile host-specific versions
#

# --- VAX Specific rules

.p.o:
	${PC} ${PFLAGS} -c $< 

.p.s:
	${PC} ${PFLAGS} -S $<

.p_p.o:
	${PC} -pg ${PFLAGS} -c $< ; mv $*.o $*_p.o

.p_p.s:
	${PC} -pg ${PFLAGS} -S $< ; mv $*.s $*_p.s

_p.s_p.o:
	${AS} ${AFLAGS} -o $*_p.o $<

.s.o:
	${AS} ${AFLAGS} -o $*.o $<

#
#   Miscellaneous stuff -- mflib.a, utilities
#

${MFLIB}: always
	@cd ${MFLIBDIR}; make mflib.a 

${MFLIBPROF}: always
	cd ${MFLIBDIR}; make mflib_p.a

always:

clean:
	rm -f inimf*.o virmf*.o trapmf*.o
	rm -f inimf*.s virmf*.s trapmf*.s
	rm -f inimf*.p virmf*.p trapmf*.p mf*.p
	rm -f inimf*.ch virmf*.ch trapmf*.ch
	rm -f inimf.pool virmf.pool core

cleanall:
	mfhome=`pwd`; for dir in . MFlib MFutils; do \
		cd $$mfhome/$$dir; make clean; done

SHAR_EOF
cat << \SHAR_EOF > mf84/dist_inimf.BSD4_n.ch
% $Header: dist_inimf.ch,v 1.3 87/03/06 21:15:21 mackay Released $

% Change file for 4.2 BSD UNIX, for use with the pxp Pascal preprocessor
% (that accepts an others: clause in case statements).
%
% Derived from INITEX.CH for Berkeley Unix TeX 1.1, by Howard Trickey
%   and Pavel Curtis

% Modification History:
%
% $Log:	dist_inimf.ch,v $
% Revision 1.3  87/03/07  21:15:21  mackay
%
%	Minor changes found on archive version on SCORE
%	(max_in_open increased to 10. --  88/02/07 PAM)
%
% Revision 1.2  86/09/29  21:46:43  mackay
%
%	Made no-debug the default, and changed version number
%	to correspond with improved mf.web file
%	(Got rid of debug code to avoid bug in range check
%	code of VAX4.3 BSD and SUN3 version 3.x Os pc interpreter)
%
% Revision 1.0  86/01/31  15:46:08  richards
% Released for MF 1.0;
% 
% 	Incorporates: New binary I/O library, seperate optimized
% 	arithmetic for takefraction/makefraction, new graphics interface
% 
% Revision 0.999999.1.2  86/01/28  19:49:38  richards
% Added:
% 	variable "dummy" to routine initterm() because SUN PC compiler
% 	loops with only i,j,k defined. Argh!
% 
% Revision 0.999999.1.1  86/01/21  23:05:16  richards
% First cut for MF 1.0
% 
% Revision 0.999999  86/01/13  00:40:25  richards
% Released for 0.999999:
% 	added OTHERCASES sentinel
% 	revised WINDOW interface and include files
% 
% Revision 0.99999  85/12/09  20:23:35  richards
% Version for 0.99999
% 
% Revision 0.9999  85/10/21  20:48:24  richards
% Released for MF version 0.9999
% 
% Revision 0.999  85/10/18  21:33:44  richards
% Version that works with 0.999 MF (Never released)
% 
% Revision 0.91  85/05/16  10:58:13  richards
% Released for MF version 0.91
% 
% Revision 0.81  85/05/05  12:24:08  richards
% Released for MF version 0.81
% 
% Revision 0.77  85/03/11  20:23:37  richards
% Released for MF version 0.77
% 
% Revision 0.6.1.1  85/02/12  20:12:32  richards
% First edit for 0.76
% 
% Revision 0.6  85/02/08  00:52:40  richards
% Distribution version for MF 0.6
% 
% Revision 0.0.2.1  84/12/06  03:43:33  richards
% Edited to work with 0.4 -- still needs to have section numbers re-done
% 	before release.
% 
% Revision 0.0  84/11/05  00:50:38  richards
% Base version (first cut) for MetaFont 0.0
% 
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [0] WEAVE: only print changes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
\def\botofcontents{\vskip 0pt plus 1fil minus 1.5in}
@y
\def\botofcontents{\vskip 0pt plus 1fil minus 1.5in}
\let\maybe=\iffalse
\def\title{{\logo opqrstuq} changes for Berkeley {\mc UNIX}}
\def\glob{13}\def\gglob{20, 25} % these are defined in module 1
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.2] banner line
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d banner=='This is METAFONT, Version 1.3' {printed when \MF\ starts}
@y
@d banner=='This is METAFONT, Version 1.3 for Berkeley UNIX'
                                                 {printed when \MF\ starts}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.4] program header, include mf_ext.h for C routine linkage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
Actually the heading shown here is not quite normal: The |program| line
does not mention any |output| file, because \ph\ would ask the \MF\ user
to specify a file name if |output| were specified here.
@^system dependencies@>

@d mtype==t@&y@&p@&e {this is a \.{WEB} coding trick:}
@y
@d mtype==t@&y@&p@&e {this is a \.{WEB} coding trick:}
@d standard_input==i@&n@&p@&u@&t {and another}
@z
@x
program MF; {all file names are defined dynamically}
@y
program MF(standard_input,output); {other file names are defined dynamically}
@z
@x
var @<Global variables@>@/
@y
var @<Global variables@>@/
@#
@\@=#include "mf_ext.h"@>@\ {declarations for external C procedures}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.7] debug..gubed, stat..tats
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% @x
% @d debug==@{ {change this to `$\\{debug}\equiv\null$' when debugging}
% @d gubed==@t@>@} {change this to `$\\{gubed}\equiv\null$' when debugging}
% @y
% @d debug==
% @d gubed==
% @z
% All removed to avoid bug in pc for VAX 4.3 and SUN2/3 Version 3.1 Os.
@x
@d stat==@{ {change this to `$\\{stat}\equiv\null$' when gathering
  usage statistics}
@d tats==@t@>@} {change this to `$\\{tats}\equiv\null$' when gathering
  usage statistics}
@y
@d stat==
@d tats==
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.8] init..tini
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d init== {change this to `$\\{init}\equiv\.{@@\{}$' in the production version}
@d tini== {change this to `$\\{tini}\equiv\.{@@\}}$' in the production version}
@y
@d init==
@d tini==
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.9] compiler directives
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@{@&$C-,A+,D-@} {no range check, catch arithmetic overflow, no debug overhead}
@!debug @{@&$C+,D+@}@+ gubed {but turn everything on when debugging}
@y
@=(*$C-*)@> {no range check}
@!debug @=(*$C+*)@> @+ gubed {but turn everything on when debugging}
@z

% ADD-OTHERCASES-CHANGES-HERE	%%% SENTINEL LINE -- DO NOT REMOVE %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.11] compile-time constants, use logical names
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x %% mem_max %% NEEDED FOR ini_to_vir
@!mem_max=30000; {greatest index in \MF's internal |mem| array;
  must be strictly less than |max_halfword|;
  must be equal to |mem_top| in \.{INIMF}, otherwise |>=mem_top|}
@y
@!mem_max=30000; {greatest index in \MF's internal |mem| array;
  must be strictly less than |max_halfword|;
  must be equal to |mem_top| in \.{INIMF}, otherwise |>=mem_top|}
@z
@x %% error_line half_error_line max_print_line %%
@!error_line=72; {width of context lines on terminal error messages}
@!half_error_line=42; {width of first lines of contexts in terminal
  error messages; should be between 30 and |error_line-15|}
@!max_print_line=79; {width of longest text lines output; should be at least 60}
@y
@!error_line=79; {width of context lines on terminal error messages}
@!half_error_line=50; {width of first lines of contexts in terminal
  error messages; should be between 30 and |error_line-15|}
@!max_print_line=79; {width of longest text lines output; should be at least 60}
@z
@x %% screen_width screen_depth %%
@!screen_width=768; {number of pixels in each row of screen display}
@!screen_depth=1024; {number of pixels in each column of screen display}
@y
@!screen_width=1024; {number of pixels in each row of screen display}
@!screen_depth=1024; {number of pixels in each column of screen display}
@z
@x %% gf_buf_size file_name_size pool_name %%
@!gf_buf_size=800; {size of the output buffer, must be a multiple of 8}
@!file_name_size=40; {file names shouldn't be longer than this}
@!pool_name='MFbases:MF.POOL                         ';
  {string of length |file_name_size|; tells where the string pool appears}
@y
@!gf_buf_size=800; {size of the output buffer, must be a multiple of 8}
@!file_name_size=256; {file names shouldn't be longer than this}
@!pool_name='mf.pool';
  {string of length |file_name_size|; tells where the string pool appears}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.12] sensitive compile-time constants
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d mem_min=0 {smallest index in the |mem| array, must not be less
  than |min_halfword|}
@d mem_top==30000 {largest index in the |mem| array dumped by \.{INIMF};
  must be substantially larger than |mem_min|
  and not greater than |mem_max|}
@d hash_size=2100 {maximum number of symbolic tokens,
  must be less than |max_halfword-3*param_size|}
@d hash_prime=1777 {a prime number equal to about 85\% of |hash_size|}
@d max_in_open=6 {maximum number of input files and error insertions that
  can be going on simultaneously}
@d param_size=150 {maximum number of simultaneous macro parameters}
@y
@d mem_min==-30000{smallest index in the |mem| array, must not be less
  than |min_halfword|}
@d mem_top==30000 {largest index in the |mem| array dumped by \.{INIMF};
  must be substantially larger than |mem_min|
  and not greater than |mem_max|}
@d hash_size=2100 {maximum number of symbolic tokens,
  must be less than |max_halfword-3*param_size|}
@d hash_prime=1777 {a prime number equal to about 85\% of |hash_size|}
@d max_in_open=10 {maximum number of input files and error insertions that
  can be going on simultaneously. Enlarged for Silvio Levy's Greek}
@d param_size=150 {maximum number of simultaneous macro parameters}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.22] accept <tab> and <ff> as valid input chars
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@^character set dependencies@>
@^system dependencies@>

@<Set init...@>=
for i:=1 to @'37 do xchr[i]:=' ';

@y
@^character set dependencies@>
@^system dependencies@>

@d tab = @'11 { ASCII horizontal tab }
@d form_feed = @'14 { ASCII form-feed }

@<Set init...@>=
for i:=1 to @'37 do xchr[i]:=' ';
xchr[tab]:=chr(tab);
xchr[form_feed]:=chr(form_feed);

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.24] file types
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The program actually makes use also of a third kind of file, called a
@y
Not all Pascal compilers available under the various implementations
of {\mc UNIX} produce programs that are able to read and write binary
data in reasonable ways, so we resort to using an external library to
do the reading and writing for us.  We still use a variable of type
|byte_file| to indicate to those routines which file we wish to manipulate,
but |byte_file| no longer is a Pascal file type.  Instead, we redefine
it to be a special record (a ``magic cookie'', if you will) that has
enough information to maintain the file state.

The program actually makes use also of a third kind of file, called a
@z
@x
@!alpha_file=packed file of text_char; {files that contain textual data}
@!byte_file=packed file of eight_bits; {files that contain binary data}
@y
@!alpha_file=t@&e@&x@&t; {files that contain textual data}
@!UNIX_file_name=packed array [1..file_name_size] of char; {for file names}
@!byte_file=record@/
stdio_ptr: ^integer; {pointer for stdio FILE struct}
loc_ptr: ^integer; {pointer to byte position ptr to keep in sync with file}
file_name: UNIX_file_name; {file name saved by open routines}
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.25] add real_name_of_file array for search path resolution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
is crucial for our purposes. We shall assume that |name_of_file| is a variable
of an appropriate type such that the \PASCAL\ run-time system being used to
implement \MF\ can open a file whose external name is specified by
|name_of_file|.
@^system dependencies@>

@<Glob...@>=
@!name_of_file:packed array[1..file_name_size] of char;@;@/
  {on some systems this may be a \&{record} variable}
@!name_length:0..file_name_size;@/{this many characters are actually
  relevant in |name_of_file| (the rest are blank)}
@y
is crucial for our purposes. We shall assume that |name_of_file| is a variable
of an appropriate type such that the \PASCAL\ run-time system being used to
implement \MF\ can open a file whose external name is specified by
|name_of_file|.
The Berkeley {\mc UNIX} version uses search paths to look for files to open.
We use |real_name_of_file| to hold the |name_of_file| with a directory
name from the path in front of it.
@^system dependencies@>

@<Glob...@>=
@!name_of_file,@!real_name_of_file:UNIX_file_name;
@;@/
@!name_length:0..file_name_size;@/{this many characters are actually
  relevant in |name_of_file| (the rest are blank)}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.26] file opening
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The \ph\ compiler with which the present version of \MF\ was prepared has
extended the rules of \PASCAL\ in a very convenient way. To open file~|f|,
we can write
$$\vbox{\halign{#\hfil\qquad&#\hfil\cr
|reset(f,@t\\{name}@>,'/O')|&for input;\cr
|rewrite(f,@t\\{name}@>,'/O')|&for output.\cr}}$$
The `\\{name}' parameter, which is of type `\ignorespaces|packed
array[@t\<\\{any}>@>] of text_char|', stands for the name of
the external file that is being opened for input or output.
Blank spaces that might appear in \\{name} are ignored.

The `\.{/O}' parameter tells the operating system not to issue its own
error messages if something goes wrong. If a file of the specified name
cannot be found, or if such a file cannot be opened for some other reason
(e.g., someone may already be trying to write the same file), we will have
|@!erstat(f)<>0| after an unsuccessful |reset| or |rewrite|.  This allows
\MF\ to undertake appropriate corrective action.
@:PASCAL H}{\ph@>
@^system dependencies@>

\MF's file-opening procedures return |false| if no file identified by
|name_of_file| could be opened.

@d reset_OK(#)==erstat(#)=0
@d rewrite_OK(#)==erstat(#)=0

@p function a_open_in(var @!f:alpha_file):boolean;
  {open a text file for input}
begin reset(f,name_of_file,'/O'); a_open_in:=reset_OK(f);
end;
@#
function a_open_out(var @!f:alpha_file):boolean;
  {open a text file for output}
begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f);
end;
@#
function b_open_out(var @!f:byte_file):boolean;
  {open a binary file for output}
begin rewrite(f,name_of_file,'/O'); b_open_out:=rewrite_OK(f);
end;
@#
function w_open_in(var @!f:word_file):boolean;
  {open a word file for input}
begin reset(f,name_of_file,'/O'); w_open_in:=reset_OK(f);
end;
@#
function w_open_out(var @!f:word_file):boolean;
  {open a word file for output}
begin rewrite(f,name_of_file,'/O'); w_open_out:=rewrite_OK(f);
end;
@y
@ The \ph\ compiler with which the present version of \MF\ was prepared has
extended the rules of \PASCAL\ in a very convenient way for file opening.
Berkeley {\mc UNIX} \PASCAL\ isn't nearly as nice as \ph.
Normally, it bombs out if a file open fails.
An external C procedure, |test_access| is used to check whether or not the
open will work.  It is declared in the `mf_ext.h' include file, and it returns
|true| or |false|. The |name_of_file| global holds the file name whose access
is to be tested.
The first parameter for |test_access| is the access mode,
one of |read_access_mode| or |write_access_mode|.

We also implement path searching in |test_access|:  its second parameter is
one of the ``file path'' constants defined below.  If |name_of_file|
doesn't start with |'/'| then |test_access| tries prepending pathnames
from the appropriate path list until success or the end of path list
is reached.
On return, |real_name_of_file| contains the original name with the path
that succeeded (if any) prepended.  It is the name used in the various
open procedures.

The binary input and output routines are slightly different, as they
implement path searching directly, and don't need an assistant to
help.  Because the arguments to |b_open_in| and |b_open_out| were
designed to correspond to what \MF\ expects, we omit their definition
herewith entirely.

Note that |a_open_in| has been redefined to take an additional argument,
which should be one of the ``file path'' specifiers.
Path searching is not done for output files.

@d read_access_mode=4  {``read'' mode for |test_access|}
@d write_access_mode=2 {``write'' mode for |test_access|}

@d no_file_path=0    {no path searching should be done}
@d MF_input_file_path=6 {path specifier for \.{input} files}
@d MF_base_file_path=7 {path specifier for base files}
@d MF_pool_file_path=8  {path specifier for the pool file}

@p function a_open_in(var @!f:alpha_file;@!path_specifier:integer):boolean;
  {open a text file for input}
var @!ok:boolean;
begin
if test_access(name_of_file, real_name_of_file,
		read_access_mode,path_specifier) then
    begin reset(f,real_name_of_file); ok:=true@+end
else
    ok:=false;
a_open_in:=ok;
end;
@#
function a_open_out(var @!f:alpha_file):boolean;
  {open a text file for output}
var @!ok:boolean;
begin
if test_access(name_of_file, real_name_of_file,
		write_access_mode,no_file_path) then
    begin rewrite(f,real_name_of_file); ok:=true @+end
else ok:=false;
a_open_out:=ok;
end;
@#
function w_open_in(var @!f:word_file):boolean;
  {open a word file for input}
var @!ok:boolean;
begin
if test_access(name_of_file, real_name_of_file,
		read_access_mode,MF_base_file_path) then
    begin reset(f,real_name_of_file); ok:=true @+end
else ok:=false;
w_open_in:=ok;
end;
@#
function w_open_out(var @!f:word_file):boolean;
  {open a word file for output}
var @!ok:boolean;
begin
if test_access(name_of_file, real_name_of_file,
		write_access_mode,no_file_path) then
    begin rewrite(f,name_of_file); ok:=true @+end
else ok:=false;
w_open_out:=ok;
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.27] file closing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
This makes |f| available to be opened again, if desired; and if |f| was used for
output, the |close| operation makes the corresponding external file appear
on the user's area, ready to be read.

@p procedure a_close(var @!f:alpha_file); {close a text file}
begin close(f);
end;
@#
procedure b_close(var @!f:byte_file); {close a binary file}
begin close(f);
end;
@#
procedure w_close(var @!f:word_file); {close a word file}
begin close(f);
end;
@y
This makes |f| available to be opened again, if desired; and if |f| was used for
output, the |close| operation makes the corresponding external file appear
on the user's area, ready to be read.

With the pc library, files will be automatically closed when the program stops
and when one reopens them.
There is however, the problem of opening a file and writing it, and then
wanting to read it again, but from a different file variable.
For this purpose we use external procedures |close_a|, |close_b|, and
|close_w|.
There should be an ``include'' statement above, to declare these external
procedures.


@p procedure a_close(var f:alpha_file); {close a text file}
begin close_a(f);
end;
@#
procedure w_close(var f:word_file); {close a word file}
begin close_w(f);
end;

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.30] fix bypass_eoln bug in input_ln()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
Standard \PASCAL\ says that a file should have |eoln| immediately
before |eof|, but \MF\ needs only a weaker restriction: If |eof|
occurs in the middle of a line, the system function |eoln| should return
a |true| result (even though |f^| will be undefined).

@p function input_ln(var @!f:alpha_file;@!bypass_eoln:boolean):boolean;
  {inputs the next line or returns |false|}
var @!last_nonblank:0..buf_size; {|last| with trailing blanks removed}
begin if bypass_eoln then if not eof(f) then get(f);
  {input the first character of the line into |f^|}
last:=first; {cf.\ Matthew 19\thinspace:\thinspace30}
@y
Standard \PASCAL\ says that a file should have |eoln| immediately
before |eof|, but \MF\ needs only a weaker restriction: If |eof|
occurs in the middle of a line, the system function |eoln| should return
a |true| result (even though |f^| will be undefined).

In Berkeley {\mc UNIX} Pascal, input from a terminal does not normally
insert a blank line, causing the |bypass_eoln| test below to (incorrectly)
skip over the first character of valid input.  But the mechanism used to
create pre-loaded bases leaves the file structures for the terminal input
file thinking |eoln(input)| is |true|.  Hence, the |bypass_eoln| test must
check whether to eliminate a blank line or not.

@p function input_ln(var @!f:alpha_file;@!bypass_eoln:boolean):boolean;
  {inputs the next line or returns |false|}
var @!last_nonblank:0..buf_size; {|last| with trailing blanks removed}
begin if bypass_eoln then if not eof(f) then if eoln(f) then get(f);
  {input the first character of the line into |f^|}
last:=first; {cf.\ Matthew 19\thinspace:\thinspace30}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.31] term_in/out are input,output
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The user's terminal acts essentially like other files of text, except
that it is used both for input and for output. When the terminal is
considered an input file, the file variable is called |term_in|, and when it
is considered an output file the file variable is |term_out|.
@^system dependencies@>

@<Glob...@>=
@!term_in:alpha_file; {the terminal as an input file}
@!term_out:alpha_file; {the terminal as an output file}
@y
@ The user's terminal acts essentially like other files of text, except
that it is used both for input and for output. When the terminal is
considered an input file, the file is called |term_in|, and when it
is considered an output file the file is |term_out|.
For Berkeley {\mc UNIX} we use |standard_input| and |output| for these
files, as were declared in the program header.   The former name
|standard_input| was defined using a web trick so that ``input'' is
produced in the Pascal file.

@d term_in==standard_input {the terminal as an input file}
@d term_out==output {the terminal as an output file}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.32] don't need to open terminal files
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ Here is how to open the terminal files
in \ph. The `\.{/I}' switch suppresses the first |get|.
@^system dependencies@>

@d t_open_in==reset(term_in,'TTY:','/O/I') {open the terminal for text input}
@d t_open_out==rewrite(term_out,'TTY:','/O') {open the terminal for text output}
@y
@ Here is how to open the terminal files
 ---do nothing.

@d t_open_in == {input already open for text input}
@d t_open_out == {output already open for text output}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.33] flushing output
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
these operations can be specified in \ph:
@^system dependencies@>

@d update_terminal == break(term_out) {empty the terminal output buffer}
@d clear_terminal == break_in(term_in,true) {clear the terminal input buffer}
@d wake_up_terminal == do_nothing {cancel the user's cancellation of output}
@y
these operations can be specified with Berkeley {\mc UNIX}.
@^system dependencies@>

@d update_terminal == flush(output)
@d clear_terminal == {nothing necessary on UNIX}
@d wake_up_terminal == {nothing necessary on UNIX}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.36] rescanning the command line 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The following program does the required initialization
without retrieving a possible command line.
It should be clear how to modify this routine to deal with command lines,
if the system permits them.
@^system dependencies@>

@p function init_terminal:boolean; {gets the terminal input started}
label exit;
begin t_open_in;
loop@+begin wake_up_terminal; write(term_out,'**'); update_terminal;
@.**@>
  if not input_ln(term_in,true) then {this shouldn't happen}
    begin write_ln(term_out);
    write(term_out,'! End of file on the terminal... why?');
@.End of file on the terminal@>
    init_terminal:=false; return;
    end;
  loc:=first;
  while (loc<last)and(buffer[loc]=" ") do incr(loc);
  if loc<last then
    begin init_terminal:=true;
    return; {return unless the line was all blank}
    end;
  write_ln(term_out,'Please type the name of your input file.');
  end;
exit:end;
@y
@ The following program does the required initialization
and also retrieves a possible command line.
@^system dependencies@>

@p
function init_terminal:boolean; {gets the terminal input started}
label exit;

var
    dummy, i, j, k: integer;
    arg: packed array[1..100] of char;

begin
    t_open_in;
    if argc > 1 then begin
        last := first;
        for i := 1 to argc - 1 do begin
	    argv(i, arg);
	    j := 1;
	    k := 100; {find last non-blank char in arg}
	    while (k > 1) and (arg[k] = ' ') do@/
		decr(k);
	    while (j <= k) do begin
	        buffer[last] := xord[arg[j]];
		incr(j); incr(last);
            end;
	    if k > 1 then begin
	        buffer[last] := xord[' '];
	        incr(last);
            end;
	end;
	if last > first then begin
	    loc := first;
            init_terminal := true;
            return;
	end;
    end;
    loop@+begin
        wake_up_terminal; write(term_out, '**'); update_terminal;
@.**@>
        if not input_ln(term_in,true) then begin {this shouldn't happen}
            write_ln(term_out);
            write_ln(term_out, '! End of file on the terminal... why?');
@.End of file on the terminal@>
            init_terminal:=false;
	    return;
        end;

        loc:=first;
        while (loc<last)and(buffer[loc]=" ") do
            incr(loc);

        if loc<last then begin
           init_terminal:=true;
           return; {return unless the line was all blank}
        end;
        write_ln(term_out, 'Please type the name of your input file.');
@.Please type the name...@>
    end;
exit:
end;
@z

% ADD-PYRAMID-KLUDGE-HERE % SENTINEL LINE --- DO NOT REMOVE %%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [4.51] a_open_in of pool file needs path specifier
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
if a_open_in(pool_file) then
@y
if a_open_in(pool_file,MF_pool_file_path) then
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [4.51,52,53] make MF.POOL lowercase in messages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
else  bad_pool('! I can''t read MF.POOL.')
@y
else  bad_pool('! I can''t read mf.pool.')
@z
@x
begin if eof(pool_file) then bad_pool('! MF.POOL has no check sum.');
@y
begin if eof(pool_file) then bad_pool('! mf.pool has no check sum.');
@z
@x
    bad_pool('! MF.POOL line doesn''t begin with two digits.');
@y
    bad_pool('! mf.pool line doesn''t begin with two digits.');
@z
@x
  bad_pool('! MF.POOL check sum doesn''t have nine digits.');
@y
  bad_pool('! mf.pool check sum doesn''t have nine digits.');
@z
@x
done: if a<>@$ then bad_pool('! MF.POOL doesn''t match; TANGLE me again.');
@y
done: if a<>@$ then bad_pool('! mf.pool doesn''t match; tangle me again.');
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [6.79] switch-to-editor option
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
line ready to be edited. But such an extension requires some system
wizardry, so the present implementation simply types out what file should be
edited and the relevant line number.
@^system dependencies@>

There is a secret `\.D' option available when the debugging routines have
not been commented out.
@^debugging@>
@y
line ready to be edited.
We do this by calling the external procedure |calledit| with a pointer to
the filename, its length, and the line number.
However, here we just set up the variables that will be used as arguments,
since we don't want to do the switch-to-editor until after TeX has closed
its files.
@^system dependencies@>

There is a secret `\.D' option available when the debugging routines have
not been commented out.
@^debugging@>
@d edit_file==input_stack[file_ptr]
@z
@x
"E": if file_ptr>0 then
  begin print_nl("You want to edit file ");
@.You want to edit file x@>
  print(input_stack[file_ptr].name_field);
  print(" at line "); print_int(line);
  interaction:=scroll_mode; jump_out;
@y
"E": if file_ptr>0 then
    begin
    edit_name_start:=str_start[edit_file.name_field];
    edit_name_length:=str_start[edit_file.name_field+1] -
    		      str_start[edit_file.name_field];
    edit_line:=line;
    jump_out;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [7.107,108] replace make_fraction with external routine
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@p function make_fraction(@!p,@!q:integer):fraction;
var @!f:integer; {the fraction bits, with a leading 1 bit}
@!n:integer; {the integer part of $\vert p/q\vert$}
@!negative:boolean; {should the result be negated?}
@!be_careful:integer; {disables certain compiler optimizations}
begin if p>=0 then negative:=false
else  begin negate(p); negative:=true;
  end;
if q<=0 then
  begin debug if q=0 then confusion("/");@;@+gubed@;@/
@:this can't happen /}{\quad \./@>
  negate(q); negative:=not negative;
  end;
n:=p div q; p:=p mod q;
if n>=8 then
  begin arith_error:=true;
  if negative then make_fraction:=-el_gordo@+else make_fraction:=el_gordo;
  end
else  begin n:=(n-1)*fraction_one;
  @<Compute $f=\lfloor 2^{28}(1+p/q)+{1\over2}\rfloor$@>;
  if negative then make_fraction:=-(f+n)@+else make_fraction:=f+n;
  end;
end;

@ The |repeat| loop here preserves the following invariant relations:
(i)~|0<=p<q|; (ii)~$fq+p=2^k(q+p_0)$, where $k$ is an integer and
$p_0$ is the original value of~$p$.

Notice that the computation specifies
|(p-q)+p| instead of |(p+p)-q|, because the latter could overflow.
Let us hope that optimizing compilers do not miss this point; a
special variable |be_careful| is used to emphasize the necessary
order of computation. Optimizing compilers should keep |be_careful|
in a register, not store it in memory.
@^inner loop@>

@<Compute $f=\lfloor 2^{28}(1+p/q)+{1\over2}\rfloor$@>=
f:=1;
repeat be_careful:=p-q; p:=be_careful+p;
if p>=0 then f:=f+f+1
else  begin double(f); p:=p+q;
  end;
until f>=fraction_one;
be_careful:=p-q;
if be_careful+p>=0 then incr(f)

@y
Under {\mc UNIX} \MF, we have replaced the \PASCAL\ version of |make_fraction|
with either a C or assembly language equivalent for efficiency.

@ This section was deleted when |make_fraction| was removed.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [7.109,110,111] replace take_fraction with external version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@p function take_fraction(@!q:integer;@!f:fraction):integer;
var @!p:integer; {the fraction so far}
@!negative:boolean; {should the result be negated?}
@!n:integer; {additional multiple of $q$}
@!be_careful:integer; {disables certain compiler optimizations}
begin @<Reduce to the case that |f>=0| and |q>0|@>;
if f<fraction_one then n:=0
else  begin n:=f div fraction_one; f:=f mod fraction_one;
  if q<=el_gordo div n then n:=n*q
  else  begin arith_error:=true; n:=el_gordo;
    end;
  end;
f:=f+fraction_one;
@<Compute $p=\lfloor qf/2^{28}+{1\over2}\rfloor-q$@>;
be_careful:=n-el_gordo;
if be_careful+p>0 then
  begin arith_error:=true; n:=el_gordo-p;
  end;
if negative then take_fraction:=-(n+p)
else take_fraction:=n+p;
end;

@ @<Reduce to the case that |f>=0| and |q>0|@>=
if f>=0 then negative:=false
else  begin negate(f); negative:=true;
  end;
if q<0 then
  begin negate(q); negative:=not negative;
  end;

@ The invariant relations in this case are (i)~$\lfloor(qf+p)/2^k\rfloor
=\lfloor qf_0/2^{28}+{1\over2}\rfloor$, where $k$ is an integer and
$f_0$ is the original value of~$f$; (ii)~$2^k\L f<2^{k+1}$.
@^inner loop@>

@<Compute $p=\lfloor qf/2^{28}+{1\over2}\rfloor-q$@>=
p:=fraction_half; {that's $2^{27}$; the invariants hold now with $k=28$}
if q<fraction_four then
  repeat if odd(f) then p:=half(p+q)@+else p:=half(p);
  f:=half(f);
  until f=1
else  repeat if odd(f) then p:=p+half(q-p)@+else p:=half(p);
  f:=half(f);
  until f=1

@y
Function |take_fraction| has also been replaced by an external routine.

@ @<Reduce to the case that |f>=0| and |q>0|@>=
if f>=0 then negative:=false
else  begin negate(f); negative:=true;
  end;
if q<0 then
  begin negate(q); negative:=not negative;
  end;

@ This section was deleted when |take_fraction| was replaced by an
external routine.

@z

% ADD-VAX-KLUDGE-HERE % SENTINEL LINE --- DO NOT REMOVE %%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [9.153] ranges for quarter,half words
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
can get 256 values into a quarterword only if the subrange is `|-128..127|'.

The present implementation tries to accommodate as many variations as possible,
so it makes rather general assumptions. If integers having the subrange
`|min_quarterword..max_quarterword|' can be packed into a quarterword,
and if integers having the subrange `|min_halfword..max_halfword|'
can be packed into a halfword, everything should work satisfactorily.

It is usually most efficient to have |min_quarterword=min_halfword=0|,
so one should try to achieve this unless it causes a severe problem.
The values defined here are recommended for most 32-bit computers.

@d min_quarterword=0 {smallest allowable value in a |quarterword|}
@d max_quarterword=255 {largest allowable value in a |quarterword|}
@d min_halfword==0 {smallest allowable value in a |halfword|}
@d max_halfword==65535 {largest allowable value in a |halfword|}
@y
can get 256 values into a quarterword only if the subrange is `|-128..127|'.

For Berkeley {\mc UNIX} we need to do the |-128..127| kind of range.

@d min_quarterword=-128 {smallest allowable value in a |quarterword|}
@d max_quarterword=127 {largest allowable value in a |quarterword|}
@d min_halfword==-32768 {smallest allowable value in a |halfword|}
@d max_halfword==32767 {largest allowable value in a |halfword|}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [11.178] fix the word "free" so that it doesn't conflict with a runtime proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
been included. (You may want to decrease the size of |mem| while you
@^debugging@>
are debugging.)
@y
been included. (You may want to decrease the size of |mem| while you
@^debugging@>
are debugging.)

@d free==free_arr
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [12.194] fix_date_and_time
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The following procedure, which is called just before \MF\ initializes its
input and output, establishes the initial values of the date and time.
@^system dependencies@>
Since standard \PASCAL\ cannot provide such information, something special
is needed. The program here simply specifies July 4, 1776, at noon; but
users probably want a better approximation to the truth.

Note that the values are |scaled| integers. Hence \MF\ can no longer
be used after the year 32767.

@p procedure fix_date_and_time;
begin internal[time]:=12*60*unity; {minutes since midnight}
internal[day]:=4*unity; {fourth day of the month}
internal[month]:=7*unity; {seventh month of the year}
internal[year]:=1776*unity; {Anno Domini}
end;
@y
@ The following procedure, which is called just before \MF\ initializes its
input and output, establishes the initial values of the date and time.
It is calls an externally defined |date_and_time|, even though it could
be done from Pascal.
The external procedure also sets up interrupt catching.
@^system dependencies@>

Note that the values are |scaled| integers. Hence \MF\ can no longer
be used after the year 32767.

@p procedure fix_date_and_time;
begin
    date_and_time(internal[time],internal[day],internal[month],internal[year]);
    internal[time] := internal[time] * unity;
    internal[day] := internal[day] * unity;
    internal[month] := internal[month] * unity;
    internal[year] := internal[year] * unity;
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [12.199] allow <tab> and <ff> as input
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
for k:=0 to " "-1 do char_class[k]:=invalid_class;
char_class[127]:=invalid_class;
@y
for k:=0 to " "-1 do char_class[k]:=invalid_class;
char_class[127]:=invalid_class;
char_class[tab]:=space_class;
char_class[form_feed]:=space_class;
@z

% ADD-WINDOW-CHANGES-HERE	%%% SENTINEL LINE -- DO NOT REMOVE %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.765] area and extension rules
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The file names we shall deal with for illustrative purposes have the
following structure:  If the name contains `\.>' or `\.:', the file area
consists of all characters up to and including the final such character;
otherwise the file area is null.  If the remaining file name contains
`\..', the file extension consists of all such characters from the first
remaining `\..' to the end, otherwise the file extension is null.
@^system dependencies@>

We can scan such file names easily by using two global variables that keep track
of the occurrences of area and extension delimiters:

@<Glob...@>=
@!area_delimiter:pool_pointer; {the most recent `\.>' or `\.:', if any}
@!ext_delimiter:pool_pointer; {the relevant `\..', if any}
@y
@ The file names we shall deal with for illustrative purposes have the
following structure:  If the name contains `\./', the file area
consists of all characters up to and including the final such character;
otherwise the file area is null.  If the remaining file name contains
`\..', the file extension consists of all such characters from the first
remaining `\..' to the end, otherwise the file extension is null.
@^system dependencies@>

We can scan such file names easily by using two global variables that keep
track of the occurrences of area and extension delimiters:

@<Glob...@>=
@!area_delimiter:pool_pointer; {the most recent `\./', if any}
@!ext_delimiter:pool_pointer; {the most recent `\..', if any}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.766] MF area directories
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d MF_area=="MFinputs:"
@.MFinputs@>
@y
Under Berkeley {\mc UNIX}, the default paths are specified in a seprate
file, ``mfpaths.h''.  The file opening procedures do path searching
based either on those default paths, or on paths given by the user
in ``environment'' variables.
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.768] more_name
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
begin if c=" " then more_name:=false
else  begin if (c=">")or(c=":") then
@y
begin if (c=" ")or(c=tab) then more_name:=false
else  begin if (c="/") then
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.772] default base
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d base_default_length=18 {length of the |MF_base_default| string}
@d base_area_length=8 {length of its area part}
@d base_ext_length=5 {length of its `\.{.base}' part}
@y
Under Berkeley {\mc UNIX} we don't give the area part, instead depending
on the path searching that will happen during file opening.

@d base_default_length=10 {length of the |MF_base_default| string}
@d base_area_length=0 {length of its area part}
@d base_ext_length=5 {length of its `\.{.base}' part}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.773] plain base location
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
MF_base_default:='MFbases:plain.base';
@y
MF_base_default:='plain.base';
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.776] w_open_in of base file needs to be called only once
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
  pack_buffered_name(0,loc,j-1); {try first without the system file area}
  if w_open_in(base_file) then goto found;
  pack_buffered_name(base_area_length,loc,j-1);
    {now try the system base file area}
  if w_open_in(base_file) then goto found;
@y
  pack_buffered_name(0,loc,j-1);
  if w_open_in(base_file) then goto found;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.777] make_name_string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
which simply makes a \MF\ string from the value of |name_of_file|, should
ideally be changed to deduce the full name of file~|f|, which is the file
most recently opened, if it is possible to do this in a \PASCAL\ program.
@^system dependencies@>

This routine might be called after string memory has overflowed, hence
we dare not use `|str_room|'.

@p function make_name_string:str_number;
var @!k:1..file_name_size; {index into |name_of_file|}
begin if (pool_ptr+name_length>pool_size)or(str_ptr=max_strings) then
  make_name_string:="?"
else  begin for k:=1 to name_length do append_char(xord[name_of_file[k]]);
  make_name_string:=make_string;
  end;
end;
@y
which simply makes a \MF\ string from the value of |name_of_file|, should
ideally be changed to deduce the full name of file~|f|, which is the file
most recently opened, if it is possible to do this in a \PASCAL\ program.
With the Berkeley {\mc UNIX} version, we know that |real_name_of_file|
contains |name_of_file| prepended with the directory name that was found
by path searching.
If |real_name_of_file| starts with |'./'|, we don't use that part of the
name, since {\mc UNIX} users understand that.
@^system dependencies@>

This routine might be called after string memory has overflowed, hence
we dare not use `|str_room|'.

@p function make_name_string:str_number;
var @!k,@!kstart:1..file_name_size; {index into |name_of_file|}
begin
k:=1;
while (k<file_name_size) and (xord[real_name_of_file[k]]<>" ") do
    incr(k);
name_length:=k-1; {the real |name_length|}
if (pool_ptr+name_length>pool_size)or(str_ptr=max_strings) then
  make_name_string:="?"
else  begin
  if (xord[real_name_of_file[1]]=".") and (xord[real_name_of_file[2]]="/") then
    kstart:=3
  else
    kstart:=1;
  for k:=kstart to name_length do append_char(xord[real_name_of_file[k]]);
  make_name_string:=make_string;
  end;
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.780] change b_make_name_string to retrieve file name to
%		real_name_of_file for make_name_string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
function b_make_name_string(var @!f:byte_file):str_number;
begin b_make_name_string:=make_name_string;
end;
@y
function b_make_name_string(var @!f:byte_file):str_number;
begin b_get_name(f, real_name_of_file);@/
b_make_name_string:=make_name_string;
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.778] scan_file_name ignore leading tabs as well as spaces
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@p procedure scan_file_name;
label done;
begin begin_name;
while buffer[loc]=" " do incr(loc);
@y
@p procedure scan_file_name;
label done;
begin begin_name;
while (buffer[loc]=" ")or(buffer[loc]=tab) do incr(loc);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.783] <scan_file_name...> needs similar leading tab treatment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ @<Scan file name in the buffer@>=
begin begin_name; k:=first;
while (buffer[k]=" ")and(k<last) do incr(k);
@y
@ @<Scan file name in the buffer@>=
begin begin_name; k:=first;
while ((buffer[k]=" ")or(buffer[k]=tab))and(k<last) do incr(k);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.791] add file name to b_open_out() calls in set_output_file_name
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
  pack_job_name(gf_ext);
  while not b_open_out(gf_file) do
    prompt_file_name("file name for output",gf_ext);
@y
  pack_job_name(gf_ext);
  while not b_open_out(gf_file, name_of_file) do
    prompt_file_name("file name for output",gf_ext);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.789] a_open_in of input file needs path selector
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
  if a_open_in(cur_file) then goto done;
  pack_file_name(cur_name,MF_area,cur_ext);
  if a_open_in(cur_file) then goto done;
@y
  if a_open_in(cur_file,MF_input_file_path) then goto done;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.789] get rid of return of name to string pool
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
if name=str_ptr-1 then {we can conserve string pool space now}
  begin flush_string(name); name:=cur_name;
  end;
@y
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [45.1128] writing the tfm file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d tfm_out(#)==write(tfm_file,#) {output one byte to |tfm_file|}

@p procedure tfm_two(@!x:integer); {output two bytes to |tfm_file|}
begin tfm_out(x div 256); tfm_out(x mod 256);
end;
@#
procedure tfm_four(@!x:integer); {output four bytes to |tfm_file|}
begin if x>=0 then tfm_out(x div three_bytes)
else  begin x:=x+@'10000000000; {use two's complement for negative values}
  x:=x+@'10000000000;
  tfm_out((x div three_bytes) + 128);
  end;
x:=x mod three_bytes; tfm_out(x div unity);
x:=x mod unity; tfm_out(x div @'400);
tfm_out(x mod @'400);
end;
@#
procedure tfm_qqqq(@!x:four_quarters); {output four quarterwords to |tfm_file|}
begin tfm_out(qo(x.b0)); tfm_out(qo(x.b1)); tfm_out(qo(x.b2));
tfm_out(qo(x.b3));
end;
@y
Under {\mc UNIX}, we are using the binary input and output routines.
Hence, we redefine all the {\mc TFM} input and output in terms of those
routines.

@d tfm_out(#) == b_write_byte(tfm_file, #)
@d tfm_two(#) == b_write_2_bytes(tfm_file, #)
@d tfm_four(#) == b_write_4_bytes(tfm_file, #)

@p procedure tfm_qqqq(@!x:four_quarters); {output four quarterwords to |tfm_file|}
begin tfm_out(qo(x.b0)); tfm_out(qo(x.b1)); tfm_out(qo(x.b2));
tfm_out(qo(x.b3));
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [45.1134] add file name to b_open_out call in <finish the tfm file>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
pack_job_name(".tfm");
while not b_open_out(tfm_file) do
@y
pack_job_name(".tfm");
while not b_open_out(tfm_file, name_of_file) do
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [47.1151] add gf_buf_type type definition so we can pass it to
%		b_write_buf()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@!gf_index=0..gf_buf_size; {an index into the output buffer}
@y
@!gf_index=0..gf_buf_size; {an index into the output buffer}
@!gf_buf_type = array[gf_index] of eight_bits; {type declared for ext procs}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [47.1152] and redefine gf_buf[] in terms of gf_buf_type
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@!gf_buf:array[gf_index] of eight_bits; {buffer for \.{GF} output}
@y
@!gf_buf:gf_buf_type; {buffer for \.{GF} output}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [47.1148] write_gf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@<Declare generic font output procedures@>=
procedure write_gf(@!a,@!b:gf_index);
var k:gf_index;
begin for k:=a to b do write(gf_file,gf_buf[k]);
end;
@y
For Berkeley {\mc UNIX}, this is going to be handled by an external procedure,
|b_write_buf|, which will do the output using |fwrite|.

@d write_gf(#) == b_write_buf(gf_file, gf_buf, #)
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [49.1197] Add call to exit() depending upon value of `history'
%           Also, add call to set_paths
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ Now this is really it: \MF\ starts and ends here.

The initial test involving |ready_already| should be deleted if the
\PASCAL\ runtime system is smart enough to detect such a ``mistake.''
@y
@ Now this is really it: \MF\ starts and ends here.

Use the value of |history| to determine what exit-code to use.  We use
1 if |history <> spotless| and 0 otherwise.

@d UNIXexit==e@&x@&i@&t
@z

@x
t_open_out; {open the terminal for output}
@y
t_open_out; {open the terminal for output}
set_paths;
@z

@x
final_end: ready_already:=0;
@y
final_end: ready_already:=0;
if (history <> spotless) and (history <> warning_issued) then
    UNIXexit(1)
else
    UNIXexit(0);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [49.1198] print new line before termination; switch to editor if nec.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
    print(log_name); print_char(".");
    end;
  end;
@y
    print(log_name); print_char(".");
    end;
  end;
print_ln;
if (edit_name_start<>0) and (interaction>batch_mode) then
    calledit(str_pool[edit_name_start],edit_name_length,edit_line);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [51.1207,1208] add editor-switch variable to globals
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@* \[51] System-dependent changes.
This section should be replaced, if necessary, by changes to the program
that are necessary to make \MF\ work at a particular installation.
It is usually best to design your change file so that all changes to
previous sections preserve the section numbering; then everybody's version
will be consistent with the published program. More extensive changes,
which introduce new sections, can be inserted here; then only the index
itself will get a new section number.
@^system dependencies@>
@y
@* \[51] System-dependent changes.
Here are the variables used to hold ``switch-to-editor'' information.
@^system dependencies@>

@<Global...@>=
@!edit_name_start: pool_pointer;
@!edit_name_length,@!edit_line: integer;

@ The |edit_name_start| will be set to point into |str_pool| somewhere after
its beginning if \MF\ is supposed to switch to an editor on exit.

@<Set init...@>=
edit_name_start:=0;
@z

SHAR_EOF
cat << \SHAR_EOF > mf84/dist_inimf.SYS_V.ch
% $Header: dist_inimf.ch,v 1.3 87/03/06 21:15:21 mackay Released $

% Change file for 4.2 BSD UNIX, for use with the pxp Pascal preprocessor
% (that accepts an others: clause in case statements).
%
% Derived from INITEX.CH for Berkeley Unix TeX 1.1, by Howard Trickey
%   and Pavel Curtis

% Modification History:
%
% $Log:	dist_inimf.ch,v $
% Revision 1.3  87/03/07  21:15:21  mackay
%
%	Minor changes found on archive version on SCORE
%	(max_in_open increased to 10. --  88/02/07 PAM)
%
% Revision 1.2  86/09/29  21:46:43  mackay
%
%	Made no-debug the default, and changed version number
%	to correspond with improved mf.web file
%	(Got rid of debug code to avoid bug in range check
%	code of VAX4.3 BSD and SUN3 version 3.1 Os pc interpreter)
%
% Revision 1.0  86/01/31  15:46:08  richards
% Released for MF 1.0;
% 
% 	Incorporates: New binary I/O library, seperate optimized
% 	arithmetic for takefraction/makefraction, new graphics interface
% 
% Revision 0.999999.1.2  86/01/28  19:49:38  richards
% Added:
% 	variable "dummy" to routine initterm() because SUN PC compiler
% 	loops with only i,j,k defined. Argh!
% 
% Revision 0.999999.1.1  86/01/21  23:05:16  richards
% First cut for MF 1.0
% 
% Revision 0.999999  86/01/13  00:40:25  richards
% Released for 0.999999:
% 	added OTHERCASES sentinel
% 	revised WINDOW interface and include files
% 
% Revision 0.99999  85/12/09  20:23:35  richards
% Version for 0.99999
% 
% Revision 0.9999  85/10/21  20:48:24  richards
% Released for MF version 0.9999
% 
% Revision 0.999  85/10/18  21:33:44  richards
% Version that works with 0.999 MF (Never released)
% 
% Revision 0.91  85/05/16  10:58:13  richards
% Released for MF version 0.91
% 
% Revision 0.81  85/05/05  12:24:08  richards
% Released for MF version 0.81
% 
% Revision 0.77  85/03/11  20:23:37  richards
% Released for MF version 0.77
% 
% Revision 0.6.1.1  85/02/12  20:12:32  richards
% First edit for 0.76
% 
% Revision 0.6  85/02/08  00:52:40  richards
% Distribution version for MF 0.6
% 
% Revision 0.0.2.1  84/12/06  03:43:33  richards
% Edited to work with 0.4 -- still needs to have section numbers re-done
% 	before release.
% 
% Revision 0.0  84/11/05  00:50:38  richards
% Base version (first cut) for MetaFont 0.0
% 
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [0] WEAVE: only print changes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
\def\botofcontents{\vskip 0pt plus 1fil minus 1.5in}
@y
\def\botofcontents{\vskip 0pt plus 1fil minus 1.5in}
\let\maybe=\iffalse
\def\title{{\logo opqrstuq} changes for System V {\mc UNIX}}
\def\glob{13}\def\gglob{20, 25} % these are defined in module 1
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.2] banner line
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d banner=='This is METAFONT, Version 1.3' {printed when \MF\ starts}
@y
@d banner=='This is METAFONT, Version 1.3 for System V UNIX'
                                                 {printed when \MF\ starts}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.4] program header, include mf_ext.h for C routine linkage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
Actually the heading shown here is not quite normal: The |program| line
does not mention any |output| file, because \ph\ would ask the \MF\ user
to specify a file name if |output| were specified here.
@^system dependencies@>

@d mtype==t@&y@&p@&e {this is a \.{WEB} coding trick:}
@y
@d mtype==t@&y@&p@&e {this is a \.{WEB} coding trick:}
@d standard_input==i@&n@&p@&u@&t {and another}
@z
@x
program MF; {all file names are defined dynamically}
@y
program MF(standard_input,output); {other file names are defined dynamically}
@z
@x
var @<Global variables@>@/
@y
var @<Global variables@>@/
@#
@\@=#include "mf_ext.h"@>@\ {declarations for external C procedures}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.7] debug..gubed, stat..tats
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% @x
% @d debug==@{ {change this to `$\\{debug}\equiv\null$' when debugging}
% @d gubed==@t@>@} {change this to `$\\{gubed}\equiv\null$' when debugging}
% @y
% @d debug==
% @d gubed==
% @z
% All removed to avoid bug in pc for VAX 4.3 and SUN2/3 Version 3.1 Os.
@x
@d stat==@{ {change this to `$\\{stat}\equiv\null$' when gathering
  usage statistics}
@d tats==@t@>@} {change this to `$\\{tats}\equiv\null$' when gathering
  usage statistics}
@y
@d stat==
@d tats==
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.8] init..tini
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d init== {change this to `$\\{init}\equiv\.{@@\{}$' in the production version}
@d tini== {change this to `$\\{tini}\equiv\.{@@\}}$' in the production version}
@y
@d init==
@d tini==
@z

% ADD-OTHERCASES-CHANGES-HERE	%%% SENTINEL LINE -- DO NOT REMOVE %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.11] compile-time constants, use logical names
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x %% mem_max %% NEEDED FOR ini_to_vir
@!mem_max=30000; {greatest index in \MF's internal |mem| array;
  must be strictly less than |max_halfword|;
  must be equal to |mem_top| in \.{INIMF}, otherwise |>=mem_top|}
@y
@!mem_max=30000; {greatest index in \MF's internal |mem| array;
  must be strictly less than |max_halfword|;
  must be equal to |mem_top| in \.{INIMF}, otherwise |>=mem_top|}
@z
@x %% error_line half_error_line max_print_line %%
@!error_line=72; {width of context lines on terminal error messages}
@!half_error_line=42; {width of first lines of contexts in terminal
  error messages; should be between 30 and |error_line-15|}
@!max_print_line=79; {width of longest text lines output; should be at least 60}
@y
@!error_line=79; {width of context lines on terminal error messages}
@!half_error_line=50; {width of first lines of contexts in terminal
  error messages; should be between 30 and |error_line-15|}
@!max_print_line=79; {width of longest text lines output; should be at least 60}
@z
@x %% screen_width screen_depth %%
@!screen_width=768; {number of pixels in each row of screen display}
@!screen_depth=1024; {number of pixels in each column of screen display}
@y
@!screen_width=1024; {number of pixels in each row of screen display}
@!screen_depth=1024; {number of pixels in each column of screen display}
@z
@x %% gf_buf_size file_name_size pool_name %%
@!gf_buf_size=800; {size of the output buffer, must be a multiple of 8}
@!file_name_size=40; {file names shouldn't be longer than this}
@!pool_name='MFbases:MF.POOL                         ';
  {string of length |file_name_size|; tells where the string pool appears}
@y
@!gf_buf_size=800; {size of the output buffer, must be a multiple of 8}
@!file_name_size=256; {file names shouldn't be longer than this}
@!pool_name='mf.pool';
  {string of length |file_name_size|; tells where the string pool appears}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.12] sensitive compile-time constants
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d mem_min=0 {smallest index in the |mem| array, must not be less
  than |min_halfword|}
@d mem_top==30000 {largest index in the |mem| array dumped by \.{INIMF};
  must be substantially larger than |mem_min|
  and not greater than |mem_max|}
@d hash_size=2100 {maximum number of symbolic tokens,
  must be less than |max_halfword-3*param_size|}
@d hash_prime=1777 {a prime number equal to about 85\% of |hash_size|}
@d max_in_open=6 {maximum number of input files and error insertions that
  can be going on simultaneously}
@d param_size=150 {maximum number of simultaneous macro parameters}
@y
@d mem_min=-30000 {smallest index in the |mem| array, must not be less
  than |min_halfword|}
@d mem_top==30000 {largest index in the |mem| array dumped by \.{INIMF};
  must be substantially larger than |mem_min|
  and not greater than |mem_max|}
@d hash_size=2100 {maximum number of symbolic tokens,
  must be less than |max_halfword-3*param_size|}
@d hash_prime=1777 {a prime number equal to about 85\% of |hash_size|}
@d max_in_open=10 {maximum number of input files and error insertions that
  can be going on simultaneously. Enlarged for Silvio Levy's Greek}
@d param_size=150 {maximum number of simultaneous macro parameters}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.22] accept <tab> and <ff> as valid input chars
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@^character set dependencies@>
@^system dependencies@>

@<Set init...@>=
for i:=1 to @'37 do xchr[i]:=' ';

@y
@^character set dependencies@>
@^system dependencies@>

@d tab = @'11 { ASCII horizontal tab }
@d form_feed = @'14 { ASCII form-feed }

@<Set init...@>=
for i:=1 to @'37 do xchr[i]:=' ';
xchr[tab]:=chr(tab);
xchr[form_feed]:=chr(form_feed);

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.24] file types
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The program actually makes use also of a third kind of file, called a
@y
Not all Pascal compilers available under the various implementations
of {\mc UNIX} produce programs that are able to read and write binary
data in reasonable ways, so we resort to using an external library to
do the reading and writing for us.  We still use a variable of type
|byte_file| to indicate to those routines which file we wish to manipulate,
but |byte_file| no longer is a Pascal file type.  Instead, we redefine
it to be a special record (a ``magic cookie'', if you will) that has
enough information to maintain the file state.

The program actually makes use also of a third kind of file, called a
@z
@x
@!alpha_file=packed file of text_char; {files that contain textual data}
@!byte_file=packed file of eight_bits; {files that contain binary data}
@y
@!alpha_file=t@&e@&x@&t; {files that contain textual data}
@!UNIX_file_name=packed array [1..file_name_size] of char; {for file names}
@!byte_file=record@/
stdio_ptr: ^integer; {pointer for stdio FILE struct}
loc_ptr: ^integer; {pointer to byte position ptr to keep in sync with file}
file_name: UNIX_file_name; {file name saved by open routines}
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.25] add real_name_of_file array for search path resolution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
is crucial for our purposes. We shall assume that |name_of_file| is a variable
of an appropriate type such that the \PASCAL\ run-time system being used to
implement \MF\ can open a file whose external name is specified by
|name_of_file|.
@^system dependencies@>

@<Glob...@>=
@!name_of_file:packed array[1..file_name_size] of char;@;@/
  {on some systems this may be a \&{record} variable}
@!name_length:0..file_name_size;@/{this many characters are actually
  relevant in |name_of_file| (the rest are blank)}
@y
is crucial for our purposes. We shall assume that |name_of_file| is a variable
of an appropriate type such that the \PASCAL\ run-time system being used to
implement \MF\ can open a file whose external name is specified by
|name_of_file|.
The System V {\mc UNIX} version uses search paths to look for files to open.
We use |real_name_of_file| to hold the |name_of_file| with a directory
name from the path in front of it.
@^system dependencies@>

@<Glob...@>=
@!name_of_file,@!real_name_of_file:UNIX_file_name;
@;@/
@!name_length:0..file_name_size;@/{this many characters are actually
  relevant in |name_of_file| (the rest are blank)}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.26] file opening
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The \ph\ compiler with which the present version of \MF\ was prepared has
extended the rules of \PASCAL\ in a very convenient way. To open file~|f|,
we can write
$$\vbox{\halign{#\hfil\qquad&#\hfil\cr
|reset(f,@t\\{name}@>,'/O')|&for input;\cr
|rewrite(f,@t\\{name}@>,'/O')|&for output.\cr}}$$
The `\\{name}' parameter, which is of type `\ignorespaces|packed
array[@t\<\\{any}>@>] of text_char|', stands for the name of
the external file that is being opened for input or output.
Blank spaces that might appear in \\{name} are ignored.

The `\.{/O}' parameter tells the operating system not to issue its own
error messages if something goes wrong. If a file of the specified name
cannot be found, or if such a file cannot be opened for some other reason
(e.g., someone may already be trying to write the same file), we will have
|@!erstat(f)<>0| after an unsuccessful |reset| or |rewrite|.  This allows
\MF\ to undertake appropriate corrective action.
@:PASCAL H}{\ph@>
@^system dependencies@>

\MF's file-opening procedures return |false| if no file identified by
|name_of_file| could be opened.

@d reset_OK(#)==erstat(#)=0
@d rewrite_OK(#)==erstat(#)=0

@p function a_open_in(var @!f:alpha_file):boolean;
  {open a text file for input}
begin reset(f,name_of_file,'/O'); a_open_in:=reset_OK(f);
end;
@#
function a_open_out(var @!f:alpha_file):boolean;
  {open a text file for output}
begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f);
end;
@#
function b_open_out(var @!f:byte_file):boolean;
  {open a binary file for output}
begin rewrite(f,name_of_file,'/O'); b_open_out:=rewrite_OK(f);
end;
@#
function w_open_in(var @!f:word_file):boolean;
  {open a word file for input}
begin reset(f,name_of_file,'/O'); w_open_in:=reset_OK(f);
end;
@#
function w_open_out(var @!f:word_file):boolean;
  {open a word file for output}
begin rewrite(f,name_of_file,'/O'); w_open_out:=rewrite_OK(f);
end;
@y
@ The \ph\ compiler with which the present version of \MF\ was prepared has
extended the rules of \PASCAL\ in a very convenient way for file opening.
System V {\mc UNIX} \PASCAL\ isn't nearly as nice as \ph.
Normally, it bombs out if a file open fails.
An external C procedure, |test_access| is used to check whether or not the
open will work.  It is declared in the `mf_ext.h' include file, and it returns
|true| or |false|. The |name_of_file| global holds the file name whose access
is to be tested.
The first parameter for |test_access| is the access mode,
one of |read_access_mode| or |write_access_mode|.

We also implement path searching in |test_access|:  its second parameter is
one of the ``file path'' constants defined below.  If |name_of_file|
doesn't start with |'/'| then |test_access| tries prepending pathnames
from the appropriate path list until success or the end of path list
is reached.
On return, |real_name_of_file| contains the original name with the path
that succeeded (if any) prepended.  It is the name used in the various
open procedures.

The binary input and output routines are slightly different, as they
implement path searching directly, and don't need an assistant to
help.  Because the arguments to |b_open_in| and |b_open_out| were
designed to correspond to what \MF\ expects, we omit their definition
herewith entirely.

Note that |a_open_in| has been redefined to take an additional argument,
which should be one of the ``file path'' specifiers.
Path searching is not done for output files.

@d read_access_mode=4  {``read'' mode for |test_access|}
@d write_access_mode=2 {``write'' mode for |test_access|}

@d no_file_path=0    {no path searching should be done}
@d MF_input_file_path=6 {path specifier for \.{input} files}
@d MF_base_file_path=7 {path specifier for base files}
@d MF_pool_file_path=8  {path specifier for the pool file}

@p function a_open_in(var @!f:alpha_file;@!path_specifier:integer):boolean;
  {open a text file for input}
var @!ok:boolean;
begin
if test_access(name_of_file, real_name_of_file,
		read_access_mode,path_specifier) then
    begin reset(f,real_name_of_file); ok:=true@+end
else
    ok:=false;
a_open_in:=ok;
end;
@#
function a_open_out(var @!f:alpha_file):boolean;
  {open a text file for output}
var @!ok:boolean;
begin
if test_access(name_of_file, real_name_of_file,
		write_access_mode,no_file_path) then
    begin rewrite(f,real_name_of_file); ok:=true @+end
else ok:=false;
a_open_out:=ok;
end;
@#
function w_open_in(var @!f:word_file):boolean;
  {open a word file for input}
var @!ok:boolean;
begin
if test_access(name_of_file, real_name_of_file,
		read_access_mode,MF_base_file_path) then
    begin reset(f,real_name_of_file); ok:=true @+end
else ok:=false;
w_open_in:=ok;
end;
@#
function w_open_out(var @!f:word_file):boolean;
  {open a word file for output}
var @!ok:boolean;
begin
if test_access(name_of_file, real_name_of_file,
		write_access_mode,no_file_path) then
    begin rewrite(f,name_of_file); ok:=true @+end
else ok:=false;
w_open_out:=ok;
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.27] file closing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
This makes |f| available to be opened again, if desired; and if |f| was used for
output, the |close| operation makes the corresponding external file appear
on the user's area, ready to be read.

@p procedure a_close(var @!f:alpha_file); {close a text file}
begin close(f);
end;
@#
procedure b_close(var @!f:byte_file); {close a binary file}
begin close(f);
end;
@#
procedure w_close(var @!f:word_file); {close a word file}
begin close(f);
end;
@y
This makes |f| available to be opened again, if desired; and if |f| was used for
output, the |close| operation makes the corresponding external file appear
on the user's area, ready to be read.

With the pc library, files will be automatically closed when the program stops
and when one reopens them.
There is however, the problem of opening a file and writing it, and then
wanting to read it again, but from a different file variable.
For this purpose we use external procedures |close_a|, |close_b|, and
|close_w|.
There should be an ``include'' statement above, to declare these external
procedures.


@p procedure a_close(var f:alpha_file); {close a text file}
begin close_a(f);
end;
@#
procedure w_close(var f:word_file); {close a word file}
begin close_w(f);
end;

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.30] fix bypass_eoln bug in input_ln()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
Standard \PASCAL\ says that a file should have |eoln| immediately
before |eof|, but \MF\ needs only a weaker restriction: If |eof|
occurs in the middle of a line, the system function |eoln| should return
a |true| result (even though |f^| will be undefined).

@p function input_ln(var @!f:alpha_file;@!bypass_eoln:boolean):boolean;
  {inputs the next line or returns |false|}
var @!last_nonblank:0..buf_size; {|last| with trailing blanks removed}
begin if bypass_eoln then if not eof(f) then get(f);
  {input the first character of the line into |f^|}
last:=first; {cf.\ Matthew 19\thinspace:\thinspace30}
@y
Standard \PASCAL\ says that a file should have |eoln| immediately
before |eof|, but \MF\ needs only a weaker restriction: If |eof|
occurs in the middle of a line, the system function |eoln| should return
a |true| result (even though |f^| will be undefined).

In System V {\mc UNIX} Pascal, input from a terminal does not normally
insert a blank line, causing the |bypass_eoln| test below to (incorrectly)
skip over the first character of valid input.  But the mechanism used to
create pre-loaded bases leaves the file structures for the terminal input
file thinking |eoln(input)| is |true|.  Hence, the |bypass_eoln| test must
check whether to eliminate a blank line or not.

@p function input_ln(var @!f:alpha_file;@!bypass_eoln:boolean):boolean;
  {inputs the next line or returns |false|}
var @!last_nonblank:0..buf_size; {|last| with trailing blanks removed}
begin if bypass_eoln then if not eof(f) then if eoln(f) then get(f);
  {input the first character of the line into |f^|}
last:=first; {cf.\ Matthew 19\thinspace:\thinspace30}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.31] term_in/out are input,output
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The user's terminal acts essentially like other files of text, except
that it is used both for input and for output. When the terminal is
considered an input file, the file variable is called |term_in|, and when it
is considered an output file the file variable is |term_out|.
@^system dependencies@>

@<Glob...@>=
@!term_in:alpha_file; {the terminal as an input file}
@!term_out:alpha_file; {the terminal as an output file}
@y
@ The user's terminal acts essentially like other files of text, except
that it is used both for input and for output. When the terminal is
considered an input file, the file is called |term_in|, and when it
is considered an output file the file is |term_out|.
For System V {\mc UNIX} we use |standard_input| and |output| for these
files, as were declared in the program header.   The former name
|standard_input| was defined using a web trick so that ``input'' is
produced in the Pascal file.

@d term_in==standard_input {the terminal as an input file}
@d term_out==output {the terminal as an output file}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.32] don't need to open terminal files
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ Here is how to open the terminal files
in \ph. The `\.{/I}' switch suppresses the first |get|.
@^system dependencies@>

@d t_open_in==reset(term_in,'TTY:','/O/I') {open the terminal for text input}
@d t_open_out==rewrite(term_out,'TTY:','/O') {open the terminal for text output}
@y
@ Here is how to open the terminal files
 ---do nothing.

@d t_open_in == {input already open for text input}
@d t_open_out == {output already open for text output}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.33] flushing output
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
these operations can be specified in \ph:
@^system dependencies@>

@d update_terminal == break(term_out) {empty the terminal output buffer}
@d clear_terminal == break_in(term_in,true) {clear the terminal input buffer}
@d wake_up_terminal == do_nothing {cancel the user's cancellation of output}
@y
these operations can be specified with Berkeley {\mc UNIX}.
@^system dependencies@>

@d update_terminal == flush(output)
@d clear_terminal == {nothing necessary on UNIX}
@d wake_up_terminal == {nothing necessary on UNIX}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [3.36] rescanning the command line 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The following program does the required initialization
without retrieving a possible command line.
It should be clear how to modify this routine to deal with command lines,
if the system permits them.
@^system dependencies@>

@p function init_terminal:boolean; {gets the terminal input started}
label exit;
begin t_open_in;
loop@+begin wake_up_terminal; write(term_out,'**'); update_terminal;
@.**@>
  if not input_ln(term_in,true) then {this shouldn't happen}
    begin write_ln(term_out);
    write(term_out,'! End of file on the terminal... why?');
@.End of file on the terminal@>
    init_terminal:=false; return;
    end;
  loc:=first;
  while (loc<last)and(buffer[loc]=" ") do incr(loc);
  if loc<last then
    begin init_terminal:=true;
    return; {return unless the line was all blank}
    end;
  write_ln(term_out,'Please type the name of your input file.');
  end;
exit:end;
@y
@ The following program does the required initialization
and also retrieves a possible command line.
@^system dependencies@>

@p
function init_terminal:boolean; {gets the terminal input started}
label exit;

var
    dummy, i, j, k: integer;
    arg: packed array[1..100] of char;

begin
    t_open_in;
    if argc > 1 then begin
        last := first;
        for i := 2 to argc do begin
	    argv(i, arg);
	    j := 1;
	    k := 100; {find last non-blank char in arg}
	    while (k > 1) and (arg[k] = ' ') do@/
		decr(k);
	    while (j <= k) do begin
	        buffer[last] := xord[arg[j]];
		incr(j); incr(last);
            end;
	    if k > 1 then begin
	        buffer[last] := xord[' '];
	        incr(last);
            end;
	end;
	if last > first then begin
	    loc := first;
            init_terminal := true;
            return;
	end;
    end;
    loop@+begin
        wake_up_terminal; write(term_out, '**'); update_terminal;
@.**@>
        if not input_ln(term_in,true) then begin {this shouldn't happen}
            write_ln(term_out);
            write_ln(term_out, '! End of file on the terminal... why?');
@.End of file on the terminal@>
            init_terminal:=false;
	    return;
        end;

        loc:=first;
        while (loc<last)and(buffer[loc]=" ") do
            incr(loc);

        if loc<last then begin
           init_terminal:=true;
           return; {return unless the line was all blank}
        end;
        write_ln(term_out, 'Please type the name of your input file.');
@.Please type the name...@>
    end;
exit:
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [4.51] a_open_in of pool file needs path specifier
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
if a_open_in(pool_file) then
@y
if a_open_in(pool_file,MF_pool_file_path) then
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [4.51,52,53] make MF.POOL lowercase in messages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
else  bad_pool('! I can''t read MF.POOL.')
@y
else  bad_pool('! I can''t read mf.pool.')
@z
@x
begin if eof(pool_file) then bad_pool('! MF.POOL has no check sum.');
@y
begin if eof(pool_file) then bad_pool('! mf.pool has no check sum.');
@z
@x
    bad_pool('! MF.POOL line doesn''t begin with two digits.');
@y
    bad_pool('! mf.pool line doesn''t begin with two digits.');
@z
@x
  bad_pool('! MF.POOL check sum doesn''t have nine digits.');
@y
  bad_pool('! mf.pool check sum doesn''t have nine digits.');
@z
@x
done: if a<>@$ then bad_pool('! MF.POOL doesn''t match; TANGLE me again.');
@y
done: if a<>@$ then bad_pool('! mf.pool doesn''t match; tangle me again.');
@z

% eliminate non-local goto
@x
procedure that quietly terminates the program.

@<Error hand...@>=
procedure jump_out;
begin goto end_of_MF;
end;
@y
procedure that quietly terminates the program.

Use the value of |history| to determine what exit-code to use.  We use
1 if |history <> spotless| and 0 otherwise.

@d UNIXexit==e@&x@&i@&t

@<Error hand...@>=
procedure jump_out;
begin
close_files_and_terminate;
ready_already:=0;
if (history <> spotless) and (history <> warning_issued) then
    UNIXexit(1)
else
    UNIXexit(0);
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [6.79] switch-to-editor option
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
line ready to be edited. But such an extension requires some system
wizardry, so the present implementation simply types out what file should be
edited and the relevant line number.
@^system dependencies@>

There is a secret `\.D' option available when the debugging routines have
not been commented out.
@^debugging@>
@y
line ready to be edited.
We do this by calling the external procedure |calledit| with a pointer to
the filename, its length, and the line number.
However, here we just set up the variables that will be used as arguments,
since we don't want to do the switch-to-editor until after TeX has closed
its files.
@^system dependencies@>

There is a secret `\.D' option available when the debugging routines have
not been commented out.
@^debugging@>
@d edit_file==input_stack[file_ptr]
@z
@x
"E": if file_ptr>0 then
  begin print_nl("You want to edit file ");
@.You want to edit file x@>
  print(input_stack[file_ptr].name_field);
  print(" at line "); print_int(line);
  interaction:=scroll_mode; jump_out;
@y
"E": if file_ptr>0 then
    begin
    edit_name_start:=str_start[edit_file.name_field];
    edit_name_length:=str_start[edit_file.name_field+1] -
    		      str_start[edit_file.name_field];
    edit_line:=line;
    jump_out;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [7.107,108] replace make_fraction with external routine
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@p function make_fraction(@!p,@!q:integer):fraction;
var @!f:integer; {the fraction bits, with a leading 1 bit}
@!n:integer; {the integer part of $\vert p/q\vert$}
@!negative:boolean; {should the result be negated?}
@!be_careful:integer; {disables certain compiler optimizations}
begin if p>=0 then negative:=false
else  begin negate(p); negative:=true;
  end;
if q<=0 then
  begin debug if q=0 then confusion("/");@;@+gubed@;@/
@:this can't happen /}{\quad \./@>
  negate(q); negative:=not negative;
  end;
n:=p div q; p:=p mod q;
if n>=8 then
  begin arith_error:=true;
  if negative then make_fraction:=-el_gordo@+else make_fraction:=el_gordo;
  end
else  begin n:=(n-1)*fraction_one;
  @<Compute $f=\lfloor 2^{28}(1+p/q)+{1\over2}\rfloor$@>;
  if negative then make_fraction:=-(f+n)@+else make_fraction:=f+n;
  end;
end;

@ The |repeat| loop here preserves the following invariant relations:
(i)~|0<=p<q|; (ii)~$fq+p=2^k(q+p_0)$, where $k$ is an integer and
$p_0$ is the original value of~$p$.

Notice that the computation specifies
|(p-q)+p| instead of |(p+p)-q|, because the latter could overflow.
Let us hope that optimizing compilers do not miss this point; a
special variable |be_careful| is used to emphasize the necessary
order of computation. Optimizing compilers should keep |be_careful|
in a register, not store it in memory.
@^inner loop@>

@<Compute $f=\lfloor 2^{28}(1+p/q)+{1\over2}\rfloor$@>=
f:=1;
repeat be_careful:=p-q; p:=be_careful+p;
if p>=0 then f:=f+f+1
else  begin double(f); p:=p+q;
  end;
until f>=fraction_one;
be_careful:=p-q;
if be_careful+p>=0 then incr(f)

@y
Under {\mc UNIX} \MF, we have replaced the \PASCAL\ version of |make_fraction|
with either a C or assembly language equivalent for efficiency.

@ This section was deleted when |make_fraction| was removed.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [7.109,110,111] replace take_fraction with external version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@p function take_fraction(@!q:integer;@!f:fraction):integer;
var @!p:integer; {the fraction so far}
@!negative:boolean; {should the result be negated?}
@!n:integer; {additional multiple of $q$}
@!be_careful:integer; {disables certain compiler optimizations}
begin @<Reduce to the case that |f>=0| and |q>0|@>;
if f<fraction_one then n:=0
else  begin n:=f div fraction_one; f:=f mod fraction_one;
  if q<=el_gordo div n then n:=n*q
  else  begin arith_error:=true; n:=el_gordo;
    end;
  end;
f:=f+fraction_one;
@<Compute $p=\lfloor qf/2^{28}+{1\over2}\rfloor-q$@>;
be_careful:=n-el_gordo;
if be_careful+p>0 then
  begin arith_error:=true; n:=el_gordo-p;
  end;
if negative then take_fraction:=-(n+p)
else take_fraction:=n+p;
end;

@ @<Reduce to the case that |f>=0| and |q>0|@>=
if f>=0 then negative:=false
else  begin negate(f); negative:=true;
  end;
if q<0 then
  begin negate(q); negative:=not negative;
  end;

@ The invariant relations in this case are (i)~$\lfloor(qf+p)/2^k\rfloor
=\lfloor qf_0/2^{28}+{1\over2}\rfloor$, where $k$ is an integer and
$f_0$ is the original value of~$f$; (ii)~$2^k\L f<2^{k+1}$.
@^inner loop@>

@<Compute $p=\lfloor qf/2^{28}+{1\over2}\rfloor-q$@>=
p:=fraction_half; {that's $2^{27}$; the invariants hold now with $k=28$}
if q<fraction_four then
  repeat if odd(f) then p:=half(p+q)@+else p:=half(p);
  f:=half(f);
  until f=1
else  repeat if odd(f) then p:=p+half(q-p)@+else p:=half(p);
  f:=half(f);
  until f=1

@y
Function |take_fraction| has also been replaced by an external routine.

@ @<Reduce to the case that |f>=0| and |q>0|@>=
if f>=0 then negative:=false
else  begin negate(f); negative:=true;
  end;
if q<0 then
  begin negate(q); negative:=not negative;
  end;

@ This section was deleted when |take_fraction| was replaced by an
external routine.

@z

% ADD-VAX-KLUDGE-HERE % SENTINEL LINE --- DO NOT REMOVE %%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [9.153] ranges for quarter,half words
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
can get 256 values into a quarterword only if the subrange is `|-128..127|'.

The present implementation tries to accommodate as many variations as possible,
so it makes rather general assumptions. If integers having the subrange
`|min_quarterword..max_quarterword|' can be packed into a quarterword,
and if integers having the subrange `|min_halfword..max_halfword|'
can be packed into a halfword, everything should work satisfactorily.

It is usually most efficient to have |min_quarterword=min_halfword=0|,
so one should try to achieve this unless it causes a severe problem.
The values defined here are recommended for most 32-bit computers.

@d min_quarterword=0 {smallest allowable value in a |quarterword|}
@d max_quarterword=255 {largest allowable value in a |quarterword|}
@d min_halfword==0 {smallest allowable value in a |halfword|}
@d max_halfword==65535 {largest allowable value in a |halfword|}
@y
can get 256 values into a quarterword only if the subrange is `|-128..127|'.

For Berkeley {\mc UNIX} we need to do the |-128..127| kind of range.

@d min_quarterword=-128 {smallest allowable value in a |quarterword|}
@d max_quarterword=127 {largest allowable value in a |quarterword|}
@d min_halfword==-32768 {smallest allowable value in a |halfword|}
@d max_halfword==32767 {largest allowable value in a |halfword|}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [11.178] fix the word "free" so that it doesn't conflict with a runtime proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
been included. (You may want to decrease the size of |mem| while you
@^debugging@>
are debugging.)
@y
been included. (You may want to decrease the size of |mem| while you
@^debugging@>
are debugging.)

@d free==free_arr
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [12.194] fix_date_and_time
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The following procedure, which is called just before \MF\ initializes its
input and output, establishes the initial values of the date and time.
@^system dependencies@>
Since standard \PASCAL\ cannot provide such information, something special
is needed. The program here simply specifies July 4, 1776, at noon; but
users probably want a better approximation to the truth.

Note that the values are |scaled| integers. Hence \MF\ can no longer
be used after the year 32767.

@p procedure fix_date_and_time;
begin internal[time]:=12*60*unity; {minutes since midnight}
internal[day]:=4*unity; {fourth day of the month}
internal[month]:=7*unity; {seventh month of the year}
internal[year]:=1776*unity; {Anno Domini}
end;
@y
@ The following procedure, which is called just before \MF\ initializes its
input and output, establishes the initial values of the date and time.
It is calls an externally defined |date_and_time|, even though it could
be done from Pascal.
The external procedure also sets up interrupt catching.
@^system dependencies@>

Note that the values are |scaled| integers. Hence \MF\ can no longer
be used after the year 32767.

@p procedure fix_date_and_time;
begin
    date_and_time(internal[time],internal[day],internal[month],internal[year]);
    internal[time] := internal[time] * unity;
    internal[day] := internal[day] * unity;
    internal[month] := internal[month] * unity;
    internal[year] := internal[year] * unity;
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [12.199] allow <tab> and <ff> as input
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
for k:=0 to " "-1 do char_class[k]:=invalid_class;
char_class[127]:=invalid_class;
@y
for k:=0 to " "-1 do char_class[k]:=invalid_class;
char_class[127]:=invalid_class;
char_class[tab]:=space_class;
char_class[form_feed]:=space_class;
@z

% WORKAROUND FOR BUG IN SYSTEM V PC
@x
case o2-o1 of
1,-7,7,-1: goto done;
2,-6: clockwise:=false;
3,-5,4,-4,5,-3: @<Decide whether or not to go clockwise@>;
6,-2: clockwise:=true;
0:clockwise:=rev_turns;
@y
case o2-o1+7 of
{1,-7,7,-1} 8,0,14,6: goto done;
{2,-6} 9,1: clockwise:=false;
{3,-5,4,-4,5,-3} 10,2,11,3,12,4: @<Decide whether or not to go clockwise@>;
{6,-2} 13,5: clockwise:=true;
{0} 7:clockwise:=rev_turns;
@z

% ADD-WINDOW-CHANGES-HERE	%%% SENTINEL LINE -- DO NOT REMOVE %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.765] area and extension rules
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ The file names we shall deal with for illustrative purposes have the
following structure:  If the name contains `\.>' or `\.:', the file area
consists of all characters up to and including the final such character;
otherwise the file area is null.  If the remaining file name contains
`\..', the file extension consists of all such characters from the first
remaining `\..' to the end, otherwise the file extension is null.
@^system dependencies@>

We can scan such file names easily by using two global variables that keep track
of the occurrences of area and extension delimiters:

@<Glob...@>=
@!area_delimiter:pool_pointer; {the most recent `\.>' or `\.:', if any}
@!ext_delimiter:pool_pointer; {the relevant `\..', if any}
@y
@ The file names we shall deal with for illustrative purposes have the
following structure:  If the name contains `\./', the file area
consists of all characters up to and including the final such character;
otherwise the file area is null.  If the remaining file name contains
`\..', the file extension consists of all such characters from the first
remaining `\..' to the end, otherwise the file extension is null.
@^system dependencies@>

We can scan such file names easily by using two global variables that keep
track of the occurrences of area and extension delimiters:

@<Glob...@>=
@!area_delimiter:pool_pointer; {the most recent `\./', if any}
@!ext_delimiter:pool_pointer; {the most recent `\..', if any}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.766] MF area directories
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d MF_area=="MFinputs:"
@.MFinputs@>
@y
Under System V {\mc UNIX}, the default paths are specified in a seprate
file, ``mfpaths.h''.  The file opening procedures do path searching
based either on those default paths, or on paths given by the user
in ``environment'' variables.
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.768] more_name
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
begin if c=" " then more_name:=false
else  begin if (c=">")or(c=":") then
@y
begin if (c=" ")or(c=tab) then more_name:=false
else  begin if (c="/") then
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.772] default base
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d base_default_length=18 {length of the |MF_base_default| string}
@d base_area_length=8 {length of its area part}
@d base_ext_length=5 {length of its `\.{.base}' part}
@y
Under System V {\mc UNIX} we don't give the area part, instead depending
on the path searching that will happen during file opening.

@d base_default_length=10 {length of the |MF_base_default| string}
@d base_area_length=0 {length of its area part}
@d base_ext_length=5 {length of its `\.{.base}' part}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.773] plain base location
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
MF_base_default:='MFbases:plain.base';
@y
MF_base_default:='plain.base';
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.776] w_open_in of base file needs to be called only once
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
  pack_buffered_name(0,loc,j-1); {try first without the system file area}
  if w_open_in(base_file) then goto found;
  pack_buffered_name(base_area_length,loc,j-1);
    {now try the system base file area}
  if w_open_in(base_file) then goto found;
@y
  pack_buffered_name(0,loc,j-1);
  if w_open_in(base_file) then goto found;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.777] make_name_string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
which simply makes a \MF\ string from the value of |name_of_file|, should
ideally be changed to deduce the full name of file~|f|, which is the file
most recently opened, if it is possible to do this in a \PASCAL\ program.
@^system dependencies@>

This routine might be called after string memory has overflowed, hence
we dare not use `|str_room|'.

@p function make_name_string:str_number;
var @!k:1..file_name_size; {index into |name_of_file|}
begin if (pool_ptr+name_length>pool_size)or(str_ptr=max_strings) then
  make_name_string:="?"
else  begin for k:=1 to name_length do append_char(xord[name_of_file[k]]);
  make_name_string:=make_string;
  end;
end;
@y
which simply makes a \MF\ string from the value of |name_of_file|, should
ideally be changed to deduce the full name of file~|f|, which is the file
most recently opened, if it is possible to do this in a \PASCAL\ program.
With the System V {\mc UNIX} version, we know that |real_name_of_file|
contains |name_of_file| prepended with the directory name that was found
by path searching.
If |real_name_of_file| starts with |'./'|, we don't use that part of the
name, since {\mc UNIX} users understand that.
@^system dependencies@>

This routine might be called after string memory has overflowed, hence
we dare not use `|str_room|'.

@p function make_name_string:str_number;
var @!k,@!kstart:1..file_name_size; {index into |name_of_file|}
begin
k:=1;
while (k<file_name_size) and (xord[real_name_of_file[k]]<>" ") do
    incr(k);
name_length:=k-1; {the real |name_length|}
if (pool_ptr+name_length>pool_size)or(str_ptr=max_strings) then
  make_name_string:="?"
else  begin
  if (xord[real_name_of_file[1]]=".") and (xord[real_name_of_file[2]]="/") then
    kstart:=3
  else
    kstart:=1;
  for k:=kstart to name_length do append_char(xord[real_name_of_file[k]]);
  make_name_string:=make_string;
  end;
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.780] change b_make_name_string to retrieve file name to
%		real_name_of_file for make_name_string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
function b_make_name_string(var @!f:byte_file):str_number;
begin b_make_name_string:=make_name_string;
end;
@y
function b_make_name_string(var @!f:byte_file):str_number;
begin b_get_name(f, real_name_of_file);@/
b_make_name_string:=make_name_string;
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.778] scan_file_name ignore leading tabs as well as spaces
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@p procedure scan_file_name;
label done;
begin begin_name;
while buffer[loc]=" " do incr(loc);
@y
@p procedure scan_file_name;
label done;
begin begin_name;
while (buffer[loc]=" ")or(buffer[loc]=tab) do incr(loc);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.783] <scan_file_name...> needs similar leading tab treatment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ @<Scan file name in the buffer@>=
begin begin_name; k:=first;
while (buffer[k]=" ")and(k<last) do incr(k);
@y
@ @<Scan file name in the buffer@>=
begin begin_name; k:=first;
while ((buffer[k]=" ")or(buffer[k]=tab))and(k<last) do incr(k);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.791] add file name to b_open_out() calls in set_output_file_name
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
  pack_job_name(gf_ext);
  while not b_open_out(gf_file) do
    prompt_file_name("file name for output",gf_ext);
@y
  pack_job_name(gf_ext);
  while not b_open_out(gf_file, name_of_file) do
    prompt_file_name("file name for output",gf_ext);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.789] a_open_in of input file needs path selector
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
  if a_open_in(cur_file) then goto done;
  pack_file_name(cur_name,MF_area,cur_ext);
  if a_open_in(cur_file) then goto done;
@y
  if a_open_in(cur_file,MF_input_file_path) then goto done;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [38.789] get rid of return of name to string pool
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
if name=str_ptr-1 then {we can conserve string pool space now}
  begin flush_string(name); name:=cur_name;
  end;
@y
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [45.1128] writing the tfm file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d tfm_out(#)==write(tfm_file,#) {output one byte to |tfm_file|}

@p procedure tfm_two(@!x:integer); {output two bytes to |tfm_file|}
begin tfm_out(x div 256); tfm_out(x mod 256);
end;
@#
procedure tfm_four(@!x:integer); {output four bytes to |tfm_file|}
begin if x>=0 then tfm_out(x div three_bytes)
else  begin x:=x+@'10000000000; {use two's complement for negative values}
  x:=x+@'10000000000;
  tfm_out((x div three_bytes) + 128);
  end;
x:=x mod three_bytes; tfm_out(x div unity);
x:=x mod unity; tfm_out(x div @'400);
tfm_out(x mod @'400);
end;
@#
procedure tfm_qqqq(@!x:four_quarters); {output four quarterwords to |tfm_file|}
begin tfm_out(qo(x.b0)); tfm_out(qo(x.b1)); tfm_out(qo(x.b2));
tfm_out(qo(x.b3));
end;
@y
Under {\mc UNIX}, we are using the binary input and output routines.
Hence, we redefine all the {\mc TFM} input and output in terms of those
routines.

@d tfm_out(#) == b_write_byte(tfm_file, #)
@d tfm_two(#) == b_write_2_bytes(tfm_file, #)
@d tfm_four(#) == b_write_4_bytes(tfm_file, #)

@p procedure tfm_qqqq(@!x:four_quarters); {output four quarterwords to |tfm_file|}
begin tfm_out(qo(x.b0)); tfm_out(qo(x.b1)); tfm_out(qo(x.b2));
tfm_out(qo(x.b3));
end;
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [45.1134] add file name to b_open_out call in <finish the tfm file>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
pack_job_name(".tfm");
while not b_open_out(tfm_file) do
@y
pack_job_name(".tfm");
while not b_open_out(tfm_file, name_of_file) do
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [47.1151] add gf_buf_type type definition so we can pass it to
%		b_write_buf()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@!gf_index=0..gf_buf_size; {an index into the output buffer}
@y
@!gf_index=0..gf_buf_size; {an index into the output buffer}
@!gf_buf_type = array[gf_index] of eight_bits; {type declared for ext procs}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [47.1152] and redefine gf_buf[] in terms of gf_buf_type
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@!gf_buf:array[gf_index] of eight_bits; {buffer for \.{GF} output}
@y
@!gf_buf:gf_buf_type; {buffer for \.{GF} output}
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [47.1148] write_gf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@<Declare generic font output procedures@>=
procedure write_gf(@!a,@!b:gf_index);
var k:gf_index;
begin for k:=a to b do write(gf_file,gf_buf[k]);
end;
@y
For Berkeley {\mc UNIX}, this is going to be handled by an external procedure,
|b_write_buf|, which will do the output using |fwrite|.

@d write_gf(#) == b_write_buf(gf_file, gf_buf, #)
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [49.1197] Add call to exit() depending upon value of `history'
%           Also, add call to set_paths
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
t_open_out; {open the terminal for output}
@y
t_open_out; {open the terminal for output}
set_paths;
@z

@x
final_end: ready_already:=0;
@y
final_end: ready_already:=0;
if (history <> spotless) and (history <> warning_issued) then
    UNIXexit(1)
else
    UNIXexit(0);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [49.1198] print new line before termination; switch to editor if nec.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
    print(log_name); print_char(".");
    end;
  end;
@y
    print(log_name); print_char(".");
    end;
  end;
print_ln;
if (edit_name_start<>0) and (interaction>batch_mode) then
    calledit(str_pool[edit_name_start],edit_name_length,edit_line);
@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [51.1207,1208] add editor-switch variable to globals
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@* \[51] System-dependent changes.
This section should be replaced, if necessary, by changes to the program
that are necessary to make \MF\ work at a particular installation.
It is usually best to design your change file so that all changes to
previous sections preserve the section numbering; then everybody's version
will be consistent with the published program. More extensive changes,
which introduce new sections, can be inserted here; then only the index
itself will get a new section number.
@^system dependencies@>
@y
@* \[51] System-dependent changes.
Here are the variables used to hold ``switch-to-editor'' information.
@^system dependencies@>

@<Global...@>=
@!edit_name_start: pool_pointer;
@!edit_name_length,@!edit_line: integer;

@ The |edit_name_start| will be set to point into |str_pool| somewhere after
its beginning if \MF\ is supposed to switch to an editor on exit.

@<Set init...@>=
edit_name_start:=0;
@z

SHAR_EOF
cat << \SHAR_EOF > mf84/dist_splitsource.BSD4_n
#!/bin/sh
#
# $Header: dist_splitsource,v 0.999999 86/01/05 23:21:04 richards Released $
#
# DIST_SPLITSOURCE: split monolithic Pascal source file generated from WEB
#			version of MF into small(er), seperately compilable
#			Pascal files
#
# Usage: dist_splitsource [inimf|virmf|trapmf]
#
MFVERSION=$1
case $MFVERSION in
	inimf|virmf|trapmf)
		;;
	*)
		echo "WARNING: Consistancy error -- $0 called with illegal MF version"
		exit 1
		;;
esac
sed < ${MFVERSION}.p > ${MFVERSION}.h \
	   -e "/[ 	]function/s/[:(].*/(*&*);/" \
	   -e "/[ 	]procedure/s/[(].*/(*&*);/" \
	   -e "/program MF/w ${MFVERSION}4.p" \
	   -e "/program MF/s/.*/#include \"${MFVERSION}.h\"/" \
	   -e "/#include \"${MFVERSION}.h\"/w ${MFVERSION}1.p" \
	   -e "/#include \"${MFVERSION}.h\"/w ${MFVERSION}2.p" \
	   -e "/#include \"${MFVERSION}.h\"/w ${MFVERSION}3.p" \
	   -e "/#include \"${MFVERSION}.h\"/w ${MFVERSION}4.p" \
	   -e "/#include \"${MFVERSION}.h\"/d" \
	   -e "/[ 	]procedure initialize/,/end; {:254} {264:}/w ${MFVERSION}1.p" \
	   -e "/[ 	]procedure initialize/,/end; {:254} {264:}/d" \
	   -e "/[ 	]function copyknot/,/end; {:622} {626:}/w ${MFVERSION}2.p" \
	   -e "/[ 	]function copyknot/,/end; {:622} {626:}/d" \
	   -e "/[ 	]procedure showcmdmod/,/end; {:944} {989:} {1155:}/w ${MFVERSION}3.p" \
	   -e "/[ 	]procedure showcmdmod/,/end; {:944} {989:} {1155:}/d" \
	   -e "/[ 	]procedure gfswap/,\$w ${MFVERSION}4.p" \
	   -e "/[ 	]procedure gfswap/,\$d"
sed < ${MFVERSION}.p -n >> ${MFVERSION}.h \
	   -e "/[ 	]function/s/\$/ external;/p" \
	   -e "/[ 	]procedure/s/\$/ external;/p"

SHAR_EOF
cat << \SHAR_EOF > mf84/dist_to_ini.BSD4_n
#!/bin/sh
#
# $Header: dist_to_ini,v 1.3 87/03/06 21:15:45 mackay Released $
#
# Usage: dist_to_ini [MACHINE] distribution_changefile inimf_changefile
#
#	Changes distributed BSD change file for METAFONT 84 (INIMF) to
#	correct format for host machine
#
DISTVERS='% Header: dist_inimf.ch,v 1.3 87/03/06 21:15:21 mackay Released '
SCRIPTVERS='$Header: dist_to_ini,v 1.3 87/03/06 21:15:45 mackay Released $'
TODAY=`date`
#
if [ $# -ne 3 ]; then
	echo "Usage: $0 [MACHINE] distribution_changefile target_changefile"
	exit 1
elif [ "`grep \"^% .Header:\" $2|sed -e s/\\\\$//g`" != "${DISTVERS}" ]; then
	echo "$0: WARNING: this script doesn't match version of $2"
fi
case $1 in
	VAX*|SUN*) ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%    BY $SCRIPTVERS

.
w $3
q
!!EOF!!
		;;
	PYRAMID*) ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%    BY $SCRIPTVERS

.
/^% ADD-OTHERCASES-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.10] adjust "others:" to "otherwise" for Pyramid pascal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d othercases == others: {default for cases not listed explicitly}
@y
@d othercases == otherwise {default for cases not listed explicitly}
@z

.
/^% ADD-PYRAMID-KLUDGE-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [4.37] remove packed from str_pool so we can call calledit by reference
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@!str_pool:packed array[pool_pointer] of ASCII_code; {the characters}
@y
@!str_pool:array[pool_pointer] of ASCII_code; {the characters}
@z
.
1
/^@!screen_depth=1024;/
//c
@!screen_depth=780; {number of pixels in each column of screen display}
.
/^@d mem_min=-30000/c
@d mem_min=0 {smallest index in the |mem| array, must not be less
.
/-128..127/
//
//
.,.+5c
For Pyramid {\mc Unix} we need to do the |0..255| kind of range.

@d min_quarterword=0 {smallest allowable value in a |quarterword|}
@d max_quarterword=255 {largest allowable value in a |quarterword|}
@d min_halfword==0 {smallest allowable value in a |halfword|}
@d max_halfword==65535 {largest allowable value in a |halfword|}
.
w $3
q
!!EOF!!
		;;
	*)	echo "$0: Unknown target host: $1"
		exit 3
		;;
esac
exit
SHAR_EOF
cat << \SHAR_EOF > mf84/dist_to_ini.SYS_V
#!/bin/sh
#
# $Header: dist_to_ini,v 1.2 86/09/30 10:20:15 mackay Released $
#
# Usage: dist_to_ini [MACHINE] distribution_changefile inimf_changefile
#
#	Changes distributed BSD change file for METAFONT 84 (INIMF) to
#	correct format for host machine
#
DISTVERS='% Header: dist_inimf.ch,v 1.2 86/09/29 21:46:43 mackay Released '
SCRIPTVERS='$Header: dist_to_ini,v 1.2 86/09/30 10:20:15 mackay Released $'
TODAY=`date`
#
if [ $# -ne 3 ]; then
	echo "Usage: $0 [MACHINE] distribution_changefile target_changefile"
	exit 1
elif [ "`grep \"^% .Header:\" $2|sed -e s/\\\\$//g`" != "${DISTVERS}" ]; then
	echo "$0: WARNING: this script doesn't match version of $2"
fi
case $1 in
	VAX*|SUN*|U3B*) ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%    BY $SCRIPTVERS

.
w $3
q
!!EOF!!
		;;
	PYRAMID*) ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%    BY $SCRIPTVERS

.
/^% ADD-OTHERCASES-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.10] adjust "others:" to "otherwise" for Pyramid pascal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d othercases == others: {default for cases not listed explicitly}
@y
@d othercases == otherwise {default for cases not listed explicitly}
@z

.
w $3
q
!!EOF!!
		;;
	*)	echo "$0: Unknown target host: $1"
		exit 3
		;;
esac
exit
SHAR_EOF
cat << \SHAR_EOF > mf84/dist_to_trap.BSD4_n
#!/bin/sh
#
# $Header: dist_to_trap,v 1.3 87/03/06 21:15:51 mackay Released $
#
# Usage: dist_to_trap [MACHINE] distribution_changefile trapmf_changefile
#
#	Changes distributed BSD change file for METAFONT 84 (TRAPMF) to
#	correct format for host machine
#
DISTVERS='% Header: dist_inimf.ch,v 1.3 87/03/06 21:15:21 mackay Released '
SCRIPTVERS='$Header: dist_to_trap,v 1.3 87/03/06 21:15:51 mackay Released $'
TODAY=`date`
#
if [ $# -ne 3 ]; then
	echo "Usage: $0 [MACHINE] distribution_changefile target_changefile"
	exit 1
elif [ "`grep \"^% .Header:\" $2|sed -e s/\\\\$//g`" != "${DISTVERS}" ]; then
	echo "$0: WARNING: this script doesn't match version of $2"
fi
case $1 in
	VAX*|SUN*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%    BY $SCRIPTVERS

.
/@!mem_max=/
//
s/-*[0-9][0-9]*/-27000/p
/@!error_line=/
//
s/-*[0-9][0-9]*/64/p
/@!half_error_line=/
s/-*[0-9][0-9]*/32/p
/@!max_print_line=/
s/-*[0-9][0-9]*/72/p
/@!screen_width=/
//
s/-*[0-9][0-9]*/100/p
/@!screen_depth=/
s/-*[0-9][0-9]*/200/p
/@!gf_buf_size=/
//
s/-*[0-9][0-9]*/8/p
/@d mem_top=/
//
s/-*[0-9][0-9]*/-27000/p
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] turn graphic output routines on for TRAPMF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@y
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. For running the \.{TRAP} test, |init_screen| has
been changed to return |true|, which causes the other routines to simply
log the fact that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=true; {screen instructions will be logged}
end;
@z

.
w $3
q
!!EOF!!
		;;
	PYRAMID*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%    BY $SCRIPTVERS

.
/% ADD-OTHERCASES-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.10] adjust "others:" to "otherwise" for Pyramid pascal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d othercases == others: {default for cases not listed explicitly}
@y
@d othercases == otherwise {default for cases not listed explicitly}
@z

.
/@!mem_max=/
//
s/-*[0-9][0-9]*/-27000/p
/@!error_line=/
//
s/-*[0-9][0-9]*/64/p
/@!half_error_line=/
s/-*[0-9][0-9]*/32/p
/@!max_print_line=/
s/-*[0-9][0-9]*/72/p
/@!screen_width=/
//
s/-*[0-9][0-9]*/100/p
/@!screen_depth=/
s/-*[0-9][0-9]*/200/p
/@!gf_buf_size=/
//
s/-*[0-9][0-9]*/8/p
/@d mem_top=/
//
s/-*[0-9][0-9]*/-27000/p
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] turn graphic output routines on for TRAPMF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@y
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. For running the \.{TRAP} test, |init_screen| has
been changed to return |true|, which causes the other routines to simply
log the fact that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=true; {screen instructions will be logged}
end;
@z

.
w $3
q
!!EOF!!
		;;
	*)	echo "$0: Unknown target host: $1"
		exit 3
		;;
esac
exit
SHAR_EOF
cat << \SHAR_EOF > mf84/dist_to_trap.SYS_V
#!/bin/sh
#
# $Header: dist_to_trap,v 1.2 86/09/30 10:22:13 mackay Released $
#
# Usage: dist_to_trap [MACHINE] distribution_changefile trapmf_changefile
#
#	Changes distributed BSD change file for METAFONT 84 (TRAPMF) to
#	correct format for host machine
#
DISTVERS='% Header: dist_inimf.ch,v 1.2 86/09/29 21:46:43 mackay Released '
SCRIPTVERS='$Header: dist_to_trap,v 1.2 86/09/30 10:22:13 mackay Released $'
TODAY=`date`
#
if [ $# -ne 3 ]; then
	echo "Usage: $0 [MACHINE] distribution_changefile target_changefile"
	exit 1
elif [ "`grep \"^% .Header:\" $2|sed -e s/\\\\$//g`" != "${DISTVERS}" ]; then
	echo "$0: WARNING: this script doesn't match version of $2"
fi
case $1 in
	VAX*|SUN*|U3B*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%    BY $SCRIPTVERS

.
/@!mem_max=/
//
s/-*[0-9][0-9]*/-27000/p
/@!error_line=/
//
s/-*[0-9][0-9]*/64/p
/@!half_error_line=/
s/-*[0-9][0-9]*/32/p
/@!max_print_line=/
s/-*[0-9][0-9]*/72/p
/@!screen_width=/
//
s/-*[0-9][0-9]*/100/p
/@!screen_depth=/
s/-*[0-9][0-9]*/200/p
/@!gf_buf_size=/
//
s/-*[0-9][0-9]*/8/p
/@d mem_top=/
//
s/-*[0-9][0-9]*/-27000/p
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] turn graphic output routines on for TRAPMF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@y
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. For running the \.{TRAP} test, |init_screen| has
been changed to return |true|, which causes the other routines to simply
log the fact that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=true; {screen instructions will be logged}
end;
@z

.
w $3
q
!!EOF!!
		;;
	PYRAMID*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%    BY $SCRIPTVERS

.
/% ADD-OTHERCASES-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.10] adjust "others:" to "otherwise" for Pyramid pascal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d othercases == others: {default for cases not listed explicitly}
@y
@d othercases == otherwise {default for cases not listed explicitly}
@z

.
/@!mem_max=/
//
s/-*[0-9][0-9]*/-27000/p
/@!error_line=/
//
s/-*[0-9][0-9]*/64/p
/@!half_error_line=/
s/-*[0-9][0-9]*/32/p
/@!max_print_line=/
s/-*[0-9][0-9]*/72/p
/@!screen_width=/
//
s/-*[0-9][0-9]*/100/p
/@!screen_depth=/
s/-*[0-9][0-9]*/200/p
/@!gf_buf_size=/
//
s/-*[0-9][0-9]*/8/p
/@d mem_top=/
//
s/-*[0-9][0-9]*/-27000/p
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] turn graphic output routines on for TRAPMF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@y
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. For running the \.{TRAP} test, |init_screen| has
been changed to return |true|, which causes the other routines to simply
log the fact that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=true; {screen instructions will be logged}
end;
@z

.
w $3
q
!!EOF!!
		;;
	*)	echo "$0: Unknown target host: $1"
		exit 3
		;;
esac
exit
SHAR_EOF
cat << \SHAR_EOF > mf84/dist_to_vir.BSD4_n
#!/bin/sh
#
# $Header: dist_to_vir,v 1.3 87/03/06 21:15:47 mackay Released $
#
# A shell script to perform modifications on the distribution changefile
# to make a changefile for virmf.  This means changing constants and
# debug..gubed, init..tini, stat..tats.
#
# To use it, say
#	dist_to_vir [MACHINE] dist_inimf.ch virmf.ch
#
DISTVERS='% Header: dist_inimf.ch,v 1.3 87/03/06 21:15:21 mackay Released '
SCRIPTVERS='$Header: dist_to_vir,v 1.3 87/03/06 21:15:47 mackay Released $'
TODAY=`date`
#
if [ $# -ne 3 ]; then
	echo "Usage: $0 [MACHINE] distribution_changefile virmf_changefile"
	exit 1
elif [ "`grep \"^% .Header:\" $2|sed -e s/\\\\$//g`" != "${DISTVERS}" ]; then
	echo "$0: WARNING: this script doesn't match version of $2"
fi
case $1 in
	VAX*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%   BY: $SCRIPTVERS

.
/@d debug==/
//
s//&@{/p
/@d gubed==/
s//&@}/p
/@d stat==/
//
s//&@{/p
/@d tats==/
s//&@}/p
/@d init==/
//
s//&@{/p
/@d tini==/
s//&@}/p
/@!mem_max=/
//
s/[0-9][0-9]*/32700/p
/% ADD-VAX-KLUDGE-HERE/a
% KLUDGE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% KLUDGE %% Add some non-functional code to m_log.  This is done to get around
% KLUDGE %% 	a bug in the VAX assembler related to branches that are
% KLUDGE %%	exactly -128 bytes in displacement in source files longer
% KLUDGE %%	than 65k lines.  Obscure, Huh? *SIGH*
% KLUDGE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ @<Increase |k| until |x| can...@>=
begin z:=((x-1) div two_to_the[k])+1; {\$z=\lceil x/2^k\rceil\$}
while x<fraction_four+z do
  begin z:=half(z+1); k:=k+1;
  end;
y:=y+spec_log[k]; x:=x-z;
end
@y
@ @<Increase |k| until |x| can...@>=
begin z:=((x-1) div two_to_the[k])+1; {\$z=\lceil x/2^k\rceil\$}
while x<fraction_four+z do
  begin z:=half(z+1); k:=k+1;
  end;
y:=y+spec_log[k]; x:=x-z; z:=0;
end
@z

.
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] init_screen and update_screen are external C procs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@#
procedure update_screen; {will be called only if |init_screen| returns |true|}
begin @!init wlog_ln('Calling UPDATESCREEN');@+tini {for testing only}
end;

@y
We have declared |init_screen| and |update_screen| to be external procedures
for the {\mc unix} version of \MF\ in the header file at the beginning
of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.559] blank_rectangle is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The commented-out code in the following procedure is for illustrative
purposes only.
@^system dependencies@>

@p procedure blank_rectangle(@!left_col,@!right_col:screen_col;
  @!top_row,@!bot_row:screen_row);
var @!r:screen_row;
@!c:screen_col;
begin @{@+for r:=top_row to bot_row-1 do
  for c:=left_col to right_col-1 do
    screen_pixel[r,c]:=white;@+@}@/
@!init wlog_cr; {this will be done only after |init_screen=true|}
wlog_ln('Calling BLANKRECTANGLE(',left_col:1,',',
  right_col:1,',',top_row:1,',',bot_row:1,')');@+tini
end;

@y
@^system dependencies@>

|Blank_rectangle| has been declared an external routine for the {\mc unix}
version of \MF\ in the header files included at the beginning of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.560] paint_row is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The general idea is to paint blocks of pixels in alternate colors;
the precise details are best conveyed by means of a \PASCAL\\ 
program (see the commented-out code below).
@^system dependencies@>

@p procedure paint_row(@!r:screen_row;@!b:pixel_color;var @!a:trans_spec;
  @!n:screen_col);
var @!k:screen_col; {an index into |a|}
@!c:screen_col; {an index into |screen_pixel|}
begin @{ k:=0; c:=a[0];
repeat incr(k);
  repeat screen_pixel[r,c]:=b; incr(c);
  until c=a[k];
  b:=black-b; {$|black|\swap|white|$}
  until k=n;@+@}@/
@!init wlog('Calling PAINTROW(',r:1,',',b:1,';');
  {this is done only after |init_screen=true|}
for k:=0 to n do
  begin wlog(a[k]:1); if k<>n then wlog(',');
  end;
wlog_ln(')');@+tini
end;

@y
@^system dependencies@>

|Paint_row| has been declared an external routine in the {\mc unix} version
of \MF\ in the header files included at the beginning of the program.

@z

.
/#include "mf_ext.h"/a
@\@=#include "mf_window.h"@>@\ {declarations for external C procedures}
.
w $3
q
!!EOF!!
		;;
	SUN*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%   BY: $SCRIPTVERS

.
/@d debug==/
//
s//&@{/p
/@d gubed==/
s//&@}/p
/@d stat==/
//
s//&@{/p
/@d tats==/
s//&@}/p
/@d init==/
//
s//&@{/p
/@d tini==/
s//&@}/p
/@!mem_max=/
//
s/[0-9][0-9]*/32700/p
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] init_screen and update_screen are external C procs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@#
procedure update_screen; {will be called only if |init_screen| returns |true|}
begin @!init wlog_ln('Calling UPDATESCREEN');@+tini {for testing only}
end;

@y
We have declared |init_screen| and |update_screen| to be external procedures
for the {\mc unix} version of \MF\ in the header file at the beginning
of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.559] blank_rectangle is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The commented-out code in the following procedure is for illustrative
purposes only.
@^system dependencies@>

@p procedure blank_rectangle(@!left_col,@!right_col:screen_col;
  @!top_row,@!bot_row:screen_row);
var @!r:screen_row;
@!c:screen_col;
begin @{@+for r:=top_row to bot_row-1 do
  for c:=left_col to right_col-1 do
    screen_pixel[r,c]:=white;@+@}@/
@!init wlog_cr; {this will be done only after |init_screen=true|}
wlog_ln('Calling BLANKRECTANGLE(',left_col:1,',',
  right_col:1,',',top_row:1,',',bot_row:1,')');@+tini
end;

@y
@^system dependencies@>

|Blank_rectangle| has been declared an external routine for the {\mc unix}
version of \MF\ in the header files included at the beginning of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.560] paint_row is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The general idea is to paint blocks of pixels in alternate colors;
the precise details are best conveyed by means of a \PASCAL\\ 
program (see the commented-out code below).
@^system dependencies@>

@p procedure paint_row(@!r:screen_row;@!b:pixel_color;var @!a:trans_spec;
  @!n:screen_col);
var @!k:screen_col; {an index into |a|}
@!c:screen_col; {an index into |screen_pixel|}
begin @{ k:=0; c:=a[0];
repeat incr(k);
  repeat screen_pixel[r,c]:=b; incr(c);
  until c=a[k];
  b:=black-b; {$|black|\swap|white|$}
  until k=n;@+@}@/
@!init wlog('Calling PAINTROW(',r:1,',',b:1,';');
  {this is done only after |init_screen=true|}
for k:=0 to n do
  begin wlog(a[k]:1); if k<>n then wlog(',');
  end;
wlog_ln(')');@+tini
end;

@y
@^system dependencies@>

|Paint_row| has been declared an external routine in the {\mc unix} version
of \MF\ in the header files included at the beginning of the program.

@z

.
/#include "mf_ext.h"/a
@\@=#include "mf_window.h"@>@\ {declarations for external C procedures}
.
.
w $3
q
!!EOF!!
		;;
	PYRAMID*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%   BY: $SCRIPTVERS

.
/% ADD-OTHERCASES-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.10] adjust "others:" to "otherwise" for Pyramid pascal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d othercases == others: {default for cases not listed explicitly}
@y
@d othercases == otherwise {default for cases not listed explicitly}
@z

.
/@d debug==/
//
s//&@{/p
/@d gubed==/
s//&@}/p
/@d stat==/
//
s//&@{/p
/@d tats==/
s//&@}/p
/@d init==/
//
s//&@{/p
/@d tini==/
s//&@}/p
/@!mem_max=/
//
s/[0-9][0-9]*/32700/p
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] init_screen and update_screen are external C procs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@#
procedure update_screen; {will be called only if |init_screen| returns |true|}
begin @!init wlog_ln('Calling UPDATESCREEN');@+tini {for testing only}
end;

@y
We have declared |init_screen| and |update_screen| to be external procedures
for the {\mc unix} version of \MF\ in the header file at the beginning
of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.559] blank_rectangle is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The commented-out code in the following procedure is for illustrative
purposes only.
@^system dependencies@>

@p procedure blank_rectangle(@!left_col,@!right_col:screen_col;
  @!top_row,@!bot_row:screen_row);
var @!r:screen_row;
@!c:screen_col;
begin @{@+for r:=top_row to bot_row-1 do
  for c:=left_col to right_col-1 do
    screen_pixel[r,c]:=white;@+@}@/
@!init wlog_cr; {this will be done only after |init_screen=true|}
wlog_ln('Calling BLANKRECTANGLE(',left_col:1,',',
  right_col:1,',',top_row:1,',',bot_row:1,')');@+tini
end;

@y
@^system dependencies@>

|Blank_rectangle| has been declared an external routine for the {\mc unix}
version of \MF\ in the header files included at the beginning of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.560] paint_row is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The general idea is to paint blocks of pixels in alternate colors;
the precise details are best conveyed by means of a \PASCAL\\ 
program (see the commented-out code below).
@^system dependencies@>

@p procedure paint_row(@!r:screen_row;@!b:pixel_color;var @!a:trans_spec;
  @!n:screen_col);
var @!k:screen_col; {an index into |a|}
@!c:screen_col; {an index into |screen_pixel|}
begin @{ k:=0; c:=a[0];
repeat incr(k);
  repeat screen_pixel[r,c]:=b; incr(c);
  until c=a[k];
  b:=black-b; {$|black|\swap|white|$}
  until k=n;@+@}@/
@!init wlog('Calling PAINTROW(',r:1,',',b:1,';');
  {this is done only after |init_screen=true|}
for k:=0 to n do
  begin wlog(a[k]:1); if k<>n then wlog(',');
  end;
wlog_ln(')');@+tini
end;

@y
@^system dependencies@>

|Paint_row| has been declared an external routine in the {\mc unix} version
of \MF\ in the header files included at the beginning of the program.

@z

.
/#include "mf_ext.h"/a
@\@=#include "mf_window.h"@>@\ {declarations for external C procedures}
.
.
1
/^% ADD-PYRAMID-KLUDGE-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [4.37] remove packed from str_pool so we can call calledit by reference
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@!str_pool:packed array[pool_pointer] of ASCII_code; {the characters}
@y
@!str_pool:array[pool_pointer] of ASCII_code; {the characters}
@z
.
1
/^@!screen_depth=1024;/
//c
@!screen_depth=780; {number of pixels in each column of screen display}
.
/^@d mem_min=-30000/c
@d mem_min=0 {smallest index in the |mem| array, must not be less
.
/-128..127/
//
//
.,.+5c
For Pyramid {\mc Unix} we need to do the |0..255| kind of range.

@d min_quarterword=0 {smallest allowable value in a |quarterword|}
@d max_quarterword=255 {largest allowable value in a |quarterword|}
@d min_halfword==0 {smallest allowable value in a |halfword|}
@d max_halfword==65535 {largest allowable value in a |halfword|}
.
w $3
q
!!EOF!!
		;;
	*)	echo "$0: Unknown target host: $1"
		exit 3
		;;
esac
exit
SHAR_EOF
cat << \SHAR_EOF > mf84/dist_to_vir.SYS_V
#!/bin/sh
#
# $Header: dist_to_vir,v 1.2 86/09/30 10:21:27 richards Released $
#
# A shell script to perform modifications on the distribution changefile
# to make a changefile for virmf.  This means changing constants and
# debug..gubed, init..tini, stat..tats.
#
# To use it, say
#	dist_to_vir [MACHINE] dist_inimf.ch virmf.ch
#
DISTVERS='% Header: dist_inimf.ch,v 1.2 86/09/29 21:46:43 mackay Released '
SCRIPTVERS='$Header: dist_to_vir,v 1.2 86/09/30 10:21:27 mackay Released $'
TODAY=`date`
#
if [ $# -ne 3 ]; then
	echo "Usage: $0 [MACHINE] distribution_changefile virmf_changefile"
	exit 1
elif [ "`grep \"^% .Header:\" $2|sed -e s/\\\\$//g`" != "${DISTVERS}" ]; then
	echo "$0: WARNING: this script doesn't match version of $2"
fi
case $1 in
	VAX*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%   BY: $SCRIPTVERS

.
/@d debug==/
//
s//&@{/p
/@d gubed==/
s//&@}/p
/@d stat==/
//
s//&@{/p
/@d tats==/
s//&@}/p
/@d init==/
//
s//&@{/p
/@d tini==/
s//&@}/p
/@!mem_max=/
//
s/[0-9][0-9]*/32700/p
/% ADD-VAX-KLUDGE-HERE/a
% KLUDGE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% KLUDGE %% Add some non-functional code to m_log.  This is done to get around
% KLUDGE %% 	a bug in the VAX assembler related to branches that are
% KLUDGE %%	exactly -128 bytes in displacement in source files longer
% KLUDGE %%	than 65k lines.  Obscure, Huh? *SIGH*
% KLUDGE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@ @<Increase |k| until |x| can...@>=
begin z:=((x-1) div two_to_the[k])+1; {\$z=\lceil x/2^k\rceil\$}
while x<fraction_four+z do
  begin z:=half(z+1); k:=k+1;
  end;
y:=y+spec_log[k]; x:=x-z;
end
@y
@ @<Increase |k| until |x| can...@>=
begin z:=((x-1) div two_to_the[k])+1; {\$z=\lceil x/2^k\rceil\$}
while x<fraction_four+z do
  begin z:=half(z+1); k:=k+1;
  end;
y:=y+spec_log[k]; x:=x-z; z:=0;
end
@z

.
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] init_screen and update_screen are external C procs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@#
procedure update_screen; {will be called only if |init_screen| returns |true|}
begin @!init wlog_ln('Calling UPDATESCREEN');@+tini {for testing only}
end;

@y
We have declared |init_screen| and |update_screen| to be external procedures
for the {\mc unix} version of \MF\ in the header file at the beginning
of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.559] blank_rectangle is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The commented-out code in the following procedure is for illustrative
purposes only.
@^system dependencies@>

@p procedure blank_rectangle(@!left_col,@!right_col:screen_col;
  @!top_row,@!bot_row:screen_row);
var @!r:screen_row;
@!c:screen_col;
begin @{@+for r:=top_row to bot_row-1 do
  for c:=left_col to right_col-1 do
    screen_pixel[r,c]:=white;@+@}@/
@!init wlog_cr; {this will be done only after |init_screen=true|}
wlog_ln('Calling BLANKRECTANGLE(',left_col:1,',',
  right_col:1,',',top_row:1,',',bot_row:1,')');@+tini
end;

@y
@^system dependencies@>

|Blank_rectangle| has been declared an external routine for the {\mc unix}
version of \MF\ in the header files included at the beginning of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.560] paint_row is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The general idea is to paint blocks of pixels in alternate colors;
the precise details are best conveyed by means of a \PASCAL\\ 
program (see the commented-out code below).
@^system dependencies@>

@p procedure paint_row(@!r:screen_row;@!b:pixel_color;var @!a:trans_spec;
  @!n:screen_col);
var @!k:screen_col; {an index into |a|}
@!c:screen_col; {an index into |screen_pixel|}
begin @{ k:=0; c:=a[0];
repeat incr(k);
  repeat screen_pixel[r,c]:=b; incr(c);
  until c=a[k];
  b:=black-b; {$|black|\swap|white|$}
  until k=n;@+@}@/
@!init wlog('Calling PAINTROW(',r:1,',',b:1,';');
  {this is done only after |init_screen=true|}
for k:=0 to n do
  begin wlog(a[k]:1); if k<>n then wlog(',');
  end;
wlog_ln(')');@+tini
end;

@y
@^system dependencies@>

|Paint_row| has been declared an external routine in the {\mc unix} version
of \MF\ in the header files included at the beginning of the program.

@z

.
/#include "mf_ext.h"/a
@\@=#include "mf_window.h"@>@\ {declarations for external C procedures}
.
w $3
q
!!EOF!!
		;;
	SUN*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%   BY: $SCRIPTVERS

.
/@d debug==/
//
s//&@{/p
/@d gubed==/
s//&@}/p
/@d stat==/
//
s//&@{/p
/@d tats==/
s//&@}/p
/@d init==/
//
s//&@{/p
/@d tini==/
s//&@}/p
/@!mem_max=/
//
s/[0-9][0-9]*/32700/p
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] init_screen and update_screen are external C procs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@#
procedure update_screen; {will be called only if |init_screen| returns |true|}
begin @!init wlog_ln('Calling UPDATESCREEN');@+tini {for testing only}
end;

@y
We have declared |init_screen| and |update_screen| to be external procedures
for the {\mc unix} version of \MF\ in the header file at the beginning
of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.559] blank_rectangle is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The commented-out code in the following procedure is for illustrative
purposes only.
@^system dependencies@>

@p procedure blank_rectangle(@!left_col,@!right_col:screen_col;
  @!top_row,@!bot_row:screen_row);
var @!r:screen_row;
@!c:screen_col;
begin @{@+for r:=top_row to bot_row-1 do
  for c:=left_col to right_col-1 do
    screen_pixel[r,c]:=white;@+@}@/
@!init wlog_cr; {this will be done only after |init_screen=true|}
wlog_ln('Calling BLANKRECTANGLE(',left_col:1,',',
  right_col:1,',',top_row:1,',',bot_row:1,')');@+tini
end;

@y
@^system dependencies@>

|Blank_rectangle| has been declared an external routine for the {\mc unix}
version of \MF\ in the header files included at the beginning of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.560] paint_row is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The general idea is to paint blocks of pixels in alternate colors;
the precise details are best conveyed by means of a \PASCAL\\ 
program (see the commented-out code below).
@^system dependencies@>

@p procedure paint_row(@!r:screen_row;@!b:pixel_color;var @!a:trans_spec;
  @!n:screen_col);
var @!k:screen_col; {an index into |a|}
@!c:screen_col; {an index into |screen_pixel|}
begin @{ k:=0; c:=a[0];
repeat incr(k);
  repeat screen_pixel[r,c]:=b; incr(c);
  until c=a[k];
  b:=black-b; {$|black|\swap|white|$}
  until k=n;@+@}@/
@!init wlog('Calling PAINTROW(',r:1,',',b:1,';');
  {this is done only after |init_screen=true|}
for k:=0 to n do
  begin wlog(a[k]:1); if k<>n then wlog(',');
  end;
wlog_ln(')');@+tini
end;

@y
@^system dependencies@>

|Paint_row| has been declared an external routine in the {\mc unix} version
of \MF\ in the header files included at the beginning of the program.

@z

.
/#include "mf_ext.h"/a
@\@=#include "mf_window.h"@>@\ {declarations for external C procedures}
.
.
w $3
q
!!EOF!!
		;;
	PYRAMID*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%   BY: $SCRIPTVERS

.
/% ADD-OTHERCASES-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [1.10] adjust "others:" to "otherwise" for Pyramid pascal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
@d othercases == others: {default for cases not listed explicitly}
@y
@d othercases == otherwise {default for cases not listed explicitly}
@z

.
/@d debug==/
//
s//&@{/p
/@d gubed==/
s//&@}/p
/@d stat==/
//
s//&@{/p
/@d tats==/
s//&@}/p
/@d init==/
//
s//&@{/p
/@d tini==/
s//&@}/p
/@!mem_max=/
//
s/[0-9][0-9]*/32700/p
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] init_screen and update_screen are external C procs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@#
procedure update_screen; {will be called only if |init_screen| returns |true|}
begin @!init wlog_ln('Calling UPDATESCREEN');@+tini {for testing only}
end;

@y
We have declared |init_screen| and |update_screen| to be external procedures
for the {\mc unix} version of \MF\ in the header file at the beginning
of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.559] blank_rectangle is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The commented-out code in the following procedure is for illustrative
purposes only.
@^system dependencies@>

@p procedure blank_rectangle(@!left_col,@!right_col:screen_col;
  @!top_row,@!bot_row:screen_row);
var @!r:screen_row;
@!c:screen_col;
begin @{@+for r:=top_row to bot_row-1 do
  for c:=left_col to right_col-1 do
    screen_pixel[r,c]:=white;@+@}@/
@!init wlog_cr; {this will be done only after |init_screen=true|}
wlog_ln('Calling BLANKRECTANGLE(',left_col:1,',',
  right_col:1,',',top_row:1,',',bot_row:1,')');@+tini
end;

@y
@^system dependencies@>

|Blank_rectangle| has been declared an external routine for the {\mc unix}
version of \MF\ in the header files included at the beginning of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.560] paint_row is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The general idea is to paint blocks of pixels in alternate colors;
the precise details are best conveyed by means of a \PASCAL\\ 
program (see the commented-out code below).
@^system dependencies@>

@p procedure paint_row(@!r:screen_row;@!b:pixel_color;var @!a:trans_spec;
  @!n:screen_col);
var @!k:screen_col; {an index into |a|}
@!c:screen_col; {an index into |screen_pixel|}
begin @{ k:=0; c:=a[0];
repeat incr(k);
  repeat screen_pixel[r,c]:=b; incr(c);
  until c=a[k];
  b:=black-b; {$|black|\swap|white|$}
  until k=n;@+@}@/
@!init wlog('Calling PAINTROW(',r:1,',',b:1,';');
  {this is done only after |init_screen=true|}
for k:=0 to n do
  begin wlog(a[k]:1); if k<>n then wlog(',');
  end;
wlog_ln(')');@+tini
end;

@y
@^system dependencies@>

|Paint_row| has been declared an external routine in the {\mc unix} version
of \MF\ in the header files included at the beginning of the program.

@z

.
/#include "mf_ext.h"/a
@\@=#include "mf_window.h"@>@\ {declarations for external C procedures}
.
.
w $3
q
!!EOF!!
		;;
	U3B*)
		ed - $2 <<!!EOF!!
0a
% EDITED FROM $2 INTO $3 FOR HOST TYPE "$1" on $TODAY
%   BY: $SCRIPTVERS

.
/@d debug==/
//
s//&@{/p
/@d gubed==/
s//&@}/p
/@d stat==/
//
s//&@{/p
/@d tats==/
s//&@}/p
/@d init==/
//
s//&@{/p
/@d tini==/
s//&@}/p
/@!mem_max=/
//
s/[0-9][0-9]*/32700/p
/% ADD-WINDOW-CHANGES-HERE/a
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.556] init_screen and update_screen are external C procs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The \PASCAL\ code here is a minimum version of |init_screen| and
|update_screen|, usable on \MF\ installations that don't
support screen output. If |init_screen| is changed to return |true|
instead of |false|, the other routines will simply log the fact
that they have been called; they won't really display anything.
The standard test routines for \MF\ use this log information to check
that \MF\ is working properly, but the |wlog| instructions should be
removed from production versions of \MF.

@p function init_screen:boolean;
begin init_screen:=false;
end;
@#
procedure update_screen; {will be called only if |init_screen| returns |true|}
begin @!init wlog_ln('Calling UPDATESCREEN');@+tini {for testing only}
end;

@y
We have declared |init_screen| and |update_screen| to be external procedures
for the {\mc unix} version of \MF\ in the header file at the beginning
of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.559] blank_rectangle is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The commented-out code in the following procedure is for illustrative
purposes only.
@^system dependencies@>

@p procedure blank_rectangle(@!left_col,@!right_col:screen_col;
  @!top_row,@!bot_row:screen_row);
var @!r:screen_row;
@!c:screen_col;
begin @{@+for r:=top_row to bot_row-1 do
  for c:=left_col to right_col-1 do
    screen_pixel[r,c]:=white;@+@}@/
@!init wlog_cr; {this will be done only after |init_screen=true|}
wlog_ln('Calling BLANKRECTANGLE(',left_col:1,',',
  right_col:1,',',top_row:1,',',bot_row:1,')');@+tini
end;

@y
@^system dependencies@>

|Blank_rectangle| has been declared an external routine for the {\mc unix}
version of \MF\ in the header files included at the beginning of the program.

@z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [27.560] paint_row is an external C proc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@x
The general idea is to paint blocks of pixels in alternate colors;
the precise details are best conveyed by means of a \PASCAL\\ 
program (see the commented-out code below).
@^system dependencies@>

@p procedure paint_row(@!r:screen_row;@!b:pixel_color;var @!a:trans_spec;
  @!n:screen_col);
var @!k:screen_col; {an index into |a|}
@!c:screen_col; {an index into |screen_pixel|}
begin @{ k:=0; c:=a[0];
repeat incr(k);
  repeat screen_pixel[r,c]:=b; incr(c);
  until c=a[k];
  b:=black-b; {$|black|\swap|white|$}
  until k=n;@+@}@/
@!init wlog('Calling PAINTROW(',r:1,',',b:1,';');
  {this is done only after |init_screen=true|}
for k:=0 to n do
  begin wlog(a[k]:1); if k<>n then wlog(',');
  end;
wlog_ln(')');@+tini
end;

@y
@^system dependencies@>

|Paint_row| has been declared an external routine in the {\mc unix} version
of \MF\ in the header files included at the beginning of the program.

@z

.
/#include "mf_ext.h"/a
@\@=#include "mf_window.h"@>@\ {declarations for external C procedures}
.
.
w $3
q
!!EOF!!
		;;
	*)	echo "$0: Unknown target host: $1"
		exit 3
		;;
esac
exit
SHAR_EOF
cat << \SHAR_EOF > mf84/makemf.SYS_V
# change the following to remove intermediate files
RM=echo

# definitions needed for Pascal compilation
PC0=/usr/lib/pc0
PC1=/usr/lib/pc1
PC2=/usr/lib/pc2
# compile with no range check
PC0OPTS="-T r"

# where assembler temporaries are put
TMPDIR=/usr/tmp
export TMPDIR

case $# in
1)
	;;
*)
	echo "usage: $0 tex"
	exit 1
	;;
esac
name=$1

# break up the monolithic pascal source into
# six pieces.  this prevents the System V Pascal
# compiler or assembler from running out of internal
# table space.

sed -e "s/mfsep/$name/" <mfsep.sed >$name.sed
sed -f $name.sed <$name.p
$RM $name.sed

# simulate pc -c on each individual piece.
# we don't use pc because it insists on placing temporaries
# in /tmp, and we don't have much disk space there.
# see also the definition of TMPDIR above.

for i in 1 2 3 4 5 6
do
	piece=${name}$i
	$PC0 -o $piece.0 $PC0OPTS $piece.p
	$PC1 <$piece.0 >$piece.s
# UGLY!  the last piece can't use the optimizer.
# (we get a stack overflow exception)
	case $i in
	[1-5])
		$PC2 <$piece.s >$piece.0
		as -o $piece.o $piece.0
		;;
	6)
		as -o $piece.o $piece.s
		;;
	esac
	$RM $piece.0 $piece.s
done

pc -o $name ${name}6.o ${name}[1-5].o MFlib/mflib.a
SHAR_EOF
cat << \SHAR_EOF > mf84/mf_ext.BSD4_n.h
{ $Header: mf_ext.h,v 1.0 86/01/31 16:42:56 richards Released $ }

{ declarations for external C assist routines for MetaFont }

procedure exit(x : integer);
 external;

procedure closea(var f:text);
 external;

procedure closew(var f:wordfile);
 external;

procedure dateandtime(var minutes, day, month, year : integer);
    external;

procedure setpaths;
    external;

function testaccess(var nameoffile, realnameoffile: UNIXfilename;
		accessmode:integer; filepath:integer): boolean;
    external;

procedure calledit(var filename: ASCIIcode; fnlength, linenumber: integer);
    external;

function bopenout(var f: bytefile; var name: UNIXfilename): boolean;
    external;

procedure bclose(var f: bytefile);
    external;

procedure bgetname(var f: bytefile; var name: UNIXfilename);
    external;

procedure bwritebuf(var f: bytefile; var buf: gfbuftype;
		first, last: integer);
    external;

procedure bwritebyte(var f: bytefile; b: integer);
    external;

procedure bwrite2bytes(var f: bytefile; b: integer);
    external;

procedure bwrite4bytes(var f: bytefile; b: integer);
    external;

function makefraction(p, q: integer): fraction;
    external;

function takefraction(q: integer; f: fraction): integer;
    external;

SHAR_EOF
cat << \SHAR_EOF > mf84/mf_ext.SYS_V.h
{ $Header: mf_ext.h,v 1.0 86/01/31 16:42:56 richards Released $ }

{ declarations for external C assist routines for MetaFont }

procedure exit(x : integer);
 external C;

procedure closea(var f:text);
 external C;

procedure closew(var f:wordfile);
 external C;

procedure dateandtime(var minutes, day, month, year : integer);
    external C;

procedure setpaths;
    external C;

function testaccess(var nameoffile, realnameoffile: UNIXfilename;
		accessmode:integer; filepath:integer): boolean;
    external C;

procedure calledit(var filename: ASCIIcode; fnlength, linenumber: integer);
    external C;

function bopenout(var f: bytefile; var name: UNIXfilename): boolean;
    external C;

procedure bclose(var f: bytefile);
    external C;

procedure bgetname(var f: bytefile; var name: UNIXfilename);
    external C;

procedure bwritebuf(var f: bytefile; var buf: gfbuftype;
		first, last: integer);
    external C;

procedure bwritebyte(var f: bytefile; b: integer);
    external C;

procedure bwrite2bytes(var f: bytefile; b: integer);
    external C;

procedure bwrite4bytes(var f: bytefile; b: integer);
    external C;

function makefraction(p, q: integer): fraction;
    external C;

function takefraction(q: integer; f: fraction): integer;
    external C;

procedure flush(var f: text);
    external C;

SHAR_EOF
cat << \SHAR_EOF > mf84/mf_window.BSD4_n.h
{ $Header: mf_window.h,v 0.999999 86/01/13 00:43:56 richards Released $ }

{ External procedures for UNIX MetaFont VIRMF for display graphics }

function initscreen: boolean;
    external;

procedure updatescreen;
    external;

procedure blankrectangle(leftcol, rightcol: screencol; toprow, botrow: screenrow);
    external;

procedure paintrow(r: screenrow; b: pixelcolor; var a: transspec; n: screencol);
    external;
SHAR_EOF
cat << \SHAR_EOF > mf84/mf_window.SYS_V.h
{ $Header: mf_window.h,v 0.999999 86/01/13 00:43:56 richards Released $ }

{ External procedures for UNIX MetaFont VIRMF for display graphics }

function initscreen: boolean;
    external C;

procedure updatescreen;
    external C;

procedure blankrectangle(leftcol, rightcol: screencol; toprow, botrow: screenrow);
    external C;

procedure paintrow(r: screenrow; b: pixelcolor; var a: transspec; n: screencol);
    external C;
SHAR_EOF
cat << \SHAR_EOF > mf84/mfsep.SYS_V.sed
/^    procedure/{
	s/$/ external;/w mfsep1.h
	s/^\(    procedure [^(;]*\).*/\1;/
}
/^    function/{
	s/$/ external;/w mfsep1.h
	s/^\(    function [^(:]*\).*/\1;/
}
/^program/,/^const/{
	/^const/b co
	w mfsep0.h
	d
}
:co
/^const/,/^    procedure initialize/{
	/^    procedure initialize/b t1
	w mfsep1.h
	d
}
:t1
/^    procedure initialize/,/^    procedure showmacro/{
	/^    procedure showmacro/b t2
	/^    procedure initialize/s/^/#include "mfsep1.h"\
/
	w mfsep1.p
	d
}
:t2
/^    procedure showmacro/,/^    procedure abnegate/{
	/^    procedure abnegate/b t3
	/^    procedure showmacro/s/^/#include "mfsep1.h"\
/
	w mfsep2.p
	d
}
:t3
/^    procedure abnegate/,/^    procedure dispedges/{
	/^    procedure dispedges/b t4
	/^    procedure abnegate/s/^/#include "mfsep1.h"\
/
	w mfsep3.p
	d
}
:t4
/^    procedure dispedges/,/^    procedure dounary/{
	/^    procedure dounary/b t5
	/^    procedure dispedges/s/^/#include "mfsep1.h"\
/
	w mfsep4.p
	d
}
:t5
/^    procedure dounary/,/^    procedure dospecial/{
	/^    procedure dospecial/b t6
	/^    procedure dounary/s/^/#include "mfsep1.h"\
/
	w mfsep5.p
	d
}
:t6
/^    procedure dospecial/,${
	/^    procedure dospecial/s/^/#include "mfsep0.h"\
#include "mfsep1.h"\
/
	w mfsep6.p
	d
}
SHAR_EOF
#	End of shell archive
exit 0