Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Mar 2023 18:24:54 +0100
From:      Warner Losh <imp@bsdimp.com>
To:        Drew Gallatin <gallatin@freebsd.org>
Cc:        Warner Losh <imp@freebsd.org>, src-committers@freebsd.org,  dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org
Subject:   Re: git: 3a3c9242739e - main - checkstyle9.pl: Perl script to check if a change is approximately style(9)
Message-ID:  <CANCZdfo8upPbGd5Ji3SQ4V9aGsTysxiuYZU4x6smjVQgOoArgg@mail.gmail.com>
In-Reply-To: <5b9c31d2-4aaf-4822-b405-cae57164f314@app.fastmail.com>
References:  <202303251708.32PH8BUq079177@gitrepo.freebsd.org> <5b9c31d2-4aaf-4822-b405-cae57164f314@app.fastmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000006acd1f05f7bcca27
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Yea, I did most of the work on this 18 months ago or so, but the shit in
core and subsequent nastiness derailed it til now.

It's gotten to 'decent or better' at things, but far from perfect. I'm sure
that now the bug reports will come.

Warner

On Sat, Mar 25, 2023 at 6:22=E2=80=AFPM Drew Gallatin <gallatin@freebsd.org=
> wrote:

> Thanks so much.  I've wanted something like this *forever*
>
> On Sat, Mar 25, 2023, at 1:08 PM, Warner Losh wrote:
>
> The branch main has been updated by imp:
>
> URL:
> https://cgit.FreeBSD.org/src/commit/?id=3D3a3c9242739efb0c76587ffbaa54c5d=
10b2cbcb4
>
> commit 3a3c9242739efb0c76587ffbaa54c5d10b2cbcb4
> Author:     Warner Losh <imp@FreeBSD.org>
> AuthorDate: 2023-03-14 21:28:05 +0000
> Commit:     Warner Losh <imp@FreeBSD.org>
> CommitDate: 2023-03-25 17:06:13 +0000
>
>     checkstyle9.pl: Perl script to check if a change is approximately
> style(9)
>
>     This code is adapted from the QEMU checkpatch.pl script. It can check
>     either a patch, a file or a git branch. It tries to warn about things
>     that I believe might be style(9) violations. It's experimental, since=
 I
>     heavily hacked on the qemu version to get it to not complain (much)
>     about iconic code in the tree. At the moment, it's use should be
>     considered expermental. It will likely miss violations, and complain
>     about code that's perfectly fine.  It's offered as an experiment
>     and to make it easier for contributors to submit patches.
> ---
> tools/build/checkstyle9.pl | 2748
> ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 2748 insertions(+)
>
> diff --git a/tools/build/checkstyle9.pl b/tools/build/checkstyle9.pl
> new file mode 100755
> index 000000000000..5aec3819bf7c
> --- /dev/null
> +++ b/tools/build/checkstyle9.pl
> @@ -0,0 +1,2748 @@
> +#!/usr/bin/env perl
> +# (c) 2001, Dave Jones. (the file handling bit)
> +# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
> +# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test
> suite)
> +# (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
> +# Licensed under the terms of the GNU GPL License version 2
> +
> +use strict;
> +use warnings;
> +use Term::ANSIColor qw(:constants);
> +
> +my $P =3D $0;
> +$P =3D~ s@.*/@@g;
> +
> +our $SrcFile    =3D qr{\.(?:h|c|cpp|s|S|pl|py|sh)$};
> +
> +my $V =3D '0.31';
> +
> +use Getopt::Long qw(:config no_auto_abbrev);
> +
> +my $quiet =3D 0;
> +my $tree =3D 1;
> +my $chk_signoff =3D 1;
> +my $chk_patch =3D undef;
> +my $chk_branch =3D undef;
> +my $tst_only;
> +my $emacs =3D 0;
> +my $terse =3D 0;
> +my $file =3D undef;
> +my $color =3D "auto";
> +my $no_warnings =3D 0;
> +my $summary =3D 1;
> +my $mailback =3D 0;
> +my $summary_file =3D 0;
> +my $root;
> +my %debug;
> +my $help =3D 0;
> +
> +sub help {
> + my ($exitcode) =3D @_;
> +
> + print << "EOM";
> +Usage:
> +
> +    $P [OPTION]... [FILE]...
> +    $P [OPTION]... [GIT-REV-LIST]
> +
> +Version: $V
> +
> +Options:
> +  -q, --quiet                quiet
> +  --patch                    treat FILE as patchfile
> +  --branch                   treat args as GIT revision list
> +  --emacs                    emacs compile window format
> +  --terse                    one line per report
> +  -f, --file                 treat FILE as regular source file
> +  --strict                   fail if only warnings are found
> +  --no-summary               suppress the per-file summary
> +  --mailback                 only produce a report in case of
> warnings/errors
> +  --summary-file             include the filename in summary
> +  --debug KEY=3D[0|1]          turn on/off debugging of KEY, where KEY i=
s
> one of
> +                             'values', 'possible', 'type', and 'attr'
> (default
> +                             is all off)
> +  --test-only=3DWORD           report only warnings/errors containing WO=
RD
> +                             literally
> +  --color[=3DWHEN]             Use colors 'always', 'never', or only whe=
n
> output
> +                             is a terminal ('auto'). Default is 'auto'.
> +  -h, --help, --version      display this help and exit
> +
> +When FILE is - read standard input.
> +EOM
> +
> + exit($exitcode);
> +}
> +
> +# Use at your own risk
> +print "\n", MAGENTA, "WARNING:", RESET, " This code is highly
> experimental ... likely isn't a great style(9) match yet\n\n";
> +
> +# Perl's Getopt::Long allows options to take optional arguments after a
> space.
> +# Prevent --color by itself from consuming other arguments
> +foreach (@ARGV) {
> + if ($_ eq "--color" || $_ eq "-color") {
> + $_ =3D "--color=3D$color";
> + }
> +}
> +
> +GetOptions(
> + 'q|quiet+' =3D> \$quiet,
> + 'tree!' =3D> \$tree,
> + 'signoff!' =3D> \$chk_signoff,
> + 'patch!' =3D> \$chk_patch,
> + 'branch!' =3D> \$chk_branch,
> + 'emacs!' =3D> \$emacs,
> + 'terse!' =3D> \$terse,
> + 'f|file!' =3D> \$file,
> + 'strict!' =3D> \$no_warnings,
> + 'root=3Ds' =3D> \$root,
> + 'summary!' =3D> \$summary,
> + 'mailback!' =3D> \$mailback,
> + 'summary-file!' =3D> \$summary_file,
> +
> + 'debug=3Ds' =3D> \%debug,
> + 'test-only=3Ds' =3D> \$tst_only,
> + 'color=3Ds'       =3D> \$color,
> + 'no-color'      =3D> sub { $color =3D 'never'; },
> + 'h|help' =3D> \$help,
> + 'version' =3D> \$help
> +) or help(1);
> +
> +help(0) if ($help);
> +
> +my $exit =3D 0;
> +
> +if ($#ARGV < 0) {
> + print "$P: no input files\n";
> + exit(1);
> +}
> +
> +if (!defined $chk_branch && !defined $chk_patch && !defined $file) {
> + $chk_branch =3D $ARGV[0] =3D~ /.\.\./ ? 1 : 0;
> + $file =3D $ARGV[0] =3D~ /$SrcFile/ ? 1 : 0;
> + $chk_patch =3D $chk_branch || $file ? 0 : 1;
> +} elsif (!defined $chk_branch && !defined $chk_patch) {
> + if ($file) {
> + $chk_branch =3D $chk_patch =3D 0;
> + } else {
> + $chk_branch =3D $ARGV[0] =3D~ /.\.\./ ? 1 : 0;
> + $chk_patch =3D $chk_branch ? 0 : 1;
> + }
> +} elsif (!defined $chk_branch && !defined $file) {
> + if ($chk_patch) {
> + $chk_branch =3D $file =3D 0;
> + } else {
> + $chk_branch =3D $ARGV[0] =3D~ /.\.\./ ? 1 : 0;
> + $file =3D $chk_branch ? 0 : 1;
> + }
> +} elsif (!defined $chk_patch && !defined $file) {
> + if ($chk_branch) {
> + $chk_patch =3D $file =3D 0;
> + } else {
> + $file =3D $ARGV[0] =3D~ /$SrcFile/ ? 1 : 0;
> + $chk_patch =3D $file ? 0 : 1;
> + }
> +} elsif (!defined $chk_branch) {
> + $chk_branch =3D $chk_patch || $file ? 0 : 1;
> +} elsif (!defined $chk_patch) {
> + $chk_patch =3D $chk_branch || $file ? 0 : 1;
> +} elsif (!defined $file) {
> + $file =3D $chk_patch || $chk_branch ? 0 : 1;
> +}
> +
> +if (($chk_patch && $chk_branch) ||
> +    ($chk_patch && $file) ||
> +    ($chk_branch && $file)) {
> + die "Only one of --file, --branch, --patch is permitted\n";
> +}
> +if (!$chk_patch && !$chk_branch && !$file) {
> + die "One of --file, --branch, --patch is required\n";
> +}
> +
> +if ($color =3D~ /^always$/i) {
> + $color =3D 1;
> +} elsif ($color =3D~ /^never$/i) {
> + $color =3D 0;
> +} elsif ($color =3D~ /^auto$/i) {
> + $color =3D (-t STDOUT);
> +} else {
> + die "Invalid color mode: $color\n";
> +}
> +
> +my $dbg_values =3D 0;
> +my $dbg_possible =3D 0;
> +my $dbg_type =3D 0;
> +my $dbg_attr =3D 0;
> +my $dbg_adv_dcs =3D 0;
> +my $dbg_adv_checking =3D 0;
> +my $dbg_adv_apw =3D 0;
> +for my $key (keys %debug) {
> + ## no critic
> + eval "\${dbg_$key} =3D '$debug{$key}';";
> + die "$@" if ($@);
> +}
> +
> +my $rpt_cleaners =3D 0;
> +
> +if ($terse) {
> + $emacs =3D 1;
> + $quiet++;
> +}
> +
> +my $emitted_corrupt =3D 0;
> +
> +our $Ident =3D qr{
> + [A-Za-z_][A-Za-z\d_]*
> + (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
> + }x;
> +our $Storage =3D qr{extern|static|asmlinkage};
> +our $Sparse =3D qr{
> + __force
> + }x;
> +
> +# Notes to $Attribute:
> +our $Attribute =3D qr{
> + const|
> + volatile|
> + QEMU_NORETURN|
> + QEMU_WARN_UNUSED_RESULT|
> + QEMU_SENTINEL|
> + QEMU_PACKED|
> + GCC_FMT_ATTR
> +   }x;
> +our $Modifier;
> +our $Inline =3D qr{inline};
> +our $Member =3D qr{->$Ident|\.$Ident|\[[^]]*\]};
> +our $Lval =3D qr{$Ident(?:$Member)*};
> +
> +our $Constant =3D qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*};
> +our $Assignment =3D qr{(?:\*\=3D|/=3D|%=3D|\+=3D|-=3D|<<=3D|>>=3D|&=3D|\=
^=3D|\|=3D|=3D)};
> +our $Compare    =3D qr{<=3D|>=3D|=3D=3D|!=3D|<|>};
> +our $Operators =3D qr{
> + <=3D|>=3D|=3D=3D|!=3D|
> + =3D>|->|<<|>>|<|>|!|~|
> + &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%
> +   }x;
> +
> +our $NonptrType;
> +our $Type;
> +our $Declare;
> +
> +our $NON_ASCII_UTF8 =3D qr{
> + [\xC2-\xDF][\x80-\xBF]               # non-overlong 2-byte
> + |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
> + | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
> + |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
> + |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
> + | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
> + |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
> +}x;
> +
> +our $UTF8 =3D qr{
> + [\x09\x0A\x0D\x20-\x7E]              # ASCII
> + | $NON_ASCII_UTF8
> +}x;
> +
> +# some readers default to ISO-8859-1 when showing email source. detect
> +# when UTF-8 is incorrectly interpreted as ISO-8859-1 and reencoded back=
.
> +# False positives are possible but very unlikely.
> +our $UTF8_MOJIBAKE =3D qr{
> + \xC3[\x82-\x9F] \xC2[\x80-\xBF]                    # c2-df 80-bf
> + | \xC3\xA0 \xC2[\xA0-\xBF] \xC2[\x80-\xBF]         # e0 a0-bf 80-bf
> + | \xC3[\xA1-\xAC\xAE\xAF] (?: \xC2[\x80-\xBF]){2}  # e1-ec/ee/ef 80-bf
> 80-bf
> + | \xC3\xAD \xC2[\x80-\x9F] \xC2[\x80-\xBF]         # ed 80-9f 80-bf
> + | \xC3\xB0 \xC2[\x90-\xBF] (?: \xC2[\x80-\xBF]){2} # f0 90-bf 80-bf 80-=
bf
> + | \xC3[\xB1-\xB3] (?: \xC2[\x80-\xBF]){3}          # f1-f3 80-bf 80-bf
> 80-bf
> + | \xC3\xB4 \xC2[\x80-\x8F] (?: \xC2[\x80-\xBF]){2} # f4 80-b8 80-bf 80-=
bf
> +}x;
> +
> +# There are still some false positives, but this catches most
> +# common cases.
> +our $typeTypedefs =3D qr{(?x:
> +        (?![KMGTPE]iB)                      # IEC binary prefix (do not
> match)
> +        [A-Z][A-Z\d_]*[a-z][A-Za-z\d_]*     # camelcase
> +        | [A-Z][A-Z\d_]*AIOCB               # all uppercase
> +        | [A-Z][A-Z\d_]*CPU                 # all uppercase
> +        | QEMUBH                            # all uppercase
> +)};
> +
> +our @typeList =3D (
> + qr{void},
> + qr{(?:unsigned\s+)?char},
> + qr{(?:unsigned\s+)?short},
> + qr{(?:unsigned\s+)?int},
> + qr{(?:unsigned\s+)?long},
> + qr{(?:unsigned\s+)?long\s+int},
> + qr{(?:unsigned\s+)?long\s+long},
> + qr{(?:unsigned\s+)?long\s+long\s+int},
> + qr{unsigned},
> + qr{float},
> + qr{double},
> + qr{bool},
> + qr{struct\s+$Ident},
> + qr{union\s+$Ident},
> + qr{enum\s+$Ident},
> + qr{${Ident}_t},
> + qr{${Ident}_handler},
> + qr{${Ident}_handler_fn},
> + qr{target_(?:u)?long},
> + qr{hwaddr},
> +);
> +
> +# This can be modified by sub possible.  Since it can be empty, be caref=
ul
> +# about regexes that always match, because they can cause infinite loops=
.
> +our @modifierList =3D (
> +);
> +
> +sub build_types {
> + my $all =3D "(?x:  \n" . join("|\n  ", @typeList) . "\n)";
> + if (@modifierList > 0) {
> + my $mods =3D "(?x:  \n" . join("|\n  ", @modifierList) . "\n)";
> + $Modifier =3D qr{(?:$Attribute|$Sparse|$mods)};
> + } else {
> + $Modifier =3D qr{(?:$Attribute|$Sparse)};
> + }
> + $NonptrType =3D qr{
> + (?:$Modifier\s+|const\s+)*
> + (?:
> + (?:typeof|__typeof__)\s*\(\s*\**\s*$Ident\s*\)|
> + (?:$typeTypedefs\b)|
> + (?:${all}\b)
> + )
> + (?:\s+$Modifier|\s+const)*
> +   }x;
> + $Type =3D qr{
> + $NonptrType
> + (?:[\s\*]+\s*const|[\s\*]+|(?:\s*\[\s*\])+)?
> + (?:\s+$Inline|\s+$Modifier)*
> +   }x;
> + $Declare =3D qr{(?:$Storage\s+)?$Type};
> +}
> +build_types();
> +
> +$chk_signoff =3D 0 if ($file);
> +
> +my @rawlines =3D ();
> +my @lines =3D ();
> +my $vname;
> +if ($chk_branch) {
> + my @patches;
> + my %git_commits =3D ();
> + my $HASH;
> + open($HASH, "-|", "git", "log", "--reverse", "--no-merges", "--format=
=3D%H
> %s", $ARGV[0]) ||
> + die "$P: git log --reverse --no-merges --format=3D'%H %s' $ARGV[0] fail=
ed
> - $!\n";
> +
> + for my $line (<$HASH>) {
> + $line =3D~ /^([0-9a-fA-F]{40,40}) (.*)$/;
> + next if (!defined($1) || !defined($2));
> + my $sha1 =3D $1;
> + my $subject =3D $2;
> + push(@patches, $sha1);
> + $git_commits{$sha1} =3D $subject;
> + }
> +
> + close $HASH;
> +
> + die "$P: no revisions returned for revlist '$ARGV[0]'\n"
> +     unless @patches;
> +
> + my $i =3D 1;
> + my $num_patches =3D @patches;
> + for my $hash (@patches) {
> + my $FILE;
> + open($FILE, '-|', "git", "show", "--patch-with-stat", $hash) ||
> + die "$P: git show $hash - $!\n";
> + while (<$FILE>) {
> + chomp;
> + push(@rawlines, $_);
> + }
> + close($FILE);
> + $vname =3D substr($hash, 0, 12) . ' (' . $git_commits{$hash} . ')';
> + if ($num_patches > 1 && $quiet =3D=3D 0) {
> + my $prefix =3D "$i/$num_patches";
> + $prefix =3D BLUE . BOLD . $prefix . RESET if $color;
> + print "$prefix Checking commit $vname\n";
> + $vname =3D "Patch $i/$num_patches";
> + } else {
> + $vname =3D "Commit " . $vname;
> + }
> + if (!process($hash)) {
> + $exit =3D 1;
> + print "\n" if ($num_patches > 1 && $quiet =3D=3D 0);
> + }
> + @rawlines =3D ();
> + @lines =3D ();
> + $i++;
> + }
> +} else {
> + for my $filename (@ARGV) {
> + my $FILE;
> + if ($file) {
> + open($FILE, '-|', "diff -u /dev/null $filename") ||
> + die "$P: $filename: diff failed - $!\n";
> + } elsif ($filename eq '-') {
> + open($FILE, '<&STDIN');
> + } else {
> + open($FILE, '<', "$filename") ||
> + die "$P: $filename: open failed - $!\n";
> + }
> + if ($filename eq '-') {
> + $vname =3D 'Your patch';
> + } else {
> + $vname =3D $filename;
> + }
> + print "Checking $filename...\n" if @ARGV > 1 && $quiet =3D=3D 0;
> + while (<$FILE>) {
> + chomp;
> + push(@rawlines, $_);
> + }
> + close($FILE);
> + if (!process($filename)) {
> + $exit =3D 1;
> + }
> + @rawlines =3D ();
> + @lines =3D ();
> + }
> +}
> +
> +exit($exit);
> +
> +sub top_of_kernel_tree {
> + my ($root) =3D @_;
> +
> + my @tree_check =3D (
> +     "Makefile.inc1", "README.md", "sys",
> +     "usr.sbin"
> + );
> +
> + foreach my $check (@tree_check) {
> + if (! -e $root . '/' . $check) {
> + return 0;
> + }
> + }
> + return 1;
> +}
> +
> +sub expand_tabs {
> + my ($str) =3D @_;
> +
> + my $res =3D '';
> + my $n =3D 0;
> + for my $c (split(//, $str)) {
> + if ($c eq "\t") {
> + $res .=3D ' ';
> + $n++;
> + for (; ($n % 8) !=3D 0; $n++) {
> + $res .=3D ' ';
> + }
> + next;
> + }
> + $res .=3D $c;
> + $n++;
> + }
> +
> + return $res;
> +}
> +sub copy_spacing {
> + (my $res =3D shift) =3D~ tr/\t/ /c;
> + return $res;
> +}
> +
> +sub line_stats {
> + my ($line) =3D @_;
> +
> + # Drop the diff line leader and expand tabs
> + $line =3D~ s/^.//;
> + $line =3D expand_tabs($line);
> +
> + # Pick the indent from the front of the line.
> + my ($white) =3D ($line =3D~ /^(\s*)/);
> +
> + return (length($line), length($white));
> +}
> +
> +my $sanitise_quote =3D '';
> +
> +sub sanitise_line_reset {
> + my ($in_comment) =3D @_;
> +
> + if ($in_comment) {
> + $sanitise_quote =3D '*/';
> + } else {
> + $sanitise_quote =3D '';
> + }
> +}
> +sub sanitise_line {
> + my ($line) =3D @_;
> +
> + my $res =3D '';
> + my $l =3D '';
> +
> + my $qlen =3D 0;
> + my $off =3D 0;
> + my $c;
> +
> + # Always copy over the diff marker.
> + $res =3D substr($line, 0, 1);
> +
> + for ($off =3D 1; $off < length($line); $off++) {
> + $c =3D substr($line, $off, 1);
> +
> + # Comments we are wacking completely including the begin
> + # and end, all to $;.
> + if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
> + $sanitise_quote =3D '*/';
> +
> + substr($res, $off, 2, "$;$;");
> + $off++;
> + next;
> + }
> + if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
> + $sanitise_quote =3D '';
> + substr($res, $off, 2, "$;$;");
> + $off++;
> + next;
> + }
> + if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
> + $sanitise_quote =3D '//';
> +
> + substr($res, $off, 2, $sanitise_quote);
> + $off++;
> + next;
> + }
> +
> + # A \ in a string means ignore the next character.
> + if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
> +     $c eq "\\") {
> + substr($res, $off, 2, 'XX');
> + $off++;
> + next;
> + }
> + # Regular quotes.
> + if ($c eq "'" || $c eq '"') {
> + if ($sanitise_quote eq '') {
> + $sanitise_quote =3D $c;
> +
> + substr($res, $off, 1, $c);
> + next;
> + } elsif ($sanitise_quote eq $c) {
> + $sanitise_quote =3D '';
> + }
> + }
> +
> + #print "c<$c> SQ<$sanitise_quote>\n";
> + if ($off !=3D 0 && $sanitise_quote eq '*/' && $c ne "\t") {
> + substr($res, $off, 1, $;);
> + } elsif ($off !=3D 0 && $sanitise_quote eq '//' && $c ne "\t") {
> + substr($res, $off, 1, $;);
> + } elsif ($off !=3D 0 && $sanitise_quote && $c ne "\t") {
> + substr($res, $off, 1, 'X');
> + } else {
> + substr($res, $off, 1, $c);
> + }
> + }
> +
> + if ($sanitise_quote eq '//') {
> + $sanitise_quote =3D '';
> + }
> +
> + # The pathname on a #include may be surrounded by '<' and '>'.
> + if ($res =3D~ /^.\s*\#\s*include\s+\<(.*)\>/) {
> + my $clean =3D 'X' x length($1);
> + $res =3D~ s@\<.*\>@<$clean>@;
> +
> + # The whole of a #error is a string.
> + } elsif ($res =3D~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
> + my $clean =3D 'X' x length($1);
> + $res =3D~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
> + }
> +
> + return $res;
> +}
> +
> +sub ctx_statement_block {
> + my ($linenr, $remain, $off) =3D @_;
> + my $line =3D $linenr - 1;
> + my $blk =3D '';
> + my $soff =3D $off;
> + my $coff =3D $off - 1;
> + my $coff_set =3D 0;
> +
> + my $loff =3D 0;
> +
> + my $type =3D '';
> + my $level =3D 0;
> + my @stack =3D ();
> + my $p;
> + my $c;
> + my $len =3D 0;
> +
> + my $remainder;
> + while (1) {
> + @stack =3D (['', 0]) if ($#stack =3D=3D -1);
> +
> + #warn "CSB: blk<$blk> remain<$remain>\n";
> + # If we are about to drop off the end, pull in more
> + # context.
> + if ($off >=3D $len) {
> + for (; $remain > 0; $line++) {
> + last if (!defined $lines[$line]);
> + next if ($lines[$line] =3D~ /^-/);
> + $remain--;
> + $loff =3D $len;
> + $blk .=3D $lines[$line] . "\n";
> + $len =3D length($blk);
> + $line++;
> + last;
> + }
> + # Bail if there is no further context.
> + #warn "CSB: blk<$blk> off<$off> len<$len>\n";
> + if ($off >=3D $len) {
> + last;
> + }
> + }
> + $p =3D $c;
> + $c =3D substr($blk, $off, 1);
> + $remainder =3D substr($blk, $off);
> +
> + #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder>
> coff_set<$coff_set>\n";
> +
> + # Handle nested #if/#else.
> + if ($remainder =3D~ /^#\s*(?:ifndef|ifdef|if)\s/) {
> + push(@stack, [ $type, $level ]);
> + } elsif ($remainder =3D~ /^#\s*(?:else|elif)\b/) {
> + ($type, $level) =3D @{$stack[$#stack - 1]};
> + } elsif ($remainder =3D~ /^#\s*endif\b/) {
> + ($type, $level) =3D @{pop(@stack)};
> + }
> +
> + # Statement ends at the ';' or a close '}' at the
> + # outermost level.
> + if ($level =3D=3D 0 && $c eq ';') {
> + last;
> + }
> +
> + # An else is really a conditional as long as its not else if
> + if ($level =3D=3D 0 && $coff_set =3D=3D 0 &&
> + (!defined($p) || $p =3D~ /(?:\s|\}|\+)/) &&
> + $remainder =3D~ /^(else)(?:\s|{)/ &&
> + $remainder !~ /^else\s+if\b/) {
> + $coff =3D $off + length($1) - 1;
> + $coff_set =3D 1;
> + #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
> + #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
> + }
> +
> + if (($type eq '' || $type eq '(') && $c eq '(') {
> + $level++;
> + $type =3D '(';
> + }
> + if ($type eq '(' && $c eq ')') {
> + $level--;
> + $type =3D ($level !=3D 0)? '(' : '';
> +
> + if ($level =3D=3D 0 && $coff < $soff) {
> + $coff =3D $off;
> + $coff_set =3D 1;
> + #warn "CSB: mark coff<$coff>\n";
> + }
> + }
> + if (($type eq '' || $type eq '{') && $c eq '{') {
> + $level++;
> + $type =3D '{';
> + }
> + if ($type eq '{' && $c eq '}') {
> + $level--;
> + $type =3D ($level !=3D 0)? '{' : '';
> +
> + if ($level =3D=3D 0) {
> + if (substr($blk, $off + 1, 1) eq ';') {
> + $off++;
> + }
> + last;
> + }
> + }
> + $off++;
> + }
> + # We are truly at the end, so shuffle to the next line.
> + if ($off =3D=3D $len) {
> + $loff =3D $len + 1;
> + $line++;
> + $remain--;
> + }
> +
> + my $statement =3D substr($blk, $soff, $off - $soff + 1);
> + my $condition =3D substr($blk, $soff, $coff - $soff + 1);
> +
> + #warn "STATEMENT<$statement>\n";
> + #warn "CONDITION<$condition>\n";
> +
> + #print "coff<$coff> soff<$off> loff<$loff>\n";
> +
> + return ($statement, $condition,
> + $line, $remain + 1, $off - $loff + 1, $level);
> +}
> +
> +sub statement_lines {
> + my ($stmt) =3D @_;
> +
> + # Strip the diff line prefixes and rip blank lines at start and end.
> + $stmt =3D~ s/(^|\n)./$1/g;
> + $stmt =3D~ s/^\s*//;
> + $stmt =3D~ s/\s*$//;
> +
> + my @stmt_lines =3D ($stmt =3D~ /\n/g);
> +
> + return $#stmt_lines + 2;
> +}
> +
> +sub statement_rawlines {
> + my ($stmt) =3D @_;
> +
> + my @stmt_lines =3D ($stmt =3D~ /\n/g);
> +
> + return $#stmt_lines + 2;
> +}
> +
> +sub statement_block_size {
> + my ($stmt) =3D @_;
> +
> + $stmt =3D~ s/(^|\n)./$1/g;
> + $stmt =3D~ s/^\s*\{//;
> + $stmt =3D~ s/}\s*$//;
> + $stmt =3D~ s/^\s*//;
> + $stmt =3D~ s/\s*$//;
> +
> + my @stmt_lines =3D ($stmt =3D~ /\n/g);
> + my @stmt_statements =3D ($stmt =3D~ /;/g);
> +
> + my $stmt_lines =3D $#stmt_lines + 2;
> + my $stmt_statements =3D $#stmt_statements + 1;
> +
> + if ($stmt_lines > $stmt_statements) {
> + return $stmt_lines;
> + } else {
> + return $stmt_statements;
> + }
> +}
> +
> +sub ctx_statement_full {
> + my ($linenr, $remain, $off) =3D @_;
> + my ($statement, $condition, $level);
> +
> + my (@chunks);
> +
> + # Grab the first conditional/block pair.
> + ($statement, $condition, $linenr, $remain, $off, $level) =3D
> + ctx_statement_block($linenr, $remain, $off);
> + #print "F: c<$condition> s<$statement> remain<$remain>\n";
> + push(@chunks, [ $condition, $statement ]);
> + if (!($remain > 0 && $condition =3D~
> /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
> + return ($level, $linenr, @chunks);
> + }
> +
> + # Pull in the following conditional/block pairs and see if they
> + # could continue the statement.
> + for (;;) {
> + ($statement, $condition, $linenr, $remain, $off, $level) =3D
> + ctx_statement_block($linenr, $remain, $off);
> + #print "C: c<$condition> s<$statement> remain<$remain>\n";
> + last if (!($remain > 0 && $condition =3D~
> /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
> + #print "C: push\n";
> + push(@chunks, [ $condition, $statement ]);
> + }
> +
> + return ($level, $linenr, @chunks);
> +}
> +
> +sub ctx_block_get {
> + my ($linenr, $remain, $outer, $open, $close, $off) =3D @_;
> + my $line;
> + my $start =3D $linenr - 1;
> + my $blk =3D '';
> + my @o;
> + my @c;
> + my @res =3D ();
> +
> + my $level =3D 0;
> + my @stack =3D ($level);
> + for ($line =3D $start; $remain > 0; $line++) {
> + next if ($rawlines[$line] =3D~ /^-/);
> + $remain--;
> +
> + $blk .=3D $rawlines[$line];
> +
> + # Handle nested #if/#else.
> + if ($lines[$line] =3D~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
> + push(@stack, $level);
> + } elsif ($lines[$line] =3D~ /^.\s*#\s*(?:else|elif)\b/) {
> + $level =3D $stack[$#stack - 1];
> + } elsif ($lines[$line] =3D~ /^.\s*#\s*endif\b/) {
> + $level =3D pop(@stack);
> + }
> +
> + foreach my $c (split(//, $lines[$line])) {
> + ##print "C<$c>L<$level><$open$close>O<$off>\n";
> + if ($off > 0) {
> + $off--;
> + next;
> + }
> +
> + if ($c eq $close && $level > 0) {
> + $level--;
> + last if ($level =3D=3D 0);
> + } elsif ($c eq $open) {
> + $level++;
> + }
> + }
> +
> + if (!$outer || $level <=3D 1) {
> + push(@res, $rawlines[$line]);
> + }
> +
> + last if ($level =3D=3D 0);
> + }
> +
> + return ($level, @res);
> +}
> +sub ctx_block_outer {
> + my ($linenr, $remain) =3D @_;
> +
> + my ($level, @r) =3D ctx_block_get($linenr, $remain, 1, '{', '}', 0);
> + return @r;
> +}
> +sub ctx_block {
> + my ($linenr, $remain) =3D @_;
> +
> + my ($level, @r) =3D ctx_block_get($linenr, $remain, 0, '{', '}', 0);
> + return @r;
> +}
> +sub ctx_statement {
> + my ($linenr, $remain, $off) =3D @_;
> +
> + my ($level, @r) =3D ctx_block_get($linenr, $remain, 0, '(', ')', $off);
> + return @r;
> +}
> +sub ctx_block_level {
> + my ($linenr, $remain) =3D @_;
> +
> + return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
> +}
> +sub ctx_statement_level {
> + my ($linenr, $remain, $off) =3D @_;
> +
> + return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
> +}
> +
> +sub ctx_locate_comment {
> + my ($first_line, $end_line) =3D @_;
> +
> + # Catch a comment on the end of the line itself.
> + my ($current_comment) =3D ($rawlines[$end_line - 1] =3D~ m@
> .*(/\*.*\*/)\s*(?:\\\s*)?$@);
> + return $current_comment if (defined $current_comment);
> +
> + # Look through the context and try and figure out if there is a
> + # comment.
> + my $in_comment =3D 0;
> + $current_comment =3D '';
> + for (my $linenr =3D $first_line; $linenr < $end_line; $linenr++) {
> + my $line =3D $rawlines[$linenr - 1];
> + #warn "           $line\n";
> + if ($linenr =3D=3D $first_line and $line =3D~ m@^.\s*\*@) {
> + $in_comment =3D 1;
> + }
> + if ($line =3D~ m@/\*@) {
> + $in_comment =3D 1;
> + }
> + if (!$in_comment && $current_comment ne '') {
> + $current_comment =3D '';
> + }
> + $current_comment .=3D $line . "\n" if ($in_comment);
> + if ($line =3D~ m@\*/@) {
> + $in_comment =3D 0;
> + }
> + }
> +
> + chomp($current_comment);
> + return($current_comment);
> +}
> +sub ctx_has_comment {
> + my ($first_line, $end_line) =3D @_;
> + my $cmt =3D ctx_locate_comment($first_line, $end_line);
> +
> + ##print "LINE: $rawlines[$end_line - 1 ]\n";
> + ##print "CMMT: $cmt\n";
> +
> + return ($cmt ne '');
> +}
> +
> +sub raw_line {
> + my ($linenr, $cnt) =3D @_;
> +
> + my $offset =3D $linenr - 1;
> + $cnt++;
> +
> + my $line;
> + while ($cnt) {
> + $line =3D $rawlines[$offset++];
> + next if (defined($line) && $line =3D~ /^-/);
> + $cnt--;
> + }
> +
> + return $line;
> +}
> +
> +sub cat_vet {
> + my ($vet) =3D @_;
> + my ($res, $coded);
> +
> + $res =3D '';
> + while ($vet =3D~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
> + $res .=3D $1;
> + if ($2 ne '') {
> + $coded =3D sprintf("^%c", unpack('C', $2) + 64);
> + $res .=3D $coded;
> + }
> + }
> + $res =3D~ s/$/\$/;
> +
> + return $res;
> +}
> +
> +my $av_preprocessor =3D 0;
> +my $av_pending;
> +my @av_paren_type;
> +my $av_pend_colon;
> +
> +sub annotate_reset {
> + $av_preprocessor =3D 0;
> + $av_pending =3D '_';
> + @av_paren_type =3D ('E');
> + $av_pend_colon =3D 'O';
> +}
> +
> +sub annotate_values {
> + my ($stream, $type) =3D @_;
> +
> + my $res;
> + my $var =3D '_' x length($stream);
> + my $cur =3D $stream;
> +
> + print "$stream\n" if ($dbg_values > 1);
> +
> + while (length($cur)) {
> + @av_paren_type =3D ('E') if ($#av_paren_type < 0);
> + print " <" . join('', @av_paren_type) .
> + "> <$type> <$av_pending>" if ($dbg_values > 1);
> + if ($cur =3D~ /^(\s+)/o) {
> + print "WS($1)\n" if ($dbg_values > 1);
> + if ($1 =3D~ /\n/ && $av_preprocessor) {
> + $type =3D pop(@av_paren_type);
> + $av_preprocessor =3D 0;
> + }
> +
> + } elsif ($cur =3D~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
> + print "CAST($1)\n" if ($dbg_values > 1);
> + push(@av_paren_type, $type);
> + $type =3D 'C';
> +
> + } elsif ($cur =3D~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
> + print "DECLARE($1)\n" if ($dbg_values > 1);
> + $type =3D 'T';
> +
> + } elsif ($cur =3D~ /^($Modifier)\s*/) {
> + print "MODIFIER($1)\n" if ($dbg_values > 1);
> + $type =3D 'T';
> +
> + } elsif ($cur =3D~ /^(\#\s*define\s*$Ident)(\(?)/o) {
> + print "DEFINE($1,$2)\n" if ($dbg_values > 1);
> *** 1791 LINES SKIPPED ***
>
>
>

--0000000000006acd1f05f7bcca27
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Yea, I did most of the work on this 18 months ago or so, b=
ut the shit in core and subsequent nastiness derailed it til now.<div><br><=
/div><div>It&#39;s gotten to &#39;decent or better&#39; at things, but far =
from perfect. I&#39;m sure that now the bug reports will come.</div><div><b=
r></div><div>Warner</div></div><br><div class=3D"gmail_quote"><div dir=3D"l=
tr" class=3D"gmail_attr">On Sat, Mar 25, 2023 at 6:22=E2=80=AFPM Drew Galla=
tin &lt;<a href=3D"mailto:gallatin@freebsd.org">gallatin@freebsd.org</a>&gt=
; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div cl=
ass=3D"msg6092219090955855520"><u></u><div><div>Thanks so much.=C2=A0 I&#39=
;ve wanted something like this *forever*<br></div><div><br></div><div>On Sa=
t, Mar 25, 2023, at 1:08 PM, Warner Losh wrote:<br></div><blockquote type=
=3D"cite" id=3D"m_6092219090955855520qt"><div>The branch main has been upda=
ted by imp:<br></div><div><br></div><div>URL:=C2=A0<a href=3D"https://cgit.=
FreeBSD.org/src/commit/?id=3D3a3c9242739efb0c76587ffbaa54c5d10b2cbcb4" targ=
et=3D"_blank">https://cgit.FreeBSD.org/src/commit/?id=3D3a3c9242739efb0c765=
87ffbaa54c5d10b2cbcb4</a><br></div><div><br></div><div>commit 3a3c9242739ef=
b0c76587ffbaa54c5d10b2cbcb4<br></div><div>Author:=C2=A0=C2=A0=C2=A0=C2=A0 W=
arner Losh &lt;<a href=3D"mailto:imp@FreeBSD.org" target=3D"_blank">imp@Fre=
eBSD.org</a>&gt;<br></div><div>AuthorDate: 2023-03-14 21:28:05 +0000<br></d=
iv><div>Commit:=C2=A0=C2=A0=C2=A0=C2=A0 Warner Losh &lt;<a href=3D"mailto:i=
mp@FreeBSD.org" target=3D"_blank">imp@FreeBSD.org</a>&gt;<br></div><div>Com=
mitDate: 2023-03-25 17:06:13 +0000<br></div><div><br></div><div>=C2=A0=C2=
=A0=C2=A0 <a href=3D"http://checkstyle9.pl" target=3D"_blank">checkstyle9.p=
l</a>: Perl script to check if a change is approximately style(9)<br></div>=
<div>=C2=A0=C2=A0=C2=A0=C2=A0<br></div><div>=C2=A0=C2=A0=C2=A0 This code is=
 adapted from the QEMU <a href=3D"http://checkpatch.pl" target=3D"_blank">c=
heckpatch.pl</a> script. It can check<br></div><div>=C2=A0=C2=A0=C2=A0 eith=
er a patch, a file or a git branch. It tries to warn about things<br></div>=
<div>=C2=A0=C2=A0=C2=A0 that I believe might be style(9) violations. It&#39=
;s experimental, since I<br></div><div>=C2=A0=C2=A0=C2=A0 heavily hacked on=
 the qemu version to get it to not complain (much)<br></div><div>=C2=A0=C2=
=A0=C2=A0 about iconic code in the tree. At the moment, it&#39;s use should=
 be<br></div><div>=C2=A0=C2=A0=C2=A0 considered expermental. It will likely=
 miss violations, and complain<br></div><div>=C2=A0=C2=A0=C2=A0 about code =
that&#39;s perfectly fine.=C2=A0 It&#39;s offered as an experiment<br></div=
><div>=C2=A0=C2=A0=C2=A0 and to make it easier for contributors to submit p=
atches.<br></div><div>---<br></div><div>tools/build/<a href=3D"http://check=
style9.pl" target=3D"_blank">checkstyle9.pl</a> | 2748 ++++++++++++++++++++=
++++++++++++++++++++++++<br></div><div>1 file changed, 2748 insertions(+)<b=
r></div><div><br></div><div>diff --git a/tools/build/<a href=3D"http://chec=
kstyle9.pl" target=3D"_blank">checkstyle9.pl</a> b/tools/build/<a href=3D"h=
ttp://checkstyle9.pl" target=3D"_blank">checkstyle9.pl</a><br></div><div>ne=
w file mode 100755<br></div><div>index 000000000000..5aec3819bf7c<br></div>=
<div>--- /dev/null<br></div><div>+++ b/tools/build/<a href=3D"http://checks=
tyle9.pl" target=3D"_blank">checkstyle9.pl</a><br></div><div>@@ -0,0 +1,274=
8 @@<br></div><div>+#!/usr/bin/env perl<br></div><div>+# (c) 2001, Dave Jon=
es. (the file handling bit)<br></div><div>+# (c) 2005, Joel Schopp &lt;<a h=
ref=3D"mailto:jschopp@austin.ibm.com" target=3D"_blank">jschopp@austin.ibm.=
com</a>&gt; (the ugly bit)<br></div><div>+# (c) 2007,2008, Andy Whitcroft &=
lt;<a href=3D"mailto:apw@uk.ibm.com" target=3D"_blank">apw@uk.ibm.com</a>&g=
t; (new conditions, test suite)<br></div><div>+# (c) 2008-2010 Andy Whitcro=
ft &lt;<a href=3D"mailto:apw@canonical.com" target=3D"_blank">apw@canonical=
.com</a>&gt;<br></div><div>+# Licensed under the terms of the GNU GPL Licen=
se version 2<br></div><div>+<br></div><div>+use strict;<br></div><div>+use =
warnings;<br></div><div>+use Term::ANSIColor qw(:constants);<br></div><div>=
+<br></div><div>+my $P =3D $0;<br></div><div>+$P =3D~ s@.*/@@g;<br></div><d=
iv>+<br></div><div>+our $SrcFile=C2=A0=C2=A0=C2=A0 =3D qr{\.(?:h|c|cpp|s|S|=
pl|py|sh)$};<br></div><div>+<br></div><div>+my $V =3D &#39;0.31&#39;;<br></=
div><div>+<br></div><div>+use Getopt::Long qw(:config no_auto_abbrev);<br><=
/div><div>+<br></div><div>+my $quiet =3D 0;<br></div><div>+my $tree =3D 1;<=
br></div><div>+my $chk_signoff =3D 1;<br></div><div>+my $chk_patch =3D unde=
f;<br></div><div>+my $chk_branch =3D undef;<br></div><div>+my $tst_only;<br=
></div><div>+my $emacs =3D 0;<br></div><div>+my $terse =3D 0;<br></div><div=
>+my $file =3D undef;<br></div><div>+my $color =3D &quot;auto&quot;;<br></d=
iv><div>+my $no_warnings =3D 0;<br></div><div>+my $summary =3D 1;<br></div>=
<div>+my $mailback =3D 0;<br></div><div>+my $summary_file =3D 0;<br></div><=
div>+my $root;<br></div><div>+my %debug;<br></div><div>+my $help =3D 0;<br>=
</div><div>+<br></div><div>+sub help {<br></div><div>+	my ($exitcode) =3D @=
_;<br></div><div>+<br></div><div>+	print &lt;&lt; &quot;EOM&quot;;<br></div=
><div>+Usage:<br></div><div>+<br></div><div>+=C2=A0=C2=A0=C2=A0 $P [OPTION]=
... [FILE]...<br></div><div>+=C2=A0=C2=A0=C2=A0 $P [OPTION]... [GIT-REV-LIS=
T]<br></div><div>+<br></div><div>+Version: $V<br></div><div>+<br></div><div=
>+Options:<br></div><div>+=C2=A0 -q, --quiet=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 quiet<br></div=
><div>+=C2=A0 --patch=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 treat FILE as =
patchfile<br></div><div>+=C2=A0 --branch=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
 treat args as GIT revision list<br></div><div>+=C2=A0 --emacs=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 emacs compile window format<br></div><div>+=C2=
=A0 --terse=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 one line per report<br>=
</div><div>+=C2=A0 -f, --file=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 treat FILE as regular s=
ource file<br></div><div>+=C2=A0 --strict=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
 fail if only warnings are found<br></div><div>+=C2=A0 --no-summary=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 suppress the per-file summary<br></div><div>+=C2=A0 --mailback=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 only produce a report in case of warnings/errors<br></div><div=
>+=C2=A0 --summary-file=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 include the filename in summary<br></div><div>+=C2=A0=
 --debug KEY=3D[0|1]=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
turn on/off debugging of KEY, where KEY is one of<br></div><div>+=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 &#39;values&#39;, &#39;possible&#39;, &#39;type&#39;, and &#39;at=
tr&#39; (default<br></div><div>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 is all off)<br></div><d=
iv>+=C2=A0 --test-only=3DWORD=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 report only warnings/errors containing WORD<br></div><div>+=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 literally<br></div><div>+=C2=A0 --color[=3DWHEN]=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Use colo=
rs &#39;always&#39;, &#39;never&#39;, or only when output<br></div><div>+=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 is a terminal (&#39;auto&#39;). Default is &#39;auto&#39=
;.<br></div><div>+=C2=A0 -h, --help, --version=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 display this help and exit<br></div><div>+<br></div><div>+When FILE is =
- read standard input.<br></div><div>+EOM<br></div><div>+<br></div><div>+	e=
xit($exitcode);<br></div><div>+}<br></div><div>+<br></div><div>+# Use at yo=
ur own risk<br></div><div>+print &quot;\n&quot;, MAGENTA, &quot;WARNING:&qu=
ot;, RESET, &quot; This code is highly experimental ... likely isn&#39;t a =
great style(9) match yet\n\n&quot;;<br></div><div>+<br></div><div>+# Perl&#=
39;s Getopt::Long allows options to take optional arguments after a space.<=
br></div><div>+# Prevent --color by itself from consuming other arguments<b=
r></div><div>+foreach (@ARGV) {<br></div><div>+	if ($_ eq &quot;--color&quo=
t; || $_ eq &quot;-color&quot;) {<br></div><div>+		$_ =3D &quot;--color=3D$=
color&quot;;<br></div><div>+	}<br></div><div>+}<br></div><div>+<br></div><d=
iv>+GetOptions(<br></div><div>+	&#39;q|quiet+&#39;	=3D&gt; \$quiet,<br></di=
v><div>+	&#39;tree!&#39;		=3D&gt; \$tree,<br></div><div>+	&#39;signoff!&#39=
;	=3D&gt; \$chk_signoff,<br></div><div>+	&#39;patch!&#39;	=3D&gt; \$chk_pat=
ch,<br></div><div>+	&#39;branch!&#39;	=3D&gt; \$chk_branch,<br></div><div>+=
	&#39;emacs!&#39;	=3D&gt; \$emacs,<br></div><div>+	&#39;terse!&#39;	=3D&gt;=
 \$terse,<br></div><div>+	&#39;f|file!&#39;	=3D&gt; \$file,<br></div><div>+=
	&#39;strict!&#39;	=3D&gt; \$no_warnings,<br></div><div>+	&#39;root=3Ds&#39=
;	=3D&gt; \$root,<br></div><div>+	&#39;summary!&#39;	=3D&gt; \$summary,<br>=
</div><div>+	&#39;mailback!&#39;	=3D&gt; \$mailback,<br></div><div>+	&#39;s=
ummary-file!&#39;	=3D&gt; \$summary_file,<br></div><div>+<br></div><div>+	&=
#39;debug=3Ds&#39;	=3D&gt; \%debug,<br></div><div>+	&#39;test-only=3Ds&#39;=
	=3D&gt; \$tst_only,<br></div><div>+	&#39;color=3Ds&#39;=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 =3D&gt; \$color,<br></div><div>+	&#39;no-color&#39;=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D&gt; sub { $color =3D &#39;never&#39;; },<br=
></div><div>+	&#39;h|help&#39;	=3D&gt; \$help,<br></div><div>+	&#39;version=
&#39;	=3D&gt; \$help<br></div><div>+) or help(1);<br></div><div>+<br></div>=
<div>+help(0) if ($help);<br></div><div>+<br></div><div>+my $exit =3D 0;<br=
></div><div>+<br></div><div>+if ($#ARGV &lt; 0) {<br></div><div>+	print &qu=
ot;$P: no input files\n&quot;;<br></div><div>+	exit(1);<br></div><div>+}<br=
></div><div>+<br></div><div>+if (!defined $chk_branch &amp;&amp; !defined $=
chk_patch &amp;&amp; !defined $file) {<br></div><div>+	$chk_branch =3D $ARG=
V[0] =3D~ /.\.\./ ? 1 : 0;<br></div><div>+	$file =3D $ARGV[0] =3D~ /$SrcFil=
e/ ? 1 : 0;<br></div><div>+	$chk_patch =3D $chk_branch || $file ? 0 : 1;<br=
></div><div>+} elsif (!defined $chk_branch &amp;&amp; !defined $chk_patch) =
{<br></div><div>+	if ($file) {<br></div><div>+		$chk_branch =3D $chk_patch =
=3D 0;<br></div><div>+	} else {<br></div><div>+		$chk_branch =3D $ARGV[0] =
=3D~ /.\.\./ ? 1 : 0;<br></div><div>+		$chk_patch =3D $chk_branch ? 0 : 1;<=
br></div><div>+	}<br></div><div>+} elsif (!defined $chk_branch &amp;&amp; !=
defined $file) {<br></div><div>+	if ($chk_patch) {<br></div><div>+		$chk_br=
anch =3D $file =3D 0;<br></div><div>+	} else {<br></div><div>+		$chk_branch=
 =3D $ARGV[0] =3D~ /.\.\./ ? 1 : 0;<br></div><div>+		$file =3D $chk_branch =
? 0 : 1;<br></div><div>+	}<br></div><div>+} elsif (!defined $chk_patch &amp=
;&amp; !defined $file) {<br></div><div>+	if ($chk_branch) {<br></div><div>+=
		$chk_patch =3D $file =3D 0;<br></div><div>+	} else {<br></div><div>+		$fi=
le =3D $ARGV[0] =3D~ /$SrcFile/ ? 1 : 0;<br></div><div>+		$chk_patch =3D $f=
ile ? 0 : 1;<br></div><div>+	}<br></div><div>+} elsif (!defined $chk_branch=
) {<br></div><div>+	$chk_branch =3D $chk_patch || $file ? 0 : 1;<br></div><=
div>+} elsif (!defined $chk_patch) {<br></div><div>+	$chk_patch =3D $chk_br=
anch || $file ? 0 : 1;<br></div><div>+} elsif (!defined $file) {<br></div><=
div>+	$file =3D $chk_patch || $chk_branch ? 0 : 1;<br></div><div>+}<br></di=
v><div>+<br></div><div>+if (($chk_patch &amp;&amp; $chk_branch) ||<br></div=
><div>+=C2=A0=C2=A0=C2=A0 ($chk_patch &amp;&amp; $file) ||<br></div><div>+=
=C2=A0=C2=A0=C2=A0 ($chk_branch &amp;&amp; $file)) {<br></div><div>+	die &q=
uot;Only one of --file, --branch, --patch is permitted\n&quot;;<br></div><d=
iv>+}<br></div><div>+if (!$chk_patch &amp;&amp; !$chk_branch &amp;&amp; !$f=
ile) {<br></div><div>+	die &quot;One of --file, --branch, --patch is requir=
ed\n&quot;;<br></div><div>+}<br></div><div>+<br></div><div>+if ($color =3D~=
 /^always$/i) {<br></div><div>+	$color =3D 1;<br></div><div>+} elsif ($colo=
r =3D~ /^never$/i) {<br></div><div>+	$color =3D 0;<br></div><div>+} elsif (=
$color =3D~ /^auto$/i) {<br></div><div>+	$color =3D (-t STDOUT);<br></div><=
div>+} else {<br></div><div>+	die &quot;Invalid color mode: $color\n&quot;;=
<br></div><div>+}<br></div><div>+<br></div><div>+my $dbg_values =3D 0;<br><=
/div><div>+my $dbg_possible =3D 0;<br></div><div>+my $dbg_type =3D 0;<br></=
div><div>+my $dbg_attr =3D 0;<br></div><div>+my $dbg_adv_dcs =3D 0;<br></di=
v><div>+my $dbg_adv_checking =3D 0;<br></div><div>+my $dbg_adv_apw =3D 0;<b=
r></div><div>+for my $key (keys %debug) {<br></div><div>+	## no critic<br><=
/div><div>+	eval &quot;\${dbg_$key} =3D &#39;$debug{$key}&#39;;&quot;;<br><=
/div><div>+	die &quot;$@&quot; if ($@);<br></div><div>+}<br></div><div>+<br=
></div><div>+my $rpt_cleaners =3D 0;<br></div><div>+<br></div><div>+if ($te=
rse) {<br></div><div>+	$emacs =3D 1;<br></div><div>+	$quiet++;<br></div><di=
v>+}<br></div><div>+<br></div><div>+my $emitted_corrupt =3D 0;<br></div><di=
v>+<br></div><div>+our $Ident	=3D qr{<br></div><div>+			[A-Za-z_][A-Za-z\d_=
]*<br></div><div>+			(?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*<br></div><div>+		=
}x;<br></div><div>+our $Storage	=3D qr{extern|static|asmlinkage};<br></div>=
<div>+our $Sparse	=3D qr{<br></div><div>+			__force<br></div><div>+		}x;<br=
></div><div>+<br></div><div>+# Notes to $Attribute:<br></div><div>+our $Att=
ribute	=3D qr{<br></div><div>+			const|<br></div><div>+			volatile|<br></di=
v><div>+			QEMU_NORETURN|<br></div><div>+			QEMU_WARN_UNUSED_RESULT|<br></d=
iv><div>+			QEMU_SENTINEL|<br></div><div>+			QEMU_PACKED|<br></div><div>+		=
	GCC_FMT_ATTR<br></div><div>+		=C2=A0 }x;<br></div><div>+our $Modifier;<br>=
</div><div>+our $Inline	=3D qr{inline};<br></div><div>+our $Member	=3D qr{-=
&gt;$Ident|\.$Ident|\[[^]]*\]};<br></div><div>+our $Lval	=3D qr{$Ident(?:$M=
ember)*};<br></div><div>+<br></div><div>+our $Constant	=3D qr{(?:[0-9]+|0x[=
0-9a-fA-F]+)[UL]*};<br></div><div>+our $Assignment	=3D qr{(?:\*\=3D|/=3D|%=
=3D|\+=3D|-=3D|&lt;&lt;=3D|&gt;&gt;=3D|&amp;=3D|\^=3D|\|=3D|=3D)};<br></div=
><div>+our $Compare=C2=A0=C2=A0=C2=A0 =3D qr{&lt;=3D|&gt;=3D|=3D=3D|!=3D|&l=
t;|&gt;};<br></div><div>+our $Operators	=3D qr{<br></div><div>+			&lt;=3D|&=
gt;=3D|=3D=3D|!=3D|<br></div><div>+			=3D&gt;|-&gt;|&lt;&lt;|&gt;&gt;|&lt;|=
&gt;|!|~|<br></div><div>+			&amp;&amp;|\|\||,|\^|\+\+|--|&amp;|\||\+|-|\*|\=
/|%<br></div><div>+		=C2=A0 }x;<br></div><div>+<br></div><div>+our $NonptrT=
ype;<br></div><div>+our $Type;<br></div><div>+our $Declare;<br></div><div>+=
<br></div><div>+our $NON_ASCII_UTF8	=3D qr{<br></div><div>+	[\xC2-\xDF][\x8=
0-\xBF]=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 # non-overlong 2-byte<br></div><div>+	|=C2=A0 \xE0[\xA0-=
\xBF][\x80-\xBF]=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # excluding over=
longs<br></div><div>+	| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}=C2=A0 # straight =
3-byte<br></div><div>+	|=C2=A0 \xED[\x80-\x9F][\x80-\xBF]=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 # excluding surrogates<br></div><div>+	|=C2=A0 \xF=
0[\x90-\xBF][\x80-\xBF]{2}=C2=A0=C2=A0=C2=A0=C2=A0 # planes 1-3<br></div><d=
iv>+	| [\xF1-\xF3][\x80-\xBF]{3}=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 # planes 4-15<br></div><div>+	|=C2=A0 \xF4[\x80-\x8F][\x80-\xB=
F]{2}=C2=A0=C2=A0=C2=A0=C2=A0 # plane 16<br></div><div>+}x;<br></div><div>+=
<br></div><div>+our $UTF8	=3D qr{<br></div><div>+	[\x09\x0A\x0D\x20-\x7E]=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 # ASCII<br></div><div>+	| $NON_ASCII_UTF8<br></div><div>+}x;<br></div><=
div>+<br></div><div>+# some readers default to ISO-8859-1 when showing emai=
l source. detect<br></div><div>+# when UTF-8 is incorrectly interpreted as =
ISO-8859-1 and reencoded back.<br></div><div>+# False positives are possibl=
e but very unlikely.<br></div><div>+our $UTF8_MOJIBAKE =3D qr{<br></div><di=
v>+	\xC3[\x82-\x9F] \xC2[\x80-\xBF]=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
 # c2-df 80-bf<br></div><div>+	| \xC3\xA0 \xC2[\xA0-\xBF] \xC2[\x80-\xBF]=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # e0 a0-bf 80-bf<br></div>=
<div>+	| \xC3[\xA1-\xAC\xAE\xAF] (?: \xC2[\x80-\xBF]){2}=C2=A0 # e1-ec/ee/e=
f 80-bf 80-bf<br></div><div>+	| \xC3\xAD \xC2[\x80-\x9F] \xC2[\x80-\xBF]=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # ed 80-9f 80-bf<br></div><di=
v>+	| \xC3\xB0 \xC2[\x90-\xBF] (?: \xC2[\x80-\xBF]){2} # f0 90-bf 80-bf 80-=
bf<br></div><div>+	| \xC3[\xB1-\xB3] (?: \xC2[\x80-\xBF]){3}=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # f1-f3 80-bf 80-bf 80-bf<br></div>=
<div>+	| \xC3\xB4 \xC2[\x80-\x8F] (?: \xC2[\x80-\xBF]){2} # f4 80-b8 80-bf =
80-bf<br></div><div>+}x;<br></div><div>+<br></div><div>+# There are still s=
ome false positives, but this catches most<br></div><div>+# common cases.<b=
r></div><div>+our $typeTypedefs =3D qr{(?x:<br></div><div>+=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 (?![KMGTPE]iB)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 # IEC binary prefix (do not match)<br></div><div>+=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 [A-Z][A-Z\d_]*[a-z][A-Za-z\d_]*=C2=A0=
=C2=A0=C2=A0=C2=A0 # camelcase<br></div><div>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 | [A-Z][A-Z\d_]*AIOCB=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # all uppercase<br></div><=
div>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | [A-Z][A-Z\d_]*CPU=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 # all uppercase<br></div><div>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 | QEMUBH=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # all uppercase<br></div><div>+)};<br>=
</div><div>+<br></div><div>+our @typeList =3D (<br></div><div>+	qr{void},<b=
r></div><div>+	qr{(?:unsigned\s+)?char},<br></div><div>+	qr{(?:unsigned\s+)=
?short},<br></div><div>+	qr{(?:unsigned\s+)?int},<br></div><div>+	qr{(?:uns=
igned\s+)?long},<br></div><div>+	qr{(?:unsigned\s+)?long\s+int},<br></div><=
div>+	qr{(?:unsigned\s+)?long\s+long},<br></div><div>+	qr{(?:unsigned\s+)?l=
ong\s+long\s+int},<br></div><div>+	qr{unsigned},<br></div><div>+	qr{float},=
<br></div><div>+	qr{double},<br></div><div>+	qr{bool},<br></div><div>+	qr{s=
truct\s+$Ident},<br></div><div>+	qr{union\s+$Ident},<br></div><div>+	qr{enu=
m\s+$Ident},<br></div><div>+	qr{${Ident}_t},<br></div><div>+	qr{${Ident}_ha=
ndler},<br></div><div>+	qr{${Ident}_handler_fn},<br></div><div>+	qr{target_=
(?:u)?long},<br></div><div>+	qr{hwaddr},<br></div><div>+);<br></div><div>+<=
br></div><div>+# This can be modified by sub possible.=C2=A0 Since it can b=
e empty, be careful<br></div><div>+# about regexes that always match, becau=
se they can cause infinite loops.<br></div><div>+our @modifierList =3D (<br=
></div><div>+);<br></div><div>+<br></div><div>+sub build_types {<br></div><=
div>+	my $all =3D &quot;(?x:=C2=A0 \n&quot; . join(&quot;|\n=C2=A0 &quot;, =
@typeList) . &quot;\n)&quot;;<br></div><div>+	if (@modifierList &gt; 0) {<b=
r></div><div>+		my $mods =3D &quot;(?x:=C2=A0 \n&quot; . join(&quot;|\n=C2=
=A0 &quot;, @modifierList) . &quot;\n)&quot;;<br></div><div>+		$Modifier =
=3D qr{(?:$Attribute|$Sparse|$mods)};<br></div><div>+	} else {<br></div><di=
v>+		$Modifier =3D qr{(?:$Attribute|$Sparse)};<br></div><div>+	}<br></div><=
div>+	$NonptrType	=3D qr{<br></div><div>+			(?:$Modifier\s+|const\s+)*<br><=
/div><div>+			(?:<br></div><div>+				(?:typeof|__typeof__)\s*\(\s*\**\s*$Id=
ent\s*\)|<br></div><div>+				(?:$typeTypedefs\b)|<br></div><div>+				(?:${a=
ll}\b)<br></div><div>+			)<br></div><div>+			(?:\s+$Modifier|\s+const)*<br>=
</div><div>+		=C2=A0 }x;<br></div><div>+	$Type	=3D qr{<br></div><div>+			$N=
onptrType<br></div><div>+			(?:[\s\*]+\s*const|[\s\*]+|(?:\s*\[\s*\])+)?<br=
></div><div>+			(?:\s+$Inline|\s+$Modifier)*<br></div><div>+		=C2=A0 }x;<br=
></div><div>+	$Declare	=3D qr{(?:$Storage\s+)?$Type};<br></div><div>+}<br><=
/div><div>+build_types();<br></div><div>+<br></div><div>+$chk_signoff =3D 0=
 if ($file);<br></div><div>+<br></div><div>+my @rawlines =3D ();<br></div><=
div>+my @lines =3D ();<br></div><div>+my $vname;<br></div><div>+if ($chk_br=
anch) {<br></div><div>+	my @patches;<br></div><div>+	my %git_commits =3D ()=
;<br></div><div>+	my $HASH;<br></div><div>+	open($HASH, &quot;-|&quot;, &qu=
ot;git&quot;, &quot;log&quot;, &quot;--reverse&quot;, &quot;--no-merges&quo=
t;, &quot;--format=3D%H %s&quot;, $ARGV[0]) ||<br></div><div>+		die &quot;$=
P: git log --reverse --no-merges --format=3D&#39;%H %s&#39; $ARGV[0] failed=
 - $!\n&quot;;<br></div><div>+<br></div><div>+	for my $line (&lt;$HASH&gt;)=
 {<br></div><div>+		$line =3D~ /^([0-9a-fA-F]{40,40}) (.*)$/;<br></div><div=
>+		next if (!defined($1) || !defined($2));<br></div><div>+		my $sha1 =3D $=
1;<br></div><div>+		my $subject =3D $2;<br></div><div>+		push(@patches, $sh=
a1);<br></div><div>+		$git_commits{$sha1} =3D $subject;<br></div><div>+	}<b=
r></div><div>+<br></div><div>+	close $HASH;<br></div><div>+<br></div><div>+=
	die &quot;$P: no revisions returned for revlist &#39;$ARGV[0]&#39;\n&quot;=
<br></div><div>+	=C2=A0=C2=A0=C2=A0 unless @patches;<br></div><div>+<br></d=
iv><div>+	my $i =3D 1;<br></div><div>+	my $num_patches =3D @patches;<br></d=
iv><div>+	for my $hash (@patches) {<br></div><div>+		my $FILE;<br></div><di=
v>+		open($FILE, &#39;-|&#39;, &quot;git&quot;, &quot;show&quot;, &quot;--p=
atch-with-stat&quot;, $hash) ||<br></div><div>+			die &quot;$P: git show $h=
ash - $!\n&quot;;<br></div><div>+		while (&lt;$FILE&gt;) {<br></div><div>+	=
		chomp;<br></div><div>+			push(@rawlines, $_);<br></div><div>+		}<br></div=
><div>+		close($FILE);<br></div><div>+		$vname =3D substr($hash, 0, 12) . &=
#39; (&#39; . $git_commits{$hash} . &#39;)&#39;;<br></div><div>+		if ($num_=
patches &gt; 1 &amp;&amp; $quiet =3D=3D 0) {<br></div><div>+			my $prefix =
=3D &quot;$i/$num_patches&quot;;<br></div><div>+			$prefix =3D BLUE . BOLD =
. $prefix . RESET if $color;<br></div><div>+			print &quot;$prefix Checking=
 commit $vname\n&quot;;<br></div><div>+			$vname =3D &quot;Patch $i/$num_pa=
tches&quot;;<br></div><div>+		} else {<br></div><div>+			$vname =3D &quot;C=
ommit &quot; . $vname;<br></div><div>+		}<br></div><div>+		if (!process($ha=
sh)) {<br></div><div>+			$exit =3D 1;<br></div><div>+			print &quot;\n&quot=
; if ($num_patches &gt; 1 &amp;&amp; $quiet =3D=3D 0);<br></div><div>+		}<b=
r></div><div>+		@rawlines =3D ();<br></div><div>+		@lines =3D ();<br></div>=
<div>+		$i++;<br></div><div>+	}<br></div><div>+} else {<br></div><div>+	for=
 my $filename (@ARGV) {<br></div><div>+		my $FILE;<br></div><div>+		if ($fi=
le) {<br></div><div>+			open($FILE, &#39;-|&#39;, &quot;diff -u /dev/null $=
filename&quot;) ||<br></div><div>+				die &quot;$P: $filename: diff failed =
- $!\n&quot;;<br></div><div>+		} elsif ($filename eq &#39;-&#39;) {<br></di=
v><div>+			open($FILE, &#39;&lt;&amp;STDIN&#39;);<br></div><div>+		} else {=
<br></div><div>+			open($FILE, &#39;&lt;&#39;, &quot;$filename&quot;) ||<br=
></div><div>+				die &quot;$P: $filename: open failed - $!\n&quot;;<br></di=
v><div>+		}<br></div><div>+		if ($filename eq &#39;-&#39;) {<br></div><div>=
+			$vname =3D &#39;Your patch&#39;;<br></div><div>+		} else {<br></div><di=
v>+			$vname =3D $filename;<br></div><div>+		}<br></div><div>+		print &quot=
;Checking $filename...\n&quot; if @ARGV &gt; 1 &amp;&amp; $quiet =3D=3D 0;<=
br></div><div>+		while (&lt;$FILE&gt;) {<br></div><div>+			chomp;<br></div>=
<div>+			push(@rawlines, $_);<br></div><div>+		}<br></div><div>+		close($FI=
LE);<br></div><div>+		if (!process($filename)) {<br></div><div>+			$exit =
=3D 1;<br></div><div>+		}<br></div><div>+		@rawlines =3D ();<br></div><div>=
+		@lines =3D ();<br></div><div>+	}<br></div><div>+}<br></div><div>+<br></d=
iv><div>+exit($exit);<br></div><div>+<br></div><div>+sub top_of_kernel_tree=
 {<br></div><div>+	my ($root) =3D @_;<br></div><div>+<br></div><div>+	my @t=
ree_check =3D (<br></div><div>+	=C2=A0=C2=A0=C2=A0 &quot;Makefile.inc1&quot=
;, &quot;README.md&quot;, &quot;sys&quot;,<br></div><div>+	=C2=A0=C2=A0=C2=
=A0 &quot;usr.sbin&quot;<br></div><div>+	);<br></div><div>+<br></div><div>+=
	foreach my $check (@tree_check) {<br></div><div>+		if (! -e $root . &#39;/=
&#39; . $check) {<br></div><div>+			return 0;<br></div><div>+		}<br></div><=
div>+	}<br></div><div>+	return 1;<br></div><div>+}<br></div><div>+<br></div=
><div>+sub expand_tabs {<br></div><div>+	my ($str) =3D @_;<br></div><div>+<=
br></div><div>+	my $res =3D &#39;&#39;;<br></div><div>+	my $n =3D 0;<br></d=
iv><div>+	for my $c (split(//, $str)) {<br></div><div>+		if ($c eq &quot;\t=
&quot;) {<br></div><div>+			$res .=3D &#39; &#39;;<br></div><div>+			$n++;<=
br></div><div>+			for (; ($n % 8) !=3D 0; $n++) {<br></div><div>+				$res .=
=3D &#39; &#39;;<br></div><div>+			}<br></div><div>+			next;<br></div><div>=
+		}<br></div><div>+		$res .=3D $c;<br></div><div>+		$n++;<br></div><div>+	=
}<br></div><div>+<br></div><div>+	return $res;<br></div><div>+}<br></div><d=
iv>+sub copy_spacing {<br></div><div>+	(my $res =3D shift) =3D~ tr/\t/ /c;<=
br></div><div>+	return $res;<br></div><div>+}<br></div><div>+<br></div><div=
>+sub line_stats {<br></div><div>+	my ($line) =3D @_;<br></div><div>+<br></=
div><div>+	# Drop the diff line leader and expand tabs<br></div><div>+	$lin=
e =3D~ s/^.//;<br></div><div>+	$line =3D expand_tabs($line);<br></div><div>=
+<br></div><div>+	# Pick the indent from the front of the line.<br></div><d=
iv>+	my ($white) =3D ($line =3D~ /^(\s*)/);<br></div><div>+<br></div><div>+=
	return (length($line), length($white));<br></div><div>+}<br></div><div>+<b=
r></div><div>+my $sanitise_quote =3D &#39;&#39;;<br></div><div>+<br></div><=
div>+sub sanitise_line_reset {<br></div><div>+	my ($in_comment) =3D @_;<br>=
</div><div>+<br></div><div>+	if ($in_comment) {<br></div><div>+		$sanitise_=
quote =3D &#39;*/&#39;;<br></div><div>+	} else {<br></div><div>+		$sanitise=
_quote =3D &#39;&#39;;<br></div><div>+	}<br></div><div>+}<br></div><div>+su=
b sanitise_line {<br></div><div>+	my ($line) =3D @_;<br></div><div>+<br></d=
iv><div>+	my $res =3D &#39;&#39;;<br></div><div>+	my $l =3D &#39;&#39;;<br>=
</div><div>+<br></div><div>+	my $qlen =3D 0;<br></div><div>+	my $off =3D 0;=
<br></div><div>+	my $c;<br></div><div>+<br></div><div>+	# Always copy over =
the diff marker.<br></div><div>+	$res =3D substr($line, 0, 1);<br></div><di=
v>+<br></div><div>+	for ($off =3D 1; $off &lt; length($line); $off++) {<br>=
</div><div>+		$c =3D substr($line, $off, 1);<br></div><div>+<br></div><div>=
+		# Comments we are wacking completely including the begin<br></div><div>+=
		# and end, all to $;.<br></div><div>+		if ($sanitise_quote eq &#39;&#39; =
&amp;&amp; substr($line, $off, 2) eq &#39;/*&#39;) {<br></div><div>+			$san=
itise_quote =3D &#39;*/&#39;;<br></div><div>+<br></div><div>+			substr($res=
, $off, 2, &quot;$;$;&quot;);<br></div><div>+			$off++;<br></div><div>+			n=
ext;<br></div><div>+		}<br></div><div>+		if ($sanitise_quote eq &#39;*/&#39=
; &amp;&amp; substr($line, $off, 2) eq &#39;*/&#39;) {<br></div><div>+			$s=
anitise_quote =3D &#39;&#39;;<br></div><div>+			substr($res, $off, 2, &quot=
;$;$;&quot;);<br></div><div>+			$off++;<br></div><div>+			next;<br></div><d=
iv>+		}<br></div><div>+		if ($sanitise_quote eq &#39;&#39; &amp;&amp; subst=
r($line, $off, 2) eq &#39;//&#39;) {<br></div><div>+			$sanitise_quote =3D =
&#39;//&#39;;<br></div><div>+<br></div><div>+			substr($res, $off, 2, $sani=
tise_quote);<br></div><div>+			$off++;<br></div><div>+			next;<br></div><di=
v>+		}<br></div><div>+<br></div><div>+		# A \ in a string means ignore the =
next character.<br></div><div>+		if (($sanitise_quote eq &quot;&#39;&quot; =
|| $sanitise_quote eq &#39;&quot;&#39;) &amp;&amp;<br></div><div>+		=C2=A0=
=C2=A0=C2=A0 $c eq &quot;\\&quot;) {<br></div><div>+			substr($res, $off, 2=
, &#39;XX&#39;);<br></div><div>+			$off++;<br></div><div>+			next;<br></div=
><div>+		}<br></div><div>+		# Regular quotes.<br></div><div>+		if ($c eq &q=
uot;&#39;&quot; || $c eq &#39;&quot;&#39;) {<br></div><div>+			if ($sanitis=
e_quote eq &#39;&#39;) {<br></div><div>+				$sanitise_quote =3D $c;<br></di=
v><div>+<br></div><div>+				substr($res, $off, 1, $c);<br></div><div>+				n=
ext;<br></div><div>+			} elsif ($sanitise_quote eq $c) {<br></div><div>+			=
	$sanitise_quote =3D &#39;&#39;;<br></div><div>+			}<br></div><div>+		}<br>=
</div><div>+<br></div><div>+		#print &quot;c&lt;$c&gt; SQ&lt;$sanitise_quot=
e&gt;\n&quot;;<br></div><div>+		if ($off !=3D 0 &amp;&amp; $sanitise_quote =
eq &#39;*/&#39; &amp;&amp; $c ne &quot;\t&quot;) {<br></div><div>+			substr=
($res, $off, 1, $;);<br></div><div>+		} elsif ($off !=3D 0 &amp;&amp; $sani=
tise_quote eq &#39;//&#39; &amp;&amp; $c ne &quot;\t&quot;) {<br></div><div=
>+			substr($res, $off, 1, $;);<br></div><div>+		} elsif ($off !=3D 0 &amp;=
&amp; $sanitise_quote &amp;&amp; $c ne &quot;\t&quot;) {<br></div><div>+			=
substr($res, $off, 1, &#39;X&#39;);<br></div><div>+		} else {<br></div><div=
>+			substr($res, $off, 1, $c);<br></div><div>+		}<br></div><div>+	}<br></d=
iv><div>+<br></div><div>+	if ($sanitise_quote eq &#39;//&#39;) {<br></div><=
div>+		$sanitise_quote =3D &#39;&#39;;<br></div><div>+	}<br></div><div>+<br=
></div><div>+	# The pathname on a #include may be surrounded by &#39;&lt;&#=
39; and &#39;&gt;&#39;.<br></div><div>+	if ($res =3D~ /^.\s*\#\s*include\s+=
\&lt;(.*)\&gt;/) {<br></div><div>+		my $clean =3D &#39;X&#39; x length($1);=
<br></div><div>+		$res =3D~ s@\&lt;.*\&gt;@&lt;$clean&gt;@;<br></div><div>+=
<br></div><div>+	# The whole of a #error is a string.<br></div><div>+	} els=
if ($res =3D~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {<br></div><div>+		my=
 $clean =3D &#39;X&#39; x length($1);<br></div><div>+		$res =3D~ s@(\#\s*(?=
:error|warning)\s+).*@$1$clean@;<br></div><div>+	}<br></div><div>+<br></div=
><div>+	return $res;<br></div><div>+}<br></div><div>+<br></div><div>+sub ct=
x_statement_block {<br></div><div>+	my ($linenr, $remain, $off) =3D @_;<br>=
</div><div>+	my $line =3D $linenr - 1;<br></div><div>+	my $blk =3D &#39;&#3=
9;;<br></div><div>+	my $soff =3D $off;<br></div><div>+	my $coff =3D $off - =
1;<br></div><div>+	my $coff_set =3D 0;<br></div><div>+<br></div><div>+	my $=
loff =3D 0;<br></div><div>+<br></div><div>+	my $type =3D &#39;&#39;;<br></d=
iv><div>+	my $level =3D 0;<br></div><div>+	my @stack =3D ();<br></div><div>=
+	my $p;<br></div><div>+	my $c;<br></div><div>+	my $len =3D 0;<br></div><di=
v>+<br></div><div>+	my $remainder;<br></div><div>+	while (1) {<br></div><di=
v>+		@stack =3D ([&#39;&#39;, 0]) if ($#stack =3D=3D -1);<br></div><div>+<b=
r></div><div>+		#warn &quot;CSB: blk&lt;$blk&gt; remain&lt;$remain&gt;\n&qu=
ot;;<br></div><div>+		# If we are about to drop off the end, pull in more<b=
r></div><div>+		# context.<br></div><div>+		if ($off &gt;=3D $len) {<br></d=
iv><div>+			for (; $remain &gt; 0; $line++) {<br></div><div>+				last if (!=
defined $lines[$line]);<br></div><div>+				next if ($lines[$line] =3D~ /^-/=
);<br></div><div>+				$remain--;<br></div><div>+				$loff =3D $len;<br></di=
v><div>+				$blk .=3D $lines[$line] . &quot;\n&quot;;<br></div><div>+				$l=
en =3D length($blk);<br></div><div>+				$line++;<br></div><div>+				last;<b=
r></div><div>+			}<br></div><div>+			# Bail if there is no further context.=
<br></div><div>+			#warn &quot;CSB: blk&lt;$blk&gt; off&lt;$off&gt; len&lt;=
$len&gt;\n&quot;;<br></div><div>+			if ($off &gt;=3D $len) {<br></div><div>=
+				last;<br></div><div>+			}<br></div><div>+		}<br></div><div>+		$p =3D $=
c;<br></div><div>+		$c =3D substr($blk, $off, 1);<br></div><div>+		$remaind=
er =3D substr($blk, $off);<br></div><div>+<br></div><div>+		#warn &quot;CSB=
: c&lt;$c&gt; type&lt;$type&gt; level&lt;$level&gt; remainder&lt;$remainder=
&gt; coff_set&lt;$coff_set&gt;\n&quot;;<br></div><div>+<br></div><div>+		# =
Handle nested #if/#else.<br></div><div>+		if ($remainder =3D~ /^#\s*(?:ifnd=
ef|ifdef|if)\s/) {<br></div><div>+			push(@stack, [ $type, $level ]);<br></=
div><div>+		} elsif ($remainder =3D~ /^#\s*(?:else|elif)\b/) {<br></div><di=
v>+			($type, $level) =3D @{$stack[$#stack - 1]};<br></div><div>+		} elsif =
($remainder =3D~ /^#\s*endif\b/) {<br></div><div>+			($type, $level) =3D @{=
pop(@stack)};<br></div><div>+		}<br></div><div>+<br></div><div>+		# Stateme=
nt ends at the &#39;;&#39; or a close &#39;}&#39; at the<br></div><div>+		#=
 outermost level.<br></div><div>+		if ($level =3D=3D 0 &amp;&amp; $c eq &#3=
9;;&#39;) {<br></div><div>+			last;<br></div><div>+		}<br></div><div>+<br><=
/div><div>+		# An else is really a conditional as long as its not else if<b=
r></div><div>+		if ($level =3D=3D 0 &amp;&amp; $coff_set =3D=3D 0 &amp;&amp=
;<br></div><div>+				(!defined($p) || $p =3D~ /(?:\s|\}|\+)/) &amp;&amp;<br=
></div><div>+				$remainder =3D~ /^(else)(?:\s|{)/ &amp;&amp;<br></div><div=
>+				$remainder !~ /^else\s+if\b/) {<br></div><div>+			$coff =3D $off + le=
ngth($1) - 1;<br></div><div>+			$coff_set =3D 1;<br></div><div>+			#warn &q=
uot;CSB: mark coff&lt;$coff&gt; soff&lt;$soff&gt; 1&lt;$1&gt;\n&quot;;<br><=
/div><div>+			#warn &quot;[&quot; . substr($blk, $soff, $coff - $soff + 1) =
. &quot;]\n&quot;;<br></div><div>+		}<br></div><div>+<br></div><div>+		if (=
($type eq &#39;&#39; || $type eq &#39;(&#39;) &amp;&amp; $c eq &#39;(&#39;)=
 {<br></div><div>+			$level++;<br></div><div>+			$type =3D &#39;(&#39;;<br>=
</div><div>+		}<br></div><div>+		if ($type eq &#39;(&#39; &amp;&amp; $c eq =
&#39;)&#39;) {<br></div><div>+			$level--;<br></div><div>+			$type =3D ($le=
vel !=3D 0)? &#39;(&#39; : &#39;&#39;;<br></div><div>+<br></div><div>+			if=
 ($level =3D=3D 0 &amp;&amp; $coff &lt; $soff) {<br></div><div>+				$coff =
=3D $off;<br></div><div>+				$coff_set =3D 1;<br></div><div>+				#warn &quo=
t;CSB: mark coff&lt;$coff&gt;\n&quot;;<br></div><div>+			}<br></div><div>+	=
	}<br></div><div>+		if (($type eq &#39;&#39; || $type eq &#39;{&#39;) &amp;=
&amp; $c eq &#39;{&#39;) {<br></div><div>+			$level++;<br></div><div>+			$t=
ype =3D &#39;{&#39;;<br></div><div>+		}<br></div><div>+		if ($type eq &#39;=
{&#39; &amp;&amp; $c eq &#39;}&#39;) {<br></div><div>+			$level--;<br></div=
><div>+			$type =3D ($level !=3D 0)? &#39;{&#39; : &#39;&#39;;<br></div><di=
v>+<br></div><div>+			if ($level =3D=3D 0) {<br></div><div>+				if (substr(=
$blk, $off + 1, 1) eq &#39;;&#39;) {<br></div><div>+					$off++;<br></div><=
div>+				}<br></div><div>+				last;<br></div><div>+			}<br></div><div>+		}<=
br></div><div>+		$off++;<br></div><div>+	}<br></div><div>+	# We are truly a=
t the end, so shuffle to the next line.<br></div><div>+	if ($off =3D=3D $le=
n) {<br></div><div>+		$loff =3D $len + 1;<br></div><div>+		$line++;<br></di=
v><div>+		$remain--;<br></div><div>+	}<br></div><div>+<br></div><div>+	my $=
statement =3D substr($blk, $soff, $off - $soff + 1);<br></div><div>+	my $co=
ndition =3D substr($blk, $soff, $coff - $soff + 1);<br></div><div>+<br></di=
v><div>+	#warn &quot;STATEMENT&lt;$statement&gt;\n&quot;;<br></div><div>+	#=
warn &quot;CONDITION&lt;$condition&gt;\n&quot;;<br></div><div>+<br></div><d=
iv>+	#print &quot;coff&lt;$coff&gt; soff&lt;$off&gt; loff&lt;$loff&gt;\n&qu=
ot;;<br></div><div>+<br></div><div>+	return ($statement, $condition,<br></d=
iv><div>+			$line, $remain + 1, $off - $loff + 1, $level);<br></div><div>+}=
<br></div><div>+<br></div><div>+sub statement_lines {<br></div><div>+	my ($=
stmt) =3D @_;<br></div><div>+<br></div><div>+	# Strip the diff line prefixe=
s and rip blank lines at start and end.<br></div><div>+	$stmt =3D~ s/(^|\n)=
./$1/g;<br></div><div>+	$stmt =3D~ s/^\s*//;<br></div><div>+	$stmt =3D~ s/\=
s*$//;<br></div><div>+<br></div><div>+	my @stmt_lines =3D ($stmt =3D~ /\n/g=
);<br></div><div>+<br></div><div>+	return $#stmt_lines + 2;<br></div><div>+=
}<br></div><div>+<br></div><div>+sub statement_rawlines {<br></div><div>+	m=
y ($stmt) =3D @_;<br></div><div>+<br></div><div>+	my @stmt_lines =3D ($stmt=
 =3D~ /\n/g);<br></div><div>+<br></div><div>+	return $#stmt_lines + 2;<br><=
/div><div>+}<br></div><div>+<br></div><div>+sub statement_block_size {<br><=
/div><div>+	my ($stmt) =3D @_;<br></div><div>+<br></div><div>+	$stmt =3D~ s=
/(^|\n)./$1/g;<br></div><div>+	$stmt =3D~ s/^\s*\{//;<br></div><div>+	$stmt=
 =3D~ s/}\s*$//;<br></div><div>+	$stmt =3D~ s/^\s*//;<br></div><div>+	$stmt=
 =3D~ s/\s*$//;<br></div><div>+<br></div><div>+	my @stmt_lines =3D ($stmt =
=3D~ /\n/g);<br></div><div>+	my @stmt_statements =3D ($stmt =3D~ /;/g);<br>=
</div><div>+<br></div><div>+	my $stmt_lines =3D $#stmt_lines + 2;<br></div>=
<div>+	my $stmt_statements =3D $#stmt_statements + 1;<br></div><div>+<br></=
div><div>+	if ($stmt_lines &gt; $stmt_statements) {<br></div><div>+		return=
 $stmt_lines;<br></div><div>+	} else {<br></div><div>+		return $stmt_statem=
ents;<br></div><div>+	}<br></div><div>+}<br></div><div>+<br></div><div>+sub=
 ctx_statement_full {<br></div><div>+	my ($linenr, $remain, $off) =3D @_;<b=
r></div><div>+	my ($statement, $condition, $level);<br></div><div>+<br></di=
v><div>+	my (@chunks);<br></div><div>+<br></div><div>+	# Grab the first con=
ditional/block pair.<br></div><div>+	($statement, $condition, $linenr, $rem=
ain, $off, $level) =3D<br></div><div>+				ctx_statement_block($linenr, $rem=
ain, $off);<br></div><div>+	#print &quot;F: c&lt;$condition&gt; s&lt;$state=
ment&gt; remain&lt;$remain&gt;\n&quot;;<br></div><div>+	push(@chunks, [ $co=
ndition, $statement ]);<br></div><div>+	if (!($remain &gt; 0 &amp;&amp; $co=
ndition =3D~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {<br></div><div>+		ret=
urn ($level, $linenr, @chunks);<br></div><div>+	}<br></div><div>+<br></div>=
<div>+	# Pull in the following conditional/block pairs and see if they<br><=
/div><div>+	# could continue the statement.<br></div><div>+	for (;;) {<br><=
/div><div>+		($statement, $condition, $linenr, $remain, $off, $level) =3D<b=
r></div><div>+				ctx_statement_block($linenr, $remain, $off);<br></div><di=
v>+		#print &quot;C: c&lt;$condition&gt; s&lt;$statement&gt; remain&lt;$rem=
ain&gt;\n&quot;;<br></div><div>+		last if (!($remain &gt; 0 &amp;&amp; $con=
dition =3D~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));<br></div><div>+		#print &=
quot;C: push\n&quot;;<br></div><div>+		push(@chunks, [ $condition, $stateme=
nt ]);<br></div><div>+	}<br></div><div>+<br></div><div>+	return ($level, $l=
inenr, @chunks);<br></div><div>+}<br></div><div>+<br></div><div>+sub ctx_bl=
ock_get {<br></div><div>+	my ($linenr, $remain, $outer, $open, $close, $off=
) =3D @_;<br></div><div>+	my $line;<br></div><div>+	my $start =3D $linenr -=
 1;<br></div><div>+	my $blk =3D &#39;&#39;;<br></div><div>+	my @o;<br></div=
><div>+	my @c;<br></div><div>+	my @res =3D ();<br></div><div>+<br></div><di=
v>+	my $level =3D 0;<br></div><div>+	my @stack =3D ($level);<br></div><div>=
+	for ($line =3D $start; $remain &gt; 0; $line++) {<br></div><div>+		next i=
f ($rawlines[$line] =3D~ /^-/);<br></div><div>+		$remain--;<br></div><div>+=
<br></div><div>+		$blk .=3D $rawlines[$line];<br></div><div>+<br></div><div=
>+		# Handle nested #if/#else.<br></div><div>+		if ($lines[$line] =3D~ /^.\=
s*#\s*(?:ifndef|ifdef|if)\s/) {<br></div><div>+			push(@stack, $level);<br>=
</div><div>+		} elsif ($lines[$line] =3D~ /^.\s*#\s*(?:else|elif)\b/) {<br>=
</div><div>+			$level =3D $stack[$#stack - 1];<br></div><div>+		} elsif ($l=
ines[$line] =3D~ /^.\s*#\s*endif\b/) {<br></div><div>+			$level =3D pop(@st=
ack);<br></div><div>+		}<br></div><div>+<br></div><div>+		foreach my $c (sp=
lit(//, $lines[$line])) {<br></div><div>+			##print &quot;C&lt;$c&gt;L&lt;$=
level&gt;&lt;$open$close&gt;O&lt;$off&gt;\n&quot;;<br></div><div>+			if ($o=
ff &gt; 0) {<br></div><div>+				$off--;<br></div><div>+				next;<br></div><=
div>+			}<br></div><div>+<br></div><div>+			if ($c eq $close &amp;&amp; $le=
vel &gt; 0) {<br></div><div>+				$level--;<br></div><div>+				last if ($lev=
el =3D=3D 0);<br></div><div>+			} elsif ($c eq $open) {<br></div><div>+				=
$level++;<br></div><div>+			}<br></div><div>+		}<br></div><div>+<br></div><=
div>+		if (!$outer || $level &lt;=3D 1) {<br></div><div>+			push(@res, $raw=
lines[$line]);<br></div><div>+		}<br></div><div>+<br></div><div>+		last if =
($level =3D=3D 0);<br></div><div>+	}<br></div><div>+<br></div><div>+	return=
 ($level, @res);<br></div><div>+}<br></div><div>+sub ctx_block_outer {<br><=
/div><div>+	my ($linenr, $remain) =3D @_;<br></div><div>+<br></div><div>+	m=
y ($level, @r) =3D ctx_block_get($linenr, $remain, 1, &#39;{&#39;, &#39;}&#=
39;, 0);<br></div><div>+	return @r;<br></div><div>+}<br></div><div>+sub ctx=
_block {<br></div><div>+	my ($linenr, $remain) =3D @_;<br></div><div>+<br><=
/div><div>+	my ($level, @r) =3D ctx_block_get($linenr, $remain, 0, &#39;{&#=
39;, &#39;}&#39;, 0);<br></div><div>+	return @r;<br></div><div>+}<br></div>=
<div>+sub ctx_statement {<br></div><div>+	my ($linenr, $remain, $off) =3D @=
_;<br></div><div>+<br></div><div>+	my ($level, @r) =3D ctx_block_get($linen=
r, $remain, 0, &#39;(&#39;, &#39;)&#39;, $off);<br></div><div>+	return @r;<=
br></div><div>+}<br></div><div>+sub ctx_block_level {<br></div><div>+	my ($=
linenr, $remain) =3D @_;<br></div><div>+<br></div><div>+	return ctx_block_g=
et($linenr, $remain, 0, &#39;{&#39;, &#39;}&#39;, 0);<br></div><div>+}<br><=
/div><div>+sub ctx_statement_level {<br></div><div>+	my ($linenr, $remain, =
$off) =3D @_;<br></div><div>+<br></div><div>+	return ctx_block_get($linenr,=
 $remain, 0, &#39;(&#39;, &#39;)&#39;, $off);<br></div><div>+}<br></div><di=
v>+<br></div><div>+sub ctx_locate_comment {<br></div><div>+	my ($first_line=
, $end_line) =3D @_;<br></div><div>+<br></div><div>+	# Catch a comment on t=
he end of the line itself.<br></div><div>+	my ($current_comment) =3D ($rawl=
ines[$end_line - 1] =3D~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);<br></div><div>+	re=
turn $current_comment if (defined $current_comment);<br></div><div>+<br></d=
iv><div>+	# Look through the context and try and figure out if there is a<b=
r></div><div>+	# comment.<br></div><div>+	my $in_comment =3D 0;<br></div><d=
iv>+	$current_comment =3D &#39;&#39;;<br></div><div>+	for (my $linenr =3D $=
first_line; $linenr &lt; $end_line; $linenr++) {<br></div><div>+		my $line =
=3D $rawlines[$linenr - 1];<br></div><div>+		#warn &quot;=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 $line\n&quot;;<br></div><div>+		=
if ($linenr =3D=3D $first_line and $line =3D~ m@^.\s*\*@) {<br></div><div>+=
			$in_comment =3D 1;<br></div><div>+		}<br></div><div>+		if ($line =3D~ m@=
/\*@) {<br></div><div>+			$in_comment =3D 1;<br></div><div>+		}<br></div><d=
iv>+		if (!$in_comment &amp;&amp; $current_comment ne &#39;&#39;) {<br></di=
v><div>+			$current_comment =3D &#39;&#39;;<br></div><div>+		}<br></div><di=
v>+		$current_comment .=3D $line . &quot;\n&quot; if ($in_comment);<br></di=
v><div>+		if ($line =3D~ m@\*/@) {<br></div><div>+			$in_comment =3D 0;<br>=
</div><div>+		}<br></div><div>+	}<br></div><div>+<br></div><div>+	chomp($cu=
rrent_comment);<br></div><div>+	return($current_comment);<br></div><div>+}<=
br></div><div>+sub ctx_has_comment {<br></div><div>+	my ($first_line, $end_=
line) =3D @_;<br></div><div>+	my $cmt =3D ctx_locate_comment($first_line, $=
end_line);<br></div><div>+<br></div><div>+	##print &quot;LINE: $rawlines[$e=
nd_line - 1 ]\n&quot;;<br></div><div>+	##print &quot;CMMT: $cmt\n&quot;;<br=
></div><div>+<br></div><div>+	return ($cmt ne &#39;&#39;);<br></div><div>+}=
<br></div><div>+<br></div><div>+sub raw_line {<br></div><div>+	my ($linenr,=
 $cnt) =3D @_;<br></div><div>+<br></div><div>+	my $offset =3D $linenr - 1;<=
br></div><div>+	$cnt++;<br></div><div>+<br></div><div>+	my $line;<br></div>=
<div>+	while ($cnt) {<br></div><div>+		$line =3D $rawlines[$offset++];<br><=
/div><div>+		next if (defined($line) &amp;&amp; $line =3D~ /^-/);<br></div>=
<div>+		$cnt--;<br></div><div>+	}<br></div><div>+<br></div><div>+	return $l=
ine;<br></div><div>+}<br></div><div>+<br></div><div>+sub cat_vet {<br></div=
><div>+	my ($vet) =3D @_;<br></div><div>+	my ($res, $coded);<br></div><div>=
+<br></div><div>+	$res =3D &#39;&#39;;<br></div><div>+	while ($vet =3D~ /([=
^[:cntrl:]]*)([[:cntrl:]]|$)/g) {<br></div><div>+		$res .=3D $1;<br></div><=
div>+		if ($2 ne &#39;&#39;) {<br></div><div>+			$coded =3D sprintf(&quot;^=
%c&quot;, unpack(&#39;C&#39;, $2) + 64);<br></div><div>+			$res .=3D $coded=
;<br></div><div>+		}<br></div><div>+	}<br></div><div>+	$res =3D~ s/$/\$/;<b=
r></div><div>+<br></div><div>+	return $res;<br></div><div>+}<br></div><div>=
+<br></div><div>+my $av_preprocessor =3D 0;<br></div><div>+my $av_pending;<=
br></div><div>+my @av_paren_type;<br></div><div>+my $av_pend_colon;<br></di=
v><div>+<br></div><div>+sub annotate_reset {<br></div><div>+	$av_preprocess=
or =3D 0;<br></div><div>+	$av_pending =3D &#39;_&#39;;<br></div><div>+	@av_=
paren_type =3D (&#39;E&#39;);<br></div><div>+	$av_pend_colon =3D &#39;O&#39=
;;<br></div><div>+}<br></div><div>+<br></div><div>+sub annotate_values {<br=
></div><div>+	my ($stream, $type) =3D @_;<br></div><div>+<br></div><div>+	m=
y $res;<br></div><div>+	my $var =3D &#39;_&#39; x length($stream);<br></div=
><div>+	my $cur =3D $stream;<br></div><div>+<br></div><div>+	print &quot;$s=
tream\n&quot; if ($dbg_values &gt; 1);<br></div><div>+<br></div><div>+	whil=
e (length($cur)) {<br></div><div>+		@av_paren_type =3D (&#39;E&#39;) if ($#=
av_paren_type &lt; 0);<br></div><div>+		print &quot; &lt;&quot; . join(&#39=
;&#39;, @av_paren_type) .<br></div><div>+				&quot;&gt; &lt;$type&gt; &lt;$=
av_pending&gt;&quot; if ($dbg_values &gt; 1);<br></div><div>+		if ($cur =3D=
~ /^(\s+)/o) {<br></div><div>+			print &quot;WS($1)\n&quot; if ($dbg_values=
 &gt; 1);<br></div><div>+			if ($1 =3D~ /\n/ &amp;&amp; $av_preprocessor) {=
<br></div><div>+				$type =3D pop(@av_paren_type);<br></div><div>+				$av_p=
reprocessor =3D 0;<br></div><div>+			}<br></div><div>+<br></div><div>+		} e=
lsif ($cur =3D~ /^(\(\s*$Type\s*)\)/ &amp;&amp; $av_pending eq &#39;_&#39;)=
 {<br></div><div>+			print &quot;CAST($1)\n&quot; if ($dbg_values &gt; 1);<=
br></div><div>+			push(@av_paren_type, $type);<br></div><div>+			$type =3D =
&#39;C&#39;;<br></div><div>+<br></div><div>+		} elsif ($cur =3D~ /^($Type)\=
s*(?:$Ident|,|\)|\(|\s*$)/) {<br></div><div>+			print &quot;DECLARE($1)\n&q=
uot; if ($dbg_values &gt; 1);<br></div><div>+			$type =3D &#39;T&#39;;<br><=
/div><div>+<br></div><div>+		} elsif ($cur =3D~ /^($Modifier)\s*/) {<br></d=
iv><div>+			print &quot;MODIFIER($1)\n&quot; if ($dbg_values &gt; 1);<br></=
div><div>+			$type =3D &#39;T&#39;;<br></div><div>+<br></div><div>+		} elsi=
f ($cur =3D~ /^(\#\s*define\s*$Ident)(\(?)/o) {<br></div><div>+			print &qu=
ot;DEFINE($1,$2)\n&quot; if ($dbg_values &gt; 1);<br></div><div>*** 1791 LI=
NES SKIPPED ***<br></div><div><br></div></blockquote><div><br></div></div><=
/div></blockquote></div>

--0000000000006acd1f05f7bcca27--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfo8upPbGd5Ji3SQ4V9aGsTysxiuYZU4x6smjVQgOoArgg>