[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp .cvsignore Makefile.am Texinfo/Conve...
From: |
Patrice Dumas |
Subject: |
texinfo/tp .cvsignore Makefile.am Texinfo/Conve... |
Date: |
Sun, 15 Jan 2012 23:38:22 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 12/01/15 23:38:22
Modified files:
tp : .cvsignore Makefile.am
tp/Texinfo/Convert: TextContent.pm
Added files:
tp : texi_sort_elements_count.pl
Log message:
A new script to dump out a list of nodes sorted by the number of
lines (or words) they contain.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/.cvsignore?cvsroot=texinfo&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Makefile.am?cvsroot=texinfo&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi_sort_elements_count.pl?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/TextContent.pm?cvsroot=texinfo&r1=1.1&r2=1.2
Patches:
Index: .cvsignore
===================================================================
RCS file: /sources/texinfo/texinfo/tp/.cvsignore,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- .cvsignore 14 Jan 2012 13:28:52 -0000 1.6
+++ .cvsignore 15 Jan 2012 23:38:22 -0000 1.7
@@ -6,6 +6,7 @@
blib
pm_to_blib
texi2any
+texi_sort_elements_count
po
po_document
texi2any-perl
Index: Makefile.am
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Makefile.am,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- Makefile.am 15 Jan 2012 20:51:14 -0000 1.26
+++ Makefile.am 15 Jan 2012 23:38:22 -0000 1.27
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.26 2012/01/15 20:51:14 pertusus Exp $
+# $Id: Makefile.am,v 1.27 2012/01/15 23:38:22 pertusus Exp $
# Makefile.am for texinfo/tp.
#
# Copyright 2011 Free Software Foundation, Inc.
@@ -20,6 +20,7 @@
SUBDIRS = . tests
bin_SCRIPTS = texi2any
+noinst_SCRIPTS = texi_sort_elements_count
do_subst = sed \
-e 's,address@hidden@],$(PACKAGE_VERSION),g' \
@@ -38,6 +39,10 @@
$(do_subst) $(srcdir)/$< >$@
chmod a+x $@
+texi_sort_elements_count: texi_sort_elements_count.pl
$(top_builddir)/config.status
+ $(do_subst) $(srcdir)/$< >$@
+ chmod a+x $@
+
makeinfo: texi2any
rm -f $@
-$(LN_S) texi2any $@
@@ -168,6 +173,7 @@
EXTRA_DIST = \
texi2any.pl \
+ texi_sort_elements_count.pl \
$(test_results) \
$(test_files) \
$(tp_tests) \
Index: Texinfo/Convert/TextContent.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/TextContent.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Texinfo/Convert/TextContent.pm 15 Jan 2012 20:51:14 -0000 1.1
+++ Texinfo/Convert/TextContent.pm 15 Jan 2012 23:38:22 -0000 1.2
@@ -1,6 +1,6 @@
# TextContent.pm: return the text contents stripped of commands
#
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2012 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Index: texi_sort_elements_count.pl
===================================================================
RCS file: texi_sort_elements_count.pl
diff -N texi_sort_elements_count.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ texi_sort_elements_count.pl 15 Jan 2012 23:38:22 -0000 1.1
@@ -0,0 +1,200 @@
+#! /usr/bin/perl -w
+
+# texi_sort_elements_count: sort elements based on words or line counts.
+#
+# Copyright 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Original author: Patrice Dumas <address@hidden>
+
+
+use strict;
+
+use Getopt::Long qw(GetOptions);
+
+Getopt::Long::Configure("gnu_getopt");
+
+BEGIN
+{
+ my $texinfolibdir = '@datadir@/@PACKAGE@';
+ unshift @INC, ($texinfolibdir)
+ if ($texinfolibdir ne ''
+ and $texinfolibdir ne '@' .'datadir@/@PACKAGE'.'@');
+}
+
+use Texinfo::Parser;
+use Texinfo::Structuring;
+use Texinfo::Convert::TextContent;
+
+my $configured_version = '@PACKAGE_VERSION@';
+$configured_version = $Texinfo::Parser::VERSION
+ if ($configured_version eq '@' . 'PACKAGE_VERSION@');
+
+my $real_command_name = $0;
+$real_command_name =~ s/.*\///;
+$real_command_name =~ s/\.pl$//;
+
+
+
+my $force = 0;
+my $use_sections = 0;
+my $count_words = 0;
+my $no_warn = 0;
+
+# placeholder for future i18n.
+sub __($)
+{
+ return $_[0];
+}
+
+my $result_options = Getopt::Long::GetOptions (
+ 'help|h' => sub { print_help(); exit 0; },
+ 'version|V' => sub {print "$real_command_name $configured_version\n\n";
+ printf __("Copyright (C) %s Free Software Foundation, Inc.
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.\n"), '2012';
+ exit 0;},
+ 'force' => \$force,
+ 'use-sections!' => \$use_sections,
+ 'count-words!' => \$count_words,
+ 'no-warn' => \$no_warn,
+);
+
+exit 1 if (!$result_options);
+
+my @input_files = @ARGV;
+# use STDIN if not a tty, like makeinfo does
address@hidden = ('-') if (!scalar(@input_files) and !-t STDIN);
+
+die sprintf(__("%s: missing file argument.\n"), $real_command_name)
+ .sprintf(__("Try `%s --help' for more information.\n"), $real_command_name)
+ unless (scalar(@input_files) >= 1);
+
+
+if (scalar(@input_files) > 1) {
+ warn sprintf(__("%s: superfluous file arguments.\n"), $real_command_name);
+}
+
+my $file = shift @input_files;
+
+sub print_help()
+{
+ print STDERR sprintf(__("Usage: %s [OPTION]... TEXINFO-FILE...
+
+Dump out a list of elements sorted by the number of lines (or words)
+they contain after removal of address@hidden
+
+Options:
+ --count-words count words instead of lines.
+ --force keep on even if the Texinfo file parsing failed.
+ --help display this help and exit.
+ --no-warn suppress warnings (but not errors).
+ --use-sections use sections as elements instead of nodes.
+ --version display version information and exit.
+"), $real_command_name);
+}
+
+if (!defined($file)) {
+ print_help();
+ exit 1;
+}
+
+sub _exit($)
+{
+ my $error_count = shift;
+ exit (1) if ($error_count and !$force);
+}
+
+sub handle_errors($$)
+{
+ my $self = shift;
+ my $error_count = shift;
+ my ($errors, $new_error_count) = $self->errors();
+ $error_count += $new_error_count if ($new_error_count);
+ foreach my $error_message (@$errors) {
+ warn $error_message->{'error_line'} if ($error_message->{'type'} eq 'error'
+ or !$no_warn);
+ }
+
+ _exit($error_count);
+ return $error_count;
+}
+
+my $error_count = 0;
+my $parser = Texinfo::Parser::parser();
+my $tree = $parser->parse_texi_file($file);
+
+if (!defined($tree)) {
+ handle_errors($parser, $error_count);
+ exit (1);
+}
+
+my $converter_options = {};
+$converter_options->{'parser'} = $parser;
+my $converter = Texinfo::Convert::TextContent->converter($converter_options);
+my $elements;
+if ($use_sections) {
+ $elements = Texinfo::Structuring::split_by_section($tree);
+} else {
+ $elements = Texinfo::Structuring::split_by_node($tree);
+}
+
+if (!$elements) {
+ @$elements = [ $tree ];
+} elsif (scalar(@$elements) >= 1
+ and (!$elements->[0]->{'extra'}->{'node'}
+ and !$elements->[0]->{'extra'}->{'section'})) {
+ shift @$elements;
+}
+
+my $max_count = 0;
+my @name_counts_array;
+foreach my $element (@$elements) {
+ my $name = 'UNNAMED element';
+ if ($element->{'extra'}->{'node'} or $element->{'extra'}->{'section'}) {
+ my $command = $element->{'extra'}->{'element_command'};
+ if ($command->{'cmdname'} eq 'node') {
+ $name = $converter->convert_tree({'contents'
+ => $command->{'extra'}->{'nodes_manuals'}->[0]->{'node_content'}});
+ } else {
+ $name = "address@hidden>{'cmdname'}
".$converter->convert_tree($command->{'args'}->[0]);
+ }
+ }
+ chomp($name);
+ my $count;
+ my $element_content = $converter->convert($element);
+ if ($count_words) {
+ my @res = split /\W+/, $element_content;
+ $count = scalar(@res);
+ } else {
+ my @res = split /^/, $element_content;
+ $count = scalar(@res);
+ }
+ push @name_counts_array, [$count, $name];
+ if ($count > $max_count) {
+ $max_count = $count;
+ }
+}
+
+my @sorted_name_counts_array = sort {$a->[0] <=> $b->[0]} @name_counts_array;
address@hidden = reverse(@sorted_name_counts_array);
+
+my $max_length = length($max_count);
+foreach my $sorted_count (@sorted_name_counts_array) {
+ print STDOUT sprintf("%${max_length}d $sorted_count->[1]\n",
$sorted_count->[0]);
+}
+
+1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp .cvsignore Makefile.am Texinfo/Conve...,
Patrice Dumas <=