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


#;/////////////////////////////////////////////////////////////////////////////// 
#; Copyright(C) SigmaTel, Inc. 2000-2001 
#; 
#; Filename: build_scripts.pl 
#; Description: 
#     build_scripts.bat 
#     Builds the Scritps resource (prefix_scripts.src) 
# 
#     The "PGM_list" and "SGM_list_xx" files must already exist. 
#     Also, the files, "build_all_scripts.bat" and "scripts.inc". 
# 
#     "prefix" is the font identifier, used to name the output file 
#     (e.g. "arial_6"). 
# 
#     This batch file creates a number of intermediate files (script_xx.src,  
#     script.inc, script.bin, scripts_xx.src, SGMs.inc, and prefix_scripts.bin).  It  
#     will delete them, at the end, if nothing goes wrong.  It it fails,  
#     you'll have to delete them by hand. 
#;/////////////////////////////////////////////////////////////////////////////// 
 
use strict; 
use File::Basename; 
 
 
sub build_scripts {			# ($prefix, \%SGMs) 
 
	my $prefix = shift; 
	my $pSGMs  = shift; 
    my $modulo = shift; 
				 
 
	print STDERR "Creating the individual Script resources\n"; 
	 
	open SCRIPTS_INC_FILE, ">scripts.inc" || die "Can't open file: scripts.inc\n"; 
 
	my $Scripts_index = 0; 
	my $highByte; 
	my $lowByte; 
	my $cmd; 
	for ($highByte=0; $highByte<256; $highByte++) { 
		if (defined($pSGMs->{$highByte})) { 
 
			my $scriptName = sprintf("script_%02x", $highByte); 
			open SCRIPT_INC_FILE, (">" . $scriptName . ".inc") ||  
                die "Can't open file: $scriptName"; 
 
			my $glyph_count = 0; 
			for ($lowByte=0; $lowByte<256; $lowByte++) { 
				if (defined($pSGMs->{$highByte}{$lowByte})) { 
                    my $bmpName; 
                                               # Create prefix_xxxx.src from BMP 
					$bmpName = sprintf("$prefix\_%02x%02x", $highByte, $lowByte); 
					$cmd = sprintf("buildres -z $modulo -b$bmpName.bmp\n", ); 
					(system $cmd) == 0 || die "FAILED: '$cmd'"; 
 
	 
					# and add entry to Scripts.inc 
			   		printf SCRIPT_INC_FILE "$bmpName\tequ\t%d\t;\$FILENAME $bmpName.src\n", 
						1 + $glyph_count++; 
				} 
			} 
 
			close SCRIPT_INC_FILE; 
 
			 # RUN RSCLINK, here, to combine glyphs into script 
            $cmd = "rsclink -d -h$scriptName.inc -o$scriptName.bin"; 
            (system $cmd) == 0 || die "FAILED: '$cmd'"; 
 
			 # RUN BUILDRES, here to convert script to SRC 
            $cmd = "buildres -r$scriptName.bin"; 
            (system $cmd) == 0 || die "FAILED: '$cmd'"; 
 
			 # and add entry to Scripts.inc 
			printf SCRIPTS_INC_FILE "$scriptName\tequ\t%d\t;\$FILENAME $scriptName.src\n", 
				1 + $Scripts_index++; 
 
 
             # Clean up the glyph bitmap SRC and ASM files for this block 
            $cmd = sprintf("del $prefix\_%02x*.asm", $highByte); 
            (system $cmd) == 0 || die "FAILED: $cmd"; 
            $cmd = sprintf("del $prefix\_%02x*.src", $highByte); 
            (system $cmd) == 0 || die "FAILED: $cmd"; 
 
             # Clean up the individual INC and BIN files for this block 
            $cmd = sprintf("del script_%02x.inc", $highByte); 
            (system $cmd) == 0 || die "FAILED: $cmd"; 
            $cmd = sprintf("del script_%02x.bin", $highByte); 
            (system $cmd) == 0 || die "FAILED: $cmd"; 
		} 
	} 
 
	close SCRIPTS_INC_FILE; 
 
	print STDERR "Combining Script entries into resource file\n"; 
    $cmd = "rsclink -d -hscripts.inc -o$prefix\_scripts.bin"; 
	(system $cmd) == 0 || die "FAILED: '$cmd'"; 
 
 
	print STDERR "Converting resource file to nested resource\n"; 
    $cmd = "buildres -r$prefix\_scripts.bin"; 
	(system $cmd) == 0 || die "FAILED: '$cmd'"; 
 
 
	print "build_scripts: Cleaning up\n"; 
    system "rename script_00.src $prefix\_script_00.src"; 
    system "del script_*.src"; 
    system "del script_*.asm"; 
    system "del $prefix\_scripts.asm"; 
    system "del scripts.inc"; 
    system "del $prefix\_scripts.bin"; 
} 
 
1;