#!/sbin/ksh
#Tag 0x00ff1a02
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
# convert Cosmoworld outputfile to standard VRML on a SGI
# uses /usr/sbin/worldsToVrml and /usr/sbin/imgcopy
if test $# -eq 4; then
# undocumented
IMAGEFORMAT=$3
TMP3=$4
if test -d $2 ; then
echo > /dev/null
else
echo $2 not a directory 1>&2
exit 1
fi
else
TMP3=cosmo2vrml_3_$$.wrl
if test $# -eq 3 ; then
IMAGEFORMAT=$3
else
IMAGEFORMAT=png
if test $# -ne 1 ; then
if test $# -eq 0; then
xterm -geometry 24x5 -e /bin/sh "echo drag a cosmoworldsfile;echo into the icon;echo press return to continue; read"
exit 1
else
echo convert cosmoworld output to standard vrml '(default imageformat png)' 1>&2
echo Usage $0 inputfile '[outputdirectory imageformat]' 1>&2
exit 1
fi
fi
fi
fi
TMP1=/tmp/cosmo2vrml_1_$$/
mkdir -p $HOME/.cosmo2vrml97
TMP2=$HOME/.cosmo2vrml97/cosmo2vrml_2_$$/
mkdir $TMP2
/usr/sbin/worldsToVrml $1 $TMP1
awk -v dirname=`dirname $1` -v tmp2=$TMP2 -v imageformat=$IMAGEFORMAT \
-v ownscript=$0 -v process=$$ ' \
/\"file:.*\"/ \
{ \
flag=1; \
match($0,"file:.*[^\"]"); \
x=substr($0,RSTART+length("file:"),RLENGTH-length("file:")); \
if (substr(x,length(x)-3,4)==".wrl") \
{ \
file="tmp_" process "_" ++filenum ".wrl"; \
system(ownscript " " x " " tmp2 " " imageformat " " file); \
} \
else \
{ \
file="tmp_" process "_" ++filenum "." imageformat; \
system("/usr/sbin/imgcopy " x " " tmp2 file); \
} \
y=$0; \
gsub("file:" x,"./" file,y); \
print y; \
} \
/^/ {if (flag==0) print $0} \
/\"file:.*\"/ {flag=0} \
' $TMP1 > $TMP2/$TMP3
if test $# -ne 4; then
dirview $TMP2
fi