public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Rical Jasan <ricaljasan@pacific.net>
To: libc-alpha@sourceware.org
Cc: joseph@codesourcery.com, mtk.manpages@gmail.com, carlos@redhat.com
Subject: [PATCH v2 4/5] manual: Enforce header and standard requirements.
Date: Tue, 06 Dec 2016 10:55:00 -0000	[thread overview]
Message-ID: <20161206105525.21117-5-ricaljasan@pacific.net> (raw)
In-Reply-To: <20161206105525.21117-1-ricaljasan@pacific.net>

[-- Attachment #1: Type: text/plain, Size: 1365 bytes --]

	Introduces a new script, check-stds.pl, which examines the
	immediately preceding lines of entries requiring annotation
	for valid header and standard annotations.

	Only two classes of entries can currently be known to require
	annotation: @def*-commands and @item entries within @vtables.
	Note that summary.awk also indexes @vindex entries, but this
	script does not enforce any requirements upon them, as they
	are better addressed by reworking the documentation in more
	significant ways (than conversion of @vindexed @items in
	@tables to @items in @vtables, for example).

	Standards are essentially free-form, and headers must look
	like *.h, and multiple headers may not be comma-separated.

	The syntax comment in summary.awk is updated, and the new
	script is added to the Makefile.  It exits with error
	(printing any) in case of trouble, so this should help prevent
	new errors from creeping in.

	* manual/check-stds.pl: New file.  Check anything that we can
	know deserves header/standard annotation, and report errors.
	* manual/Makefile: Use check-stds.pl.
	* manual/summary.awk: Update comment about syntax.
---
 manual/Makefile      |   1 +
 manual/check-stds.pl | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++
 manual/summary.awk   |   3 +-
 3 files changed, 214 insertions(+), 1 deletion(-)
 create mode 100755 manual/check-stds.pl


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-manual-Enforce-header-and-standard-requirements.patch --]
[-- Type: text/x-patch; name="0004-manual-Enforce-header-and-standard-requirements.patch", Size: 5999 bytes --]

diff --git a/manual/Makefile b/manual/Makefile
index f2f694f..d6d8c27 100644
--- a/manual/Makefile
+++ b/manual/Makefile
@@ -85,6 +85,7 @@ $(objpfx)summary.texi: $(objpfx)stamp-summary ;
 $(objpfx)stamp-summary: summary.awk $(filter-out $(objpfx)summary.texi, \
 					$(texis-path))
 	$(SHELL) ./check-safety.sh $(filter-out $(objpfx)%, $(texis-path))
+	$(PERL) check-stds.pl $^
 	$(AWK) -f $^ | sort -t'\f' -df -k 1,1 | tr '\014' '\012' \
 		> $(objpfx)summary-tmp
 	$(move-if-change) $(objpfx)summary-tmp $(objpfx)summary.texi
diff --git a/manual/check-stds.pl b/manual/check-stds.pl
new file mode 100755
index 0000000..b4b7146
--- /dev/null
+++ b/manual/check-stds.pl
@@ -0,0 +1,211 @@
+#!/usr/bin/perl
+# Copyright (C) 2016 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+# Contributed by Rical Jasan <ricaljasan@pacific.net>, 2016.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+# Complement summary.awk by finding entries within the manual that
+# require header and standards @comments, ensuring they have them,
+# and verifying their syntax.  Also see summary.awk.
+
+use strict;
+use warnings;
+
+# Keep track of context.
+my @lines;
+my ($cur, $std, $hdr, $ctx) = (0, 1, 2, 3);
+
+# Error messages.
+my $missing_header = "Missing header.";
+my $missing_standard = "Missing standard.";
+
+# Accept files to check as args.
+my @texis = @ARGV;
+
+for (my $i=0; $i<@texis; $i++) {
+    # Probes is a special chapter...
+    if ($texis[$i] =~ /probes\.texi$/) {
+	splice(@texis, $i, 1);
+	last;
+    }
+}
+
+# @c-style comments aren't used.
+my $comment = qr/^\@comment /;
+# Strict check for header @comments, based on current practice.
+my $header = qr/${comment}(([\w\/]+\.h ?)+(\(optional\))?|\(none\))$/i;
+# Standards are free-form but do not contain @-commands.
+my $standard = qr/${comment}[^\@]+/;
+# All @def*-commands need annotation.
+my $def = qr/^\@def/;
+# Not all @items do; we'll know by context.
+my $item = qr/^\@itemx? /;
+# @items in @vtables must be annotated.
+my $vtable = qr/^\@vtable /;
+my $vtable_end = qr/^\@end vtable$/;
+# @tables must be recognized for recursion.
+my $table = qr/^\@table /;
+my $table_end = qr/\@end table$/;
+# Contexts we know need checking.
+my $table_or_list = qr/^\@v?table /;
+
+# For subsequent analysis.
+my %errors;
+
+# Global scope.
+my $input;
+
+for (@texis) {
+    open $input, '<', $_;
+    while ($lines[$cur] = <$input>)
+    {
+	if ($lines[$cur] =~ $def)
+	{
+	    &check_annotations();
+	}
+	elsif ($lines[$cur] =~ $table_or_list)
+	{
+	    &check_items();
+	}
+
+	&shuffle();
+    }
+    close $input;
+}
+
+if (%errors)
+{
+    &print_errors();
+    exit 1;
+}
+
+exit 0;
+
+sub shuffle
+{
+    $lines[$ctx] = $lines[$hdr] if $lines[$hdr];
+    $lines[$hdr] = $lines[$std] if $lines[$std];
+    $lines[$std] = $lines[$cur];
+}
+
+sub store_error
+{
+    push @{$errors{$_}}, {
+	errors => shift,
+	line => $lines[$cur],
+	standard => $lines[$std] ? $lines[$std] : undef,
+	header => $lines[$hdr] ? $lines[$hdr] : undef,
+	context => $lines[$ctx] ? $lines[$ctx] : undef,
+    };
+}
+
+sub check_annotations
+{
+    my @errors;
+
+    if (!$lines[$std] || $lines[$std] !~ $standard) {
+	push @errors, $missing_standard
+    }
+
+    if (!$lines[$hdr]) {
+	push @errors, $missing_header;
+    }
+    elsif ($lines[$hdr] !~ $header) {
+	if ($lines[$std] =~ $header) {
+	    push @errors, $missing_standard;
+	} else {
+	    push @errors, $missing_header;
+	}
+    }
+
+    &store_error(\@errors) if @errors;
+}
+
+sub check_items
+{
+    if ($lines[$cur] =~ $vtable)
+    {
+	&check_vtable();
+    }
+    elsif ($lines[$cur] =~ $table)
+    {
+	&check_table();
+    }
+}
+
+sub check_vtable
+{
+    &shuffle();
+    until (($lines[$cur] = <$input>) =~ $vtable_end)
+    {
+	# detect nested tables or lists.
+	if ($lines[$cur] =~ $table_or_list)
+	{
+	    &check_items();
+	}
+	# vtable item
+	elsif ($lines[$cur] =~ $item)
+	{
+	    &check_annotations();
+	}
+	elsif ($lines[$cur] =~ $def)
+	{
+	    &check_annotations();
+	}
+	&shuffle();
+    }
+}
+
+sub check_table
+{
+    &shuffle();
+    until (($lines[$cur] = <$input>) =~ $table_end) {
+	# detect nested tables/lists.
+	if ($lines[$cur] =~ $table_or_list)
+	{
+	    &check_items();
+	}
+	&shuffle();
+    }
+}
+
+sub print_errors
+{
+    for my $texi (sort keys %errors)
+    {
+	my $printed_texi = 0;
+
+	for (@{$errors{$texi}})
+	{
+	    if (!$printed_texi)
+	    {
+		print STDERR "****\nErrors detected in $texi:\n\n";
+		$printed_texi = 1;
+	    }
+	    print STDERR "----------------\n";
+	    for my $error (@{$_->{errors}})
+	    {
+		print STDERR "$error\n";
+	    }
+	    print STDERR "\n";
+	    print STDERR "C:$_->{context}" if $_->{context};
+	    print STDERR "H:$_->{header}" if $_->{header};
+	    print STDERR "S:$_->{standard}" if $_->{standard};
+	    print STDERR "L:$_->{line}";
+	    print STDERR "  ^^^^\n\n";
+	}
+    }
+}
diff --git a/manual/summary.awk b/manual/summary.awk
index 7f721e9..e6e0c49 100644
--- a/manual/summary.awk
+++ b/manual/summary.awk
@@ -17,9 +17,10 @@
 # <http://www.gnu.org/licenses/>.
 
 # This script recognizes sequences that look like:
-#	@comment HEADER.h
+#	@comment HEADER.h[ HEADER.h[...]]
 #	@comment STANDARD
 #	@def... ITEM | @item ITEM | @vindex ITEM
+# where STANDARD is essentially free-form.
 
 BEGIN { header = 0;
 nameword["@defun"]=1

  reply	other threads:[~2016-12-06 10:55 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06 10:55 [PATCH v2 0/5] Header & Standards Cleanup Rical Jasan
2016-12-06 10:55 ` Rical Jasan [this message]
2016-12-06 10:55 ` [PATCH v2 2/5] manual: Convert @tables of variables to @vtables Rical Jasan
2016-12-06 13:50   ` Zack Weinberg
2016-12-06 15:46   ` Joseph Myers
2016-12-07 15:18   ` Nix
2016-12-08  1:38     ` Rical Jasan
2016-12-21 10:08       ` Rical Jasan
2016-12-21 12:42         ` Joseph Myers
2016-12-06 10:55 ` [PATCH v2 1/5] manual: Refactor header and standards annotations Rical Jasan
2016-12-06 13:49   ` Zack Weinberg
2016-12-06 15:33   ` Joseph Myers
2016-12-19 10:37     ` Rical Jasan
2016-12-19 13:48       ` Joseph Myers
2017-02-07  6:46   ` Rical Jasan
2016-12-06 10:56 ` [PATCH v2 3/5] manual: Add new " Rical Jasan
2016-12-06 13:23   ` Zack Weinberg
2016-12-06 14:27     ` Andreas Schwab
2016-12-06 16:24     ` Joseph Myers
2016-12-06 19:23       ` Zack Weinberg
2016-12-06 21:42         ` Joseph Myers
2016-12-07 16:32   ` Joseph Myers
2016-12-08  2:56     ` Rical Jasan
2016-12-08 14:02       ` Joseph Myers
2016-12-12  9:01         ` Rical Jasan
2016-12-14 18:18           ` Joseph Myers
2016-12-14 23:30             ` Rical Jasan
2016-12-15  9:58               ` Rical Jasan
2016-12-15 13:01                 ` Joseph Myers
2017-02-07  5:13                   ` Rical Jasan
2017-02-07 16:41                     ` Joseph Myers
2017-02-08  8:50                       ` Rical Jasan
2017-02-08 13:52                         ` Joseph Myers
2017-02-12  6:01                           ` Rical Jasan
2017-04-04  3:58                             ` Rical Jasan
2017-04-04 11:26                               ` Joseph Myers
2017-04-05  3:08                                 ` Rical Jasan
2017-06-16 13:40                                   ` Zack Weinberg
2017-06-16  8:28     ` Rical Jasan
2016-12-06 11:42 ` [PATCH v2 5/5] manual: Clean up miscellaneous standards Rical Jasan
2017-05-16  9:55 ` [PATCH v3 0/7] manual: Header & Standards Cleanup Rical Jasan
2017-05-16  9:55   ` [PATCH v3 2/7] manual: Create empty placeholder macros for @standards Rical Jasan
2017-05-16  9:55   ` [PATCH v3 1/7] manual: Provide one-off standards conversion script Rical Jasan
2017-05-16  9:55   ` [PATCH v3 3/7] manual: Fix up invalid header and standards syntax Rical Jasan
2017-05-16 11:51     ` Joseph Myers
2017-05-17  4:49       ` Rical Jasan
2017-05-17 10:03         ` Joseph Myers
2017-05-18  8:10       ` Rical Jasan
2017-05-16 10:27   ` [PATCH v3 7/7] manual: Replace summary.awk with summary.pl Rical Jasan
2017-05-16 10:28   ` [PATCH v3 5/7] manual: Convert @tables of annotated @items to @vtables Rical Jasan
2017-05-16 11:53     ` Joseph Myers
2017-05-18  8:11       ` Rical Jasan
2017-05-16 10:28   ` [PATCH v3 6/7] manual: Convert header and standards @comments to @standards Rical Jasan
2017-05-16 10:29   ` [PATCH v3 4/7] manual: Refactor errno @comments Rical Jasan
2017-05-16 11:06     ` Joseph Myers
2017-05-17  4:44       ` Rical Jasan
2017-05-17 13:21         ` Zack Weinberg
2017-05-17 13:31           ` Zack Weinberg
2017-05-18  9:42           ` Rical Jasan
2017-05-18 12:32             ` Zack Weinberg
2017-05-19  9:46               ` Rical Jasan
2017-05-19 20:50                 ` Zack Weinberg
2017-05-19  6:20         ` Rical Jasan
2017-05-18  9:58       ` Rical Jasan
2017-05-19  9:33   ` [PATCH v4 0/5] manual: Header & Standards Cleanup Rical Jasan
2017-05-19  9:33     ` [PATCH v4 2/5] manual: Create empty placeholder macros for @standards Rical Jasan
2017-05-19 21:02       ` Zack Weinberg
2017-05-20  6:05         ` Rical Jasan
2017-05-19  9:34     ` [PATCH v4 1/5] manual: Provide one-off standards conversion script Rical Jasan
2017-05-19  9:34     ` [PATCH v4 5/5] manual: Replace summary.awk with summary.pl Rical Jasan
2017-05-19  9:34     ` [PATCH v4 3/5] manual: Convert errno @comments to new @errno macro Rical Jasan
2017-05-19 21:03       ` Zack Weinberg
2017-05-20  6:05         ` Rical Jasan
2017-05-19  9:36     ` [PATCH v4 4/5] manual: Convert header and standards @comments to @standards Rical Jasan
2017-05-19 21:05     ` [PATCH v4 0/5] manual: Header & Standards Cleanup Zack Weinberg
2017-05-22  9:03       ` Rical Jasan
2017-05-24 13:12         ` Rical Jasan
2017-05-24 13:29           ` Zack Weinberg
2017-05-26  5:01     ` [PATCH v5 0/3] " Rical Jasan
2017-05-26  5:01       ` [PATCH v5 0/3] manual: Header & Standards Cleanup [conversion script] Rical Jasan
2017-05-26  5:01       ` [PATCH v5 3/3] manual: Replace summary.awk with summary.pl Rical Jasan
2017-05-26  5:01       ` [PATCH v5 2/3] manual: Convert header and standards @comments to @standards Rical Jasan
2017-05-26  5:01       ` [PATCH v5 1/3] manual: Create empty placeholder macros for @standards Rical Jasan
2017-05-31  9:23       ` [PATCH v5 0/3] manual: Header & Standards Cleanup Rical Jasan
2017-06-08 11:46         ` [PING] " Rical Jasan
2017-06-08 13:41           ` Zack Weinberg
2017-06-09  2:31             ` Rical Jasan
2017-06-15  8:47               ` Rical Jasan
2017-06-15  8:32           ` Rical Jasan
2017-06-15 18:01             ` Joseph Myers
2017-06-16  4:38               ` Rical Jasan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161206105525.21117-5-ricaljasan@pacific.net \
    --to=ricaljasan@pacific.net \
    --cc=carlos@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=mtk.manpages@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).