Mercurial > octave
annotate libinterp/corefcn/utils.cc @ 29960:939bef0b66e0
merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
In files with both OCTAVE_NAMESPACE_BEGIN/END and "namespace octave"
blocks, merge adjacent blocks. Use the macros in place of "namespace
octave" in affected files and the corresponding header files.
Files affected: call-stack.cc, call-stack.h, defaults.cc, defaults.h,
defun-int.h, display.cc, display.h, environment.cc, environment.h,
error.cc, error.h, event-manager.cc, event-manager.h, fcn-info.cc,
fcn-info.h, help.cc, help.h, input.cc, input.h, interpreter.cc,
interpreter.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
oct-hist.cc, oct-hist.h, pager.cc, pager.h, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, symtab.cc, symtab.h, sysdep.cc,
sysdep.h, utils.cc, utils.h, __ode15__.cc, gzip.cc, ov-fcn-handle.cc,
ov-fcn-handle.h, ov-java.cc, ov-java.h, ov-typeinfo.cc, ov-typeinfo.h,
ov.cc, ov.h, octave.cc, octave.h, lex.ll, oct-parse.yy, profiler.cc,
profiler.h, pt-eval.cc, and pt-eval.h.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 14 Aug 2021 21:50:26 -0400 |
parents | 32c3a5805893 |
children | 7d6709900da7 |
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 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
28292
diff
changeset
|
3 // Copyright (C) 1993-2021 The Octave Project Developers |
27923
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 |
29960
939bef0b66e0
merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
73 OCTAVE_NAMESPACE_BEGIN |
939bef0b66e0
merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
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 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
93 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8715
diff
changeset
|
94 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
|
95 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
|
96 @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
|
97 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
|
98 |
82b9b970ff19
doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents:
26203
diff
changeset
|
99 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
|
100 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
|
101 @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
|
102 @end deftypefn */) |
4264 | 103 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
104 if (args.length () != 1) |
5823 | 105 print_usage (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
106 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
107 octave_value retval = false; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
108 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
109 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
|
110 { |
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
111 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
|
112 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
113 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
|
114 && ! 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
|
115 } |
4264 | 116 |
117 return retval; | |
118 } | |
119 | |
13094 | 120 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
121 %!assert (isvarname ("foo"), true) |
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 ("_1"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
124 %!assert (isvarname ("1foo"), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
125 %!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
|
126 %!assert (isvarname (12), false) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
127 %!assert (isvarname ("foo+bar"), false) |
13094 | 128 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
129 %!error isvarname () |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21526
diff
changeset
|
130 %!error isvarname ("foo", "bar") |
13094 | 131 */ |
132 | |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
133 bool |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
134 make_valid_name (std::string& str, const make_valid_name_options& options) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
135 { |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
136 // If `isvarname (str)`, no modifications necessary. |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
137 if (valid_identifier (str) && ! iskeyword (str)) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
138 return false; |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
139 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
140 // Change whitespace followed by lowercase letter to uppercase, except |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
141 // for the first |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
142 bool previous = false; |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
143 bool any_non_space = false; |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
144 for (char& c : str) |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
145 { |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
146 c = ((any_non_space && previous && std::isalpha (c)) ? std::toupper (c) |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
147 : c); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
148 previous = std::isspace (c); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
149 any_non_space |= (! previous); // once true, always true |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
150 } |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
151 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
152 // Remove any whitespace. |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
153 str.erase (std::remove_if (str.begin(), str.end(), |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
154 [] (unsigned char x) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
155 { return std::isspace(x); }), |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
156 str.end()); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
157 if (str.empty ()) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
158 str = options.get_prefix (); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
159 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
160 // Add prefix and capitalize first character, if `str` is a reserved |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
161 // keyword. |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
162 if (iskeyword (str)) |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
163 { |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
164 str[0] = std::toupper (str[0]); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
165 str = options.get_prefix () + str; |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
166 } |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
167 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
168 // Add prefix if first character is not a letter or underscore. |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
169 if (! std::isalpha (str[0]) && str[0] != '_') |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
170 str = options.get_prefix () + str; |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
171 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
172 // Replace non alphanumerics or underscores |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
173 if (options.get_replacement_style () == "underscore") |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
174 for (char& c : str) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
175 c = (std::isalnum (c) ? c : '_'); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
176 else if (options.get_replacement_style () == "delete") |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
177 str.erase (std::remove_if (str.begin(), str.end(), |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
178 [] (unsigned char x) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
179 { return ! std::isalnum (x) && x != '_'; }), |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
180 str.end()); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
181 else if (options.get_replacement_style () == "hex") |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
182 { |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
183 const std::string permitted_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
184 "abcdefghijklmnopqrstuvwxyz" |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
185 "_0123456789"; |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
186 // Get the first non-permitted char. |
29572
aef11bb4e6d1
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
187 std::size_t pos = str.find_first_not_of (permitted_chars); |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
188 // Buffer for hex string "0xFF" (+1 for null terminator). |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
189 char hex_str[5]; |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
190 // Repeat until end of string. |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
191 while (pos != std::string::npos) |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
192 { |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
193 // Replace non-permitted char by it's hex value. |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
194 std::snprintf (hex_str, sizeof (hex_str), "0x%02X", str[pos]); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
195 str.replace (pos, 1, hex_str); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
196 // Get the next occurrence from the last position. |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
197 // (-1 for null terminator) |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
198 pos = str.find_first_not_of (permitted_chars, |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
199 pos + sizeof (hex_str) - 1); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
200 } |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
201 } |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
202 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
203 return true; |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
204 } |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
205 |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
206 make_valid_name_options::make_valid_name_options |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
207 (const octave_value_list& args) |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
208 { |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
209 auto nargs = args.length (); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
210 if (nargs == 0) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
211 return; |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
212 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
213 // nargs = 2, 4, 6, ... permitted |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
214 if (nargs % 2) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
215 error ("makeValidName: property/value options must occur in pairs"); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
216 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
217 auto str_to_lower = [] (std::string& s) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
218 { |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
219 std::transform (s.begin(), s.end(), s.begin(), |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
220 [] (unsigned char c) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
221 { return std::tolower(c); }); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
222 }; |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
223 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
224 for (auto i = 0; i < nargs; i = i + 2) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
225 { |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
226 std::string parameter = args(i).xstring_value ("makeValidName: " |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
227 "option argument must be a string"); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
228 str_to_lower (parameter); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
229 if (parameter == "replacementstyle") |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
230 { |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
231 m_replacement_style = args(i + 1).xstring_value ("makeValidName: " |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
232 "'ReplacementStyle' value must be a string"); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
233 str_to_lower (m_replacement_style); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
234 if ((m_replacement_style != "underscore") |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
235 && (m_replacement_style != "delete") |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
236 && (m_replacement_style != "hex")) |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
237 error ("makeValidName: invalid 'ReplacementStyle' value '%s'", |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
238 m_replacement_style.c_str ()); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
239 } |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
240 else if (parameter == "prefix") |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
241 { |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
242 m_prefix = args(i + 1).xstring_value ("makeValidName: " |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
243 "'Prefix' value must be a string"); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
244 if (! octave::valid_identifier (m_prefix) |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
245 || octave::iskeyword (m_prefix)) |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
246 error ("makeValidName: invalid 'Prefix' value '%s'", |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
247 m_prefix.c_str ()); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
248 } |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
249 else |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
250 error ("makeValidName: unknown property '%s'", parameter.c_str ()); |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
251 } |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
252 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
253 |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
254 DEFUN (__make_valid_name__, args, , |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
255 doc: /* -*- texinfo -*- |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
256 @deftypefn {} {@var{varname} =} __make_valid_name__ (@var{str}) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
257 @deftypefnx {} {@var{varname} =} __make_valid_name__ (@var{str}, @qcode{"ReplacementStyle"}) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
258 @deftypefnx {} {@var{varname} =} __make_valid_name__ (@var{str}, @qcode{"ReplacementStyle"}, @qcode{"Prefix"}) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
259 @deftypefnx {} {[@var{varname}, @var{ismodified}] =} __make_valid_name__ (@dots{}) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
260 Return a valid variable name @var{varname} from input @var{str}. |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
261 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
262 For more documentation, see @code{matlab.lang.makeValidName}. |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
263 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
264 @seealso{isvarname, matlab.lang.makeValidName} |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
265 @end deftypefn */) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
266 { |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
267 auto nargin = args.length (); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
268 if (nargin < 1) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
269 print_usage (); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
270 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
271 octave::make_valid_name_options options (args.slice (1, nargin - 1)); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
272 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
273 if (args(0).is_string ()) |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
274 { |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
275 std::string varname = args(0).string_value (); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
276 bool is_modified = octave::make_valid_name (varname, options); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
277 return ovl (varname, is_modified); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
278 } |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
279 else if (args(0).iscellstr ()) |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
280 { |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
281 Array<std::string> varnames = args(0).cellstr_value (); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
282 Array<bool> is_modified (varnames.dims ()); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
283 for (auto i = 0; i < varnames.numel (); i++) |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
284 is_modified(i) = octave::make_valid_name (varnames(i), options); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
285 return ovl (varnames, is_modified); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
286 } |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
287 else |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
288 error ("makeValidName: STR must be a string or cellstr"); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
289 } |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
290 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
291 // Return TRUE if F and G are both names for the same file. |
6323 | 292 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
293 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
|
294 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
295 return same_file_internal (f, g); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
296 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
297 |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
298 DEFUN (is_same_file, args, , |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
299 doc: /* -*- texinfo -*- |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
300 @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
|
301 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
|
302 |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
303 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
|
304 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
|
305 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
|
306 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
|
307 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
316 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
|
317 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
|
318 return true. |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
319 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
320 @seealso{canonicalize_file_name, strcmp} |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
321 @end deftypefn */) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
322 { |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
323 if (args.length () != 2) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
324 print_usage (); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
325 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
326 octave_value retval; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
327 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
328 bool s1_string = args(0).is_string (); |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
329 bool s1_cellstr = args(0).iscellstr (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
330 bool s2_string = args(1).is_string (); |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
331 bool s2_cellstr = args(1).iscellstr (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
332 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
333 if (s1_string && s2_string) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
334 { |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
335 std::string file1 = args(0).string_value (); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
336 std::string file2 = args(1).string_value (); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
337 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
338 retval = octave::same_file (file1, file2); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
339 } |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
340 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
|
341 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
342 octave_value str_arg, cellstr_arg; |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
343 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
344 if (s1_string) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
345 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
346 str_arg = args(0); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
347 cellstr_arg = args(1); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
348 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
349 else |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
350 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
351 str_arg = args(1); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
352 cellstr_arg = args(0); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
353 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
354 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
355 const Array<std::string> cellstr = cellstr_arg.cellstr_value (); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
356 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
|
357 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
358 boolNDArray output (cellstr.dims (), false); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
359 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
360 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
|
361 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
|
362 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
363 retval = output; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
364 } |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
365 else if (s1_cellstr && s2_cellstr) |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
366 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
367 const Array<std::string> cellstr1 = args(0).cellstr_value (); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
368 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
|
369 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
370 const dim_vector size1 = cellstr1.dims (); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
371 const dim_vector size2 = cellstr2.dims (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
372 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
373 if (size1 != size2) |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
374 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
|
375 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
376 boolNDArray output (size1, false); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
377 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
378 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
|
379 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
|
380 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
381 retval = output; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
382 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
383 else |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
384 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
|
385 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
386 return retval; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
387 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
388 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
389 /* |
27580
e7df1df55f0e
Fix BIST test for is_same_file on Windows platforms.
Rik <rik@octave.org>
parents:
27571
diff
changeset
|
390 %!testif ; ! ispc () |
e7df1df55f0e
Fix BIST test for is_same_file on Windows platforms.
Rik <rik@octave.org>
parents:
27571
diff
changeset
|
391 %! assert (is_same_file ("~", tilde_expand ("~"))); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
392 %!testif ; ispc () |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
393 %! 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
|
394 %! toupper (getenv ("OCTAVE_HOME"))), true); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
395 %!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
|
396 %! [true, true, false]) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
397 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
398 %!error is_same_file () |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
399 %!error is_same_file ("foo") |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
400 %!error is_same_file ("foo", "bar", "baz") |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
401 %!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
|
402 %!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
|
403 %!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
|
404 %!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
|
405 %!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
|
406 */ |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
407 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
408 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
|
409 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
|
410 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
411 int stdlen = std.length (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
412 int slen = s.length (); |
1 | 413 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
414 return (slen <= stdlen |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
415 && slen >= min_match_len |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
416 && (case_sens |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
417 ? (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
|
418 : (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
|
419 } |
287 | 420 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
421 // Ugh. |
581 | 422 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
423 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
|
424 const std::string& s, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
425 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
|
426 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
427 int status = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
428 int tok_count = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
429 int toks_matched = 0; |
287 | 430 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
431 if (s.empty () || max_toks < 1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
432 return status; |
287 | 433 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
434 char *kw = strsave (s.c_str ()); |
287 | 435 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
436 char *t = kw; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
437 while (*t != '\0') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
438 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
439 if (*t == '\t') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
440 *t = ' '; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
441 t++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
442 } |
287 | 443 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
444 char *beg = kw; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
445 while (*beg == ' ') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
446 beg++; |
287 | 447 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
448 if (*beg == '\0') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
449 return status; |
287 | 450 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
451 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
|
452 const char * const *s1 = std; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
453 const char **s2 = to_match; |
287 | 454 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
455 if (! s1 || ! s2) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
456 goto done; |
287 | 457 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
458 s2[tok_count] = beg; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
459 char *end; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
460 while ((end = strchr (beg, ' ')) != nullptr) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
461 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
462 *end = '\0'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
463 beg = end + 1; |
287 | 464 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
465 while (*beg == ' ') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
466 beg++; |
287 | 467 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
468 if (*beg == '\0') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
469 break; |
287 | 470 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
471 tok_count++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
472 if (tok_count >= max_toks) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
473 goto done; |
287 | 474 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
475 s2[tok_count] = beg; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
476 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
477 s2[tok_count+1] = nullptr; |
287 | 478 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
479 s2 = to_match; |
287 | 480 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
481 for (;;) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
482 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
483 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
|
484 goto done; |
287 | 485 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
486 toks_matched++; |
287 | 487 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
488 s1++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
489 s2++; |
287 | 490 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
491 if (! *s2) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
492 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
493 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
|
494 goto done; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
495 } |
287 | 496 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
497 if (! *s1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
498 goto done; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
499 } |
287 | 500 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
501 done: |
287 | 502 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
503 delete [] kw; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
504 delete [] to_match; |
287 | 505 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
506 return status; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
507 } |
1 | 508 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
509 // See if the given file is in the path. |
581 | 510 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
511 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
|
512 const string_vector& names) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
513 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
514 directory_path p (path); |
686 | 515 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
516 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
|
517 } |
686 | 518 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
519 // Find all locations of the given file in the path. |
4216 | 520 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
521 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
|
522 const string_vector& names) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
523 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
524 directory_path p (path); |
4216 | 525 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
526 string_vector sv = p.find_all_first_of (names.std_list ()); |
4216 | 527 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
528 octave_idx_type len = sv.numel (); |
4216 | 529 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
530 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
|
531 sv[i] = sys::env::make_absolute (sv[i]); |
4216 | 532 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
533 return sv; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
534 } |
4216 | 535 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
536 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
|
537 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
538 octave_idx_type len = sv.numel (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
539 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
540 string_vector retval (len); |
6379 | 541 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
542 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
|
543 retval[i] = sys::env::make_absolute (sv[i]); |
4216 | 544 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
545 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
546 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
547 |
23519
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
548 DEFMETHOD (file_in_loadpath, interp, args, , |
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
549 doc: /* -*- texinfo -*- |
23988
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
550 @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
|
551 @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
|
552 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
|
553 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
|
554 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
555 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
|
556 |
23988
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
557 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
|
558 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
|
559 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
|
560 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
561 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
|
562 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
|
563 matches. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
564 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
565 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
|
566 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
|
567 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
|
568 @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
|
569 @end deftypefn */) |
3195 | 570 { |
4243 | 571 int nargin = args.length (); |
3195 | 572 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
573 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
574 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
575 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20973
diff
changeset
|
576 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
|
577 |
20973 | 578 if (names.empty ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
579 error ("file_in_loadpath: FILE argument must not be empty"); |
4243 | 580 |
23519
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
581 octave::load_path& lp = interp.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
582 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
583 if (nargin == 1) |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
584 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
|
585 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
586 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
587 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
|
588 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
589 if (opt != "all") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
590 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
|
591 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
592 return ovl (Cell (octave::make_absolute (lp.find_all_first_of (names)))); |
4216 | 593 } |
3195 | 594 } |
595 | |
13094 | 596 /* |
597 %!test | |
598 %! f = file_in_loadpath ("plot.m"); | |
599 %! assert (ischar (f)); | |
600 %! assert (! isempty (f)); | |
601 | |
602 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
603 %! f = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$"); |
13094 | 604 %! assert (f, ""); |
605 | |
606 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
607 %! lst = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$", "all"); |
13094 | 608 %! assert (lst, {}); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
609 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
610 %!error file_in_loadpath () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
611 %!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
|
612 %!error file_in_loadpath ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
613 %!error file_in_loadpath ("plot.m", "bar") |
13094 | 614 */ |
615 | |
1957 | 616 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
|
617 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
|
618 @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
|
619 @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
|
620 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
|
621 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
622 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
|
623 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
|
624 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
|
625 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
626 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
627 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
628 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
|
629 @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
|
630 @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
|
631 @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
|
632 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
633 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
|
634 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
|
635 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
636 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
|
637 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
|
638 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
|
639 @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
|
640 @end deftypefn */) |
686 | 641 { |
4243 | 642 int nargin = args.length (); |
1755 | 643 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
644 if (nargin < 2 || nargin > 3) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
645 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
646 |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
647 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
|
648 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20973
diff
changeset
|
649 string_vector names = args(1).xstring_vector_value ("file_in_path: FILE argument must be a string"); |
4243 | 650 |
20973 | 651 if (names.empty ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
652 error ("file_in_path: FILE argument must not be empty"); |
4243 | 653 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
654 if (nargin == 2) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
655 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
|
656 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
657 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
658 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
|
659 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
660 if (opt != "all") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
661 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
|
662 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
663 return ovl (Cell (octave::make_absolute (octave::search_path_for_all_files (path, names)))); |
686 | 664 } |
665 } | |
666 | |
13094 | 667 /* |
668 %!test | |
669 %! f = file_in_path (path (), "plot.m"); | |
670 %! assert (ischar (f)); | |
671 %! assert (! isempty (f)); | |
672 | |
673 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
674 %! f = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$"); |
13094 | 675 %! assert (f, ""); |
676 | |
677 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
678 %! lst = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$", "all"); |
13094 | 679 %! assert (lst, {}); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
680 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
681 %!error file_in_path () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
682 %!error file_in_path ("foo") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
683 %!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
|
684 %!error file_in_path ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
685 %!error file_in_path (path (), []) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
686 %!error file_in_path (path (), "plot.m", "bar") |
13094 | 687 */ |
688 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
689 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
|
690 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
691 std::string nm = name; |
526 | 692 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
693 if (! suffix.empty ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
694 nm.append (suffix); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
695 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
696 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
|
697 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
698 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
|
699 } |
526 | 700 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
701 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
|
702 const std::string& file, |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
703 bool require_regular_file) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
704 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
705 std::string fname = file; |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
706 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
707 if (! (sys::env::absolute_pathname (fname) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
708 || sys::env::rooted_relative_pathname (fname))) |
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 // 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
|
711 // 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
|
712 // 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
|
713 sys::file_stat fs (fname); |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
714 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
715 bool local_file_ok |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
716 = fs.exists () && (fs.is_reg () || ! require_regular_file); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
717 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
718 if (! local_file_ok) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
719 { |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
720 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
|
721 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
722 // 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
|
723 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
|
724 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
725 if (! tmp.empty ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
726 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
727 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
|
728 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
729 fname = tmp; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
730 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
731 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
732 } |
581 | 733 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
734 return fname; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
735 } |
908 | 736 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
737 // 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
|
738 // 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
|
739 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
740 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
|
741 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
742 std::string retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
743 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
744 int len = name.length (); |
5832 | 745 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
746 if (len > 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
747 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
748 if (sys::env::absolute_pathname (name)) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
749 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
750 sys::file_stat fs (name); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
751 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
752 if (fs.exists () && ! fs.is_dir ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
753 retval = name; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
754 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
755 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
|
756 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
757 load_path& lp = __get_load_path__ ("fcn_file_in_path"); |
1755 | 758 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
759 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
|
760 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
761 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
762 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
763 std::string fname = name; |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
764 std::size_t pos = name.find_first_of ('>'); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
765 if (pos != std::string::npos) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
766 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
|
767 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
768 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
|
769 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
770 retval = lp.find_fcn_file (fname); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
771 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
772 } |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
773 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
774 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
775 } |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
776 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
777 // 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
|
778 // 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
|
779 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
780 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
|
781 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
782 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
|
783 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
784 if (! dir.empty ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
785 { |
29140
c7498b5aece0
Fix typo in identifier.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29117
diff
changeset
|
786 load_path& lp = __get_load_path__ ("contents_file_in_path"); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
787 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
788 std::string tcontents |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
789 = sys::file_ops::concat (lp.find_dir (dir), "Contents.m"); |
3103 | 790 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
791 sys::file_stat fs (tcontents); |
3103 | 792 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
793 if (fs.exists ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
794 retval = sys::env::make_absolute (tcontents); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
795 } |
3103 | 796 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
797 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
798 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
799 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
800 // Replace backslash escapes in a string with the real values. |
3103 | 801 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
802 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
|
803 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
804 std::string retval; |
3103 | 805 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
806 std::size_t i = 0; |
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
807 std::size_t j = 0; |
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
808 std::size_t len = s.length (); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
809 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
810 retval.resize (len); |
3103 | 811 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
812 while (j < len) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
813 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
814 if (s[j] == '\\' && j+1 < len) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
815 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
816 switch (s[++j]) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
817 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
818 case 'a': // alarm |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
819 retval[i] = '\a'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
820 break; |
3103 | 821 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
822 case 'b': // backspace |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
823 retval[i] = '\b'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
824 break; |
3103 | 825 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
826 case 'f': // formfeed |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
827 retval[i] = '\f'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
828 break; |
3103 | 829 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
830 case 'n': // newline |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
831 retval[i] = '\n'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
832 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
833 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
834 case 'r': // carriage return |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
835 retval[i] = '\r'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
836 break; |
3103 | 837 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
838 case 't': // horizontal tab |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
839 retval[i] = '\t'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
840 break; |
3103 | 841 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
842 case 'v': // vertical tab |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
843 retval[i] = '\v'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
844 break; |
3103 | 845 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
846 case '\\': // backslash |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
847 retval[i] = '\\'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
848 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
849 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
850 case '\'': // quote |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
851 retval[i] = '\''; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
852 break; |
3103 | 853 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
854 case '"': // double quote |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
855 retval[i] = '"'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
856 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
857 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
858 case '0': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
859 case '1': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
860 case '2': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
861 case '3': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
862 case '4': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
863 case '5': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
864 case '6': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
865 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
|
866 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
867 std::size_t k; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
868 int tmpi = s[j] - '0'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
869 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
|
870 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
871 int digit = s[k] - '0'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
872 if (digit < 0 || digit > 7) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
873 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
874 tmpi <<= 3; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
875 tmpi += digit; |
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 retval[i] = tmpi; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
878 j = k - 1; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
879 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
|
880 } |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
881 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
882 case 'x': // hex input |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
883 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
884 std::size_t k; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
885 int tmpi = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
886 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
|
887 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
888 if (! isxdigit (s[k])) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
889 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
|
890 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
891 tmpi <<= 4; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
892 int digit = s[k]; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
893 if (digit >= 'a') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
894 tmpi += digit - 'a' + 10; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
895 else if (digit >= 'A') |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
896 tmpi += digit - 'A' + 10; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
897 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
898 tmpi += digit - '0'; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
899 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
900 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
901 if (k == j+1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
902 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
|
903 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
904 retval[i] = tmpi; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
905 j = k - 1; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
906 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
907 } |
3103 | 908 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
909 default: |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
910 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
|
911 retval[i] = s[j]; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
912 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
913 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
914 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
915 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
916 retval[i] = s[j]; |
3103 | 917 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
918 i++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
919 j++; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
920 } |
3103 | 921 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
922 retval.resize (i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
923 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
924 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
925 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
926 |
3103 | 927 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
|
928 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
|
929 @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
|
930 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
|
931 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
932 Escape sequences begin with a leading backslash |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
29094
diff
changeset
|
933 (@qcode{'@backslashchar{}'}) followed by 1--3 characters |
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
29094
diff
changeset
|
934 (.e.g., @qcode{"@backslashchar{}n"} => newline). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
935 @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
|
936 @end deftypefn */) |
3103 | 937 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
938 if (args.length () != 1) |
5823 | 939 print_usage (); |
3103 | 940 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
941 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
|
942 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
943 return ovl (octave::do_string_escapes (str)); |
3103 | 944 } |
945 | |
13094 | 946 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
947 %!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
|
948 %!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
|
949 %!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
|
950 %!assert ("foo\nbar", ["foo", char(10), "bar"]) |
13094 | 951 |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
952 %!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
|
953 %!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
|
954 %!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
|
955 %! 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
|
956 %!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
|
957 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
958 %!assert (do_string_escapes ('\\'), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
959 %!assert (do_string_escapes ("\\\\"), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
960 %!assert (do_string_escapes ("\\\\"), char (92)) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
961 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
962 %!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
|
963 %!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
|
964 %!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
|
965 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"") |
13094 | 966 |
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
|
967 %!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
|
968 %!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
|
969 %!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
|
970 %!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
|
971 |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
972 %!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
|
973 %!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
|
974 %!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
|
975 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
976 %!error do_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
977 %!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
|
978 %!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
|
979 %!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
|
980 %!warning <unrecognized escape sequence> do_string_escapes ('\G'); |
13094 | 981 */ |
982 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
983 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
|
984 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
985 if (! c) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
986 return ""; |
801 | 987 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
988 switch (c) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
989 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
990 case '\0': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
991 return R"(\0)"; |
801 | 992 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
993 case '\a': |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
994 return R"(\a)"; |
801 | 995 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
996 case '\b': // backspace |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
997 return R"(\b)"; |
801 | 998 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
999 case '\f': // formfeed |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1000 return R"(\f)"; |
801 | 1001 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1002 case '\n': // newline |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1003 return R"(\n)"; |
801 | 1004 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1005 case '\r': // carriage return |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1006 return R"(\r)"; |
801 | 1007 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1008 case '\t': // horizontal tab |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1009 return R"(\t)"; |
801 | 1010 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1011 case '\v': // vertical tab |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1012 return R"(\v)"; |
801 | 1013 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1014 case '\\': // backslash |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1015 return R"(\\)"; |
801 | 1016 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1017 case '"': // double quote |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1018 return R"(\")"; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1019 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1020 default: |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1021 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1022 static char retval[2] {'\0', '\0'}; |
20973 | 1023 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1024 retval[0] = c; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1025 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1026 } |
1755 | 1027 } |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1028 } |
801 | 1029 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1030 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
|
1031 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1032 std::string retval; |
801 | 1033 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1034 for (std::size_t i = 0; i < s.length (); i++) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1035 retval.append (undo_string_escape (s[i])); |
801 | 1036 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1037 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1038 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1039 |
1957 | 1040 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
|
1041 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
|
1042 @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
|
1043 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
|
1044 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1045 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
|
1046 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1047 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1048 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
|
1049 @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
|
1050 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1051 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 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
|
1057 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
|
1058 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1059 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1060 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1061 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
|
1062 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
|
1063 @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
|
1064 @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
|
1065 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1066 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1067 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
|
1068 @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
|
1069 @end deftypefn */) |
801 | 1070 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
1071 if (args.length () != 1) |
5823 | 1072 print_usage (); |
801 | 1073 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1074 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
|
1075 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1076 return ovl (octave::undo_string_escapes (str)); |
801 | 1077 } |
1078 | |
13094 | 1079 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1080 %!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
|
1081 %!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
|
1082 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar") |
13094 | 1083 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1084 %!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
|
1085 %!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
|
1086 %!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
|
1087 %! "\\a\\b\\f\\n\\r\\t\\v") |
13094 | 1088 |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1089 %!assert (undo_string_escapes ("\\"), '\\') |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1090 %!assert (undo_string_escapes ("\\"), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1091 %!assert (undo_string_escapes (char (92)), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1092 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1093 %!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
|
1094 %!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
|
1095 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1096 %!error undo_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1097 %!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
|
1098 %!error undo_string_escapes (3) |
13094 | 1099 */ |
1100 | |
8229 | 1101 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
|
1102 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
|
1103 @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
|
1104 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
|
1105 @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
|
1106 @end deftypefn */) |
8229 | 1107 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1108 if (args.length () != 1) |
8229 | 1109 print_usage (); |
1110 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1111 return ovl (args(0).is_string () |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1112 && octave::sys::env::absolute_pathname (args(0).string_value ())); |
8229 | 1113 } |
1114 | |
13094 | 1115 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1116 ## FIXME: We need system-dependent tests here. |
13094 | 1117 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1118 %!error is_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1119 %!error is_absolute_filename ("foo", "bar") |
13094 | 1120 */ |
1121 | |
8229 | 1122 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
|
1123 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
|
1124 @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
|
1125 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
|
1126 @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
|
1127 @end deftypefn */) |
8229 | 1128 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1129 if (args.length () != 1) |
8229 | 1130 print_usage (); |
1131 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1132 return ovl (args(0).is_string () |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1133 && octave::sys::env::rooted_relative_pathname (args(0).string_value ())); |
8229 | 1134 } |
1135 | |
13094 | 1136 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1137 ## FIXME: We need system-dependent tests here. |
13094 | 1138 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1139 %!error is_rooted_relative_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1140 %!error is_rooted_relative_filename ("foo", "bar") |
13094 | 1141 */ |
1142 | |
8229 | 1143 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
|
1144 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
|
1145 @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
|
1146 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
|
1147 system. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1148 |
28292
5bf3f462c11e
Document that make_absolute_filename and canonicalize_file_name do not
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
28012
diff
changeset
|
1149 No check is done for the existence of @var{file}. No tilde expansion of |
5bf3f462c11e
Document that make_absolute_filename and canonicalize_file_name do not
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
28012
diff
changeset
|
1150 @var{file} is performed. |
5bf3f462c11e
Document that make_absolute_filename and canonicalize_file_name do not
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
28012
diff
changeset
|
1151 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isfolder, tilde_expand} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1152 @end deftypefn */) |
8229 | 1153 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1154 if (args.length () != 1) |
8229 | 1155 print_usage (); |
1156 | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1157 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
|
1158 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1159 return ovl (octave::sys::env::make_absolute (nm)); |
8229 | 1160 } |
1161 | |
13094 | 1162 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1163 ## FIXME: We need system-dependent tests here. |
13094 | 1164 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1165 %!error make_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1166 %!error make_absolute_filename ("foo", "bar") |
13094 | 1167 */ |
1168 | |
23519
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
1169 DEFMETHOD (dir_in_loadpath, interp, args, , |
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
1170 doc: /* -*- texinfo -*- |
23988
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1171 @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
|
1172 @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
|
1173 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
|
1174 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
|
1175 |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1176 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
|
1177 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1178 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
|
1179 @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
|
1180 @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
|
1181 @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
|
1182 @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
|
1183 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
|
1184 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
|
1185 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
|
1186 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1187 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
|
1188 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
|
1189 @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
|
1190 @end deftypefn */) |
8229 | 1191 { |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
1192 int nargin = args.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
1193 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1194 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1195 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1196 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
1197 std::string dir; |
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
1198 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1199 dir = args(0).xstring_value ("dir_in_loadpath: DIR must be a directory name"); |
8229 | 1200 |
23519
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
1201 octave::load_path& lp = interp.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
1202 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1203 if (nargin == 1) |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
1204 return ovl (lp.find_dir (dir)); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1205 else |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
1206 return ovl (Cell (lp.find_matching_dirs (dir))); |
8229 | 1207 } |
1208 | |
13094 | 1209 /* |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1210 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1211 %! f = dir_in_loadpath ("plot"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1212 %! assert (ischar (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1213 %! assert (! isempty (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1214 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1215 %!test |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1216 %! 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
|
1217 %! assert (f, ""); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1218 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1219 %!test |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1220 %! 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
|
1221 %! assert (lst, {}); |
13094 | 1222 |
18110
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18105
diff
changeset
|
1223 %!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
|
1224 %!error dir_in_loadpath ("foo", "bar", 1) |
13094 | 1225 */ |
1226 | |
5465 | 1227 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
|
1228 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
|
1229 @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
|
1230 @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
|
1231 @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
|
1232 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
|
1233 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1234 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
|
1235 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1236 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
|
1237 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
|
1238 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1239 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
|
1240 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
|
1241 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
|
1242 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1243 @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
|
1244 @end deftypefn */) |
3716 | 1245 { |
5465 | 1246 int nargin = args.length (); |
1247 | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1248 if (nargin > 1) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1249 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1250 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1251 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1252 |
5465 | 1253 if (nargin == 1) |
1254 { | |
1255 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1256 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1257 std::string nm = args(0).string_value (); |
5465 | 1258 |
19743
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1259 retval = octave_errno::lookup (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1260 } |
5465 | 1261 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1262 { |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1263 int val = args(0).xint_value ("errno: argument must be string or integer"); |
5465 | 1264 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1265 retval = octave_errno::set (val); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1266 } |
5465 | 1267 } |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1268 else |
5465 | 1269 retval = octave_errno::get (); |
3716 | 1270 |
1271 return retval; | |
1272 } | |
1273 | |
13094 | 1274 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1275 %!assert (isnumeric (errno ())) |
13094 | 1276 |
1277 %!test | |
1278 %! lst = errno_list (); | |
1279 %! fns = fieldnames (lst); | |
1280 %! oldval = errno (fns{1}); | |
1281 %! assert (isnumeric (oldval)); | |
1282 %! errno (oldval); | |
1283 %! newval = errno (); | |
1284 %! assert (oldval, newval); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1285 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1286 %!error errno ("foo", 1) |
13094 | 1287 */ |
1288 | |
5465 | 1289 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
|
1290 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
|
1291 @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
|
1292 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
|
1293 @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
|
1294 @end deftypefn */) |
5465 | 1295 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1296 if (args.length () != 0) |
5823 | 1297 print_usage (); |
5465 | 1298 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1299 return ovl (octave_errno::list ()); |
5465 | 1300 } |
3716 | 1301 |
13094 | 1302 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1303 %!assert (isstruct (errno_list ())) |
13094 | 1304 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1305 %!error errno_list ("foo") |
13094 | 1306 */ |
1307 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1308 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
|
1309 const char *warnfor) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1310 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1311 if (nr < 0 || nc < 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 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
|
1314 "%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
|
1315 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1316 nr = (nr < 0) ? 0 : nr; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1317 nc = (nc < 0) ? 0 : 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 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1320 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1321 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
|
1322 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1323 bool neg = false; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1324 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1325 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
|
1326 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1327 if (dim(i) < 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1328 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1329 dim(i) = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1330 neg = true; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1331 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1332 } |
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 if (neg) |
5781 | 1335 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
|
1336 "%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
|
1337 } |
4481 | 1338 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1339 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
|
1340 dim_vector& dim) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1341 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1342 // 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
|
1343 // 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
|
1344 // 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
|
1345 if (! a.dims ().isvector ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1346 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
4481 | 1347 |
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
|
1348 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
|
1349 const octave_idx_type n = v.numel (); |
4481 | 1350 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1351 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
|
1352 if (n == 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1353 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1354 dim(0) = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1355 dim(1) = 0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1356 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1357 else if (n == 1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1358 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1359 dim(0) = v(0); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1360 dim(1) = v(0); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1361 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1362 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1363 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
|
1364 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
|
1365 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1366 check_dimensions (dim, warn_for); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1367 } |
21405
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1368 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1369 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
|
1370 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
|
1371 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1372 if (a.is_scalar_type ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1373 { |
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
|
1374 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
|
1375 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1376 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1377 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1378 nr = a.rows (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1379 nc = a.columns (); |
4481 | 1380 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1381 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
|
1382 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
4481 | 1383 |
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
|
1384 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
|
1385 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
|
1386 nc = v(1); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1387 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1388 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1389 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
|
1390 } |
3354 | 1391 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1392 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
|
1393 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
|
1394 octave_idx_type& nc) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1395 { |
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
|
1396 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
|
1397 nc = (b.isempty () ? 0 : b.idx_type_value (true)); |
3354 | 1398 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1399 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
|
1400 } |
3354 | 1401 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1402 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
|
1403 const octave_value_list& idx_arg) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1404 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1405 octave_idx_type retval; |
3354 | 1406 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1407 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
|
1408 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1409 if (len == 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1410 retval = dims.numel (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1411 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1412 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1413 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
|
1414 retval = 1; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1415 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
|
1416 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1417 octave_value idxi = idx_arg(i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1418 if (idxi.is_magic_colon ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1419 retval *= dv(i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1420 else if (idxi.isnumeric ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1421 retval *= idxi.numel (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1422 else |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1423 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1424 try |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1425 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1426 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
|
1427 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1428 retval *= jdx.length (dv(i)); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1429 } |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29140
diff
changeset
|
1430 catch (const index_exception& ie) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1431 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29140
diff
changeset
|
1432 error ("dims_to_numel: invalid index %s", ie.what ()); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1433 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1434 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1435 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1436 } |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
1437 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1438 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1439 } |
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 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
|
1442 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1443 Matrix m (nr, nc, 0.0); |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1444 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1445 if (nr > 0 && nc > 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1446 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1447 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
|
1448 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1449 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
|
1450 m (i, i) = 1.0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1451 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1452 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1453 return m; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1454 } |
4478 | 1455 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1456 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
|
1457 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1458 FloatMatrix m (nr, nc, 0.0); |
4478 | 1459 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1460 if (nr > 0 && nc > 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1461 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1462 octave_idx_type n = std::min (nr, nc); |
4478 | 1463 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1464 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
|
1465 m (i, i) = 1.0; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1466 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1467 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1468 return m; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1469 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1470 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1471 std::size_t format (std::ostream& os, const char *fmt, ...) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1472 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1473 std::size_t retval; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1474 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1475 va_list args; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1476 va_start (args, fmt); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1477 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1478 retval = vformat (os, fmt, args); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1479 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1480 va_end (args); |
3620 | 1481 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1482 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1483 } |
3620 | 1484 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1485 std::size_t vformat (std::ostream& os, const char *fmt, va_list args) |
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 std::string s = vasprintf (fmt, args); |
3620 | 1488 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1489 os << s; |
3620 | 1490 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1491 return s.length (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1492 } |
3620 | 1493 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1494 std::size_t format (std::ostream& os, const std::string& enc, const char *fmt, ...) |
27279
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1495 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1496 std::size_t retval; |
27279
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1497 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1498 va_list args; |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1499 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
|
1500 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1501 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
|
1502 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1503 va_end (args); |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1504 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1505 return retval; |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1506 } |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1507 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
1508 std::size_t vformat (std::ostream& os, const std::string& enc, const char *fmt, |
27279
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1509 va_list args) |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1510 { |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1511 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
|
1512 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1513 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
|
1514 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
|
1515 else |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1516 os << s; |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1517 |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1518 return s.length (); |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1519 } |
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27277
diff
changeset
|
1520 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1521 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
|
1522 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1523 std::string retval; |
3620 | 1524 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1525 char *result; |
4135 | 1526 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1527 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
|
1528 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1529 if (status >= 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1530 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1531 retval = result; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1532 ::free (result); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1533 } |
4302 | 1534 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1535 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1536 } |
3620 | 1537 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1538 std::string asprintf (const char *fmt, ...) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1539 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1540 std::string retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1541 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1542 va_list args; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1543 va_start (args, fmt); |
3620 | 1544 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1545 retval = vasprintf (fmt, args); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1546 |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1547 va_end (args); |
4302 | 1548 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1549 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1550 } |
4302 | 1551 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1552 // 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
|
1553 // 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
|
1554 // 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
|
1555 // breaking this up into multiple shorter intervals? |
4302 | 1556 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1557 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
|
1558 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1559 if (seconds <= 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1560 return; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1561 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1562 // 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
|
1563 // is asleep |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1564 |
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1565 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
|
1566 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1567 if (do_graphics_events) |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1568 gh_mgr.unlock (); |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1569 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1570 if (math::isinf (seconds)) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1571 { |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1572 // 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
|
1573 int c = -1; |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1574 flush_stdout (); |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1575 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1576 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
|
1577 |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1578 while (c < 0) |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1579 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1580 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
|
1581 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1582 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
|
1583 |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1584 if (do_graphics_events) |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1585 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
|
1586 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1587 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
|
1588 } |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1589 } |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1590 else |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1591 { |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1592 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
|
1593 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
|
1594 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
|
1595 |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1596 // 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
|
1597 // 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
|
1598 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
|
1599 |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1600 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
|
1601 { |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1602 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
|
1603 |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1604 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
|
1605 { |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1606 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
|
1607 |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1608 now.stamp (); |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1609 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
|
1610 |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1611 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
|
1612 break; |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1613 } |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1614 |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1615 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
|
1616 |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1617 now.stamp (); |
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1618 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
|
1619 } |
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1620 |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1621 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
|
1622 { |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1623 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
|
1624 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
|
1625 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1626 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1627 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1628 |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
1629 DEFMETHOD (isindex, interp, args, , |
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
1630 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
|
1631 @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
|
1632 @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
|
1633 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
|
1634 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1635 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
|
1636 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
|
1637 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1638 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
|
1639 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
|
1640 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
|
1641 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1642 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
|
1643 checks for valid indices are made. Unless a string contains the NULL |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
29094
diff
changeset
|
1644 character @nospell{"@backslashchar{}0"}, it will always be a valid index. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1645 @end deftypefn */) |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1646 { |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1647 int nargin = args.length (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1648 |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1649 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1650 print_usage (); |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1651 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1652 octave_idx_type n = 0; |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1653 if (nargin == 2) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1654 n = args(1).idx_type_value (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1655 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1656 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1657 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1658 try |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1659 { |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1660 octave::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
|
1661 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1662 if (nargin == 2) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1663 retval = idx.extent (n) <= n; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1664 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1665 retval = true; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1666 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1667 catch (const octave::execution_exception&) |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1668 { |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
1669 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
|
1670 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1671 retval = false; |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1672 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1673 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1674 return retval; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1675 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1676 |
13094 | 1677 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1678 %!assert (isindex ([1, 2, 3])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1679 %!assert (isindex (1:3)) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1680 %!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
|
1681 %!assert (isindex ([1, 2, -3]), false) |
13094 | 1682 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1683 %!error isindex () |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1684 %!error isindex (1:3, 2, 3) |
13094 | 1685 */ |
1686 | |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1687 octave_value_list |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1688 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
|
1689 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
|
1690 int nargout) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1691 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1692 octave_value_list new_args = args; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1693 octave_value_list retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1694 int nargin = args.length (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1695 OCTAVE_LOCAL_BUFFER (bool, iscell, nargin); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1696 OCTAVE_LOCAL_BUFFER (Cell, cells, nargin); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1697 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
|
1698 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1699 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
|
1700 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1701 octave_idx_type numel = 1; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1702 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
|
1703 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1704 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
|
1705 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1706 octave_value arg = new_args(i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1707 iscell[i] = arg.iscell (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1708 if (iscell[i]) |
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 cells[i] = arg.cell_value (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1711 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
|
1712 if (n == 1) |
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 iscell[i] = false; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1715 new_args(i) = ccells[i](0); |
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 else if (numel == 1) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1718 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1719 numel = n; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1720 dims = ccells[i].dims (); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1721 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1722 else if (dims != ccells[i].dims ()) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1723 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
|
1724 } |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1725 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1726 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1727 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
|
1728 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
|
1729 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1730 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
|
1731 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1732 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
|
1733 if (iscell[i]) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1734 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
|
1735 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1736 octave_quit (); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1737 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1738 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
|
1739 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1740 if (tmp.length () < nargout) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1741 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
|
1742 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1743 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
|
1744 rcells[i](j) = tmp(i); |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1745 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1746 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1747 retval.resize (nargout); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1748 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1749 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
|
1750 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
|
1751 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1752 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1753 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1754 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1755 octave_value |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1756 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
|
1757 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
|
1758 { |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1759 octave_value retval; |
20973 | 1760 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27094
diff
changeset
|
1761 const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1); |
20973 | 1762 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1763 if (tmp.length () > 0) |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1764 retval = tmp(0); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1765 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1766 return retval; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1767 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1768 |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1769 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
|
1770 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
|
1771 @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
|
1772 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
|
1773 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1774 @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
|
1775 @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
|
1776 @end deftypefn */) |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1777 { |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1778 if (args.length () != 0) |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1779 print_usage (); |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1780 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1781 return ovl (false); |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1782 } |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1783 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1784 /* |
19152
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1785 %!assert (isstudent (), false) |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1786 |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1787 %!error isstudent (1) |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1788 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1789 |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1790 OCTAVE_NAMESPACE_END |