#!/usr/local/bin/perl $fp_bool = open(FPW, ">2.e"); if( $fp_bool == 0 ) { print ("by PK open fail file is 2.e\n"); exit(1); } select(FPW); $fp_bool = open(FPR, $ARGV[0]); if( $fp_bool == 0 ) { print ("open fail $ARGV[0]\n"); } $start="{"; $stop ="}"; $start_n=0; $stop_n =0; $start1="("; $stop1 =")"; $start_n1=0; $stop_n1 =0; $offset=0; $offset_step=2; $offset_exp=0; #exceptional cases offset $lineN=0; #current line number read_line($line, $lineN); while( $line ne "" ) { # select(stdout); # 0 1 2 3 4 5 offset_U($line, $start_n, $stop_n, $start, $stop, $offset_exp); offset_U($line, $start_n1, $stop_n1, $start1, $stop1, $offset_exp); # print("(start $start_n1 stop $stop_n1\n"); # print("{start $start_n stop $stop_n \n"); # select(FPW); if($stop_n > 0) { $offset -= ($offset_step * $stop_n); } if($stop_n1 > 0) { $offset -= ($offset_step * $stop_n1); } trim_S($line, $offset, $offset_exp); # select(stdout); # print("$line"); $temp = $line; $temp =~ s/^\t//g; $temp =~ s/ //g; # print("$temp"); # select(FPW); if($start_n > 0) { $offset += ($offset_step * $start_n); } if($start_n1 > 0) { $offset += ($offset_step * $start_n1); } #dbg # if($lineN == 195 || $lineN == 196 || $lineN==197) { # prt_msg( # "start1 " . # $start_n . " " . $stop_n . " " . # $start_n1 . " " . $stop_n1 . " " . $offset, # $lineN # ); # } #dbg read_line($line, $lineN); }# end while sub trim_S { $i=0; $l=length($_[0]); $line =~ s/^\t//g; #get rid of TABs. if( $_[0] =~ /'>/ ) { #specman specific. #We should not insert any leading spaces or TABs. #We simply print it as it was in the file. print("$_[0]"); } else { #Count spaces. while( substr($_[0], $i, 1) =~ / / && ($i < $l) ) { $i++; } $s=substr($_[0], $i, ($l-$i)); #Handle negative offset values. Negative values are the result of special #remarks or code error i.e. unbalanced { or (. if($_[1] < 0 ) { prt_msg("negative value = " . $_[1] . "\^" . $_[0], $lineN); $_[1]=0; } #Add spaces. $h=""; $i=$_[1] + $_[2]; # print("...$i "); while($i > 0) { $i--; $h = $h . " "; } $result=$h . $s; print("$result"); } } sub get_S { $i=0; $l=length($_[0]); while( substr($_[0], $i, 1) =~ / / && $i < $l ) { $i++; } } #Works on line [0] and updates start and stop [1] and [2]. #0 line 1 start number 2 stop number 3 start char 4 stop char #5 offset exceptional sub offset_U { $_[1]=0; $_[2]=0; $_[5]=0; $k=0; # string under search pointer. $l =length($_[0]); $k1=length($_[3]); $k2=length($_[4]); $my_line=""; #Clean line/line tail from VHDL/Verilog remark (// or --). rm_remarks($_[0], $my_line); if($my_line =~ /}.*else.*{/) { #exceptional event $_[1] = 1; $_[2] = 1; $_[5] = 2; } else { #regular while($k < $l) { #if(substr($my_line, $k, $k1) =~ /$_[3]/) {}#Is it a begin if(substr($my_line, $k, $k1) eq $_[3]) { #Is it a begin $_[1]++; $k += $k1; } else { #if(substr($my_line, $k, $k2) =~ /$_[4]/) {}#Is it an end if(substr($my_line, $k, $k2) eq $_[4]) { #Is it an end $_[2]++; $k += $k2; } else { #This is nither begin nor end. $k++; } } } #end while #Prepare results and finish. if($_[1] == $_[2]) { $_[1] = 0; $_[2] = 0; } else { if($_[1] > $_[2]) { $_[1] = $_[1] - $_[2]; $_[2] = 0; } else { $_[2] = $_[2] - $_[1]; $_[1] = 0; } } } #end of regular else } sub read_line { $_[1]++; $_[0]=; $_[0]=~ s/^\t//g; $_[0]=~ s/\t/ /g; } #Clean line/line tail from VHDL/Verilog remark (// or --). sub rm_remarks { $rl=length($_[0]); $ri=0; #position in string of verilog remark //, vhdl remark --, and string " $str_pos=0; $_[1]=$_[0]; #$_[1] is the result. #Fix string problem. When the // or -- are enclosed in a "..." string, #we should not treat it as a remark. if($_[0] =~ /\"/ ) { $str_pos=index($_[0], "\"", 0); } else { $str_pos=length($_[0]) + 1; } #remove remark if($_[0] =~ /\/\//) { if( index($_[0], "\/\/", 0) < $str_pos ) { @ra=split(/\/\//, $_[0]); $_[1]=$ra[0]; } } else { if($_[0] =~ /--/) { if( index($_[0], "--", 0) < $str_pos ) { @ra=split(/--/, $_[0]); $_[1]=$ra[0]; } } } } # 0 string to print to screen. # 1 line number in file under test. sub prt_msg { select(stdout); print("$_[0] at line $_[1]\n"); select(FPW); }