ck_errf.pl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. my $err_strict = 0;
  10. my $bad = 0;
  11. foreach $file (@ARGV)
  12. {
  13. if ($file eq "-strict")
  14. {
  15. $err_strict = 1;
  16. next;
  17. }
  18. open(IN,"<$file") || die "unable to open $file\n";
  19. $func="";
  20. while (<IN>)
  21. {
  22. if (!/;$/ && /^([a-zA-Z].*[\s*])?([A-Za-z_0-9]+)\(.*[),]/)
  23. {
  24. /^([^()]*(\([^()]*\)[^()]*)*)\(/;
  25. $1 =~ /([A-Za-z_0-9]*)$/;
  26. $func = $1;
  27. $func =~ tr/A-Z/a-z/;
  28. }
  29. if (/([A-Z0-9]+)err\(([^,]+)/ && ! /ckerr_ignore/)
  30. {
  31. $errlib=$1;
  32. $n=$2;
  33. if ($func eq "")
  34. { print "$file:$.:???:$n\n"; $bad = 1; next; }
  35. if ($n !~ /([^_]+)_F_(.+)$/)
  36. {
  37. # print "check -$file:$.:$func:$n\n";
  38. next;
  39. }
  40. $lib=$1;
  41. $n=$2;
  42. if ($lib ne $errlib)
  43. { print "$file:$.:$func:$n [${errlib}err]\n"; $bad = 1; next; }
  44. $n =~ tr/A-Z/a-z/;
  45. if (($n ne $func) && ($errlib ne "SYS"))
  46. { print "$file:$.:$func:$n\n"; $bad = 1; next; }
  47. # print "$func:$1\n";
  48. }
  49. }
  50. close(IN);
  51. }
  52. if ($bad && $err_strict)
  53. {
  54. print STDERR "FATAL: error discrepancy\n";
  55. exit 1;
  56. }