comparison scripts/mkdoc.pl @ 14617:8ffb01c3a27a

doc: Use Perl to create DOCSTRINGS in scripts directory. * mkdoc.pl: Perl script that generates DOCSTRINGS file. * Makefile.am: Use mkdoc.pl in build procedures. * gethelp.cc: Remove C++ helper program for building DOCSTRINGS file.
author Rik <octave@nomad.inbox5.com>
date Thu, 10 May 2012 16:58:41 -0700
parents
children f49e47ab83ca
comparison
equal deleted inserted replaced
14616:13cc11418393 14617:8ffb01c3a27a
1 #! /usr/bin/perl -w
2 #
3 # Copyright (C) 2012 Rik Wehbring
4 #
5 # This file is part of Octave.
6 #
7 # Octave is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 3 of the License, or (at
10 # your option) any later version.
11 #
12 # Octave is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Octave; see the file COPYING. If not, see
19 # <http://www.gnu.org/licenses/>.
20
21 ## Expecting arguments in this order:
22 ##
23 ## SRCDIR SRCDIR-FILES ... -- LOCAL-FILES ...
24
25 unless (@ARGV >= 2) { die "Usage: $0 srcdir m_filename1 ..." ; }
26
27 $srcdir = shift (@ARGV) . '/';
28
29 print <<__END_OF_MSG__;
30 ### DO NOT EDIT!
31 ###
32 ### This file is generated automatically from Octave source files.
33 ### Edit source files directly and run make to update this file.
34
35 __END_OF_MSG__
36
37 MFILE: foreach $m_fname (@ARGV)
38 {
39 if ($m_fname eq "--")
40 {
41 $srcdir = "./";
42 next MFILE;
43 }
44
45 $full_fname = $srcdir . $m_fname;
46 next MFILE unless ( $full_fname =~ m{(.*)/(@|)([^/]*)/(.*)\.m} );
47 if ($2) {
48 $fcn = "$2$3/$4";
49 } else {
50 $fcn = $4;
51 }
52
53 @help_txt = mygethelp ($fcn, $full_fname);
54 next MFILE if ($help_txt[0] eq "");
55
56 print "$fcn\n";
57 print "\@c $fcn scripts/$m_fname\n";
58
59 foreach $_ (@help_txt)
60 {
61 s/^\s+\@/\@/ unless $in_example;
62 s/^\s+\@group/\@group/;
63 s/^\s+\@end\s+group/\@end group/;
64 $in_example = (/\s*\@example\b/ .. /\s*\@end\s+example\b/);
65 print $_;
66 }
67 }
68
69 ################################################################################
70 # Subroutines
71 ################################################################################
72 sub mygethelp
73 {
74 ($fcn, $fname) = @_[0..1];
75 open (FH, $fname) or return "";
76
77 do
78 {
79 @help_txt = ();
80
81 ## Advance to non-blank line
82 while (defined ($_ = <FH>) and /^\s*$/) {;}
83
84 if (! /^\s*(?:#|%)/ or eof (FH))
85 {
86 ## No comment block found. Return empty string
87 close (FH);
88 return "";
89 }
90
91 ## Extract help text stopping when comment block ends
92 do
93 {
94 ## Remove comment characters at start of line
95 s/^\s*(?:#|%){1,2} ?//;
96 push (@help_txt, $_);
97 } until (! defined ($_ = <FH>) or ! /^\s*(?:#|%)/);
98
99 } until ($help_txt[0] !~ /^(?:Copyright|Author)/);
100
101 close (FH);
102
103 return @help_txt;
104 }