// -*- ASCII:EDT -*- // RCSdiff.edt // Compares two files and generates output to LaTeX it // with correct.sty or changebar.sty // (schlicht 20030423) //////////////////////////////////// IfFileExists("%b\Config\RCS\RCSconf.edt",> !"Exe('%b\Config\RCS\RCSconf.edt');> Assign('RCSconfig','%%b\Config\RCS\RCSconf.edt');",> !"// You only have to adjust these settings, if you are using this file as a stand-alone macro. <> // If you use it is a part of the RCS menu, edit the file %b\Config\RCS\RCSconf.edt instead! // -- the path to the RCS system: Assign('RCSpath','%@(|ProgramFiles|);\Componentsoftware\CS-RCS\system');> // -- the main executable: Assign('RCSexe','%$(|RCSpath|);\csrcs.exe');> // -- the diff program Assign('RCSdiffexe','%$(|RCSpath|);\csdiff.exe');> // -- the path for temporary files Assign('RCStempPath','%@(|TEMP|);');> // -- the command line to retrieve the previous version of the file 'RCSfile' into the directory 'RCStempPath': Assign('RCSret',`%$('RCSexe'); ret /q /a""%$('RCStempPath');\"" ""%%$('RCSfile');""`);> // -- the command line to compare 'RCSfile1' with 'RCSfile2' and write the result to the file 'RCSdiffresult': // CSDiff 3.0: // Assign('RCSdiff', `%$('RCSdiffexe'); /q /T""%%$('RCSdiffresult');"" ""%%$('RCSfile1');"" ""%%$('RCSfile2');""`);> // comparison by word is not implemented for CSDiff 3.0. Please upgrade your CSDiff! // CSDiff 4.0: Assign('RCSdiff', `%$('RCSdiffexe'); /q /Od""%%$('RCSdiffresult');"" ""%%$('RCSfile1');"" ""%%$('RCSfile2');""`);> Assign('RCSdiffHTML',`%$('RCSdiffexe'); /q /Oh""%%$('RCSdiffresult');"" ""%%$('RCSfile1');"" ""%%$('RCSfile2');""`);> // -- ignore changes in the preamble? (possible values: "yes", "no", "ask") Assign('RCSdiffIgnorePreamble','yes');> Assign('RCSconfig','RCSdiff.edt');> "); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ IfStr("%$('RCSdiffIgnorePreamble');","ask","=",!`> Prompt("Ignore changes in the preamble?",1,4,> "Assign('diffIgnorePreamble','yes');",> "Assign('diffIgnorePreamble','no');","Exit;");`); IfStr("%$('RCSdiffIgnorePreamble');","no","=",!`> Assign("diffIgnorePreamble","no");`,!`> Assign("diffIgnorePreamble","yes");`); IfStr("%$('diffPrev');","","=",> "Prompt('Compare with previous version in RCS (YES) or browse for a file (NO)?',1,4,> 'Assign(''diffPrev'',''RCS'');',> 'Assign(''diffPrev'',''browse'');',> 'Exit;'> );"> ); IfStr("%$('diffOutput');","","=",> "Prompt('Generate output for changebar.sty (YES) or for correct.sty (NO)?',1,4,> 'Assign(''diffOutput'',''changebar'');',> 'Assign(''diffOutput'',''correct'');',> 'Exit;'> );"> ); IfStr("%$('diffbyword');","","=",> "Prompt('Compare by word?',1,4,> 'Assign(''diffbyword'',''yes'');',> 'Assign(''diffbyword'',''no'');',> 'Exit;'> );"> ); IfStr("%$('diffOutput');","correct","=",!"> Assign('diffAddStart','\Add{');> Assign('diffAddEnd','}');> Assign('diffDelStart','\Del{');> Assign('diffDelEnd','}');> Assign('diffUsepackage','\usepackage[active,old,new]{correct}');> "); IfStr("%$('diffOutput');","changebar","=",!"> Assign('diffAddStart','\cbstart{}');> Assign('diffAddEnd','\cbend{}');> Assign('diffDelStart','\cbdelete{}');> Assign('diffDelEnd','');> Assign('diffUsepackage','\usepackage{changebar}');> "); StartWorking("Comparing..."); Assign("RCSdiffresult","%$('RCStempPath');\%n%t$$"); DeleteFile("%$('RCSdiffresult');"); // Get the file to compare with IfStr("%$('diffPrev');","RCS","=",!`> // from RCS Assign("RCSfile","%p\%n%t");> Assign("RCSfile1","%$('RCStempPath');\%n%t");> DeleteFile("%$('RCSfile1');");> IfFileExists("%$('RCStempPath');\","","CreateFolders('%$(|RCStempPath|);\',1);");> Do(*WinExe("",|%$("RCSret");|,"%p","",011100);*);> IfOK("",!"> Prompt('Could not retrieve previous revision! Make sure the settings are correct in%\%$(|RCSconfig|);.',3,1);> Release('diffOutput');Release('diffPrev');Release('diffbyword');Exit;");> IfFileExists("%$('RCSfile1');","",> !"Prompt('File ""%n%t"" is not in the repository',0,1);> Release('diffOutput');Release('diffPrev');Release('diffbyword');Exit;");> `,!`// compare with another file <> Prompt("Please choose a file that I will regard as the older version of%\%\ %p\%n%t.%\",0,0);> Browse(1,"%t files|*%t|All files|*.*","%p");> IfStr("%$('RCSfile1');","%p\%n%t","=",> "Prompt('You cannot compare a file with itself.',2,1);> Release('diffOutput');Release('diffPrev');Release('diffbyword');Exit;");> Assign("RCSfile1","%!1");> `); // run CSDiff IfStr("%$('diffbyword');","yes","=",> !"IfStr('%$(|RCSdiffHTML|);','','=',> !'Prompt(''Cannot run CSDiff by word. Please set RCSdiffHTML in %$(|RCSconfig|);!'');Exit;',> 'LetReg(1,''HTML'');');",> !"LetReg(1,'');"); Assign("RCSfile2","%p\%n%t"); Do(*WinExe("",`%$("RCSdiff%!1");`,"%p","",011100);*); IfOK("LetReg(1,'');","LetReg(1,'error');"); IfStr('%$(|diffPrev|);','RCS','=','DeleteFile(''%$(|RCSfile1|);'');'); IfStr("%!1","error","=",!"> DeleteFile('%$(|RCSdiffresult|);');> Release('diffOutput');Release('diffPrev');Release('diffbyword');> Prompt('Error running CSDiff! Make sure the settings are correct in%\%$(|RCSconfig|);.',3,1);> Exit;"); IfFileExists("%$('RCSdiffresult');",> !"ReadFile('%$(|RCSdiffresult|);',0);",> !"DeleteFile('%$(|RCSdiffresult|);');> Release('diffOutput');Release('diffPrev');Release('diffbyword');> Prompt('Files are the same.',0,1);> Exit;"); IfStr("%!0","","=",!"> DeleteFile('%$(|RCSdiffresult|);');> Release('diffOutput');Release('diffPrev');Release('diffbyword');> Prompt('Diff file is empty. Don''t know what to do.',3,1);> Exit;"); StartWorking("Generating..."); CloseFile("%p\%n_diff%t",1); DeleteFile("%$('RCSdiffresult');"); // RCS will check out the file as readonly, so this doesn't work in that case Assign("diffPreambleEnd","0"); IfStr("%$('diffbyword');","yes","=",!`> // remove the HTML stuff at the beginning FindInString("%!0","\}\>@{>}",1,2,1);> IfOK(!"ReplaceInString('%!0','',0,%!2,0,0);");> IfStr("%$('diffIgnorePreamble');","yes","=",!"> FindInString('%!0','<@^{%%|\\}\\begin\{document\}',2,1,1);> IfOK(!'Assign(''diffPreambleEnd'',''%!1'');');> ");`,> !`// we'll work on the original file here <> ReadFile("%p\%n%t",7);> IfStr("%$('diffIgnorePreamble');","yes","=",!"> FindInString('%!7','<@^{%%|\\}\\begin\{document\}',2,1,1);> IfOK(!'IndexToCL(%!1,2,1,''%!7'');> Assign(''diffPreambleEnd'',''%!1'');');> ");> `); IfStr("%$('diffbyword');","no","=",!`> // * Use CSDiff's text output (comparison by line) LetRegNum(1,0);> // Looking for added stuff Loop(!``> SetOK(1);> FindInString("%!0","<+$Numeric$@{,+$Numeric$}[ca]\(1+$Numeric$\)@{,}\(2@{$Numeric$}\)",1,2,1011,%!1+1);> IfOK(!"> GetTag(1,8);> IfNum(%!8,'%$(|diffPreambleEnd|);','>',!'// not in preamble? <> GetTag(2,9);> IfStr(''%!9'','''',''='',!''LetRegNum(9,%!8);'');> CLToIndex(1,%!8,5,''%!7'');> InsertByIndex(7,''%!7'',''%$(|diffAddStart|);'',%!5);> CLToIndex(1,%!9+1,6,''%!7'');> InsertByIndex(7,''%!7'',''%$(|diffAddEnd|);'',%!6);> ');> ",> "Stop;");> ``);> // Looking for deleted stuff (backwards, to get the lines right): Release("RCSdel");> LetReg(9,"[cd]");> // only mark deleted (not: changed) stuff with "\cbdelete" (?) IfStr("%$('diffOutput');","changebar","=","LetReg(9,'d');");> Loop(!``> SetOK(1);> FindInString("%!0","<+$Numeric$@{,+$Numeric$}%!9\(1+$Numeric$\)@{,+$Numeric$}>",1,2,1111,%!1-1);> IfOK(!"> GetTag(1,8);> IfNum(%!8,'%$(|diffPreambleEnd|);','>',!'> Release(''RCSdel'');> IfStr(''%$(|diffOutput|);'',''correct'',''='',!''> // get the text (only for use with correct.sty): FindInString(|%!0|,|<+{$Numeric$||,}?+{$Numeric$||,}>|,6,3,1011,%!2);> LetRegNum(4,%!2-1);> Loop(!|> SetOK(1);> FindInString(""%!0"",""<\< \(0*\)>"",4,5,1011,%!4+1);> IfOK(!""> IfNum(%!5,%!6,||>||,||Stop;||,> !||GetTag(0,3);> Assign(:RCSdel:,:%$(*RCSdel*);%!3%\:);||);"",> ""Stop;"");> |);> '');> IfNum(%!8,0,''='',''LetRegNum(8,1);'');> CLToIndex(1,%!8,5,''%!7'');> GetLength(6,''%$(|diffAddEnd|);'');> IfStr(''%!8'',''%$(|diffAddEnd|);'',''='',''LetRegNum(8,%!5+%!6);'',''LetRegNum(8,%!5);'');> InsertByIndex(7,''%!7'',''%$(|diffDelStart|);%$(|RCSdel|);%$(|diffDelEnd|);'',%!8);> ','Stop;');> ",> "Stop;");> ``);> LetReg(0,"%!7");`,> !`// * Use HTML output (comparison by word): <> // first we clean up the output a bit (we remove redundant tags on every line; CSDiff likes to do that): LetRegNum(1,"%$('diffPreambleEnd');");> Loop(!``> SetOK(1);> FindInString("%!0","\\(0@^{\}\)<\\",1,2,1001,%!1);> IfOK(!"> GetTag(0,3);> GetTag(1,4);> ReplaceInString('%!0','%!3',%!1,%!2,0,0);",> "Stop;");> ``);> // now let's replace the tags GetLength(2,"%!0");> Loop(!``> SetOK(1);> FindInString("%!0","\\(2**\)\",1,2,1101,%!2);> IfOK(!"> GetTag(1,8);> GetTag(2,9);> IfStr('%!8','Added','=',> !'IfNum(%!1,''%$(|diffPreambleEnd|);'',''<'',!''// not in preamble? <> LetReg(7,|%!9|);'',> !''LetReg(7,*%$(:diffAddStart:);%!9%$(:diffAddEnd:);*);'');',> !'IfNum(%!1,''%$(|diffPreambleEnd|);'',''<'',!''// not in preamble? <> LetReg(7,||);'',> !''LetReg(7,*%$(:diffDelStart:);%!9%$(:diffDelEnd:);*);'');');> ReplaceInString('%!0','%!7',%!1,%!2,0,0);> ",> "Stop;");> ``);> // and the rest, too: LetRegNum(1,0);> Loop(!``> SetOK(1);> FindInString("%!0","{\}\>}|{\}|{\}\>@{>}}|{\@{>}}",1,2,1001,%!1);> IfOK(!"ReplaceInString('%!0','',%!1,%!2,0,0);","Stop;");> ``);> LetRegNum(1,0);> Loop(!``> SetOK(1);> FindInString("%!0",">",1,2,1001,%!1);> IfOK(!"ReplaceInString('%!0','>',%!1,%!2,0,0);","Stop;");> ``);> LetRegNum(1,0);> Loop(!``> SetOK(1);> FindInString("%!0","<",1,2,1001,%!1);> IfOK(!"ReplaceInString('%!0','<',%!1,%!2,0,0);","Stop;");> ``);> LetRegNum(1,0);> Loop(!``> SetOK(1);> FindInString("%!0","&",1,2,1001,%!1);> IfOK(!"ReplaceInString('%!0','&',%!1,%!2,0,0);","Stop;");> ``);> SetOK(1);> FindInString("%!0","",1,2,0,0);> IfOK(!"GetLength(2,'%!0');ReplaceInString('%!0','',%!1,%!2+2,0,0);");> `); // add \usepackage{...} IfNum("%$('diffPreambleEnd');","0","<>",!"> FindInString('%!0','<@^{%%|\\}\\begin\{document\}',1,2,1);> IfOK(!'InsertByIndex(0,''%!0'',''%$(|diffUsepackage|);%\'',%!1);');"); OpenOutput("%p\%n_diff%t"); WrL("%!0"); CloseOutput; Open("%p\%n_diff%t"); StopWorking; Release("diffOutput"); Release("diffPrev"); Release('diffbyword'); IfStr("%$('diffIgnorePreamble');","yes","=","> IfNum('%$(|diffPreambleEnd|);','0','=',> 'Prompt(''I did not find the end of the preamble.%\You might have to add the command%\%\ %$(|diffUsepackage|);'',2,0);');",> "Prompt('You might have to remove commands in your preamble.');"); End; // ---------------------------------- This macro will compare a document to its last version or to another document and generate a new file, marking the differences, so that you can LaTeX it. It either uses the LaTeX package changebar.sty, or correct.sty. Of course, these packages must be installed in your TeX system. If you are not using this macro as a part of the RCS menu, you might have to adjust the commands at the beginning of the file. R Schlicht // ---------------------------------- $Id: RCSdiff.edt,v 1.3 2004-12-24 04:42:55+01 schlicht Exp schlicht $