annotate scripts/miscellaneous/run.m @ 12007:dc56a38b5a64 release-3-2-x

var.m: fix typos (thinkos?) in previous change
author John W. Eaton <jwe@octave.org>
date Tue, 23 Jun 2009 12:57:57 +0200
parents 4cb9f994dcec
children f22bbc5d56e9
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: 8746
diff changeset
1 ## Copyright (C) 2007, 2008, 2009 David Bateman
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
2 ##
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
4 ##
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6864
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6864
diff changeset
8 ## your option) any later version.
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
9 ##
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
14 ##
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6864
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6864
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
18
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
19 ## -*- texinfo -*-
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
20 ## @deftypefn {Function File} {} run (@var{f})
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
21 ## @deftypefnx {Command} {} run @var{f}
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
22 ## Run scripts in the current workspace that are not necessarily on the
9037
4cb9f994dcec Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
23 ## path. If @var{f} is the script to run, including its path, then @code{run}
4cb9f994dcec Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
24 ## change the directory to the directory where @var{f} is found. @code{run}
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
25 ## then executes the script, and returns to the original directory.
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
26 ## @seealso{system}
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
27 ## @end deftypefn
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
28
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
29 function run (s)
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
30
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
31 if (nargin != 1)
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
32 print_usage ();
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
33 endif
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
34
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
35 [d, f, ext] = fileparts (s);
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
36 if (! isempty (d))
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
37 if (exist (d, "dir"))
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
38 wd = pwd ();
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
39 unwind_protect
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
40 cd (d);
7672
2f0920d1edd4 run.m: fix check for file existence
Ben Abbott <bpabbott@mac.com>
parents: 7319
diff changeset
41 if (! exist (f, "file") || ! strcmp (ext, ".m"))
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
42 error ("run: file must exist and be a valid Octave script file");
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
43 endif
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
44 evalin ("caller", [f, ";"], "rethrow (lasterror ())");
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
45 unwind_protect_cleanup
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
46 cd (wd);
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
47 end_unwind_protect
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
48 else
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
49 error ("run: the path %s doesn't exist", d);
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
50 endif
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
51 else
7319
4a853a9138e7 [project @ 2007-12-17 19:16:27 by jwe]
jwe
parents: 7125
diff changeset
52 if (exist (f, "file"))
4a853a9138e7 [project @ 2007-12-17 19:16:27 by jwe]
jwe
parents: 7125
diff changeset
53 evalin ("caller", [f, ";"], "rethrow (lasterror ())");
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
54 else
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
55 error ("run: %s not found", s);
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
56 endif
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
57 endif
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents:
diff changeset
58 endfunction