Mercurial > hg > octave-lyh
annotate scripts/testfun/rundemos.m @ 8230:2ce2aef722c3
mark new rundemos function as command
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 16 Oct 2008 13:41:17 -0400 |
parents | 1bf51192fa1d |
children | df28b55d03c0 |
rev | line source |
---|---|
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 | |
8230
2ce2aef722c3
mark new rundemos function as command
John W. Eaton <jwe@octave.org>
parents:
8229
diff
changeset
|
23 ## PKG_ADD: mark_as_command rundemos |
2ce2aef722c3
mark new rundemos function as command
John W. Eaton <jwe@octave.org>
parents:
8229
diff
changeset
|
24 |
8229 | 25 ## Author: jwe |
26 | |
27 function rundemos (directory) | |
28 | |
29 if (nargin == 0) | |
30 dirs = cellstr (split (path (), pathsep ())); | |
31 elseif (nargin == 1) | |
32 if (is_absolute_filename (directory)) | |
33 dirs = {directory}; | |
34 else | |
35 fullname = find_dir_in_path (directory); | |
36 if (! isempty (fullname)) | |
37 dirs = {fullname}; | |
38 else | |
39 error ("rundemos: expecting argument to be a directory name"); | |
40 endif | |
41 endif | |
42 for i = 1:numel (dirs) | |
43 d = dirs{i}; | |
44 run_all_demos (d); | |
45 endfor | |
46 else | |
47 print_usage (); | |
48 endif | |
49 | |
50 endfunction | |
51 | |
52 function run_all_demos (directory) | |
53 dirinfo = dir (directory); | |
54 flist = {dirinfo.name}; | |
55 for i = 1:numel (flist) | |
56 f = flist{i}; | |
57 if (length (f) > 2 && strcmp (f((end-1):end), ".m")) | |
58 f = fullfile (directory, f); | |
59 if (has_demos (f)) | |
60 demo (f); | |
61 endif | |
62 endif | |
63 endfor | |
64 endfunction | |
65 | |
66 function retval = has_demos (f) | |
67 fid = fopen (f); | |
68 str = fscanf (fid, "%s"); | |
69 fclose (fid); | |
70 retval = findstr (str, "%!demo"); | |
71 endfunction |