#!/bin/sh -f
#
# Fig2ps2tex - generate a TeX file for including a PostScript file
#		 involves calculating the bounding box from fig2ps output
# version for systems without csh -- uses bc and awk
#
# Copyright 1994 Micah Beck
#
# The X Consortium, and any party obtaining a copy of these files from
# the X Consortium, directly or indirectly, is granted, free of charge, a
# full and unrestricted irrevocable, world-wide, paid up, royalty-free,
# nonexclusive right and license to deal in this software and
# documentation files (the "Software"), including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons who receive
# copies from any such party to do so, with the only requirement being
# that this copyright notice remain intact.  This license includes without
# limitation a license to do the foregoing actions under any patents of
# the party supplying this software to the X Consortium.
#
# Changes
#
# 2016-07-07  Thomas Loimer
#	* use here-document, instead of echo
#

bbox=`grep "^%%BoundingBox:" $1`

bbox2=`echo $bbox | awk '{print $2}'`
bbox3=`echo $bbox | awk '{print $3}'`
bbox4=`echo $bbox | awk '{print $4}'`
bbox5=`echo $bbox | awk '{print $5}'`

xsp=`echo "scale=3; ( $bbox4 - $bbox2 ) / 72" | bc`
ysp=`echo "scale=3; ( $bbox5 - $bbox3 ) / 72" | bc`

cat <<EOF
\\makebox[${xsp}in][l]{
  \\vbox to ${ysp}in{
    \\vfill
    \\special{psfile=$1}
  }
  \\vspace{-\\baselineskip}
}
EOF
