#!/bin/sh
# -*- perl -*-
# This code allows us to start perl from our path or an environment variable
# rather than hardcoding a path into the #! line.  It works from sh or csh.
(exit $?0) && eval 'exec ${QPERLQ-perl} -x $0 ${1+"$@"}'
if (! $?QPERLQ) setenv QPERLQ perl
exec $QPERLQ -x $0 $argv:q

#!/usr/local/bin/perl -w
#
# $Id: fill-tape,v 1.8 1999/03/10 23:03:27 ejb Exp $
# $Source: /home/ejb/scripts/RCS/fill-tape,v $
# $Author: ejb $
#
# This script writes five megabytes at a time to a tape drive trying to
# fill it up.
#


$whoami = ($0 =~ m,([^/]*)$,) ? $1 : $0;

&usage if (@ARGV != 1);

if ($ARGV[0] eq "random")
{
    $random = 1;
}
elsif ($ARGV[0] eq "zero")
{
    $random = 0;
}
else
{
    &usage;
}


select(STDERR); $| = 1;
select(STDOUT); $| = 1;
$tape = $ENV{'TAPE'} || "/dev/nrst17";
$n = 0;

$nmeg = 1;
$length = $nmeg * (2 ** 15);

open(TAPE, ">$tape") || die "$whoami: can't open $tape read/write: $!\n";

if ($random)
{
    $rand_blocks = 20;
    srand;
    $string = "";
    for ($i = 0; $i < $length/$rand_blocks; $i++)
    {
	# For perl 4, use
	#    $string .= pack (C, (int(rand 255)));
	$string .= chr(int(rand 255));
    }
    
    $string = $string x $rand_blocks;
}
else
{
    $string = chr(0) x $length;
}

while (1)
{
    $n++;
    syswrite(TAPE, $string, $length) ||
	die sprintf("Write failed after %d blocks: %s\n", $n, $!);
    printf("Wrote %d block%s.\n", ($t = $n * $nmeg), ($t == 1 ? "" : "s"));
}

close(TAPE);

sub usage {
    print STDERR "Usage: $whoami { random | zero }\n";
    exit 1;
}
