#!/bin/sh
# Extract the source from a Monticello Foo.mcz to Foo.st
SRC=snapshot/source.st
if [ "$1" = "-" ]; then
	shift
	for f in "$@"; do
		if [ -f "$f" ]; then
			unzip -c "$f" $SRC
		elif [ -f ~/Cog/package-cache/"$f.mcz" ]; then
			unzip -c ~/Cog/package-cache/"$f.mcz" $SRC
		else
			echo "can't find $f" 1>&2
		fi
	done
else
	for f in "$@"; do
		if [ -f "$f" ]; then
			unzip -c "$f" $SRC >`basename "$f" .mcz`.st
		elif [ -f ~/Cog/package-cache/"$f.mcz" ]; then
			unzip -c ~/Cog/package-cache/"$f.mcz" $SRC >"$f.st"
		else
			echo "can't find $f" 1>&2
		fi
	done
fi
