logo

utils-std

Collection of commonly available Unix tools
commit: 04fb603b59922be031ca64b01fe21084296aeea0
parent eed246337f441f0124ec022f0cf4d5eb709fea1f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 23 Apr 2024 12:04:05 +0200

static-funcs-check.pl: Add here for now

Diffstat:

Astatic-funcs-check.pl33+++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)

diff --git a/static-funcs-check.pl b/static-funcs-check.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +# Checks if a non-main function wasn't declared static, as ones for executables should be +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +my $visible = 0; +my $err = 0; + +if($#ARGV < 0) +{ + print "Usage: $0 [file.c ...]\n"; + exit 1; +} + +while(<>) { + my $line = $_; + + if($line =~ /^[a-zA-Z0-9_]+\(/) { + if($line =~ /^main/) { next; } + if($visible == 0) { next; } + + print "Non-static function ${ARGV}: $line"; + $err = 1; + } else { + if($line =~ /^static /) { + $visible = 0; + } else { + $visible = 1; + } + } +} + +exit $err;