Author Topic: simple file difference macro?  (Read 4200 times)

Mike H

  • Community Member
  • Posts: 25
  • Hero Points: 3
simple file difference macro?
« on: April 05, 2007, 09:40:49 pm »
Can someone give me some help on writing a macro to compare 2 files and returning the number of lines that are different?  Diffzilla has this "imaginary line buffer" that it inserts and messes this up.  I am generating data files and need to know if they match a reference file and if not, all I want to know is the number of lines different - something that returns, for example "20/5000 lines different".  Just a straight line for line compare and outputting the total number of mismatches.

thanks in advance!
Mike

Graeme

  • Senior Community Member
  • Posts: 2336
  • Hero Points: 307
Re: simple file difference macro?
« Reply #1 on: April 06, 2007, 01:51:13 am »
Can someone give me some help on writing a macro to compare 2 files and returning the number of lines that are different?  Diffzilla has this "imaginary line buffer" that it inserts and messes this up.  I am generating data files and need to know if they match a reference file and if not, all I want to know is the number of lines different - something that returns, for example "20/5000 lines different".  Just a straight line for line compare and outputting the total number of mismatches.

thanks in advance!
Mike

Here's some code I've posted before for reading a file.  It creates a temporary view/buffer for reading the file into and restores the prior view/buffer on exit.  You could modify it a little to create another temp buffer and do a "get" for the second file, then alternate activate_view calls to do a get_line from each buffer.  To compare strings you can just do something like if ( line :== other_line )   - or see "string functions" in slick macro programming guide.
If you need any more help, feel free to ask...

Graeme


Code: [Select]
static void read_a_file()
{
   int new_view, current_view;
   _str line;
   current_view = _create_temp_view(new_view);
   if (current_view == '') {
       return;
   }
   activate_view(new_view);

   if (get('somefile.txt')) {
      message('read failed - FILE: ' :+ 'somefile.txt');
   }
   else
   {
      top();
      while (true) {
         if (down())
            break;
         get_line(line);
      }
   }
   _delete_temp_view(new_view);
   activate_view(current_view);
}