comparison scripts/help/gen_doc_cache.m @ 14486:6bed5141fdad

Let gen_doc_cache_in_dir accept multiple directories as input. * scripts/help/gen_doc_cache.m: Allow a cell array with multiple dir names to be passed as input.
author Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
date Thu, 22 Mar 2012 11:27:56 +0100
parents 72c96de7a403
children 86854d032a37
comparison
equal deleted inserted replaced
14483:6a736395ff7d 14486:6bed5141fdad
39 endif 39 endif
40 40
41 ## Generate cache 41 ## Generate cache
42 if (isempty (directory)) 42 if (isempty (directory))
43 cache = gen_builtin_cache (); 43 cache = gen_builtin_cache ();
44 elseif (iscell (directory))
45 if all(cellfun (@ischar, directory))
46 cache = gen_doc_cache_in_dir (directory);
47 else
48 error ("gen_doc_cache: cell must contain only strings");
49 end
44 elseif (ischar (directory)) 50 elseif (ischar (directory))
45 cache = gen_doc_cache_in_dir (directory); 51 cache = gen_doc_cache_in_dir (directory);
46 else 52 else
47 error ("gen_doc_cache: second input argument must be a string"); 53 error ("gen_doc_cache: second input argument must be a string or a cell of strings");
48 endif 54 endif
49 55
50 ## Save cache 56 ## Save cache
51 if (! isempty (cache)) 57 if (! isempty (cache))
52 save ("-text", out_file, "cache"); 58 save ("-text", out_file, "cache");
53 endif 59 endif
60
54 endfunction 61 endfunction
55 62
56 function [text, first_sentence, status] = handle_function (f, text, format) 63 function [text, first_sentence, status] = handle_function (f, text, format)
57 first_sentence = ""; 64 first_sentence = "";
58 ## Skip functions that start with __ as these shouldn't be searched by lookfor 65 ## Skip functions that start with __ as these shouldn't be searched by lookfor
106 cache (3, end) = first_sentence; 113 cache (3, end) = first_sentence;
107 endfor 114 endfor
108 endfunction 115 endfunction
109 116
110 function cache = gen_doc_cache_in_dir (directory) 117 function cache = gen_doc_cache_in_dir (directory)
118
111 ## If 'directory' is not in the current path, add it so we search it 119 ## If 'directory' is not in the current path, add it so we search it
112 dir_in_path = false; 120 dir_in_path = ismember (directory, strsplit (path (), pathsep ()));
113 p = path ();
114 idx = find (p == pathsep ());
115 prev_idx = 1;
116 for n = 1:length (idx)
117 f = p (prev_idx:idx (n)-1);
118 if (strcmp (f, directory))
119 dir_in_path = true;
120 break;
121 endif
122 prev_idx = idx (n) + 1;
123 endfor
124 121
125 if (!dir_in_path) 122 # dirs not in path
126 addpath (directory); 123 if !iscell (directory)
127 endif 124 directory = {directory};
125 end
126 dirs_notpath = {directory{!dir_in_path}};
128 127
129 ## Get list of functions in directory and create cache 128 # add them
130 list = __list_functions__ (directory); 129 if !isempty (dirs_notpath)
131 cache = create_cache (list); 130 cellfun (@addpath, dirs_notpath);
131 end
132 132
133 if (!dir_in_path) 133 # create cache
134 rmpath (directory); 134 func = @(s_) create_cache (__list_functions__ (s_));
135 endif 135 cache = cellfun (func, directory, 'UniformOutput', false);
136
137 # concatenate results
138 cache = [cache{:}];
139
140 #remove dirs form path
141 if !isempty (dirs_notpath)
142 cellfun (@rmpath, dirs_notpath);
143 end
144
136 endfunction 145 endfunction
137 146
138 function cache = gen_builtin_cache () 147 function cache = gen_builtin_cache ()
139 operators = __operators__ (); 148 operators = __operators__ ();
140 keywords = __keywords__ (); 149 keywords = __keywords__ ();
146 155
147 156
148 %% No true tests desirable for this function. 157 %% No true tests desirable for this function.
149 %% Test input validation 158 %% Test input validation
150 %!error gen_doc_cache (1) 159 %!error gen_doc_cache (1)
151