xref: /freebsd/contrib/ntp/ntpdc/nl.pl (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1#! /usr/local/bin/perl -w
2
3$found = 0;
4$last = 0;
5$debug = 0;
6
7while (<>) {
8    next if /^#/;
9    next if /^\s*$/;
10    if (/^typedef union req_data_u_tag/) {
11	$found = 1;
12    }
13    if (/^struct info_dns_assoc/) {
14	$last = 1;
15    }
16    if ($found) {
17	if (/^(struct\s*\w*)\s*{\s*$/) {
18	    $type = $1;
19	    print STDERR "type = '$type'\n" if $debug;
20	    printf "  printf(\"sizeof($type) = %%d\\n\", \n\t (int) sizeof($type));\n";
21	    next;
22	}
23	if (/^typedef (union\s*\w*)\s*{\s*$/) {
24	    $type = $1;
25	    print STDERR "union = '$type'\n" if $debug;
26	    printf "  printf(\"sizeof($type) = %%d\\n\", \n\t (int) sizeof($type));\n";
27	    next;
28	}
29	if (/\s*\w+\s+(\w*)\s*(\[.*\])?\s*;\s*$/) {
30	    $field = $1;
31	    print STDERR "\tfield = '$field'\n" if $debug;
32	    printf "  printf(\"offsetof($field) = %%d\\n\", \n\t (int) offsetof($type, $field));\n";
33	    next;
34	}
35	if (/^}\s*\w*\s*;\s*$/) {
36	    printf "  printf(\"\\n\");\n\n";
37	    $found = 0 if $last;
38	    next;
39	}
40	print STDERR "Unmatched line: $_";
41	exit 1;
42    }
43}
44