mirror of
https://github.com/jschauma/spf.git
synced 2024-05-09 09:54:51 +00:00
pretty-print large numbers with thousands-separator
This commit is contained in:
3
CHANGES
3
CHANGES
@ -1,3 +1,6 @@
|
||||
0.8 (2024-03-11)
|
||||
* pretty-print large numbers with thousands-separator
|
||||
|
||||
0.7 (2024-02-06)
|
||||
* fixed a regular expression to use \t instead of a literal tab
|
||||
* changed variable named $nm to $netmask
|
||||
|
@ -58,9 +58,9 @@ Total counts:
|
||||
Total # of 'exists' directives : 1
|
||||
Total # of 'include' directives : 7
|
||||
Total # of ip4 directives : 45
|
||||
Total # of ip4 addresses : 870171
|
||||
Total # of ip4 addresses : 870,171
|
||||
Total # of ip6 directives : 11
|
||||
Total # of ip6 addresses : 29712752120897178112958136320
|
||||
Total # of ip6 addresses : 29,712,752,120,897,178,112,958,136,320
|
||||
|
||||
All others: softfail
|
||||
```
|
||||
|
17
src/spf.pl
17
src/spf.pl
@ -14,6 +14,7 @@ use Getopt::Long;
|
||||
Getopt::Long::Configure("bundling");
|
||||
use Math::BigInt; # Used to show IP counts in full without scientific notation
|
||||
|
||||
use POSIX qw(locale_h);
|
||||
use Socket qw(PF_UNSPEC PF_INET PF_INET6 SOCK_STREAM inet_ntoa);
|
||||
use Socket6;
|
||||
|
||||
@ -46,7 +47,7 @@ use constant MAXLENGTH => 450;
|
||||
my %OPTS = ( v => 0 );
|
||||
my $PROGNAME = basename($0);
|
||||
my $RETVAL = 0;
|
||||
my $VERSION = 0.7;
|
||||
my $VERSION = 0.8;
|
||||
|
||||
# The final result in json representation:
|
||||
# {
|
||||
@ -773,6 +774,16 @@ sub expandSPF($$$$) {
|
||||
}
|
||||
}
|
||||
|
||||
sub formatNumber($) {
|
||||
my ($num) = @_;
|
||||
my $h = localeconv();
|
||||
my $t = $h->{mon_thousands_sep};
|
||||
$t //= ',';
|
||||
|
||||
while ($num =~ s/^(-?\d+)(\d\d\d)/$1$t$2/) {};
|
||||
return $num;
|
||||
}
|
||||
|
||||
sub getCIDRCount($) {
|
||||
my ($cidr) = @_;
|
||||
|
||||
@ -1281,12 +1292,12 @@ sub printCount($$$) {
|
||||
if ($stats{"${ipv}-directives"}) {
|
||||
print " ";
|
||||
print "Total # of $ipv directives : ";
|
||||
print $stats{"${ipv}-directives"} . "\n";
|
||||
print formatNumber($stats{"${ipv}-directives"}) . "\n";
|
||||
}
|
||||
if ($stats{"${ipv}count"}) {
|
||||
print " ";
|
||||
print "Total # of $ipv addresses : ";
|
||||
print $stats{"${ipv}count"} . "\n";
|
||||
print formatNumber($stats{"${ipv}count"}) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user