?? buildrsccfile.pm
字號(hào):
#!/usr/bin/perl
package BuildRscCFile;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(BuildImg BuildFnt BuildStr BuildDataFile BuildInc CopyAndSave BuildDir BuildCompactDir);
# set up some constants
my $BIG_ENDIAN = 2;
my $LITTLE_ENDIAN = 1;
my $NATIVE_ENDIAN = 0;
@_ui16 = ("S","v","n");
@_ui32 = ("L","V","N");
#config endian
$output_endian = $BIG_ENDIAN;
$ui16 = $_ui16[$output_endian];
$ui32 = $_ui32[$output_endian];
# and export them
@EXPORT_OK = qw($BIG_ENDIAN $LITTLE_ENDIAN $NATIVE_ENDIAN $ui16 $ui32);
#------------------------------------------------------------------------
# RecordAFileIntoDir : Record a file's infomation into a dir file
#
# $DirFile: string, Dir file' name
# $TargetFile: string, target file's name
# $SaveName: string(<=6), target file's save name in dir
# $FileAddress: number(L), target file's save address , 0xFFFFFFFF for unknown yet
# $FileAttr: number(C), target file's attribute
# ------------------------------------------------------------------------
sub RecordAFileIntoDir
{
my ($DirFile,$TargetFile,$FileAttr,$FileAddress) = @_;
my @file_state;
my $SaveName;
$TargetFile =~ /\/*([a-zA-Z0-9_]+)\./;
$SaveName = $1;
# # print "Save name is $SaveName\n";
open (H_DIR_FILE,">>$DirFile") || die ("Error: Can not open $DirFile !");#record every image file's palette info into this dir file
binmode(H_DIR_FILE);
my $temp = syswrite (H_DIR_FILE, $SaveName, 6, 0);
for (;$temp<6;$temp++)
{
syswrite H_DIR_FILE, pack ("C",0); # add to 6 if not enogh
}
syswrite H_DIR_FILE, pack ("C",0); # reserved
syswrite H_DIR_FILE, pack ("C",($FileAttr));
syswrite H_DIR_FILE, pack("$ui32",($FileAddress)); # DWORD for FileAddress, 0xFFFFFFFF for null value, this will be refilled in later procedure
@file_state = stat("$TargetFile");
syswrite H_DIR_FILE, pack("$ui32",$file_state[7]);
close(H_DIR_FILE);
}
sub BuildFnt
{
#### step 1 : get arguments
my ( $FntCFile,$FntBinSaveName , $FntDirFile, $is_zip) = @_;
# print " Build Font file \"$FntCFile\", iszip = $is_zip\n";
#save name should be within 6 chars.
if (length($FntBinSaveName)>6)
{
$FntBinSaveName = substr($FntBinSaveName,0,6);
}
my $FntBinFile = $FntBinSaveName.".fbn";
#### step 2 : declare my data
#const
my $FBN_HEAD_LENGTH = 16;
my $EHVW_INFO_LENGTH = 20;
my $MASS_INFO_LENGTH = 16;
#vars
my $font_flag;
my $char_number;
my $font_height;
my $member_address;
my $line;
my $linenum = 0;
my @file_state;
##
my @proglist;
my $STEP_FONT_INFO = 0;
my $STEP_MCHAR_END_ADDR = 1;
my $STEP_CHAR_INDEX = 2;
my $STEP_CHAR_END = 3;
my $STEP_CHAR_WIDTH = 4;
my $STEP_CHAR_DATA = 5;
my $STEP_OVER = 6;
my $SUB_STEP_SEEK_DATA = 0;
my $SUB_STEP_HANDLE_DATA = 1;
my $ft_info_stru;
my $scanswitch;
my $sub_scan;
my $temp;
#### step 3: open C and Bin files
open (H_FNT_C,$FntCFile) || die ("Error: Can not open file $FntCFile\n");
# print " $FntCFile has been opened !\n";
open (H_FNT_BIN,">$FntBinFile") || die ("Error: Can not open file $FntBinFile !");#record one font data
binmode(H_FNT_BIN);
# for fbn's header 's name part (12 bytes)
$temp = syswrite (H_FNT_BIN, $FntBinSaveName, 12, 0);
for (;$temp<12;$temp++)
{
syswrite H_FNT_BIN, pack ("C",0); # add to 6 if not enogh
}
#### step 4: init some vars
$ft_info_stru = $FntCFile;
$ft_info_stru =~ s/[a-zA-Z0-9_\.]*\\//g; #remove the path part, letf filename only
$ft_info_stru =~ s/\.fnt//; #remove ext name and add _table
$ft_info_stru = "ft_info_".$ft_info_stru;
$ft_info_stru =~ tr/A-Z/a-z/; # structure names in .fnt are all low case
$scanswitch = $STEP_FONT_INFO;
$sub_scan = $SUB_STEP_SEEK_DATA;
#### step 5: deal with .fnt file's data
foreach $line (<H_FNT_C>)
{
$linenum ++;
$line =~ s/(\/\/.*)//; #remove lines marked by //
if ($scanswitch == $STEP_FONT_INFO)
{
if ($line =~ /CHAR_NUM\s+(\d+)/)
{
$char_number = $1;
}
elsif ($line =~ /CHAR_HEIGHT\s+(\d+)/)
{
$font_height = $1;
}
elsif ($line =~ /(EHVW_FONT_INFO|MASS_FONT_INFO)\s+$ft_info_stru/)
{
$font_flag = $1;
if ($font_flag =~ /EHVW_FONT_INFO/)
{
# for fbn's header 's flag part (1 bytes) and reserved part (3 bytes)
syswrite H_FNT_BIN, (pack("C",0x81)); # 10XX 0001 FOR "EH VW . . 1BPP"
syswrite H_FNT_BIN, (pack("C",0));
syswrite H_FNT_BIN, (pack("C",0));
syswrite H_FNT_BIN, (pack("C",0));
# for WORD wCharSetNum;
syswrite H_FNT_BIN, pack("$ui16",$char_number);
# for BYTE bHeight;
syswrite H_FNT_BIN, pack("C",$font_height);
# for BYTE placeholer
syswrite H_FNT_BIN, (pack("C",0));
# for const BYTE* pIndexTable; 2 bytes per item
$member_address = $FBN_HEAD_LENGTH + $EHVW_INFO_LENGTH;
syswrite H_FNT_BIN, (pack("$ui32",$member_address));
# for const WORD * pEndTable; 2 bytes per item
$member_address += $char_number * 2; # add length of pIndexTable
syswrite H_FNT_BIN, (pack("$ui32",$member_address));
# for const BYTE * pWidthTable; 1 byte per item
$member_address += $char_number * 2;# add length of pEndTable
syswrite H_FNT_BIN, (pack("$ui32",$member_address));
# for const BYTE* pFontData;
$member_address += $char_number * 1;# add length of pWidthTable
syswrite H_FNT_BIN, (pack("$ui32",$member_address));
$scanswitch = $STEP_CHAR_INDEX;
}
elsif ($font_flag =~ /MASS_FONT_INFO/)
{
# for fbn's header 's flag part (1 bytes) and reserved part (3 bytes)
syswrite H_FNT_BIN, (pack("C",0x01)); # 00XX 0001 FOR "VH VW . . 1BPP"
syswrite H_FNT_BIN, (pack("C",0));
syswrite H_FNT_BIN, (pack("C",0));
syswrite H_FNT_BIN, (pack("C",0));
# for WORD wCharSetNum;
syswrite H_FNT_BIN, pack("$ui16",$char_number);
# for placeholer
syswrite H_FNT_BIN, (pack("C",0));
syswrite H_FNT_BIN, (pack("C",0));
# for const DWORD * pOffsetTable;
$member_address = $FBN_HEAD_LENGTH + $MASS_INFO_LENGTH;
syswrite H_FNT_BIN, (pack("$ui32",$member_address));
# for const BYTE* pIndexTable;
$member_address += $char_number * 4; # add length of pOffsetTable
syswrite H_FNT_BIN, (pack("$ui32",$member_address));
# for const BYTE* pFontData;
$member_address += $char_number * 2;# add length of pIndexTable
syswrite H_FNT_BIN, (pack("$ui32",$member_address));
$scanswitch = $STEP_MCHAR_END_ADDR;
}
}
}
elsif ($scanswitch == $STEP_MCHAR_END_ADDR)
{
if ($sub_scan == $SUB_STEP_SEEK_DATA)
{
if ($line =~ /mass_char_end_adr\[\]=/)
{
$sub_scan = $SUB_STEP_HANDLE_DATA;
}
}
elsif ($sub_scan == $SUB_STEP_HANDLE_DATA)
{
while ($line =~ /(\d+)/g)
{
syswrite H_FNT_BIN, pack("$ui32",$1);
}
if ($line =~ /}/) #finish handling char_index[]
{
$scanswitch = $STEP_CHAR_INDEX;# next step
$sub_scan = $SUB_STEP_SEEK_DATA; #reset
}
}
}
elsif ($scanswitch == $STEP_CHAR_INDEX)
{
if ($sub_scan == $SUB_STEP_SEEK_DATA)
{
if ($line =~ /char_index\[\]=/)
{
# print " >deal with char_index\[\] at line $linenum\n";
$sub_scan = $SUB_STEP_HANDLE_DATA;
}
}
elsif ($sub_scan == $SUB_STEP_HANDLE_DATA)
{
while ($line =~ /(0x..)/g)
{
syswrite H_FNT_BIN, (pack("C",hex($1)));
}
if ($line =~ /}/) #finish handling char_index[]
{
if ($font_flag =~ /EHVW_FONT_INFO/)#for EHVW char
{
$scanswitch = $STEP_CHAR_END;# next step
$sub_scan = $SUB_STEP_SEEK_DATA; #reset
}
else#for mass char
{
$scanswitch = $STEP_CHAR_DATA;# next step
$sub_scan = $SUB_STEP_SEEK_DATA; #reset
}
}
}
}
elsif ($scanswitch == $STEP_CHAR_END)
{
if ($sub_scan == $SUB_STEP_SEEK_DATA)
{
if ($line =~ /char_end\[\]=/)
{
# print " >deal with char_end\[\] at line $linenum\n";
$sub_scan = $SUB_STEP_HANDLE_DATA;
}
}
elsif ($sub_scan == $SUB_STEP_HANDLE_DATA)
{
while ($line =~ /(\d+)/g)
{
syswrite H_FNT_BIN, (pack("$ui16",$1));
}
if ($line =~ /}/) #finish handling char_end[]
{
$scanswitch = $STEP_CHAR_WIDTH;# next step
$sub_scan = $SUB_STEP_SEEK_DATA; #reset
}
}
}
elsif ($scanswitch == $STEP_CHAR_WIDTH)
{
if ($sub_scan == $SUB_STEP_SEEK_DATA)
{
if ($line =~ /char_width\[\]=/)
{
# print " >deal with char_width\[\] at line $linenum\n";
$sub_scan = $SUB_STEP_HANDLE_DATA;
}
}
elsif ($sub_scan == $SUB_STEP_HANDLE_DATA)
{
while ($line =~ /(\d+)/g)
{
syswrite H_FNT_BIN, (pack("C",$1));
}
if ($line =~ /}/) #finish handling char_width[]
{
$scanswitch = $STEP_CHAR_DATA;# next step
$sub_scan = $SUB_STEP_SEEK_DATA; #reset
}
}
}
elsif ($scanswitch == $STEP_CHAR_DATA)
{
if ($sub_scan == $SUB_STEP_SEEK_DATA)
{
if ($line =~ /char_data\[\]=/)
{
# print " >deal with char_data\[\] at line $linenum\n";
$sub_scan = $SUB_STEP_HANDLE_DATA;
}
}
elsif ($sub_scan == $SUB_STEP_HANDLE_DATA)
{
while ($line =~ /(0x..)/g)
{
syswrite H_FNT_BIN, (pack("C",hex($1)));
}
if ($line =~ /}/) #finish handling char_width[]
{
# $scanswitch = $STEP_OVER;# over
# $sub_scan = $SUB_STEP_SEEK_DATA; #reset
last; #over, jump out of foreach.
}
}
}
}
#### step 6: close C and Bin files
close(H_FNT_BIN);
close (H_FNT_C);
# print " $FntCFile has been closed !\n\n";
#### step 7: build file info in dir file
my $file_attr;
if ($is_zip != 0)
{
$file_attr = 0x42; # 0 1 xx 0010 for (file|zip|font)
@proglist = ("7zip","e", "$FntBinFile", "$FntBinFile".".7z", "-lc0", "-lp2");
system(@proglist);
@proglist = ("mv","$FntBinFile".".7z","$FntBinFile");
system(@proglist);
}
else
{
$file_attr = 0x02; # 0 0 xx 0010 for (file|not-zip|font)
}
RecordAFileIntoDir($FntDirFile,$FntBinFile,$file_attr,0xFFFFFFFF);
}
sub BuildStr
{
#### step 1 : get arguments
my ( $StrCFile, $StrIDFile,$StrBinSaveName, $StrDirFile, $is_zip ) = @_;
# print " Build String file \"$StrCFile\", iszip = $is_zip\n";
#save name should be within 6 chars.
if (length($StrBinSaveName)>6)
{
$StrBinSaveName = substr($StrBinSaveName,0,6);
}
my $StrBinFile = $StrBinSaveName.".sbn";
#### step 2 : declare my data
#const
my $SBN_HEAD_LENGTH = 16;
#vars
my @StrIDs = (""); #reserve first one.
my @StrAddrs = (0); #reserve first one.
my $StringIDIndex;
my $string_number;
my $string_address;
my $line;
my $linenum = 0;
my @file_state;
my @proglist;
my $temp;
#### step 3: open C and Bin files
open (H_STR_C,$StrCFile) || die ("Error: Can not open file $StrCFile\n");
# print " $StrCFile has been opened !\n";
open (H_STR_ID,$StrIDFile) || die ("Error: Can not open file $StrIDFile\n");
# print " $StrIDFile has been opened !\n";
open (H_STR_BIN,">$StrBinFile") || die ("Error: Can not open file $StrBinFile !");#record one font data
binmode(H_STR_BIN);
# for sbn's header 's name part (12 bytes)
$temp = syswrite (H_STR_BIN, $StrBinSaveName, 12, 0); #12 bytes for name
for (;$temp<12;$temp++)
{
syswrite H_STR_BIN, pack ("C",0);
}
#### step 4: deal with String id file
foreach $line (<H_STR_ID>)
{
$line =~ s/(\/\/.*)//; #remove lines marked by //
if ($line =~ /\#define\s+(RS_[A-Z0-9_]+)\s+\d+/)
{
$temp = $1;
$temp =~ tr/A-Z/a-z/;
@StrIDs = (@StrIDs,$temp); #record ids
# # print "$1\n";
}
elsif ($line =~ /\#define\s+STR_TABLE_CELL_NUM\s+\d+/)
{
last;#end
}
}
$string_number = @StrIDs; #num of string ids
syswrite H_STR_BIN, pack("$ui16",0); #reserved 2 bytes
syswrite H_STR_BIN, pack("$ui16",$string_number);
#### step 5: deal with .str file
## step 5.1: string data part
$string_address = $SBN_HEAD_LENGTH + 4 * $string_number;
seek (H_STR_BIN, $string_address, 0); #jump over table area.
# # print "step 5.1 start \n";
# # print "????1???? $StrAddrs[$StringIDIndex] \n";
$StringIDIndex = 1;
foreach $line (<H_STR_C>)
{
$line =~ s/(\/\/.*)//; #remove lines marked by //
$line =~ s/(\s*)//g; #remove all space for easy patten
if ($line =~ /constBYTE($StrIDs[$StringIDIndex])[a-z0-9_]+\[\]=/)
{
$StrAddrs[$StringIDIndex] = $string_address;
while ($line =~ /(0x..)/g)
{
$string_address ++;
syswrite H_STR_BIN, pack("C",hex($1));
}
$StringIDIndex ++;
if ($StringIDIndex >= @StrIDs)
{
last;
}
}
}
if ($StringIDIndex < @StrIDs)
{
print "Warning: String No.$StringIDIndex is missed in file \n $StrCFile !!!\n";
}
# # print "step 5.1 over \n";
## step 5.2: string table part
seek(H_STR_BIN,$SBN_HEAD_LENGTH,0); #move file pointer to table area.
for ($StringIDIndex = 0;$StringIDIndex<@StrIDs;$StringIDIndex++)
{
syswrite H_STR_BIN, pack("$ui32",$StrAddrs[$StringIDIndex]);
}
#### step 6: close C and Bin files
close(H_STR_BIN);
close (H_STR_ID);
close (H_STR_C);
# print " $StrIDFile has been closed !\n";
# print " $StrCFile has been closed ! \n\n";
#### step 7: build file info in dir file
my $file_attr;
if ($is_zip != 0)
{
$file_attr = 0x43; # 0 1 xx 0011 for (file|zip|string)
@proglist = ("7zip","e","$StrBinFile", "$StrBinFile".".7z", "-lc0", "-lp2");
system(@proglist);
@proglist = ("mv","$StrBinFile".".7z","$StrBinFile");
system(@proglist);
}
else
{
$file_attr = 0x03; # 0 0 xx 0011 for (file|not-zip|string)
}
RecordAFileIntoDir($StrDirFile,$StrBinFile,$file_attr,0xFFFFFFFF);
}
sub BuildImg
{
#### step 1 : get arguments
my ( $ImgCFile, $ImgBinFile, $ImgDirFile, $is_zip,$PalDirFile) = @_;
# print " Build Image file \"$ImgCFile\", iszip = $is_zip\n";
#### step 2 : deal with data in image C file
#const
my $STEP_OPEN_IID = 0;
my $STEP_FIND_BPP = 1;
my $STEP_FIND_TABLE = 2;
my $STEP_FIND_PALETTE = 3;
my $STEP_RECORD_PALETTE = 4;
my $STEP_RECORD_TABLE = 5;
my $STEP_FIND_DATA = 6;
my $STEP_HANDLE_DATA = 7;
my $PAL_FILE_ATTR = 0x04; # not-zip palette file
#var
# my $first_create;
my $scan_step;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -