summaryrefslogtreecommitdiff
path: root/h2pl/mksizes
blob: f28ba9e24367f697bb4b4c35cf48c7bd14825a9a (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
32
33
34
35
36
37
38
39
40
41
42
#!/usr/local/bin/perl

($iam = $0) =~ s%.*/%%;
$tmp = "$iam.$$";
open (CODE, '>', "$tmp.c") || die "$iam: cannot create $tmp.c: $!\n";

$mask = q/printf ("$sizeof{'%s'} = %d;\n"/; 

# write C program
select(CODE);

print <<EO_C_PROGRAM;
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <net/if.h>
#include <net/route.h>
#include <sys/ioctl.h>

main() {
EO_C_PROGRAM

while ( <> ) {
    chop;
    printf "\t%s, \n\t\t\"%s\", sizeof(%s));\n", $mask, $_,$_;
}

print "\n}\n";

close CODE;

# compile C program

select(STDOUT);

system "cc $tmp.c -o $tmp";
die "couldn't compile $tmp.c" if $?;
system "./$tmp"; 	   
die "couldn't run $tmp" if $?;

unlink "$tmp.c", $tmp;