#!/usr/bin/perl
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#NAME
#  count - generate a sequence of numbers
#
#SYNOPSIS
#  count [start] end [incr]
#
#REQUIRES
#
#DESCRIPTION
#
#OPTIONS
#
#EXAMPLES
#
#FILES
#
#BUGS
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

$| = 1;
$exitstat = 0;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || $ENV{"D_$P"} || 1;	# Verbose level.

$start = 1;
$end   = 0;
$incr  = 1;

$args = 0;		# Args processed
for $arg (@ARGV) {
	if ($args == 0) {
		if (defined($n = int($arg))) {
			$end = $n;
			++$args;
		} else {
			print STDERR "$P: \"$arg\" is not a number.\n" if $V>0;
		}
	} elsif ($args == 1) {
		if (defined($n = int($arg))) {
			$start = $end;
			$end = $n;
			++$args;
		} else {
			print STDERR "$P: \"$arg\" is not a number.\n" if $V>0;
		}
	} elsif ($args == 2) {
		if (defined($n = int($arg))) {
			$incr = $n;
			++$args;
		} else {
			print STDERR "$P: \"$arg\" is not a number.\n" if $V>0;
		}
	} else {
		print STDERR "$P: Too many args; \"$arg\" ignored.\n" if $V>0;
	}
}

print "$P: start=$start incr=$incr end=$end.\n" if $V>1;
if ($incr > 0) {
	for ($n = $start; $n <= $end; $n += $incr) {
		print "$n\n";
	}
} else {
	print STDERR "$P: Can't handle increment by $incr yet.\n" if $V>0;
	$exitstat = 1;
}

print "$P: Exit with status $exitstat.\n" if $V>1;
exit $exitstat;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
