• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

RexxDiff, determine difference between two files.

Started by jep, 2008.12.08, 20:38:30

Previous topic - Next topic

jep

Marked as: Normal
Hello,

It's sometimes quite useful to find out what has changed between two saves of a file. If you rename the files each time then it's possible to use this script to see each row that doesn't look the same.

The script take the path and file name as parameter, then it ask for the file to compare to and last what the output file should be called. If you don't specify the path when asked for the second file or the output file, it'll use the path provided with the command line parameter. After that the code will load each file into a stem, then use the sorting routine SysStemSort to order each row and then do a simple row by row comparison and output lines unique to both files.

This script has only been tested briefly and may not produce reliable results, so you may want to rewrite it and improve it yourself. Feel free to post replies with cfode changes and improvements. Ensure that you register as a member to be able to see attached files mentioned and to reply to posts.

/* DIFFROWS */                       

call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs


fname =  ARG(1)
say 'Name of second file:'
parse pull fname2
fname2.path = strip( filespec( 'D', fname2 )||filespec( 'p', fname2 ), 'T', '\' )
if length( fname2.path ) = 0 then
   fname2 = filespec( 'D', fname )||filespec( 'p', fname )||fname2

say 'Name of output file:'
parse pull outfname
outfname.path = strip( filespec( 'D', outfname )||filespec( 'p', outfname ), 'T', '\' )
if length( outfname.path ) = 0 then
   outfname = filespec( 'D', fname )||filespec( 'p', fname )||outfname

return Diff( fname, fname2, outfname )


Diff: PROCEDURE
row = 1
do while lines( ARG(1) ) > 0
   frst.row = linein( ARG(1) )
   row = row + 1
end
call stream ARG(1), 'C' 'CLOSE'
frst.0 = row - 1

row = 1
do while lines( ARG(2) ) > 0
   scnd.row = linein( ARG(2) )
   row = row + 1
end
call stream ARG(1), 'C' 'CLOSE'
scnd.0 = row - 1

/* sort all elements ascending, ignore the case */
Call SysStemSort 'frst.', 'A', 'I'
Call SysStemSort 'scnd.', 'A', 'I'
row = 1
do i = 1 to frst.0
   do while translate( frst.i ) > translate( scnd.row )
      call Lineout ARG(3), scnd.row
      row = row + 1
   end
   do while translate( frst.i ) < translate( scnd.row )
      call Lineout ARG(3), frst.i
      i = i + 1
   end
   row = row + 1
end
call stream ARG(3), 'C' 'CLOSE'
return 0