texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

texinfo/tp/Texinfo Structuring.pm Convert/Conve...


From: Patrice Dumas
Subject: texinfo/tp/Texinfo Structuring.pm Convert/Conve...
Date: Thu, 24 Mar 2011 23:06:48 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/03/24 23:06:48

Modified files:
        tp/Texinfo     : Structuring.pm 
        tp/Texinfo/Convert: Converter.pm Info.pm Plaintext.pm 

Log message:
        Prepare splitting by page.
        Put the out file name determination into the Converter common code.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.42&r2=1.43
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Converter.pm?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Info.pm?cvsroot=texinfo&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.126&r2=1.127

Patches:
Index: Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- Structuring.pm      20 Mar 2011 20:47:49 -0000      1.42
+++ Structuring.pm      24 Mar 2011 23:06:47 -0000      1.43
@@ -594,6 +594,42 @@
   return $elements;
 }
 
+# associate elements to pages according to the splitting specification.
+sub split_pages ($$)
+{
+  my $elements = shift;
+  my $split = shift;
+
+  return undef if (!$elements or !$split);
+
+  my $split_level;
+  if ($split eq 'chapter') {
+    $split_level = 1;
+  } elsif ($split eq 'section') {
+    $split_level = 2;
+  }
+
+  my @pages = ();
+
+  foreach my $element (@$elements) {
+    my $level;
+    if ($element->{'extra'}->{'section'}) {
+      $level = $element->{'extra'}->{'section'}->{'level'};
+    } elsif ($element->{'extra'}->{'node'} 
+             and $element->{'extra'}->{'node'}->{'associated_section'}) {
+      $level = 
$element->{'extra'}->{'node'}->{'associated_section'}->{'level'};
+    }
+    if ($split eq 'node' or (defined($level) and $split_level <= $level)
+        or address@hidden) {
+      push @pages, {};
+    }
+    push @{$pages[-1]->{'contents'}}, $element;
+    $element->{'parent'} = $pages[-1];
+  }
+  return address@hidden;
+}
+
+# this is used in the test suite, but not likely to be useful in real life.
 sub _unsplit($)
 {
   my $root = shift;

Index: Convert/Converter.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Converter.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Convert/Converter.pm        24 Mar 2011 00:51:56 -0000      1.1
+++ Convert/Converter.pm        24 Mar 2011 23:06:47 -0000      1.2
@@ -181,4 +181,66 @@
   }
 }
 
+my $STDIN_DOCU_NAME = 'stdin';
+
+# This is especially useful for unsplit manuals
+sub _set_outfile($$$)
+{
+  my $self = shift;
+
+  # determine input file base name
+  my $input_basename;
+  if (defined($self->{'info'}->{'input_file_name'})) {
+    $input_basename = $self->{'info'}->{'input_file_name'};
+  } else {
+    # This could happen if called on a piece of texinfo
+    $input_basename = '';
+  }
+  $input_basename =~ s/^.*\///;
+  $self->{'input_basename'} = $input_basename;
+  $input_basename = $STDIN_DOCU_NAME if ($input_basename eq '-');
+
+  my $setfilename;
+  $setfilename = $self->{'extra'}->{'setfilename'}->{'extra'}->{'text_arg'}
+    if ($self->{'extra'} and $self->{'extra'}->{'setfilename'}
+        and $self->{'extra'}->{'setfilename'}->{'extra'}
+        and 
defined($self->{'extra'}->{'setfilename'}->{'extra'}->{'text_arg'}));
+
+  # determine output file and output file name
+  if (!defined($self->{'OUTFILE'})) {
+    if (defined($setfilename)) {
+      $self->{'OUTFILE'} = $setfilename;
+      if (!$self->{'USE_SETFILENAME_EXTENSION'}) {
+        $self->{'OUTFILE'} =~ s/\.[^\.]*$//;
+        $self->{'OUTFILE'} .= '.'.$self->{'EXTENSION'} 
+          if (defined($self->{'EXTENSION'}) and $self->{'EXTENSION'} ne '');
+      }
+    } elsif ($input_basename ne '') {
+      $self->{'OUTFILE'} = $input_basename;
+      $self->{'OUTFILE'} =~ s/\.te?x(i|info)?$//;
+      $self->{'OUTFILE'} .= '.'.$self->{'EXTENSION'} 
+        if (defined($self->{'EXTENSION'}) and $self->{'EXTENSION'} ne '');
+    } else {
+      $self->{'OUTFILE'} = '';
+    }
+    if (defined($self->{'SUBDIR'}) and $self->{'OUTFILE'} ne '') {
+      $self->{'OUTFILE'} = "$self->{'SUBDIR'}/$self->{'OUTFILE'}";
+    }
+  }
+
+  my $output_basename = $self->{'OUTFILE'};
+  # this is a case that should happen rarely: one wants to get 
+  # the result in a string and there is a setfilename.
+  if ($self->{'OUTFILE'} eq '' and defined($setfilename)) {
+    $output_basename = $setfilename;
+  }
+  $output_basename =~ s/^.*\///;
+  $self->{'output_filename'} = $output_basename;
+  my $output_dir = $self->{'OUTFILE'};
+  $output_dir =~ s|[^/]*$||;
+  if ($output_dir ne '') {
+    $self->{'output_dir'} = $output_dir;
+  }
+}
+
 1;

Index: Convert/Info.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Info.pm,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- Convert/Info.pm     20 Mar 2011 20:47:49 -0000      1.49
+++ Convert/Info.pm     24 Mar 2011 23:06:47 -0000      1.50
@@ -47,7 +47,6 @@
 $VERSION = '0.01';
 
 my $STDIN_DOCU_NAME = 'stdin';
-my $INFO_EXTENSION = 'info';
 
 sub output($)
 {
@@ -56,59 +55,14 @@
 
   my $result;
 
-  # determine input file base name
-  my $input_basename;
-  if (defined($self->{'info'}->{'input_file_name'})) {
-    $input_basename = $self->{'info'}->{'input_file_name'};
-  } else {
-    # This could happen if called on a piece of texinfo
-    $input_basename = '';
-  }
-  $input_basename =~ s/^.*\///;
-  $input_basename = $STDIN_DOCU_NAME if ($input_basename eq '-');
-  $self->{'input_basename'} = $input_basename;
-
-  my $setfilename;
-  $setfilename = $self->{'extra'}->{'setfilename'}->{'extra'}->{'text_arg'}
-    if ($self->{'extra'} and $self->{'extra'}->{'setfilename'}
-        and $self->{'extra'}->{'setfilename'}->{'extra'}
-        and 
defined($self->{'extra'}->{'setfilename'}->{'extra'}->{'text_arg'}));
-
-  # determine output file and output file name
-  if (!defined($self->{'OUTFILE'})) {
-    if (defined($setfilename)) {
-      $self->{'OUTFILE'} = $setfilename;
-    } elsif ($input_basename ne '') {
-      $self->{'OUTFILE'} = $input_basename;
-      $self->{'OUTFILE'} =~ s/\.te?x(i|info)?$//;
-      $self->{'OUTFILE'} .= '.'.$INFO_EXTENSION;
-    } else {
-      $self->{'OUTFILE'} = '';
-    }
-    if (defined($self->{'SUBDIR'}) and $self->{'OUTFILE'} ne '') {
-      $self->{'OUTFILE'} = "$self->{'SUBDIR'}/$self->{'OUTFILE'}";
-    }
-  } else {
+  $self->_set_outfile();
+  $self->{'input_basename'} = $STDIN_DOCU_NAME if ($self->{'input_basename'} 
eq '-');
+
     # no splitting when writing to the null device or to stdout
     if ($Texinfo::Common::null_device_file{$self->{'OUTFILE'}} 
          or $self->{'OUTFILE'} eq '-') {
       $self->{'SPLIT_SIZE'} = undef;
     }
-  }
-
-  my $output_basename = $self->{'OUTFILE'};
-  # this is a case that should happen rarely: one wants to get 
-  # the result in a string and there is a setfilename.
-  if ($self->{'OUTFILE'} eq '' and defined($setfilename)) {
-    $output_basename = $setfilename;
-  }
-  $output_basename =~ s/^.*\///;
-  $self->{'output_filename'} = $output_basename;
-  my $output_dir = $self->{'OUTFILE'};
-  $output_dir =~ s|[^/]*$||;
-  if ($output_dir ne '') {
-    $self->{'output_dir'} = $output_dir;
-  }
 
   push @{$self->{'count_context'}}, {'lines' => 0, 'bytes' => 0,
                                      'locations' => []};

Index: Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -b -r1.126 -r1.127
--- Convert/Plaintext.pm        24 Mar 2011 00:51:56 -0000      1.126
+++ Convert/Plaintext.pm        24 Mar 2011 23:06:47 -0000      1.127
@@ -236,6 +236,10 @@
 # this default is for Info, but also when doing Texinfo fragments.  So this 
 # has to be explicitly set to 0 when doing real plaintext.
   'SHOW_MENU'            => 1,
+# not used for plaintext, since default is '-' for plaintext.
+  'EXTENSION'            => 'info',
+  'USE_SETFILENAME_EXTENSION' => 1,
+
   'footnotestyle'        => 'end',
   'fillcolumn'           => 72,
 #  'perl_encoding'        => 'ascii',



reply via email to

[Prev in Thread] Current Thread [Next in Thread]