Mercurial > octave
annotate libinterp/corefcn/utils.cc @ 27923:bd51beb6205e
update formatting of copyright notices
* Use <https://octave.org/copyright/> instead of
<https://octave.org/COPYRIGHT.html/>.
* For consistency with other comments in the Octave sources, use
C++-style comments for copyright blocks in C and C++ files.
* Use delimiters above and below copyright blocks that are appropriate
for the language used in the file.
* Eliminate extra spacing inside copyright blocks.
* lex.ll (looks_like_copyright): Also allow newlines and carriage
returns before the word "Copyright".
* scripts/mk-doc.pl (gethelp): Also skip empty comment lines.
* bp-table.cc, type.m: Adjust tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Jan 2020 11:59:41 -0500 |
parents | 1891570abac8 |
children | 9a965fec21c1 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 1993-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
1 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
1 | 28 #endif |
29 | |
3716 | 30 #include <cerrno> |
1346 | 31 #include <cstring> |
1343 | 32 |
3503 | 33 #include <fstream> |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
34 #include <limits> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25173
diff
changeset
|
35 #include <ostream> |
1728 | 36 #include <string> |
37 | |
3040 | 38 #include "dir-ops.h" |
39 #include "file-ops.h" | |
2926 | 40 #include "file-stat.h" |
4732 | 41 #include "lo-mappers.h" |
11006
aca961a3f387
provide gethostname function
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
42 #include "lo-utils.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
43 #include "nanosleep-wrapper.h" |
1651 | 44 #include "oct-cmplx.h" |
2926 | 45 #include "oct-env.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19152
diff
changeset
|
46 #include "oct-locbuf.h" |
27279
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
47 #include "oct-string.h" |
3040 | 48 #include "pathsearch.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19152
diff
changeset
|
49 #include "quit.h" |
1755 | 50 #include "str-vec.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
51 #include "vasprintf-wrapper.h" |
1651 | 52 |
4216 | 53 #include "Cell.h" |
1352 | 54 #include "defun.h" |
55 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21041
diff
changeset
|
56 #include "errwarn.h" |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
57 #include "graphics.h" |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
58 #include "interpreter-private.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
59 #include "interpreter.h" |
10502
f13bf183a003
isvarname: keywords are not valid variable names
Judd Storrs <jstorrs@gmail.com>
parents:
10315
diff
changeset
|
60 #include "lex.h" |
5832 | 61 #include "load-path.h" |
5465 | 62 #include "oct-errno.h" |
1742 | 63 #include "oct-hist.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
64 #include "ovl.h" |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10605
diff
changeset
|
65 #include "ov-range.h" |
1352 | 66 #include "pager.h" |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10502
diff
changeset
|
67 #include "parse.h" |
1690 | 68 #include "sysdep.h" |
1 | 69 #include "unwind-prot.h" |
1352 | 70 #include "utils.h" |
71 #include "variables.h" | |
1 | 72 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
73 namespace octave |
4143 | 74 { |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
75 // Return TRUE if S is a valid identifier. |
4143 | 76 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
77 bool valid_identifier (const char *s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
78 { |
26203
3c445cd7f1a4
Don't accept '$' as a valid character in variable names.
Rik <rik@octave.org>
parents:
26059
diff
changeset
|
79 if (! s || ! (isalpha (*s) || *s == '_')) |
4143 | 80 return false; |
81 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
82 while (*++s != '\0') |
26203
3c445cd7f1a4
Don't accept '$' as a valid character in variable names.
Rik <rik@octave.org>
parents:
26059
diff
changeset
|
83 if (! (isalnum (*s) || *s == '_')) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
84 return false; |
4143 | 85 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
86 return true; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
87 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
88 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
89 bool valid_identifier (const std::string& s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
90 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
91 return valid_identifier (s.c_str ()); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
92 } |
4143 | 93 } |
94 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8715
diff
changeset
|
95 DEFUN (isvarname, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
96 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
97 @deftypefn {} {} isvarname (@var{name}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
98 Return true if @var{name} is a valid variable name. |
26204
82b9b970ff19
doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents:
26203
diff
changeset
|
99 |
82b9b970ff19
doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents:
26203
diff
changeset
|
100 A valid variable name is composed of letters, digits, and underscores ("_"), |
82b9b970ff19
doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents:
26203
diff
changeset
|
101 and the first character must not be a digit. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
102 @seealso{iskeyword, exist, who} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
103 @end deftypefn */) |
4264 | 104 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
105 if (args.length () != 1) |
5823 | 106 print_usage (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
107 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
108 octave_value retval = false; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
109 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
110 if (args(0).is_string ()) |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
111 { |
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
112 std::string varname = args(0).string_value (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
113 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
114 retval = (octave::valid_identifier (varname) |
26059
da2bbcf1fbcd
Deprecate C++ function is_keyword in favor of iskeyword for readability.
Rik <rik@octave.org>
parents:
25961
diff
changeset
|
115 && ! octave::iskeyword (varname)); |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
116 } |
4264 | 117 |
118 return retval; | |
119 } | |
120 | |
13094 | 121 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
122 %!assert (isvarname ("foo"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
123 %!assert (isvarname ("_foo"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
124 %!assert (isvarname ("_1"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
125 %!assert (isvarname ("1foo"), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
126 %!assert (isvarname (""), false) |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
127 %!assert (isvarname (12), false) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
128 %!assert (isvarname ("foo+bar"), false) |
13094 | 129 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
130 %!error isvarname () |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21526
diff
changeset
|
131 %!error isvarname ("foo", "bar") |
13094 | 132 */ |
133 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
134 namespace octave |
6323 | 135 { |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
136 // Return TRUE if F and G are both names for the same file. |
6323 | 137 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
138 bool same_file (const std::string& f, const std::string& g) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
139 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
140 return same_file_internal (f, g); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
141 } |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
142 } |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
143 |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
144 DEFUN (is_same_file, args, , |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
145 doc: /* -*- texinfo -*- |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
146 @deftypefn {} {@var{same} =} is_same_file (@var{filepath1}, @var{filepath2}) |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
147 Return true if @var{filepath1} and @var{filepath2} refer to the same file. |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
148 |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
149 If either @var{filepath1} or @var{filepath2} is a cell array of strings, then |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
150 an array of the same size is returned, containing the values described above |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
151 for every member of the cell array. The other argument may also be a cell |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
152 array of strings (of the same size) or a string. |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
153 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
154 Programming Notes: Depending on the operating system and file system, the same |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
155 file or folder can be referred to with different paths. In particular, paths |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
156 on the Windows platform may differ in case (@file{file1} vs.@: @file {FILE1}), |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
157 file separator (@samp{\} vs.@: @samp{/}), and format (@file{A~spaces.txt} (8.3 |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
158 convention) vs.@: @file{A filename with spaces.txt}). This function returns |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
159 true if the paths in @var{filepath1} and @var{filepath2} actually refer to the |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
160 same file or folder, and false otherwise. |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
161 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
162 Note that unlike @code{strcmp}, this function requires that @var{filepath1} |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
163 and @var{filepath2} exist, as well as point to the same location, in order to |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
164 return true. |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
165 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
166 @seealso{canonicalize_file_name, strcmp} |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
167 @end deftypefn */) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
168 { |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
169 if (args.length () != 2) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
170 print_usage (); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
171 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
172 octave_value retval; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
173 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
174 bool s1_string = args(0).is_string (); |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
175 bool s1_cellstr = args(0).iscellstr (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
176 bool s2_string = args(1).is_string (); |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
177 bool s2_cellstr = args(1).iscellstr (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
178 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
179 if (s1_string && s2_string) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
180 { |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
181 std::string file1 = args(0).string_value (); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
182 std::string file2 = args(1).string_value (); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
183 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
184 retval = octave::same_file (file1, file2); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
185 } |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
186 else if ((s1_string && s2_cellstr) || (s1_cellstr && s2_string)) |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
187 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
188 octave_value str_arg, cellstr_arg; |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
189 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
190 if (s1_string) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
191 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
192 str_arg = args(0); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
193 cellstr_arg = args(1); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
194 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
195 else |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
196 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
197 str_arg = args(1); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
198 cellstr_arg = args(0); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
199 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
200 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
201 const Array<std::string> cellstr = cellstr_arg.cellstr_value (); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
202 const std::string str = str_arg.string_value (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
203 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
204 boolNDArray output (cellstr.dims (), false); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
205 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
206 for (octave_idx_type idx = 0; idx < cellstr.numel (); idx++) |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
207 output(idx) = octave::same_file (str, cellstr(idx)); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
208 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
209 retval = output; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
210 } |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
211 else if (s1_cellstr && s2_cellstr) |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
212 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
213 const Array<std::string> cellstr1 = args(0).cellstr_value (); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
214 const Array<std::string> cellstr2 = args(1).cellstr_value (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
215 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
216 const dim_vector size1 = cellstr1.dims (); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
217 const dim_vector size2 = cellstr2.dims (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
218 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
219 if (size1 != size2) |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
220 error ("is_same_file: cellstr arrays FILEPATH1 and FILEPATH2 must be the same size"); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
221 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
222 boolNDArray output (size1, false); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
223 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
224 for (octave_idx_type idx = 0; idx < cellstr1.numel (); idx++) |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
225 output(idx) = octave::same_file (cellstr1(idx), cellstr2(idx)); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
226 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
227 retval = output; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
228 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
229 else |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
230 error ("is_same_file: FILEPATH1 and FILEPATH2 must be strings or cell arrays of strings"); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
231 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
232 return retval; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
233 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
234 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
235 /* |
27580
e7df1df55f0e
Fix BIST test for is_same_file on Windows platforms.
Rik <rik@octave.org>
parents:
27571
diff
changeset
|
236 %!testif ; ! ispc () |
e7df1df55f0e
Fix BIST test for is_same_file on Windows platforms.
Rik <rik@octave.org>
parents:
27571
diff
changeset
|
237 %! assert (is_same_file ("~", tilde_expand ("~"))); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
238 %!testif ; ispc () |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
239 %! assert (is_same_file (tolower (getenv ("OCTAVE_HOME")), |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
240 %! toupper (getenv ("OCTAVE_HOME"))), true); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
241 %!assert (is_same_file ({pwd(), ".", tempdir()}, canonicalize_file_name (".")), |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
242 %! [true, true, false]) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
243 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
244 %!error is_same_file () |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
245 %!error is_same_file ("foo") |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
246 %!error is_same_file ("foo", "bar", "baz") |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
247 %!error <must be strings or cell arrays of strings> is_same_file ("foo", 1) |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
248 %!error <must be strings or cell arrays of strings> is_same_file (1, "foo") |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
249 %!error <must be strings or cell arrays of strings> is_same_file ("foo", {1}) |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
250 %!error <must be strings or cell arrays of strings> is_same_file ({1}, "foo") |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
251 %!error <arrays .* must be the same size> is_same_file ({"1", "2"}, {"1"; "2"}) |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
252 */ |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
253 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
254 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
255 namespace octave |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
256 { |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
257 int almost_match (const std::string& std, const std::string& s, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
258 int min_match_len, int case_sens) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
259 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
260 int stdlen = std.length (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
261 int slen = s.length (); |
1 | 262 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
263 return (slen <= stdlen |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
264 && slen >= min_match_len |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
265 && (case_sens |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
266 ? (strncmp (std.c_str (), s.c_str (), slen) == 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
267 : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0))); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
268 } |
287 | 269 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
270 // Ugh. |
581 | 271 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
272 int keyword_almost_match (const char * const *std, int *min_len, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
273 const std::string& s, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
274 int min_toks_to_match, int max_toks) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
275 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
276 int status = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
277 int tok_count = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
278 int toks_matched = 0; |
287 | 279 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
280 if (s.empty () || max_toks < 1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
281 return status; |
287 | 282 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
283 char *kw = strsave (s.c_str ()); |
287 | 284 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
285 char *t = kw; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
286 while (*t != '\0') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
287 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
288 if (*t == '\t') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
289 *t = ' '; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
290 t++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
291 } |
287 | 292 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
293 char *beg = kw; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
294 while (*beg == ' ') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
295 beg++; |
287 | 296 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
297 if (*beg == '\0') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
298 return status; |
287 | 299 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
300 const char **to_match = new const char * [max_toks + 1]; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
301 const char * const *s1 = std; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
302 const char **s2 = to_match; |
287 | 303 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
304 if (! s1 || ! s2) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
305 goto done; |
287 | 306 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
307 s2[tok_count] = beg; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
308 char *end; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
309 while ((end = strchr (beg, ' ')) != nullptr) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
310 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
311 *end = '\0'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
312 beg = end + 1; |
287 | 313 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
314 while (*beg == ' ') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
315 beg++; |
287 | 316 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
317 if (*beg == '\0') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
318 break; |
287 | 319 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
320 tok_count++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
321 if (tok_count >= max_toks) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
322 goto done; |
287 | 323 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
324 s2[tok_count] = beg; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
325 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
326 s2[tok_count+1] = nullptr; |
287 | 327 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
328 s2 = to_match; |
287 | 329 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
330 for (;;) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
331 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
332 if (! almost_match (*s1, *s2, min_len[toks_matched], 0)) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
333 goto done; |
287 | 334 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
335 toks_matched++; |
287 | 336 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
337 s1++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
338 s2++; |
287 | 339 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
340 if (! *s2) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
341 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
342 status = (toks_matched >= min_toks_to_match); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
343 goto done; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
344 } |
287 | 345 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
346 if (! *s1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
347 goto done; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
348 } |
287 | 349 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
350 done: |
287 | 351 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
352 delete [] kw; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
353 delete [] to_match; |
287 | 354 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
355 return status; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
356 } |
1 | 357 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
358 // See if the given file is in the path. |
581 | 359 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
360 std::string search_path_for_file (const std::string& path, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
361 const string_vector& names) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
362 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
363 directory_path p (path); |
686 | 364 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
365 return sys::env::make_absolute (p.find_first_of (names.std_list ())); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
366 } |
686 | 367 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
368 // Find all locations of the given file in the path. |
4216 | 369 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
370 string_vector search_path_for_all_files (const std::string& path, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
371 const string_vector& names) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
372 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
373 directory_path p (path); |
4216 | 374 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
375 string_vector sv = p.find_all_first_of (names.std_list ()); |
4216 | 376 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
377 octave_idx_type len = sv.numel (); |
4216 | 378 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
379 for (octave_idx_type i = 0; i < len; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
380 sv[i] = sys::env::make_absolute (sv[i]); |
4216 | 381 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
382 return sv; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
383 } |
4216 | 384 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
385 static string_vector make_absolute (const string_vector& sv) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
386 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
387 octave_idx_type len = sv.numel (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
388 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
389 string_vector retval (len); |
6379 | 390 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
391 for (octave_idx_type i = 0; i < len; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
392 retval[i] = sys::env::make_absolute (sv[i]); |
4216 | 393 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
394 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
395 } |
4216 | 396 } |
397 | |
23519
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
398 DEFMETHOD (file_in_loadpath, interp, args, , |
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
399 doc: /* -*- texinfo -*- |
23988
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
400 @deftypefn {} {@var{fname} =} file_in_loadpath (@var{file}) |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
401 @deftypefnx {} {@var{fname} =} file_in_loadpath (@var{file}, "all") |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
402 Return the absolute name of @var{file} if it can be found in the list of |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
403 directories specified by @code{path}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
404 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
405 If no file is found, return an empty character string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
406 |
23988
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
407 When @var{file} is already an absolute name, the name is checked against the |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
408 file system instead of Octave's loadpath. In this case, if @var{file} exists |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
409 it will be returned in @var{fname}, otherwise an empty string is returned. |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
410 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
411 If the first argument is a cell array of strings, search each directory of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
412 the loadpath for element of the cell array and return the first that |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
413 matches. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
414 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
415 If the second optional argument @qcode{"all"} is supplied, return a cell |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
416 array containing the list of all files that have the same name in the path. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
417 If no files are found, return an empty cell array. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
418 @seealso{file_in_path, dir_in_loadpath, path} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
419 @end deftypefn */) |
3195 | 420 { |
4243 | 421 int nargin = args.length (); |
3195 | 422 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
423 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
424 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
425 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20973
diff
changeset
|
426 string_vector names = args(0).xstring_vector_value ("file_in_loadpath: FILE argument must be a string"); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
427 |
20973 | 428 if (names.empty ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
429 error ("file_in_loadpath: FILE argument must not be empty"); |
4243 | 430 |
23519
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
431 octave::load_path& lp = interp.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
432 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
433 if (nargin == 1) |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
434 return ovl (octave::sys::env::make_absolute (lp.find_first_of (names))); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
435 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
436 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
437 std::string opt = args(1).xstring_value ("file_in_loadpath: optional second argument must be a string"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
438 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
439 if (opt != "all") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
440 error (R"(file_in_loadpath: "all" is only valid second argument)"); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
441 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
442 return ovl (Cell (octave::make_absolute (lp.find_all_first_of (names)))); |
4216 | 443 } |
3195 | 444 } |
445 | |
13094 | 446 /* |
447 %!test | |
448 %! f = file_in_loadpath ("plot.m"); | |
449 %! assert (ischar (f)); | |
450 %! assert (! isempty (f)); | |
451 | |
452 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
453 %! f = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$"); |
13094 | 454 %! assert (f, ""); |
455 | |
456 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
457 %! lst = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$", "all"); |
13094 | 458 %! assert (lst, {}); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
459 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
460 %!error file_in_loadpath () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
461 %!error file_in_loadpath ("foo", "bar", 1) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
462 %!error file_in_loadpath ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
463 %!error file_in_loadpath ("plot.m", "bar") |
13094 | 464 */ |
465 | |
1957 | 466 DEFUN (file_in_path, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
467 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
468 @deftypefn {} {} file_in_path (@var{path}, @var{file}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
469 @deftypefnx {} {} file_in_path (@var{path}, @var{file}, "all") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
470 Return the absolute name of @var{file} if it can be found in @var{path}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
471 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
472 The value of @var{path} should be a colon-separated list of directories in |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
473 the format described for @code{path}. If no file is found, return an empty |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
474 character string. For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
475 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
476 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
477 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
478 file_in_path (EXEC_PATH, "sh") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
479 @result{} "/bin/sh" |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
480 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
481 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
482 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
483 If the second argument is a cell array of strings, search each directory of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
484 the path for element of the cell array and return the first that matches. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
485 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
486 If the third optional argument @qcode{"all"} is supplied, return a cell |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
487 array containing the list of all files that have the same name in the path. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
488 If no files are found, return an empty cell array. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
489 @seealso{file_in_loadpath, dir_in_loadpath, path} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
490 @end deftypefn */) |
686 | 491 { |
4243 | 492 int nargin = args.length (); |
1755 | 493 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
494 if (nargin < 2 || nargin > 3) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
495 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
496 |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
497 std::string path = args(0).xstring_value ("file_in_path: PATH must be a string"); |
20582
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20559
diff
changeset
|
498 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20973
diff
changeset
|
499 string_vector names = args(1).xstring_vector_value ("file_in_path: FILE argument must be a string"); |
4243 | 500 |
20973 | 501 if (names.empty ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
502 error ("file_in_path: FILE argument must not be empty"); |
4243 | 503 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
504 if (nargin == 2) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
505 return ovl (octave::search_path_for_file (path, names)); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
506 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
507 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
508 std::string opt = args(2).xstring_value ("file_in_path: optional third argument must be a string"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
509 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
510 if (opt != "all") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
511 error (R"(file_in_path: "all" is only valid third argument)"); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
512 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
513 return ovl (Cell (octave::make_absolute (octave::search_path_for_all_files (path, names)))); |
686 | 514 } |
515 } | |
516 | |
13094 | 517 /* |
518 %!test | |
519 %! f = file_in_path (path (), "plot.m"); | |
520 %! assert (ischar (f)); | |
521 %! assert (! isempty (f)); | |
522 | |
523 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
524 %! f = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$"); |
13094 | 525 %! assert (f, ""); |
526 | |
527 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
528 %! lst = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$", "all"); |
13094 | 529 %! assert (lst, {}); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
530 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
531 %!error file_in_path () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
532 %!error file_in_path ("foo") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
533 %!error file_in_path ("foo", "bar", "baz", 1) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
534 %!error file_in_path ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
535 %!error file_in_path (path (), []) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
536 %!error file_in_path (path (), "plot.m", "bar") |
13094 | 537 */ |
538 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
539 namespace octave |
526 | 540 { |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
541 std::string file_in_path (const std::string& name, const std::string& suffix) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
542 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
543 std::string nm = name; |
526 | 544 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
545 if (! suffix.empty ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
546 nm.append (suffix); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
547 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
548 load_path& lp = __get_load_path__ ("file_in_path"); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
549 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
550 return sys::env::make_absolute (lp.find_file (nm)); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
551 } |
526 | 552 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
553 std::string find_data_file_in_load_path (const std::string& fcn, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
554 const std::string& file, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
555 bool require_regular_file) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
556 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
557 std::string fname = file; |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
558 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
559 if (! (sys::env::absolute_pathname (fname) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
560 || sys::env::rooted_relative_pathname (fname))) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
561 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
562 // Load path will also search "." first, but we don't want to |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
563 // issue a warning if the file is found in the current directory, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
564 // so do an explicit check for that. |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
565 sys::file_stat fs (fname); |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
566 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
567 bool local_file_ok |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
568 = fs.exists () && (fs.is_reg () || ! require_regular_file); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
569 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
570 if (! local_file_ok) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
571 { |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
572 load_path& lp = __get_load_path__ ("find_data_file_in_load_path"); |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
573 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
574 // Not directly found; search load path. |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
575 std::string tmp = sys::env::make_absolute (lp.find_file (fname)); |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
576 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
577 if (! tmp.empty ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
578 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
579 warn_data_file_in_path (fcn, tmp); |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
580 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
581 fname = tmp; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
582 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
583 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
584 } |
581 | 585 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
586 return fname; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
587 } |
908 | 588 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
589 // See if there is an function file in the path. |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
590 // If so, return the full path to the file. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
591 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
592 std::string fcn_file_in_path (const std::string& name) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
593 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
594 std::string retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
595 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
596 int len = name.length (); |
5832 | 597 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
598 if (len > 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
599 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
600 if (sys::env::absolute_pathname (name)) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
601 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
602 sys::file_stat fs (name); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
603 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
604 if (fs.exists () && ! fs.is_dir ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
605 retval = name; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
606 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
607 else if (len > 2 && name[len - 2] == '.' && name[len - 1] == 'm') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
608 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
609 load_path& lp = __get_load_path__ ("fcn_file_in_path"); |
1755 | 610 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
611 retval = lp.find_fcn_file (name.substr (0, len-2)); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
612 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
613 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
614 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
615 std::string fname = name; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
616 size_t pos = name.find_first_of ('>'); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
617 if (pos != std::string::npos) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
618 fname = name.substr (0, pos); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
619 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
620 load_path& lp = __get_load_path__ ("fcn_file_in_path"); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
621 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
622 retval = lp.find_fcn_file (fname); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
623 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
624 } |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
625 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
626 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
627 } |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
628 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
629 // See if there is a directory called "name" in the path and if it |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
630 // contains a Contents.m file. If so, return the full path to this file. |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
631 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
632 std::string contents_file_in_path (const std::string& dir) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
633 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
634 std::string retval; |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
635 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
636 if (! dir.empty ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
637 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
638 load_path& lp = __get_load_path__ ("contents_in_file_path"); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
639 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
640 std::string tcontents |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
641 = sys::file_ops::concat (lp.find_dir (dir), "Contents.m"); |
3103 | 642 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
643 sys::file_stat fs (tcontents); |
3103 | 644 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
645 if (fs.exists ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
646 retval = sys::env::make_absolute (tcontents); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
647 } |
3103 | 648 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
649 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
650 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
651 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
652 // Replace backslash escapes in a string with the real values. |
3103 | 653 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
654 std::string do_string_escapes (const std::string& s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
655 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
656 std::string retval; |
3103 | 657 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
658 size_t i = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
659 size_t j = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
660 size_t len = s.length (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
661 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
662 retval.resize (len); |
3103 | 663 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
664 while (j < len) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
665 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
666 if (s[j] == '\\' && j+1 < len) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
667 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
668 switch (s[++j]) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
669 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
670 case 'a': // alarm |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
671 retval[i] = '\a'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
672 break; |
3103 | 673 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
674 case 'b': // backspace |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
675 retval[i] = '\b'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
676 break; |
3103 | 677 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
678 case 'f': // formfeed |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
679 retval[i] = '\f'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
680 break; |
3103 | 681 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
682 case 'n': // newline |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
683 retval[i] = '\n'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
684 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
685 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
686 case 'r': // carriage return |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
687 retval[i] = '\r'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
688 break; |
3103 | 689 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
690 case 't': // horizontal tab |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
691 retval[i] = '\t'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
692 break; |
3103 | 693 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
694 case 'v': // vertical tab |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
695 retval[i] = '\v'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
696 break; |
3103 | 697 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
698 case '\\': // backslash |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
699 retval[i] = '\\'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
700 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
701 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
702 case '\'': // quote |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
703 retval[i] = '\''; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
704 break; |
3103 | 705 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
706 case '"': // double quote |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
707 retval[i] = '"'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
708 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
709 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
710 case '0': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
711 case '1': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
712 case '2': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
713 case '3': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
714 case '4': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
715 case '5': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
716 case '6': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
717 case '7': // octal input |
20210
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
718 { |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
719 size_t k; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
720 int tmpi = s[j] - '0'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
721 for (k = j+1; k < std::min (j+3, len); k++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
722 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
723 int digit = s[k] - '0'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
724 if (digit < 0 || digit > 7) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
725 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
726 tmpi <<= 3; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
727 tmpi += digit; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
728 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
729 retval[i] = tmpi; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
730 j = k - 1; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
731 break; |
20210
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
732 } |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
733 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
734 case 'x': // hex input |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
735 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
736 size_t k; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
737 int tmpi = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
738 for (k = j+1; k < std::min (j+3, len); k++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
739 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
740 if (! isxdigit (s[k])) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
741 break; |
20210
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
742 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
743 tmpi <<= 4; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
744 int digit = s[k]; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
745 if (digit >= 'a') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
746 tmpi += digit - 'a' + 10; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
747 else if (digit >= 'A') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
748 tmpi += digit - 'A' + 10; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
749 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
750 tmpi += digit - '0'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
751 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
752 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
753 if (k == j+1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
754 warning (R"(malformed hex escape sequence '\x' -- converting to '\0')"); |
20210
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
755 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
756 retval[i] = tmpi; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
757 j = k - 1; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
758 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
759 } |
3103 | 760 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
761 default: |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
762 warning (R"(unrecognized escape sequence '\%c' -- converting to '%c')", s[j], s[j]); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
763 retval[i] = s[j]; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
764 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
765 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
766 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
767 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
768 retval[i] = s[j]; |
3103 | 769 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
770 i++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
771 j++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
772 } |
3103 | 773 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
774 retval.resize (i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
775 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
776 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
777 } |
3103 | 778 } |
779 | |
780 DEFUN (do_string_escapes, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
781 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
782 @deftypefn {} {} do_string_escapes (@var{string}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
783 Convert escape sequences in @var{string} to the characters they represent. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
784 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
785 Escape sequences begin with a leading backslash |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
786 (@qcode{'@xbackslashchar{}'}) followed by 1--3 characters |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
787 (.e.g., @qcode{"@xbackslashchar{}n"} => newline). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
788 @seealso{undo_string_escapes} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
789 @end deftypefn */) |
3103 | 790 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
791 if (args.length () != 1) |
5823 | 792 print_usage (); |
3103 | 793 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
794 std::string str = args(0).xstring_value ("do_string_escapes: STRING argument must be of type string"); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
795 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
796 return ovl (octave::do_string_escapes (str)); |
3103 | 797 } |
798 | |
13094 | 799 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
800 %!assert (do_string_escapes ('foo\nbar'), "foo\nbar") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
801 %!assert (do_string_escapes ("foo\\nbar"), "foo\nbar") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
802 %!assert (do_string_escapes ("foo\\nbar"), ["foo", char(10), "bar"]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
803 %!assert ("foo\nbar", ["foo", char(10), "bar"]) |
13094 | 804 |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
805 %!assert (do_string_escapes ('\0\a\b\f\n\r\t\v'), "\0\a\b\f\n\r\t\v") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
806 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"), "\0\a\b\f\n\r\t\v") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
807 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"), |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
808 %! char ([0, 7, 8, 12, 10, 13, 9, 11])) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
809 %!assert ("\0\a\b\f\n\r\t\v", char ([0, 7, 8, 12, 10, 13, 9, 11])) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
810 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
811 %!assert (do_string_escapes ('\\'), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
812 %!assert (do_string_escapes ("\\\\"), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
813 %!assert (do_string_escapes ("\\\\"), char (92)) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
814 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
815 %!assert (do_string_escapes ('\''single-quoted\'''), "'single-quoted'") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
816 %!assert (do_string_escapes ("\\'single-quoted\\'"), "'single-quoted'") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
817 %!assert (do_string_escapes ('\"double-quoted\"'), "\"double-quoted\"") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
818 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"") |
13094 | 819 |
20210
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
820 %!assert (do_string_escapes ('A\4B'), ["A" char(4) "B"]) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
821 %!assert (do_string_escapes ('A\45B'), ["A" char(37) "B"]) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
822 %!assert (do_string_escapes ('A\123B'), ["A" char(83) "B"]) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
823 %!assert (sprintf ('\117\143\164\141\166\145'), "Octave") |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
824 |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
825 %!assert (do_string_escapes ('A\x4G'), ["A" char(4) "G"]) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
826 %!assert (do_string_escapes ('A\x4AG'), ["A" char(74) "G"]) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
827 %!assert (sprintf ('\x4f\x63\x74\x61\x76\x65'), "Octave") |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
828 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
829 %!error do_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
830 %!error do_string_escapes ("foo", "bar") |
20210
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
831 %!error <STRING argument> do_string_escapes (3) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
832 %!warning <malformed hex escape sequence> do_string_escapes ('\xG'); |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
833 %!warning <unrecognized escape sequence> do_string_escapes ('\G'); |
13094 | 834 */ |
835 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
836 namespace octave |
801 | 837 { |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
838 const char * undo_string_escape (char c) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
839 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
840 if (! c) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
841 return ""; |
801 | 842 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
843 switch (c) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
844 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
845 case '\0': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
846 return R"(\0)"; |
801 | 847 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
848 case '\a': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
849 return R"(\a)"; |
801 | 850 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
851 case '\b': // backspace |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
852 return R"(\b)"; |
801 | 853 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
854 case '\f': // formfeed |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
855 return R"(\f)"; |
801 | 856 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
857 case '\n': // newline |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
858 return R"(\n)"; |
801 | 859 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
860 case '\r': // carriage return |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
861 return R"(\r)"; |
801 | 862 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
863 case '\t': // horizontal tab |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
864 return R"(\t)"; |
801 | 865 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
866 case '\v': // vertical tab |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
867 return R"(\v)"; |
801 | 868 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
869 case '\\': // backslash |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
870 return R"(\\)"; |
801 | 871 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
872 case '"': // double quote |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
873 return R"(\")"; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
874 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
875 default: |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
876 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
877 static char retval[2] {'\0', '\0'}; |
20973 | 878 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
879 retval[0] = c; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
880 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
881 } |
1755 | 882 } |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
883 } |
801 | 884 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
885 std::string undo_string_escapes (const std::string& s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
886 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
887 std::string retval; |
801 | 888 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
889 for (size_t i = 0; i < s.length (); i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
890 retval.append (undo_string_escape (s[i])); |
801 | 891 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
892 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
893 } |
801 | 894 } |
895 | |
1957 | 896 DEFUN (undo_string_escapes, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
897 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
898 @deftypefn {} {} undo_string_escapes (@var{s}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
899 Convert special characters in strings back to their escaped forms. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
900 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
901 For example, the expression |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
902 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
903 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
904 bell = "\a"; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
905 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
906 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
907 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
908 assigns the value of the alert character (control-g, ASCII code 7) to the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
909 string variable @code{bell}. If this string is printed, the system will |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
910 ring the terminal bell (if it is possible). This is normally the desired |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
911 outcome. However, sometimes it is useful to be able to print the original |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
912 representation of the string, with the special characters replaced by their |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
913 escape sequences. For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
914 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
915 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
916 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
917 octave:13> undo_string_escapes (bell) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
918 ans = \a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
919 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
920 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
921 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
922 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
923 replaces the unprintable alert character with its printable representation. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
924 @seealso{do_string_escapes} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
925 @end deftypefn */) |
801 | 926 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
927 if (args.length () != 1) |
5823 | 928 print_usage (); |
801 | 929 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
930 std::string str = args(0).xstring_value ("undo_string_escapes: S argument must be a string"); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
931 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
932 return ovl (octave::undo_string_escapes (str)); |
801 | 933 } |
934 | |
13094 | 935 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
936 %!assert (undo_string_escapes ("foo\nbar"), 'foo\nbar') |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
937 %!assert (undo_string_escapes ("foo\nbar"), "foo\\nbar") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
938 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar") |
13094 | 939 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
940 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), '\a\b\f\n\r\t\v') |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
941 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), "\\a\\b\\f\\n\\r\\t\\v") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
942 %!assert (undo_string_escapes (char ([7, 8, 12, 10, 13, 9, 11])), |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
943 %! "\\a\\b\\f\\n\\r\\t\\v") |
13094 | 944 |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
945 %!assert (undo_string_escapes ("\\"), '\\') |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
946 %!assert (undo_string_escapes ("\\"), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
947 %!assert (undo_string_escapes (char (92)), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
948 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
949 %!assert (undo_string_escapes ("\"double-quoted\""), '\"double-quoted\"') |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
950 %!assert (undo_string_escapes ("\"double-quoted\""), "\\\"double-quoted\\\"") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
951 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
952 %!error undo_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
953 %!error undo_string_escapes ("foo", "bar") |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
954 %!error undo_string_escapes (3) |
13094 | 955 */ |
956 | |
8229 | 957 DEFUN (is_absolute_filename, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
958 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
959 @deftypefn {} {} is_absolute_filename (@var{file}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
960 Return true if @var{file} is an absolute filename. |
25781
e04c56bbbace
isdir.m: Make m-file a legacy function (bug #54489)
Rik <rik@octave.org>
parents:
25659
diff
changeset
|
961 @seealso{is_rooted_relative_filename, make_absolute_filename, isfolder} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
962 @end deftypefn */) |
8229 | 963 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
964 if (args.length () != 1) |
8229 | 965 print_usage (); |
966 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
967 return ovl (args(0).is_string () |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
968 && octave::sys::env::absolute_pathname (args(0).string_value ())); |
8229 | 969 } |
970 | |
13094 | 971 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
972 ## FIXME: We need system-dependent tests here. |
13094 | 973 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
974 %!error is_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
975 %!error is_absolute_filename ("foo", "bar") |
13094 | 976 */ |
977 | |
8229 | 978 DEFUN (is_rooted_relative_filename, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
979 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
980 @deftypefn {} {} is_rooted_relative_filename (@var{file}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
981 Return true if @var{file} is a rooted-relative filename. |
25781
e04c56bbbace
isdir.m: Make m-file a legacy function (bug #54489)
Rik <rik@octave.org>
parents:
25659
diff
changeset
|
982 @seealso{is_absolute_filename, make_absolute_filename, isfolder} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
983 @end deftypefn */) |
8229 | 984 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
985 if (args.length () != 1) |
8229 | 986 print_usage (); |
987 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
988 return ovl (args(0).is_string () |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
989 && octave::sys::env::rooted_relative_pathname (args(0).string_value ())); |
8229 | 990 } |
991 | |
13094 | 992 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
993 ## FIXME: We need system-dependent tests here. |
13094 | 994 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
995 %!error is_rooted_relative_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
996 %!error is_rooted_relative_filename ("foo", "bar") |
13094 | 997 */ |
998 | |
8229 | 999 DEFUN (make_absolute_filename, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1000 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1001 @deftypefn {} {} make_absolute_filename (@var{file}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1002 Return the full name of @var{file} beginning from the root of the file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1003 system. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1004 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1005 No check is done for the existence of @var{file}. |
25781
e04c56bbbace
isdir.m: Make m-file a legacy function (bug #54489)
Rik <rik@octave.org>
parents:
25659
diff
changeset
|
1006 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isfolder} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1007 @end deftypefn */) |
8229 | 1008 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1009 if (args.length () != 1) |
8229 | 1010 print_usage (); |
1011 | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1012 std::string nm = args(0).xstring_value ("make_absolute_filename: FILE argument must be a filename"); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1013 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1014 return ovl (octave::sys::env::make_absolute (nm)); |
8229 | 1015 } |
1016 | |
13094 | 1017 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1018 ## FIXME: We need system-dependent tests here. |
13094 | 1019 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1020 %!error make_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1021 %!error make_absolute_filename ("foo", "bar") |
13094 | 1022 */ |
1023 | |
23519
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
1024 DEFMETHOD (dir_in_loadpath, interp, args, , |
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
1025 doc: /* -*- texinfo -*- |
23988
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1026 @deftypefn {} {@var{dirname} =} dir_in_loadpath (@var{dir}) |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1027 @deftypefnx {} {@var{dirname} =} dir_in_loadpath (@var{dir}, "all") |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1028 Return the absolute name of the loadpath element matching @var{dir} if it can |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1029 be found in the list of directories specified by @code{path}. |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1030 |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1031 If no match is found, return an empty character string. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1032 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1033 The match is performed at the end of each path element. For example, if |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1034 @var{dir} is @qcode{"foo/bar"}, it matches the path element |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1035 @nospell{@qcode{"/some/dir/foo/bar"}}, but not |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1036 @nospell{@qcode{"/some/dir/foo/bar/baz"}} |
23988
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1037 @nospell{@qcode{"/some/dir/allfoo/bar"}}. When @var{dir} is an absolute name, |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1038 rather than just a path fragment, it is matched against the file system |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1039 instead of Octave's loadpath. In this case, if @var{dir} exists it will be |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1040 returned in @var{dirname}, otherwise an empty string is returned. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1041 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1042 If the optional second argument is supplied, return a cell array containing |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1043 all name matches rather than just the first. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1044 @seealso{file_in_path, file_in_loadpath, path} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1045 @end deftypefn */) |
8229 | 1046 { |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
1047 int nargin = args.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
1048 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1049 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1050 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1051 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
1052 std::string dir; |
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
1053 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1054 dir = args(0).xstring_value ("dir_in_loadpath: DIR must be a directory name"); |
8229 | 1055 |
23519
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
1056 octave::load_path& lp = interp.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
1057 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1058 if (nargin == 1) |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
1059 return ovl (lp.find_dir (dir)); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1060 else |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
1061 return ovl (Cell (lp.find_matching_dirs (dir))); |
8229 | 1062 } |
1063 | |
13094 | 1064 /* |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1065 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1066 %! f = dir_in_loadpath ("plot"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1067 %! assert (ischar (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1068 %! assert (! isempty (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1069 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1070 %!test |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1071 %! f = dir_in_loadpath ("$$probably_!! _not_&&_a_!! _dir$$"); |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1072 %! assert (f, ""); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1073 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1074 %!test |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1075 %! lst = dir_in_loadpath ("$$probably_!! _not_&&_a_!! _dir$$", "all"); |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1076 %! assert (lst, {}); |
13094 | 1077 |
18110
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18105
diff
changeset
|
1078 %!error dir_in_loadpath () |
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18105
diff
changeset
|
1079 %!error dir_in_loadpath ("foo", "bar", 1) |
13094 | 1080 */ |
1081 | |
5465 | 1082 DEFUNX ("errno", Ferrno, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1083 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1084 @deftypefn {} {@var{err} =} errno () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1085 @deftypefnx {} {@var{err} =} errno (@var{val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1086 @deftypefnx {} {@var{err} =} errno (@var{name}) |
25106
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1087 Query or set the system-dependent variable errno. |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1088 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1089 When called with no inputs, return the current value of errno. |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1090 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1091 When called with a numeric input @var{val}, set the current value of errno |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1092 to the specified value. The previous value of errno is returned as @var{err}. |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1093 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1094 When called with a character string @var{name}, return the numeric value of |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1095 errno which corresponds to the specified error code. If @var{name} is not |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1096 a recognized error code then -1 is returned. |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1097 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1098 @seealso{errno_list} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1099 @end deftypefn */) |
3716 | 1100 { |
5465 | 1101 int nargin = args.length (); |
1102 | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1103 if (nargin > 1) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1104 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1105 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1106 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1107 |
5465 | 1108 if (nargin == 1) |
1109 { | |
1110 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1111 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1112 std::string nm = args(0).string_value (); |
5465 | 1113 |
19743
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1114 retval = octave_errno::lookup (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1115 } |
5465 | 1116 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1117 { |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1118 int val = args(0).xint_value ("errno: argument must be string or integer"); |
5465 | 1119 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1120 retval = octave_errno::set (val); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1121 } |
5465 | 1122 } |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1123 else |
5465 | 1124 retval = octave_errno::get (); |
3716 | 1125 |
1126 return retval; | |
1127 } | |
1128 | |
13094 | 1129 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1130 %!assert (isnumeric (errno ())) |
13094 | 1131 |
1132 %!test | |
1133 %! lst = errno_list (); | |
1134 %! fns = fieldnames (lst); | |
1135 %! oldval = errno (fns{1}); | |
1136 %! assert (isnumeric (oldval)); | |
1137 %! errno (oldval); | |
1138 %! newval = errno (); | |
1139 %! assert (oldval, newval); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1140 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1141 %!error errno ("foo", 1) |
13094 | 1142 */ |
1143 | |
5465 | 1144 DEFUN (errno_list, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1145 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1146 @deftypefn {} {} errno_list () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1147 Return a structure containing the system-dependent errno values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1148 @seealso{errno} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1149 @end deftypefn */) |
5465 | 1150 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1151 if (args.length () != 0) |
5823 | 1152 print_usage (); |
5465 | 1153 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1154 return ovl (octave_errno::list ()); |
5465 | 1155 } |
3716 | 1156 |
13094 | 1157 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1158 %!assert (isstruct (errno_list ())) |
13094 | 1159 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1160 %!error errno_list ("foo") |
13094 | 1161 */ |
1162 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1163 namespace octave |
3354 | 1164 { |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1165 static void check_dimensions (octave_idx_type& nr, octave_idx_type& nc, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1166 const char *warnfor) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1167 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1168 if (nr < 0 || nc < 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1169 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1170 warning_with_id ("Octave:neg-dim-as-zero", |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1171 "%s: converting negative dimension to zero", warnfor); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1172 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1173 nr = (nr < 0) ? 0 : nr; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1174 nc = (nc < 0) ? 0 : nc; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1175 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1176 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1177 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1178 void check_dimensions (dim_vector& dim, const char *warnfor) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1179 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1180 bool neg = false; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1181 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1182 for (int i = 0; i < dim.ndims (); i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1183 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1184 if (dim(i) < 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1185 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1186 dim(i) = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1187 neg = true; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1188 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1189 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1190 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1191 if (neg) |
5781 | 1192 warning_with_id ("Octave:neg-dim-as-zero", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1193 "%s: converting negative dimension to zero", warnfor); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1194 } |
4481 | 1195 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1196 void get_dimensions (const octave_value& a, const char *warn_for, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1197 dim_vector& dim) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1198 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1199 // We support dimensions to be specified by any vector, even if it's a |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1200 // vector of dimensions 0x1, 1x0, 1x1x0, or 1x1x6. If the vector ends |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1201 // up being empty, the final dimensions end up being 0x0. |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1202 if (! a.dims ().isvector ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1203 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
4481 | 1204 |
25927
d6581134daaa
Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
1205 const Array<octave_idx_type> v = a.octave_idx_type_vector_value (true); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1206 const octave_idx_type n = v.numel (); |
4481 | 1207 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1208 dim.resize (n); // even if n < 2, resize sets it back to 2 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1209 if (n == 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1210 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1211 dim(0) = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1212 dim(1) = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1213 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1214 else if (n == 1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1215 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1216 dim(0) = v(0); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1217 dim(1) = v(0); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1218 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1219 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1220 for (octave_idx_type i = 0; i < n; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1221 dim(i) = v(i); |
21405
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1222 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1223 check_dimensions (dim, warn_for); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1224 } |
21405
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1225 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1226 void get_dimensions (const octave_value& a, const char *warn_for, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1227 octave_idx_type& nr, octave_idx_type& nc) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1228 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1229 if (a.is_scalar_type ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1230 { |
25928
a533a7c4d2cc
Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25927
diff
changeset
|
1231 nr = nc = a.idx_type_value (true); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1232 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1233 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1234 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1235 nr = a.rows (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1236 nc = a.columns (); |
4481 | 1237 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1238 if ((nr != 1 || nc != 2) && (nr != 2 || nc != 1)) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1239 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
4481 | 1240 |
25928
a533a7c4d2cc
Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25927
diff
changeset
|
1241 Array<octave_idx_type> v = a.octave_idx_type_vector_value (true); |
a533a7c4d2cc
Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25927
diff
changeset
|
1242 nr = v(0); |
a533a7c4d2cc
Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25927
diff
changeset
|
1243 nc = v(1); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1244 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1245 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1246 check_dimensions (nr, nc, warn_for); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1247 } |
3354 | 1248 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1249 void get_dimensions (const octave_value& a, const octave_value& b, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1250 const char *warn_for, octave_idx_type& nr, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1251 octave_idx_type& nc) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1252 { |
25928
a533a7c4d2cc
Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25927
diff
changeset
|
1253 nr = (a.isempty () ? 0 : a.idx_type_value (true)); |
a533a7c4d2cc
Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25927
diff
changeset
|
1254 nc = (b.isempty () ? 0 : b.idx_type_value (true)); |
3354 | 1255 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1256 check_dimensions (nr, nc, warn_for); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1257 } |
3354 | 1258 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1259 octave_idx_type dims_to_numel (const dim_vector& dims, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1260 const octave_value_list& idx_arg) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1261 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1262 octave_idx_type retval; |
3354 | 1263 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1264 octave_idx_type len = idx_arg.length (); |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1265 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1266 if (len == 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1267 retval = dims.numel (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1268 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1269 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1270 const dim_vector dv = dims.redim (len); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1271 retval = 1; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1272 for (octave_idx_type i = 0; i < len; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1273 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1274 octave_value idxi = idx_arg(i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1275 if (idxi.is_magic_colon ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1276 retval *= dv(i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1277 else if (idxi.isnumeric ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1278 retval *= idxi.numel (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1279 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1280 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1281 try |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1282 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1283 idx_vector jdx = idxi.index_vector (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1284 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1285 retval *= jdx.length (dv(i)); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1286 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1287 catch (const index_exception& e) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1288 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1289 std::string idx = e.idx (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1290 std::string msg = e.details (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1291 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1292 error ("dims_to_numel: Invalid IDX %s. %s", |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1293 idx.c_str (), msg.c_str ()); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1294 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1295 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1296 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1297 } |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
1298 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1299 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1300 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1301 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1302 Matrix identity_matrix (octave_idx_type nr, octave_idx_type nc) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1303 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1304 Matrix m (nr, nc, 0.0); |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1305 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1306 if (nr > 0 && nc > 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1307 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1308 octave_idx_type n = std::min (nr, nc); |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1309 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1310 for (octave_idx_type i = 0; i < n; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1311 m (i, i) = 1.0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1312 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1313 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1314 return m; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1315 } |
4478 | 1316 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1317 FloatMatrix float_identity_matrix (octave_idx_type nr, octave_idx_type nc) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1318 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1319 FloatMatrix m (nr, nc, 0.0); |
4478 | 1320 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1321 if (nr > 0 && nc > 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1322 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1323 octave_idx_type n = std::min (nr, nc); |
4478 | 1324 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1325 for (octave_idx_type i = 0; i < n; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1326 m (i, i) = 1.0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1327 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1328 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1329 return m; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1330 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1331 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1332 size_t format (std::ostream& os, const char *fmt, ...) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1333 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1334 size_t retval; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1335 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1336 va_list args; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1337 va_start (args, fmt); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1338 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1339 retval = vformat (os, fmt, args); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1340 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1341 va_end (args); |
3620 | 1342 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1343 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1344 } |
3620 | 1345 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1346 size_t vformat (std::ostream& os, const char *fmt, va_list args) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1347 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1348 std::string s = vasprintf (fmt, args); |
3620 | 1349 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1350 os << s; |
3620 | 1351 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1352 return s.length (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1353 } |
3620 | 1354 |
27279
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1355 size_t format (std::ostream& os, const std::string& enc, const char *fmt, ...) |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1356 { |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1357 size_t retval; |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1358 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1359 va_list args; |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1360 va_start (args, fmt); |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1361 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1362 retval = vformat (os, enc, fmt, args); |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1363 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1364 va_end (args); |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1365 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1366 return retval; |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1367 } |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1368 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1369 size_t vformat (std::ostream& os, const std::string& enc, const char *fmt, |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1370 va_list args) |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1371 { |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1372 std::string s = vasprintf (fmt, args); |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1373 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1374 if (enc.compare ("utf-8")) |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1375 os << string::u8_to_encoding ("printf", s, enc); |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1376 else |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1377 os << s; |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1378 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1379 return s.length (); |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1380 } |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1381 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1382 std::string vasprintf (const char *fmt, va_list args) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1383 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1384 std::string retval; |
3620 | 1385 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1386 char *result; |
4135 | 1387 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1388 int status = octave_vasprintf_wrapper (&result, fmt, args); |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1389 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1390 if (status >= 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1391 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1392 retval = result; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1393 ::free (result); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1394 } |
4302 | 1395 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1396 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1397 } |
3620 | 1398 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1399 std::string asprintf (const char *fmt, ...) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1400 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1401 std::string retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1402 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1403 va_list args; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1404 va_start (args, fmt); |
3620 | 1405 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1406 retval = vasprintf (fmt, args); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1407 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1408 va_end (args); |
4302 | 1409 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1410 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1411 } |
4302 | 1412 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1413 // FIXME: sleep is complicated because we want it to be interruptible. |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1414 // With the way this program handles signals, the sleep system call |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1415 // won't respond to SIGINT. Maybe there is a better way than |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1416 // breaking this up into multiple shorter intervals? |
4302 | 1417 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1418 void sleep (double seconds, bool do_graphics_events) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1419 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1420 if (seconds <= 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1421 return; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1422 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1423 // Allow free access to graphics resources while the interpreter thread |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1424 // is asleep |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1425 |
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1426 gh_manager& gh_mgr = __get_gh_manager__ ("sleep"); |
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1427 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1428 if (do_graphics_events) |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1429 gh_mgr.unlock (); |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1430 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1431 if (math::isinf (seconds)) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1432 { |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1433 // Wait for kbhit |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1434 int c = -1; |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1435 flush_stdout (); |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1436 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1437 struct timespec one_tenth = { 0, 100000000 }; |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1438 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1439 while (c < 0) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1440 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1441 octave_nanosleep_wrapper (&one_tenth, nullptr); |
24604
6b3c78f84d3b
allow octave_sleep to be interruptible (bug #52876)
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1442 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1443 octave_quit (); |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1444 |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1445 if (do_graphics_events) |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1446 gh_mgr.process_events (); |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1447 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1448 c = kbhit (false); |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1449 } |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1450 } |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1451 else |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1452 { |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1453 sys::time now; |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1454 double end_time = now.double_value () + seconds; |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1455 double remaining_time = seconds; |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1456 |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1457 // Split pause into 100 ms time steps to allow the execution of |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1458 // graphics events and interrupts. |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1459 struct timespec nano_laps = { 0, 100000000 }; |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1460 |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1461 while (remaining_time > 0.1) |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1462 { |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1463 octave_quit (); |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1464 |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1465 if (do_graphics_events) |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1466 { |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1467 gh_mgr.process_events (); |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1468 |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1469 now.stamp (); |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1470 remaining_time = end_time - now.double_value (); |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1471 |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1472 if (remaining_time < 0.1) |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1473 break; |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1474 } |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1475 |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1476 octave_nanosleep_wrapper (&nano_laps, nullptr); |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1477 |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1478 now.stamp (); |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1479 remaining_time = end_time - now.double_value (); |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1480 } |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1481 |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1482 if (remaining_time > 0.0) |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1483 { |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1484 nano_laps = { 0, static_cast<int> (remaining_time * 1e9) }; |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1485 octave_nanosleep_wrapper (&nano_laps, nullptr); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1486 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1487 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1488 } |
4086 | 1489 } |
1490 | |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
1491 DEFMETHOD (isindex, interp, args, , |
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
1492 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1493 @deftypefn {} {} isindex (@var{ind}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1494 @deftypefnx {} {} isindex (@var{ind}, @var{n}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1495 Return true if @var{ind} is a valid index. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1496 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1497 Valid indices are either positive integers (although possibly of real data |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1498 type), or logical arrays. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1499 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1500 If present, @var{n} specifies the maximum extent of the dimension to be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1501 indexed. When possible the internal result is cached so that subsequent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1502 indexing using @var{ind} will not perform the check again. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1503 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1504 Implementation Note: Strings are first converted to double values before the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1505 checks for valid indices are made. Unless a string contains the NULL |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1506 character @nospell{"@xbackslashchar{}0"}, it will always be a valid index. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1507 @end deftypefn */) |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1508 { |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1509 int nargin = args.length (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1510 |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1511 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1512 print_usage (); |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1513 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1514 octave_idx_type n = 0; |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1515 if (nargin == 2) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1516 n = args(1).idx_type_value (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1517 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1518 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1519 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1520 try |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1521 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1522 idx_vector idx = args(0).index_vector (true); |
18130
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
18105
diff
changeset
|
1523 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1524 if (nargin == 2) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1525 retval = idx.extent (n) <= n; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1526 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1527 retval = true; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1528 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1529 catch (const octave::execution_exception&) |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1530 { |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
1531 interp.recover_from_exception (); |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
1532 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1533 retval = false; |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1534 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1535 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1536 return retval; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1537 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1538 |
13094 | 1539 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1540 %!assert (isindex ([1, 2, 3])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1541 %!assert (isindex (1:3)) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1542 %!assert (isindex (1:3, 2), false) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1543 %!assert (isindex ([1, 2, -3]), false) |
13094 | 1544 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1545 %!error isindex () |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1546 %!error isindex (1:3, 2, 3) |
13094 | 1547 */ |
1548 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1549 namespace octave |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1550 { |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1551 octave_value_list |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1552 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1553 const char *fun_name, const octave_value_list& args, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1554 int nargout) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1555 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1556 octave_value_list new_args = args; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1557 octave_value_list retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1558 int nargin = args.length (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1559 OCTAVE_LOCAL_BUFFER (bool, iscell, nargin); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1560 OCTAVE_LOCAL_BUFFER (Cell, cells, nargin); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1561 OCTAVE_LOCAL_BUFFER (Cell, rcells, nargout); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1562 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1563 const Cell *ccells = cells; |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1564 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1565 octave_idx_type numel = 1; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1566 dim_vector dims (1, 1); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1567 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1568 for (int i = 0; i < nargin; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1569 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1570 octave_value arg = new_args(i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1571 iscell[i] = arg.iscell (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1572 if (iscell[i]) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1573 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1574 cells[i] = arg.cell_value (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1575 octave_idx_type n = ccells[i].numel (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1576 if (n == 1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1577 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1578 iscell[i] = false; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1579 new_args(i) = ccells[i](0); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1580 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1581 else if (numel == 1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1582 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1583 numel = n; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1584 dims = ccells[i].dims (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1585 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1586 else if (dims != ccells[i].dims ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1587 error ("%s: cell arguments must have matching sizes", fun_name); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1588 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1589 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1590 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1591 for (int i = 0; i < nargout; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1592 rcells[i].clear (dims); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1593 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1594 for (octave_idx_type j = 0; j < numel; j++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1595 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1596 for (int i = 0; i < nargin; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1597 if (iscell[i]) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1598 new_args(i) = ccells[i](j); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1599 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1600 octave_quit (); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1601 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1602 const octave_value_list tmp = fun (new_args, nargout); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1603 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1604 if (tmp.length () < nargout) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1605 error ("%s: do_simple_cellfun: internal error", fun_name); |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
1606 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1607 for (int i = 0; i < nargout; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1608 rcells[i](j) = tmp(i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1609 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1610 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1611 retval.resize (nargout); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1612 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1613 for (int i = 0; i < nargout; i++) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1614 retval(i) = rcells[i]; |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1615 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1616 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1617 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1618 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1619 octave_value |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1620 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1621 const char *fun_name, const octave_value_list& args) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1622 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1623 octave_value retval; |
20973 | 1624 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1625 const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1); |
20973 | 1626 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1627 if (tmp.length () > 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1628 retval = tmp(0); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1629 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1630 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1631 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1632 } |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1633 |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1634 DEFUN (isstudent, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1635 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1636 @deftypefn {} {} isstudent () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1637 Return true if running in the student edition of @sc{matlab}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1638 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1639 @code{isstudent} always returns false in Octave. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1640 @seealso{false} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1641 @end deftypefn */) |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1642 { |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1643 if (args.length () != 0) |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1644 print_usage (); |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1645 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1646 return ovl (false); |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1647 } |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1648 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1649 /* |
19152
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1650 %!assert (isstudent (), false) |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1651 |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1652 %!error isstudent (1) |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1653 */ |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1654 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25646
diff
changeset
|
1655 // Always define these functions. The macro is intended to allow the |
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25646
diff
changeset
|
1656 // declarations to be hidden, not so that Octave will not provide the |
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25646
diff
changeset
|
1657 // functions if they are requested. |
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25646
diff
changeset
|
1658 |
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25646
diff
changeset
|
1659 // #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1660 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1661 #include "ov.h" |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1662 #include "ovl.h" |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1663 #include "str-vec.h" |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1664 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1665 bool |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1666 valid_identifier (const char *s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1667 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1668 return octave::valid_identifier (s); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1669 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1670 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1671 bool |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1672 valid_identifier (const std::string& s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1673 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1674 return octave::valid_identifier (s); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1675 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1676 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1677 bool |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1678 same_file (const std::string& f, const std::string& g) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1679 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1680 return octave::same_file (f, g); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1681 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1682 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1683 int |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1684 almost_match (const std::string& std, const std::string& s, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1685 int min_match_len, int case_sens) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1686 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1687 return octave::almost_match (std, s, min_match_len, case_sens); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1688 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1689 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1690 int |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1691 keyword_almost_match (const char * const *std, int *min_len, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1692 const std::string& s, int min_toks_to_match, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1693 int max_toks) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1694 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1695 return octave::keyword_almost_match (std, min_len, s, min_toks_to_match, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1696 max_toks); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1697 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1698 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1699 std::string |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1700 search_path_for_file (const std::string& path, const string_vector& names) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1701 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1702 return octave::search_path_for_file (path, names); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1703 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1704 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1705 string_vector |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1706 search_path_for_all_files (const std::string& path, const string_vector& names) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1707 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1708 return octave::search_path_for_all_files (path, names); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1709 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1710 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1711 std::string |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1712 file_in_path (const std::string& name, const std::string& suffix) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1713 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1714 return octave::file_in_path (name, suffix); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1715 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1716 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1717 std::string |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1718 find_data_file_in_load_path (const std::string& fcn, const std::string& file, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1719 bool require_regular_file) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1720 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1721 return octave::find_data_file_in_load_path (fcn, file, require_regular_file); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1722 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1723 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1724 std::string |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1725 contents_file_in_path (const std::string& s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1726 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1727 return octave::contents_file_in_path (s); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1728 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1729 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1730 std::string |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1731 fcn_file_in_path (const std::string& s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1732 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1733 return octave::fcn_file_in_path (s); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1734 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1735 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1736 std::string |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1737 do_string_escapes (const std::string& s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1738 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1739 return octave::do_string_escapes (s); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1740 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1741 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1742 const char * |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1743 undo_string_escape (char c) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1744 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1745 return octave::undo_string_escape (c); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1746 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1747 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1748 std::string |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1749 undo_string_escapes (const std::string& s) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1750 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1751 return octave::undo_string_escapes (s); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1752 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1753 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1754 void |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1755 check_dimensions (dim_vector& dim, const char *warnfor) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1756 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1757 return octave::check_dimensions (dim, warnfor); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1758 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1759 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1760 void |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1761 get_dimensions (const octave_value& a, const char *warn_for, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1762 dim_vector& dim) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1763 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1764 return octave::get_dimensions (a, warn_for, dim); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1765 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1766 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1767 void |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1768 get_dimensions (const octave_value& a, const octave_value& b, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1769 const char *warn_for, octave_idx_type& nr, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1770 octave_idx_type& nc) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1771 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1772 return octave::get_dimensions (a, b, warn_for, nr, nc); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1773 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1774 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1775 void |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1776 get_dimensions (const octave_value& a, const char *warn_for, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1777 octave_idx_type& nr, octave_idx_type& nc) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1778 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1779 return octave::get_dimensions (a, warn_for, nr, nc); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1780 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1781 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1782 octave_idx_type |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1783 dims_to_numel (const dim_vector& dims, const octave_value_list& idx) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1784 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1785 return octave::dims_to_numel (dims, idx); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1786 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1787 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1788 Matrix |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1789 identity_matrix (octave_idx_type nr, octave_idx_type nc) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1790 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1791 return octave::identity_matrix (nr, nc); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1792 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1793 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1794 FloatMatrix |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1795 float_identity_matrix (octave_idx_type nr, octave_idx_type nc) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1796 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1797 return octave::float_identity_matrix (nr, nc); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1798 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1799 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1800 size_t |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1801 octave_vformat (std::ostream& os, const char *fmt, va_list args) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1802 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1803 return octave::vformat (os, fmt, args); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1804 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1805 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1806 std::string |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1807 octave_vasprintf (const char *fmt, va_list args) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1808 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1809 return octave::vasprintf (fmt, args); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1810 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1811 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1812 void |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1813 octave_sleep (double seconds) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1814 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1815 octave::sleep (seconds); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1816 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1817 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1818 octave_value_list |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1819 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1820 const char *fun_name, const octave_value_list& args, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1821 int nargout) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1822 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1823 return octave::do_simple_cellfun (fun, fun_name, args, nargout); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1824 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1825 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1826 octave_value |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1827 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1828 const char *fun_name, const octave_value_list& args) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1829 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1830 return octave::do_simple_cellfun (fun, fun_name, args); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1831 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1832 |
25659
e6d3f4f9473c
always provide definitions for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
25646
diff
changeset
|
1833 // #endif |