Skip to content

Commit

Permalink
Add option to --allow-global-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
papamuziko committed Dec 22, 2016
1 parent 020863a commit 5049a41
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions betty-style.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
my $max_func_length = 40;
my $max_funcs = 5;
my $safe_guard = 1;
my $allow_global_variables = 0;
my $ignore_perl_version = 0;
my $minimum_perl_version = 5.10.0;
my $min_conf_desc_length = 4;
Expand Down Expand Up @@ -131,6 +132,7 @@ sub help {
(default: 5)
Set it to -1 for infinite
--no-safe-guard Don't check for header files protection
--allow-global-variables Allow global variable definition
-h, --help, --version Display this help and exit
Expand Down Expand Up @@ -231,7 +233,8 @@ sub list_types {
'max-line-length=i' => \$max_line_length,
'max-func-length=i' => \$max_func_length,
'max-funcs=i' => \$max_funcs,
'safe-guard!' => \$safe_guard
'safe-guard!' => \$safe_guard,
'allow-global-variables!' => \$allow_global_variables,
) or help(1);

help(0) if ($help);
Expand Down Expand Up @@ -3565,12 +3568,14 @@ sub process {
}

# Check for global variables (not allowed).
if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*(?:\s*=\s*.*)?;/ ||
$line =~ /^\+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
$line =~ /^\+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
$line =~ /^\+$declaration_macros/) {
ERROR("GLOBAL_DECLARATION",
"global variables are not allowed\n" . $herecurr);
if ($allow_global_variables == 0) {
if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*(?:\s*=\s*.*)?;/ ||
$line =~ /^\+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
$line =~ /^\+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
$line =~ /^\+$declaration_macros/) {
ERROR("GLOBAL_DECLARATION",
"global variables are not allowed\n" . $herecurr);
}
}

# check for global initialisers.
Expand Down

0 comments on commit 5049a41

Please sign in to comment.