annotate doc/interpreter/munge-texi.pl @ 15827:1f1fc4798f0a stable

doc: Produce .texi from .txi files using Perl rather than C++. * munge-texi.pl: New Perl file to generate .texi files from .txi files. * munge-texi.cc: Remove C++ file for generating .texi files. * Makefile.am: Change build system to use munge-texi.pl
author Rik <octave@nomad.inbox5.com>
date Tue, 08 May 2012 21:03:42 -0700
parents
children a52b03df22cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15827
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
1 #!/usr/bin/perl -w
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
2
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
3 # Validate program call
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
4 die "usage: munge-texi TOP-SRCDIR DOCSTRING-FILE < file" if (@ARGV < 2);
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
5
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
6 $top_srcdir = shift (@ARGV);
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
7
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
8 # Constant patterns
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
9 $doc_delim = qr/^\c_/;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
10 $tex_delim = qr/\Q-*- texinfo -*-\E/;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
11 $comment_line = qr/^\s*(?:$|#)/;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
12 # Pre-declare hash size for efficiency
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
13 keys(%help_text) = 1800;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
14
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
15 ################################################################################
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
16 # Load DOCSTRINGS into memory while expanding @seealso references
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
17 foreach $DOCSTRING_file (@ARGV)
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
18 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
19 open (DOCFH, $DOCSTRING_file) or die "Unable to open $DOCSTRING_file\n";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
20
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
21 # Skip comments
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
22 while (defined ($_ = <DOCFH>) and /$comment_line/o) {;}
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
23
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
24 # Validate DOCSTRING file format
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
25 die "invalid doc file format\n" if (! /$doc_delim/o);
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
26
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
27 do
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
28 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
29 chomp;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
30 $symbol = substr ($_,1);
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
31 $docstring = extract_docstring ();
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
32 if ($help_text{$symbol})
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
33 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
34 warn "ignoring duplicate entry for $symbol\n";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
35 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
36 else
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
37 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
38 $help_text{$symbol} = $docstring;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
39 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
40
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
41 } while (! eof);
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
42
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
43 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
44
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
45 ################################################################################
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
46 # Process .txi to .texi by expanding @DOCSTRING, @EXAMPLEFILE macros
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
47
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
48 # Add warning header
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
49 print '@c DO NOT EDIT! Generated automatically by munge-texi.',"\n\n";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
50
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
51 TXI_LINE: while (<STDIN>)
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
52 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
53 if (/^\s*\@DOCSTRING\((\S+)\)/)
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
54 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
55 $func = $1;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
56 $docstring = $help_text{$func};
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
57 if (! $docstring)
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
58 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
59 warn "no docstring entry for $func\n";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
60 next TXI_LINE;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
61 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
62
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
63 $func =~ s/^@/@@/; # Texinfo uses @@ to produce '@'
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
64 $docstring =~ s/^$tex_delim$/\@anchor{doc-$func}/m;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
65 print $docstring,"\n";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
66
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
67 next TXI_LINE;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
68 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
69 if (/^\s*\@EXAMPLEFILE\((\S+)\)/)
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
70 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
71 $fname = "$top_srcdir/examples/$1";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
72 print '@verbatim',"\n";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
73 open (EXAMPFH, $fname) or die "unable to open example file $fname\n";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
74 while (<EXAMPFH>)
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
75 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
76 print $_;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
77 print "\n" if (eof and substr ($_, -1) ne "\n");
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
78 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
79 close (EXAMPFH);
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
80 print '@end verbatim',"\n\n";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
81
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
82 next TXI_LINE;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
83 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
84
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
85 # pass ordinary lines straight through to output
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
86 print $_;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
87 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
88
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
89
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
90 ################################################################################
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
91 # Subroutines
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
92 ################################################################################
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
93 sub extract_docstring
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
94 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
95 my ($docstring, $arg_list, $func_list, $repl, $rest_of_line);
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
96
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
97 while (defined ($_ = <DOCFH>) and ! /$doc_delim/o)
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
98 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
99 # expand any @seealso references
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
100 if (m'^@seealso{')
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
101 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
102 # Join multiple lines until full macro body found
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
103 while (! /}/m) { $_ .= <DOCFH>; }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
104
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
105 ($arg_list, $rest_of_line) = m'^@seealso{(.*)}(.*)?'s;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
106
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
107 $func_list = $arg_list;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
108 $func_list =~ s/\s+//gs;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
109 $repl = "";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
110 foreach $func (split (/,/, $func_list))
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
111 {
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
112 $func =~ s/^@/@@/; # Texinfo uses @@ to produce '@'
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
113 $repl .= "\@ref{doc-$func,,$func}, ";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
114 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
115 substr($repl,-2) = ""; # Remove last ', '
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
116 $_ = "\@seealso{$repl}$rest_of_line";
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
117 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
118
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
119 $docstring .= $_;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
120 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
121
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
122 return $docstring;
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
123 }
1f1fc4798f0a doc: Produce .texi from .txi files using Perl rather than C++.
Rik <octave@nomad.inbox5.com>
parents:
diff changeset
124