Mercurial > hg > octave-lyh
comparison scripts/help/gen_doc_cache.m @ 8729:d65a0a1780b6
Simplify documentation cache generation to only handle one directory per call to 'gen_doc_cache'
author | Soren Hauberg <hauberg@gmail.com> |
---|---|
date | Thu, 12 Feb 2009 09:30:33 +0100 |
parents | f134925a1cfa |
children | 257ed585b471 |
comparison
equal
deleted
inserted
replaced
8728:e6a65a8605bc | 8729:d65a0a1780b6 |
---|---|
13 ## You should have received a copy of the GNU General Public License | 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 | 14 ## along with this program; see the file COPYING. If not, see |
15 ## <http://www.gnu.org/licenses/>. | 15 ## <http://www.gnu.org/licenses/>. |
16 | 16 |
17 ## -*- texinfo -*- | 17 ## -*- texinfo -*- |
18 ## @deftypefn {Function File} gen_doc_cache () | 18 ## @deftypefn {Function File} gen_doc_cache (@var{out_file}, @var{directory}) |
19 ## @deftypefnx{Function File} gen_doc_cache (@var{directory}) | |
20 ## Generate documentation caches for all functions in a given directory. | 19 ## Generate documentation caches for all functions in a given directory. |
21 ## | 20 ## |
22 ## A documentation cache is generated for all functions in @var{directory}. The | 21 ## A documentation cache is generated for all functions in @var{directory}. The |
23 ## resulting cache is saved in the file @code{help_cache.mat} in @var{directory}. | 22 ## resulting cache is saved in the file @var{out_file}. |
24 ## The cache is used to speed up @code{lookfor}. | 23 ## The cache is used to speed up @code{lookfor}. |
25 ## If no directory is given, all directories in the current path is traversed. | 24 ## |
25 ## If no directory is given (or it is the empty matrix), a cache for builtin | |
26 ## operators, etc. is generated. | |
26 ## | 27 ## |
27 ## @seealso{lookfor, path} | 28 ## @seealso{lookfor, path} |
28 ## @end deftypefn | 29 ## @end deftypefn |
29 | 30 |
30 function gen_doc_cache (p = path ()) | 31 function gen_doc_cache (out_file = "DOC.gz", directory = []) |
31 if (!ischar (p)) | 32 ## Check input |
33 if (!ischar (out_file)) | |
32 print_usage (); | 34 print_usage (); |
33 endif | 35 endif |
34 | 36 |
35 ## Generate caches for all directories in path | 37 ## Generate cache |
36 idx = find (p == pathsep ()); | 38 if (isempty (directory)) |
37 prev_idx = 1; | 39 cache = gen_builtin_cache (); |
38 for n = 1:length (idx) | 40 elseif (ischar (directory)) |
39 f = p (prev_idx:idx (n)-1); | 41 cache = gen_doc_cache_in_dir (directory); |
40 gen_doc_cache_in_dir (f); | 42 else |
41 prev_idx = idx (n) + 1; | 43 error ("gen_doc_cache: second input argument must be a string"); |
42 endfor | |
43 | |
44 ## Generate cache for keywords, operators, and builtins if we're handling the | |
45 ## entire path | |
46 if (nargin == 0) | |
47 gen_builtin_cache (); | |
48 endif | 44 endif |
45 | |
46 ## Save cache | |
47 save ("-text", "-z", out_file, "cache"); | |
49 endfunction | 48 endfunction |
50 | 49 |
51 function [text, first_sentence, status] = handle_function (f, text, format) | 50 function [text, first_sentence, status] = handle_function (f, text, format) |
52 first_sentence = ""; | 51 first_sentence = ""; |
53 ## Skip functions that start with __ as these shouldn't be searched by lookfor | 52 ## Skip functions that start with __ as these shouldn't be searched by lookfor |
100 cache (2, end) = text; | 99 cache (2, end) = text; |
101 cache (3, end) = first_sentence; | 100 cache (3, end) = first_sentence; |
102 endfor | 101 endfor |
103 endfunction | 102 endfunction |
104 | 103 |
105 function gen_doc_cache_in_dir (directory) | 104 function cache = gen_doc_cache_in_dir (directory) |
106 ## If 'directory' is not in the current path, add it so we search it | 105 ## If 'directory' is not in the current path, add it so we search it |
107 dir_in_path = false; | 106 dir_in_path = false; |
108 p = path (); | 107 p = path (); |
109 idx = find (p == pathsep ()); | 108 idx = find (p == pathsep ()); |
110 prev_idx = 1; | 109 prev_idx = 1; |
123 | 122 |
124 ## Get list of functions in directory and create cache | 123 ## Get list of functions in directory and create cache |
125 list = __list_functions__ (directory); | 124 list = __list_functions__ (directory); |
126 cache = create_cache (list); | 125 cache = create_cache (list); |
127 | 126 |
128 ## Write the cache | |
129 fn = fullfile (directory, "help_cache.mat"); | |
130 save ("-binary", fn, "cache"); # FIXME: Should we zip it ? | |
131 | |
132 if (!dir_in_path) | 127 if (!dir_in_path) |
133 rmpath (directory); | 128 rmpath (directory); |
134 endif | 129 endif |
135 endfunction | 130 endfunction |
136 | 131 |
137 function gen_builtin_cache () | 132 function cache = gen_builtin_cache () |
138 operators = __operators__ (); | 133 operators = __operators__ (); |
139 keywords = __keywords__ (); | 134 keywords = __keywords__ (); |
140 builtins = __builtins__ (); | 135 builtins = __builtins__ (); |
141 list = {operators{:}, keywords{:}, builtins{:}}; | 136 list = {operators{:}, keywords{:}, builtins{:}}; |
142 | 137 |
143 cache = create_cache (list); | 138 cache = create_cache (list); |
144 | |
145 ## Write the cache | |
146 ## FIXME: Where should we store this cache? | |
147 ## FIXME: if we change it -- update 'lookfor' | |
148 fn = fullfile (octave_config_info.datadir, "builtin_cache.mat"); | |
149 save ("-binary", fn, "cache"); # FIXME: Should we zip it ? | |
150 endfunction | 139 endfunction |
151 | 140 |