Mercurial > hg > octave-nkf
changeset 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 | 6a736395ff7d |
children | a467f3e04b7a |
files | scripts/help/gen_doc_cache.m |
diffstat | 1 files changed, 33 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/help/gen_doc_cache.m +++ b/scripts/help/gen_doc_cache.m @@ -41,16 +41,23 @@ ## Generate cache if (isempty (directory)) cache = gen_builtin_cache (); + elseif (iscell (directory)) + if all(cellfun (@ischar, directory)) + cache = gen_doc_cache_in_dir (directory); + else + error ("gen_doc_cache: cell must contain only strings"); + end elseif (ischar (directory)) - cache = gen_doc_cache_in_dir (directory); + cache = gen_doc_cache_in_dir (directory); else - error ("gen_doc_cache: second input argument must be a string"); + error ("gen_doc_cache: second input argument must be a string or a cell of strings"); endif ## Save cache if (! isempty (cache)) - save ("-text", out_file, "cache"); + save ("-text", out_file, "cache"); endif + endfunction function [text, first_sentence, status] = handle_function (f, text, format) @@ -108,31 +115,33 @@ endfunction function cache = gen_doc_cache_in_dir (directory) + ## If 'directory' is not in the current path, add it so we search it - dir_in_path = false; - p = path (); - idx = find (p == pathsep ()); - prev_idx = 1; - for n = 1:length (idx) - f = p (prev_idx:idx (n)-1); - if (strcmp (f, directory)) - dir_in_path = true; - break; - endif - prev_idx = idx (n) + 1; - endfor + dir_in_path = ismember (directory, strsplit (path (), pathsep ())); + + # dirs not in path + if !iscell (directory) + directory = {directory}; + end + dirs_notpath = {directory{!dir_in_path}}; + + # add them + if !isempty (dirs_notpath) + cellfun (@addpath, dirs_notpath); + end - if (!dir_in_path) - addpath (directory); - endif + # create cache + func = @(s_) create_cache (__list_functions__ (s_)); + cache = cellfun (func, directory, 'UniformOutput', false); - ## Get list of functions in directory and create cache - list = __list_functions__ (directory); - cache = create_cache (list); + # concatenate results + cache = [cache{:}]; - if (!dir_in_path) - rmpath (directory); - endif + #remove dirs form path + if !isempty (dirs_notpath) + cellfun (@rmpath, dirs_notpath); + end + endfunction function cache = gen_builtin_cache () @@ -148,4 +157,3 @@ %% No true tests desirable for this function. %% Test input validation %!error gen_doc_cache (1) -