# HG changeset patch # User Soren Hauberg # Date 1234427433 -3600 # Node ID d65a0a1780b68859d6902d316c779d06c90681dd # Parent e6a65a8605bc389afd2aef31ab4a192837db293e Simplify documentation cache generation to only handle one directory per call to 'gen_doc_cache' diff -r e6a65a8605bc -r d65a0a1780b6 scripts/ChangeLog --- a/scripts/ChangeLog Thu Feb 12 03:06:46 2009 -0500 +++ b/scripts/ChangeLog Thu Feb 12 09:30:33 2009 +0100 @@ -1,3 +1,8 @@ +2009-02-12 Soren Hauberg + + * help/gen_doc_cache.m: Change API so we only handle one directory per + call to this function. + 2009-02-12 Soren Hauberg * help/lookfor.m: Adapt to new cache scheme. diff -r e6a65a8605bc -r d65a0a1780b6 scripts/help/gen_doc_cache.m --- a/scripts/help/gen_doc_cache.m Thu Feb 12 03:06:46 2009 -0500 +++ b/scripts/help/gen_doc_cache.m Thu Feb 12 09:30:33 2009 +0100 @@ -15,37 +15,36 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} gen_doc_cache () -## @deftypefnx{Function File} gen_doc_cache (@var{directory}) +## @deftypefn {Function File} gen_doc_cache (@var{out_file}, @var{directory}) ## Generate documentation caches for all functions in a given directory. ## ## A documentation cache is generated for all functions in @var{directory}. The -## resulting cache is saved in the file @code{help_cache.mat} in @var{directory}. +## resulting cache is saved in the file @var{out_file}. ## The cache is used to speed up @code{lookfor}. -## If no directory is given, all directories in the current path is traversed. +## +## If no directory is given (or it is the empty matrix), a cache for builtin +## operators, etc. is generated. ## ## @seealso{lookfor, path} ## @end deftypefn -function gen_doc_cache (p = path ()) - if (!ischar (p)) +function gen_doc_cache (out_file = "DOC.gz", directory = []) + ## Check input + if (!ischar (out_file)) print_usage (); endif - ## Generate caches for all directories in path - idx = find (p == pathsep ()); - prev_idx = 1; - for n = 1:length (idx) - f = p (prev_idx:idx (n)-1); - gen_doc_cache_in_dir (f); - prev_idx = idx (n) + 1; - endfor - - ## Generate cache for keywords, operators, and builtins if we're handling the - ## entire path - if (nargin == 0) - gen_builtin_cache (); + ## Generate cache + if (isempty (directory)) + cache = gen_builtin_cache (); + elseif (ischar (directory)) + cache = gen_doc_cache_in_dir (directory); + else + error ("gen_doc_cache: second input argument must be a string"); endif + + ## Save cache + save ("-text", "-z", out_file, "cache"); endfunction function [text, first_sentence, status] = handle_function (f, text, format) @@ -102,7 +101,7 @@ endfor endfunction -function gen_doc_cache_in_dir (directory) +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 (); @@ -125,27 +124,17 @@ list = __list_functions__ (directory); cache = create_cache (list); - ## Write the cache - fn = fullfile (directory, "help_cache.mat"); - save ("-binary", fn, "cache"); # FIXME: Should we zip it ? - if (!dir_in_path) rmpath (directory); endif endfunction -function gen_builtin_cache () +function cache = gen_builtin_cache () operators = __operators__ (); keywords = __keywords__ (); builtins = __builtins__ (); list = {operators{:}, keywords{:}, builtins{:}}; cache = create_cache (list); - - ## Write the cache - ## FIXME: Where should we store this cache? - ## FIXME: if we change it -- update 'lookfor' - fn = fullfile (octave_config_info.datadir, "builtin_cache.mat"); - save ("-binary", fn, "cache"); # FIXME: Should we zip it ? endfunction