From: Richard Levitte Date: Thu, 18 Sep 2025 09:29:10 +0000 (+0200) Subject: Fix util/find-doc-nits' check_env_vars to show where envvars were found X-Git-Tag: 3.6-PRE-CLANG-FORMAT-WEBKIT~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28d1d53f8331ab6654b9887e0e9dafc50bfaf147;p=thirdparty%2Fopenssl.git Fix util/find-doc-nits' check_env_vars to show where envvars were found This displays the list of files with line number for each envvar. Reviewed-by: Neil Horman Reviewed-by: Dmitry Belyavskiy (Merged from https://github.com/openssl/openssl/pull/28601) (cherry picked from commit 56d138ec3d0fc77630b5ed8dcced3539018294e1) --- diff --git a/util/find-doc-nits b/util/find-doc-nits index 83cc1d4587c..c29ff786f8e 100755 --- a/util/find-doc-nits +++ b/util/find-doc-nits @@ -1348,13 +1348,14 @@ sub check_env_vars { while (my $line = <$fh>) { # for windows # for .in files - $env_list{$1} = 1 if ($line =~ /GetEnvironmentVariableW\([\s\S]*"([^"]+)",/ - || $line =~ /\$ENV\{([^}"']+)\}/); + push @{$env_list{$1}}, "${filename}:$." + if ($line =~ /GetEnvironmentVariableW\([\s\S]*"([^"]+)",/ + || $line =~ /\$ENV\{([^}"']+)\}/); # this also handles ossl_safe_getenv if ($line =~ /getenv\(([^()\s]+)\)/) { my $env1 = $1; if ($env1 =~ /"([^"]+)"/) { - $env_list{$1} = 1; + push @{$env_list{$1}}, "${filename}:$."; } elsif ($env1 =~ /([A-Z0-9_])/) { push(@env_macro, $env1); } @@ -1365,12 +1366,12 @@ sub check_env_vars { # if it's a string just add to the list # otherwise look for the constant value later if ($env1 =~ /"([^"]+)"/) { - $env_list{$1} = 1; + push @{$env_list{$1}}, "${filename}:$."; } else { push(@env_macro, $env1); } if ($env2 =~ /"([^"]+)"/) { - $env_list{$1} = 1; + push @{$env_list{$1}}, "${filename}:$."; } else { push(@env_macro, $env2); } @@ -1383,14 +1384,15 @@ sub check_env_vars { find(sub { push @env_headers, $File::Find::name if /\.h$/; }, $config{sourcedir}); - foreach my $filename (@env_headers) { + foreach my $filename (@env_headers) { open my $fh, '<', $filename or die "Can't open $filename: $!"; while (my $line = <$fh>) { foreach my $em (@env_macro) { - $env_list{$1} = 1 if ($line =~ /define\s+\Q$em\E\s+"(\S+)"/); + push @{$env_list{$1}}, "${filename}:$." + if ($line =~ /define\s+\Q$em\E\s+"(\S+)"/); } } - } + } # need to save the value before starting to delete from the hash my $number_of_env = scalar keys %env_list; @@ -1417,7 +1419,12 @@ sub check_env_vars { $number_of_env = scalar keys %env_list; if ($number_of_env != 0) { print "Undocumented environment variables:\n"; - print join("\n", sort keys %env_list)."\n"; + foreach my $env_name (sort keys %env_list) { + print $env_name; + print " (found in '", join("', '", @{$env_list{$env_name}}), "')" + if ref $env_list{$env_name} eq 'ARRAY'; + print "\n"; + } err("Total:".$number_of_env."\n"); } }