File: mkdoc.pl

package info (click to toggle)
octave-optim 1.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,368 kB
  • sloc: cpp: 1,437; makefile: 185; perl: 169; xml: 29; sh: 3
file content (86 lines) | stat: -rwxr-xr-x 2,263 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /usr/bin/perl -w
#
# Copyright (C) 2012-2013 Rik Wehbring
#
# This file is part of Octave.
#
# Octave is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# Octave is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with Octave; see the file COPYING.  If not, see
# <http://www.gnu.org/licenses/>.

# copied from Octave and slightly modified by Olaf Till

unless (@ARGV >= 1) { die "Usage: $0 m_filename1 ..." ; }

print <<__END_OF_MSG__;
### This file is generated automatically by the packages `mkdoc.pl'.

__END_OF_MSG__

MFILE: foreach $full_fname (@ARGV)
{
  next MFILE unless ( $full_fname =~ m{([^/]+)\.m$} );
  $fcn = $1;

  @help_txt = gethelp ($fcn, $full_fname);
  next MFILE if ($help_txt[0] eq "");

  print "\x{1d}$fcn\n";
  print "\@c $fcn $full_fname\n";

  foreach $_ (@help_txt)
  {
    s/^\s+\@/\@/ unless $in_example;
    s/^\s+\@group/\@group/;
    s/^\s+\@end\s+group/\@end group/;
    $in_example = (/\s*\@example\b/ .. /\s*\@end\s+example\b/);
    print $_;
  }
}

################################################################################
# Subroutines
################################################################################
sub gethelp
{
  ($fcn, $fname) = @_[0..1]; 
  open (FH, $fname) or return "";

  do
  {
    @help_txt = ();

    ## Advance to non-blank line
    while (defined ($_ = <FH>) and /^\s*$/) {;}

    if (! /^\s*(?:#|%)/ or eof (FH))
    {
      ## No comment block found.  Return empty string
      close (FH);
      return "";
    }

    ## Extract help text stopping when comment block ends
    do
    {
      ## Remove comment characters at start of line
      s/^\s*(?:#|%){1,2} ?//;
      push (@help_txt, $_);
    } until (! defined ($_ = <FH>) or ! /^\s*(?:#|%)/);

  } until ($help_txt[0] !~ /^(?:Copyright|Author)/); 

  close (FH);

  return @help_txt;
}