#! /bin/csh
# Last edited on 2000-10-18 10:44:14 by stolfi

set usage = "$0 FILE..."

if ( $#argv < 1) then
  echo "usage: $usage"; exit 1
endif

foreach infile ( $* )
  set outname = ${infile:r}
  set edfile = "${outname}-ed.pov"
  echo "${infile} -> ${edfile}"

  if ( -r ${infile}.gz ) gunzip ${infile}.gz
  
  if ( ! ( -r ${infile} ) ) then
    echo "${infile} not found"
  else
    /bin/rm -f ${edfile}
    echo '#include "inc-to-pov-header.inc"' >> ${edfile}
    echo 'union{' >> ${edfile}
    cat ${infile} \
      | gawk \
         ' /texture/ { \
             gsub(/^.*\/\/ */, "", $0); \
             printf "    texture { %s_texture_%s }\n", $1, $2; \
             next; \
           } \
           /./ { \
             gsub(/>, 0[.]015/, ">, 0.018", $0); \
             gsub(/>, 0[.]0025/, ">, 0.008", $0); \
             gsub(/^    0[.]0025/, "    0.008", $0); \
           } \
           // { print; } \
         ' \
      >> ${edfile}

    echo 'rotate <0,0,0>' >> ${edfile}
    echo 'rotate <190,10,-50>' >> ${edfile}
    echo 'rotate -15*z' >> ${edfile}
    echo '}' >> ${edfile}
    gzip ${infile} ${edfile}
  endif   
end  
