📄 icl470.pl
字号:
#!/usr/bin/perl
if ($#ARGV == -1)
{
die "\nSyntax is icl470 <C file (with extension)>\n\n";
}
$Cmd_output_dir = "." ;
print "TEMPORARY_FILE_DIR = -$ENV{\"TEMPORARY_FILE_DIR\"}-\n" ;
if ( defined( $ENV{"TEMPORARY_FILE_DIR"} ) )
{
$Cmd_output_dir = $ENV{"TEMPORARY_FILE_DIR"} ;
}
# Pack copmmand line in a single word
$Original_command_line = "";
foreach $Split_command_line (@ARGV)
{
if ( $Split_command_line eq $C_input_file )
{
$Split_command_line = $C_output_file;
}
$Original_command_line = "$Original_command_line $Split_command_line";
}
# DEBUG
# print " New line:\n$Original_command_line\n";
# -------------------------------------------------------------------------------
# Search parameter with a non white-space and finishing with a .c
$Original_command_line =~ /(\S*\.cmd)/;
$C_cmd_file = $1;
$Original_command_line =~ s/(\S*\.cmd)//;
$Original_command_line =~ /(\S*\.c\b)/;
$C_input_file = $1;
if ($C_input_file eq "")
{
die "\n***** No C filename found *****\n\n";
}
# -------------------------------------------------------------------------------
# Remove .c extension and create the new filename for the processed file
@file_name = split /\.c/, $C_input_file;
$C_output_file = join ('', @file_name, "_intram.c");
# DEBUG
# print "Output file: $C_output_file\n";
# -------------------------------------------------------------------------------
# Search object files path and object files extension
$Original_command_line =~ /-eo\s*(\S*).*/;
$Obj_file_ext = $1;
$Original_command_line =~ /-fr\s*(\S+)/;
$Obj_file_path = $1;
#DEBUG
# print "\nPath: $Obj_file_path - Extension: $Obj_file_ext\n";
if ($Obj_file_ext eq "")
{
die "\n***** Object file extension not found *****\n\n";
}
if ($Obj_file_path eq "")
{
die "\n***** Object file path not found *****\n\n";
}
# Need to extract file name without the /
$C_output_file =~ /^.*[\/](.*)\.c/;
$Object_filename = $1;
# DEBUG
# print "File name: $Object_filename\n";
$Object_filename_ext = join ($Object_filename, "$Obj_file_path/", ".$Obj_file_ext");
$Object_filename = join ($Object_filename, "$Obj_file_path/", ".obj");
#DEBUG
# print "Obj File name: $Object_filename_ext $Object_filename\n";
# -------------------------------------------------------------------------------
# Reconstruct command line with the new name
@Split_command_line = split / /,$Original_command_line;
$Nb_elements_split = scalar (@Split_command_line);
$New_command_line = "";
foreach $Split_command_line (@Split_command_line)
{
if ( $Split_command_line eq $C_input_file )
{
$Split_command_line = $C_output_file;
}
$New_command_line = "$New_command_line $Split_command_line";
}
# DEBUG
# print "Original:\t$Original_command_line\n";
# DEBUG
# print "New:\t\t$New_command_line\n";
# -------------------------------------------------------------------------------
# Generates the C file for internal RAM
# Open input file
open input_stream, $C_input_file
or die "\n\n Input C file $C_input_file cannot be opened: $!\n";
# Open output file
open(output_stream,'>'.$C_output_file)
or die "\n\nCan't open output file $C_output_file: $!";
printf output_stream "/* ----- WARNING - File automatically generated - Do not modify it ----- */\n\n\n\n\n";
$d_internal_found = 0;
# Search for data
while(<input_stream>)
{
chomp $_;
# Search for start comment
if ( / *#pragma .*DUPLICATE_FOR_INTERNAL_RAM_START/ )
{
# DEBUG
#print "Found begin of string\n";
$d_internal_found = 1;
if (/ *#pragma GSM_IDLE_DUPLICATE_FOR_INTERNAL_RAM_START/)
{
printf output_stream "#if (GSM_IDLE_RAM != 0)\n";
# check if GSM IDLE FEATURE
}
if (/ *#pragma GSM_IDLE2_DUPLICATE_FOR_INTERNAL_RAM_START/)
{
printf output_stream "#if (GSM_IDLE_RAM == 2)\n";
# check if GSM IDLE FEATURE
}
# Found begin internal RAM code, then output up to the end string
while(<input_stream>)
{
chomp $_;
if ( / *#pragma .*DUPLICATE_FOR_INTERNAL_RAM_END/ )
{
# Found end of the internal RAM code, then search for another one
# DEBUG
#print "Found end of string\n";
if (/ *#pragma GSM_IDLE_DUPLICATE_FOR_INTERNAL_RAM_END/)
{
printf output_stream "#endif\n";
# check if GSM IDLE FEATURE
}
last;
}
else
{
printf output_stream "%s\n", $_;
# DEBUG
#print "Copied lines - $_\n";
}
}
}
}
close input_stream;
close output_stream;
# DEBUG
#print "status of internal RAM copies: $d_internal_found\n";
# -------------------------------------------------------------------------------
# Compile the original file and the generated one
print `$Original_command_line`;
# Compile generated file only if non-empty
if( $d_internal_found != 0)
{
print `$New_command_line`;
# Rename the new object file
rename $Object_filename_ext, $Object_filename;
}
else
{
# DEBUG
#print "File empty\n";
# Remove empty generated file
unlink $C_output_file;
}
# -------------------------------------------------------------------------------
# Search if the object declaration exists into the generated command file
# Add to a command file the object file name
$C_output_file_cmd_file= "$Cmd_output_dir/"."$C_cmd_file";
if( -e $C_output_file_cmd_file )
{
# Open input file
open input_cmd_stream, $C_output_file_cmd_file
or die "\n\n Generated cmd file $C_output_file_cmd_file cannot be opened: $!\n";
# First check if this object file exists into the command file
# DEBUG
#print "Command file exists\n";
if ($d_internal_found != 0)
{
# DEBUG
#print "File yet exists: $Object_filename\n";
push @files_list, $Object_filename;
}
while(<input_cmd_stream>)
{
chomp $_;
# DEBUG
#print "Line read in cmd file: $_\n";
# Save list of the files in a table
if($_ eq $Object_filename)
{
if ($d_internal_found != 0)
{
# DEBUG
#print "File yet exists: $Object_filename\n";
}
else
{
# DEBUG
#print "Remove from the generated command file: $Object_filename\n";
}
}
else
{
push @files_list, $_;
# DEBUG
#print "List of files: @files_list\n";
}
}
close input_cmd_stream;
}
else
{
# DEBUG
#print "Command file does not exists or empty\n";
if ($d_internal_found != 0)
{
# dEBUG
#print "Output file $Object_filename in command file\n";
push @files_list, $Object_filename;
}
}
# DEBUG
#print "List of files: @files_list\n";
# -------------------------------------------------------------------------------
# Update the generated command file
open(output_cmd_stream,'>'.$C_output_file_cmd_file)
or die "\n\nCan't open output file $C_output_file_cmd_file: $!";
foreach $files_list (sort(@files_list))
{
printf output_cmd_stream "%s\n", $files_list;
}
close output_cmd_stream;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -