[exim-cvs] Just work on numbered chapters.

Top Page
Delete this message
Reply to this message
Author: Exim Git Commits Mailing List
Date:  
To: exim-cvs
Subject: [exim-cvs] Just work on numbered chapters.
Gitweb: http://git.exim.org/exim-website.git/commitdiff/fa1923456d030387391eb3c13a5e27c3021b9935
Commit:     fa1923456d030387391eb3c13a5e27c3021b9935
Parent:     9d4d8b603568ae666ae8884e7cfb72b247c086af
Author:     Phil Pennock <pdp@???>
AuthorDate: Thu Dec 6 08:37:54 2012 -0500
Committer:  Phil Pennock <pdp@???>
CommitDate: Thu Dec 6 08:37:54 2012 -0500


    Just work on numbered chapters.


    We want to move to named chapters.  This tool relies upon directory walking to get the chapters in order.
    So, get _just_ the numbered chapters, sort, then chase any links.
---
 script/eximhtml2txt.pl |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)


diff --git a/script/eximhtml2txt.pl b/script/eximhtml2txt.pl
index 0f03ea4..38892e1 100755
--- a/script/eximhtml2txt.pl
+++ b/script/eximhtml2txt.pl
@@ -3,6 +3,7 @@
use strict;
use warnings;

+use File::Spec;
use HTML::FormatText;
use HTML::TreeBuilder;

@@ -19,8 +20,30 @@ sub process_chapter {
     return $text;
 }


+sub chapters_in_order {
+    my $dir = shift;
+
+    opendir DIR, $dir or die "opendir($dir) failed: $!\n";
+    my @numeric = sort grep {/^ch\d+\.html$/} readdir(DIR);
+    closedir(DIR) or die "closedir($dir) failed: $!\n";
+
+    my @results = map {
+        $_ = File::Spec->catfile($dir, $_);
+        if (-l $_) {
+            my $t;
+            eval { $t = readlink $_ };
+            $_ = File::Spec->rel2abs($t, $dir) if defined $t;
+        }
+        $_
+    } @numeric;
+    return @results;
+}
+
+
 my $dir = shift;
-foreach my $fn ( glob("$dir/ch*.html") ) {
+die "Need a directory\n" unless defined $dir;
+
+foreach my $fn ( chapters_in_order($dir) ) {
     print "=" x 72, "\n";
     print $fn, "\n";
     print "=" x 72, "\n";