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
|
// Reconcile DEP-5 debian/copyright to licensecheck
//
// Copyright : 2024-2025 P Blackman
// License : BSD-2-clause
//
// Test for false positive on GNU Lesser General Public License
// with 'any later version' not shown by licensecheck as GPL?+ etc
unit gpla;
{$mode delphi}
interface
function CheckGPLa (Fname : AnsiString; Dep5, Actual: String) : Boolean;
implementation uses Math, StrUtils, Support;
// test for GPL+ style license
function LaterLicense (Fname : AnsiString) : Boolean;
const Max1 : Integer = 40; // Arbitrary, license usually at start of file
Max2 : Integer = 6; // Arbitrary, this text usually two lines after G..P..L
var Lines,
Lpos : Integer;
Line : AnsiString;
Lfile : Text;
begin
result := false;
Lines := 0;
if OpenFile (FName, Lfile) then
begin
while not EOF (Lfile) and (Lines < Max1) do
begin
readln (Lfile, Line);
Lpos := NPos ('General Public License', Line, 1);
inc (Lines);
if Lpos > 0 then
begin
Lines := 0;
while not EOF (Lfile) and (Lines < Max2) do
begin
readln (Lfile, Line);
Lpos := NPos ('any later version', Line, 1);
inc (Lines);
if Lpos > 0 then
begin
result := true;
Lines := max (Max1,Max2); // terminate loop
end
end;
end;
end;
Close (Lfile);
end;
end;
// Return true if Actual should be *+ as shown in d/copyright
function CheckGPLa (Fname : AnsiString; Dep5, Actual: String) : Boolean;
begin
if ContainsStr (Dep5, 'GPL')
and ContainsStr (Dep5, Actual)
and (length (Dep5) - length (Actual) < 4)
and (Dep5 [length(Dep5)] = '+')
and ((FName = 'LICENSE') or LaterLicense (FName)) then
result := true
else
result := false;
end;
end.
|