#!/usr/bin/perl

#
# dbcoltighten
# Copyright (C) 1991-1998 by John Heidemann <johnh@isi.edu>
# $Id: dbcoltighten,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
    Removes extra space between columns.
    The opposite of dbcolneaten.

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
#  | dbcolneaten

Sample command:
cat data.jdb | dbcoltighten

Sample output:
#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
#  | dbcolneaten
#  | dbcoltighten

Bugs:
Doesn't tighten the header line.
END
    #' font-lock hack
    exit 1;
}

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

my(@orig_argv) = @ARGV;
my($prog) = &progname;
my($dbopts) = new DbGetopt("?", \@ARGV);
my($ch);
while ($dbopts->getopt) {
    $ch = $dbopts->opt;
    if (0) {
    } else {
	&usage;
    };
};
$usage if ($#ARGV != -1);

while (<STDIN>) {
	if ($_ =~ /^\#/) {
		print $_;
		next;
	};

    	s/\t/ /g;
	s/[ \t]{2,}/ /g;
	print $_;
};

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

