
(********************************************************************)
(*                                                                  *)
(*  cmpfil.sd7    Compares two files in main memory                 *)
(*  Copyright (C) 1993, 1994  Thomas Mertes                         *)
(*                                                                  *)
(*  This program is free software; you can redistribute it and/or   *)
(*  modify it under the terms of the GNU General Public License as  *)
(*  published by the Free Software Foundation; either version 2 of  *)
(*  the License, or (at your option) any later version.             *)
(*                                                                  *)
(*  This program is distributed in the hope that it will be useful, *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of  *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *)
(*  GNU General Public License for more details.                    *)
(*                                                                  *)
(*  You should have received a copy of the GNU General Public       *)
(*  License along with this program; if not, write to the           *)
(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


$ include "seed7_05.s7i";
  include "getf.s7i";

const proc: main is func

  local
    var string: file_name1 is "";
    var string: file_name2 is "";
    var string: stri1 is "";
    var string: stri2 is "";
    var integer: index is 0;
    var integer: leng is 0;
  begin
    if length(argv(PROGRAM)) >= 1 then
      file_name1 := argv(PROGRAM)[1];
    else
      write("File1: ");
      file_name1 := getln(IN);
    end if;
    if length(argv(PROGRAM)) >= 2 then
      file_name2 := argv(PROGRAM)[2];
    else
      write("File2: ");
      file_name2 := getln(IN);
    end if;
    stri1 := getf(file_name1);
    stri2 := getf(file_name2);
    if stri1 = stri2 then
      writeln("equal");
    else
      writeln("not equal");
      leng := length(stri1);
      if length(stri1) > length(stri2) then
        writeln("length(stri1) > length(stri2)");
      end if;
      if length(stri1) < length(stri2) then
        writeln("length(stri1) < length(stri2)");
        leng := length(stri2);
      end if;
      write("length(stri1) = ");
      writeln(length(stri1));
      write("length(stri2) = ");
      writeln(length(stri2));
      for index range 1 to leng do
        if stri1[index] <> stri2[index] then
          write(index);
          write(" ");
          write(ord(stri1[index]));
          write("<>");
          write(ord(stri2[index]));
          write("  ");
          write(literal(stri1[index - 4 .. index + 4]));
          write("  ");
          write(literal(stri2[index - 4 .. index + 4]));
          writeln;
        end if;
      end for;
    end if;
  end func;
