logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

static-funcs-check.pl (618B)


  1. #!/usr/bin/env perl
  2. # Checks if a non-main function wasn't declared static, as ones for executables should be
  3. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  4. # SPDX-License-Identifier: MPL-2.0
  5. my $visible = 0;
  6. my $err = 0;
  7. if($#ARGV < 0)
  8. {
  9. print "Usage: $0 [file.c ...]\n";
  10. exit 1;
  11. }
  12. while(<>) {
  13. my $line = $_;
  14. if($line =~ /^[a-zA-Z0-9_]+\(/) {
  15. if($line =~ /^main/) { next; }
  16. if($visible == 0) { next; }
  17. print "Non-static function ${ARGV}: $line";
  18. $err = 1;
  19. } else {
  20. if($line =~ /^static /) {
  21. $visible = 0;
  22. } else {
  23. $visible = 1;
  24. }
  25. }
  26. }
  27. exit $err;