#!/bin/sh
awk '
BEGIN {
    dot=0
}
/\.$/ {
    if (dot) printf(".")
    dot=1
    print substr($0,1,length($0)-1)
    next
}
{
    if (dot) printf(".")
    print 
    dot=0
}
END {
    if (dot) printf(".\n")
}
' mf.defines mf.p | \
sed -e '
    s/\.hh/.hhfield/g
    s/\.lh/.lhfield/g
' | ../web2cdir/web2c -hmf.h -m \
    | sed -e '
    s/else write/else\
    write/
    s/  *\([A-Za-z0-9]*\) *= *\(".*"\) *;/  (void) strcpy(\1 + 1, \2) ;/
    s/  *nameoffile *= *poolname/  (void) strncpy(nameoffile+1, poolname, sizeof poolname)/
    s/ maxcoef\( *[^( ]\)/ lmaxcoef\1/g
    s/ b1/ lb1/g
    s/ b2/ lb2/g
    s/ b3/ lb3/g
    / *read/ s/read *( *\([a-z]*\) *, *\([a-z]*\) *, *\([a-z]*\)/read (\1 , \2); read (\1, \3/g
' \
	| ../web2cdir/fixwrites \
	| ./fix \
	| (cd ../cmf; ../web2cdir/splitup mf)

cat coerce.h fixcoerce.h > ../cmf/coerce.h
cp mf.pool ../cmf/mf.pool
rm -f coerce.h
cd ../cmf
cp mfd.h orig_mfd.h
../mfdir/ini_to_trap mfd.h trap_mfd.h
