#!/bin/csh -f
#
# Read Sequent DYNIX Maintenance Tape into a proper hierarchy.
# Tape contains tar files with plain filenames; list.delta file contains
#  tape position and pathname info.
# All required subdirectories for the hierarchy must be made beforehand.

set TAPE = /dev/rts0n

# .list format, derived from list.delta:
# 92	custA.h		custA/custA.h

set num = `awk '{print $1}' .list`
set file = `awk '{print $2}' .list`
set dest = `awk '{print $3}' .list`

set lastline = $#num
set firstnum = $num[1]
set lastnum = $num[$lastline]

# Position tape to read file num 1 next (two utility files precede it):
mt -f $TAPE rew
mt -f $TAPE fsf 2
set pos = 1

set line = 1
while ( $line <= $lastline )
    set want = $num[$line]
    if ( $pos < $want ) then
	@ skip = $want - $pos
	mt -f $TAPE fsf $skip
	set pos = $want
    endif
    # This should be $file[$line], if not something went wrong:
    tar xplvf $TAPE
    @ pos++
    # Put it into its proper hierarchy:
    mv $file[$line] $dest[$line]
    echo "Moved to $dest[$line]"
    @ line++
end
