#!/usr/bin/perl

#
# dbrowenumerate
# Copyright (C) 1991-1998 by John Heidemann <johnh@isi.edu>
# $Id: dbrowenumerate,v 1.8 1999/11/23 02:04:29 johnh Exp $
#
# This program is distributed under terms of the GNU general
# public license, version 2.  See the file COPYING
# in $dblibdir for details.
#

sub usage {
    print <<END;
usage: $0 
	Add a ``count'' column, incremented for each row of data.

Sample input:
#h account passwd uid gid fullname homedir shell
johnh * 2274 134 John_Heidemann /home/johnh /bin/bash
greg * 2275 134 Greg_Johnson /home/greg /bin/bash
root * 0 0 Root /root /bin/bash
# this is a simple database

Command:
cat DATA/passwd.jdb | dbrowenumerate

Sample output:
#h account passwd uid  gid fullname       homedir     shell     count 
johnh      *      2274 134 John_Heidemann /home/johnh /bin/bash 0     
greg       *      2275 134 Greg_Johnson   /home/greg  /bin/bash 1     
root       *      0    0   Root           /root       /bin/bash 2     
# this is a simple database
#  | /home/johnh/BIN/DB/dbrowenumerate 

END
    exit 1;
}

BEGIN {
    $dblibdir = "/usr/local/lib/jdb";
    push(@INC, $dblibdir);
}
require "$dblibdir/dblib.pl";
use DbGetopt;



@orig_argv = @ARGV;
my($prog) = &progname;

my($dbopts) = new DbGetopt("?", \@ARGV);
my($ch);
while ($dbopts->getopt) {
    $ch = $dbopts->opt;
    if ($ch eq '') {
    } else {
	&usage;
    };
};


&usage if ($#ARGV != -1);



&readprocess_header;

$count = 0;
$count_f = &col_create('count');

&write_header();

while (<STDIN>) {
    &pass_comments && next;
    &split_cols;
    $f[$count_f] = $count++;
    &write_cols;
};

print "#  | $prog " . join(" ", @orig_argv) . "\n";
exit 0;

