]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Multiple .texi source directories support
authorSergey Matveev <stargrave@stargrave.org>
Sun, 2 Oct 2022 10:28:31 +0000 (13:28 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 2 Oct 2022 10:28:31 +0000 (13:28 +0300)
bin/bin/docstringer.pl

index 8a8db495306a79dc7c09f7a839c7b32de01cfdb2..d5b344142173aa8045c59c247bf171105f2d06c8 100755 (executable)
@@ -23,11 +23,11 @@ my $verbose = 0;
 if ($ARGV[0] eq "-v") {
     $verbose = 1;
     shift @ARGV;
-};
-my @srcDirs = split / /, $ARGV[0];
-my $docDir = $ARGV[1];
-my $docBuildDir = $ARGV[2];
-my @exts = split / /, defined $ENV{EXTS} ? $ENV{EXTS} : "c h h.in";
+}
+my $outDir = $ARGV[0];
+my @srcDirs = split /:/, $ARGV[1];
+my @docDirs = split /:/, $ARGV[2];
+my @exts = split / /, (defined $ENV{EXTS}) ? $ENV{EXTS} : "c h h.in";
 
 my %docstrings;
 
@@ -39,43 +39,48 @@ foreach my $srcDir (@srcDirs) {
         open(my $src, "<:encoding(UTF-8)", "$srcDir/$fn") or
             die "can not open $srcDir/$fn";
         my $curEntry;
-        while(<$src>) {
+        while (<$src>) {
             chomp;
             if (not /^\/\//) {
                 if (defined $curEntry) {
                     undef $curEntry;
-                };
+                }
                 next;
-            };
+            }
             s/^\/\/ ?//;
             if (/^TEXINFO: (.*)$/) {
                 $curEntry = $1;
                 $docstrings{$curEntry} = "";
                 print "\t$fn: $curEntry\n" if $verbose;
                 next;
-            };
-            ( $docstrings{$curEntry} .= "$_\n" ) if defined $curEntry;
-        };
+            }
+            ($docstrings{$curEntry} .= "$_\n") if defined $curEntry;
+        }
         close $src;
-    };
+    }
     closedir $dir;
-};
+}
 
-print "doc: $docDir\n" if $verbose;
-opendir(my $dir, $docDir) or die "can not open $docDir";
-foreach my $fn (readdir $dir) {
-    next unless $fn =~ /\.texi$/;
-    open(my $src, "<:encoding(UTF-8)", "$docDir/$fn") or
-        die "can not open $docDir/$fn";
-    open(my $dst, ">:encoding(UTF-8)", "$docBuildDir/$fn") or
-        die "can not open $docBuildDir/$fn";
-    while(<$src>) {
-        ( print($dst $_) and next ) unless /^\s*\@DOCSTRING (.*)\@$/;
-        print "\t$fn: $1\n" if $verbose;
-        die "unable to find docstring: $1" unless defined $docstrings{$1};
-        print $dst $docstrings{$1};
-    };
-    close $src;
-    close $dst;
-};
-closedir $dir;
+foreach my $docDir (@docDirs) {
+    print "doc: $docDir\n" if $verbose;
+    opendir(my $dir, $docDir) or die "can not open $docDir";
+    ($docDir .= "/") unless $docDir =~ /\/$/;
+    ($docDir = "") if $docDir eq "./";
+    foreach my $fn (readdir $dir) {
+        next unless $fn =~ /\.texi$/;
+        $fn = $docDir . $fn;
+        open(my $src, "<:encoding(UTF-8)", $fn) or die "can not open $fn";
+        mkdir "$outDir/$docDir";
+        open(my $dst, ">:encoding(UTF-8)", "$outDir/$fn") or
+            die "can not open $outDir/$fn";
+        while (<$src>) {
+            (print($dst $_) and next) unless /^\s*\@DOCSTRING (.*)\@$/;
+            print "\t$fn: $1\n" if $verbose;
+            die "unable to find docstring: $1" unless defined $docstrings{$1};
+            print $dst $docstrings{$1};
+        }
+        close $src;
+        close $dst;
+    }
+    closedir $dir;
+}