#! /bin/perl
#
# usage: getoddstructs file.h >file.c
#
# generate a C program that displays the list of structures that
# have a length not multiple of 4.
#

require 5.002;

undef $/;

die "no include" if not $include=@ARGV[0];
print STDERR "Copying $include...\n";

open(INP,"<$include");
$source=<INP>;

print "#include <stdio.h>\n";
print $source;

print "int main() {\n";

$source=~ s/^(\s*)struct((.|\n)*?)({(.|\n)*?});/&ins_struct($2)/meg;

print "}\n";

close(INP);

sub ins_struct
{
    local ($name)=@_;

    if( $name=~/^(\s*)(\w*)(\s*)$/ ) {
	$name=$2;
	print '  if(sizeof(struct '.$name.')&3) printf("'.$name.'\n");'."\n";
    }

    return "";
}

