File: options.pas

package info (click to toggle)
licenserecon 12.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 372 kB
  • sloc: pascal: 1,375; makefile: 33; perl: 31; xml: 9; sh: 2
file content (110 lines) | stat: -rw-r--r-- 2,758 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
107
108
109
110
// Reconcile DEP-5 debian/copyright to licensecheck
//
// Copyright : 2024-2025 P Blackman
// License   : BSD-2-clause
//
// Process command line options

unit options;
{$mode delphi}

interface

var
    Option_Version : Boolean = False;
    Option_Help    : Boolean = False;
    Option_Format  : Boolean = False;
    Option_Long    : Boolean = False;
    Option_Short   : Boolean = False;
    Option_SPDX    : Boolean = False;

Procedure ShowVersions;
Procedure ShowHelp;
procedure CheckParam (P : String);
procedure GetOptions;


implementation uses Process, SysUtils, StrUtils, gettext, support, rstrings;

var
    ReadMeFile : Text;
    FallbackLang,
    Lang5char   : Ansistring;
    Lang2char   : string[2];

// Get Debian package version
function GetVersion (Package : String) : String;
var S1 : String;

begin
    if RunCommand ('/usr/bin/dpkg-query',
        ['-f', '''${Version}''', '-W', Package],
        S1, [poUsePipes, poWaitOnExit])
    then
        result := S1
    else
        result := '';
end;

Procedure ShowVersions;
begin
    Writeln (Lang2char + ': Versions: licenserecon ' + (GetVersion('licenserecon'))
            + '  licensecheck ' + (GetVersion('licensecheck')));
end;

Function OpenHelpFile : Boolean;
begin
    result := OpenFile ('/usr/share/doc/licenserecon/ReadMe.'+ Lang2char, ReadMeFile);
    if not result then
        result := OpenFile ('/usr/share/doc/licenserecon/ReadMe', ReadMeFile);
end;

Procedure ShowHelp;
var line   : String;
begin
    Assert (OpenHelpFile, 'Cannot open ReadMe file');

    While not EOF (ReadMeFile) Do
    begin
        Readln (ReadMeFile, Line);
        Writeln (Line);
    end;

    Close (ReadMeFile);
end;

procedure CheckParam (P : String);
begin
    if SameText (P, '-v') or SameText (P, '--version') then
        Option_Version := true
    else if SameText (P, '-h') or SameText (P, '-?') or SameText (P, '--help') then
        Option_Help := True
    else if SameText (P, '-f') or SameText (P, '--format') then
        Option_Format := true
    else if SameText (P, '-s') or SameText (P, '--short')
         or SameText (P, '-t') or SameText (P, '--terse')  then
        Option_Short   := true
    else if SameText (P, '-l') or SameText (P, '--long')   then
        Option_Long := true
    else if SameText (P, '-x') or SameText (P, '--spdx')   then
        Option_SPDX := true
    else
        Writeln (rsIuo + ' ', P); // Ignoring unknown option
end;

procedure GetOptions;
var P : Integer;
begin
    for P := 1 to ParamCount do
        CheckParam (ParamStr(P));

    // This combination make no sense
    if Option_Short then
        Option_Long := False;

    // Setup language id
    GetLanguageIDs(Lang5char, FallbackLang);
    Lang2char := LeftStr(Lang5char, 2);
end;

end.