annotate scripts/mk-doc.pl @ 26215:39e84bf92d18

accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596) * scripts/mk-doc.pl: Detect nested +pkg directory names.
author John W. Eaton <jwe@octave.org>
date Wed, 12 Dec 2018 22:02:02 -0500
parents 6652d3823428
children 00f796120a6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
1 #! /usr/bin/perl
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
2 use utf8;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
3
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
4 # Copyright (C) 2012-2018 Rik Wehbring
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
5 #
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
6 # This file is part of Octave.
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
7 #
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23709
diff changeset
8 # Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22334
diff changeset
9 # under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23709
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22334
diff changeset
11 # (at your option) any later version.
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
12 #
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22334
diff changeset
13 # Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22334
diff changeset
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22334
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22334
diff changeset
16 # GNU General Public License for more details.
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
17 #
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
18 # 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
19 # along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23709
diff changeset
20 # <https://www.gnu.org/licenses/>.
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
21
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
22 use strict;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
23 use warnings;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
24 use File::Spec;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
25 use Cwd;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
26
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
27 ## Expecting arguments in this order:
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
28 ##
21959
627f582edbe3 extract documentation from .in.m files instead of generated .m files
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
29 ## SRCDIR SRCDIR-FILES ...
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
30
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
31 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
32
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
33 my $srcdir = shift (@ARGV);
14617
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 print <<__END_OF_MSG__;
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
36 ### DO NOT EDIT!
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
37 ###
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
38 ### 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
39 ### 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
40
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
41 __END_OF_MSG__
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
42
18943
714ce8ca71ea mkdoc.pl: Tweaks to make code easier to understand for non-Perl experts.
Rik <rik@octave.org>
parents: 18940
diff changeset
43 MFILE: foreach my $m_fname (@ARGV)
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
44 {
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
45 my $full_fname = File::Spec->catfile ($srcdir, $m_fname);
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
46 my @paths = File::Spec->splitdir ($full_fname);
18943
714ce8ca71ea mkdoc.pl: Tweaks to make code easier to understand for non-Perl experts.
Rik <rik@octave.org>
parents: 18940
diff changeset
47 if (@paths < 3
714ce8ca71ea mkdoc.pl: Tweaks to make code easier to understand for non-Perl experts.
Rik <rik@octave.org>
parents: 18940
diff changeset
48 || $paths[-2] eq "private" # skip private directories
21959
627f582edbe3 extract documentation from .in.m files instead of generated .m files
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
49 || $paths[-1] !~ s/(\.in|)\.m$//i) # skip non m-files, and remove extension
18943
714ce8ca71ea mkdoc.pl: Tweaks to make code easier to understand for non-Perl experts.
Rik <rik@octave.org>
parents: 18940
diff changeset
50 { next MFILE; }
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
51
23393
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
52 my $fcn;
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
53 if ($paths[-2] =~ m/^@/)
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
54 {
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
55 ## @classes will have @class/method as their function name
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
56 $fcn = File::Spec->catfile (@paths[-2, -1]);
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
57 }
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
58 elsif ($paths[-2] =~ m/^\+/)
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
59 {
26215
39e84bf92d18 accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
60 $fcn = $paths[-1];
39e84bf92d18 accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
61 for (my $i = 2; $i < @paths; $i++)
39e84bf92d18 accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
62 {
39e84bf92d18 accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
63 if ($paths[-$i] =~ m/^\+/)
39e84bf92d18 accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
64 {
39e84bf92d18 accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
65 ## +package functions have package.name their function name
39e84bf92d18 accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
66 $fcn = substr ($paths[-$i], 1) . "." . $fcn;
39e84bf92d18 accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
67 }
39e84bf92d18 accept functions in nested +pkg directories in @DOCSTRING macros (bug #52596)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
68 }
23393
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
69 }
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
70 else
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
71 {
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
72 $fcn = $paths[-1];
675ad11b5c05 recognize docstrings for +package functions
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
73 }
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
74
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
75 my @help_txt = gethelp ($fcn, $full_fname);
18943
714ce8ca71ea mkdoc.pl: Tweaks to make code easier to understand for non-Perl experts.
Rik <rik@octave.org>
parents: 18940
diff changeset
76 next MFILE unless @help_txt;
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
77
17256
ee1d19174316 doc: Use 0x1d as record separator for joint compatibility with Texinfo 4.x and 5.x.
Rik <rik@octave.org>
parents: 17242
diff changeset
78 print "\x{1d}$fcn\n";
22334
fed9aa2ed01d doc: Insert correct location of m-file into @c comment in .texi files.
Rik <rik@octave.org>
parents: 22323
diff changeset
79 print "\@c $fcn $m_fname\n";
14617
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 foreach $_ (@help_txt)
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
82 {
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
83 my $in_example = (m/\s*\@example\b/ .. m/\s*\@end\s+example\b/);
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
84 s/^\s+\@/\@/ unless $in_example;
18940
29fc1736a6be scripts/mkdoc.pl: remove '@(end )?example' leading spaces from DOCSTRING.
Carnë Draug <carandraug@octave.org>
parents: 18939
diff changeset
85 s/^\s+(\@(?:end)\s+(group|example))/$1/;
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
86 print $_;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
87 }
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
88 }
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 # Subroutines
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
92 ################################################################################
14644
f49e47ab83ca maint: Rename mygethelp function to gethelp in scripts/mkdoc.pl
Rik <octave@nomad.inbox5.com>
parents: 14617
diff changeset
93 sub gethelp
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
94 {
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
95 my $fcn = shift;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
96 my $fname = shift;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
97 open (my $fh, "<", $fname) or return;
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
98
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
99 my @help_txt;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
100 while (my $line = <$fh>)
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
101 {
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
102 next if $line =~ m/^\s*$/; # skip empty lines
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
103 last if $line !~ m/^\s*(#|%)/; # out of here once code starts
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
104
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
105 my $reading_block = sub {defined ($line = <$fh>) && $line !~ m/^\s*$/};
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
106
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
107 ## Skip this block
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
108 if ($line =~ /(Copyright|Author)/)
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
109 { while (&$reading_block ()) {} }
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
110 else
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
111 {
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
112 do
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
113 {
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
114 $line =~ s/^\s*(%|#)+ ?//;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
115 push (@help_txt, $line);
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
116 } while (&$reading_block ());
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
117 last;
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
118 }
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
119 }
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
120
18939
b0960d4afe5f scripts/mkdoc.pl: improve perl code portability.
Carnë Draug <carandraug@octave.org>
parents: 18938
diff changeset
121 close ($fh);
14617
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
122 return @help_txt;
8ffb01c3a27a doc: Use Perl to create DOCSTRINGS in scripts directory.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
123 }