1
2(********************************************************************)
3(*                                                                  *)
4(*  cmpfil.sd7    Compares two files in main memory                 *)
5(*  Copyright (C) 1993, 1994  Thomas Mertes                         *)
6(*                                                                  *)
7(*  This program is free software; you can redistribute it and/or   *)
8(*  modify it under the terms of the GNU General Public License as  *)
9(*  published by the Free Software Foundation; either version 2 of  *)
10(*  the License, or (at your option) any later version.             *)
11(*                                                                  *)
12(*  This program is distributed in the hope that it will be useful, *)
13(*  but WITHOUT ANY WARRANTY; without even the implied warranty of  *)
14(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *)
15(*  GNU General Public License for more details.                    *)
16(*                                                                  *)
17(*  You should have received a copy of the GNU General Public       *)
18(*  License along with this program; if not, write to the           *)
19(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
20(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
21(*                                                                  *)
22(********************************************************************)
23
24
25$ include "seed7_05.s7i";
26  include "getf.s7i";
27
28const proc: main is func
29
30  local
31    var string: file_name1 is "";
32    var string: file_name2 is "";
33    var string: stri1 is "";
34    var string: stri2 is "";
35    var integer: index is 0;
36    var integer: leng is 0;
37  begin
38    if length(argv(PROGRAM)) >= 1 then
39      file_name1 := argv(PROGRAM)[1];
40    else
41      write("File1: ");
42      file_name1 := getln(IN);
43    end if;
44    if length(argv(PROGRAM)) >= 2 then
45      file_name2 := argv(PROGRAM)[2];
46    else
47      write("File2: ");
48      file_name2 := getln(IN);
49    end if;
50    stri1 := getf(file_name1);
51    stri2 := getf(file_name2);
52    if stri1 = stri2 then
53      writeln("equal");
54    else
55      writeln("not equal");
56      leng := length(stri1);
57      if length(stri1) > length(stri2) then
58        writeln("length(stri1) > length(stri2)");
59      end if;
60      if length(stri1) < length(stri2) then
61        writeln("length(stri1) < length(stri2)");
62        leng := length(stri2);
63      end if;
64      write("length(stri1) = ");
65      writeln(length(stri1));
66      write("length(stri2) = ");
67      writeln(length(stri2));
68      for index range 1 to leng do
69        if stri1[index] <> stri2[index] then
70          write(index);
71          write(" ");
72          write(ord(stri1[index]));
73          write("<>");
74          write(ord(stri2[index]));
75          write("  ");
76          write(literal(stri1[index - 4 .. index + 4]));
77          write("  ");
78          write(literal(stri2[index - 4 .. index + 4]));
79          writeln;
80        end if;
81      end for;
82    end if;
83  end func;
84