blob: 3fdcd513d08ddb9fed9a225ac3fba8e308857c2e [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001use strict;
2use warnings;
3
4
5package CMIF_Structure_Check;
6use File::Find;
7return 1;
8
9sub crc32 {
10 my ($input, $init_value, $polynomial) = @_;
11
12 $init_value = 0 unless (defined $init_value);
13 $polynomial = 0xedb88320 unless (defined $polynomial);
14
15 my @lookup_table;
16
17 for (my $i=0; $i<256; $i++) {
18 my $x = $i;
19 for (my $j=0; $j<8; $j++) {
20 if ($x & 1) {
21 $x = ($x >> 1) ^ $polynomial;
22 } else {
23 $x = $x >> 1;
24 }
25 }
26 push @lookup_table, $x;
27 }
28
29 my $crc = $init_value ^ 0xffffffff;
30
31 foreach my $x (unpack ('C*', $input)) {
32 $crc = (($crc >> 8) & 0xffffff) ^ $lookup_table[ ($crc ^ $x) & 0xff ];
33 }
34
35 $crc = $crc ^ 0xffffffff;
36
37 return $crc;
38}
39
40sub file_checksum_input{
41 my ($filename) = @_;
42 open(FILE,$filename) or die "Could not open $filename, $!";
43 my $str="";
44 my @keyword=<FILE>;
45
46 close(FILE);
47 $str=join("",@keyword);
48
49 return $str;
50}
51
52my @all_list;
53sub want
54{
55 if($_ =~ /\.h$/){
56 push @all_list, $File::Find::name;
57 }
58}
59sub folder_checksum_input{
60
61 my ($foldername) = @_;
62 find(\&want ,$foldername);
63 my $str="";
64 my $total_str="";
65 foreach (sort{crc32($a)<=>crc32($b)}@all_list)
66 {
67 open(FILE,$_);
68 my @keyword=<FILE>;
69 close(FILE);
70 $str=join("",@keyword);
71 $total_str = join($total_str,"",$str);
72 }
73 @all_list = ();
74 return $total_str;
75}
76
77sub merge_checksum_input{
78 my (@pathlist)=@_;
79 my $checksum_input="";
80 my $checksum_str="";
81 foreach (@pathlist)
82 {
83 if($_ =~ /\.h$/){
84 $checksum_str=file_checksum_input($_);
85 $checksum_input = join($checksum_input,"",$checksum_str);
86 }
87 else{
88 $checksum_str=folder_checksum_input($_);
89 $checksum_input=join($checksum_input,"",$checksum_str);
90 }
91 }
92 return $checksum_input;
93}
94
95sub get_cmif_checksum_value{
96 my($cmif_folder_path)=@_;
97 my $CMIF_SS_FILE_PATH=$cmif_folder_path;
98 my $checksum_value=sprintf("%d",&crc32(&folder_checksum_input($CMIF_SS_FILE_PATH)) );
99 $checksum_value=join($checksum_value,"","u");
100 return $checksum_value;
101
102
103}
104
105
106##############################
107# test code
108##############################
109#my @TEST= ($ARGV[0]);
110#printf "%x",get_cmif_checksum_value(@TEST);
111#print "\n"
112
113
114
115