#! /bin/csh -f
#
#/*****************************************************************************
#                Copyright Carnegie Mellon University 1992
#
#                      All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of CMU not be
# used in advertising or publicity pertaining to distribution of the
# software without specific, written prior permission.
#
# CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
# CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
#*****************************************************************************/
#
#
# iff2ciff
#
# Compress .iff file by removing extra newlines idempotently. Output goes to
# stdout.
#
# $Header: iff2ciff,v 1.2 91/11/05 11:53:42 heydon Exp $

# Remove temp files on interrupt
#
onintr end

if ($#argv == 0) then
	set file = /tmp/iff_$$
	set dorm
	cat > $file
else
	set file = $1
endif

if ($#argv > 1) then
	echo "Usage:    $0  [iff-file]"
	exit 1
endif

if (! (-r "$file")) then
	echo $0":  Couldn't access $file, sorry!"
	exit 1
endif

set count = (`wc -wl $file`)
#
#  Make sure it hasn't already been compressed.  Here I'm guessing that
#  most of the .iff files will have very few words per line
#

@ ratio = $count[1] / $count[2]
if ($ratio < 4) then
	/usr/miro/bin/rmnl < $file
else
	cat $file
endif

end:
if ($?dorm) rm -f $file
