#!/usr/bin/perl -w # # dbrowuniq # Copyright (C) 1997-1998 by John Heidemann # $Id: dbrowuniq,v 1.15 2003/05/23 04:17:50 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 <getopt) { $ch = $dbopts->opt; if ($ch eq 'c') { $do_count = 1; } elsif ($ch eq 'd') { $debug++; } else { &usage; }; }; &readprocess_header; my($count_f); if ($do_count) { $count_f = &col_create('count'); }; my(@uniqifying_columns) = (0..$#colnames); if ($#ARGV >= 0) { @uniqifying_columns = (); foreach (@ARGV) { die ("$prog: unknown column ``$_''.\n") if (!defined($colnametonum{$_})); push (@uniqifying_columns, $colnametonum{$_}); }; }; $code = '1'; foreach (@uniqifying_columns) { next if (defined($count_f) && $_ == $count_f); $code .= " && (\$last_f[$_] eq \$f[$_])"; }; print $code if ($debug); &write_header(); sub handle_new_row { @last_f = @f; $count = 1; } sub handle_old_row { my($eof) = @_; &delayed_flush_comments() if (!$eof); $last_f[$count_f] = $count if ($do_count); &write_these_cols(@last_f); &delayed_flush_comments() if ($eof); } @last_f = (); $count = 0; my($loop) = q[ while () { &delayed_pass_comments() && next; &split_cols; if ($#last_f != -1) { if (] . $code . q[) { # identical $count++; next; } else { # not identical &handle_old_row(0); &handle_new_row(); }; } else { # first row &handle_new_row(); }; }; # handle last row &handle_old_row(1); ]; eval $loop; $@ && die "$prog: internal eval error: $@\n"; $code =~ s/\n/ /g; # otherwise comments break print "# | $prog ", join(" ", @orig_argv), "\n"; exit 0; # compiler stuff @f = @colnames = ();