#!/bin/sh
infiles=$@
trap 'rm -f $infiles; exit 1' 1 3 15

# echo ""
for infile in $infiles
do
  case $infile in
  *.h)
    cb="/*"; cs=" *"; ce=" */";;
  *.1|*.5|*.8|*.man)
    cb=.\\\"; cs=.\\\"; ce=.\\\";;
  *)
    case "`sed -n -e 1p $infile.in`" in
    '#!'*) cb="`sed -n -e 1p $infile.in`";;
    *)     cb="#";;
    esac
    cs="#"; ce="#";;
  esac
  echo "$cb"                                                    > $infile
  echo "$cs Generated automatically from $infile.in by the"     >> $infile
  echo "$cs configure script."                                  >> $infile
  echo "$ce"                                                    >> $infile
  echo "Creating $infile from $infile.in"
  sed -e '
s,@version@,man-1.6g,
s,@CC@,gcc -O,
s,@EXEEXT@,.exe,
s,@BUILD_CC@,gcc -O,
s,@INSTALL@,install,
s,@DEFS@, -DSTDC_HEADERS -DTERMIOS_HEADER -DPOSIX -DNONLS -DDO_COMPRESS,
s,@LIBS@,,
s,@LIBOBJS@,,
s,@troff@,/bin/groff -Tps -mandoc,
s,@nroff@,/bin/nroff -Tlatin1 -mandoc,
s,@jnroff@,/bin/groff -Tnippon -mandocj,
s,@eqn@,/bin/eqn -Tps,
s,@neqn@,/bin/eqn -Tlatin1,
s,@jneqn@,/bin/eqn -Tnippon,
s,@tbl@,/bin/tbl,
s,@nocol@,# ,
s,@pcol@,,
s,@col@,/bin/col,
s,@vgrind@,,
s,@refer@,/bin/refer,
s,@grap@,,
s,@pic@,/bin/pic,
s,@fcat@,,
s,@pcat@,,
s,@zcat@,/bin/zcat,
s,@unxz@,/bin/unxz -c,
s,@gunzip@,/bin/gunzip -c,
s,@bzip2@,/bin/bzip2 -c -d,
s,@unlzma@,/bin/unlzma -c -d,
s,@unyabba@,,
s,@compress@,/bin/xz,
s,@compress_ext@,.xz,
s,@decompress@,/bin/unxz -c,
s,@pager@,/bin/less -is,
s,@browser@,/bin/lynx,
s,@htmlpager@,/bin/lynx -dump,
s,@cmp@,/bin/cmp -s,
s,@cat@,/bin/cat,
s,@awk@,/bin/awk,
s,@bindir@,/bin,
s,@sbindir@,/usr/sbin,
s,@mandir@,/usr/share/man,
s,@locale@,,
s,@fhs@,# ,
s,@fsstnd@,# ,
s,@man1ext@,1,g
s,@man5ext@,5,g
s,@man8ext@,8,g
s,@man_install_flags@,,
s,@man_user@,,
s,@languages@,en,
s,@man@,/bin/man.exe,
s,@apropos@,/bin/apropos,
s,@whatis@,/bin/whatis,
s,@man2dvi@,/bin/man2dvi,
s,@makewhatis@,/usr/sbin/makewhatis,
s,@man_config_dir@,/usr/lib,
s,@man_config_file@,/usr/lib/man.conf,
s,@manpathoption@,--path,
s/@sections@/1:1p:8:2:3:3p:4:5:6:7:9:0p:tcl:n:l:p:o/
' $infile.in >> $infile
done
