#!/bin/sh
if [ $# = 0 ]; then
  echo "Usage: $0 <file to translate>"
  exit 0
fi

SOURCE=$1
TARGET=`basename ${SOURCE}`.texi
TMPTAR=${TARGET}.tmp

awk=`type gawk 2>/dev/null`
if [ x"$awk" = x ]; then
   awk="awk"
else
   awk="gawk"
fi

$awk 'BEGIN{out=1}$1=="end"&&substr($0,1,1)=="e"{out=1}out==1{print}$1=="private"&&out==1{out=0; print "   --  implementation removed"}' ${SOURCE} > genout

rm -f ${TMPTAR}

if [ $# = 1 ]; then
echo "@cartouche"        >>${TMPTAR}
fi
echo "@smallexample"     >>${TMPTAR}
if [ $# = 1 ]; then
echo "@group"            >>${TMPTAR}
fi
echo ""                  >>${TMPTAR}
sed -f ada.sed genout    >>${TMPTAR}
echo ""                  >>${TMPTAR}
if [ $# = 1 ]; then
echo "@end group"        >>${TMPTAR}
fi
echo "@end smallexample" >>${TMPTAR}
if [ $# = 1 ]; then
echo "@end cartouche"    >>${TMPTAR}
fi

cat ${TMPTAR} | tr -d '\r' > ${TARGET}
rm ${TMPTAR}
