Larry
unread,Dec 6, 2009, 1:12:20 PM12/6/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to GoogleSemWare TSE, TsePro
/***
This is not what Knud asked for, but a variation of the idea was worth
exploring. This approach works well for two files that may have subtle
differences, such as typos, added or removed words, and a few added or
deleted lines that are relatively close together.
This macro uses a "threshhold" idea that limits the lines that are
searched for differences. This prevents the macro from finding
differences too far up or down the files that would probably not be
related. Setting the threshhold variable larger or smaller defines the
number of lines above and below the current line that will be searched.
Setting the threshhold value to 1 would make the macro do a line-by-line
comparison. Setting the threshhold value to 0 would cause the macro to
canvas the entire file (and probably lead to imprecise results unless
every line is unique).
***/
// ----- macro source begins here -----
// jigcompare.s - compare two files for differences and produce a "report"
<ctrlshift 1> execmacro("jigcompare")
<ctrlshift 2> execmacro("jigcompare")
/*** Notes:
jigcompare.mac will compare two loaded files for differences and produce
two "report" reference files containing the lines where differences occur.
The two reference files are given the original respective filenames with
a random number tacked onto the extension. They are kept in TSE but are
not saved.
The original files are NOT changed.
No pretense is made that this is an in-depth comparison of the two files.
Assumptions:
1. that lines are string length (255) or less;
2. blank lines are ignored;
3. that differences between the two files are subtle, which means that
the differences are expected to be within lines that are relatively
close together; the "threshhold" integer determines how far ahead or
behind a current line to look for line differences. The default is 10
lines above and 10 lines below.
(Note: if you set the threshhold to zero (integer threshhold=0), the
macro will look through the whole file to find line matches, making the
results less precise.)
Procedure:
1. load the two files into TSE
2. make one of them the current file
3. press CtrlShift 1
4. a message box opens telling you to go to file 2
5. go to the file 2
6. press CtrlShift 2
7. a summary box opens
8. the macro ends with the first "report" file as the current file
9. the two reference files are side-by-side
10. the two original files are side-by-side as the next two files after
the second reference file
It is possible to adapt the macro to canvas a directory or two
directories and compare selected files, but this macro only compres
two loaded files as described.
This comparison method is useful to me because I save all of my file
revisions to filenames with revision numbers and, occasionally, I get
"lost" trying to remember some of the changes I make from revision to
revision (especially if a change breaks something!). This may help. :)
***/
// local globals
string fn1[_maxpath_]=""
string fn2[_maxpath_]=""
integer tb=0
integer tb1=0
integer tb2=0
integer nl1=0
integer nl2=0
proc main()
string a[255]=""
integer i=0
integer bl=0
integer el=0
integer k=query(key)
integer numdif1=0
integer numdif2=0
// number of lines to examine for differences - change to suit
integer threshhold=10 // 10 lines above to 10 lines below current line
case k
// identify first file
when <ctrlshift 1>
fn1=currfilename()
if filechanged()
savefile()
endif
changecurrfilename(fn1+"-"+rightstr(str(gettime()),4))
tb1=getbufferid()
nl1=numlines()
sound(6000,1)
warn("Goto file 2 and press Ctrlshift 2...")
goto ending
// identify second file
when <ctrlshift 2>
if tb1
fn2=currfilename()
if filechanged()
savefile()
endif
changecurrfilename(fn2+"-"+rightstr(str(gettime()),4))
tb2=getbufferid()
nl2=numlines()
else
sound(20,10)
warn("Use CtrlShift first, then CtrlShift 2")
goto ending
endif
endcase
if tb2
// identify and remove exact matches in both files
for i=1 to nl1
gotobufferid(tb1)
gotoline(i)
if currlinelen()
a=gettext(1,currlinelen())
gotobufferid(tb2)
gotoline(i)
bl=1
el=numlines()
if threshhold
el=currline()+threshhold
if currline()>threshhold
bl=currline()-threshhold
endif
if currline()<numlines()-threshhold
el=numlines()
endif
endif
markline(bl,el)
if lfind(a,"gl^") and currlinelen()==length(a)
lreplace(a,"","gcn")
gotobufferid(tb1)
lreplace(a,"","gcn")
endif
unmarkblock()
gotobufferid(tb1)
endif
endfor
// add line numbers to report file 1
gotobufferid(tb1)
for i=1 to nl1
gotoline(i)
if currlinelen()
begline()
inserttext(str(currline())+": ",_insert_)
numdif1=numdif1+1
endif
endfor
// remove blank lines in report file 1
while lfind("^$","ngx")
delline()
endwhile
begfile()
filechanged(false)
gotobufferid(tb2)
// add line numbers to report file 2
for i=1 to nl2
gotoline(i)
if currlinelen()
begline()
inserttext(str(currline())+": ",_insert_)
numdif2=numdif2+1
endif
endfor
// remove blank lines in reort file 2
while lfind("^$","ngx")
delline()
endwhile
begfile()
filechanged(false)
// reload original files
editfile(fn1)
editfile(fn2)
gotobufferid(tb1)
sound(12000,5)
// show the "report"
tb=createtempbuffer()
addline()
addline("There are at least: (differences) (lines) between the two iles,")
addline()
addline(rightstr(fn1,60)+" ("+str(numdif1)+") ("+str(nl1)+")")
addline(rightstr(fn2,60)+" ("+str(numdif2)+") ("+str(nl2)+")")
addline()
addline("The remaining lines in both report files are where the
differences")
addline("occurred in the respective original files.")
addline("The line numbers in the report files are the actual")
addline("line numbers within each original file.")
addline("The original files were NOT changed.")
msgboxbuff("JigCompare Summary",_ok_,tb)
abandonfile(tb)
fn1=""
fn2=""
tb=0
tb1=0
tb2=0
endif
goto ending
ending:
end
// ----- macro source ends here -----