checkconfig.pl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #! /usr/bin/perl
  2. #
  3. # checkconfig: find uses of CONFIG_* names without matching definitions.
  4. # Copyright abandoned, 1998, Michael Elizabeth Chastain <mailto:mec@shout.net>.
  5. use integer;
  6. $| = 1;
  7. foreach $file (@ARGV)
  8. {
  9. # Open this file.
  10. open(FILE, $file) || die "Can't open $file: $!\n";
  11. # Initialize variables.
  12. my $fInComment = 0;
  13. my $fInString = 0;
  14. my $fUseConfig = 0;
  15. my $iLinuxConfig = 0;
  16. my %configList = ();
  17. LINE: while ( <FILE> )
  18. {
  19. # Strip comments.
  20. $fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next);
  21. m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1)));
  22. # Pick up definitions.
  23. if ( m/^\s*#/o )
  24. {
  25. $iLinuxConfig = $. if m/^\s*#\s*include\s*"linux\/config\.h"/o;
  26. $configList{uc $1} = 1 if m/^\s*#\s*include\s*"config\/(\S*)\.h"/o;
  27. }
  28. # Strip strings.
  29. $fInString && (s+^.*?"+ +o ? ($fInString = 0) : next);
  30. m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1)));
  31. # Pick up definitions.
  32. if ( m/^\s*#/o )
  33. {
  34. $iLinuxConfig = $. if m/^\s*#\s*include\s*<linux\/config\.h>/o;
  35. $configList{uc $1} = 1 if m/^\s*#\s*include\s*<config\/(\S*)\.h>/o;
  36. $configList{$1} = 1 if m/^\s*#\s*define\s+CONFIG_(\w*)/o;
  37. $configList{$1} = 1 if m/^\s*#\s*undef\s+CONFIG_(\w*)/o;
  38. }
  39. # Look for usages.
  40. next unless m/CONFIG_/o;
  41. WORD: while ( m/\bCONFIG_(\w+)/og )
  42. {
  43. $fUseConfig = 1;
  44. last LINE if $iLinuxConfig;
  45. next WORD if exists $configList{$1};
  46. print "$file: $.: need CONFIG_$1.\n";
  47. $configList{$1} = 0;
  48. }
  49. }
  50. # Report superfluous includes.
  51. if ( $iLinuxConfig && ! $fUseConfig )
  52. { print "$file: $iLinuxConfig: linux/config.h not needed.\n"; }
  53. close(FILE);
  54. }