Mercurial > octave-antonio
annotate scripts/miscellaneous/run.m @ 20164:df437a52bcaf stable
doc: Update more docstrings to have one sentence summary as first line.
Reviewed miscellaneous, sparse, strings in scripts directory.
* scripts/miscellaneous/bzip2.m, scripts/miscellaneous/citation.m,
scripts/miscellaneous/compare_versions.m, scripts/miscellaneous/computer.m,
scripts/miscellaneous/debug.m, scripts/miscellaneous/dir.m,
scripts/miscellaneous/edit.m, scripts/miscellaneous/error_ids.m,
scripts/miscellaneous/fileattrib.m, scripts/miscellaneous/fullfile.m,
scripts/miscellaneous/genvarname.m, scripts/miscellaneous/gzip.m,
scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/news.m,
scripts/miscellaneous/open.m, scripts/miscellaneous/parseparams.m,
scripts/miscellaneous/recycle.m, scripts/miscellaneous/run.m,
scripts/miscellaneous/swapbytes.m, scripts/miscellaneous/tar.m,
scripts/miscellaneous/tmpnam.m, scripts/miscellaneous/unpack.m,
scripts/miscellaneous/what.m, scripts/sparse/bicg.m, scripts/sparse/bicgstab.m,
scripts/sparse/cgs.m, scripts/sparse/colperm.m, scripts/sparse/eigs.m,
scripts/sparse/etreeplot.m, scripts/sparse/gmres.m, scripts/sparse/gplot.m,
scripts/sparse/ichol.m, scripts/sparse/ilu.m, scripts/sparse/pcg.m,
scripts/sparse/pcr.m, scripts/sparse/qmr.m, scripts/sparse/spaugment.m,
scripts/sparse/spconvert.m, scripts/sparse/spdiags.m, scripts/sparse/spfun.m,
scripts/sparse/spones.m, scripts/sparse/sprandsym.m, scripts/sparse/spstats.m,
scripts/sparse/spy.m, scripts/sparse/svds.m, scripts/sparse/treelayout.m,
scripts/sparse/treeplot.m, scripts/strings/base2dec.m,
scripts/strings/bin2dec.m, scripts/strings/blanks.m, scripts/strings/cstrcat.m,
scripts/strings/deblank.m, scripts/strings/dec2base.m,
scripts/strings/dec2bin.m, scripts/strings/dec2hex.m,
scripts/strings/findstr.m, scripts/strings/hex2dec.m, scripts/strings/index.m,
scripts/strings/isletter.m, scripts/strings/isstrprop.m,
scripts/strings/mat2str.m, scripts/strings/ostrsplit.m,
scripts/strings/regexptranslate.m, scripts/strings/rindex.m,
scripts/strings/str2num.m, scripts/strings/strcat.m, scripts/strings/strchr.m,
scripts/strings/strjoin.m, scripts/strings/strjust.m,
scripts/strings/strmatch.m, scripts/strings/strsplit.m,
scripts/strings/strtok.m, scripts/strings/strtrim.m,
scripts/strings/strtrunc.m, scripts/strings/substr.m,
scripts/strings/untabify.m, scripts/time/datenum.m:
Update more docstrings to have one sentence summary as first line.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 04 May 2015 14:22:02 -0700 |
parents | 10392528396c |
children |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
1 ## Copyright (C) 2007-2015 David Bateman |
6863 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6863 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6863 | 18 |
19 ## -*- texinfo -*- | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11395
diff
changeset
|
20 ## @deftypefn {Command} {} run @var{script} |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
21 ## @deftypefnx {Function File} {} run ("@var{script}") |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
22 ## Run @var{script} in the current workspace. |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
23 ## |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19996
diff
changeset
|
24 ## Scripts which reside in directories specified in Octave's load path, and |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19996
diff
changeset
|
25 ## which end with the extension @file{".m"}, can be run simply by typing |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19996
diff
changeset
|
26 ## their name. For scripts not located on the load path, use @code{run}. |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
27 ## |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
28 ## The file name @var{script} can be a bare, fully qualified, or relative |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
29 ## filename and with or without a file extension. If no extension is specified, |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
30 ## Octave will first search for a script with the @file{".m"} extension before |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
31 ## falling back to the script name without an extension. |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
32 ## |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
33 ## Implementation Note: If @var{script} includes a path component, then |
18445
1363d909c577
run.m: Don't undo changes to current dir done by script that was run (bug #41543).
Felipe G. Nievinski <fgnievinski@gmail.com>
parents:
17744
diff
changeset
|
34 ## @code{run} first changes the working directory to the directory where |
1363d909c577
run.m: Don't undo changes to current dir done by script that was run (bug #41543).
Felipe G. Nievinski <fgnievinski@gmail.com>
parents:
17744
diff
changeset
|
35 ## @var{script} is found. Next, the script is executed. Finally, @code{run} |
1363d909c577
run.m: Don't undo changes to current dir done by script that was run (bug #41543).
Felipe G. Nievinski <fgnievinski@gmail.com>
parents:
17744
diff
changeset
|
36 ## returns to the original working directory unless @code{script} has |
1363d909c577
run.m: Don't undo changes to current dir done by script that was run (bug #41543).
Felipe G. Nievinski <fgnievinski@gmail.com>
parents:
17744
diff
changeset
|
37 ## specifically changed directories. |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
38 ## @seealso{path, addpath, source} |
6863 | 39 ## @end deftypefn |
40 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11395
diff
changeset
|
41 function run (script) |
7125 | 42 |
43 if (nargin != 1) | |
44 print_usage (); | |
45 endif | |
46 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11395
diff
changeset
|
47 [d, f, ext] = fileparts (script); |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
48 if (! strcmp (ext, ".m")) |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
49 ## prefer files with .m extension for compatibility with Matlab |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
50 if (exist ([script ".m"], "file")) |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
51 f = [f ext]; |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
52 ext = ".m"; |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
53 script = [script ".m"]; |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
54 endif |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
55 endif |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
56 |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
57 if (! exist (script, "file")) |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
58 error ("run: file SCRIPT must exist and be a valid Octave scriptfile"); |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
59 endif |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
60 |
6863 | 61 if (! isempty (d)) |
62 if (exist (d, "dir")) | |
19282
a834b3151c7e
run.m: Return to the intial directory, unless the pwd is changed (Bug #43426).
Andy Weber <andreas.weber@hs-offenburg.de>
parents:
18445
diff
changeset
|
63 startdir = pwd (); |
a834b3151c7e
run.m: Return to the intial directory, unless the pwd is changed (Bug #43426).
Andy Weber <andreas.weber@hs-offenburg.de>
parents:
18445
diff
changeset
|
64 d = canonicalize_file_name (d); |
6863 | 65 unwind_protect |
10549 | 66 cd (d); |
19996
10392528396c
run.m: Use single quotes so that '\' isn't an escape sequence (bug #44671).
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
67 evalin ("caller", sprintf ("source ('%s%s');", f, ext), |
11395
0754a4e271f4
run.m: use source to execute script
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
68 "rethrow (lasterror ())"); |
6863 | 69 unwind_protect_cleanup |
18445
1363d909c577
run.m: Don't undo changes to current dir done by script that was run (bug #41543).
Felipe G. Nievinski <fgnievinski@gmail.com>
parents:
17744
diff
changeset
|
70 if (strcmp (d, pwd ())) |
19282
a834b3151c7e
run.m: Return to the intial directory, unless the pwd is changed (Bug #43426).
Andy Weber <andreas.weber@hs-offenburg.de>
parents:
18445
diff
changeset
|
71 cd (startdir); |
18445
1363d909c577
run.m: Don't undo changes to current dir done by script that was run (bug #41543).
Felipe G. Nievinski <fgnievinski@gmail.com>
parents:
17744
diff
changeset
|
72 endif |
6863 | 73 end_unwind_protect |
74 else | |
75 error ("run: the path %s doesn't exist", d); | |
76 endif | |
77 else | |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
78 if (! isempty (ext)) |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
79 script = which (script); |
6863 | 80 else |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
81 ## Search PATH with null extension ('.' will be stripped and ext = "") |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
82 script = which ([script "."]); |
6863 | 83 endif |
19996
10392528396c
run.m: Use single quotes so that '\' isn't an escape sequence (bug #44671).
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
84 evalin ("caller", sprintf ("source ('%s');", script), |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
85 "rethrow (lasterror ())"); |
6863 | 86 endif |
87 endfunction | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
88 |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
89 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
90 ## Test input validation |
17711
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
91 %!error run () |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
92 %!error run ("a", "b") |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
93 %!error <SCRIPT must exist> run ("__A_very_#unlikely#_file_name__") |
9ccb48d39ce9
run.m: append .m extension when none was provided.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
17338
diff
changeset
|
94 |