8229
|
1 ## Copyright (C) 2008 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} rundemos (@var{directory}) |
|
21 ## @end deftypefn |
|
22 |
|
23 ## Author: jwe |
|
24 |
|
25 function rundemos (directory) |
|
26 |
|
27 if (nargin == 0) |
|
28 dirs = cellstr (split (path (), pathsep ())); |
|
29 elseif (nargin == 1) |
|
30 if (is_absolute_filename (directory)) |
|
31 dirs = {directory}; |
|
32 else |
|
33 fullname = find_dir_in_path (directory); |
|
34 if (! isempty (fullname)) |
|
35 dirs = {fullname}; |
|
36 else |
|
37 error ("rundemos: expecting argument to be a directory name"); |
|
38 endif |
|
39 endif |
|
40 for i = 1:numel (dirs) |
|
41 d = dirs{i}; |
|
42 run_all_demos (d); |
|
43 endfor |
|
44 else |
|
45 print_usage (); |
|
46 endif |
|
47 |
|
48 endfunction |
|
49 |
|
50 function run_all_demos (directory) |
|
51 dirinfo = dir (directory); |
|
52 flist = {dirinfo.name}; |
|
53 for i = 1:numel (flist) |
|
54 f = flist{i}; |
|
55 if (length (f) > 2 && strcmp (f((end-1):end), ".m")) |
|
56 f = fullfile (directory, f); |
|
57 if (has_demos (f)) |
|
58 demo (f); |
|
59 endif |
|
60 endif |
|
61 endfor |
|
62 endfunction |
|
63 |
|
64 function retval = has_demos (f) |
|
65 fid = fopen (f); |
|
66 str = fscanf (fid, "%s"); |
|
67 fclose (fid); |
|
68 retval = findstr (str, "%!demo"); |
|
69 endfunction |