Mercurial > octave
annotate libinterp/corefcn/utils.cc @ 21724:aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
* configure.ac, Doxyfile.in, make_int.cc, Backend.cc, BaseControl.cc,
ButtonControl.cc, Canvas.cc, CheckBoxControl.cc, Container.cc,
ContextMenu.cc, EditControl.cc, Figure.cc, FigureWindow.cc,
GLCanvas.cc, KeyMap.cc, ListBoxControl.cc, Logger.cc, Menu.cc,
MouseModeActionGroup.cc, Object.cc, ObjectFactory.cc,
ObjectProxy.cc, Panel.cc, PopupMenuControl.cc, PushButtonControl.cc,
PushTool.cc, QtHandlesUtils.cc, RadioButtonControl.cc,
SliderControl.cc, TextControl.cc, TextEdit.cc,
ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, __init_qt__.cc,
annotation-dialog.cc, gl-select.cc, module.mk, color-picker.cc,
dialog.cc, documentation-dock-widget.cc, files-dock-widget.cc,
find-files-dialog.cc, find-files-model.cc, history-dock-widget.cc,
liboctgui-build-info.in.cc, file-editor-tab.cc, file-editor.cc,
find-dialog.cc, marker.cc, marker.h, octave-qscintilla.cc,
octave-txt-lexer.cc, main-window.cc, octave-cmd.cc,
octave-dock-widget.cc, octave-gui.cc, octave-interpreter.cc,
octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc,
settings-dialog.cc, shortcut-manager.cc, terminal-dock-widget.cc,
thread-manager.cc, welcome-wizard.cc, workspace-model.cc,
workspace-view.cc, build-env.in.cc, Cell.cc, __contourc__.cc,
__dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc,
__lin_interpn__.cc, __luinc__.cc, __magick_read__.cc,
__pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc,
bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
cdisplay.c, cdisplay.h, cellfun.cc, coct-hdf5-types.c, colloc.cc,
comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc,
debug.cc, defaults.cc, defaults.in.h, defun.cc, det.cc, dirfns.cc,
display.cc, dlmread.cc, dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc,
error.cc, errwarn.cc, event-queue.cc, fft.cc, fft2.cc, fftn.cc,
file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, gammainc.cc,
gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc,
gl-render.cc, gl2ps-print.cc, graphics.cc, gripes.cc, hash.cc,
help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jit-ir.cc, jit-ir.h,
jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, kron.cc,
load-path.cc, load-save.cc, lookup.cc, ls-ascii-helper.cc,
ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc,
ls-oct-binary.cc, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc,
lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mex.h,
mexproto.h, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc,
oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-iostrm.cc,
oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc,
oct-stdstrm.h, oct-stream.cc, oct-strstrm.cc, oct-tex-lexer.in.ll,
oct-tex-parser.in.yy, octave-link.cc, ordschur.cc, pager.cc,
pinv.cc, pr-output.cc, procstream.cc, profiler.cc, psi.cc,
pt-jit.cc, pt-jit.h, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc,
regexp.cc, schur.cc, sighandlers.cc, sighandlers.h, siglist.c,
siglist.h, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, spparms.cc,
sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc,
sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, text-renderer.cc,
time.cc, toplev.cc, tril.cc, tsearch.cc, txt-eng.cc, typecast.cc,
urlwrite.cc, utils.cc, variables.cc, xdiv.cc, xgl2ps.c, xnorm.cc,
xpow.cc, zfstream.cc, zfstream.h, __delaunayn__.cc, __eigs__.cc,
__fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc,
audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc,
convhulln.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc,
liboctinterp-build-info.in.cc, mkbuiltins, mkops, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc,
ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc,
ov-complex.cc, ov-cs-list.cc, ov-cx-diag.cc, ov-cx-mat.cc,
ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc,
ov-fcn.cc, 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-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc,
ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc,
ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc,
ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc,
ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc,
ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ovl.cc, octave.cc, octave.h,
op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc,
op-bm-sbm.cc, op-cdm-cdm.cc, op-cdm-cm.cc, op-cdm-dm.cc,
op-cdm-m.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cdm.cc,
op-cm-cm.cc, op-cm-cs.cc, op-cm-dm.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc,
op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-cdm.cc, op-dm-cm.cc,
op-dm-dm.cc, op-dm-m.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-double-conv.cc,
op-fcdm-fcdm.cc, op-fcdm-fcm.cc, op-fcdm-fdm.cc, op-fcdm-fm.cc,
op-fcm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fdm.cc,
op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc,
op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fcdm.cc, op-fdm-fcm.cc,
op-fdm-fdm.cc, op-fdm-fm.cc, op-float-conv.cc, op-fm-fcdm.cc,
op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fdm.cc, op-fm-fm.cc, op-fm-fs.cc,
op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc,
op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc,
op-int-conv.cc, op-m-cdm.cc, op-m-cm.cc, op-m-cs.cc, op-m-dm.cc,
op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc,
op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc,
op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc,
op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc,
op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc,
op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc,
lex.ll, oct-parse.in.yy, pt-arg-list.cc, pt-array-list.cc,
pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc,
pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc, pt-const.cc,
pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc,
pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc,
pt-loop.h, pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc,
pt-stmt.cc, pt-unop.cc, pt.cc, token.cc, Array-jit.cc, Array-tc.cc,
version.cc, Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc,
Array-f.cc, Array-fC.cc, Array-i.cc, Array-idx-vec.cc, Array-s.cc,
Array-str.cc, Array-util.cc, Array-voidp.cc, Array.cc,
CColVector.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc,
CRowVector.cc, CSparse.cc, MArray-C.cc, MArray-d.cc, MArray-f.cc,
MArray-fC.cc, MArray-i.cc, MArray-s.cc, MSparse-C.cc, MSparse-d.cc,
MatrixType.cc, PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc,
Sparse-d.cc, boolMatrix.cc, boolNDArray.cc, boolSparse.cc,
chMatrix.cc, chNDArray.cc, dColVector.cc, dDiagMatrix.cc,
dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dim-vector.cc,
dim-vector.h, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc,
fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc,
fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc,
int16NDArray.cc, int32NDArray.cc, int64NDArray.cc, int8NDArray.cc,
uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc,
uint8NDArray.cc, Faddeeva.cc, blaswrap.c, cquit.c, f77-extern.cc,
f77-fcn.c, f77-fcn.h, lo-error.c, lo-error.h, quit.cc, quit.h,
liboctave-build-info.in.cc, CollocWt.cc, DASPK.cc, DASRT.cc,
DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, aepbalance.cc,
chol.cc, eigs-base.cc, fEIG.cc, gepbalance.cc, hess.cc,
lo-mappers.cc, lo-specfun.cc, lu.cc, oct-convn.cc, oct-fftw.cc,
oct-norm.cc, oct-rand.cc, oct-spparms.cc, qr.cc, qrp.cc,
randmtzig.cc, randpoisson.cc, schur.cc, sparse-chol.cc,
sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, svd.cc, mk-ops.awk,
mx-defs.h, dir-ops.cc, file-ops.cc, file-stat.cc, lo-sysdep.cc,
mach-info.cc, oct-env.cc, oct-group.cc, oct-passwd.cc,
oct-syscalls.cc, oct-time.cc, oct-uname.cc, pathlen.h, syswait.h,
cmd-edit.cc, cmd-hist.cc, data-conv.cc, f2c-main.c, glob-match.cc,
kpse.cc, lo-array-errwarn.cc, lo-array-gripes.cc, lo-cutils.c,
lo-cutils.h, lo-ieee.cc, lo-ieee.h, lo-regexp.cc, lo-utils.cc,
oct-base64.cc, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h,
oct-locbuf.cc, oct-mutex.cc, oct-rl-edit.c, oct-rl-edit.h,
oct-rl-hist.c, oct-rl-hist.h, oct-shlib.cc, oct-sort.cc,
pathsearch.cc, singleton-cleanup.cc, sparse-sort.cc, sparse-util.cc,
statdefs.h, str-vec.cc, unwind-prot.cc, url-transfer.cc,
acinclude.m4, display-available.c, display-available.h, main-cli.cc,
main-gui.cc, main.in.cc, mkoctfile.in.cc, octave-build-info.in.cc,
octave-config.in.cc, shared-fcns.h:
Use "#if ..." consistently instead of "#ifdef" and "#ifndef".
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 17 May 2016 12:09:30 -0400 |
parents | 53728df3e4c9 |
children | 6a1eded90355 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19403
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
11012 | 4 Copyright (C) 2010 VZLU Prague |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
25 # include "config.h" |
1 | 26 #endif |
27 | |
3716 | 28 #include <cerrno> |
1346 | 29 #include <cstring> |
1343 | 30 |
3503 | 31 #include <fstream> |
32 #include <iostream> | |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
33 #include <limits> |
1728 | 34 #include <string> |
35 | |
1 | 36 #include <sys/types.h> |
37 #include <unistd.h> | |
367 | 38 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
39 #include "vasnprintf.h" |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
40 |
3040 | 41 #include "dir-ops.h" |
42 #include "file-ops.h" | |
2926 | 43 #include "file-stat.h" |
4732 | 44 #include "lo-mappers.h" |
11006
aca961a3f387
provide gethostname function
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
45 #include "lo-utils.h" |
1651 | 46 #include "oct-cmplx.h" |
2926 | 47 #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
|
48 #include "oct-locbuf.h" |
3040 | 49 #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
|
50 #include "quit.h" |
1755 | 51 #include "str-vec.h" |
1651 | 52 |
4216 | 53 #include "Cell.h" |
2492 | 54 #include <defaults.h> |
1352 | 55 #include "defun.h" |
56 #include "dirfns.h" | |
57 #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
|
58 #include "errwarn.h" |
1352 | 59 #include "input.h" |
10502
f13bf183a003
isvarname: keywords are not valid variable names
Judd Storrs <jstorrs@gmail.com>
parents:
10315
diff
changeset
|
60 #include "lex.h" |
5832 | 61 #include "load-path.h" |
5465 | 62 #include "oct-errno.h" |
1742 | 63 #include "oct-hist.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
64 #include "ovl.h" |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10605
diff
changeset
|
65 #include "ov-range.h" |
1352 | 66 #include "pager.h" |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10502
diff
changeset
|
67 #include "parse.h" |
1690 | 68 #include "sysdep.h" |
1750 | 69 #include "toplev.h" |
1 | 70 #include "unwind-prot.h" |
1352 | 71 #include "utils.h" |
72 #include "variables.h" | |
1 | 73 |
4143 | 74 // Return TRUE if S is a valid identifier. |
75 | |
76 bool | |
77 valid_identifier (const char *s) | |
78 { | |
5290 | 79 if (! s || ! (isalpha (*s) || *s == '_' || *s == '$')) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
80 return false; |
4143 | 81 |
82 while (*++s != '\0') | |
5290 | 83 if (! (isalnum (*s) || *s == '_' || *s == '$')) |
4143 | 84 return false; |
85 | |
86 return true; | |
87 } | |
88 | |
89 bool | |
90 valid_identifier (const std::string& s) | |
91 { | |
92 return valid_identifier (s.c_str ()); | |
93 } | |
94 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8715
diff
changeset
|
95 DEFUN (isvarname, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
96 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
97 @deftypefn {} {} isvarname (@var{name})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
98 Return true if @var{name} is a valid variable name.\n\ |
12573
232a90612254
Add new section on parsing to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
99 @seealso{iskeyword, exist, who}\n\ |
4264 | 100 @end deftypefn") |
101 { | |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
102 if (args.length () != 1) |
5823 | 103 print_usage (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
104 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
105 octave_value retval = false; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
106 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
107 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
|
108 { |
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
109 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
|
110 |
15435
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
111 retval = valid_identifier (varname) && ! is_keyword (varname); |
13ffb3130b2f
Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents:
15215
diff
changeset
|
112 } |
4264 | 113 |
114 return retval; | |
115 } | |
116 | |
13094 | 117 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
118 %!assert (isvarname ("foo"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
119 %!assert (isvarname ("_foo"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
120 %!assert (isvarname ("_1"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
121 %!assert (isvarname ("1foo"), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
122 %!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
|
123 %!assert (isvarname (12), false) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
124 %!assert (isvarname ("foo+bar"), false) |
13094 | 125 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
126 %!error isvarname () |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21526
diff
changeset
|
127 %!error isvarname ("foo", "bar") |
13094 | 128 */ |
129 | |
6323 | 130 // Return TRUE if F and G are both names for the same file. |
131 | |
132 bool | |
133 same_file (const std::string& f, const std::string& g) | |
134 { | |
6598 | 135 return same_file_internal (f, g); |
6323 | 136 } |
137 | |
1 | 138 int |
3523 | 139 almost_match (const std::string& std, const std::string& s, int min_match_len, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
140 int case_sens) |
1 | 141 { |
1755 | 142 int stdlen = std.length (); |
143 int slen = s.length (); | |
1 | 144 |
145 return (slen <= stdlen | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
146 && slen >= min_match_len |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
147 && (case_sens |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
148 ? (strncmp (std.c_str (), s.c_str (), slen) == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
149 : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0))); |
287 | 150 } |
151 | |
581 | 152 // Ugh. |
153 | |
287 | 154 int |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
155 keyword_almost_match (const char * const *std, int *min_len, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
156 const std::string& s, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
157 int min_toks_to_match, int max_toks) |
287 | 158 { |
159 int status = 0; | |
160 int tok_count = 0; | |
161 int toks_matched = 0; | |
162 | |
1755 | 163 if (s.empty () || max_toks < 1) |
287 | 164 return status; |
165 | |
1755 | 166 char *kw = strsave (s.c_str ()); |
287 | 167 |
168 char *t = kw; | |
169 while (*t != '\0') | |
170 { | |
171 if (*t == '\t') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
172 *t = ' '; |
287 | 173 t++; |
174 } | |
175 | |
176 char *beg = kw; | |
177 while (*beg == ' ') | |
178 beg++; | |
179 | |
180 if (*beg == '\0') | |
181 return status; | |
182 | |
183 | |
3072 | 184 const char **to_match = new const char * [max_toks + 1]; |
185 const char * const *s1 = std; | |
186 const char **s2 = to_match; | |
287 | 187 |
526 | 188 if (! s1 || ! s2) |
287 | 189 goto done; |
190 | |
191 s2[tok_count] = beg; | |
192 char *end; | |
526 | 193 while ((end = strchr (beg, ' ')) != 0) |
287 | 194 { |
195 *end = '\0'; | |
196 beg = end + 1; | |
197 | |
198 while (*beg == ' ') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
199 beg++; |
287 | 200 |
201 if (*beg == '\0') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
202 break; |
287 | 203 |
204 tok_count++; | |
205 if (tok_count >= max_toks) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
206 goto done; |
287 | 207 |
208 s2[tok_count] = beg; | |
209 } | |
526 | 210 s2[tok_count+1] = 0; |
287 | 211 |
212 s2 = to_match; | |
213 | |
214 for (;;) | |
215 { | |
216 if (! almost_match (*s1, *s2, min_len[toks_matched], 0)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
217 goto done; |
287 | 218 |
219 toks_matched++; | |
220 | |
221 s1++; | |
222 s2++; | |
223 | |
224 if (! *s2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
225 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
226 status = (toks_matched >= min_toks_to_match); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
227 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
228 } |
287 | 229 |
230 if (! *s1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
231 goto done; |
287 | 232 } |
233 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
234 done: |
287 | 235 |
236 delete [] kw; | |
237 delete [] to_match; | |
238 | |
239 return status; | |
1 | 240 } |
241 | |
20973 | 242 // Return nonzero if either NR or NC is zero. |
243 // Return -1 if this should be considered fatal; return 1 if this is ok. | |
2234 | 244 |
245 int | |
5275 | 246 empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc) |
2234 | 247 { |
4478 | 248 return (nr == 0 || nc == 0); |
2234 | 249 } |
250 | |
581 | 251 // See if the given file is in the path. |
252 | |
3536 | 253 std::string |
4243 | 254 search_path_for_file (const std::string& path, const string_vector& names) |
686 | 255 { |
3174 | 256 dir_path p (path); |
686 | 257 |
10250 | 258 return octave_env::make_absolute (p.find_first_of (names)); |
686 | 259 } |
260 | |
4216 | 261 // Find all locations of the given file in the path. |
262 | |
263 string_vector | |
4243 | 264 search_path_for_all_files (const std::string& path, const string_vector& names) |
4216 | 265 { |
266 dir_path p (path); | |
267 | |
4243 | 268 string_vector sv = p.find_all_first_of (names); |
4216 | 269 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20210
diff
changeset
|
270 octave_idx_type len = sv.numel (); |
4216 | 271 |
6379 | 272 for (octave_idx_type i = 0; i < len; i++) |
10250 | 273 sv[i] = octave_env::make_absolute (sv[i]); |
4216 | 274 |
275 return sv; | |
276 } | |
277 | |
278 static string_vector | |
279 make_absolute (const string_vector& sv) | |
280 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20210
diff
changeset
|
281 octave_idx_type len = sv.numel (); |
6379 | 282 |
283 string_vector retval (len); | |
4216 | 284 |
6379 | 285 for (octave_idx_type i = 0; i < len; i++) |
10250 | 286 retval[i] = octave_env::make_absolute (sv[i]); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
287 |
6379 | 288 return retval; |
4216 | 289 } |
290 | |
3195 | 291 DEFUN (file_in_loadpath, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
292 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
293 @deftypefn {} {} file_in_loadpath (@var{file})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
294 @deftypefnx {} {} file_in_loadpath (@var{file}, \"all\")\n\ |
3195 | 295 \n\ |
5448 | 296 Return the absolute name of @var{file} if it can be found in\n\ |
5814 | 297 the list of directories specified by @code{path}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
298 \n\ |
10646
6c50b56824aa
file_in_path, file_in_loadpath: return empty string instead of empty matrix if file not found
John W. Eaton <jwe@octave.org>
parents:
10613
diff
changeset
|
299 If no file is found, return an empty character string.\n\ |
4216 | 300 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
301 If the first argument is a cell array of strings, search each directory of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
302 the loadpath for element of the cell array and return the first that\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
303 matches.\n\ |
4243 | 304 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
305 If the second optional argument @qcode{\"all\"} is supplied, return a cell\n\ |
20181
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
306 array containing the list of all files that have the same name in the path.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
307 If no files are found, return an empty cell array.\n\ |
18110
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18105
diff
changeset
|
308 @seealso{file_in_path, dir_in_loadpath, path}\n\ |
5642 | 309 @end deftypefn") |
3195 | 310 { |
4243 | 311 int nargin = args.length (); |
3195 | 312 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
313 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
314 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
315 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20973
diff
changeset
|
316 string_vector names = args(0).xstring_vector_value ("file_in_loadpath: FILE argument must be a string"); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
317 |
20973 | 318 if (names.empty ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
319 error ("file_in_loadpath: FILE argument must not be empty"); |
4243 | 320 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
321 if (nargin == 1) |
20973 | 322 return ovl (octave_env::make_absolute (load_path::find_first_of (names))); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
323 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
324 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
325 std::string opt = args(1).xstring_value ("file_in_loadpath: optional second argument must be a string"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
326 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
327 if (opt != "all") |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
328 error ("file_in_loadpath: \"all\" is only valid second argument"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
329 |
20973 | 330 return ovl (Cell (make_absolute (load_path::find_all_first_of (names)))); |
4216 | 331 } |
3195 | 332 } |
333 | |
13094 | 334 /* |
335 %!test | |
336 %! f = file_in_loadpath ("plot.m"); | |
337 %! assert (ischar (f)); | |
338 %! assert (! isempty (f)); | |
339 | |
340 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
341 %! f = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$"); |
13094 | 342 %! assert (f, ""); |
343 | |
344 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
345 %! lst = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$", "all"); |
13094 | 346 %! assert (lst, {}); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
347 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
348 %!error file_in_loadpath () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
349 %!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
|
350 %!error file_in_loadpath ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
351 %!error file_in_loadpath ("plot.m", "bar") |
13094 | 352 */ |
353 | |
1957 | 354 DEFUN (file_in_path, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
355 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
356 @deftypefn {} {} file_in_path (@var{path}, @var{file})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
357 @deftypefnx {} {} file_in_path (@var{path}, @var{file}, \"all\")\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
358 Return the absolute name of @var{file} if it can be found in @var{path}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
359 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
360 The value of @var{path} should be a colon-separated list of directories in\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
361 the format described for @code{path}. If no file is found, return an empty\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
362 character string. For example:\n\ |
3301 | 363 \n\ |
364 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
365 @group\n\ |
5456 | 366 file_in_path (EXEC_PATH, \"sh\")\n\ |
367 @result{} \"/bin/sh\"\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
368 @end group\n\ |
3301 | 369 @end example\n\ |
4216 | 370 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
371 If the second argument is a cell array of strings, search each directory of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
372 the path for element of the cell array and return the first that matches.\n\ |
4243 | 373 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
374 If the third optional argument @qcode{\"all\"} is supplied, return a cell\n\ |
20181
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
375 array containing the list of all files that have the same name in the path.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
376 If no files are found, return an empty cell array.\n\ |
18110
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18105
diff
changeset
|
377 @seealso{file_in_loadpath, dir_in_loadpath, path}\n\ |
3301 | 378 @end deftypefn") |
686 | 379 { |
4243 | 380 int nargin = args.length (); |
1755 | 381 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
382 if (nargin < 2 || nargin > 3) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
383 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
384 |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
385 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
|
386 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20973
diff
changeset
|
387 string_vector names = args(1).xstring_vector_value ("file_in_path: FILE argument must be a string"); |
4243 | 388 |
20973 | 389 if (names.empty ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
390 error ("file_in_path: FILE argument must not be empty"); |
4243 | 391 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
392 if (nargin == 2) |
20973 | 393 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
|
394 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
395 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
396 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
|
397 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
398 if (opt != "all") |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
399 error ("file_in_path: \"all\" is only valid third argument"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
400 |
20973 | 401 return ovl (Cell (make_absolute (search_path_for_all_files (path, names)))); |
686 | 402 } |
403 } | |
404 | |
13094 | 405 /* |
406 %!test | |
407 %! f = file_in_path (path (), "plot.m"); | |
408 %! assert (ischar (f)); | |
409 %! assert (! isempty (f)); | |
410 | |
411 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
412 %! f = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$"); |
13094 | 413 %! assert (f, ""); |
414 | |
415 %!test | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
416 %! lst = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$", "all"); |
13094 | 417 %! assert (lst, {}); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
418 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
419 %!error file_in_path () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
420 %!error file_in_path ("foo") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
421 %!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
|
422 %!error file_in_path ([]) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
423 %!error file_in_path (path (), []) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
424 %!error file_in_path (path (), "plot.m", "bar") |
13094 | 425 */ |
426 | |
3536 | 427 std::string |
3523 | 428 file_in_path (const std::string& name, const std::string& suffix) |
526 | 429 { |
3523 | 430 std::string nm = name; |
526 | 431 |
1755 | 432 if (! suffix.empty ()) |
433 nm.append (suffix); | |
686 | 434 |
10250 | 435 return octave_env::make_absolute (load_path::find_file (nm)); |
526 | 436 } |
437 | |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
438 std::string |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
439 find_data_file_in_load_path (const std::string& fcn, |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
440 const std::string& file, |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
441 bool require_regular_file) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
442 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
443 std::string fname = file; |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
444 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
445 if (! (octave_env::absolute_pathname (fname) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
446 || octave_env::rooted_relative_pathname (fname))) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
447 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
448 // Load path will also search "." first, but we don't want to |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
449 // issue a warning if the file is found in the current directory, |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
450 // so do an explicit check for that. |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
451 file_stat fs (fname); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
452 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
453 bool local_file_ok |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
454 = fs.exists () && (fs.is_reg () || ! require_regular_file); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
455 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
456 if (! local_file_ok) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
457 { |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
458 // Not directly found; search load path. |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
459 std::string tmp |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
460 = octave_env::make_absolute (load_path::find_file (fname)); |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
461 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
462 if (! tmp.empty ()) |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
463 { |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21041
diff
changeset
|
464 warn_data_file_in_path (fcn, tmp); |
19030
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
465 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
466 fname = tmp; |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
467 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
468 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
469 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
470 |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
471 return fname; |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
472 } |
9ef10e6a5987
make "file found in path" warnings consistent
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
473 |
20973 | 474 // See if there is an function file in the path. |
475 // If so, return the full path to the file. | |
581 | 476 |
3536 | 477 std::string |
3523 | 478 fcn_file_in_path (const std::string& name) |
526 | 479 { |
3523 | 480 std::string retval; |
908 | 481 |
1755 | 482 int len = name.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
483 |
1755 | 484 if (len > 0) |
485 { | |
5832 | 486 if (octave_env::absolute_pathname (name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
487 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
488 file_stat fs (name); |
5832 | 489 |
17955
9fc0836cb69b
Fix "get_help_text('\')" in Windows.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17818
diff
changeset
|
490 if (fs.exists () && ! fs.is_dir ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
491 retval = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
492 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
14819
diff
changeset
|
493 else if (len > 2 && name[len - 2] == '.' && name[len - 1] == 'm') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
494 retval = load_path::find_fcn_file (name.substr (0, len-2)); |
908 | 495 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
496 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
497 std::string fname = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
498 size_t pos = name.find_first_of (Vfilemarker); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
499 if (pos != std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
500 fname = name.substr (0, pos); |
7818
5640a70cbab1
Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
501 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
502 retval = load_path::find_fcn_file (fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
503 } |
908 | 504 } |
1755 | 505 |
506 return retval; | |
526 | 507 } |
508 | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
509 // See if there is a directory called "name" in the path and if it |
20973 | 510 // contains a Contents.m file. If so, return the full path to this file. |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
511 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
512 std::string |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
513 contents_file_in_path (const std::string& dir) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
514 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
515 std::string retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
516 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
517 if (dir.length () > 0) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
518 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
519 std::string tcontents = file_ops::concat (load_path::find_dir (dir), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
520 std::string ("Contents.m")); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
521 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
522 file_stat fs (tcontents); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
523 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
524 if (fs.exists ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
525 retval = octave_env::make_absolute (tcontents); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
526 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
527 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
528 return retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
529 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
530 |
21526
b76d1de20f9a
Deprecate unused C++ functions oct_file_in_path, mex_file_in_path.
Rik <rik@octave.org>
parents:
21405
diff
changeset
|
531 // Deprecated in 4.2, remove in 4.6. |
20973 | 532 // See if there is a .oct file in the path. |
533 // If so, return the full path to the file. | |
581 | 534 |
3536 | 535 std::string |
3523 | 536 oct_file_in_path (const std::string& name) |
572 | 537 { |
3523 | 538 std::string retval; |
908 | 539 |
1755 | 540 int len = name.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
541 |
1755 | 542 if (len > 0) |
543 { | |
5832 | 544 if (octave_env::absolute_pathname (name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
545 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
546 file_stat fs (name); |
5832 | 547 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
548 if (fs.exists ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
549 retval = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
550 } |
20973 | 551 else if (len > 4 && name.find (".oct", len-5)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
552 retval = load_path::find_oct_file (name.substr (0, len-4)); |
908 | 553 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
554 retval = load_path::find_oct_file (name); |
908 | 555 } |
1755 | 556 |
557 return retval; | |
572 | 558 } |
559 | |
21526
b76d1de20f9a
Deprecate unused C++ functions oct_file_in_path, mex_file_in_path.
Rik <rik@octave.org>
parents:
21405
diff
changeset
|
560 // Deprecated in 4.2, remove in 4.6. |
20973 | 561 // See if there is a .mex file in the path. |
562 // If so, return the full path to the file. | |
5864 | 563 |
564 std::string | |
565 mex_file_in_path (const std::string& name) | |
566 { | |
567 std::string retval; | |
568 | |
569 int len = name.length (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
570 |
5864 | 571 if (len > 0) |
572 { | |
573 if (octave_env::absolute_pathname (name)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
574 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
575 file_stat fs (name); |
5864 | 576 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
577 if (fs.exists ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
578 retval = name; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
579 } |
20973 | 580 else if (len > 4 && name.find (".mex", len-5)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
581 retval = load_path::find_mex_file (name.substr (0, len-4)); |
5864 | 582 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
583 retval = load_path::find_mex_file (name); |
5864 | 584 } |
585 | |
586 return retval; | |
587 } | |
588 | |
3103 | 589 // Replace backslash escapes in a string with the real values. |
590 | |
3536 | 591 std::string |
3523 | 592 do_string_escapes (const std::string& s) |
3103 | 593 { |
3523 | 594 std::string retval; |
3103 | 595 |
596 size_t i = 0; | |
597 size_t j = 0; | |
598 size_t len = s.length (); | |
599 | |
600 retval.resize (len); | |
601 | |
602 while (j < len) | |
603 { | |
604 if (s[j] == '\\' && j+1 < len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
605 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
606 switch (s[++j]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
607 { |
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
|
608 case 'a': // alarm |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
609 retval[i] = '\a'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
610 break; |
3103 | 611 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
612 case 'b': // backspace |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
613 retval[i] = '\b'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
614 break; |
3103 | 615 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
616 case 'f': // formfeed |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
617 retval[i] = '\f'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
618 break; |
3103 | 619 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
620 case 'n': // newline |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
621 retval[i] = '\n'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
622 break; |
3103 | 623 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
624 case 'r': // carriage return |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
625 retval[i] = '\r'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
626 break; |
3103 | 627 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
628 case 't': // horizontal tab |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
629 retval[i] = '\t'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
630 break; |
3103 | 631 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
632 case 'v': // vertical tab |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
633 retval[i] = '\v'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
634 break; |
3103 | 635 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
636 case '\\': // backslash |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
637 retval[i] = '\\'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
638 break; |
3103 | 639 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
640 case '\'': // quote |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
641 retval[i] = '\''; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
642 break; |
3103 | 643 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
644 case '"': // double quote |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
645 retval[i] = '"'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
646 break; |
3103 | 647 |
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
|
648 case '0': |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
649 case '1': |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
650 case '2': |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
651 case '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
|
652 case '4': |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
653 case '5': |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
654 case '6': |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
655 case '7': // octal input |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
656 { |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
657 size_t k; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
658 int tmpi = s[j] - '0'; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
659 for (k = j+1; k < std::min (j+3, len); k++) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
660 { |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
661 int digit = s[k] - '0'; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
662 if (digit < 0 || digit > 7) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
663 break; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
664 tmpi <<= 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
|
665 tmpi += digit; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
666 } |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
667 retval[i] = tmpi; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
668 j = k - 1; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
669 break; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
670 } |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
671 |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
672 case 'x': // hex input |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
673 { |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
674 size_t k; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
675 int tmpi = 0; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
676 for (k = j+1; k < std::min (j+3, len); k++) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
677 { |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
678 if (! isxdigit (s[k])) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
679 break; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
680 |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
681 tmpi <<= 4; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
682 int digit = s[k]; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
683 if (digit >= 'a') |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
684 tmpi += digit - 'a' + 10; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
685 else if (digit >= 'A') |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
686 tmpi += digit - 'A' + 10; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
687 else |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
688 tmpi += digit - '0'; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
689 } |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
690 |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
691 if (k == j+1) |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
692 warning ("malformed hex escape sequence '\\x' --\ |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
693 converting to '\\0'"); |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
694 |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
695 retval[i] = tmpi; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
696 j = k - 1; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
697 break; |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
698 } |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
699 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
700 default: |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
701 warning ("unrecognized escape sequence '\\%c' --\ |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
702 converting to '%c'", s[j], s[j]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
703 retval[i] = s[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
704 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
705 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
706 } |
3103 | 707 else |
20973 | 708 retval[i] = s[j]; |
3103 | 709 |
710 i++; | |
711 j++; | |
712 } | |
713 | |
3105 | 714 retval.resize (i); |
3103 | 715 |
716 return retval; | |
717 } | |
718 | |
719 DEFUN (do_string_escapes, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
720 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
721 @deftypefn {} {} do_string_escapes (@var{string})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
722 Convert escape sequences in @var{string} to the characters they represent.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
723 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
724 Escape sequences begin with a leading backslash\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
725 (@qcode{'@xbackslashchar{}'}) followed by 1--3 characters\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
726 (.e.g., @qcode{\"@xbackslashchar{}n\"} => newline).\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
727 @seealso{undo_string_escapes}\n\ |
3446 | 728 @end deftypefn") |
3103 | 729 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
730 if (args.length () != 1) |
5823 | 731 print_usage (); |
3103 | 732 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
733 std::string str = args(0).xstring_value ("do_string_escapes: STRING argument must be of type string"); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
734 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
735 return ovl (do_string_escapes (str)); |
3103 | 736 } |
737 | |
13094 | 738 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
739 %!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
|
740 %!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
|
741 %!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
|
742 %!assert ("foo\nbar", ["foo", char(10), "bar"]) |
13094 | 743 |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
744 %!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
|
745 %!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
|
746 %!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
|
747 %! 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
|
748 %!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
|
749 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
750 %!assert (do_string_escapes ('\\'), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
751 %!assert (do_string_escapes ("\\\\"), "\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
752 %!assert (do_string_escapes ("\\\\"), char (92)) |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
753 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
754 %!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
|
755 %!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
|
756 %!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
|
757 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"") |
13094 | 758 |
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
|
759 %!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
|
760 %!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
|
761 %!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
|
762 %!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
|
763 |
29eb47fe8e8c
Add support for octal and hex escape sequences in single-quoted *printf arguments (bug #39774).
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
764 %!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
|
765 %!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
|
766 %!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
|
767 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
768 %!error do_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
769 %!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
|
770 %!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
|
771 %!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
|
772 %!warning <unrecognized escape sequence> do_string_escapes ('\G'); |
13094 | 773 */ |
774 | |
1755 | 775 const char * |
801 | 776 undo_string_escape (char c) |
777 { | |
778 if (! c) | |
1755 | 779 return ""; |
801 | 780 |
781 switch (c) | |
782 { | |
3893 | 783 case '\0': |
784 return "\\0"; | |
785 | |
801 | 786 case '\a': |
787 return "\\a"; | |
788 | |
789 case '\b': // backspace | |
790 return "\\b"; | |
791 | |
792 case '\f': // formfeed | |
793 return "\\f"; | |
794 | |
795 case '\n': // newline | |
796 return "\\n"; | |
797 | |
798 case '\r': // carriage return | |
799 return "\\r"; | |
800 | |
801 case '\t': // horizontal tab | |
802 return "\\t"; | |
803 | |
804 case '\v': // vertical tab | |
805 return "\\v"; | |
806 | |
807 case '\\': // backslash | |
808 return "\\\\"; | |
809 | |
810 case '"': // double quote | |
811 return "\\\""; | |
812 | |
813 default: | |
1755 | 814 { |
20973 | 815 static char retval[2] = "\0"; |
816 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
817 retval[0] = c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
818 return retval; |
1755 | 819 } |
801 | 820 } |
821 } | |
822 | |
3536 | 823 std::string |
3523 | 824 undo_string_escapes (const std::string& s) |
801 | 825 { |
3523 | 826 std::string retval; |
801 | 827 |
1755 | 828 for (size_t i = 0; i < s.length (); i++) |
829 retval.append (undo_string_escape (s[i])); | |
801 | 830 |
1755 | 831 return retval; |
801 | 832 } |
833 | |
1957 | 834 DEFUN (undo_string_escapes, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
835 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
836 @deftypefn {} {} undo_string_escapes (@var{s})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
837 Convert special characters in strings back to their escaped forms.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
838 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
839 For example, the expression\n\ |
3361 | 840 \n\ |
841 @example\n\ | |
842 bell = \"\\a\";\n\ | |
843 @end example\n\ | |
844 \n\ | |
845 @noindent\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
846 assigns the value of the alert character (control-g, ASCII code 7) to the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
847 string variable @code{bell}. If this string is printed, the system will\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
848 ring the terminal bell (if it is possible). This is normally the desired\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
849 outcome. However, sometimes it is useful to be able to print the original\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
850 representation of the string, with the special characters replaced by their\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
851 escape sequences. For example,\n\ |
3361 | 852 \n\ |
853 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
854 @group\n\ |
3361 | 855 octave:13> undo_string_escapes (bell)\n\ |
856 ans = \\a\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8929
diff
changeset
|
857 @end group\n\ |
3361 | 858 @end example\n\ |
859 \n\ | |
860 @noindent\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
861 replaces the unprintable alert character with its printable representation.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
862 @seealso{do_string_escapes}\n\ |
3361 | 863 @end deftypefn") |
801 | 864 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
865 if (args.length () != 1) |
5823 | 866 print_usage (); |
801 | 867 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
868 std::string str = args(0).xstring_value ("undo_string_escapes: S argument must be a string"); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
869 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
870 return ovl (undo_string_escapes (str)); |
801 | 871 } |
872 | |
13094 | 873 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
874 %!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
|
875 %!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
|
876 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar") |
13094 | 877 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
878 %!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
|
879 %!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
|
880 %!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
|
881 %! "\\a\\b\\f\\n\\r\\t\\v") |
13094 | 882 |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
883 %!assert (undo_string_escapes ("\\"), '\\') |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
884 %!assert (undo_string_escapes ("\\"), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
885 %!assert (undo_string_escapes (char (92)), "\\\\") |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
886 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
887 %!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
|
888 %!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
|
889 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
890 %!error undo_string_escapes () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
891 %!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
|
892 %!error undo_string_escapes (3) |
13094 | 893 */ |
894 | |
8229 | 895 DEFUN (is_absolute_filename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
896 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
897 @deftypefn {} {} is_absolute_filename (@var{file})\n\ |
8229 | 898 Return true if @var{file} is an absolute filename.\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
899 @seealso{is_rooted_relative_filename, make_absolute_filename, isdir}\n\ |
8229 | 900 @end deftypefn") |
901 { | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
902 if (args.length () != 1) |
8229 | 903 print_usage (); |
904 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
905 return ovl (args(0).is_string () |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
906 && octave_env::absolute_pathname (args(0).string_value ())); |
8229 | 907 } |
908 | |
13094 | 909 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
910 ## FIXME: We need system-dependent tests here. |
13094 | 911 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
912 %!error is_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
913 %!error is_absolute_filename ("foo", "bar") |
13094 | 914 */ |
915 | |
8229 | 916 DEFUN (is_rooted_relative_filename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
917 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
918 @deftypefn {} {} is_rooted_relative_filename (@var{file})\n\ |
8229 | 919 Return true if @var{file} is a rooted-relative filename.\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11066
diff
changeset
|
920 @seealso{is_absolute_filename, make_absolute_filename, isdir}\n\ |
8229 | 921 @end deftypefn") |
922 { | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
923 if (args.length () != 1) |
8229 | 924 print_usage (); |
925 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
926 return ovl (args(0).is_string () |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
927 && octave_env::rooted_relative_pathname (args(0).string_value ())); |
8229 | 928 } |
929 | |
13094 | 930 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
931 ## FIXME: We need system-dependent tests here. |
13094 | 932 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
933 %!error is_rooted_relative_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
934 %!error is_rooted_relative_filename ("foo", "bar") |
13094 | 935 */ |
936 | |
8229 | 937 DEFUN (make_absolute_filename, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
938 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
939 @deftypefn {} {} make_absolute_filename (@var{file})\n\ |
14819
67b6b47a22f6
doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
940 Return the full name of @var{file} beginning from the root of the file\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
941 system.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
942 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
943 No check is done for the existence of @var{file}.\n\ |
14819
67b6b47a22f6
doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
944 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isdir}\n\ |
8229 | 945 @end deftypefn") |
946 { | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
947 if (args.length () != 1) |
8229 | 948 print_usage (); |
949 | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
950 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
|
951 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
952 return ovl (octave_env::make_absolute (nm)); |
8229 | 953 } |
954 | |
13094 | 955 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
956 ## FIXME: We need system-dependent tests here. |
13094 | 957 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
958 %!error make_absolute_filename () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
959 %!error make_absolute_filename ("foo", "bar") |
13094 | 960 */ |
961 | |
18110
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18105
diff
changeset
|
962 DEFUN (dir_in_loadpath, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
963 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
964 @deftypefn {} {} dir_in_loadpath (@var{dir})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
965 @deftypefnx {} {} dir_in_loadpath (@var{dir}, \"all\")\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
966 Return the full name of the path element matching @var{dir}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
967 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
968 The match is performed at the end of each path element. For example, if\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
969 @var{dir} is @qcode{\"foo/bar\"}, it matches the path element\n\ |
17290
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
970 @nospell{@qcode{\"/some/dir/foo/bar\"}}, but not\n\ |
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
971 @nospell{@qcode{\"/some/dir/foo/bar/baz\"}}\n\ |
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
972 @nospell{@qcode{\"/some/dir/allfoo/bar\"}}.\n\ |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
973 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
974 If the optional second argument is supplied, return a cell array containing\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
975 all name matches rather than just the first.\n\ |
18062
aca545afdf25
doc: Add seealso links to find_dir_in_path function.
Rik <rik@octave.org>
parents:
17955
diff
changeset
|
976 @seealso{file_in_path, file_in_loadpath, path}\n\ |
8229 | 977 @end deftypefn") |
978 { | |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
979 int nargin = args.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
980 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
981 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
982 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
983 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
984 std::string dir; |
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20800
diff
changeset
|
985 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
986 dir = args(0).xstring_value ("dir_in_loadpath: DIR must be a directory name"); |
8229 | 987 |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
988 if (nargin == 1) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
989 return ovl (load_path::find_dir (dir)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
990 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
991 return ovl (Cell (load_path::find_matching_dirs (dir))); |
8229 | 992 } |
993 | |
13094 | 994 /* |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
995 %!test |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
996 %! f = dir_in_loadpath ("plot"); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
997 %! assert (ischar (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
998 %! assert (! isempty (f)); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
999 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1000 %!test |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1001 %! 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
|
1002 %! assert (f, ""); |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1003 |
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1004 %!test |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1005 %! 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
|
1006 %! assert (lst, {}); |
13094 | 1007 |
18110
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18105
diff
changeset
|
1008 %!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
|
1009 %!error dir_in_loadpath ("foo", "bar", 1) |
13094 | 1010 */ |
1011 | |
5465 | 1012 DEFUNX ("errno", Ferrno, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1013 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
1014 @deftypefn {} {@var{err} =} errno ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
1015 @deftypefnx {} {@var{err} =} errno (@var{val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
1016 @deftypefnx {} {@var{err} =} errno (@var{name})\n\ |
5465 | 1017 Return the current value of the system-dependent variable errno,\n\ |
1018 set its value to @var{val} and return the previous value, or return\n\ | |
1019 the named error code given @var{name} as a character string, or -1\n\ | |
1020 if @var{name} is not found.\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1021 @seealso{errno_list}\n\ |
3716 | 1022 @end deftypefn") |
1023 { | |
5465 | 1024 int nargin = args.length (); |
1025 | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1026 if (nargin > 1) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1027 print_usage (); |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1028 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1029 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1030 |
5465 | 1031 if (nargin == 1) |
1032 { | |
1033 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1034 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1035 std::string nm = args(0).string_value (); |
5465 | 1036 |
19743
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1037 retval = octave_errno::lookup (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1038 } |
5465 | 1039 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1040 { |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1041 int val = args(0).xint_value ("errno: argument must be string or integer"); |
5465 | 1042 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1043 retval = octave_errno::set (val); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1044 } |
5465 | 1045 } |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1046 else |
5465 | 1047 retval = octave_errno::get (); |
3716 | 1048 |
1049 return retval; | |
1050 } | |
1051 | |
13094 | 1052 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1053 %!assert (isnumeric (errno ())) |
13094 | 1054 |
1055 %!test | |
1056 %! lst = errno_list (); | |
1057 %! fns = fieldnames (lst); | |
1058 %! oldval = errno (fns{1}); | |
1059 %! assert (isnumeric (oldval)); | |
1060 %! errno (oldval); | |
1061 %! newval = errno (); | |
1062 %! assert (oldval, newval); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1063 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1064 %!error errno ("foo", 1) |
13094 | 1065 */ |
1066 | |
5465 | 1067 DEFUN (errno_list, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1068 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
1069 @deftypefn {} {} errno_list ()\n\ |
5465 | 1070 Return a structure containing the system-dependent errno values.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1071 @seealso{errno}\n\ |
5465 | 1072 @end deftypefn") |
1073 { | |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1074 if (args.length () != 0) |
5823 | 1075 print_usage (); |
5465 | 1076 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1077 return ovl (octave_errno::list ()); |
5465 | 1078 } |
3716 | 1079 |
13094 | 1080 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1081 %!assert (isstruct (errno_list ())) |
13094 | 1082 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1083 %!error errno_list ("foo") |
13094 | 1084 */ |
1085 | |
2285 | 1086 static void |
5275 | 1087 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor) |
3354 | 1088 { |
1089 if (nr < 0 || nc < 0) | |
1090 { | |
5781 | 1091 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
|
1092 "%s: converting negative dimension to zero", warnfor); |
3354 | 1093 |
4457 | 1094 nr = (nr < 0) ? 0 : nr; |
1095 nc = (nc < 0) ? 0 : nc; | |
3354 | 1096 } |
1097 } | |
1098 | |
1099 void | |
4513 | 1100 check_dimensions (dim_vector& dim, const char *warnfor) |
4481 | 1101 { |
1102 bool neg = false; | |
1103 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21581
diff
changeset
|
1104 for (int i = 0; i < dim.ndims (); i++) |
4481 | 1105 { |
1106 if (dim(i) < 0) | |
1107 { | |
1108 dim(i) = 0; | |
1109 neg = true; | |
1110 } | |
1111 } | |
1112 | |
5781 | 1113 if (neg) |
1114 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
|
1115 "%s: converting negative dimension to zero", warnfor); |
4481 | 1116 } |
1117 | |
1118 | |
1119 void | |
1120 get_dimensions (const octave_value& a, const char *warn_for, | |
4513 | 1121 dim_vector& dim) |
4481 | 1122 { |
21405
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1123 // We support dimensions to be specified by any vector, even if it's a |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1124 // vector of dimensions 0x1, 1x0, 1x1x0, or 1x1x6. If the vector ends |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1125 // up being empty, the final dimensions end up being 0x0. |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1126 if (! a.dims ().is_vector ()) |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1127 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1128 |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1129 const Array<int> v = a.int_vector_value (); |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1130 const octave_idx_type n = v.numel (); |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1131 |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1132 dim.resize (n); // even if n < 2, resize sets it back to 2 |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1133 if (n == 0) |
4481 | 1134 { |
21405
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1135 dim(0) = 0; |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1136 dim(1) = 0; |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1137 } |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1138 else if (n == 1) |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1139 { |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1140 dim(0) = v(0); |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1141 dim(1) = v(0); |
4481 | 1142 } |
1143 else | |
21405
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1144 for (octave_idx_type i = 0; i < n; i++) |
120bb822c6f4
Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents:
21301
diff
changeset
|
1145 dim(i) = v(i); |
4481 | 1146 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1147 check_dimensions (dim, warn_for); |
4481 | 1148 } |
1149 | |
1150 | |
1151 void | |
3354 | 1152 get_dimensions (const octave_value& a, const char *warn_for, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1153 octave_idx_type& nr, octave_idx_type& nc) |
3354 | 1154 { |
1155 if (a.is_scalar_type ()) | |
1156 { | |
21041
63374982750b
Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20990
diff
changeset
|
1157 nr = nc = a.idx_type_value (); |
3354 | 1158 } |
1159 else | |
1160 { | |
1161 nr = a.rows (); | |
1162 nc = a.columns (); | |
1163 | |
20966
7026da637999
maint: utils.cc: invert if/else/error instances.
Doug Stewart <doug.dastew@gmail.com
parents:
20955
diff
changeset
|
1164 if ((nr != 1 || nc != 2) && (nr != 2 || nc != 1)) |
7026da637999
maint: utils.cc: invert if/else/error instances.
Doug Stewart <doug.dastew@gmail.com
parents:
20955
diff
changeset
|
1165 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for); |
3354 | 1166 |
20966
7026da637999
maint: utils.cc: invert if/else/error instances.
Doug Stewart <doug.dastew@gmail.com
parents:
20955
diff
changeset
|
1167 Array<double> v = a.vector_value (); |
7026da637999
maint: utils.cc: invert if/else/error instances.
Doug Stewart <doug.dastew@gmail.com
parents:
20955
diff
changeset
|
1168 nr = static_cast<octave_idx_type> (fix (v(0))); |
7026da637999
maint: utils.cc: invert if/else/error instances.
Doug Stewart <doug.dastew@gmail.com
parents:
20955
diff
changeset
|
1169 nc = static_cast<octave_idx_type> (fix (v(1))); |
3354 | 1170 } |
1171 | |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1172 check_dimensions (nr, nc, warn_for); |
3354 | 1173 } |
1174 | |
1175 void | |
1176 get_dimensions (const octave_value& a, const octave_value& b, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1177 const char *warn_for, octave_idx_type& nr, octave_idx_type& nc) |
3354 | 1178 { |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
1179 nr = a.is_empty () |
21041
63374982750b
Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20990
diff
changeset
|
1180 ? 0 : a.idx_type_value ("%s: row dimension must be a scalar", warn_for); |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20709
diff
changeset
|
1181 nc = b.is_empty () |
21041
63374982750b
Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20990
diff
changeset
|
1182 ? 0 : b.idx_type_value ("%s: column dimension must be a scalar", warn_for); |
3354 | 1183 |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1184 check_dimensions (nr, nc, warn_for); |
3354 | 1185 } |
1186 | |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1187 octave_idx_type |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
1188 dims_to_numel (const dim_vector& dims, const octave_value_list& idx_arg) |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1189 { |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1190 octave_idx_type retval; |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1191 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
1192 octave_idx_type len = idx_arg.length (); |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1193 |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1194 if (len == 0) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1195 retval = dims.numel (); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1196 else |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1197 { |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1198 const dim_vector dv = dims.redim (len); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1199 retval = 1; |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1200 for (octave_idx_type i = 0; i < len; i++) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1201 { |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
1202 octave_value idxi = idx_arg(i); |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1203 if (idxi.is_magic_colon ()) |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1204 retval *= dv(i); |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1205 else if (idxi.is_numeric_type ()) |
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1206 retval *= idxi.numel (); |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1207 else |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1208 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20535
diff
changeset
|
1209 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20535
diff
changeset
|
1210 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20535
diff
changeset
|
1211 idx_vector jdx = idxi.index_vector (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1212 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20535
diff
changeset
|
1213 retval *= jdx.length (dv(i)); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20535
diff
changeset
|
1214 } |
20651
c1d94e5cd5ea
catch index_exception by const reference where possible
John W. Eaton <jwe@octave.org>
parents:
20582
diff
changeset
|
1215 catch (const index_exception& e) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20535
diff
changeset
|
1216 { |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
1217 std::string idx = e.idx (); |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
1218 std::string msg = e.details (); |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
1219 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20535
diff
changeset
|
1220 error ("dims_to_numel: Invalid IDX %s. %s", |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
1221 idx.c_str (), msg.c_str ()); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20535
diff
changeset
|
1222 } |
9842
10519b4d6507
fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
1223 } |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1224 } |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1225 } |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1226 |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1227 return retval; |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1228 } |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9487
diff
changeset
|
1229 |
4478 | 1230 Matrix |
5275 | 1231 identity_matrix (octave_idx_type nr, octave_idx_type nc) |
4478 | 1232 { |
1233 Matrix m (nr, nc, 0.0); | |
1234 | |
1235 if (nr > 0 && nc > 0) | |
1236 { | |
5275 | 1237 octave_idx_type n = std::min (nr, nc); |
4478 | 1238 |
5275 | 1239 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1240 m (i, i) = 1.0; |
4478 | 1241 } |
1242 | |
1243 return m; | |
1244 } | |
1245 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1246 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1247 float_identity_matrix (octave_idx_type nr, octave_idx_type nc) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1248 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1249 FloatMatrix m (nr, nc, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1250 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1251 if (nr > 0 && nc > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1252 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1253 octave_idx_type n = std::min (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1254 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1255 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10257
diff
changeset
|
1256 m (i, i) = 1.0; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1257 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1258 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1259 return m; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1260 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7481
diff
changeset
|
1261 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1262 size_t |
3622 | 1263 octave_format (std::ostream& os, const char *fmt, ...) |
3620 | 1264 { |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1265 size_t retval; |
3620 | 1266 |
1267 va_list args; | |
1268 va_start (args, fmt); | |
1269 | |
1270 retval = octave_vformat (os, fmt, args); | |
1271 | |
1272 va_end (args); | |
1273 | |
1274 return retval; | |
1275 } | |
1276 | |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1277 size_t |
3622 | 1278 octave_vformat (std::ostream& os, const char *fmt, va_list args) |
3620 | 1279 { |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1280 std::string s = octave_vasprintf (fmt, args); |
3620 | 1281 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1282 os << s; |
3620 | 1283 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1284 return s.length (); |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1285 } |
4135 | 1286 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1287 std::string |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1288 octave_vasprintf (const char *fmt, va_list args) |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1289 { |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1290 std::string retval; |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1291 |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1292 char *result; |
4302 | 1293 |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1294 int status = gnulib::vasprintf (&result, fmt, args); |
4302 | 1295 |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1296 if (status >= 0) |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1297 { |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1298 retval = result; |
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1299 ::free (result); |
4302 | 1300 } |
3620 | 1301 |
1302 return retval; | |
1303 } | |
1304 | |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1305 std::string |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1306 octave_asprintf (const char *fmt, ...) |
4302 | 1307 { |
13991
051a8f94b6f8
avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents:
13932
diff
changeset
|
1308 std::string retval; |
4302 | 1309 |
1310 va_list args; | |
1311 va_start (args, fmt); | |
1312 | |
14005
f8556baf1949
rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents:
13991
diff
changeset
|
1313 retval = octave_vasprintf (fmt, args); |
4302 | 1314 |
1315 va_end (args); | |
1316 | |
1317 return retval; | |
1318 } | |
1319 | |
4086 | 1320 void |
1321 octave_sleep (double seconds) | |
1322 { | |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1323 if (seconds <= 0) |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1324 return; |
4086 | 1325 |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1326 double fraction = std::modf (seconds, &seconds); |
20926
5df1d099e56d
avoid warning about gnulib::floor
John W. Eaton <jwe@octave.org>
parents:
20925
diff
changeset
|
1327 fraction = gnulib::floor (fraction * 1000000000); // nanoseconds |
4086 | 1328 |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1329 time_t sec = ((seconds > std::numeric_limits<time_t>::max ()) |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1330 ? std::numeric_limits<time_t>::max () |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1331 : static_cast<time_t> (seconds)); |
4086 | 1332 |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1333 struct timespec delay = { sec, static_cast<long> (fraction) }; |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1334 struct timespec remaining; |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1335 gnulib::nanosleep (&delay, &remaining); |
10070
897e62651c0a
correctly handle interrupts in pause()
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
1336 |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
1337 octave_quit (); |
4086 | 1338 } |
1339 | |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1340 DEFUN (isindex, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1341 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
1342 @deftypefn {} {} isindex (@var{ind})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
1343 @deftypefnx {} {} isindex (@var{ind}, @var{n})\n\ |
20084
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19743
diff
changeset
|
1344 Return true if @var{ind} is a valid index.\n\ |
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19743
diff
changeset
|
1345 \n\ |
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19743
diff
changeset
|
1346 Valid indices are either positive integers (although possibly of real data\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1347 type), or logical arrays.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1348 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1349 If present, @var{n} specifies the maximum extent of the dimension to be\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1350 indexed. When possible the internal result is cached so that subsequent\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1351 indexing using @var{ind} will not perform the check again.\n\ |
20084
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19743
diff
changeset
|
1352 \n\ |
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19743
diff
changeset
|
1353 Implementation Note: Strings are first converted to double values before the\n\ |
4d0c7fec0a31
doc: Explain treatment of strings by isindex() (bug #44855).
Rik <rik@octave.org>
parents:
19743
diff
changeset
|
1354 checks for valid indices are made. Unless a string contains the NULL\n\ |
20317
2ec049e50ed8
doc: Fix backslash characters in docstrings
Mike Miller <mtmiller@octave.org>
parents:
20194
diff
changeset
|
1355 character @nospell{\"@xbackslashchar{}0\"}, it will always be a valid index.\n\ |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1356 @end deftypefn") |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1357 { |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1358 int nargin = args.length (); |
20800
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1359 |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1360 if (nargin < 1 || nargin > 2) |
fb128aafc322
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1361 print_usage (); |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1362 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1363 octave_idx_type n = 0; |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1364 if (nargin == 2) |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1365 n = args(1).idx_type_value (); |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1366 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1367 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1368 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1369 unwind_protect frame; |
10605
1834132fb50b
allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents:
10502
diff
changeset
|
1370 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1371 frame.protect_var (discard_error_messages); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1372 discard_error_messages = true; |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1373 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1374 try |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1375 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1376 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
|
1377 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1378 if (nargin == 2) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1379 retval = idx.extent (n) <= n; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1380 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1381 retval = true; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1382 } |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1383 catch (const octave_execution_exception&) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1384 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
1385 recover_from_exception (); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
1386 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1387 retval = false; |
9487
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1388 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1389 |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1390 return retval; |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1391 } |
2894af292e69
implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents:
9173
diff
changeset
|
1392 |
13094 | 1393 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1394 %!assert (isindex ([1, 2, 3])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1395 %!assert (isindex (1:3)) |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1396 %!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
|
1397 %!assert (isindex ([1, 2, -3]), false) |
13094 | 1398 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1399 %!error isindex () |
19138
ebeb3defae37
codesprint: Add tests to various interpreter utility functions
Mike Miller <mtmiller@ieee.org>
parents:
19128
diff
changeset
|
1400 %!error isindex (1:3, 2, 3) |
13094 | 1401 */ |
1402 | |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1403 octave_value_list |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1404 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1405 const char *fun_name, const octave_value_list& args, |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1406 int nargout) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1407 { |
20973 | 1408 octave_value_list new_args = args; |
1409 octave_value_list retval; | |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1410 int nargin = args.length (); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1411 OCTAVE_LOCAL_BUFFER (bool, iscell, nargin); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1412 OCTAVE_LOCAL_BUFFER (Cell, cells, nargin); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1413 OCTAVE_LOCAL_BUFFER (Cell, rcells, nargout); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1414 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1415 const Cell *ccells = cells; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1416 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1417 octave_idx_type numel = 1; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1418 dim_vector dims (1, 1); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1419 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1420 for (int i = 0; i < nargin; i++) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1421 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1422 octave_value arg = new_args(i); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1423 iscell[i] = arg.is_cell (); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1424 if (iscell[i]) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1425 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1426 cells[i] = arg.cell_value (); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1427 octave_idx_type n = ccells[i].numel (); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1428 if (n == 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1429 { |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1430 iscell[i] = false; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1431 new_args(i) = ccells[i](0); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1432 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1433 else if (numel == 1) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1434 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1435 numel = n; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1436 dims = ccells[i].dims (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1437 } |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1438 else if (dims != ccells[i].dims ()) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
1439 error ("%s: cell arguments must have matching sizes", fun_name); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1440 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1441 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1442 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1443 for (int i = 0; i < nargout; i++) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1444 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
|
1445 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1446 for (octave_idx_type j = 0; j < numel; j++) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1447 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1448 for (int i = 0; i < nargin; i++) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1449 if (iscell[i]) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1450 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
|
1451 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1452 octave_quit (); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1453 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1454 const octave_value_list tmp = fun (new_args, nargout); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1455 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1456 if (tmp.length () < nargout) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
1457 error ("%s: do_simple_cellfun: internal error", fun_name); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
1458 |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
1459 for (int i = 0; i < nargout; i++) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
1460 rcells[i](j) = tmp(i); |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1461 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1462 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1463 retval.resize (nargout); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1464 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1465 for (int i = 0; i < nargout; i++) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1466 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
|
1467 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1468 return retval; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1469 } |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1470 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1471 octave_value |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1472 do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1473 const char *fun_name, const octave_value_list& args) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1474 { |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1475 octave_value retval; |
20973 | 1476 |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1477 const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1); |
20973 | 1478 |
10086
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1479 if (tmp.length () > 0) |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1480 retval = tmp(0); |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1481 |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1482 return retval; |
76df75b10c80
allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents:
10070
diff
changeset
|
1483 } |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1484 |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1485 DEFUN (isstudent, args, , |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1486 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
1487 @deftypefn {} {} isstudent ()\n\ |
19152
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1488 Return true if running in the student edition of @sc{matlab}.\n\ |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1489 \n\ |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1490 @code{isstudent} always returns false in Octave.\n\ |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1491 @seealso{false}\n\ |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1492 @end deftypefn") |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1493 { |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1494 if (args.length () != 0) |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1495 print_usage (); |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1496 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20926
diff
changeset
|
1497 return ovl (false); |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1498 } |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1499 |
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1500 /* |
19152
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1501 %!assert (isstudent (), false) |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1502 |
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19138
diff
changeset
|
1503 %!error isstudent (1) |
19128
4990d5988cf5
new function, isstudent (bug #43155)
John W. Eaton <jwe@octave.org>
parents:
19030
diff
changeset
|
1504 */ |