File: compare.pas

package info (click to toggle)
licenserecon 6.0
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 352 kB
  • sloc: pascal: 1,378; makefile: 33; xml: 9; sh: 2
file content (106 lines) | stat: -rw-r--r-- 3,215 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Reconcile DEP-5 debian/copyright to licensecheck
//
// Copyright : 2023-2025 P Blackman
// License   : BSD-2-clause
//

unit compare;
{$mode delphi}

interface

procedure CompareLicenses;


implementation uses SysUtils, StrUtils, rstrings, support,
    exclude, gfdl, gpl, gpla, spdx, spdx2, dotzero,
    apache, ntprsa, eclipse, psf, andor, bsd0, options;


procedure CompareLicenses;
var F : tFileLic;
    Header,
    GotOne,
    MisMatch,
    FalsePositive : Boolean;
    last_Dep5,
    Last_Actual : String;
begin
    Header      := False;
    GotOne      := False;
    MisMatch    := False;
    Last_Dep5   := '';
    Last_Actual := '';

    for F in MyFiles do
        with F do
            if (Actual = '') then
                // Nothing to see here
            else
            begin
                MisMatch := not SameText(Dep5, Actual);
                FalsePositive := false;

                if MisMatch and not IgnoreFile (Fname) then
                    FalsePositive :=
                           CheckGPL     (Fname, Dep5, Actual)
                        or CheckGPLa    (Fname, Dep5, Actual)
                        or CheckSPDX    (Fname, Dep5, Actual)
                        or CheckSPDX2   (Fname, Dep5, Actual)
                        or CheckApache  (Fname, Dep5, Actual)
                        or CheckGFDL    (Fname, Dep5, Actual)
                        or CheckEclipse (Fname, Dep5, Actual)
                        or CheckPSF2    (Fname, Dep5, Actual)
                        or CheckBSD0    (Fname, Dep5, Actual)
                        or CheckDotZero (Dep5, Actual)
                        or CheckNTPRSA  (Dep5, Actual)
                        or CheckANDOR   (Dep5, Actual)
                        or ContainsStr (Actual, 'Autoconf-data');

                if not IgnoreFile (Fname)
                and (Option_Long or MisMatch and not FalsePositive) then
                begin
                   if not Header and not Option_Format then
                    begin
                        Writeln ('d/copyright      | licensecheck');
                        Writeln;
                        Header := True;
                    end;

                    if Option_Short and (Dep5 = last_Dep5) and (Actual = Last_Actual) then
                        // skip this file
                    else
                    if Option_Format then
                    begin
                        Writeln (Dep5);
                        Writeln (Actual);
                        Writeln (FName);
                        Writeln;
                    end
                    else
                        Writeln (PadRight(Dep5,17), '| ', PadRight(Actual,17), ' ',FName);

                    Last_Dep5   := Dep5;
                    Last_Actual := Actual;
                    GotOne      := GotOne or (MisMatch and not FalsePositive);
                end;
            end;

    if GotOne then
    begin
        Writeln;

        if Option_Short then
        begin
            Writeln ('Short ' + rsSiu); // Not all differences shown
            Writeln;
        end;

        Halt (3);
    end
    else
    if not Option_Format then
        Writeln (rsNdf); // No differences found
end;

end.