#!/bin/sh
# cctgif
#
# Script to get a gif file at fairly low resolution from a Circuit Macros
# file, suitable for the Web.
#
# Last Updated 13 July 1999. Alan Robert Clark a.clark@ee.wits.ac.za
# Redhat 7.0's version of pnmmargin now explicitly needs to be told -white!
# Change made on 16 March 2001.
#
# First copy the file to the classic ccteg, sans stomping, and process!
for i do
  filpath=`dirname $i`
  fn=$filpath/`basename $i .m4`
  if [ -e $fn.m4 ]
   then
     if [ ! -e ccteg.m4 ]
       then 
         echo -e "\n\n\nProcessing $fn.m4\n"
         cp $fn.m4 ccteg.m4
         m4 ccteg.m4 | gpic -t > ccteg.cct
         if [ ! -e ccteg.tex ]
           then 
             cp /usr/local/bin/ccteg.tex .
         fi
         latex ccteg.tex
         dvips -o ccteg.ps ccteg
         gs -sDEVICE=ppmraw -r150 -sOutputFile=- -sNOPAUSE -q ccteg.ps \
            -c showpage -c quit | pnmcrop| pnmmargin -white 10 | ppmtogif \
            >$fn.gif
         rm ccteg*   
       else
         echo "ccteg.m4 already exists, delete it first after checking it!"
     fi    
   else 
     echo "$fn.m4 does not exist!"
  fi     
done
