/contrib/ntp/ntpdc/nl.pl

https://bitbucket.org/freebsd/freebsd-head/ · Perl · 37 lines · 34 code · 2 blank · 1 comment · 12 complexity · 95955f4816b036c987b7a2d786471815 MD5 · raw file

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