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];
33 foreach my $srcDir (@srcDirs) {
34 print "src: $srcDir\n" if $verbose;
35 opendir(my $dir, $srcDir) or die "can not open $srcDir";
36 foreach my $fn (readdir $dir) {
37 next unless $fn =~ /\.[ch]$/;
38 open(my $src, "<:encoding(UTF-8)", "$srcDir/$fn") or
39 die "can not open $srcDir/$fn";
44 if (defined $curEntry) {
50 if (/^TEXINFO: (.*)$/) {
52 $docstrings{$curEntry} = "";
53 print "\t$fn: $curEntry\n" if $verbose;
56 ( $docstrings{$curEntry} .= "$_\n" ) if defined $curEntry;
63 print "doc: $docDir\n" if $verbose;
64 opendir(my $dir, $docDir) or die "can not open $docDir";
65 foreach my $fn (readdir $dir) {
66 next unless $fn =~ /\.texi$/;
67 open(my $src, "<:encoding(UTF-8)", "$docDir/$fn") or
68 die "can not open $docDir/$fn";
69 open(my $dst, ">:encoding(UTF-8)", "$docBuildDir/$fn") or
70 die "can not open $docBuildDir/$fn";
72 ( print($dst $_) and next ) unless /^\@DOCSTRING (.*)\@$/;
73 print "\t$fn: $1\n" if $verbose;
74 die "unable to find docstring: $1" unless defined $docstrings{$1};
75 print $dst $docstrings{$1};