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
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 for i = 1:numel (dirs)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 d = dirs{i};
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 run_all_demos (d);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 endfor
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 endfunction
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 function run_all_demos (directory)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 dirinfo = dir (directory);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 flist = {dirinfo.name};
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 for i = 1:numel (flist)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 f = flist{i};
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 if (length (f) > 2 && strcmp (f((end-1):end), ".m"))
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 f = fullfile (directory, f);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 if (has_demos (f))
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 demo (f);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 endif
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 endfor
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 endfunction
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 function retval = has_demos (f)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 fid = fopen (f);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 str = fscanf (fid, "%s");
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 fclose (fid);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 retval = findstr (str, "%!demo");
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 endfunction