diff2.tcl

Go to the documentation of this file.
00001 /*  MAIN PROGRAM*/
00002 /* */
00003 /*  Usage:*/
00004 /*        diff2.tcl file1 file2*/
00005 /* */
00006 /*  Output:*/
00007 /*        Puts out a list of lines describing the changes from file1 to file2*/
00008 /*  in a format similar to 'patch'. It not the same as patch, but could*/
00009 /*  be modified to be exactly the same.*/
00010 
00011 lappend auto_path \
00012     [file join \
00013     [file dirname [file dirname [file dirname [file dirname [file join [pwd] [info script]]]]]] \
00014     modules struct]
00015 package require struct
00016 
00017 /*  Open the files and read the lines into memory*/
00018 
00019                       f1 =  [open [lindex $argv 0] r]
00020  lines1 =  [split [read $f1] \n]
00021 close                   $f1
00022 
00023                       f2 =  [open [lindex $argv 1] r]
00024  lines2 =  [split [read $f2] \n]
00025 close                   $f2
00026 
00027  i =  0
00028  j =  0
00029 
00030 ::struct::list assign [::struct::list longestCommonSubsequence $lines1 $lines2] x1 x2
00031 
00032  chunks =  0
00033 foreach chunk [::struct::list lcsInvert2 $x1 $x2 [llength $lines1] [llength $lines2]] {
00034      chunks =  1
00035     puts ===========================================
00036     puts $chunk
00037     puts -------------------------------------------
00038 
00039     ::struct::list assign [lindex $chunk 1] b1 e1
00040     ::struct::list assign [lindex $chunk 2] b2 e2
00041 
00042     switch -exact -- [lindex $chunk 0] {
00043     changed {
00044         puts "< [join [lrange $lines1 $b1 $e1] "\n< "]"
00045         puts "---"
00046         puts "> [join [lrange $lines2 $b2 $e2] "\n> "]"
00047     }
00048     added   {
00049         puts "> [join [lrange $lines2 $b2 $e2] "\n> "]"
00050     }
00051     deleted {
00052         puts "< [join [lrange $lines1 $b1 $e1] "\n< "]"
00053     }
00054     }
00055 }
00056 if {$chunks} {
00057     puts ===========================================
00058 }
00059 
00060 exit
00061 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1