Mercurial > octave
annotate libinterp/corefcn/utils.cc @ 31607:aac27ad79be6 stable
maint: Re-indent code after switch to using namespace macros.
* build-env.h, build-env.in.cc, Cell.h, __betainc__.cc, __eigs__.cc,
__ftp__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __magick_read__.cc,
__pchip_deriv__.cc, amd.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.h, call-stack.cc,
call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, dasrt.cc, data.cc,
debug.cc, defaults.cc, defaults.h, det.cc, display.cc, display.h, dlmread.cc,
dynamic-ld.cc, dynamic-ld.h, ellipj.cc, environment.cc, environment.h,
error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h,
event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc,
file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h,
gcd.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h,
graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, gsvd.cc, gtk-manager.cc,
gtk-manager.h, help.cc, help.h, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-hdf5.cc, ls-mat4.cc, ls-mat5.cc, lsode.cc, lu.cc, mappers.cc,
matrix_type.cc, max.cc, mex.cc, mexproto.h, mxarray.h, mxtypes.in.h,
oct-errno.in.cc, oct-hdf5-types.cc, oct-hist.cc, oct-hist.h, oct-map.cc,
oct-map.h, oct-opengl.h, oct-prcstrm.h, oct-process.cc, oct-process.h,
oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.h,
octave-default-image.h, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc,
pow2.cc, pr-output.cc, psi.cc, qr.cc, quadcc.cc, rand.cc, regexp.cc,
settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xpow.cc,
sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfns.cc, svd.cc,
syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h,
symtab.cc, symtab.h, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h,
text-renderer.cc, text-renderer.h, time.cc, toplev.cc, typecast.cc,
url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h,
variables.cc, variables.h, xdiv.cc, __delaunayn__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audioread.cc, convhulln.cc,
gzip.cc, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc,
ov-base-mat.h, ov-base-scalar.cc, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-bool-mat.h, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.h, ov-cell.cc,
ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h,
ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc,
ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-float.cc,
ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc,
ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-intx.h, ov-java.cc, ov-lazy-idx.cc,
ov-legacy-range.cc, ov-magic-int.cc, ov-mex-fcn.cc, ov-mex-fcn.h,
ov-null-mat.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc,
ov-re-mat.h, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc,
ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, ovl.h,
octave.cc, octave.h, op-b-sbm.cc, op-bm-sbm.cc, op-cs-scm.cc, op-fm-fcm.cc,
op-fs-fcm.cc, op-s-scm.cc, op-scm-cs.cc, op-scm-s.cc, op-sm-cs.cc, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, oct-lvalue.cc, oct-lvalue.h,
parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h,
pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h,
pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc,
pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc,
pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h,
pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h,
pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h,
pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h,
pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h,
pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h,
pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h,
pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h,
idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h,
aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h,
gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc,
lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h,
oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc,
oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h,
randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h,
sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc,
sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h,
file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h,
lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h,
oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc,
oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h,
action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h,
cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h,
lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h,
lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc,
oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc,
oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc,
oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc,
pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc,
url-transfer.h:
Re-indent code after switch to using namespace macros.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 18:02:15 -0800 |
parents | e88a07dec498 |
children | 597f3ee61a48 |
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 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30329
diff
changeset
|
3 // Copyright (C) 1993-2022 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" |
30587
5d379d2ad903
strcase-wrappers: Add wrappers for strcasecmp and strncasecmp.
Markus Mützel <markus.muetzel@gmx.de>
parents:
30565
diff
changeset
|
51 #include "strcase-wrappers.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
52 #include "vasprintf-wrapper.h" |
1651 | 53 |
4216 | 54 #include "Cell.h" |
1352 | 55 #include "defun.h" |
56 #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
|
57 #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
|
58 #include "graphics.h" |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
59 #include "interpreter-private.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
60 #include "interpreter.h" |
10502
f13bf183a003
isvarname: keywords are not valid variable names
Judd Storrs <jstorrs@gmail.com>
parents:
10315
diff
changeset
|
61 #include "lex.h" |
5832 | 62 #include "load-path.h" |
5465 | 63 #include "oct-errno.h" |
1742 | 64 #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
|
65 #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
|
66 #include "ov-range.h" |
1352 | 67 #include "pager.h" |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10502
diff
changeset
|
68 #include "parse.h" |
1690 | 69 #include "sysdep.h" |
1 | 70 #include "unwind-prot.h" |
1352 | 71 #include "utils.h" |
72 #include "variables.h" | |
1 | 73 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31278
diff
changeset
|
74 OCTAVE_BEGIN_NAMESPACE(octave) |
29960
939bef0b66e0
merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
75 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
76 // Return TRUE if S is a valid identifier. |
4143 | 77 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
78 bool valid_identifier (const char *s) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
79 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
80 if (! s || ! (isalpha (*s) || *s == '_')) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
81 return false; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
82 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
83 while (*++s != '\0') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
84 if (! (isalnum (*s) || *s == '_')) |
4143 | 85 return false; |
86 | |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
87 return true; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
88 } |
4143 | 89 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
90 bool valid_identifier (const std::string& s) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
91 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
92 return valid_identifier (s.c_str ()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
93 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
94 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8715
diff
changeset
|
95 DEFUN (isvarname, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
96 doc: /* -*- texinfo -*- |
30559
841a10208c38
doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents:
30346
diff
changeset
|
97 @deftypefn {} {@var{tf} =} isvarname (@var{name}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
98 Return true if @var{name} is a valid variable name. |
26204
82b9b970ff19
doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents:
26203
diff
changeset
|
99 |
82b9b970ff19
doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents:
26203
diff
changeset
|
100 A valid variable name is composed of letters, digits, and underscores ("_"), |
82b9b970ff19
doc: Explain what a valid variable name is in isvarname documentation.
Rik <rik@octave.org>
parents:
26203
diff
changeset
|
101 and the first character must not be a digit. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
102 @seealso{iskeyword, exist, who} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
103 @end deftypefn */) |
4264 | 104 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
105 if (args.length () != 1) |
5823 | 106 print_usage (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
107 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
108 octave_value retval = false; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
109 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
110 if (args(0).is_string ()) |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
111 { |
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
112 std::string varname = args(0).string_value (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
113 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
114 retval = (valid_identifier (varname) |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
115 && ! iskeyword (varname)); |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
116 } |
4264 | 117 |
118 return retval; | |
119 } | |
120 | |
13094 | 121 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
122 %!assert (isvarname ("foo"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
123 %!assert (isvarname ("_foo"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
124 %!assert (isvarname ("_1"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
125 %!assert (isvarname ("1foo"), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
126 %!assert (isvarname (""), false) |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
127 %!assert (isvarname (12), false) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
128 %!assert (isvarname ("foo+bar"), false) |
13094 | 129 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
130 %!error isvarname () |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21526
diff
changeset
|
131 %!error isvarname ("foo", "bar") |
13094 | 132 */ |
133 | |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
134 bool |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
135 make_valid_name (std::string& str, const make_valid_name_options& options) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
136 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
137 // If `isvarname (str)`, no modifications necessary. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
138 if (valid_identifier (str) && ! iskeyword (str)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
139 return false; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
140 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
141 // Change whitespace followed by lowercase letter to uppercase, except |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
142 // for the first |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
143 bool previous = false; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
144 bool any_non_space = false; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
145 for (char& c : str) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
146 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
147 c = ((any_non_space && previous && std::isalpha (c)) ? std::toupper (c) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
148 : c); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
149 previous = std::isspace (c); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
150 any_non_space |= (! previous); // once true, always true |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
151 } |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
152 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
153 // Remove any whitespace. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
154 str.erase (std::remove_if (str.begin(), str.end(), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
155 [] (unsigned char x) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
156 { return std::isspace(x); }), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
157 str.end()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
158 if (str.empty ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
159 str = options.get_prefix (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
160 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
161 // Add prefix and capitalize first character, if `str` is a reserved |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
162 // keyword. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
163 if (iskeyword (str)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
164 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
165 str[0] = std::toupper (str[0]); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
166 str = options.get_prefix () + str; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
167 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
168 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
169 // Add prefix if first character is not a letter or underscore. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
170 if (! std::isalpha (str[0]) && str[0] != '_') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
171 str = options.get_prefix () + str; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
172 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
173 // Replace non alphanumerics or underscores |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
174 if (options.get_replacement_style () == "underscore") |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
175 for (char& c : str) |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
176 c = (std::isalnum (c) ? c : '_'); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
177 else if (options.get_replacement_style () == "delete") |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
178 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
|
179 [] (unsigned char x) |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
180 { return ! std::isalnum (x) && x != '_'; }), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
181 str.end()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
182 else if (options.get_replacement_style () == "hex") |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
183 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
184 const std::string permitted_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
185 "abcdefghijklmnopqrstuvwxyz" |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
186 "_0123456789"; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
187 // Get the first non-permitted char. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
188 std::size_t pos = str.find_first_not_of (permitted_chars); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
189 // Buffer for hex string "0xFF" (+1 for null terminator). |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
190 char hex_str[5]; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
191 // Repeat until end of string. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
192 while (pos != std::string::npos) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
193 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
194 // Replace non-permitted char by it's hex value. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
195 std::snprintf (hex_str, sizeof (hex_str), "0x%02X", str[pos]); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
196 str.replace (pos, 1, hex_str); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
197 // Get the next occurrence from the last position. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
198 // (-1 for null terminator) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
199 pos = str.find_first_not_of (permitted_chars, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
200 pos + sizeof (hex_str) - 1); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
201 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
202 } |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
203 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
204 return true; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
205 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
206 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
207 make_valid_name_options::make_valid_name_options |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
208 (const octave_value_list& args) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
209 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
210 auto nargs = args.length (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
211 if (nargs == 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
212 return; |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
213 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
214 // nargs = 2, 4, 6, ... permitted |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
215 if (nargs % 2) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
216 error ("makeValidName: property/value options must occur in pairs"); |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
217 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
218 auto str_to_lower = [] (std::string& s) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
219 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
220 std::transform (s.begin(), s.end(), s.begin(), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
221 [] (unsigned char c) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
222 { return std::tolower(c); }); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
223 }; |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
224 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
225 for (auto i = 0; i < nargs; i = i + 2) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
226 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
227 std::string parameter = args(i).xstring_value ("makeValidName: " |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
228 "option argument must be a string"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
229 str_to_lower (parameter); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
230 if (parameter == "replacementstyle") |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
231 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
232 m_replacement_style = args(i + 1).xstring_value ("makeValidName: " |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
233 "'ReplacementStyle' value must be a string"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
234 str_to_lower (m_replacement_style); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
235 if ((m_replacement_style != "underscore") |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
236 && (m_replacement_style != "delete") |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
237 && (m_replacement_style != "hex")) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
238 error ("makeValidName: invalid 'ReplacementStyle' value '%s'", |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
239 m_replacement_style.c_str ()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
240 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
241 else if (parameter == "prefix") |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
242 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
243 m_prefix = args(i + 1).xstring_value ("makeValidName: " |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
244 "'Prefix' value must be a string"); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
245 if (! valid_identifier (m_prefix) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
246 || iskeyword (m_prefix)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
247 error ("makeValidName: invalid 'Prefix' value '%s'", |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
248 m_prefix.c_str ()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
249 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
250 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
251 error ("makeValidName: unknown property '%s'", parameter.c_str ()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
252 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
253 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
254 |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
255 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
|
256 doc: /* -*- texinfo -*- |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
257 @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
|
258 @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
|
259 @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
|
260 @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
|
261 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
|
262 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
263 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
|
264 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
265 @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
|
266 @end deftypefn */) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
267 { |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
268 auto nargin = args.length (); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
269 if (nargin < 1) |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
270 print_usage (); |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
271 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
272 make_valid_name_options options (args.slice (1, nargin - 1)); |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
273 |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
274 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
|
275 { |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
276 std::string varname = args(0).string_value (); |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
277 bool is_modified = make_valid_name (varname, options); |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
278 return ovl (varname, is_modified); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
279 } |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
280 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
|
281 { |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
282 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
|
283 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
|
284 for (auto i = 0; i < varnames.numel (); i++) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
285 is_modified(i) = make_valid_name (varnames(i), options); |
29094
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
286 return ovl (varnames, is_modified); |
d09dde091073
utils.cc: Correct indentation in cset b924b916dc91.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29091
diff
changeset
|
287 } |
29091
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
288 else |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
289 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
|
290 } |
b924b916dc91
matlab.lang.makeValidName: reimplement in C++ (patch #9998)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
28888
diff
changeset
|
291 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
292 // Return TRUE if F and G are both names for the same file. |
6323 | 293 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
294 bool same_file (const std::string& f, const std::string& g) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
295 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
296 return same_file_internal (f, g); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
297 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
298 |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
299 DEFUN (is_same_file, args, , |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
300 doc: /* -*- texinfo -*- |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
301 @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
|
302 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
|
303 |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 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
|
308 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
317 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
|
318 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
|
319 return true. |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
320 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
321 @seealso{canonicalize_file_name, strcmp} |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
322 @end deftypefn */) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
323 { |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
324 if (args.length () != 2) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
325 print_usage (); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
326 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
327 octave_value retval; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
328 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
329 bool s1_string = args(0).is_string (); |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
330 bool s1_cellstr = args(0).iscellstr (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
331 bool s2_string = args(1).is_string (); |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
332 bool s2_cellstr = args(1).iscellstr (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
333 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
334 if (s1_string && s2_string) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
335 { |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
336 std::string file1 = args(0).string_value (); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
337 std::string file2 = args(1).string_value (); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
338 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
339 retval = same_file (file1, file2); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
340 } |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
341 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
|
342 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
343 octave_value str_arg, cellstr_arg; |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
344 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
345 if (s1_string) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
346 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
347 str_arg = args(0); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
348 cellstr_arg = args(1); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
349 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
350 else |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
351 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
352 str_arg = args(1); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
353 cellstr_arg = args(0); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
354 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
355 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
356 const Array<std::string> cellstr = cellstr_arg.cellstr_value (); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
357 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
|
358 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
359 boolNDArray output (cellstr.dims (), false); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
360 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
361 for (octave_idx_type idx = 0; idx < cellstr.numel (); idx++) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
362 output(idx) = same_file (str, cellstr(idx)); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
363 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
364 retval = output; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
365 } |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
366 else if (s1_cellstr && s2_cellstr) |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
367 { |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
368 const Array<std::string> cellstr1 = args(0).cellstr_value (); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
369 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
|
370 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
371 const dim_vector size1 = cellstr1.dims (); |
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
372 const dim_vector size2 = cellstr2.dims (); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
373 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
374 if (size1 != size2) |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
375 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
|
376 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
377 boolNDArray output (size1, false); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
378 |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
379 for (octave_idx_type idx = 0; idx < cellstr1.numel (); idx++) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
380 output(idx) = same_file (cellstr1(idx), cellstr2(idx)); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
381 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
382 retval = output; |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
383 } |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
384 else |
27571
24618a510749
Polish implementation of is_same_file().
Rik <rik@octave.org>
parents:
27569
diff
changeset
|
385 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
|
386 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
387 return retval; |
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 |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
390 /* |
27580
e7df1df55f0e
Fix BIST test for is_same_file on Windows platforms.
Rik <rik@octave.org>
parents:
27571
diff
changeset
|
391 %!testif ; ! ispc () |
e7df1df55f0e
Fix BIST test for is_same_file on Windows platforms.
Rik <rik@octave.org>
parents:
27571
diff
changeset
|
392 %! assert (is_same_file ("~", tilde_expand ("~"))); |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27474
diff
changeset
|
393 %!testif ; ispc () |
30269
313da8fd4657
test: Use directory in "is_same_file" test that exists in all mingw environments.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29961
diff
changeset
|
394 %! assert (is_same_file (tolower (tempdir ()), toupper (tempdir ())), true); |
27569
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 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
408 int almost_match (const std::string& std, const std::string& s, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
409 int min_match_len, int case_sens) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
410 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
411 int stdlen = std.length (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
412 int slen = s.length (); |
1 | 413 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
414 return (slen <= stdlen |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
415 && slen >= min_match_len |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
416 && (case_sens |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
417 ? (strncmp (std.c_str (), s.c_str (), slen) == 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
418 : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0))); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
419 } |
287 | 420 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
421 // Ugh. |
581 | 422 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
423 int keyword_almost_match (const char *const *std, int *min_len, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
424 const std::string& s, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
425 int min_toks_to_match, int max_toks) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
426 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
427 int status = 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
428 int tok_count = 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
429 int toks_matched = 0; |
287 | 430 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
431 if (s.empty () || max_toks < 1) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
432 return status; |
287 | 433 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
434 char *kw = strsave (s.c_str ()); |
287 | 435 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
436 char *t = kw; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
437 while (*t != '\0') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
438 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
439 if (*t == '\t') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
440 *t = ' '; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
441 t++; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
442 } |
287 | 443 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
444 char *beg = kw; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
445 while (*beg == ' ') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
446 beg++; |
287 | 447 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
448 if (*beg == '\0') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
449 return status; |
287 | 450 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
451 const char **to_match = new const char *[max_toks + 1]; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
452 const char *const *s1 = std; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
453 const char **s2 = to_match; |
287 | 454 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
455 if (! s1 || ! s2) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
456 goto done; |
287 | 457 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
458 s2[tok_count] = beg; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
459 char *end; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
460 while ((end = strchr (beg, ' ')) != nullptr) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
461 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
462 *end = '\0'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
463 beg = end + 1; |
287 | 464 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
465 while (*beg == ' ') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
466 beg++; |
287 | 467 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
468 if (*beg == '\0') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
469 break; |
287 | 470 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
471 tok_count++; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
472 if (tok_count >= max_toks) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
473 goto done; |
287 | 474 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
475 s2[tok_count] = beg; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
476 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
477 s2[tok_count+1] = nullptr; |
287 | 478 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
479 s2 = to_match; |
287 | 480 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
481 for (;;) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
482 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
483 if (! almost_match (*s1, *s2, min_len[toks_matched], 0)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
484 goto done; |
287 | 485 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
486 toks_matched++; |
287 | 487 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
488 s1++; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
489 s2++; |
287 | 490 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
491 if (! *s2) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
492 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
493 status = (toks_matched >= min_toks_to_match); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
494 goto done; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
495 } |
287 | 496 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
497 if (! *s1) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
498 goto done; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
499 } |
287 | 500 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
501 done: |
287 | 502 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
503 delete [] kw; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
504 delete [] to_match; |
287 | 505 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
506 return status; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
507 } |
1 | 508 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
509 // See if the given file is in the path. |
581 | 510 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
511 std::string search_path_for_file (const std::string& path, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
512 const string_vector& names) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
513 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
514 directory_path p (path); |
686 | 515 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
516 return sys::env::make_absolute (p.find_first_of (names.std_list ())); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
517 } |
686 | 518 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
519 // Find all locations of the given file in the path. |
4216 | 520 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
521 string_vector search_path_for_all_files (const std::string& path, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
522 const string_vector& names) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
523 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
524 directory_path p (path); |
4216 | 525 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
526 string_vector sv = p.find_all_first_of (names.std_list ()); |
4216 | 527 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
528 octave_idx_type len = sv.numel (); |
4216 | 529 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
530 for (octave_idx_type i = 0; i < len; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
531 sv[i] = sys::env::make_absolute (sv[i]); |
4216 | 532 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
533 return sv; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
534 } |
4216 | 535 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
536 static string_vector make_absolute (const string_vector& sv) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
537 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
538 octave_idx_type len = sv.numel (); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
539 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
540 string_vector retval (len); |
6379 | 541 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
542 for (octave_idx_type i = 0; i < len; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
543 retval[i] = sys::env::make_absolute (sv[i]); |
4216 | 544 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
545 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
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 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
576 string_vector names = args( |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
577 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
|
578 |
20973 | 579 if (names.empty ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
580 error ("file_in_loadpath: FILE argument must not be empty"); |
4243 | 581 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
582 load_path& lp = interp.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
583 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
584 if (nargin == 1) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
585 return ovl (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
|
586 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
587 { |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
588 std::string opt = args( |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
589 1).xstring_value ("file_in_loadpath: optional second argument must be a string"); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
590 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
591 if (opt != "all") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
592 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
|
593 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
594 return ovl (Cell (make_absolute (lp.find_all_first_of (names)))); |
4216 | 595 } |
3195 | 596 } |
597 | |
13094 | 598 /* |
599 %!test | |
600 %! f = file_in_loadpath ("plot.m"); | |
601 %! assert (ischar (f)); | |
602 %! assert (! isempty (f)); | |
603 | |
604 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
605 %! f = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$"); |
13094 | 606 %! assert (f, ""); |
607 | |
608 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
609 %! lst = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$", "all"); |
13094 | 610 %! assert (lst, {}); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
611 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
612 %!error file_in_loadpath () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
613 %!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
|
614 %!error file_in_loadpath ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
615 %!error file_in_loadpath ("plot.m", "bar") |
13094 | 616 */ |
617 | |
1957 | 618 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
|
619 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
620 @deftypefn {} {@var{fname} =} file_in_path (@var{path}, @var{file}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
621 @deftypefnx {} {@var{fname} =} file_in_path (@var{path}, @var{file}, "all") |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
622 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
|
623 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
624 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
|
625 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
|
626 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
|
627 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
628 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
629 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
630 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
|
631 @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
|
632 @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
|
633 @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
|
634 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
635 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
|
636 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
|
637 |
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 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
|
639 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
|
640 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
|
641 @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
|
642 @end deftypefn */) |
686 | 643 { |
4243 | 644 int nargin = args.length (); |
1755 | 645 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
646 if (nargin < 2 || nargin > 3) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
647 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
648 |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
649 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
|
650 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20973
diff
changeset
|
651 string_vector names = args(1).xstring_vector_value ("file_in_path: FILE argument must be a string"); |
4243 | 652 |
20973 | 653 if (names.empty ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
654 error ("file_in_path: FILE argument must not be empty"); |
4243 | 655 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
656 if (nargin == 2) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
657 return ovl (search_path_for_file (path, names)); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
658 else |
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 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
|
661 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
662 if (opt != "all") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
663 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
|
664 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
665 return ovl (Cell (make_absolute (search_path_for_all_files (path, names)))); |
686 | 666 } |
667 } | |
668 | |
13094 | 669 /* |
670 %!test | |
671 %! f = file_in_path (path (), "plot.m"); | |
672 %! assert (ischar (f)); | |
673 %! assert (! isempty (f)); | |
674 | |
675 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
676 %! f = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$"); |
13094 | 677 %! assert (f, ""); |
678 | |
679 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
680 %! lst = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$", "all"); |
13094 | 681 %! assert (lst, {}); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
682 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
683 %!error file_in_path () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
684 %!error file_in_path ("foo") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
685 %!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
|
686 %!error file_in_path ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
687 %!error file_in_path (path (), []) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
688 %!error file_in_path (path (), "plot.m", "bar") |
13094 | 689 */ |
690 | |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
691 std::string file_in_path (const std::string& name, const std::string& suffix) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
692 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
693 std::string nm = name; |
526 | 694 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
695 if (! suffix.empty ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
696 nm.append (suffix); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
697 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
698 load_path& lp = __get_load_path__ (); |
526 | 699 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
700 return sys::env::make_absolute (lp.find_file (nm)); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
701 } |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
702 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
703 std::string find_data_file_in_load_path (const std::string& fcn, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
704 const std::string& file, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
705 bool require_regular_file) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
706 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
707 std::string fname = file; |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
708 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
709 if (! (sys::env::absolute_pathname (fname) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
710 || sys::env::rooted_relative_pathname (fname))) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
711 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
712 // Load path will also search "." first, but we don't want to |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
713 // issue a warning if the file is found in the current directory, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
714 // so do an explicit check for that. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
715 sys::file_stat fs (fname); |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
716 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
717 bool local_file_ok |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
718 = fs.exists () && (fs.is_reg () || ! require_regular_file); |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
719 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
720 if (! local_file_ok) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
721 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
722 load_path& lp = __get_load_path__ (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
723 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
724 // Not directly found; search load path. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
725 std::string tmp = sys::env::make_absolute (lp.find_file (fname)); |
581 | 726 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
727 if (! tmp.empty ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
728 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
729 warn_data_file_in_path (fcn, tmp); |
908 | 730 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
731 fname = tmp; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
732 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
733 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
734 } |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
735 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
736 return fname; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
737 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
738 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
739 // See if there is an function file in the path. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
740 // If so, return the full path to the file. |
5832 | 741 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
742 std::string fcn_file_in_path (const std::string& name) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
743 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
744 std::string retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
745 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
746 int len = name.length (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
747 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
748 if (len > 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
749 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
750 if (sys::env::absolute_pathname (name)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
751 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
752 sys::file_stat fs (name); |
1755 | 753 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
754 if (fs.exists () && ! fs.is_dir ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
755 retval = name; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
756 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
757 else if (len > 2 && name[len - 2] == '.' && name[len - 1] == 'm') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
758 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
759 load_path& lp = __get_load_path__ (); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
760 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
761 retval = lp.find_fcn_file (name.substr (0, len-2)); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
762 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
763 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
764 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
765 std::string fname = name; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
766 std::size_t pos = name.find_first_of ('>'); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
767 if (pos != std::string::npos) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
768 fname = name.substr (0, pos); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
769 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
770 load_path& lp = __get_load_path__ (); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
771 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
772 retval = lp.find_fcn_file (fname); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
773 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
774 } |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
775 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
776 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
777 } |
3103 | 778 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
779 // See if there is a directory called "name" in the path and if it |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
780 // contains a Contents.m file. If so, return the full path to this file. |
3103 | 781 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
782 std::string contents_file_in_path (const std::string& dir) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
783 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
784 std::string retval; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
785 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
786 if (! dir.empty ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
787 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
788 load_path& lp = __get_load_path__ (); |
3103 | 789 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
790 std::string tcontents |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
791 = sys::file_ops::concat (lp.find_dir (dir), "Contents.m"); |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
792 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
793 sys::file_stat fs (tcontents); |
3103 | 794 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
795 if (fs.exists ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
796 retval = sys::env::make_absolute (tcontents); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
797 } |
3103 | 798 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
799 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
800 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
801 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
802 // Replace backslash escapes in a string with the real values. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
803 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
804 std::string do_string_escapes (const std::string& s) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
805 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
806 std::string retval; |
3103 | 807 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
808 std::size_t i = 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
809 std::size_t j = 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
810 std::size_t len = s.length (); |
3103 | 811 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
812 retval.resize (len); |
3103 | 813 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
814 while (j < len) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
815 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
816 if (s[j] == '\\' && j+1 < len) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
817 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
818 switch (s[++j]) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
819 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
820 case 'a': // alarm |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
821 retval[i] = '\a'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
822 break; |
3103 | 823 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
824 case 'b': // backspace |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
825 retval[i] = '\b'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
826 break; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
827 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
828 case 'f': // formfeed |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
829 retval[i] = '\f'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
830 break; |
3103 | 831 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
832 case 'n': // newline |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
833 retval[i] = '\n'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
834 break; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
835 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
836 case 'r': // carriage return |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
837 retval[i] = '\r'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
838 break; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
839 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
840 case 't': // horizontal tab |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
841 retval[i] = '\t'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
842 break; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
843 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
844 case 'v': // vertical tab |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
845 retval[i] = '\v'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
846 break; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
847 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
848 case '\\': // backslash |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
849 retval[i] = '\\'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
850 break; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
851 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
852 case '\'': // quote |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
853 retval[i] = '\''; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
854 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
|
855 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
856 case '"': // double quote |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
857 retval[i] = '"'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
858 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
|
859 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
860 case '0': |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
861 case '1': |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
862 case '2': |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
863 case '3': |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
864 case '4': |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
865 case '5': |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
866 case '6': |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
867 case '7': // octal input |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
868 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
869 std::size_t k; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
870 int tmpi = s[j] - '0'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
871 for (k = j+1; k < std::min (j+3, len); k++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
872 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
873 int digit = s[k] - '0'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
874 if (digit < 0 || digit > 7) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
875 break; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
876 tmpi <<= 3; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
877 tmpi += digit; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
878 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
879 retval[i] = tmpi; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
880 j = k - 1; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
881 break; |
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
882 } |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
883 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
884 case 'x': // hex input |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
885 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
886 std::size_t k; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
887 int tmpi = 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
888 for (k = j+1; k < std::min (j+3, len); k++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
889 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
890 if (! isxdigit (s[k])) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
891 break; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
892 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
893 tmpi <<= 4; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
894 int digit = s[k]; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
895 if (digit >= 'a') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
896 tmpi += digit - 'a' + 10; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
897 else if (digit >= 'A') |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
898 tmpi += digit - 'A' + 10; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
899 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
900 tmpi += digit - '0'; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
901 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
902 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
903 if (k == j+1) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
904 warning (R"(malformed hex escape sequence '\x' -- converting to '\0')"); |
3103 | 905 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
906 retval[i] = tmpi; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
907 j = k - 1; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
908 break; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
909 } |
3103 | 910 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
911 default: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
912 warning (R"(unrecognized escape sequence '\%c' -- converting to '%c')", s[j], s[j]); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
913 retval[i] = s[j]; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
914 break; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
915 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
916 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
917 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
918 retval[i] = s[j]; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
919 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
920 i++; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
921 j++; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
922 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
923 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
924 retval.resize (i); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
925 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
926 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
927 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
928 |
3103 | 929 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
|
930 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
931 @deftypefn {} {@var{newstr} =} do_string_escapes (@var{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
|
932 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
|
933 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
934 Escape sequences begin with a leading backslash |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
29094
diff
changeset
|
935 (@qcode{'@backslashchar{}'}) followed by 1--3 characters |
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
29094
diff
changeset
|
936 (.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
|
937 @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
|
938 @end deftypefn */) |
3103 | 939 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
940 if (args.length () != 1) |
5823 | 941 print_usage (); |
3103 | 942 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
943 std::string str = args( |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
944 0).xstring_value ("do_string_escapes: STRING argument must be of type string"); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
945 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
946 return ovl (do_string_escapes (str)); |
3103 | 947 } |
948 | |
13094 | 949 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
950 %!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
|
951 %!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
|
952 %!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
|
953 %!assert ("foo\nbar", ["foo", char(10), "bar"]) |
13094 | 954 |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
955 %!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
|
956 %!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
|
957 %!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
|
958 %! 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
|
959 %!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
|
960 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
961 %!assert (do_string_escapes ('\\'), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
962 %!assert (do_string_escapes ("\\\\"), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
963 %!assert (do_string_escapes ("\\\\"), char (92)) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
964 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
965 %!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
|
966 %!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
|
967 %!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
|
968 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"") |
13094 | 969 |
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
|
970 %!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
|
971 %!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
|
972 %!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
|
973 %!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
|
974 |
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 %!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
|
976 %!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
|
977 %!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
|
978 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
979 %!error do_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
980 %!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
|
981 %!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
|
982 %!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
|
983 %!warning <unrecognized escape sequence> do_string_escapes ('\G'); |
13094 | 984 */ |
985 | |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
986 const char * undo_string_escape (char c) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
987 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
988 if (! c) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
989 return ""; |
801 | 990 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
991 switch (c) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
992 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
993 case '\0': |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
994 return R"(\0)"; |
801 | 995 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
996 case '\a': |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
997 return R"(\a)"; |
801 | 998 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
999 case '\b': // backspace |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1000 return R"(\b)"; |
801 | 1001 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1002 case '\f': // formfeed |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1003 return R"(\f)"; |
801 | 1004 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1005 case '\n': // newline |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1006 return R"(\n)"; |
801 | 1007 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1008 case '\r': // carriage return |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1009 return R"(\r)"; |
801 | 1010 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1011 case '\t': // horizontal tab |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1012 return R"(\t)"; |
801 | 1013 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1014 case '\v': // vertical tab |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1015 return R"(\v)"; |
801 | 1016 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1017 case '\\': // backslash |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1018 return R"(\\)"; |
801 | 1019 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1020 case '"': // double quote |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1021 return R"(\")"; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1022 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1023 default: |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1024 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1025 static char retval[2] {'\0', '\0'}; |
20973 | 1026 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1027 retval[0] = c; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1028 return retval; |
1755 | 1029 } |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1030 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1031 } |
801 | 1032 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1033 std::string undo_string_escapes (const std::string& s) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1034 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1035 std::string retval; |
801 | 1036 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1037 for (std::size_t i = 0; i < s.length (); i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1038 retval.append (undo_string_escape (s[i])); |
801 | 1039 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1040 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1041 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1042 |
1957 | 1043 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
|
1044 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
1045 @deftypefn {} {@var{newstr} =} undo_string_escapes (@var{string}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
1046 Convert special characters in @var{string} back to their escaped forms. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1047 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1048 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
|
1049 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1050 @example |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
1051 @var{bell} = "\a"; |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1052 @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
|
1053 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1054 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 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
|
1061 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1062 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1063 @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 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
|
1065 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
|
1066 @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
|
1067 @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
|
1068 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1069 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1070 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
|
1071 @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
|
1072 @end deftypefn */) |
801 | 1073 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
1074 if (args.length () != 1) |
5823 | 1075 print_usage (); |
801 | 1076 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
1077 std::string str = args(0).xstring_value ("undo_string_escapes: STRING 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
|
1078 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1079 return ovl (undo_string_escapes (str)); |
801 | 1080 } |
1081 | |
13094 | 1082 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1083 %!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
|
1084 %!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
|
1085 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar") |
13094 | 1086 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1087 %!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
|
1088 %!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
|
1089 %!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
|
1090 %! "\\a\\b\\f\\n\\r\\t\\v") |
13094 | 1091 |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1092 %!assert (undo_string_escapes ("\\"), '\\') |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1093 %!assert (undo_string_escapes ("\\"), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1094 %!assert (undo_string_escapes (char (92)), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1095 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1096 %!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
|
1097 %!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
|
1098 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1099 %!error undo_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1100 %!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
|
1101 %!error undo_string_escapes (3) |
13094 | 1102 */ |
1103 | |
8229 | 1104 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
|
1105 doc: /* -*- texinfo -*- |
30559
841a10208c38
doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents:
30346
diff
changeset
|
1106 @deftypefn {} {@var{tf} =} is_absolute_filename (@var{file}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1107 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
|
1108 @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
|
1109 @end deftypefn */) |
8229 | 1110 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1111 if (args.length () != 1) |
8229 | 1112 print_usage (); |
1113 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1114 return ovl (args(0).is_string () |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1115 && sys::env::absolute_pathname (args(0).string_value ())); |
8229 | 1116 } |
1117 | |
13094 | 1118 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1119 ## FIXME: We need system-dependent tests here. |
13094 | 1120 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1121 %!error is_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1122 %!error is_absolute_filename ("foo", "bar") |
13094 | 1123 */ |
1124 | |
8229 | 1125 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
|
1126 doc: /* -*- texinfo -*- |
30559
841a10208c38
doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents:
30346
diff
changeset
|
1127 @deftypefn {} {@var{tf} =} is_rooted_relative_filename (@var{file}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1128 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
|
1129 @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
|
1130 @end deftypefn */) |
8229 | 1131 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1132 if (args.length () != 1) |
8229 | 1133 print_usage (); |
1134 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1135 return ovl (args(0).is_string () |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1136 && sys::env::rooted_relative_pathname (args(0).string_value ())); |
8229 | 1137 } |
1138 | |
13094 | 1139 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1140 ## FIXME: We need system-dependent tests here. |
13094 | 1141 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1142 %!error is_rooted_relative_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1143 %!error is_rooted_relative_filename ("foo", "bar") |
13094 | 1144 */ |
1145 | |
8229 | 1146 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
|
1147 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
1148 @deftypefn {} {@var{abs_fname} =} make_absolute_filename (@var{file}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
1149 Return the full name of @var{file} beginning from the root of the file system. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1150 |
28292
5bf3f462c11e
Document that make_absolute_filename and canonicalize_file_name do not
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
28012
diff
changeset
|
1151 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
|
1152 @var{file} is performed. |
30329
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30269
diff
changeset
|
1153 @seealso{canonicalize_file_name, is_absolute_filename, |
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30269
diff
changeset
|
1154 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
|
1155 @end deftypefn */) |
8229 | 1156 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1157 if (args.length () != 1) |
8229 | 1158 print_usage (); |
1159 | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1160 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
|
1161 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1162 return ovl (sys::env::make_absolute (nm)); |
8229 | 1163 } |
1164 | |
13094 | 1165 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1166 ## FIXME: We need system-dependent tests here. |
13094 | 1167 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1168 %!error make_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1169 %!error make_absolute_filename ("foo", "bar") |
13094 | 1170 */ |
1171 | |
23519
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
1172 DEFMETHOD (dir_in_loadpath, interp, args, , |
4fe410bd918d
use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
1173 doc: /* -*- texinfo -*- |
23988
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1174 @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
|
1175 @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
|
1176 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
|
1177 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
|
1178 |
bdde51fda657
doc: Improve docstrings for file_in_loadpath, dir_in_loadpath (bug #51706).
Rik <rik@octave.org>
parents:
23925
diff
changeset
|
1179 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
|
1180 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1181 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
|
1182 @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
|
1183 @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
|
1184 @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
|
1185 @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
|
1186 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
|
1187 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
|
1188 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
|
1189 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1190 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
|
1191 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
|
1192 @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
|
1193 @end deftypefn */) |
8229 | 1194 { |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
1195 int nargin = args.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
1196 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1197 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1198 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1199 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
1200 std::string dir; |
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
1201 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1202 dir = args(0).xstring_value ("dir_in_loadpath: DIR must be a directory name"); |
8229 | 1203 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1204 load_path& lp = interp.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
1205 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1206 if (nargin == 1) |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
1207 return ovl (lp.find_dir (dir)); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1208 else |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
1209 return ovl (Cell (lp.find_matching_dirs (dir))); |
8229 | 1210 } |
1211 | |
13094 | 1212 /* |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1213 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1214 %! f = dir_in_loadpath ("plot"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1215 %! assert (ischar (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1216 %! assert (! isempty (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1217 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1218 %!test |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1219 %! 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
|
1220 %! assert (f, ""); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1221 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1222 %!test |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1223 %! 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
|
1224 %! assert (lst, {}); |
13094 | 1225 |
18110
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18105
diff
changeset
|
1226 %!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
|
1227 %!error dir_in_loadpath ("foo", "bar", 1) |
13094 | 1228 */ |
1229 | |
5465 | 1230 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
|
1231 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
|
1232 @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
|
1233 @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
|
1234 @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
|
1235 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
|
1236 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1237 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
|
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 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
|
1240 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
|
1241 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1242 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
|
1243 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
|
1244 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
|
1245 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1246 @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
|
1247 @end deftypefn */) |
3716 | 1248 { |
5465 | 1249 int nargin = args.length (); |
1250 | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1251 if (nargin > 1) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1252 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1253 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1254 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1255 |
5465 | 1256 if (nargin == 1) |
1257 { | |
1258 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1259 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1260 std::string nm = args(0).string_value (); |
5465 | 1261 |
19743
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1262 retval = octave_errno::lookup (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1263 } |
5465 | 1264 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1265 { |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1266 int val = args(0).xint_value ("errno: argument must be string or integer"); |
5465 | 1267 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1268 retval = octave_errno::set (val); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1269 } |
5465 | 1270 } |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1271 else |
5465 | 1272 retval = octave_errno::get (); |
3716 | 1273 |
1274 return retval; | |
1275 } | |
1276 | |
13094 | 1277 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1278 %!assert (isnumeric (errno ())) |
13094 | 1279 |
1280 %!test | |
1281 %! lst = errno_list (); | |
1282 %! fns = fieldnames (lst); | |
1283 %! oldval = errno (fns{1}); | |
1284 %! assert (isnumeric (oldval)); | |
1285 %! errno (oldval); | |
1286 %! newval = errno (); | |
1287 %! assert (oldval, newval); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1288 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1289 %!error errno ("foo", 1) |
13094 | 1290 */ |
1291 | |
5465 | 1292 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
|
1293 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30822
diff
changeset
|
1294 @deftypefn {} {@var{S} =} errno_list () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1295 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
|
1296 @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
|
1297 @end deftypefn */) |
5465 | 1298 { |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1299 if (args.length () != 0) |
5823 | 1300 print_usage (); |
5465 | 1301 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1302 return ovl (octave_errno::list ()); |
5465 | 1303 } |
3716 | 1304 |
13094 | 1305 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1306 %!assert (isstruct (errno_list ())) |
13094 | 1307 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1308 %!error errno_list ("foo") |
13094 | 1309 */ |
1310 | |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1311 static void check_dimensions (octave_idx_type& nr, octave_idx_type& nc, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1312 const char *warnfor) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1313 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1314 if (nr < 0 || nc < 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1315 { |
5781 | 1316 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
|
1317 "%s: converting negative dimension to zero", warnfor); |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1318 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1319 nr = (nr < 0) ? 0 : nr; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1320 nc = (nc < 0) ? 0 : nc; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1321 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1322 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1323 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1324 void check_dimensions (dim_vector& dim, const char *warnfor) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1325 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1326 bool neg = false; |
4481 | 1327 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1328 for (int i = 0; i < dim.ndims (); i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1329 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1330 if (dim(i) < 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1331 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1332 dim(i) = 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1333 neg = true; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1334 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1335 } |
4481 | 1336 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1337 if (neg) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1338 warning_with_id ("Octave:neg-dim-as-zero", |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1339 "%s: converting negative dimension to zero", warnfor); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1340 } |
4481 | 1341 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1342 void get_dimensions (const octave_value& a, const char *warn_for, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1343 dim_vector& dim) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1344 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1345 // We support dimensions to be specified by a vector, even if it's empty. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1346 // If the vector is empty, the final dimensions end up being 0x0. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1347 if (! a.dims ().isvector () && a.dims ().numel () != 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1348 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
21405
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1349 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1350 const Array<octave_idx_type> v = a.octave_idx_type_vector_value (true); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1351 const octave_idx_type n = v.numel (); |
21405
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1352 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1353 dim.resize (n); // even if n < 2, resize sets it back to 2 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1354 if (n == 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1355 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1356 dim(0) = 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1357 dim(1) = 0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1358 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1359 else if (n == 1) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1360 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1361 dim(0) = v(0); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1362 dim(1) = v(0); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1363 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1364 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1365 for (octave_idx_type i = 0; i < n; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1366 dim(i) = v(i); |
4481 | 1367 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1368 check_dimensions (dim, warn_for); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1369 } |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1370 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1371 void get_dimensions (const octave_value& a, const char *warn_for, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1372 octave_idx_type& nr, octave_idx_type& nc) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1373 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1374 if (a.is_scalar_type ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1375 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1376 nr = nc = a.idx_type_value (true); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1377 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1378 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1379 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1380 nr = a.rows (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1381 nc = a.columns (); |
3354 | 1382 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1383 if ((nr != 1 || nc != 2) && (nr != 2 || nc != 1)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1384 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
3354 | 1385 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1386 Array<octave_idx_type> v = a.octave_idx_type_vector_value (true); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1387 nr = v(0); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1388 nc = v(1); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1389 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1390 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1391 check_dimensions (nr, nc, warn_for); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1392 } |
3354 | 1393 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1394 void get_dimensions (const octave_value& a, const octave_value& b, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1395 const char *warn_for, octave_idx_type& nr, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1396 octave_idx_type& nc) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1397 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1398 nr = (a.isempty () ? 0 : a.idx_type_value (true)); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1399 nc = (b.isempty () ? 0 : b.idx_type_value (true)); |
3354 | 1400 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1401 check_dimensions (nr, nc, warn_for); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1402 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1403 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1404 octave_idx_type dims_to_numel (const dim_vector& dims, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1405 const octave_value_list& idx_arg) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1406 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1407 octave_idx_type retval; |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1408 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1409 octave_idx_type len = idx_arg.length (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1410 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1411 if (len == 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1412 retval = dims.numel (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1413 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1414 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1415 const dim_vector dv = dims.redim (len); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1416 retval = 1; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1417 for (octave_idx_type i = 0; i < len; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1418 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1419 octave_value idxi = idx_arg(i); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1420 if (idxi.is_magic_colon ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1421 retval *= dv(i); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1422 else if (idxi.isnumeric ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1423 retval *= idxi.numel (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1424 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1425 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1426 try |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1427 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1428 idx_vector jdx = idxi.index_vector (); |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
1429 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1430 retval *= jdx.length (dv(i)); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1431 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1432 catch (const index_exception& ie) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1433 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1434 error ("dims_to_numel: invalid index %s", ie.what ()); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1435 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1436 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1437 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1438 } |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1439 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1440 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1441 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1442 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1443 Matrix identity_matrix (octave_idx_type nr, octave_idx_type nc) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1444 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1445 Matrix m (nr, nc, 0.0); |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1446 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1447 if (nr > 0 && nc > 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1448 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1449 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
|
1450 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1451 for (octave_idx_type i = 0; i < n; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1452 m (i, i) = 1.0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1453 } |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1454 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1455 return m; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1456 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1457 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1458 FloatMatrix float_identity_matrix (octave_idx_type nr, octave_idx_type nc) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1459 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1460 FloatMatrix m (nr, nc, 0.0); |
4478 | 1461 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1462 if (nr > 0 && nc > 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1463 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1464 octave_idx_type n = std::min (nr, nc); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1465 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1466 for (octave_idx_type i = 0; i < n; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1467 m (i, i) = 1.0; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1468 } |
4478 | 1469 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1470 return m; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1471 } |
4478 | 1472 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1473 std::size_t format (std::ostream& os, const char *fmt, ...) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1474 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1475 std::size_t retval; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1476 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1477 va_list args; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1478 va_start (args, fmt); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1479 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1480 retval = vformat (os, fmt, args); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1481 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1482 va_end (args); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1483 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1484 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1485 } |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1486 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1487 std::size_t vformat (std::ostream& os, const char *fmt, va_list args) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1488 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1489 std::string s = vasprintf (fmt, args); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1490 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1491 os << s; |
3620 | 1492 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1493 return s.length (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1494 } |
3620 | 1495 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1496 std::string vasprintf (const char *fmt, va_list args) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1497 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1498 std::string retval; |
3620 | 1499 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1500 char *result; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1501 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1502 int status = octave_vasprintf_wrapper (&result, fmt, args); |
3620 | 1503 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1504 if (status >= 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1505 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1506 retval = result; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1507 ::free (result); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1508 } |
3620 | 1509 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1510 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1511 } |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1512 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1513 std::string asprintf (const char *fmt, ...) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1514 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1515 std::string retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1516 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1517 va_list args; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1518 va_start (args, fmt); |
4302 | 1519 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1520 retval = vasprintf (fmt, args); |
3620 | 1521 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1522 va_end (args); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1523 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1524 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1525 } |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1526 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1527 // FIXME: sleep is complicated because we want it to be interruptible. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1528 // With the way this program handles signals, the sleep system call |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1529 // won't respond to SIGINT. Maybe there is a better way than |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1530 // breaking this up into multiple shorter intervals? |
4302 | 1531 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1532 void sleep (double seconds, bool do_graphics_events) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1533 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1534 if (seconds <= 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1535 return; |
4302 | 1536 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1537 // Allow free access to graphics resources while the interpreter thread |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1538 // is asleep |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1539 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1540 gh_manager& gh_mgr = __get_gh_manager__ (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1541 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1542 if (do_graphics_events) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1543 gh_mgr.unlock (); |
4302 | 1544 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1545 if (math::isinf (seconds)) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1546 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1547 // Wait for kbhit |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1548 int c = -1; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1549 flush_stdout (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1550 |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1551 struct timespec one_tenth = { 0, 100000000 }; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
1552 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1553 while (c < 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1554 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1555 octave_nanosleep_wrapper (&one_tenth, nullptr); |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1556 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1557 octave_quit (); |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1558 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1559 if (do_graphics_events) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1560 gh_mgr.process_events (); |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1561 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1562 c = kbhit (false); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1563 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1564 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1565 else |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1566 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1567 sys::time now; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1568 double end_time = now.double_value () + seconds; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1569 double remaining_time = seconds; |
26617
98afb8bbd1f6
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1570 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1571 // Split pause into 100 ms time steps to allow the execution of |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1572 // graphics events and interrupts. |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1573 struct timespec nano_laps = { 0, 100000000 }; |
24604
6b3c78f84d3b
allow octave_sleep to be interruptible (bug #52876)
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1574 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1575 while (remaining_time > 0.1) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1576 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1577 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
|
1578 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1579 if (do_graphics_events) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1580 { |
27335
50216d7a2f6b
eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents:
27279
diff
changeset
|
1581 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
|
1582 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1583 now.stamp (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1584 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
|
1585 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1586 if (remaining_time < 0.1) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1587 break; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1588 } |
25961
f7b205562f1d
Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25928
diff
changeset
|
1589 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1590 octave_nanosleep_wrapper (&nano_laps, nullptr); |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1591 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1592 now.stamp (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1593 remaining_time = end_time - now.double_value (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1594 } |
27094
f16471efcdf4
Fix Fpause timing accuracy when graphics events are processed (bug #56336)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26617
diff
changeset
|
1595 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1596 if (remaining_time > 0.0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1597 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1598 nano_laps = { 0, static_cast<int> (remaining_time * 1e9) }; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1599 octave_nanosleep_wrapper (&nano_laps, nullptr); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1600 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1601 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1602 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1603 |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
1604 DEFMETHOD (isindex, interp, args, , |
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
1605 doc: /* -*- texinfo -*- |
30559
841a10208c38
doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents:
30346
diff
changeset
|
1606 @deftypefn {} {@var{tf} =} isindex (@var{ind}) |
841a10208c38
doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents:
30346
diff
changeset
|
1607 @deftypefnx {} {@var{tf} =} isindex (@var{ind}, @var{n}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1608 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
|
1609 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1610 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
|
1611 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
|
1612 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1613 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
|
1614 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
|
1615 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
|
1616 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1617 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
|
1618 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
|
1619 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
|
1620 @end deftypefn */) |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1621 { |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1622 int nargin = args.length (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1623 |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1624 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1625 print_usage (); |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1626 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1627 octave_idx_type n = 0; |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1628 if (nargin == 2) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1629 n = args(1).idx_type_value (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1630 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1631 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1632 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1633 try |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1634 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1635 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
|
1636 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1637 if (nargin == 2) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1638 retval = idx.extent (n) <= n; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1639 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1640 retval = true; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1641 } |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29960
diff
changeset
|
1642 catch (const execution_exception&) |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1643 { |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
1644 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
|
1645 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1646 retval = false; |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1647 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1648 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1649 return retval; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1650 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1651 |
13094 | 1652 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1653 %!assert (isindex ([1, 2, 3])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1654 %!assert (isindex (1:3)) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1655 %!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
|
1656 %!assert (isindex ([1, 2, -3]), false) |
13094 | 1657 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1658 %!error isindex () |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1659 %!error isindex (1:3, 2, 3) |
13094 | 1660 */ |
1661 | |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1662 octave_value_list |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1663 do_simple_cellfun (octave_value_list (*fcn) (const octave_value_list&, int), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1664 const char *fcn_name, const octave_value_list& args, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1665 int nargout) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1666 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1667 octave_value_list new_args = args; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1668 octave_value_list retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1669 int nargin = args.length (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1670 OCTAVE_LOCAL_BUFFER (bool, iscell, nargin); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1671 OCTAVE_LOCAL_BUFFER (Cell, cells, nargin); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1672 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
|
1673 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1674 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
|
1675 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1676 octave_idx_type numel = 1; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1677 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
|
1678 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1679 for (int i = 0; i < nargin; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1680 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1681 octave_value arg = new_args(i); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1682 iscell[i] = arg.iscell (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1683 if (iscell[i]) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1684 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1685 cells[i] = arg.cell_value (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1686 octave_idx_type n = ccells[i].numel (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1687 if (n == 1) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1688 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1689 iscell[i] = false; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1690 new_args(i) = ccells[i](0); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1691 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1692 else if (numel == 1) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1693 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1694 numel = n; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1695 dims = ccells[i].dims (); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1696 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1697 else if (dims != ccells[i].dims ()) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1698 error ("%s: cell arguments must have matching sizes", fcn_name); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1699 } |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1700 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1701 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1702 for (int i = 0; i < nargout; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1703 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
|
1704 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1705 for (octave_idx_type j = 0; j < numel; j++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1706 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1707 for (int i = 0; i < nargin; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1708 if (iscell[i]) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1709 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
|
1710 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1711 octave_quit (); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1712 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1713 const octave_value_list tmp = fcn (new_args, nargout); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1714 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1715 if (tmp.length () < nargout) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1716 error ("%s: do_simple_cellfun: internal error", fcn_name); |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
1717 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1718 for (int i = 0; i < nargout; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1719 rcells[i](j) = tmp(i); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1720 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1721 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1722 retval.resize (nargout); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1723 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1724 for (int i = 0; i < nargout; i++) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1725 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
|
1726 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1727 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1728 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1729 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1730 octave_value |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1731 do_simple_cellfun (octave_value_list (*fcn) (const octave_value_list&, int), |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1732 const char *fcn_name, const octave_value_list& args) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1733 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1734 octave_value retval; |
20973 | 1735 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1736 const octave_value_list tmp = do_simple_cellfun (fcn, fcn_name, args, 1); |
20973 | 1737 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1738 if (tmp.length () > 0) |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1739 retval = tmp(0); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1740 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1741 return retval; |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1742 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1743 |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1744 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
|
1745 doc: /* -*- texinfo -*- |
30559
841a10208c38
doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents:
30346
diff
changeset
|
1746 @deftypefn {} {@var{tf} =} isstudent () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1747 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
|
1748 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1749 @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
|
1750 @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
|
1751 @end deftypefn */) |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1752 { |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1753 if (args.length () != 0) |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1754 print_usage (); |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1755 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1756 return ovl (false); |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1757 } |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1758 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1759 /* |
19152
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1760 %!assert (isstudent (), false) |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1761 |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1762 %!error isstudent (1) |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1763 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1764 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31278
diff
changeset
|
1765 OCTAVE_END_NAMESPACE(octave) |