bison-patches
[Top][All Lists]
Advanced

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

FYI: [PATCH 3/4] build: extexi: support out-of-order blocks


From: Akim Demaille
Subject: FYI: [PATCH 3/4] build: extexi: support out-of-order blocks
Date: Sun, 8 Apr 2012 10:21:58 +0200

Installed in master.  This is in order to document %printer.

From 830e733076a83aa5e38a86df8393ce61dce85931 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Sun, 8 Apr 2012 09:45:12 +0200
Subject: [PATCH 3/4] build: extexi: support out-of-order blocks.

* examples/extexi (%file_output): Remove.
(&process): Accept "FILE: BLOCK-NUM" requests.
---
 examples/extexi |   44 ++++++++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/examples/extexi b/examples/extexi
index 6315479..8f27a3b 100755
--- a/examples/extexi
+++ b/examples/extexi
@@ -21,6 +21,18 @@
 
 # Usage: extexi input-file.texi ... -- [FILES to extract]
 
+# Look for @example environments preceded with lines such as:
+#
+#      @comment file calc.y
+# or
+#      @comment file calc.y: 3
+#
+# and output their content in that file (calc.y).  When numbers are
+# provided, use them to decide the output order (block numbered 1 is
+# output before block 2, even if the latter appears before).  The same
+# number may be used several time, in which case the order of
+# appearance is used.
+
 use strict;
 
 # normalize($block)
@@ -52,9 +64,6 @@ sub message($)
 
 # basename => full file name for files we should extract.
 my %file_wanted;
-# Whether we already say that file (in which case, append instead of
-# create).
-my %file_output;
 
 sub process ($)
 {
@@ -62,16 +71,21 @@ sub process ($)
   use IO::File;
   my $f = new IO::File($in)
     or die "$in: cannot open: $?";
-  # The latest "@comment file: " argument.
+  # FILE-NAME => { BLOCK-NUM => CODE }
+  my %file;
+
+  # The latest "@comment file: FILE [BLOCK-NUM]" arguments.
   my $file;
+  my $block;
   # The @example block currently read.
   my $input;
   local $_;
   while (<$f>)
     {
-      if (/address@hidden file: (.*)/)
+      if (/address@hidden file: ([^:\n]+)(?::\s*(\d+))?$/)
         {
           my $f = $1;
+          $block = $2 || 1;
           if ($file_wanted{$f})
             {
               $file = $file_wanted{$f};
@@ -86,7 +100,6 @@ sub process ($)
         {
           if (/^\@(small)?example$/)
             {
-              $input = $file_output{$file} ? "\n" : "";
               # Bison supports synclines, but not Flex.
               $input .= sprintf ("#line %s \"$in\"\n", $. + 1)
                 if $file =~ /\.[chy]*$/;
@@ -97,22 +110,25 @@ sub process ($)
               die "no contents: $file"
                 if $input eq "";
 
-              $input = normalize($input);
-              # No spurious end of line: use printf.
-              my $o =
-                ($file_output{$file}
-                 ? new IO::File(">>$file")
-                 : new IO::File(">$file"));
-              print $o $input;
-              $file_output{$file} = 1;
+              $file{$file}{$block} .= normalize($input);
               $file = $input = undef;
+              ++$block;
             }
           else
             {
               $input .= $_;
             }
         }
+    }
 
+  # Output the files.
+  for my $file (keys %file)
+    {
+      # No spurious end of line: use printf.
+      my $o = new IO::File(">$file")
+        or die "$file: cannot create: $?";
+      print $o $file{$file}{$_}
+        for sort keys %{$file{$file}};
     }
 }
 
-- 
1.7.9.5





reply via email to

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