Mercurial > octave-antonio
annotate scripts/testfun/rundemos.m @ 8231:df28b55d03c0
make rundemos with no arguments work
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 16 Oct 2008 13:43:49 -0400 |
parents | 2ce2aef722c3 |
children | 166a689b77a9 |
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 else | |
43 print_usage (); | |
44 endif | |
45 | |
8231
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
46 for i = 1:numel (dirs) |
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
47 d = dirs{i}; |
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
48 run_all_demos (d); |
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
49 endfor |
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
50 |
8229 | 51 endfunction |
52 | |
53 function run_all_demos (directory) | |
54 dirinfo = dir (directory); | |
55 flist = {dirinfo.name}; | |
56 for i = 1:numel (flist) | |
57 f = flist{i}; | |
58 if (length (f) > 2 && strcmp (f((end-1):end), ".m")) | |
59 f = fullfile (directory, f); | |
60 if (has_demos (f)) | |
61 demo (f); | |
62 endif | |
63 endif | |
64 endfor | |
65 endfunction | |
66 | |
67 function retval = has_demos (f) | |
68 fid = fopen (f); | |
69 str = fscanf (fid, "%s"); | |
70 fclose (fid); | |
71 retval = findstr (str, "%!demo"); | |
72 endfunction |