annotate scripts/mkdoc.pl @ 15828:41a05ee9021a stable

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