Mercurial > hg > octave-lyh
comparison doc/interpreter/mk_doc_cache.m @ 8716:80910b37d855
generate DOC file for lookfor function
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 10 Feb 2009 17:04:20 -0500 |
parents | |
children | 28b8bd2f6e66 |
comparison
equal
deleted
inserted
replaced
8715:954b6f69f51d | 8716:80910b37d855 |
---|---|
1 ## Copyright (C) 2009 John W. Eaton | |
2 ## | |
3 ## This program is free software; you can redistribute it and/or modify it | |
4 ## under the terms of the GNU General Public License as published by | |
5 ## the Free Software Foundation; either version 3 of the License, or (at | |
6 ## your option) any later version. | |
7 ## | |
8 ## This program is distributed in the hope that it will be useful, but | |
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 ## General Public License for more details. | |
12 ## | |
13 ## You should have received a copy of the GNU General Public License | |
14 ## along with this program; see the file COPYING. If not, see | |
15 ## <http://www.gnu.org/licenses/>. | |
16 | |
17 args = argv (); | |
18 | |
19 if (nargin < 2) | |
20 error ("usage: mk_doc_cache OUTPUT-FILE DOCSTRINGS-FILE ..."); | |
21 endif | |
22 | |
23 output_file = args{1}; | |
24 docstrings_files = args(2:end); | |
25 | |
26 doc_delim = char (31); | |
27 | |
28 function str = skip_newline (str) | |
29 n = numel (str); | |
30 j = 1; | |
31 while (j <= n) | |
32 c = str(j); | |
33 if (c == "\r" || c == "\n") | |
34 j++; | |
35 else | |
36 break; | |
37 endif | |
38 endwhile | |
39 str = str(j:end); | |
40 endfunction | |
41 | |
42 doc_cache = []; | |
43 | |
44 for i = 1:numel (docstrings_files); | |
45 | |
46 file = docstrings_files{i}; | |
47 | |
48 fid = fopen (file, "r"); | |
49 | |
50 if (fid < 0) | |
51 error ("unable to open %s for reading", file); | |
52 else | |
53 | |
54 printf ("processing %s\n", file); | |
55 | |
56 text = fread (fid, Inf, "*char")'; | |
57 | |
58 delim_idx = find (text == doc_delim); | |
59 eof = numel (text); | |
60 idx = [delim_idx, eof]; | |
61 | |
62 n = numel (delim_idx); | |
63 | |
64 tmp_doc_cache = cell (3, n); | |
65 k = 1; | |
66 | |
67 for i = 1:n | |
68 | |
69 tmp = text(idx(i)+1:idx(i+1)-1); | |
70 | |
71 [symbol, doc] = strtok (tmp, "\r\n"); | |
72 | |
73 doc = skip_newline (doc); | |
74 | |
75 ## Skip functions that start with __ as these shouldn't be | |
76 ## searched by lookfor. | |
77 if (numel (symbol) > 2 && regexp (symbol, "^__.+__$")) | |
78 continue; | |
79 endif | |
80 | |
81 printf (" %s\n", symbol); | |
82 | |
83 if (strncmp (doc, "-*- texinfo -*-", 15)) | |
84 doc = skip_newline (doc(16:end)); | |
85 else | |
86 error ("doc string for %s is not in texinfo format", symbol); | |
87 endif | |
88 | |
89 [formatted_text, status] = makeinfo (doc, "plain text"); | |
90 | |
91 ## Did we get the help text? | |
92 if (status != 0 || isempty (formatted_text)) | |
93 error ("makeinfo failed for %s doc string", symbol); | |
94 endif | |
95 | |
96 ## Extract first line by searching for a period or a double | |
97 ## line-end. | |
98 | |
99 period_idx = find (formatted_text == ".", 1); | |
100 | |
101 line_end_idx = strfind (formatted_text, "\n\n"); | |
102 | |
103 max_first_sentence_len = 80; | |
104 | |
105 first_sentence = formatted_text (1:min ([period_idx(:); line_end_idx(:); max_first_sentence_len; numel(formatted_text)])); | |
106 | |
107 tmp_doc_cache{1,k} = symbol; | |
108 tmp_doc_cache{2,k} = formatted_text; | |
109 tmp_doc_cache{3,k} = first_sentence; | |
110 k++; | |
111 | |
112 endfor | |
113 | |
114 tmp_doc_cache(:,k:end) = []; | |
115 | |
116 endif | |
117 | |
118 doc_cache = [doc_cache, tmp_doc_cache]; | |
119 | |
120 save ("-text", output_file, "doc_cache"); | |
121 | |
122 endfor |