diff.tcl

Go to the documentation of this file.
00001 /*  MAIN PROGRAM*/
00002 /* */
00003 /*  Usage:*/
00004 /*        diff.tcl file1 file2*/
00005 /* */
00006 /*  Output:*/
00007 /*        Puts out a list of lines consisting of:*/
00008 /*                n1<TAB>n2<TAB>line*/
00009 /* */
00010 /*        where n1 is a line number in the first file, and n2 is a line number in the second file.*/
00011 /*        The line is the text of the line.  If a line appears in the first file but not the second,*/
00012 /*        n2 is omitted, and conversely, if it appears in the second file but not the first, n1*/
00013 /*        is omitted.*/
00014 
00015 lappend auto_path \
00016     [file join \
00017     [file dirname [file dirname [file dirname [file dirname [file join [pwd] [info script]]]]]] \
00018     modules struct]
00019 package require struct
00020 
00021 /*  Open the files and read the lines into memory*/
00022 
00023                       f1 =  [open [lindex $argv 0] r]
00024  lines1 =  [split [read $f1] \n]
00025 close                   $f1
00026 
00027                       f2 =  [open [lindex $argv 1] r]
00028  lines2 =  [split [read $f2] \n]
00029 close                   $f2
00030 
00031  i =  0
00032  j =  0
00033 
00034 ::struct::list assign [::struct::list longestCommonSubsequence $lines1 $lines2] x1 x2
00035 
00036 foreach p $x1 q $x2 {
00037     while { $i < $p } {
00038      l =  [lindex $lines1 $i]
00039     puts "[incr i]\t\t$l"
00040     }
00041     while { $j < $q } {
00042      m =  [lindex $lines2 $j]
00043     puts "\t[incr j]\t$m"
00044     }
00045      l =  [lindex $lines1 $i]
00046     puts "[incr i]\t[incr j]\t$l"
00047 }
00048 while { $i < [llength $lines1] } {
00049      l =  [lindex $lines1 $i]
00050     puts "[incr i]\t\t$l"
00051 }
00052 while { $j < [llength $lines2] } {
00053      m =  [lindex $lines2 $j]
00054     puts "\t[incr j]\t$m"
00055 }
00056 
00057 exit
00058 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1