Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp971239ybi; Fri, 14 Jun 2019 06:31:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwL1OHHysW7LMG/jp6ZOZ+I4rt8t8Ft6Xr1aSdE/ItsMeL6DNoHdeV2Mp9g8uV5hdGVd0Px X-Received: by 2002:a63:231c:: with SMTP id j28mr35301068pgj.430.1560519065848; Fri, 14 Jun 2019 06:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560519065; cv=none; d=google.com; s=arc-20160816; b=S85FGW5JnlM7xwJqhxJjq25FReVT6aSBntgXgj+1FuZsQl0WzyJA43+nkqiTl6uRgF qxR65+SdLf+nKZzApuFrU7J9Vyxy6E0zaPxq+uTxwpM6llTaWOoF1UuefW98OzM5IGEV GHxT1caQRkn6JHTc+aMqnEVIsQQ7pY7kitE28MiQx6mGNzUIoyHvCBoxopcAT71DfECL lJsRoK04gZO97y6FOh79O52F9zkVYd7sMbMiSC8qi5PeZYlvcdA8fM8dNJ9/jYttBQKw +P5SmAahSr7WP/zCE3friZlRDp/Xiev5AYbUsNDTawC9asObLrqLtjEerKfsAnh0fOA1 liBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from; bh=efKHyvA6PaMAj4SQ6JlOuaDJi5bLq1aeJu1YC6e6Uno=; b=RanrVKiCx5MmUppdUk9d49N59XRLpV1/uD2sJC1Nt+eHw9UX/K2DbKU6A8j5Nh0Lt+ 5Xf9tQySrPi0i3hgUFAWSwYeKzLAmLfJtJNhKvuuFkZOTmRdcbSQPdkTcLSy8JncqNqn uQ8vRPBg7bKUVe0hXqvpLBEymc12kC0Jb+TfpVtsfAg03NMy5/O7aH6QsDtv9Ul5/bSU QQFTcXUWANzebSCpRiucIPi3k0/xXgEHb0h3xDMlEexvMCPRgFwAeZGGKOVERbtU5l9Q LrtVRerkYH1yHQf9PgdszfYh0z+++mqm0oTDsw+2paV3VmHxOXY0zRkiGBQlSdELZ8NP cHGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s125si2608344pgs.124.2019.06.14.06.30.49; Fri, 14 Jun 2019 06:31:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728121AbfFNN3B (ORCPT + 99 others); Fri, 14 Jun 2019 09:29:01 -0400 Received: from mga17.intel.com ([192.55.52.151]:23818 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727729AbfFNN3B (ORCPT ); Fri, 14 Jun 2019 09:29:01 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jun 2019 06:29:00 -0700 X-ExtLoop1: 1 Received: from jnikula-mobl3.fi.intel.com (HELO localhost) ([10.237.66.150]) by fmsmga001.fm.intel.com with ESMTP; 14 Jun 2019 06:28:58 -0700 From: Jani Nikula To: Mauro Carvalho Chehab , Linux Doc Mailing List , Greg Kroah-Hartman Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Jonathan Corbet , Mauro Carvalho Chehab Subject: Re: [PATCH 05/14] scripts: add an script to parse the ABI files In-Reply-To: <196fb3c497546f923bf5d156c3fddbe74a4913bc.1560477540.git.mchehab+samsung@kernel.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <196fb3c497546f923bf5d156c3fddbe74a4913bc.1560477540.git.mchehab+samsung@kernel.org> Date: Fri, 14 Jun 2019 16:31:56 +0300 Message-ID: <87r27wuwc3.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Jun 2019, Mauro Carvalho Chehab wrote: > From: Mauro Carvalho Chehab > > Add a script to parse the Documentation/ABI files and produce > an output with all entries inside an ABI (sub)directory. > > Right now, it outputs its contents on ReST format. It shouldn't > be hard to make it produce other kind of outputs, since the ABI > file parser is implemented in separate than the output generator. Hum, or just convert the ABI files to rst directly. BR, Jani. > > Signed-off-by: Mauro Carvalho Chehab > Signed-off-by: Mauro Carvalho Chehab > --- > scripts/get_abi.pl | 212 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 212 insertions(+) > create mode 100755 scripts/get_abi.pl > > diff --git a/scripts/get_abi.pl b/scripts/get_abi.pl > new file mode 100755 > index 000000000000..f7c9944a833c > --- /dev/null > +++ b/scripts/get_abi.pl > @@ -0,0 +1,212 @@ > +#!/usr/bin/perl > + > +use strict; > +use Pod::Usage; > +use Getopt::Long; > +use File::Find; > +use Fcntl ':mode'; > + > +my $help; > +my $man; > +my $debug; > + > +GetOptions( > + "debug|d+" => \$debug, > + 'help|?' => \$help, > + man => \$man > +) or pod2usage(2); > + > +pod2usage(1) if $help; > +pod2usage(-exitstatus => 0, -verbose => 2) if $man; > + > +pod2usage(2) if (scalar @ARGV != 1); > + > +my ($prefix) = @ARGV; > + > +require Data::Dumper if ($debug); > + > +my %data; > + > +# > +# Displays an error message, printing file name and line > +# > +sub parse_error($$$$) { > + my ($file, $ln, $msg, $data) = @_; > + > + print STDERR "file $file#$ln: $msg at\n\t$data"; > +} > + > +# > +# Parse an ABI file, storing its contents at %data > +# > +sub parse_abi { > + my $file = $File::Find::name; > + > + my $mode = (stat($file))[2]; > + return if ($mode & S_IFDIR); > + return if ($file =~ m,/README,); > + > + my $name = $file; > + $name =~ s,.*/,,; > + > + my $type = $file; > + $type =~ s,.*/(.*)/.*,$1,; > + > + my $what; > + my $new_what; > + my $tag; > + my $ln; > + > + print STDERR "Opening $file\n" if ($debug > 1); > + open IN, $file; > + while() { > + $ln++; > + if (m/^(\S+):\s*(.*)/i) { > + my $new_tag = lc($1); > + my $content = $2; > + > + if (!($new_tag =~ m/(what|date|kernelversion|contact|description|users)/)) { > + if ($tag eq "description") { > + $data{$what}->{$tag} .= "\n$content";; > + $data{$what}->{$tag} =~ s/\n+$//; > + next; > + } else { > + parse_error($file, $ln, "tag '$tag' is invalid", $_); > + } > + } > + > + if ($new_tag =~ m/what/) { > + if ($tag =~ m/what/) { > + $what .= ", " . $content; > + } else { > + $what = $content; > + $new_what = 1; > + } > + $tag = $new_tag; > + next; > + } > + > + $tag = $new_tag; > + > + if ($new_what) { > + $new_what = 0; > + > + $data{$what}->{type} = $type; > + $data{$what}->{file} = $name; > + print STDERR "\twhat: $what\n" if ($debug > 1); > + } > + > + if (!$what) { > + parse_error($file, $ln, "'What:' should come first:", $_); > + next; > + } > + $data{$what}->{$tag} = $content; > + next; > + } > + > + # Silently ignore any headers before the database > + next if (!$tag); > + > + if (m/^\s*(.*)/) { > + $data{$what}->{$tag} .= "\n$1"; > + $data{$what}->{$tag} =~ s/\n+$//; > + next; > + } > + > + # Everything else is error > + parse_error($file, $ln, "Unexpected line:", $_); > + } > + close IN; > +} > + > +# Outputs the output on ReST format > +sub output_rest { > + foreach my $what (sort keys %data) { > + my $type = $data{$what}->{type}; > + my $file = $data{$what}->{file}; > + > + my $w = $what; > + $w =~ s/([\(\)\_\-\*\=\^\~\\])/\\$1/g; > + > + print "$w\n\n"; > + print "- defined on file $file (type: $type)\n\n::\n\n"; > + > + my $desc = $data{$what}->{description}; > + $desc =~ s/^\s+//; > + > + # Remove title markups from the description, as they won't work > + $desc =~ s/\n[\-\*\=\^\~]+\n/\n/g; > + > + # put everything inside a code block > + $desc =~ s/\n/\n /g; > + > + > + if (!($desc =~ /^\s*$/)) { > + print " $desc\n\n"; > + } else { > + print " DESCRIPTION MISSING\n\n"; > + } > + } > +} > + > +# > +# Parses all ABI files located at $prefix dir > +# > +find({wanted =>\&parse_abi, no_chdir => 1}, $prefix); > + > +print STDERR Data::Dumper->Dump([\%data], [qw(*data)]) if ($debug); > + > +# > +# Outputs an ReST file with the ABI contents > +# > +output_rest > + > + > +__END__ > + > +=head1 NAME > + > +abi_book.pl - parse the Linux ABI files and produce a ReST book. > + > +=head1 SYNOPSIS > + > +B [--debug] ] > + > +=head1 OPTIONS > + > +=over 8 > + > +=item B<--debug> > + > +Put the script in verbose mode, useful for debugging. Can be called multiple > +times, to increase verbosity. > + > +=item B<--help> > + > +Prints a brief help message and exits. > + > +=item B<--man> > + > +Prints the manual page and exits. > + > +=back > + > +=head1 DESCRIPTION > + > +Parse the Linux ABI files from ABI DIR (usually located at Documentation/ABI) > +and produce a ReST book containing the Linux ABI. > + > +=head1 BUGS > + > +Report bugs to Mauro Carvalho Chehab > + > +=head1 COPYRIGHT > + > +Copyright (c) 2016 by Mauro Carvalho Chehab . > + > +License GPLv2: GNU GPL version 2 . > + > +This is free software: you are free to change and redistribute it. > +There is NO WARRANTY, to the extent permitted by law. > + > +=cut -- Jani Nikula, Intel Open Source Graphics Center