-
Notifications
You must be signed in to change notification settings - Fork 3
/
systemscanner.dpr
134 lines (126 loc) · 4.17 KB
/
systemscanner.dpr
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
program systemscanner;
uses
readtxt2,sysutils, contnrs, classes, process, util;
var
line : string;
currentpackage, currentversion, currentsourcepackage, currentsourceversion, currentstatus, currentbuiltusing :string;
sourcesandversions : tfphashlist;
procedure reset;
begin
currentpackage := '';
currentversion := '';
currentsourcepackage := '';
currentsourceversion := '';
currentstatus := '';
currentbuiltusing := '';
end;
procedure processpackage;
var
inbrackets : boolean;
dependency : string;
sourceandversion : string;
builtusingstringlist : tstringlist;
i : integer;
begin
if currentversion = '' then begin
writeln(erroutput,'package without version!');
halt;
end;
if currentsourcepackage = '' then currentsourcepackage := currentpackage;
if currentsourceversion = '' then currentsourceversion := currentversion;
sourceandversion := currentsourcepackage + ' ' +currentsourceversion;
//writeln(erroutput,sourceandversion);
if sourcesandversions.findindexof(sourceandversion) < 0 then sourcesandversions.add(sourceandversion,pointer($deadbeef));
if currentbuiltusing <> '' then begin
builtusingstringlist := tstringlist.create;
extractstrings([','],[' '],pchar(currentbuiltusing),builtusingstringlist);
for i := 0 to builtusingstringlist.count-1 do begin
sourceandversion := stringreplace(builtusingstringlist[i],' (= ',' ',[]);
setlength(sourceandversion,length(sourceandversion)-1);
writeln('!'+sourceandversion);
if sourcesandversions.findindexof(sourceandversion) < 0 then sourcesandversions.add(sourceandversion,pointer($deadbeef));
end;
builtusingstringlist.free;
end;
end;
procedure processtext(t : treadtxt; stripinitialspace : boolean);
var
p : integer;
sourcelinecontent : string;
begin
reset;
repeat
line := t.readline;
if stripinitialspace and (length(line) > 0) then begin
if line[1] = ' ' then line := copy(line,2,maxlongint);
end;
//writeln(erroutput,line);
if stringstartis(line,'Package:') then begin
currentpackage := trim(copy(line,9,maxlongint));
end;
if stringstartis(line,'Version:') then begin
currentversion := trim(copy(line,9,maxlongint));
end;
if stringstartis(line,'Source:') then begin
sourcelinecontent := trim(copy(line,8,maxlongint));
p := pos('(',sourcelinecontent);
if p = 0 then begin
currentsourcepackage := sourcelinecontent;
end else begin
currentsourcepackage := trim(copy(sourcelinecontent,1,p-1));
currentsourceversion := copy(sourcelinecontent,p+1,255);
p := pos(')',currentsourceversion);
currentsourceversion := trim(copy(currentsourceversion,1,p-1));
end;
end;
if stringstartis(line,'Built-Using:') then begin
currentbuiltusing := trim(copy(line,13,maxlongint));
end;
if stringstartis(line,'Status:') then begin
currentstatus := trim(copy(line,8,maxlongint));
end;
if line = '' then begin
//end of block
if currentpackage <> '' then processpackage;
reset;
end;
until t.eof;
if currentpackage <> '' then processpackage;
end;
var
t: treadtxt;
i: integer;
s : tsearchrec;
findresult : longint;
param : string;
process : tprocess;
begin
sourcesandversions := tfphashlist.create;
for i := 1 to paramcount do begin
param := paramstr(i);
writeln(erroutput,'scanning '+param);
if param[length(param)] = '/' then begin
findresult := findfirst(param+'*.deb',faReadOnly or fahidden or fasysfile or faarchive,s);
while findresult = 0 do begin
writeln(erroutput,' reading info from '+s.name);
process := tprocess.create(nil);
process.options := [poUsePipes];
process.commandline := 'dpkg-deb --info '+param+s.name;
process.execute;
t := treadtxt.create(process.output,false);
processtext(t,true);
t.free;
process.free;
findresult := findnext(s);
end;
findclose(s);
end else begin
t := treadtxt.createf(param);
processtext(t,true);
t.free;
end;
end;
for i := 0 to sourcesandversions.count - 1 do begin
writeln(sourcesandversions.nameofindex(i));
end;
end.