1 ################################################################################
2 # Copyright (c) [2017-2019] [Radisys] #
4 # Licensed under the Apache License, Version 2.0 (the "License"); #
5 # you may not use this file except in compliance with the License. #
6 # You may obtain a copy of the License at #
8 # http://www.apache.org/licenses/LICENSE-2.0 #
10 # Unless required by applicable law or agreed to in writing, software #
11 # distributed under the License is distributed on an "AS IS" BASIS, #
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13 # See the License for the specific language governing permissions and #
14 # limitations under the License. #
15 ################################################################################
20 use Time::HiRes qw(usleep);
23 #if($ARGV[1] eq "INTEL") {
25 # print "Make DB Script ERROR: More than two arument is passed to script\n";
30 # print "Make DB Script ERROR: More than two arument is passed to script\n";
34 ###########################################################
35 # Reading File name and creating DB file name.
36 # my $OrgFileName = $ARGV[0]; # Copied File name in to a varible.
37 # my @spltname = split('/', $OrgFileName);
38 my $numelem = $#spltname;
39 my $fileName = $spltname[$numelem];
41 #variable declaration.
62 #my $isModuleNameFound = 0;
63 my $greatestTokenID = 0;
69 ###########################################################
70 # Declare the subroutines
76 # Perl trim function to remove whitespace from the start and end of the string
84 # Left trim function to remove leading whitespace
91 # Right trim function to remove trailing whitespace
100 my @dbFilesDir = ($ARGV[2]);
102 # Process the file and generate the log DB for the file
103 #print "Arguments passed are ", @ARGV, "\n";
104 #print "Calling process of the file with argument ", $ARGV[1], "\n";
105 parse_preproc_file($ARGV[1]);
107 sub parse_preproc_file {
108 my $OrgFileName = shift;
109 #print "File passed is ", $OrgFileName, "\n";
112 my $dbFileName = sprintf("%s%s", $OrgFileName,".db");
115 my $isModuleIdFound = 0;
116 my $isFileIdFound = 0;
117 my $isModuleNameFound = 0;
121 # Opening source.i file and DB file
122 # print "FILE:$OrgFileName\n";
123 `cp -f $OrgFileName $OrgFileName.bak`;
124 if($tmp eq "INTEL") {
125 #print "Removing # for INTEL";
126 system("sed -i '/^#/d' $OrgFileName");
127 } elsif($tmp eq "XEON"){
128 #print "Remove # for XEON";
129 system("sed -i '/stdlib\-bsearch.h/s/^#//g' $OrgFileName");
130 system("sed -i '/^#/d' $OrgFileName");
131 system("sed -i '/stdlib\-bsearch.h/s/^/#/g' $OrgFileName");
133 #print "Don't Remove # for BRCM";
134 #system("sed -i '/^#/d' $OrgFileName");
137 open FILE, "<$OrgFileName" or die $!;
138 open my $OUTPFILE, '>', "$OrgFileName.tmp" or die "Can't write new file: $!";
142 if (( $_ =~ /logLev[0-4EHS]/ ) && ( $_ !~ /}[;]*/) && ( $_ !~ /R_LOG_LEVEL/)) {
149 if( ($_ =~ /}[;]*/) && ($fromFound == 1) ) {
150 $concatStr =~ s/(.*)(logLev[E0-4HS]) +(.*)/$1$2$3/g;
151 print $OUTPFILE $concatStr;
157 if ($fromFound == 1) {
159 $concatStr = $concatStr.$_;
161 #print $OUTPFILE "/* AARTI4*/";
162 $_ =~ s/(.*)(logLev[E0-4HS]) +(.*)/$1$2$3/g;
168 `mv -f $OrgFileName.tmp $OrgFileName`;
170 open(INFILE, "< $OrgFileName") || die("Make DB Script ERROR: Cannot open file $OrgFileName for parse");
171 open $tmpfile, "> $OrgFileName.tmp.i" || die("Data Base ERROR: Cannot Create temporary file");
172 open ($dbfile, '>' , "$OrgFileName.tmp.db") || die("Data Base ERROR: Cannot create the file $dbFileName");
173 ##########################################################
174 # Read each line and create the DB entries
176 if (($isModuleIdFound != 1) || ($isFileIdFound != 1) || ($isModuleNameFound !=1)) {
177 if (/(\s*.*)RLOG_MODULE_ID(\s*.*)=(\s*.*);/) {
179 $isModuleIdFound = 1;
182 if (/(\s*.*)RLOG_FILE_ID(\s*.*)=(\s*.*);/) {
185 #print "FILE $OrgFileName FILE ID $fileId [$1] [$2] [$3]\n";
187 if (/(\s*.*)*RLOG_MODULE_NAME(\s*.*)=(\s*.*);/) {
189 $moduleName = substr($moduleName,1);
190 $moduleName = substr($moduleName, 0, -1);
191 $isModuleNameFound = 1;
195 } elsif (/(\s*.*)(logLev[E0-4HS]\()(\s*.*\,)(\s*\".*\")(\s*.*)/) {
202 if( $3 =~ m/_LOGID/ ) {
203 my $fmtStr = $CString;
204 @variables = split(/,/, $CVarible);
205 my $arrSize = $#variables;
206 my $line = $variables[$arrSize];
207 my $file = $variables[$arrSize-1];
209 if ($fileId < 0x3FF) {
210 $tokenID = ($fileId << 16)|(++$logNum);
211 $hexTokenID = sprintf("0x%x", $tokenID);
212 } else { print "SOME ERROR MODID:$moduleId FILEID:$fileId\n";
216 $CVarible =~ s/_LOGID/$hexTokenID/;
218 print $tmpfile "$CStart$CPattern$CVarible$CString$CEnd\n";
219 print $dbfile "$tokenID;$line;$moduleName;$file;$fmtStr\n";
225 $lineNum = $lineNum + 1;
228 ##########################################################################
229 #Close all files and create final output file
235 #if( $generatedb eq 1) {
236 `cp -f $OrgFileName.tmp.i $OrgFileName`;
237 `mv -f $OrgFileName.tmp.db $dbFileName`;
238 `dos2unix -q $OrgFileName`;
239 `dos2unix -q $dbFileName`;
240 `rm -f $OrgFileName.tmp.i`