#!/bin/sh
# Cedido al dominio público. 2003. Sin garantías.
# http://structio.sourceforge.net/sigue

if (test ! -f "regval.cls") then {
	echo "Ejecutar desde el directorio con regval.cls";
	exit 1;
} fi;

cp escudo-120.eps /tmp/impresion/

#generación de .dvi
for i in `find "/tmp/impresion/" -name "*.tex"`; do \
	echo $i;
	d=`dirname $i`; \
	echo $d;
	if (test ! -f "$d/regval.cls") then { \
		echo "Enlazando";
		ad=`pwd`;
		for j in *cls; do ln -s $ad/$j $d/$j; done
	} fi;
	ndvi=`echo $i | sed -e  "s/.tex/.dvi/g"`;
	echo $ndvi;
	if (test ! -f "$ndvi" -o "$ndvi" -ot "$i") then {
	(cd $d;  latex `basename $i`; latex `basename $i`); \
	if (test "$?" != "0") then { \
		echo "Problemas procesando $i" > /dev/stderr; \
	} fi; \
	} fi;
done

echo "generación de .ps"
for i in `find "/tmp/impresion/" -name "*.dvi"`; do \
	nps=`echo $i | sed -e  "s/.dvi/.ps/g"`;
	echo $nps;
	if (test ! -f "$nps" -o "$nps" -ot "$i") then {
		(cd `dirname $i`; dvips -o `basename $i .dvi`.ps -t legal `basename $i`); \
		if (test "$?" != "0") then { \
			echo "Problemas procesando $i" > /dev/stderr; \
		} fi; \
	} fi;
done
