annotate scripts/testfun/rundemos.m @ 10549:95c3e38098bf

Untabify .m scripts
author Rik <code@nomad.inbox5.com>
date Fri, 23 Apr 2010 11:28:50 -0700
parents eb63fbe60fab
children d1978e7364ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8877
diff changeset
1 ## Copyright (C) 2008, 2009 John W. Eaton
8229
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
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 ## Author: jwe
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 function rundemos (directory)
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 if (nargin == 0)
8877
2c8b2399247b implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
28 dirs = strsplit (path (), pathsep ());
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 elseif (nargin == 1)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 if (is_absolute_filename (directory))
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 dirs = {directory};
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 fullname = find_dir_in_path (directory);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 if (! isempty (fullname))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
35 dirs = {fullname};
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
37 error ("rundemos: expecting argument to be a directory name");
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
8231
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
44 for i = 1:numel (dirs)
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
45 d = dirs{i};
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
46 run_all_demos (d);
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
47 endfor
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
48
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 endfunction
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 function run_all_demos (directory)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 dirinfo = dir (directory);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 flist = {dirinfo.name};
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 for i = 1:numel (flist)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 f = flist{i};
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 if (length (f) > 2 && strcmp (f((end-1):end), ".m"))
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 f = fullfile (directory, f);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 if (has_demos (f))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
59 demo (f);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
60 if (i != numel (flist))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
61 input ("Press <enter> to continue: ", "s");
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
62 endif
8229
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 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 endfor
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 endfunction
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 function retval = has_demos (f)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 fid = fopen (f);
8699
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
70 if (f < 0)
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
71 error ("fopen failed: %s", f);
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
72 else
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
73 str = fscanf (fid, "%s");
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
74 fclose (fid);
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
75 retval = findstr (str, "%!demo");
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
76 endif
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 endfunction