#!/usr/bin/perl

use warnings;
use strict;

use File::Find;

my %atoms=();

find \&work, @ARGV;


printf "%-30s %6.6s %6.6s %6.6s\n", "atom", "def'd", "protos", "used";
for(keys(%atoms)){
	my $s=' ';
	if(!$atoms{$_}{used}){$s='!'};
	printf "%s %-30s %6d %6d %6d\n", $s, $_, $atoms{$_}{defined}||0, $atoms{$_}{prot}||0, $atoms{$_}{used}||0;
}

sub work(){
	my ($f)=$_;
	if($f!~/\.[ch]$/){return}
	local *F;
	my $comment=0;
	open(F, '<', $f)||die;
	while(my $l=<F>){
		if($comment){if($l!~s,^.*?\*/,,){next}}
		$comment=0;
		$l=~s,/\*.*?\*/, ,g;
		$l=~s,//.*\$,,;
		if($l=~s,/\*.*$,,){$comment=1}

		if($l=~s/^(\w.*\s)(\w+)\(/$1 /){
			$atoms{$2}{prot}++
		}elsif($l=~s/^\s*#define\ +(\w+)//){
			$atoms{$1}{defined}++;
		}else{
			$l=~s/#include\s.*//;
		}
		$l=~s/^\s*#\w+//;
		
		for(split(/\W+/,$l)){
			$atoms{$_}{used}++;
		}
	}
}
