#! perl my %const_iv; sub gl() { $_ = <>; defined $_ or last file; 1 while s/\/\*.*?\*\///; s/\/\*.*$//; # we don't handle multiline-/* comments, so hack around s/\/\/.*$//; s/^\s+//; s/\s+$//; $_ } file: while () { gl; if (/^#define\s+([A-Z_0-9]+)\s+(0x[0-9a-fA-F]+|[0-9\.]+)$/) { undef $const_iv{$1}; } elsif (/^enum\b/) { while () { gl; if (/^([a-zA-Z_0-9]+)\s*(?:,|=|$)/) { undef $const_iv{$1}; } elsif (/^\}/) { last; } } } } for (sort keys %const_iv) { print "const_iv($_)\n"; }