#!/bin/csh -f

@ errorflag = 0
if ($#argv != 1) then 
    @ errorflag = 1
else if ( "$1" == "-") then
    @ errorflag = 1
else if ( ! -f $1 ) then
    echo file $1 not found
    @ errorflag = 1
endif

if ($errorflag == 1) then
    echo "usage: cpio_expand <cpio_file>"
    echo
    echo "cpio_expand will expand a cpio file such as a .bmot or a sage file"
    echo "into a directory structure that can then be edited using standard"
    echo "tools, then collapsed back into a regular file using cpio_collapse"
    exit
endif

if ( -d cpio.${1}.dir ) then
    echo directory cpio.${1}.dir already exists.
    echo remove it before continuing.
    exit
endif

mkdir cpio.${1}.dir
cpio -itI $1 > cpio.${1}.contents
echo table of contents for $1 stored in cpio.${1}.contents
cd cpio.${1}.dir
cpio -idI ../$1
echo $1 expanded into the directory cpio.${1}.dir
cd ..
