#! moat

#-----------------------------------------------
# Start tclMotif
#

xtAppInitialize -class DumpIt


#-----------------------------------------------
# Define environement
#

set name [lrange $argv 0 0]
set args [lrange $argv 1 100]

proc dumpit {} "
	puts stderr \"Dumping window $name\"
	exec xwd -name $name -frame -out $name.wd $args
	exec xpr -device ps -scale 2 -portrait -psfig -plane 0 -output $name.epsf $name.wd
	exec /bin/rm -f $name.wd
	exit
"
. setValues \
	-title $name \

#-----------------------------------------------
# Parse target file, and filter it
#

set tmpname /tmp/$name.filtered
set top ""

set file [open $name.tcl "r"]
set tmp  [open $tmpname "w"]

while {! [eof $file]} {

	gets $file line
	set cmd [lindex $line 0]

	switch -regexp -- $cmd {
		"^[.]$"
			-
		"xtAppInitialize"
			{}
		"^xm[A-Z]*"
			-
		default
			{	puts $tmp "$line" }
	}
}
close $tmp

#-----------------------------------------
# Read and realize the filtered file
#

source $tmpname
exec rm $tmpname

. realizeWidget
. addInput stdin r {
	read stdin 1
	dumpit
}

. mainLoop dumpit
