#!/bin/csh -f
# Author:       Luca Prasso
# Revision Date Thu May 19 10:23:44 CET 1994


set prg = unPad
set ver	= "Version 1.1"

if($#argv < 4) goto Usage

set sequence = $1
set start = $2
set end = $3
set step = $4
set outsequence = $sequence
set extension = pic
set oper = mv
set ask = ""
set dos = 0
set count = 1

while ($count <= $#argv)
        switch ($argv[$count])
                case -e:
                        @ count += 1
                        set extension = $argv[$count]
                        breaksw
                case -o:
                        @ count += 1
                        set outsequence = $argv[$count]
                        breaksw
                case -dos:
                        set dos = 1
                        echo "Dos is ON"
                        breaksw
                case -i:
                        set ask = "-i"
                        breaksw
                case -cp:
                        set oper = cp
                        breaksw
        endsw
        @ count += 1
end


#
# MAIN
#
echo
echo "$prg - $ver"
echo "(c) 1994 The Ray Rebels"
echo
echo "Original Sequence     [$sequence]"
echo "Original Range        [$start-$end-$step]"
echo "New Sequence          [$outsequence]"
echo "Extension             [$extension]"
if($dos == 1) then 
echo "Dos naming            [active]" 
else
echo "Dos naming            [inactive]" 
endif
echo "Renaming operation    [$oper]"
if($ask == "-i") then 
echo "Interactive renaming  [active]" 
else
echo "Interactive renaming  [inactive]" 
endif
echo


#
# MAIN
#
while ($start <= $end)
	if($start < 1000) then
		set frame = 0$start
	endif
	if($start < 100) then
		set frame = 00$start
	endif
	if($start < 10) then
		set frame = 000$start
	endif
	  if($dos == 1) then
                if( -e $sequence.$frame.$extension) then
			$oper $ask $sequence$frame.$extension $outsequence.$start.$extension
		  	echo "Renaming [$sequence$frame.$extension] in [$outsequence.$start.$extension]"
                else
                        echo "Skipping...File [$sequence.$start.$extension] is missing."
                endif
	  else
                if( -e $sequence.$frame.$extension) then
	  		$oper $ask $sequence.$frame.$extension $outsequence.$start.$extension
	  		echo "Renaming [$sequence.$frame.$extension] in [$outsequence.$start.$extension]"
                else
                        echo "Skipping...File [$sequence.$start.$extension] is missing."
                endif
	  endif
	endif
	@ start += $step
end

exit(0)


#
# Usage
#
Usage:
        echo
        echo "$prg - $ver"
        echo "(c) 1994 The Ray Rebels"
        echo
        echo "Usage: $prg <Sequence> <Start> <End> <Step> [options]"
        echo
        echo "Options: -cp       Perform a copy instead a move"
        echo "         -i        Ask before moving or copying"
        echo "         -dos      Activated DOS filename"
        echo "         -o <name> Output File Name"
        echo "         -e <ext>  Extension"
        echo
        echo "This C-Shell remove zeros padding to an existing sequence"
        echo "Default extension is pic"
        echo "Example: file.0001.pic   will become    file.1.pic"
        echo
        echo
exit(1)

