2 # Simple script for substitute placeholders in Texinfo files with
3 # docstring values found in source code.
4 # Copyright (C) 2020 Sergey Matveev (stargrave@stargrave.org)
6 # If you C source code contains:
10 # // last line of docstring
13 # Then under "SomeKey" you will have the whole docstring (starting from
14 # the line after "TEXINFO", till "last line"). You can include its
15 # contents (excluding comment characters) in your .texi files placing
23 if ($ARGV[0] eq "-v") {
27 my @srcDirs = split / /, $ARGV[0];
28 my $docDir = $ARGV[1];
29 my $docBuildDir = $ARGV[2];
30 my @exts = split / /, defined $ENV{EXTS} ? $ENV{EXTS} : "c h h.in";
34 foreach my $srcDir (@srcDirs) {
35 print "src: $srcDir\n" if $verbose;
36 opendir(my $dir, $srcDir) or die "can not open $srcDir";
37 foreach my $fn (readdir $dir) {
38 next unless grep { $fn =~ /\.$_$/ } @exts;
39 open(my $src, "<:encoding(UTF-8)", "$srcDir/$fn") or
40 die "can not open $srcDir/$fn";
45 if (defined $curEntry) {
51 if (/^TEXINFO: (.*)$/) {
53 $docstrings{$curEntry} = "";
54 print "\t$fn: $curEntry\n" if $verbose;
57 ( $docstrings{$curEntry} .= "$_\n" ) if defined $curEntry;
64 print "doc: $docDir\n" if $verbose;
65 opendir(my $dir, $docDir) or die "can not open $docDir";
66 foreach my $fn (readdir $dir) {
67 next unless $fn =~ /\.texi$/;
68 open(my $src, "<:encoding(UTF-8)", "$docDir/$fn") or
69 die "can not open $docDir/$fn";
70 open(my $dst, ">:encoding(UTF-8)", "$docBuildDir/$fn") or
71 die "can not open $docBuildDir/$fn";
73 ( print($dst $_) and next ) unless /^\s*\@DOCSTRING (.*)\@$/;
74 print "\t$fn: $1\n" if $verbose;
75 die "unable to find docstring: $1" unless defined $docstrings{$1};
76 print $dst $docstrings{$1};