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


#	rscrenum.pl 
#	G. Abbott 
#	SigmaTel 
#	Created: 4/9/2001 
#   Revised: 10/31/01 
#       Changed patterns to make matches more strict.  Lines that are commented out 
#       should now be properly skipped. 
 
 
#	Usage:	rscrenum.pl [path\]resource.old >resource.new 
#		perl rscrenum.pl resource.new 
# 
#		NOTE: The first form assumes the ".pl" type is 
#		registered with Windows. 
 
#	Renumber the resources in a resource.inc file, so that 
#	they are all sequential. 
# 
#	The lines we want to renumber come in either one-line form: 
#		label	equ	number	;$FILENAME filename 
# 
#	or two-line form: 
#		;$FILENAME filename	; comments 
#		label	equ	number 
# 
#	where "equ" and ";$FILENAME" are literal. 
# 
#	Any other lines, we leave alone (print to output, as is). 
 
#       NOTE: If you leave out the "$" in ";$FILENAME", that line 
#       will not be renumbered, and you won't be warned... 
 
 
 
 
$count = 1; 
$two_liner = 0; 
 
print ";\n"; 
print ";  NOTE: This file was generated automatically by rscrenum.pl\n"; 
print ";  Do not edit it directly.\n"; 
print ";  Created on ", scalar localtime(time()); 
if (@ARGV >= 1) { 
    print " using @ARGV[0] as input.\n"; 
} 
else { 
    print " using STDIN as input.\n"; 
} 
print "\n\n\n"; 
 
     
while (<>) { 
 
                                                # Note: In the matches below, the pattern "[\w_]+" 
                                                # is used to match "label".  "label" is expected  
                                                # to be a valid assembly language label  
                                                # (alphanumerics and/or underscores);  it's checked 
                                                # for the correct characters but not necessarily 
                                                # the right form. 
                                                # The pattern "[^\s;]+" is used to match "num". 
                                                # That is, "num" can be any characters other than 
                                                # whitespaces or semicolons;  it doesn't have to 
                                                # be a number.  So you can use something like "??" 
                                                # for "num" and it should match. 
 
    if ($two_liner) { 
        if (/^([\w_]+)\s+equ\s+([^\s;]+)\s*$/) { # MATCH: label	  equ	num 
            $renum = $count; 
            $count++; 
                                            	 # OUTPUT: label   equ   renum 
            printf "%-20s    equ    %5d\n", $1, $renum; 
        } 
        $two_liner = 0; 
    } 
                                                 # MATCH: label   equ   num    ;FILENAME filename 
    elsif (/^([\w_]+)\s+equ\s+([^\s;]+)\s+;\$FILENAME\s+(\S.*)$/) { 
        $renum = $count; 
        $count++; 
				                                 # OUTPUT: label   equ  renum   ;FILENAME filename 
        printf "%-20s    equ    %5d    ;\$FILENAME %-s\n", $1, $renum, $3; 
    } 
    elsif (/^;FILENAME\s+\S+.*$/) { 
        $two_liner = 1; 
        print $_; 
    } 
    else { 
        print $_; 
    } 
}