/*** C2fc.s - compare 2 files using an auto-swapping visual inspection
method
C2fc was written with TSE PRO 4.4 but compiles and works with TSE 2.5.
(Actually, it runs better on TSE 2.5 than on 4.4...the screen updates
are much faster...no flicker.)
Characteristics:
===================
1. The macro is simple and intuitive.
2. It works on two files at a time.
3. It can be sped up or slowed down
4. It can be exited and resumed on the same two files.
5. It does not make any changes on the two files being compared.
6. While the compare is working, keys are available to roll the text up
or down on both files or on the visible file, page up and page down
on both files, go to top or end of both files, go to the same line in
both files, and the macro can be paused.
7. After exiting, an assigned key switches from one file to the other
even if they are not together.
8. The two file selection prompts allow you to list the open files, go
to previous file, go to next file, use a PickList, or choose a file
from the macro's custom history.
The macro uses prompts to set up the two files and a prompt to resume,
and every prompt has its own help file. There is also an Overview file
to generally discuss the macro's characteristics.
The basic strategy for starting or resuming a file comparison session is
to prepare the two files such that the same line in both files is at the
top of the screen, then execute the macro. Once the macro starts, you
can easily set the 1/2 second default start speed to what is most
comfortable.
When you identify a difference that you want to edit, you press the ESC
key to stop the macro, make the editing change, then execute the macro
again and resume the swapping comparisons.
Limitations:
===============
1. The cursor line always remains at the top of the current window.
2. The visual field is limited to the current window width...no left or
right scrolling is supported. However, if the text is scrolled before
starting the macro, the text in those columns is what is visible.
I suppose the theme song for this macro should be Sinead O'Conner's
"Nothing Compares To You". :)
http://www.youtube.com/watch?v=zJEIJAPMPvI
Enjoy.
(FYI: Let's see...we have C2fa and C2fc...but where is C2fb? :) Well,
C2fb was supposed to be a macro that compared two files for
out-of-sequence lines. The goal seems simple enough...note paragraphs
that are out of sequence with each other, then note lines within
paragraphs that out of sequence with each other...report the results.
Problem is, just how to do that and how to report it. As Data would say,
"Processing..." :) Be nice if I could work it the way the mind works
memories...they are all there, but the mind has ways of identifying them
from each other so they can be found when needed (except when taking a
test, of course.:)) After all, a memory is not just a spot but is a
bunch of spots and many bunches of spots are similar to each other.
Somehow, the mind knows the differences and tends to pick the right
bunch of spots when needed. Giving a macro that kind of insight has
proven to be elusive so far...)
***/
// c2fc.s - compare 2 files using an auto-swapping visual inspection mothod
string rev[50]="C2fcRev1014"
// assigned execute key:
<ctrlshift c><c> execmacro("C2fc")
/***
{This Revision:}
1014- 20130421- okay, clean it up...test
- changed rolling up/down method and keys
- added top/end of file keys
- removed <pause> to be compatible with tse 2.5
- no sounds
- added go to line number
- changed top/end of file to support horizontally scrolled
text
1013- 20130421- adding helps, cleanup
1012- 20130419- changing dwell delay method
- added purgemacro to resume prompt
- adding resume prompt help and keys
- good additions...
1011- 20130417- adding resume/new prompt
- simplifying action keys
- adding conditionals to assigned keys
1010- 20130414- update with new things from c2fa
1009- 20130414- safe save
1008- 20130406- testing...
- added alt 1 and alt 2 assigned keys to go to file 1 or file
2
after the macro is quit
- added goto current file when escape pressed when macro is
quit
1007- 20130406- safe save
- still have 'match' to do...
1006- 20130406- now match keys in show key display...
1005- 20130405- do fn2: done but not tested...
- change the active keys while swapping so that
rollup/rolldown
work on both files and individual files
- add match fn1 to fn2 or fn2 to fn1 top lines
- not sure if i need cursor movement...
1004- 20130405- adding file selection prompts with next/prev file ability
- fn1 works
1003- 20130404- add file 1/file 2 routine from C2FARev2003
1002- putting movement into proc mC2fcActionKeys()
- considering set(attr gotoxy and putstr for key list
1001- first take...
- add speed control
- add keyboard keys
- add delay
- add message
***/
// local globals
string fn1[255]="" // file 1 filename
string fn2[255]="" // file 2 filename
string xfil[255]="" //
integer tb1=0 // file 1 buffer id
integer tb2=0 // file 2 buffer id
integer quit=0 // quit macro flag
integer sk=1 // show keys flag
integer bad=0 // loop break out flag
integer nf=0 // number of open files
integer c2fc_hist=0 // custom c2fc history list
integer vdt=9 // viewing dwell time
helpdef overview
title="Overview of the C2fc Macro (C2fcRev1014)"
""""
"Macro Name: Compare 2 Files by Auto-Swap Method"
"Macro Version: C2fcRev1014"
""
"Assigned Keys:"
"================"
"<CtrlShift c><c> execute macro"
"<CtrlShift SpaceBar> switch between compared files after quitting macro"
"<Alt h> Overview help screen"
""
"The C2fc macro allows you to visually inspect two files for differences."
"The two files to be compared are automatically swapped as the macro"
"runs. The speed of the swapping can be increased or decreased using the"
"keys below as the macro runs."
""
"The two files do not have to be together in the file ring."
""
"As the files are swapped, you can check for differences that you see. If"
"you see a difference you want to edit, press the ESC key to stop the"
"macro and make you changes."
""
"After successfully executing the macro and selecting the two files, you"
"can stop the macro at any time and then resume on the same two files by"
"executing the macro again."
""
"The macro uses three prompts:"
"==============================="
"1. First: select first file to compare"
"2. Second: select second file to compare"
"3. Resume: after executing the macro and choosing the two files to"
" compare, then quitting the macro, executing the macro again brings"
" up this prompt where you can choose to Resume comparing the current"
" two files, Select two other files to compare, or Purge the macro."
""
"Each of the prompts has its own help screen and custom keys to aid the"
"selection of the two files."
""
"The best way to start with the two files is to make the window displays"
"of both files as nearly aligned as possible such that the top line of"
"each file is the same. Once this is done, subtle adjustments can be made"
"while the macro is running using the cursor keys."
""
"The keys available as the macro executes:"
"============================================"
"ESC Quit"
"Pgup Page Up"
"Pgdn Page Down"
"Cursorup RollUp Visible"
"Cursordown RollDown Visible"
"Cursorleft Roll Up Both"
"Cursorright Roll Down Both"
"Home Top of Both Files"
"End End of Both Files"
"G Go To Line Both Files"
"F Faster"
"S Slower"
"P Pause"
"F1 Overview"
"D This Display"
""
"The above keys produce instant updated results for the current file"
"being viewed."
""
end
helpdef file1help
title="Choosing File 1 Help"
""
"This first prompt allows you to select the first of the two files to"
"compare. It expects that the file has already been loaded, but will load"
"the file if needed."
""
"This prompt offers a variety of ways to select the file:"
"1. F2: List Open Files"
"2. F3: Pick a file from a directory"
"3. F5: Previous File"
"4. F6: Next File"
"5. CursorDown: History"
"6. Manual Entry of the file path/name"
""
"Once a file is selected, the macro remembers it as: Fn1"
""
end
helpdef file2help
title="Choosing File 2 Help"
""
"This second prompt works exactly the same as the first prompt."
""
"This second prompt allows you to select the second of the two files to"
"compare. It expects that the file has already been loaded, but will load"
"the file if needed."
""
"This prompt offers a variety of ways to select the file:"
"1. F2: List Open Files"
"2. F3: Pick a file from a directory"
"3. F5: Previous File"
"4. F6: Next File"
"5. CursorDown: History"
"6. Manual Entry of the file path/name"
""
"Once a file is selected, the macro remembers it as: Fn2"
""
"The macro now immediately begins the swapping routine. Each of the two"
"files is presented for viewing for a timed duration. The macro can be"
"stopped at any time for editing either of the two files."
""
end
// show the keys
proc mshowkeys()
set(attr,159)
gotoxy(query(windowcols)-33,4) putstr(rev)
gotoxy(query(windowcols)-33,5) putstr("Key: Purpose:")
gotoxy(query(windowcols)-33,6) putstr("ESC Quit")
gotoxy(query(windowcols)-33,7) putstr("Pgup Page Up")
gotoxy(query(windowcols)-33,8) putstr("Pgdn Page Down")
gotoxy(query(windowcols)-33,9) putstr("Cursorup RollUp Visible")
gotoxy(query(windowcols)-33,10) putstr("Cursordown RollDown Visible")
gotoxy(query(windowcols)-33,11) putstr("Cursorleft Roll Up Both")
gotoxy(query(windowcols)-33,12) putstr("Cursorright Roll Down Both")
gotoxy(query(windowcols)-33,13) putstr("Home Top of Both Files")
gotoxy(query(windowcols)-33,14) putstr("End End of Both Files")
gotoxy(query(windowcols)-33,15) putstr("G Go To Line Both
Files")
gotoxy(query(windowcols)-33,16) putstr("F Faster")
gotoxy(query(windowcols)-33,17) putstr("S Slower")
gotoxy(query(windowcols)-33,18) putstr(" (Speed: "+str(vdt)+")")
gotoxy(query(windowcols)-33,19) putstr("P Pause")
gotoxy(query(windowcols)-33,20) putstr("F1 Overview")
gotoxy(query(windowcols)-33,21) putstr("D This Display")
end
// action key processing
proc mC2fcActionKeys()
integer tb=0
integer i=0
integer k=0
integer l=0
if quit==0
for i=1 to vdt
if keypressed()
k=getkey()
tb=getbufferid()
i=1
case k
// page up both
when <pgup>,<greypgup>
gotobufferid(tb1)
pageup()
gotobufferid(tb2)
pageup()
// page down both
when <pgdn>,<greypgdn>
gotobufferid(tb1)
pagedown()
gotobufferid(tb2)
pagedown()
// rollup fn1
when <cursorup>,<greycursorup>
rollup()
// rolldown fn1
when <cursordown>,<greycursordown>
rolldown()
// rollup both
when <cursorleft>,<greycursorleft>
gotobufferid(tb1)
rollup()
gotobufferid(tb2)
rollup()
// rolldown both
when <cursorright>,<greycursorright>
gotobufferid(tb1)
rolldown()
gotobufferid(tb2)
rolldown()
// top of file on both
when <home>,<greyhome>
gotobufferid(tb1)
gotoline(1)
gotobufferid(tb2)
gotoline(1)
// end of file on both
when <end>,<greyend>
gotobufferid(tb1)
gotoline(numlines())
pageup()
gotobufferid(tb2)
gotoline(numlines())
pageup()
// go to a line in both files
when <g>,<G> gotoline() l=currline()
iif(getbufferid()==tb1,gotobufferid(tb2),gotobufferid(tb1))
gotoline(l)
// faster
when <f>,<F> if vdt>0 vdt=vdt-1 endif
// slower
when <s>,<S> vdt=vdt+5
// help
when <f1> quickhelp(overview)
// toggle key display
when <d>,<D> sk=not sk
// quit
when <escape>
quit=1
gotobufferid(tb)
when <p>,<P> message("L "+str(currline())+" C "+str(currcol())+
" P=Resume.") k=getkey()
endcase
gotobufferid(tb)
endif
updatedisplay()
if sk mshowkeys() endif
delay(1)
endfor
endif
end
// create list of open files
proc mcreatelist()
integer tb=0
integer i=0
pushposition()
tb=createbuffer("fnx",_hidden_)
emptybuffer()
popposition()
pushposition()
for i=1 to nf+1
addline(currfilename(),tb)
nextfile(_dontload_)
endfor
gotobufferid(tb)
begfile()
if currlinelen()==0
delline()
endif
set(y1,query(windowy1))
list("Select a file and press Enter, ESC=Cancel",query(windowcols))
if query(key) in <enter>,<greyenter>,<leftbtn>
xfil=gettext(1,currlinelen())
addhistorystr(xfil,c2fc_hist)
popposition()
begline()
deltoeol()
inserttext(xfil)
else
popposition()
endif
abandonfile(tb)
end
// first prompt keydef
keydef c2fc1keys
<f1> quickhelp(file1help)
<f2> mcreatelist() if xfil<>"" fn1=xfil endif // list open files
<f3> xfil=pickfile(currdir()) if xfil<>"" begline() deltoeol()
inserttext(xfil) endif
<f5> bad=1 pushkey(<escape>) // prev file
<f6> bad=2 pushkey(<escape>) // next file
<Alt h> quickhelp(overview)
end
// first prompt startup
proc c2fc1Startup()
Enable(c2fc1Keys)
UnHook(c2fc1Startup)
windowfooter("{F1}=Help {F2}=List Open {F3}=PickFile {F5}=PrevFile
{F6}=NextFile {Alt-h}=Overview")
end
// second prompt keydef
keydef c2fc2keys
<f1> quickhelp(file2help)
<f2> mcreatelist() if xfil<>"" fn2=xfil endif // list open files
<f3> xfil=pickfile(currdir()) if xfil<>"" begline() deltoeol()
inserttext(xfil) endif
<f5> bad=1 pushkey(<escape>) // prev file
<f6> bad=2 pushkey(<escape>) // next file
<Alt h> quickhelp(overview)
end
// second prompt startup
proc c2fc2Startup()
Enable(c2fc2Keys)
UnHook(c2fc2Startup)
windowfooter("{F1}=Help {F2}=List Open {F3}=PickFile {F5}=PrevFile
{F6}=NextFile {Alt-h}=Overview")
end
// resume prompt help
helpdef resumehelp
title="Resuming compare Help"
""
"Choosing R will resume comparing the previously selected files chosen to"
"be compared. The macro will use the current screens of both files and"
"begin swapping at the same speed as before."
""
"Choosing S will start the selection process for the two files to compare"
"all over again."
""
"Choosing P at this prompt will remove the macro and all of its saved"
"state from TSE."
""
end
// show current compare files for resume prompt
proc mresumelist()
integer tf=0
tf=createtempbuffer()
insertline(fn1)
addline(fn2)
set(x1,query(windowx1))
set(y1,8)
list("These are the current files to compare. ESC=Close.",query(windowcols))
abandonfile(tf)
end
// resume prompt
keydef mc2fcresumekeys
<f1> quickhelp(resumehelp)
<f2> mresumelist() // list current two files
<Alt h> quickhelp(overview)
end
// resume prompt startup
proc mc2fcresumeStartup()
Enable(mc2fcresumeKeys)
UnHook(mc2fcresumeStartup)
windowfooter("{F1}=Help {F2}=List Current Two Files {Alt-h}=Overview")
end
proc main()
string xs[1]="R"
integer skip=0
integer ok=0
nf=numfiles()
fn1=currfilename()
c2fc_hist=getfreehistory("C2fc:Compare_2_Files")
// resume prompt after quitting
if tb1 and tb2
set(x1,query(windowx1))
set(y1,query(windowrows)/2)
hook(_prompt_startup_,mc2fcresumestartup)
ok=ask("(R)esume Current Files, (S)elect Two New Files,(P)urge macro,
ESC=Quit",xs)
unhook(mc2fcresumestartup)
if ok and length(xs)
if pos(xs,"rR")
skip=1
elseif pos(xs,"pP")
purgemacro("C2fc")
goto ending
endif
else
warn("Cancelled.")
goto ending
endif
endif
// select first file
if skip==0
repeat
bad=0
Hook(_PROMPT_STARTUP_, c2fc1Startup)
set(x1,query(windowx1))
set(y1,query(windowrows)/2-3)
ask("Choose the FIRST File, ESC=Quit",fn1,c2fc_hist)
unHook(c2fc1Startup)
if query(key)==<escape> and bad==0
warn("Cancelled.")
goto ending
endif
case bad
when 1 prevfile() updatedisplay() fn1=currfilename()
when 2 nextfile() updatedisplay() fn1=currfilename()
endcase
until bad==0
editfile(fn1)
updatedisplay()
// select second file
repeat
bad=0
Hook(_PROMPT_STARTUP_, c2fc2Startup)
set(x1,query(windowx1))
set(y1,query(windowrows)/2)
ask("Choose SECOND File, ESC=Quit",fn2,c2fc_hist)
unHook(c2fc2Startup)
if query(key)==<escape> and bad==0
warn("Cancelled.")
fn1="" fn2=""
tb1=0 tb2=0
goto ending
endif
case bad
when 1 prevfile() updatedisplay() fn2=currfilename()
when 2 nextfile() updatedisplay() fn2=currfilename()
endcase
until bad==0
editfile(fn2)
updatedisplay()
// set the buffer ids
if fn1<>fn2
tb1=getbufferid(fn1)
tb2=getbufferid(fn2)
else
warn("The two files cannot be the same. Cancelled.")
goto ending
endif
endif
// go into file-swapping
repeat
// show first file
gotobufferid(tb1)
updatedisplay()
if sk mshowkeys() endif
mC2fcActionKeys()
if quit goto ending endif
// show second file
gotobufferid(tb2)
updatedisplay()
if sk mshowkeys() endif
mC2fcActionKeys()
if quit goto ending endif
until quit==1
goto ending
ending:
quit=0
updatedisplay(_all_windows_refresh_)
end
// for swapping the two files after quitting
<ctrlshift spacebar> if tb1 and tb2
iif(getbufferid()==tb1,gotobufferid(tb2),gotobufferid(tb1)) endif
<alt h> quickhelp(overview)