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