ck_errf.pl revision 296465
1#!/usr/local/bin/perl
2#
3# This is just a quick script to scan for cases where the 'error'
4# function name in a XXXerr() macro is wrong.
5#
6# Run in the top level by going
7# perl util/ck_errf.pl */*.c */*/*.c
8#
9
10foreach $file (@ARGV)
11	{
12	open(IN,"<$file") || die "unable to open $file\n";
13	$func="";
14	while (<IN>)
15		{
16		if (!/;$/ && /^\**([a-zA-Z].*[\s*])?([A-Za-z_0-9]+)\(.*([),]|$)/)
17			{
18			/^([^()]*(\([^()]*\)[^()]*)*)\(/;
19			$1 =~ /([A-Za-z_0-9]*)$/;
20			$func = $1;
21			$func =~ tr/A-Z/a-z/;
22			}
23		if (/([A-Z0-9]+)err\(([^,]+)/)
24			{
25			$errlib=$1;
26			$n=$2;
27
28			if ($func eq "")
29				{ print "$file:$.:???:$n\n"; next; }
30
31			if ($n !~ /([^_]+)_F_(.+)$/)
32				{
33		#		print "check -$file:$.:$func:$n\n";
34				next;
35				}
36			$lib=$1;
37			$n=$2;
38
39			if ($lib ne $errlib)
40				{ print "$file:$.:$func:$n [${errlib}err]\n"; next; }
41
42			$n =~ tr/A-Z/a-z/;
43			if (($n ne $func) && ($errlib ne "SYS"))
44				{ print "$file:$.:$func:$n\n"; next; }
45	#		print "$func:$1\n";
46			}
47		}
48	close(IN);
49        }
50
51