annotate doc/interpreter/mk_doc_cache.m @ 12254:23385f2c90b7 release-3-4-x

whitespace fixes
author John W. Eaton <jwe@octave.org>
date Wed, 26 Jan 2011 23:49:42 -0500
parents fd0a3ac60b0e
children f5535b401c83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
1 ## Copyright (C) 2009-2011 John W. Eaton
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 ## This program is free software; you can redistribute it and/or modify it
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ## under the terms of the GNU General Public License as published by
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 ## the Free Software Foundation; either version 3 of the License, or (at
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## your option) any later version.
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ##
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## This program is distributed in the hope that it will be useful, but
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 ## General Public License for more details.
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 ##
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ## You should have received a copy of the GNU General Public License
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ## along with this program; see the file COPYING. If not, see
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## <http://www.gnu.org/licenses/>.
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 args = argv ();
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 if (nargin < 2)
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 error ("usage: mk_doc_cache OUTPUT-FILE DOCSTRINGS-FILE ...");
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 endif
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 output_file = args{1};
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 docstrings_files = args(2:end);
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
26 ## Special character used as break between DOCSTRINGS
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 doc_delim = char (31);
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
29 ## Read the contents of all the DOCSTRINGS files into TEXT.
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
30 ## It is more efficient to fork to shell for makeinfo only once on large data
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
32 nfiles = numel (docstrings_files);
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
33 text = cell (1, nfiles+1);
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
34 for i = 1:nfiles
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 file = docstrings_files{i};
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 fid = fopen (file, "r");
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 if (fid < 0)
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 error ("unable to open %s for reading", file);
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 else
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
40 tmp = fread (fid, Inf, "*char")';
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
41 ## Strip off header lines
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
42 [null, text{i}] = strtok (tmp, doc_delim);
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
43 endif
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
44 endfor
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
45 text = [text{:}, doc_delim];
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
47 ## Modify Octave-specific macros before passing to makeinfo
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11020
diff changeset
48 text = regexprep (text, '@seealso *\{([^}]*)\}', "See also: $1.");
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11020
diff changeset
49 text = regexprep (text, '@nospell *\{([^}]*)\}', "$1");
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
50 text = regexprep (text, "-\\*- texinfo -\\*-[ \t]*[\r\n]*", "");
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11020
diff changeset
51 text = regexprep (text, '@', "@@");
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
53 ## Write data to temporary file for input to makeinfo
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
54 [fid, name, msg] = mkstemp ("octave_doc_XXXXXX", true);
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
55 if (fid < 0)
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
56 error ("%s: %s\n", name, msg);
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
57 endif
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
58 fwrite (fid, text, "char");
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
59 fclose (fid);
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
60
8720
dda421a1f1e6 doc/interpreter/mk_doc_cache.m: pass --fill-column=1024 to makeinfo
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
61 cmd = sprintf ("%s --no-headers --no-warn --force --no-validate --fill-column=1024 %s",
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
62 makeinfo_program (), name);
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
63
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
64 [status, formatted_text] = system (cmd);
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
66 ## Did we get the help text?
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
67 if (status != 0)
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
68 error ("makeinfo failed with exit status %d!", status);
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
69 endif
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
71 if (isempty (formatted_text))
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
72 error ("makeinfo produced no output!");
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
73 endif
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
75 ## Break apart output and store in cache variable
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
76 delim_idx = find (formatted_text == doc_delim);
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
77 n = length (delim_idx);
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
79 cache = cell (3, n); # pre-allocate storage for efficiency
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
80 k = 1;
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
82 for i = 2:n
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
84 block = formatted_text(delim_idx(i-1)+1:delim_idx(i)-1);
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
86 [symbol, doc] = strtok (block, "\r\n");
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
87
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
88 doc = regexprep (doc, "^[\r\n]+", '');
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
12254
23385f2c90b7 whitespace fixes
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
90 ## Skip internal functions that start with __ as these aren't
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
91 ## indexed by lookfor.
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11020
diff changeset
92 if (length (symbol) > 2 && regexp (symbol, '^__.+__$'))
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
93 continue;
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 endif
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
96 if (isempty (doc))
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
97 continue;
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
98 endif
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
99
11020
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
100 tmp = doc;
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
101 found = 0;
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
102 do
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
103 [s, e] = regexp (tmp, "^ -- [^\r\n]*[\r\n]");
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
104 if (! isempty(s))
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
105 found = 1;
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
106 tmp = tmp(e+1:end);
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
107 endif
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
108 until (isempty (s))
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
109
11020
a2773763e3ff Remove requirement for PCRE to build doc-cache.
Rik <octave@nomad.inbox5.com>
parents: 10802
diff changeset
110 if (! found)
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
111 continue;
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
112 endif
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
113
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11020
diff changeset
114 end_of_first_sentence = regexp (tmp, "(\\.|[\r\n][\r\n])", "once");
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
115 if (isempty (end_of_first_sentence))
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
116 end_of_first_sentence = length (tmp);
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
117 else
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
118 end_of_first_sentence = end_of_first_sentence;
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
119 endif
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
120
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
121 first_sentence = tmp(1:end_of_first_sentence);
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11020
diff changeset
122 first_sentence = regexprep (first_sentence, "([\r\n]| {2,})", " ");
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 11020
diff changeset
123 first_sentence = regexprep (first_sentence, '^ +', "");
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
125 cache{1,k} = symbol;
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
126 cache{2,k} = doc;
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
127 cache{3,k} = first_sentence;
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
128 k++;
8716
80910b37d855 generate DOC file for lookfor function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 endfor
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
130
10802
c7475803e0c0 mk_doc_cache.m: Use regexp rather than fussing with character arrays
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
131 cache(:,k:end) = []; # delete unused pre-allocated entries
8717
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
132
28b8bd2f6e66 doc/interpreter/mk_doc_cache.m: improve performance
John W. Eaton <jwe@octave.org>
parents: 8716
diff changeset
133 save ("-text", output_file, "cache");