#!/usr/bin/perl
#
#   tags2funcs [file]
#
# This little perl program converts a C tags file to a list of  source
# files and functions.  If you don't give it a file name, it will read
# stdin as usual. Perhaps it should read "tags" instead. The output is
# formatted  in  a  way  that's  convenient  for  incorporating into a
# document; you will probably want to change it somewhat.
#
%no = (	# C keyword-functions that tags idiotically includes.
	'if', 1,
	'while', 1,
	'for', 1,
	'until', 1,
	'sizeof', 1,
);
while (<>) {
	if (m'([A-Za-z0-9_]+)	(.+)	/\^(.+)/+$') {
		$f = $1;	# Function name.
		$m = $2;	# Module (file) name.
		$p = $3;	# Pattern for ex/vi/grep.
		if ($m =~ /.*\.h$/) {
#		print '#',$m," ",$f," ignored.\n";
		} elsif ($p =~ /^#define\s/) {
#			print '#',$m," ",$p," ignored.\n";
		} else {
			$p =~ m'\s([A-Za-z0-9_]+)\(';
			$r = $1;	# Routine name.
			if ($no{$r}) {
#				print '#',$m," ",$r," ignored.\n";
			} else {
				print $m," ",$r," ? ___\n";
			}
		}
	}
}
