blob: 44a320acefde370d7820d25526b0b4d7f186b975 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001#!/usr/bin/perl
2#
3# Copyright Statement:
4# --------------------
5# This software is protected by Copyright and the information contained
6# herein is confidential. The software may not be copied and the information
7# contained herein may not be used or disclosed except with the written
8# permission of MediaTek Inc. (C) 2005
9#
10# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
11# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
12# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
13# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
14# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
15# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
16# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
17# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
18# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
19# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
20# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
21# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
22#
23# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
24# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
25# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
26# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
27# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
28#
29# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
30# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
31# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
32# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
33# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
34#
35#
36#!/usr/bin/perl
37# filter out the lines having PVCS Log
38use File::Copy;
39
40# Log Area Turn on Criteria:
41# 1. match $log_turnon in one line and match "^ \*-{75}" in the next line, log area begin from the next line
42$log_turnon = " \* Below this line, this part is controlled by PVCS VM\. DO NOT MODIFY!!";
43$log_turnon_slim = "\* Below this line, this part is controlled by PVCS VM\. DO NOT MODIFY!!";
44# 2. match " * $Revision: ... $", " * $Modtime: ... $" or " * $Log: ... $", log area begin from this line
45
46# Log Area Turn on Criteria:
47# 1. match $log_turnoff and log area is before this line
48$log_turnoff = " \* Upper this line, this part is controlled by PVCS VM\. DO NOT MODIFY!!";
49$log_turnoff_slim = "\* Upper this line, this part is controlled by PVCS VM\. DO NOT MODIFY!!";
50# 2. match "^ \*-{75}" and $log_turnon is not in previous line
51# 3. match "^ \*{15}\*+\/" and $log_turnon is not in previous line
52
53$author_turnon = " \* Author:";
54$author_turnon_slim = "\* Author:";
55
56$revision_turnon = "\; \* Revision History";
57$revision_turnon_slim = "\;\* Revision History";
58
59$revision_turnoff = "\; \******************************";
60$revision_turnoff_slim = "\;\******************************";
61
62#
63# parsing command arguments
64#
65
66my $reading;
67my $line_no;
68my $debug_print = 0; # 1 for debug; 0 for non-debug
69
70if (!($ARGV[0] =~ /\.(h|c|hpp|cpp|s|java|txt|inc)$/i))
71{
72 &usage;
73}
74
75if ($#ARGV < 1)
76{
77 $TMP_FILE = "~log_fil($$).tmp";
78}
79else
80{
81 $TMP_FILE = $ARGV[1];
82}
83
84#
85# open source file & result file
86#
87my $SRC_FILE = $ARGV[0];
88my $is_exist = 0;
89$is_exist = 1 if -e $SRC_FILE;
90if ($is_exist == 1)
91{
92 open SRC_FILE_R , "+<$SRC_FILE" or die "cannot open $SRC_FILE\n";
93}
94else
95{
96 die "cannot find $SRC_FILE\n";
97}
98
99#
100# search the PVCS $Log & remove them
101#
102$is_log_area = -1; # -1: not in a log area
103 # 0: possibly the beginning of the area
104 # 1: in a log area
105
106$is_author_area = -1; # -1: not in a author area
107 # 0: possibly the beginning of the area
108 # 1: in a author area
109
110$is_revision_area = -1;# -1: not in a author area
111 # 0: possibly the beginning of the area
112 # 1: in a author area
113$line_no = 1;
114my $SRC_FILE_RW;
115foreach (<SRC_FILE_R>)
116{
117 my $read_line = $_;
118 $read_line =~ s/\r\n$/\n/;
119
120 print "$line_no\t" if ($debug_print == 1);
121 if (((index($read_line, $log_turnon) >=0) || (index($read_line, $log_turnon_slim) >=0)) && ($is_log_area == -1))
122 {
123 $SRC_FILE_RW .= $read_line;
124 $is_log_area = 0;
125 $turnon_line_no = $line_no;
126 print "Log Area $is_log_area\n" if ($debug_print == 1);
127 }
128 elsif (/^\;? ?\*-{75}/)
129 {
130 $SRC_FILE_RW .= $read_line;
131 $is_log_area = (($is_log_area == 0) && ($line_no == $turnon_line_no+1)) ? 1 : -1;
132 print "Log Area $is_log_area\n" if ($debug_print == 1);
133 }
134 elsif (/^\;? ?\*{15}\*+\//)
135 {
136 $SRC_FILE_RW .= $read_line;
137 $is_log_area = (($is_log_area == 0) && ($line_no == $turnon_line_no+1)) ? 1 : -1;
138 print "Log Area $is_log_area\n" if ($debug_print == 1);
139 }
140 elsif (((index($read_line, $log_turnoff) >=0) || (index($read_line, $log_turnoff_slim) >=0)) && ($is_log_area == 1))
141 {
142 $SRC_FILE_RW .= $read_line;
143 $is_log_area = -1;
144 print "Log Area $is_log_area\n" if ($debug_print == 1);
145 }
146 elsif (/^(\;?) ?\* \$Revision:.*\$$/) # match " * $Revision: ... $"
147 {
148 ($1 eq '')? ($read_line =~ s/^ ?\* .*/ \* removed!/) : ($read_line =~ s/^\; \* .*/\; \* removed!/);
149 $SRC_FILE_RW .= $read_line;
150 $is_log_area = 1;
151 print "Log Area $is_log_area\n" if ($debug_print == 1);
152 }
153 elsif (/^(\;?) ?\* \$Modtime:.*\$$/) # match " * $Modtime: ... $"
154 {
155 ($1 eq '')? ($read_line =~ s/^ ?\* .*/ \* removed!/) : ($read_line =~ s/^\; \* .*/\; \* removed!/);
156 $SRC_FILE_RW .= $read_line;
157 $is_log_area = 1;
158 print "Log Area $is_log_area\n" if ($debug_print == 1);
159 }
160 elsif (/^(\;?) ?\* \$Log:.*\$$/) # match " * $Log: ... $"
161 {
162 ($1 eq '')? ($read_line =~ s/^ ?\* .*/ \* removed!/) : ($read_line =~ s/^\; \* .*/\; \* removed!/);
163 $SRC_FILE_RW .= $read_line;
164 $is_log_area = 1;
165 print "Log Area $is_log_area\n" if ($debug_print == 1);
166 }
167 elsif (((index($read_line, $author_turnon) >=0) || (index($read_line, $author_turnon_slim) >=0)) && ($is_author_area == -1))
168 {
169 $SRC_FILE_RW .= $read_line;
170 $is_author_area = 0;
171 print "Author on\n" if ($debug_print == 1);
172 }
173 elsif (((index($read_line, $revision_turnon) >= 0) || (index($read_line, $revision_turnon_slim) >= 0)) && ($is_revision_area == -1))
174 {
175 $SRC_FILE_RW .= $read_line;
176 $is_revision_area = 0;
177 print "Revision on\n" if ($debug_print == 1);
178 }
179 elsif (((index($read_line, $revision_turnoff) >= 0) || (index($read_line, $revision_turnoff_slim) >= 0)) && ($is_revision_area == 1))
180 {
181 $SRC_FILE_RW .= $read_line;
182 $is_revision_area = -1;
183 print "Revision Area $is_revision_area\n" if ($debug_print == 1);
184 }
185 elsif (/^\;? ?\* -{6}/)
186 {
187 $SRC_FILE_RW .= $read_line;
188 $is_author_area = ($is_author_area == 0) ? 1 : -1;
189 print "Log Area $is_log_area\n" if ($debug_print == 1);
190 }
191# Not remove author information from the scatter file.
192# elsif ((/^\; \* -{6}/) && ($is_author_area == 0))
193# {
194# $SRC_FILE_RW .= $read_line;
195# $is_author_area = 1;
196# print "Log Area $is_author_area\n" if ($debug_print == 1);
197# }
198 elsif ((/^\; \* -{6}/) && ($is_revision_area == 0))
199 {
200 $SRC_FILE_RW .= $read_line;
201 # $is_revision_area = ($is_revision_area == 0) ? 1 : -1;
202 $is_revision_area = 1;
203 print "Revision Area $is_revision_area\n" if ($debug_print == 1);
204 }
205 else
206 {
207 if ($is_log_area == 1)
208 {
209 if ($read_line =~ /^ ?\* .*/)
210 {
211 $read_line =~ s/^ ?\* .*/ \* removed!/; # For C source file log removal
212 }
213 elsif ($read_line =~ /^\;.*/)
214 {
215 $read_line =~ s/^\;.*/\; \* removed!/; # For assembly language source file log removal
216 }
217 $SRC_FILE_RW .= $read_line;
218 print "log removed\n" if ($debug_print == 1);
219 }
220 elsif ($is_author_area == 1)
221 {
222 if ($read_line =~ /^ ?\*\s+\S+/)
223 {
224 $read_line =~ s/^ ?\*.*/ \* -------/;
225 }
226 elsif ($read_line =~ /^\; \*?\s+\S+/)
227 {
228 if ($SRC_FILE =~ /scat\w+\.txt/i)
229 {
230 $read_line =~ s/^\; \*.*/\; \* -------/; # For scatter file author removal
231 $is_author_area = -1;
232 }
233 else
234 {
235 $read_line =~ s/^\; \*.*/\; \* -------/; # For assembly language source file author removal
236 }
237 }
238 else
239 {
240 $is_author_area = -1;
241 }
242 $SRC_FILE_RW .= $read_line;
243 print "author removed\n" if ($debug_print == 1);
244 }
245 elsif ($is_revision_area == 1)
246 {
247 $read_line =~ s/^\; \* .*/\; \* removed!/; # For scatter file revision history removal
248 $SRC_FILE_RW .= $read_line;
249 $is_revision_area = 1;
250 print "Revision removed\n" if ($debug_print == 1);
251 }
252 else
253 {
254 if (($read_line =~ /^ ?\* \S{3} \d{1,2} \d{4} \S{8}/) || ($read_line =~ /^ ?\* \[MAUI_\d{8}\]/) || ($read_line =~ /^ ?\* \[MOLY_\d{8}\]/)) {
255 $read_line =~ s/^ ?\* .*/ \* removed!/; # For C source file revision history removal
256 }
257 elsif (($read_line =~ /^\; \* \S{3} \d{1,2} \d{4} \S{8}/) || ($read_line =~ /^\; \* \[MAUI_\d{8}\]/) || ($read_line =~ /^ ?\* \[MOLY_\d{8}\]/)) {
258 $read_line =~ s/^\; \* .*/\; \* removed!/; # For assembly language source file revision history removal
259 }
260 $SRC_FILE_RW .= $read_line;
261
262 print "remained\n" if ($debug_print == 1);
263 }
264 }
265 $line_no ++;
266 if ( ( ($is_log_area != -1)||($is_author_area != -1) ) && ($line_no > 150) )
267 {
268 #system "echo Possible ERROR in line $SRC_FILE $line_no [$is_log_area,$is_author_area]!! >> fil.log";
269 #exit(0);
270 }
271} # foreach (<SRC_FILE_R>) of parsing directives: #if, #ifdef, #ifndef, #endif, #else, #elif
272
273if ($TMP_FILE eq $SRC_FILE)
274{
275 # clear all file content
276 truncate(SRC_FILE_R, 0);
277 seek(SRC_FILE_R, 0, 0);
278 print SRC_FILE_R $SRC_FILE_RW;
279 close SRC_FILE_R;
280}
281else
282{
283 close SRC_FILE_R;
284 open SRC_FILE_RW, ">$TMP_FILE" or die "cannot write $TMP_FILE\n";
285 print SRC_FILE_RW $SRC_FILE_RW;
286 close SRC_FILE_RW;
287 move("$TMP_FILE","$SRC_FILE") or move("$TMP_FILE","$SRC_FILE") or die "Error: log_fil can not move cover file, please check it is read only or not $SRC_FILE\n";
288}
289exit 0;
290
291
292# show usage
293sub usage
294{
295 print "USAGE: perl log_fil.pl <source file> <tmpfile>\n";
296 exit(1);
297}