From: Rical Jasan <ricaljasan@pacific.net>
To: libc-alpha@sourceware.org
Cc: Joseph Myers <joseph@codesourcery.com>,
Carlos O'Donell <carlos@redhat.com>,
Michael Kerrisk <mtk.manpages@gmail.com>
Subject: [PATCH v3 1/7] manual: Provide one-off standards conversion script.
Date: Tue, 16 May 2017 09:55:00 -0000 [thread overview]
Message-ID: <f065cd7fab90b7cdade2d3f755e073c2a589f3d2.1494920105.git.ricaljasan@pacific.net> (raw)
In-Reply-To: <cover.1494920105.git.ricaljasan@pacific.net>
[-- Attachment #1: Type: text/plain, Size: 393 bytes --]
This is an ephemeral script used to automate conversion of the
@comment-based header and standards annotations to the @standards
macro.
* manual/convert-stds.pl: New file. Convert header and
standards @comments to @standards.
---
manual/convert-stds.pl | 186 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 186 insertions(+)
create mode 100755 manual/convert-stds.pl
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-manual-Provide-one-off-standards-conversion-script.patch --]
[-- Type: text/x-patch; name="0001-manual-Provide-one-off-standards-conversion-script.patch", Size: 5640 bytes --]
diff --git a/manual/convert-stds.pl b/manual/convert-stds.pl
new file mode 100755
index 0000000000..d67354a850
--- /dev/null
+++ b/manual/convert-stds.pl
@@ -0,0 +1,186 @@
+#!/usr/bin/perl
+# Copyright (C) 2017 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+# Contributed by Rical Jasan <ricaljasan@pacific.net>, 2017.
+
+# 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/>.
+
+# This is a one-off script, used to convert existing header and
+# standards annotations embedded in @comments to @standards macros.
+# Buffers each input file, making adjustments as necessary, then
+# replaces the file with the reannotated contents.
+
+use strict;
+use warnings;
+
+# Files to convert.
+my @texis = @ARGV;
+
+# Track context.
+my @lines;
+my ($c, $s, $h); # Cur, Std, Hdr indices.
+
+# Regexes.
+my $cmt = qr/\@comment /;
+my $hdr = qr/^${cmt}(([\w\/]+\.h,? ?)+(\(optional\))?|\(none\))$/i;
+my $std = qr/^${cmt}[^\@]+/;
+my $def = qr/^\@def/;
+my $itm = qr/^\@itemx? /;
+my $dix = qr/^\@(def\S+|item)x /;
+my $stm = qr/\@standards/;
+my $stx = qr/^${stm}x\{/;
+
+# Convert.
+for (@texis) {
+ open my $input, '<', $_ or die "open $_: $!";
+ while ($lines[@lines] = <$input>) {
+ ($c, $s, $h) = (@lines-1, @lines-2, @lines-3);
+ if ($lines[$c] =~ $def || $lines[$c] =~ $itm)
+ {
+ # Convert @comments to @standards.
+ my @standards = &convert($lines[$h], $lines[$s],
+ $lines[$c] =~ $dix
+ ? &get_elem($lines[$c]) : undef);
+
+ # Unannotated, but beware partial @*x chains.
+ next if ! @standards && $lines[$s] !~ /^${stm}/;
+
+ # Splice out the @comment(s).
+ if ($lines[$h] =~ $hdr) {
+ splice @lines, $h, 1; --$s;
+ }
+ if ($lines[$s] =~ $std || $lines[$s] =~ $hdr) {
+ splice @lines, $s, 1;
+ }
+
+ # Relocate preceding @standards.
+ my $i = my $j = $#lines-1;
+ while ($lines[$i] =~ /^${stm}/) {
+ splice @standards, 0, 0, $lines[$i--];
+ }
+ splice @lines, $i+1, $j-$i;
+
+ # Convert @standards in @*x chains.
+ if ($standards[$#standards] =~ $stx && $standards[0] !~ $stx) {
+ my $e = &get_elem($lines[$#lines-1]);
+ $i = 0;
+ while ($standards[$i] !~ $stx) {
+ $standards[$i++] =~ s/^(${stm})\{(.*)/$1x{$e, $2/;
+ }
+ }
+ # Partial @*x chain w/ only the first annotation.
+ elsif (@standards == 1 && $lines[$#lines] =~ $dix
+ && $standards[0] !~ $stx)
+ {
+ $i = $#lines;
+ --$i while $lines[$i] =~ $dix;
+ my $e = &get_elem($lines[$i]);
+ $standards[0] =~ s/^(${stm})\{(.*)/$1x{$e, $2/;
+ }
+
+ # Append the @standards.
+ push @lines, @standards;
+ }
+ }
+ close $input or die "close $_: $!";
+ splice @lines, -1;
+ open my $output, '>', "$_" or die "open $_: $!";
+ print $output @lines;
+ close $output or die "close $_: $!";
+ @lines=();
+}
+
+# Returns the annotated element from an @def or @item line.
+sub get_elem
+{
+ my @toks = split /\s+/, shift;
+ my $i = 0;
+ for (; $i<@toks; $i++) {
+ last if $toks[$i] =~ /^\(/;
+ }
+ return $toks[$i-1];
+}
+
+# Converts header and standards @comments to an array of @standards.
+# The optional annotated element argument is used to determine whether
+# @standards or @standardsx macros are generated.
+sub convert
+{
+ my ($hl, $sl, $el) = @_;
+ my (@hdrs, @stds);
+ my ($i, $j, @arr);
+
+ # Useful routine to split a header or standard line. Uses a
+ # little magic to distinguish the two where it counts.
+ my $split = sub {
+ my ($line, $ish) = @_;
+ $line =~ s/^${cmt}//;
+ chomp $line;
+ if ($ish) {split /\s+/, $line}
+ else {split /,\s+/, $line}
+ };
+
+ # Split the header and standards lines, handling cases of partial
+ # or absent annotations.
+ if ($hl =~ $hdr && $sl =~ $std) {
+ @hdrs = $split->($hl, 1);
+ @stds = $split->($sl, 0);
+ } elsif ($sl =~ $hdr) {
+ @hdrs = $split->($sl, 0);
+ @stds = ('???');
+ } elsif ($sl =~ $std) {
+ @hdrs = ('???');
+ @stds = $split->($sl, 0);
+ } else {
+ return (); # Unannotated.
+ }
+
+ # Append "(optional)" to the preceding header, which would have
+ # incorrectly split on the intervening whitespace.
+ for ($i=0; $i<@hdrs; ++$i) {
+ if ($hdrs[$i] eq '(optional)') {
+ $hdrs[$i-1] .= " $hdrs[$i]";
+ splice @hdrs, $i--, 1;
+ }
+ }
+
+ # Ensure we have equal length, paired, and populated header and
+ # standards arrays. Propagates the last header or standard; not
+ # necessarily a convention, just a coping strategy.
+ if (@hdrs != @stds) {
+ if (@hdrs < @stds) {
+ $i = $#hdrs;
+ for ($j=@hdrs; $j<@stds; ++$j) {
+ $hdrs[$j] = $hdrs[$i];
+ }
+ } else {
+ $i = $#stds;
+ for ($j=@stds; $j<@hdrs; ++$j) {
+ $stds[$j] = $stds[$i];
+ }
+ }
+ }
+
+ # Generate the list of @standards.
+ for ($i=0; $i<@hdrs; ++$i) {
+ if ($el) {
+ push @arr, "\@standardsx{$el, $stds[$i], $hdrs[$i]}\n";
+ } else {
+ push @arr, "\@standards{$stds[$i], $hdrs[$i]}\n";
+ }
+ }
+
+ return @arr;
+}
next prev parent reply other threads:[~2017-05-16 9: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 ` [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:55 ` [PATCH v2 4/5] manual: Enforce header and standard requirements Rical Jasan
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:56 ` [PATCH v2 3/5] manual: Add new header and standards annotations 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 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 9:55 ` Rical Jasan [this message]
2017-05-16 9:55 ` [PATCH v3 2/7] manual: Create empty placeholder macros for @standards 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 6/7] manual: Convert header and standards @comments to @standards 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: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 5/5] manual: Replace summary.awk with summary.pl 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 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 2/3] manual: Convert header and standards @comments to @standards 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 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=f065cd7fab90b7cdade2d3f755e073c2a589f3d2.1494920105.git.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).