Files
pcre2/maint/CheckTxt
Nicholas Wilson 5b3edae9d2 Add CI test to ensure installation manifest is correct (#630)
The new CI job ensures that `make distcheck` passes.

It also bundles up the tarball and includes in the GitHub artifacts, along with a GitHub-provided attestation that the tarball is derived from the given build steps.
2024-12-18 12:02:23 +00:00

65 lines
1.0 KiB
Perl
Executable File

#! /usr/bin/perl
# This is a script for checking whether a file contains any carriage return
# characters, and whether it is valid UTF-8.
use Encode;
# This subroutine does the work for one file.
$yield = 0;
$ascii = 0; # bool
$crlf = 0; # bool
sub checktxt {
my($file) = $_[0];
open(IN, "<:raw", "$file") || die "Can't open $file for input";
$bin = do { local $/ = undef; <IN> };
close(IN);
my $data;
eval
{
$data = Encode::decode("UTF-8", $bin, Encode::FB_CROAK);
1; # return true
}
or do
{
printf "Bad UTF-8 in $file\n";
$yield = 1;
return;
};
if (!$crlf && index($data, "\r") != -1)
{
printf "CR in $file\n";
$yield = 1;
}
if ($ascii && $data =~ /[^\x01-\x7e]/)
{
printf "Non-ASCII in $file\n";
$yield = 1;
}
}
# This is the main program
$, = ""; # Output field separator
for ($i = 0; $i < @ARGV; $i++)
{
if ($ARGV[$i] eq "-ascii")
{
$ascii = 1;
}
elsif ($ARGV[$i] eq "-crlf")
{
$crlf = 1;
}
else
{
checktxt($ARGV[$i]);
}
}
exit $yield;
# End