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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#!/usr/bin/perl -w
$infile = "stdin";
if ($ARGV[0]) {
$infile = $ARGV[0];
}
$infile =~ m"^([^.]+)"o;
# $fpref = $1;
$allsrc = "";
open (IN, $infile) || die "Cannot open input file $infile";
while (<IN>) {
$allsrc .= $_;
}
close IN;
print "\n";
print "============================\n";
print ".. File $infile\n";
print "============================\n";
################
# typedef struct
################
@presrc = split (/^typedef\s+struct\s+\S*\s*[{][^}]+[}]\s*[^;]+;\s*$/osm, $allsrc);
$ip = 0;
$dalias="";
while ($allsrc =~ /^typedef\s+struct\s+(\S*)\s*[{][^}]+[}]\s*([^;]+);\s*(\#define\s+(\S+)\s+\S+[*])?$/gosm) {
$dnam = $1;
$dalias = $2;
$ddefine = $4;
@anam = (split(/[ \t,*]+/, $dalias));
if (defined($ddefine)) {
push @anam, $ddefine;
}
if (!defined($dnam) || $dnam eq "") {
$dnam = $anam[$#anam];
}
$presrc = $presrc[$ip];
if ($presrc =~ /[\n][\/][*]\s+[@]data[static]*\s+(\S+)([^\/*][^*]*[*]+)*[\/]\s*$/osm) {
$hnam = $1;
$ok = 0;
foreach $nam (@anam) {
if ($hnam eq $nam) {$ok = 1}
}
if (!$ok && $dnam ne $hnam) {
print "bad docheader for $hnam precedes $dnam\n";
}
}
else {
print "bad or missing docheader for $dnam\n";
}
$ip++;
}
################
# typedef enum
################
@presrc = split (/^typedef\s+enum\s+\S*\s*[{][^}]+[}]\s*[^;]+;\s*$/osm, $allsrc);
$ip = 0;
$dalias="";
while ($allsrc =~ /^typedef\s+enum\s+(\S*)\s*[{][^}]+[}]\s*([^;]+);\s*?$/gosm) {
$ealias = $1;
$enam = $2;
if (!defined($enam) || $enam eq "") {
$enam = $ealias;
}
@anam = (split(/[ \t,*]+/, $enam));
$presrc = $presrc[$ip];
if ($presrc =~ /[\n][\/][*]\s+[@]enum[static]*\s+(\S+)([^\/*][^*]*[*]+)*[\/]\s*$/osm) {
$hnam = $1;
$ok = 0;
foreach $nam (@anam) {
if ($hnam eq $nam) {$ok = 1}
}
if (!$ok && $enam ne $hnam) {
print "bad enumheader for $hnam precedes $enam\n";
}
}
else {
print "bad enumheader bad or missing docheader for $enam\n";
}
$ip++;
}
################
# const
################
@presrc = split (/^[sc][tatic ]*onst\s+[^*=;\(\)]*\s[^*]\S+\s*[=][^;]+;\s*?$/osm, $allsrc);
$ip = 0;
$dalias="";
while ($allsrc =~ /^[sc][tatic ]*onst\s+[^*=;\(\)]*\s([^*]\S+)\s*[=]([^;]+);\s*?$/gosm) {
$cnam = $1;
$cnam =~ s/[\[][0-9]*[\]]$//;
if (!defined($cnam) || $cnam eq "") {
$cnam = "unknown";
}
$presrc = $presrc[$ip];
# print "PRESRC $ip\n$presrc\n====================\n";
if ($presrc =~ /[\n][\/][*]\s+[@]const(static)?\s+(\S+)([^\/*][^*]*[*]+)*[\/]\s*$/osm) {
$hnam = $2;
# if ($cnam ne $hnam) {
# print "bad constheader for $hnam precedes $cnam\n";
# }
}
elsif ($presrc =~ /^\s*$/) {}
else {
print "bad constheader bad or missing docheader for $cnam\n";
}
$ip++;
}
|