From 0824ef377f9cdfae13b2c702d1bc2b83f048c2d9 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 9 Dec 2022 20:32:09 -0500 Subject: [PATCH] wip --- test_regress/t/t_dist_docs_style.pl | 65 +++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 test_regress/t/t_dist_docs_style.pl diff --git a/test_regress/t/t_dist_docs_style.pl b/test_regress/t/t_dist_docs_style.pl new file mode 100755 index 000000000..0cda99082 --- /dev/null +++ b/test_regress/t/t_dist_docs_style.pl @@ -0,0 +1,65 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Primitive C++ style checker +# +# Copyright 2022 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(dist => 1); + +my $root = ".."; + +### Must trim output before and after our file list +my %files = %{get_source_files($root)}; + +foreach my $file (sort keys %files) { + my $filename = "$root/$file"; + next if !-f $filename; # git file might be deleted but not yet staged + next unless $file =~ /\.rst$/; + + my $contents = file_contents($filename); + + checkPattern($filename, $contents, + qr/.*(?{verbose}; + my %files; + foreach my $file (split /\s+/, $git_files) { + next if $file eq ''; + $files{$file} |= 1; + } + return \%files; +} + +sub checkPattern { + my $filename = shift; + my $contents = shift; + my $pattern = shift; + my $message = shift; + + my $offset = 0; + my $buffer = $contents; + while ($buffer =~ s/.*?^($pattern)//sm) { + my $lineno = offset_to_lineno($contents, $offset + $-[-1]); + $offset += $+[1]; + error("$filename:$lineno: $message"); + } +} + +sub offset_to_lineno { + my $contents = shift; + my $offset = shift; + my $count = (substr $contents, 0, $offset) =~ tr/\n//; + return $count + 1; +}