www.pudn.com > sdk_host_2520.rar > build_sdms.pl


#;/////////////////////////////////////////////////////////////////////////////// 
#; Copyright(C) SigmaTel, Inc. 2000-2001 
#; 
#; Filename: build_SDMs.pl 
#; Description: Builds the Secondary DBCS Maps resource (CodePagePrefix_SDMs.src) 
#;/////////////////////////////////////////////////////////////////////////////// 
 
 
 
#require "build_SDM.pl"; 
require "PDM_SDM.pl"; 
use strict; 
 
 
 
 
#;/////////////////////////////////////////////////////////////////////////////// 
#;> Name: build_SGMs 
#; 
#;  Type: Function 
#;  Description: Builds the Secondary DBCS Maps resource (CodePagePrefix_SDMs.src) 
#                Also, generates SDMs.inc, for use in creating Secondary DBCS Map resources. 
# 
#;  Prototype:   build_SDMs($PrimaryDBCSMapRef, $CodePagePrefix, $defaultUnicodeChar); 
# 
#;  Inputs:      $PrimaryDBCSMapRef  -  Reference to Primary DBCS Map (a hash) 
#                $CodePagePrefix     - First part of Code Page Filename (before the 
#                                      ".TXT").  Used in naming output files. 
#                                      Example: "CP1250" 
#                $defaultUnicodeChar - Default Unicode character: use when no 
#                                      mapping is defined. 
#;  Outputs:     Returns 1 for success, 0 for failure.  (May not return on some 
#                errors.) 
#;  Notes:  
#     This routine creates a number of intermediate files (SDM_xx.src,  
#     SDM.inc, SDM.bin, SDMs_xx.src, SDMs.inc, and prefix_SDMs.bin).  It  
#     will delete them, at the end, if nothing goes wrong.  It it fails,  
#     you'll have to delete them by hand. 
#;< 
#;/////////////////////////////////////////////////////////////////////////////// 
sub build_SDMs { 
 
    my $PrimaryDBCSMapRef = shift; 
    my $CodePagePrefix = shift; 
    my $defaultUnicodeChar = shift; 
 
 
    my $rsclink = "rsclink";  #$tool_dir . "\\rsclink"; 
    my $buildres = "buildres";  #$tool_dir . "\\buildres"; 
 
    my $cntLeadBytes = 0; 
 
    (open SDMs_INC_FILE, ">SDMs.inc") || die "Can't open file: SDMs.inc\n"; 
 
                              # The Primary and Secondary Maps are implemented as  
                              # hashes.  %PrimaryDBCSMap is the Primary Map.  Each 
                              # key (00-ff) is either a Single Byte Character (SBC) 
                              # or the Lead Byte of a Multi (double) Byte Character 
                              # (MBC).  For an SBC key, the value of the hash for  
                              # that key is a Unicode Character.  For an MBC key, 
                              # the value is a reference to another hash - the 
                              # Secondary DBCS Map (SDM) for that Lead Byte.  Some 
                              # keys for the Primary Map may have undefined values. 
                              # These should map to the default Unicode character, 
                              # as SBCs. 
 
    print STDERR "Creating the individual SDMs resources\n"; 
    for (my $LeadByte=0; $LeadByte<=0xff; $LeadByte++) { 
        if ((defined $$PrimaryDBCSMapRef{$LeadByte}) &&  
            (ref $$PrimaryDBCSMapRef{$LeadByte})) {  # MBC 
     
            my $filename = sprintf("SDMs_%02x.src", $LeadByte); 
            build_SDMs_src($filename, $PrimaryDBCSMapRef->{$LeadByte}, $defaultUnicodeChar); 
 
            printf SDMs_INC_FILE "SDMs_%02x\tequ\t%d\t;\$FILENAME $filename\n", 
                $LeadByte, 1 + $cntLeadBytes++; 
        } 
    } 
 
    if (!$cntLeadBytes) { 
        print "No Multi-Byte Characters defined.  Using default SDMs file."; 
        close SDMs_INC_FILE; 
        build_defaultSDM($CodePagePrefix); 
        return 1; 
    } 
 
    print STDERR "Combining SDMs entries into resource file\n"; 
    (system "\"$rsclink\"  -hSDMs.inc -o$CodePagePrefix\_SDMs.bin") == 0 || die "?"; 
 
 
    print STDERR "Converting SDMs resource file to nested resource\n"; 
    (system "\"$buildres\" -z -r$CodePagePrefix\_SDMs.bin") == 0 || die "?"; 
 
 
    close SDMs_INC_FILE; 
 
    print STDERR "Cleaning up after build_SDMs\n"; 
    system "del SDMs_*.src"; 
    system "del $CodePagePrefix\_SDMs.asm"; 
    system "del SDMs.inc"; 
    system "del $CodePagePrefix\_SDMs.bin"; 
 
    return 1; 
} 
 
 
 
 
#;/////////////////////////////////////////////////////////////////////////////// 
#;> Name: build_defaultSDM 
#; 
#;  Type: Function 
#;  Description: Create a placeholder SDMs.src file 
#                (when there are no Secondary DBCS Maps). 
#  
#;  Inputs: $CodePagePrefix  - First part of Code Page Filename 
#;  Outputs:  
#;  Notes:  
#           Creates a dummy SRC file, using a convenient 
#           tool, then renames it to the desired result. 
#;< 
#;/////////////////////////////////////////////////////////////////////////////// 
 
 
sub build_defaultSDM { 
 
    my $CodePagePrefix = shift; 
 
    my $filename = "$CodePagePrefix\_SDMs.src"; 
 
    open(SDM_SRC, ">$filename") || die "Can't open output file: $filename\n"; 
 
    print SDM_SRC "\$RESOURCE_TYPE\n"; 
    print SDM_SRC "DATA\n"; 
    print SDM_SRC "\$REC_SIZE\n"; 
    print SDM_SRC 3+1,"\n"; 
    print SDM_SRC "\$DATA\n"; 
    printf SDM_SRC "%06x\n", 3; 
    print SDM_SRC "000002\n";		              # RSRC_TYPE_DATA 
    print SDM_SRC "000000\n"; 
} 
 
 
1; 
 
#;/////////////////////////////////////////////////////////////////////////////// 
#;/////////////////////////////////////////////////////////////////////////////// 
#;///////////////////////////////////////////////////////////////////////////////