summaryrefslogtreecommitdiff
path: root/h2pl/mkvars
blob: ffb0f0b0b9e2ed6089939f86060b539ed1c36378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl

require 'sizeof.ph';

$LIB = '/usr/local/lib/perl';

foreach $include (@ARGV) {
    printf STDERR "including %s\n", $include;
    do $include;
    warn "sourcing $include: $@\n" if ($@);
    if (!open (INCLUDE,"$LIB/$include")) {
	warn "can't open $LIB/$include: $!\n"; 
	next; 
    } 
    while (<INCLUDE>) {
	chop;
	if (/^\s*eval\s+'sub\s+(\w+)\s.*[^{]$/ || /^\s*sub\s+(\w+)\s.*[^{]$/) {
	    $var = $1;
	    $val = eval "&$var;";
	    if ($@) {
		warn "$@: $_";
		print <<EOT;
warn "\$$var isn't correctly set" if defined \$_main{'$var'};
EOT
		next;
	    } 
	    ( $nval = sprintf ("%x",$val ) ) =~ tr/a-z/A-Z/;
	    printf "\$%s = 0x%s;\n", $var, $nval;
	} 
    }
}