#!/usr/bin/perl
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#NAME
#  lineno - Add line numbers to data
#
#SYNOPSIS
#  lineno [file]..
#
#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.

$wn = 0;
$ws = '';
@files = ();

for $a (@ARGV) {
	if ($a =~ /^\d+$/) {
		$wn = int($a);
		$ws = $wn;
	} elsif (-f $a) {
		push @files, $a;
	} else {
		print STDERR "$0: Arg \"$a\" unknown, ignored.\n" if $V>0;
	}
}
@ARGV = @files;
$fmt = '%' . $ws . 'd	%s';

for $l (<>) {
	$ln ++;
	printf($fmt,$ln,$l);
}

print "$P: Exit with status $exitstat.\n" if $V>1 || ($V>0 && $exitstat>0);
exit $exitstat;

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