Mercurial > hg > octave-nkf
annotate 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 |
rev | line source |
---|---|
14617
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
1 #! /usr/bin/perl -w |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
2 # |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
3 # Copyright (C) 2012 Rik Wehbring |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
4 # |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
5 # This file is part of Octave. |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
6 # |
8ffb01c3a27a
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 |
8ffb01c3a27a
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 |
8ffb01c3a27a
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 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
10 # your option) any later version. |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
11 # |
8ffb01c3a27a
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 |
8ffb01c3a27a
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 |
8ffb01c3a27a
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 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
15 # for more details. |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
16 # |
8ffb01c3a27a
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 |
8ffb01c3a27a
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 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
19 # <http://www.gnu.org/licenses/>. |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
20 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
21 ## Expecting arguments in this order: |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
22 ## |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
23 ## SRCDIR SRCDIR-FILES ... -- LOCAL-FILES ... |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
24 |
8ffb01c3a27a
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 ..." ; } |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
26 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
27 $srcdir = shift (@ARGV) . '/'; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
28 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
29 print <<__END_OF_MSG__; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
30 ### DO NOT EDIT! |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
31 ### |
8ffb01c3a27a
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. |
8ffb01c3a27a
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. |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
34 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
35 __END_OF_MSG__ |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
36 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
37 MFILE: foreach $m_fname (@ARGV) |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
38 { |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
39 if ($m_fname eq "--") |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
40 { |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
41 $srcdir = "./"; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
42 next MFILE; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
43 } |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
44 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
45 $full_fname = $srcdir . $m_fname; |
8ffb01c3a27a
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} ); |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
47 if ($2) { |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
48 $fcn = "$2$3/$4"; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
49 } else { |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
50 $fcn = $4; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
51 } |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
52 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
53 @help_txt = mygethelp ($fcn, $full_fname); |
8ffb01c3a27a
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 ""); |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
55 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
56 print "$fcn\n"; |
8ffb01c3a27a
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"; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
58 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
59 foreach $_ (@help_txt) |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
60 { |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
61 s/^\s+\@/\@/ unless $in_example; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
62 s/^\s+\@group/\@group/; |
8ffb01c3a27a
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/; |
8ffb01c3a27a
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/); |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
65 print $_; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
66 } |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
67 } |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
68 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
69 ################################################################################ |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
70 # Subroutines |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
71 ################################################################################ |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
72 sub mygethelp |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
73 { |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
74 ($fcn, $fname) = @_[0..1]; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
75 open (FH, $fname) or return ""; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
76 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
77 do |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
78 { |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
79 @help_txt = (); |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
80 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
81 ## Advance to non-blank line |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
82 while (defined ($_ = <FH>) and /^\s*$/) {;} |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
83 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
84 if (! /^\s*(?:#|%)/ or eof (FH)) |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
85 { |
8ffb01c3a27a
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 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
87 close (FH); |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
88 return ""; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
89 } |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
90 |
8ffb01c3a27a
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 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
92 do |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
93 { |
8ffb01c3a27a
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 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
95 s/^\s*(?:#|%){1,2} ?//; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
96 push (@help_txt, $_); |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
97 } until (! defined ($_ = <FH>) or ! /^\s*(?:#|%)/); |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
98 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
99 } until ($help_txt[0] !~ /^(?:Copyright|Author)/); |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
100 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
101 close (FH); |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
102 |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
103 return @help_txt; |
8ffb01c3a27a
doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff
changeset
|
104 } |