[xml/sgml-commit] [SCM] linuxdoc-tools package for Debian. branch, experimental, updated. debian/0.9.60-9-g24eee79
Agustin Martin Domingo
agmartin at debian.org
Sun Apr 26 23:44:01 UTC 2009
The following commit has been merged in the experimental branch:
commit 24eee797a642ef00e11175c219d0f255fa2acd32
Author: Agustin Martin Domingo <agmartin at debian.org>
Date: Mon Apr 27 01:44:46 2009 +0200
Remove info-postASP.awk. Use instead new InfoUtils.pm written from scratch.
diff --git a/lib/filters/info-postASP.awk b/lib/filters/info-postASP.awk
deleted file mode 100644
index 5ece179..0000000
--- a/lib/filters/info-postASP.awk
+++ /dev/null
@@ -1,177 +0,0 @@
-
-function cut(s) {
- while ((substr(s,1,1)==" ")||(substr(s,1,1)=="\t"))
- s=substr(s,2,length(s)-1);
- while ((substr(s,length(s),1)==" ")||(substr(s,length(s),1)=="\t"))
- s=substr(s,1,length(s)-1);
- return s;
-}
-
-function rest(n)
-{
- save = $0;
- $0 = cut($0);
- for (i=0; i<n-1; i++)
- $0 = cut(substr($0,length($1)+1,length($0)));
- val = $0;
- $0 = save;
- return val;
-}
-
-function fill(s,l)
-{
- while ( length(s) < l )
- s = s " ";
- return s;
-}
-
-# entrytext: Section full name (Title shown, not having label entity)
-# info format does not allow variables, braces, dots or commas here.
-# nodename: Section or reference node name (what will apear in menus and
-# will be used in labels). Besides things not accepted in entrytext,
-# info format does not accept here any of colons, semicolons
-
-# Sanitize section full names
-function conv(entrytext)
-{
- gsub( "@[A-Za-z][A-Za-z0-9]*", "", entrytext );
- gsub( "{", "", entrytext );
- gsub( "}", "", entrytext );
- gsub( ",", "", entrytext );
- gsub( /\./, "-", entrytext );
- gsub( " +", " ", entrytext );
- return entrytext;
-}
-
-# Sanitize Menu section node names. Above function should be applied first
-function cleannodename (nodename)
-{
- gsub( ":", "", nodename );
- gsub( ";", "", nodename );
- return nodename;
-}
-
-BEGIN {
- curmenu=0;
- curlevel=0;
- menustack[curlevel]=0;
- count[menustack[curlevel]]=0;
-}
-
-NR == 2 {
- print "@c %** START OF HEADER";
- print "@setfilename " INFO;
- print "@c %** END OF HEADER";
-}
-
-{
- if ( $1=="@SUB" ) {
- # Build node menus for further use
- entrytext = conv(rest(2));
- if ( cut(entrytext)=="" ) {
- getline;
- if ( $1=="@LABEL" ) {
- tmp = $2;
- getline;
- entrytext = $0;
- labels[tmp] = entrytext;
- } else {
- entrytext = $0;
- }
- }
-
- nodename = cleannodename(entrytext);
- entry = fill("* " nodename "::",24);
-
- if ( firstnode=="" ) firstnode=entrytext;
- menuentry[menustack[curlevel] count[menustack[curlevel]]] = entry;
- count[menustack[curlevel]]++;
-
- curlevel++;
- curmenu++;
- menustack[curlevel] = curmenu;
- count[menustack[curlevel]]=0;
- }
- else if ( $1=="@ENDSUB" ) {
- curlevel--;
- }
- else if ( $1=="@LABEL" ) {
- labels[$2] = entrytext;
- }
- else if ( $1=="@title" ) {
- title = rest(2);
- }
- else if ( $1=="@subtitle" ) {
- subtitle = rest(2);
- }
- else if ( $1=="@author" ) {
- author = rest(2);
- }
-}
-
-END {
- close(FILENAME);
-
- curmenu=0;
- curlevel=0;
- firstsec=1;
-
- # Put node menus and references in the right place
- while ( getline < FILENAME )
- {
- if ( $1=="@TOP" ) {
- print "@node top";
- print "@top " title;
- print "@example";
- print author;
- print subtitle;
- print "@end example";
- }
- else if ( ( $1=="@title" ) || ( $1=="@subtitle" ) || ( $1=="@author" ) ||
- ( $1=="@LABEL" ) )
- {
- }
- else if ( $1=="@REF" ) {
- print "@ref{" cleannodename(labels[$2]) "}";
- }
- else if ( $1=="@SUB" ) {
- if ( firstsec==1 ) {
- if ( count[menustack[curlevel]] ) {
- print "@menu";
- for (i=0; i<count[menustack[curlevel]]; i++)
- print menuentry[menustack[curlevel] i];
- print "@end menu";
- }
- }
-
- s = conv(rest(2));
- if ( s=="" ) {
- getline < FILENAME;
- if ( $1=="@LABEL" ) {
- getline < FILENAME;
- s = $0;
- } else {
- s = $0;
- }
- }
-
- snode = cleannodename(s);
- print "@node " snode;
-
- if ( curlevel==0 ) print "@chapter " s;
- else if ( curlevel==1 ) print "@section " s;
- else if ( curlevel==2 ) print "@subsection " s;
- else print "@subsubsection " s;
-
- curlevel++;
- curmenu++;
- menustack[curlevel] = curmenu;
- firstsec=1;
- }
- else if ( $1=="@ENDSUB" ) {
- curlevel--;
- firstsec=0;
- }
- else print;
- }
-}
diff --git a/lib/fmt/fmt_info.pl b/lib/fmt/fmt_info.pl
index ce0f73d..5e841f0 100644
--- a/lib/fmt/fmt_info.pl
+++ b/lib/fmt/fmt_info.pl
@@ -18,7 +18,7 @@ use Text::EntityMap;
use LinuxDocTools::CharEnts;
use LinuxDocTools::Lang;
use LinuxDocTools::Vars;
-use LinuxDocTools::Utils qw(create_temp);
+use LinuxDocTools::InfoUtils qw{info_process_texi};
my $info = {};
$info->{NAME} = "info";
@@ -108,20 +108,18 @@ $info->{postASP} = sub {
my $msgheader = "fmt_info::postASP";
my $fileinfo = "info file generated after $global->{origfile} by means of linuxdoc-tools";
- my $awk = $main::progs->{AWK};
- my $awkfilter = "$main::DataDir" . "/filters/info-postASP.awk";
- my $awkin = "$global->{tmpbase}.1.texi0";
+ my $rawtexi = "$global->{tmpbase}.1.texi0";
my $texifile = "$global->{tmpbase}.2.texi";
my $infofile = "$global->{filename}.info";
my $infofile0 = "$global->{tmpbase}.info";
- open ($OUTFILE, "> $awkin")
- or die "fmt_info::postASP: Could not open \"$awkin\" for writing\n";
+ open ($OUTFILE, "> $rawtexi")
+ or die "fmt_info::postASP: Could not open \"$rawtexi\" for writing. Aborting ...\n";
copy ($INFILE, $OUTFILE);
close $OUTFILE;
- system ("$awk -v INFO=$infofile -f $awkfilter $awkin > $texifile") == 0
- or die "$msgheader: Failed to run awk filter. Aborting ...\n";
+ # Preprocess the raw texinfo file
+ info_process_texi($rawtexi,$texifile,$infofile);
system ("makeinfo $texifile -o $infofile") == 0
or die "$msgheader: Failed to run makeinfo. Aborting ...\n";
diff --git a/perl5lib/LinuxDocTools/InfoUtils.pm b/perl5lib/LinuxDocTools/InfoUtils.pm
new file mode 100644
index 0000000..ec146e5
--- /dev/null
+++ b/perl5lib/LinuxDocTools/InfoUtils.pm
@@ -0,0 +1,332 @@
+# InfoUtils.pm
+#
+# Some utils for the linuxdoc info backend.
+#
+# * Create menus
+# * Normalize node names and associated text
+# * Point references to the associated node as needed
+#
+# Copyright (C) 2009 Agustín Martín Domingo, agmartin at debian org
+#
+# 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/>.
+# --------------------------------------------------------------------
+
+
+package LinuxDocTools::InfoUtils;
+
+use base qw(Exporter);
+
+# List all exported symbols here.
+our @EXPORT_OK = qw(info_process_texi);
+
+# Import :all to get everything.
+our %EXPORT_TAGS = (all => [@EXPORT_OK]);
+
+=head1 NAME
+
+ InfoUtils - Some utils for the linuxdoc info backend.
+
+=head1 SYNOPSIS
+
+use InfoUtils q{:all};
+
+info_process_texi($infile, $outfile, $infoname)
+
+=head1 DESCRIPTION
+
+This module contains some utils to process the raw texinfo file
+creating menus, normalizing node names and associated text and
+pointing references to the associated node as needed.
+
+=head1 FUNCTIONS
+
+=over 4
+
+=cut
+
+# -------------------------------------------------------------------------
+sub info_normalize_node_text {
+# -------------------------------------------------------------------------
+# Filter characters not allowed in section names
+# -------------------------------------------------------------------------
+ my $text = shift;
+
+ $text =~ s/\s+/ /g;
+ $text =~ s/\@[A-Za-z][A-Za-z0-9]*//g;
+ $text =~ s/(\{|\})//g;
+ $text =~ s/\,//g;
+# $text =~ s/\.+$//g;
+ $text =~ s/\./-/g;
+ $text =~ s/\s+$//g;
+
+ return $text;
+}
+
+# -------------------------------------------------------------------------
+sub info_normalize_node_name {
+# -------------------------------------------------------------------------
+# Filter characters not allowed in node names. Previous filtering of
+# characters not allowed in section names is supposed.
+# -------------------------------------------------------------------------
+ my $text = shift;
+# my $tmpnodedata = shift;
+
+ $text =~ s/\://g;
+ $text =~ s/\;//g;
+
+# die "Error: Reference \"$text\" already used"
+# if defined $tmpnodedata->{$text};
+
+ return $text;
+}
+
+# -------------------------------------------------------------------------
+sub info_parse_raw_file {
+# -------------------------------------------------------------------------
+# Parse raw texinfo file. It does not yet contain section names, menus,
+# correct references or title.
+# -------------------------------------------------------------------------
+ my $inputfile = shift;
+ my $INPUT;
+
+ my @inputtext = (); # Copy of input file with some preprocessing
+ my %nodedata = # A hash of hashes with all node info
+ ( 'Top' =>
+ { 'text' => "Top",
+ 'depth' => 0,
+ 'up' => "",
+ 'next' => '',
+ 'previous' => "",
+ 'sort' => 0,
+ 'debug' => "",
+ 'menu' => []}
+ );
+
+ my %menu = ();
+ my %levellast = (0 => "Top");
+ my %labels = ();
+ my %docdata = # Some misc data for the document
+ ( 'title' => "",
+ 'author' => "",
+ 'subtitle' => ""
+ );
+
+ my $depth = my $lastdepth = 0;
+ my $lastnode = "";
+ my $sort = 0;
+
+ open ($INPUT, "< $inputfile")
+ or die "info-postASP: Could not open $inputfile for read. Aborting ...\n";
+
+ while (<$INPUT>){
+ chomp;
+ if ( s/^\@SUB\s+// ){
+ my $updepth = $depth;
+ $depth++;
+ $sort++;
+
+ my @levelmenu = ();
+
+ if ( $lastdepth > $depth ){
+ $nodedata{$levellast{$depth}}->{'menu'} = $menu{$depth};
+ delete $menu{$depth};
+ @levelmenu = ();
+ }
+
+ if ( defined $menu{$updepth} ){
+ @levelmenu = @{ $menu{$updepth} };
+ }
+
+ my $nodetext = info_normalize_node_text($_);
+ my $nodename = info_normalize_node_name($nodetext,\%nodedata);
+
+ # Make first appearing node the next node for top node
+ $nodedata{'Top'}->{'next'} = $nodename if ( $lastdepth eq 0);
+
+ # Fill info for current node (and 'next' for last one in level)
+ $nodedata{$nodename}->{'text'} = $nodetext;
+ $nodedata{$nodename}->{'depth'} = $depth;
+ $nodedata{$nodename}->{'previous'} =
+ defined $levellast{$depth} ? $levellast{$depth} : "";
+ $nodedata{$levellast{$depth}}->{'next'} = $nodename
+ if defined $levellast{$depth};
+ $nodedata{$nodename}->{'up'} = $levellast{$updepth};
+ $nodedata{$nodename}->{'sort'} = $sort;
+ $nodedata{$nodename}->{'debug'} =
+ "updepth: $updepth, lastdepth: $lastdepth, up: $levellast{$updepth}";
+
+ # Keep this defined in case tbere is no next node in the same level.
+ $nodedata{$nodename}->{'next'} = "";
+
+ push @inputtext, "\@SUB $nodename"; # Rewrite @SUB with the new name
+ push @levelmenu, $nodename; # Add $nodename to the level menu list
+
+ # Prepare things for next @SUB entry found
+ $levellast{$depth} = $lastnode = $nodename;
+ $lastdepth = $depth;
+ $menu{$updepth} = \@levelmenu;
+
+ } elsif ( s/^\@ENDSUB// ){
+ $depth--;
+ push @inputtext, $_;
+ } elsif (s/^\@LABEL\s+//){
+ # Keep record of node labels vs nodenames. Will use the last.
+ $labels{$_} = $lastnode;
+ } elsif (s/^\@title\s+//){
+ $docdata{'title'} = $_;
+ } elsif (s/^\@author\s+//){
+ $docdata{'author'} = $_;
+ } elsif (s/^\@subtitle\s+//){
+ $docdata{'subtitle'} = $_;
+ } else {
+ push @inputtext, $_;
+ }
+ }
+ close $INPUT;
+
+ # Flush pending menus
+ foreach (0..5){
+ $nodedata{$levellast{$_}}->{'menu'} = $menu{$_} if defined $menu{$_};
+ }
+
+ $docdata{'nodedata'} = \%nodedata;
+ $docdata{'labels'} = \%labels;
+ $docdata{'inputtext'} = \@inputtext;
+
+ return \%docdata;
+}
+
+# -------------------------------------------------------------------------
+sub info_write_preprocessed_file {
+# -------------------------------------------------------------------------
+# Write processed texinfo file. Add section names, menus, correct
+# references and title.
+# -------------------------------------------------------------------------
+ my $docdata = shift;
+ my $infoname = shift;
+ my $texiout = shift;
+
+ die "InfoUtils.pm: No info file name $infoname.\n" unless $infoname;
+ die "InfoUtils.pm: No output texi file $texiout\n" unless $texiout;
+
+ my $nodedata = $docdata->{'nodedata'};
+ my $labels = $docdata->{'labels'};
+ my $inputtext = $docdata->{'inputtext'};
+
+ my $OUTFILE;
+
+ # check_parsed_data($nodedata);
+
+ my %sections = ( 1 => "\@chapter",
+ 2 => "\@section",
+ 3 => "\@subsection",
+ 4 => "\@subsubsection");
+
+ my $lastdepth = 0;
+ my $lastnode = "Top";
+ my $texinfo = "\@c %** START OF HEADER
+\@setfilename $infoname
+\@c %** END OF HEADER\n";
+
+ foreach ( @$inputtext ) {
+ if ( s/^\@SUB\s+// ){
+ my $key = $_;
+ my $depth = $nodedata->{$key}->{'depth'};
+ my $name = $nodedata->{$key}->{'text'};
+
+ if ( $depth le 4 ){
+ my $next = $nodedata->{$key}->{'next'};
+ my $previous = $nodedata->{$key}->{'previous'};
+ my $up = $nodedata->{$key}->{'up'};
+ # my $txt = "\@comment nodename, next, previous, up\n";
+ my $txt = "";
+
+ # $txt .= "\@node $key, $previous, $next, $up\n";
+ $txt .= "\@node $key\n";
+ $txt .= "$sections{$depth} $name\n";
+
+ if ( $depth gt $lastdepth && defined $nodedata->{$lastnode}->{'menu'}){
+ $txt = "\n\@menu\n\* "
+ . join("::\n\* ",@{$nodedata->{$lastnode}->{'menu'}})
+ . "::\n\@end menu\n"
+ . "\n$txt";
+ }
+
+ $texinfo .= $txt;
+ $lastdepth = $depth;
+ $lastnode = $key;
+ } else {
+ die "info-postASP:$key has wrong depth $depth\n";
+ }
+ } elsif (s/^\@REF\s+//){
+ if ( defined $labels->{$_} ){
+ # If this reference is to a node, use its nodename
+ $texinfo .= "\@ref{" . $labels->{$_} . "}\n";
+ } else {
+ $texinfo .= "\@ref{$_}\n";
+ }
+ } elsif (s/^\@TOP//){
+ $texinfo .= "\@node top\n"
+ . "\@top " . $docdata->{'title'} . "\n"
+ . "\@example\n"
+ . $docdata->{'author'} . "\n"
+ . $docdata->{'subtitle'} . "\n"
+ . "\@end example\n";
+ } else {
+ $texinfo .= "$_\n";
+ }
+ }
+
+ open ($OUTFILE, "> $texiout")
+ or die "Could not open \"$texiout\" for write. Aborting ...\n";
+ print $OUTFILE $texinfo;
+ close $OUTFILE;
+}
+
+# -------------------------------------------------------------------------
+sub info_check_parsed_data {
+# -------------------------------------------------------------------------
+# -------------------------------------------------------------------------
+ my $tmpnodedata = shift;
+ my @sections = sort {
+ $tmpnodedata->{$a}->{'sort'} <=> $tmpnodedata->{$b}->{'sort'}
+ } keys %$tmpnodedata;
+
+ foreach ( @sections ){
+ my $ref = $tmpnodedata->{$_};
+ print "$_\n";
+ print " text: $ref->{'text'}\n";
+ print " debug: $ref->{'debug'}\n";
+ print " up: $ref->{'up'}\n";
+ print " depth: $ref->{'depth'}\n";
+ print " previous: $ref->{'previous'}\n";
+ print " next: $ref->{'next'}\n";
+ print " sort: $ref->{'sort'}\n";
+ print " menu:\n * " . join("\n * ",@{$ref->{'menu'}}) . "\n" if defined $ref->{'menu'};
+ }
+}
+
+# -------------------------------------------------------------------------
+sub info_process_texi {
+# -------------------------------------------------------------------------
+# info_process_texi($infile, $outfile, $infoname)
+#
+# Call the other functions.
+# -------------------------------------------------------------------------
+ my $infile = shift;
+ my $outfile = shift;
+ my $infoname = shift;
+
+ info_write_preprocessed_file(info_parse_raw_file($infile),$infoname,$outfile);
+}
--
linuxdoc-tools package for Debian.
More information about the debian-xml-sgml-commit
mailing list