# HG changeset patch # User Juan Pablo Carbajal # Date 1332412076 -3600 # Node ID 6bed5141fdadcc03232e87af6c32e7a2603eb7fa # Parent 6a736395ff7d0ee577ea80336eec367b99b4441e 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. diff --git a/scripts/help/gen_doc_cache.m b/scripts/help/gen_doc_cache.m --- 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) -