Tk Library Source Code

View Ticket
Login
Ticket UUID: 551133
Title: csvdiff duplicate key bug
Type: Bug Version: None
Submitter: lvirden Created on: 2002-05-01 19:23:55
Subsystem: csv Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2002-05-10 12:52:19
Resolution: Fixed Closed By: andreas_kupries
    Closed on: 2002-05-10 05:52:19
Description:
csvdiff expects that there are no 'keys' within either
the first or second input files.  This results in
erroneous differences reported currently.

the --help option doesn't mention this limitation and
there is no man page to mention this limitation, so I
will file this behavior as a bug.

I know I'd prefer to have duplicates retained and
diffed...
User Comments: andreas_kupries added on 2002-05-10 12:52:19:
Logged In: YES 
user_id=75003

Patch committed to head.

andreas_kupries added on 2002-05-09 13:13:13:
Logged In: YES 
user_id=75003

Applied the patch manually. Note that the lines opening the
files were removed, not changed. This is wrong and was
corrected. New app sent to Larry for review.

dkf added on 2002-05-02 02:41:05:
Logged In: YES 
user_id=79902

Hmm. People not involved in the project (or the item) can't
attach files. That's a sucky piece of interface design,
SourceForge!  Here's the patch anyway, but with some long
lines chewed about...

Index: csvdiff
===================================================================
RCS file: /cvsroot/tcllib/tcllib/examples/csv/csvdiff,v
retrieving revision 1.1
diff -u -r1.1 csvdiff
--- csvdiff     17 Jan 2002 17:07:25 -0000      1.1
+++ csvdiff     1 May 2002 19:32:08 -0000
@@ -28,7 +28,7 @@
     exit -1
 }

-foreach {inA inB} $argv break
+foreach {fileA fileB} $argv break


 if {[llength $keySpec] == 0} {
@@ -61,8 +61,8 @@
 set keySpec $idx


-set inA [open $inA r]
-set inB [open $inB r]

 # ----------------------------------------------------
 # Actual processing, uses the following information from the
@@ -93,36 +93,48 @@

 set order [list]
 array set map {}
+set linenum 0
 while {![eof $inB]} {
     if {[gets $inB line] < 0} {
        continue
     }
-
+    incr linenum
     set data [::csv::split $line $sepChar]
+
     set key [keyof $data]
-    set map($key) .
+    if {[info exist map($key)]} {
+       puts stderr "warning: $key occurs multiple times in
$fileB (lines $linenum and $map($key))"
+    }
+    set map($key) $linenum
     lappend order $data
 }
 close $inB

+set linenum 0
 while {![eof $inA]} {
     if {[gets $inA line] < 0} {
        continue
     }
+    incr linenum
     set data [::csv::split $line $sepChar]

     set key [keyof $data]
     if {[info exists map($key)]} {
-       unset map($key)
+       if {$map($key) < 0} {
+           puts stderr "warning: $key occurs multiple times
in $fileA (lines $linenum and [expr {-$map($key)}]"
+       } else {
+           set map($key) [expr {-$linenum}]
+       }
        continue
     }

     puts stdout [::csv::join [linsert $data 0 -] $sepChar]
 }
+close $inA

 foreach data $order {
     set key [keyof $data]
-    if {[info exists map($key)]} {
+    if {$map($key) > 0} {
        puts stdout [::csv::join [linsert $data 0 +] $sepChar]
     }
 }