summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/ntpdc/nl.pl
blob: 6974fe2996b56884bfae570d3536c6e81b47600e (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
#! /usr/local/bin/perl -w

$found = 0;
$last = 0;
$debug = 0;

while (<>) {
    next if /^#/;
    next if /^\s*$/;
    if (/^struct req_pkt/) {
	$found = 1;
    }
    if (/^struct info_dns_assoc/) {
	$last = 1;
    }
    if ($found) {
	if (/^(struct\s*\w*)\s*{\s*$/) {
	    $type = $1;
	    print STDERR "type = '$type'\n" if $debug;
	    printf "  printf(\"sizeof($type) = %%d\\n\", \n\t (int) sizeof($type));\n";
	    next;
	}
	if (/\s*\w+\s*(\w*)(\[.*\])?\s*;\s*$/) {
	    $field = $1;
	    print STDERR "\tfield = '$field'\n" if $debug;
	    printf "  printf(\"offsetof($field) = %%d\\n\", \n\t (int) offsetof($type, $field));\n";
	    next;
	}
	if (/^};$/) {
	    printf "  printf(\"\\n\");\n\n";
	    $found = 0 if $last;
	    next;
	}
	print STDERR "Unmatched line: $_";
	exit 1;
    }
}
OpenPOWER on IntegriCloud