#!/dfs/devel/ipn/bin/perl ############################################################################## # listfields - List verity collection fields # # (c) Copyright Delphion, Inc. 2000 # Portions (c) IBM Corporation 2000 # Delphion Confidential - DO NOT DISTRIBUTE # # The source code for this program is not published or otherwise divested of # its trade secrets, irrespective of what has been deposited with the U.S. # Copyright Office. # # $Header: /cvsroot_ipsfdb2/ipscheck/cmp_verity2db/listfields,v 1.2 2000/08/09 22:27:23 sander Exp $ # # $Log: listfields,v $ # Revision 1.2 2000/08/09 22:27:23 sander # added copyrights # # ############################################################################## #00/06/29 sjb v1.0 Initial version, used v1.2 of listpartnrs use IPC::Open2; if($#ARGV < 0) { print "\n$0 v1.0\n"; print "List one or more field values of all records in Verity partition "; print "files or Verity collections\n"; print "Usage: $0 [-s] [-d] [] [] [] \n"; print " -s = Sort result\n"; print " -d = Show deleted records only\n"; print "By default the field name is VdkVgwKey, only non-deleted records are shown and the result s not sorted\n\n"; exit 1; } $program = "browse"; $tmpfn = "/tmp/$0.$$.tmp"; foreach (@ARGV) { if($_ eq "-s") { # Enable sorting? $sort = 1; } elsif($_ eq "-d") { # Show deleted patents only (don't show them by default)? $sd = 1; } elsif(-d $_) { # A directory? $dir = "$_/parts"; if(!opendir DIR, "$dir") { print STDERR "Error opening directory \"$dir\"\n"; exit 2; } while($fn = readdir DIR) { if(-e "$dir/$fn" && $fn =~ /^\d*\.ddd$/) { # Process .ddd files only push @partfn, "$dir/$fn"; } } } elsif(-e $_) { # An existing file? if($_ =~ /^.*\.ddd$/) { # Process .ddd files only push @partfn, "$_"; } else { print STDERR "Illegal argument \"$_\"\n"; exit 3; } } else { push @field, "$_" if($_ ne "_SECURITY"); } } push @field, "VdkVgwKey" if($#field == -1); if($#partfn == -1) { print STDERR "No input files\n"; exit 4; } open TMP, ">$tmpfn"; $SIG{'INT'} = 'handler'; foreach $filename (@partfn) { # $filename eg "/arc/coll/coll_be/parts/00000235.ddd" print STDERR "$filename: "; eval { open2(\*README, \*WRITEME, $program . " " . $filename); }; if($@) { if($@ =~ /^open2/) { warn "open2 failed: $!\n$@\n"; return; } die; } print WRITEME "v\n-1\n"; foreach (@field) { print WRITEME "$_\n"; } print WRITEME "_SECURITY\n"; print WRITEME "\n0\n"; $i = 0; $ndoc = 0; $ndel = 0; while($output = ) { if($output =~ /\d*\s*(\S*)\s*.*= *(.*)/) { $id = $1; $value = $2; if($value =~ /records/) { print WRITEME "q\n"; last; } $vals{$id} = "$value"; $i++; if($i > $#field + 1) { $ndoc++ if($vals{"_SECURITY"} ne "2147483648"); $ndel++ if($vals{"_SECURITY"} eq "2147483648"); if(($sd && $vals{"_SECURITY"} eq "2147483648") || (!$sd && $vals{"_SECURITY"} ne "2147483648")) { for($j = 0; $j < $#field; $j++) { print TMP "$vals{$field[$j]}\t"; } print TMP "$vals{$field[$#field]}\n"; %vals = (); } $i = 0; print WRITEME "\n"; } } elsif($output =~ /is not a field name/) { print STDERR "\nUnknown field name, one of:\n"; foreach (@field) { print "$_\n"; } exit 5; } } print STDERR $ndoc + $ndel . " docs ($ndoc active + $ndel deleted)\n"; close(WRITEME); close(README); } close(TMP); if($sort) { print STDERR "Sorting...\n"; `sort $tmpfn > $tmpfn.s`; `mv $tmpfn.s $tmpfn`; } open TMP, "$tmpfn"; while() { print "$_"; } close(TMP); unlink "$tmpfn"; sub handler { unlink "$tmpfn"; print STDERR "Temporary file \"$tmpfn\" removed\n"; $SIG{'INT'} = 'DEFAULT'; exit 1; }