Mercurial > hg > octave-nkf
comparison scripts/help/gen_doc_cache.m @ 11587:c792872f8942
all script files: untabify and strip trailing whitespace
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:35:29 -0500 |
parents | fd0a3ac60b0e |
children | d5bd2766c640 |
comparison
equal
deleted
inserted
replaced
11586:12df7854fa7c | 11587:c792872f8942 |
---|---|
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} gen_doc_cache (@var{out_file}, @var{directory}) | 20 ## @deftypefn {Function File} {} gen_doc_cache (@var{out_file}, @var{directory}) |
21 ## Generate documentation caches for all functions in a given directory. | 21 ## Generate documentation caches for all functions in a given directory. |
22 ## | 22 ## |
23 ## A documentation cache is generated for all functions in @var{directory}. | 23 ## A documentation cache is generated for all functions in @var{directory}. |
24 ## The | 24 ## The |
25 ## resulting cache is saved in the file @var{out_file}. | 25 ## resulting cache is saved in the file @var{out_file}. |
26 ## The cache is used to speed up @code{lookfor}. | 26 ## The cache is used to speed up @code{lookfor}. |
27 ## | 27 ## |
28 ## If no directory is given (or it is the empty matrix), a cache for builtin | 28 ## If no directory is given (or it is the empty matrix), a cache for builtin |
34 function gen_doc_cache (out_file = "doc-cache", directory = []) | 34 function gen_doc_cache (out_file = "doc-cache", directory = []) |
35 ## Check input | 35 ## Check input |
36 if (!ischar (out_file)) | 36 if (!ischar (out_file)) |
37 print_usage (); | 37 print_usage (); |
38 endif | 38 endif |
39 | 39 |
40 ## Generate cache | 40 ## Generate cache |
41 if (isempty (directory)) | 41 if (isempty (directory)) |
42 cache = gen_builtin_cache (); | 42 cache = gen_builtin_cache (); |
43 elseif (ischar (directory)) | 43 elseif (ischar (directory)) |
44 cache = gen_doc_cache_in_dir (directory); | 44 cache = gen_doc_cache_in_dir (directory); |
45 else | 45 else |
46 error ("gen_doc_cache: second input argument must be a string"); | 46 error ("gen_doc_cache: second input argument must be a string"); |
47 endif | 47 endif |
48 | 48 |
49 ## Save cache | 49 ## Save cache |
50 if (! isempty (cache)) | 50 if (! isempty (cache)) |
51 save ("-text", out_file, "cache"); | 51 save ("-text", out_file, "cache"); |
52 endif | 52 endif |
53 endfunction | 53 endfunction |
69 case "html" | 69 case "html" |
70 [text, status] = strip_html_tags (text); | 70 [text, status] = strip_html_tags (text); |
71 otherwise | 71 otherwise |
72 status = 1; | 72 status = 1; |
73 endswitch | 73 endswitch |
74 | 74 |
75 ## Did we get the help text? | 75 ## Did we get the help text? |
76 if (status != 0 || isempty (text)) | 76 if (status != 0 || isempty (text)) |
77 warning ("gen_doc_cache: unusable help text in '%s'. Ignoring function.", f); | 77 warning ("gen_doc_cache: unusable help text in '%s'. Ignoring function.", f); |
78 return; | 78 return; |
79 endif | 79 endif |
82 first_sentence = get_first_help_sentence (f); | 82 first_sentence = get_first_help_sentence (f); |
83 endfunction | 83 endfunction |
84 | 84 |
85 function cache = create_cache (list) | 85 function cache = create_cache (list) |
86 cache = {}; | 86 cache = {}; |
87 | 87 |
88 ## For each function: | 88 ## For each function: |
89 for n = 1:length (list) | 89 for n = 1:length (list) |
90 f = list {n}; | 90 f = list {n}; |
91 | 91 |
92 ## Get help text | 92 ## Get help text |
93 [text, format] = get_help_text (f); | 93 [text, format] = get_help_text (f); |
94 | 94 |
95 [text, first_sentence, status] = handle_function (f, text, format); | 95 [text, first_sentence, status] = handle_function (f, text, format); |
96 | 96 |
97 ## Did we get the help text? | 97 ## Did we get the help text? |
98 if (status != 0) | 98 if (status != 0) |
99 continue; | 99 continue; |
100 endif | 100 endif |
101 | 101 |
102 ## Store the help text | 102 ## Store the help text |
103 cache (1, end+1) = f; | 103 cache (1, end+1) = f; |
104 cache (2, end) = text; | 104 cache (2, end) = text; |
105 cache (3, end) = first_sentence; | 105 cache (3, end) = first_sentence; |
106 endfor | 106 endfor |
118 dir_in_path = true; | 118 dir_in_path = true; |
119 break; | 119 break; |
120 endif | 120 endif |
121 prev_idx = idx (n) + 1; | 121 prev_idx = idx (n) + 1; |
122 endfor | 122 endfor |
123 | 123 |
124 if (!dir_in_path) | 124 if (!dir_in_path) |
125 addpath (directory); | 125 addpath (directory); |
126 endif | 126 endif |
127 | 127 |
128 ## Get list of functions in directory and create cache | 128 ## Get list of functions in directory and create cache |
129 list = __list_functions__ (directory); | 129 list = __list_functions__ (directory); |
130 cache = create_cache (list); | 130 cache = create_cache (list); |
131 | 131 |
132 if (!dir_in_path) | 132 if (!dir_in_path) |
133 rmpath (directory); | 133 rmpath (directory); |
134 endif | 134 endif |
135 endfunction | 135 endfunction |
136 | 136 |