-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicense_check.pl
More file actions
executable file
·236 lines (209 loc) · 4.74 KB
/
license_check.pl
File metadata and controls
executable file
·236 lines (209 loc) · 4.74 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/perl -w
#
# license check: check the file license head
# Copyright Hake Huang 2010, Freescale Semiconductor Inc.
#
# The code contained herein is licensed under the GNU General Public
# License. You may obtain a copy of the GNU General Public License
# Version 2 or later at the following locations:
#
# http://www.opensource.org/licenses/gpl-license.html
# http://www.gnu.org/copyleft/gpl.html
use strict;
use File::Spec::Functions;
my $g_pattern="";
#report file
my $rFile;
#summary file
my $sFile;
#current file name
my $cfile_name="";
my @marks = ();
my $file_cnt=0;
sub add_summary_head{
open($sFile, ">license_summary.html") || die "can not write report";
print $sFile "<head>\n";
print $sFile "<H2>The license_report summary</H2>";
print $sFile "</head>\n";
print $sFile "<body>\n";
}
sub add_summary_end
{
print $sFile "</body>\n";
close($sFile);
}
sub add_summary{
my ($id, $status) = @_ ;
if($status == 0)
{
print $sFile "<div>";
print $sFile "<font color=\"blue\"><a href=\"license_report.html#$id\">$cfile_name</a></font>";
print $sFile "</div>\n";
}else{
print $sFile "<div>";
print $sFile "<a href=\"license_report.html#$id\"><font color=\"red\">!!!!</font>$cfile_name</a>";
print $sFile "</div>\n";
}
}
sub add_report_head{
open($rFile, ">license_report.html") || die "can not write report";
print $rFile "<head>\n";
print $rFile "<H2>The license_report</H2>";
print $rFile "</head>\n";
print $rFile "<body>\n";
}
sub add_report_end
{
print $rFile "</body>\n";
close($rFile);
}
sub add_report{
my ($file_name, $status) = @_ ;
my $servity = 0;
my $cline = "";
$file_cnt++;
if( $file_name ne $cfile_name )
{
print $rFile "<div>";
print $rFile "<a name=\"$file_cnt\"><font color=\"blue\">$file_name</font></a>";
print $rFile "</div>\n";
$cfile_name = $file_name;
}
my $items = @marks;
if( $items == 0 )
{
$servity=1;
print $rFile "<div>";
print $rFile "   <font color=\"red\" >$file_name has not license info </font>";
print $rFile "</div>\n";
}
if ( $status == -1)
{
$servity=1;
print $rFile "<div>";
print $rFile "   <font color=\"red\" >can not open file $file_name </font>";
print $rFile "</div>\n";
}elsif( $status == -2)
{
$servity=1;
print $rFile "<div>";
print $rFile "   <font color=\"red\" >properitary licnese found in $file_name </font>";
print $rFile "</div>\n";
}elsif( $status == -10)
{
$servity=1;
print $rFile "<div>";
print $rFile "   <font color=\"red\" >binary file found in $file_name </font>";
print $rFile "</div>\n";
}elsif( $status == -11)
{
$servity=1;
print $rFile "<div>";
print $rFile "   <font color=\"red\" >swap file found in $file_name </font>";
print $rFile "</div>\n";
}
while($cline=pop(@marks))
{
print $rFile "<div>";
print $rFile "   $cline";
print $rFile "</div>\n";
}
add_summary($file_cnt,$servity);
}
#should be txt file
sub check_file_license{
my($file_name) = @_ ;
my $rt = 0;
my $line = "";
my $count=0;
my $hFile;
open($hFile,"<$file_name") or $rt=-1 ;
while(<$hFile>)
{
$line = $_;
$count++;
$line = $count." ".$line;
if( $line =~ /GPL/i )
{
$rt++;
push(@marks, $line);
next;
}
if ( $line =~ /COPYRIGHT/i )
{
push(@marks, $line);
next;
}
if ( $line =~ /LICENSE/i )
{
push(@marks, $line);
next;
}
if ( $line =~ /PROPRIETARY/i )
{
$rt=-2;
push(@marks, $line);
next;
}
}
close($hFile);
add_report($file_name, $rt);
}
sub search_dir
{
my ($dirpath)=@_;
my $rt = 0;
die "Error: $dirpath not exsit\n" if !$dirpath;
print "Starting search in $dirpath ... \n";
my @list_dirs=();
if (-d $dirpath)
{
push @list_dirs,$dirpath;
}
while($dirpath=pop(@list_dirs))
{
opendir(my $hDir, $dirpath) || (print "Can not open $dirpath" && next);
for my $file_index (readdir($hDir))
{
my $tmp=catfile($dirpath,$file_index);
if (-d $tmp )
{
if($file_index ne '.' && $file_index ne '..')
{
push(@list_dirs,$tmp);
$rt=0;
}
}else{
if ( -T $tmp)
{
if( $tmp =~ /\.swap/i )
{
push(@marks, $tmp);
$rt=-11;
add_report($tmp, $rt);
}else{
search_file($tmp);
}
}else{
push(@marks, $tmp);
$rt=-10;
add_report($tmp, $rt);
}
}
}
}
add_report_end;
add_summary_end;
}
sub search_file
{
my ($filepath)=@_;
if( -T "$filepath" )
{
print "$filepath \n";
&check_file_license($filepath);
}
}
add_report_head;
add_summary_head;
search_dir($ARGV[0]);