#!/usr/bin/perl -w # # dbrowsplituniq # Copyright (C) 1997-1998 by John Heidemann # $Id: dbrowsplituniq,v 1.3 2003/05/23 04:15: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 'T') { $test_suite = 1; } elsif ($ch eq 'p') { $prefix = $dbopts->optarg; } elsif ($ch eq 'd') { $debug++; } else { &usage; }; }; &usage if ($#ARGV == -1); &readprocess_header; 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 = '$key = ""'; foreach (@uniqifying_columns) { $code .= " . \$f[$_]"; }; $code .= ";\n"; print $code if ($debug); my($index) = 0; my(%keys_to_paths); sub key_to_path { my($key) = @_; # also handles new keys return $keys_to_paths{$key} if (defined($keys_to_paths{$key})); my($path) = $prefix . $index . ".jdb"; $index++; $keys_to_paths{$key} = $path; open $fh, ">>$path"; write_header_fh_tag($fh, $col_headertag); return $path; } my($loop) = q[ while () { &delayed_pass_comments() && next; &split_cols; ] . $code . q[ my($path) = &key_to_path($key); open $fh, ">>$path"; write_these_cols_fh($fh, @f); }; # cleanup foreach (values %keys_to_paths) { open $fh, ">>$_"; delayed_write_comments($fh); print $fh "# | $prog ", join(" ", @orig_argv), "\n"; close $fh; }; ]; print $loop if ($debug); eval $loop; $@ && die "$prog: internal eval error: $@\n"; # # for the test suite, concatinate the output files # if ($test_suite) { # minor xxx: lexographic order :-( my($fn); foreach $fn (sort values %keys_to_paths) { open(IN, "<$fn") || die "$prog: cannot reopen $fn\n"; print "*** $fn\n"; while () { print $_; }; close(IN); unlink($fn) if (!$debug); # clean up after ourselves }; }; exit 0; # compiler stuff @colnames = @orig_argv = (); $col_headertag = "";