annotate libinterp/corefcn/utils.cc @ 17787:175b392e91fe

Use GNU style coding conventions for code in libinterp/ * libinterp/corefcn/Cell.h, libinterp/corefcn/__contourc__.cc, libinterp/corefcn/__dispatch__.cc, libinterp/corefcn/__lin_interpn__.cc, libinterp/corefcn/__pchip_deriv__.cc, libinterp/corefcn/__qp__.cc, libinterp/corefcn/balance.cc, libinterp/corefcn/besselj.cc, libinterp/corefcn/betainc.cc, libinterp/corefcn/bitfcns.cc, libinterp/corefcn/bsxfun.cc, libinterp/corefcn/c-file-ptr-stream.cc, libinterp/corefcn/c-file-ptr-stream.h, libinterp/corefcn/cellfun.cc, libinterp/corefcn/colloc.cc, libinterp/corefcn/comment-list.h, libinterp/corefcn/conv2.cc, libinterp/corefcn/daspk.cc, libinterp/corefcn/dasrt.cc, libinterp/corefcn/dassl.cc, libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc, libinterp/corefcn/defaults.in.h, libinterp/corefcn/defun-int.h, libinterp/corefcn/defun.cc, libinterp/corefcn/det.cc, libinterp/corefcn/dirfns.cc, libinterp/corefcn/display.cc, libinterp/corefcn/dlmread.cc, libinterp/corefcn/dot.cc, libinterp/corefcn/dynamic-ld.cc, libinterp/corefcn/dynamic-ld.h, libinterp/corefcn/eig.cc, libinterp/corefcn/ellipj.cc, libinterp/corefcn/error.cc, libinterp/corefcn/error.h, libinterp/corefcn/event-queue.h, libinterp/corefcn/fft.cc, libinterp/corefcn/fft2.cc, libinterp/corefcn/fftn.cc, libinterp/corefcn/file-io.cc, libinterp/corefcn/filter.cc, libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc, libinterp/corefcn/gcd.cc, libinterp/corefcn/getgrent.cc, libinterp/corefcn/getpwent.cc, libinterp/corefcn/getrusage.cc, libinterp/corefcn/givens.cc, libinterp/corefcn/gl-render.cc, libinterp/corefcn/gl2ps-renderer.cc, libinterp/corefcn/gl2ps-renderer.h, libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h, libinterp/corefcn/gripes.cc, libinterp/corefcn/gripes.h, libinterp/corefcn/help.cc, libinterp/corefcn/hess.cc, libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc, libinterp/corefcn/input.h, libinterp/corefcn/inv.cc, libinterp/corefcn/jit-ir.h, libinterp/corefcn/jit-typeinfo.cc, libinterp/corefcn/jit-typeinfo.h, libinterp/corefcn/jit-util.h, libinterp/corefcn/kron.cc, libinterp/corefcn/load-path.cc, libinterp/corefcn/load-path.h, libinterp/corefcn/load-save.cc, libinterp/corefcn/load-save.h, libinterp/corefcn/lookup.cc, libinterp/corefcn/ls-ascii-helper.cc, libinterp/corefcn/ls-hdf5.cc, libinterp/corefcn/ls-hdf5.h, libinterp/corefcn/ls-mat-ascii.cc, libinterp/corefcn/ls-mat-ascii.h, libinterp/corefcn/ls-mat4.cc, libinterp/corefcn/ls-mat5.cc, libinterp/corefcn/ls-mat5.h, libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lsode.cc, libinterp/corefcn/lu.cc, libinterp/corefcn/luinc.cc, libinterp/corefcn/mappers.cc, libinterp/corefcn/matrix_type.cc, libinterp/corefcn/max.cc, libinterp/corefcn/md5sum.cc, libinterp/corefcn/mex.cc, libinterp/corefcn/mexproto.h, libinterp/corefcn/mgorth.cc, libinterp/corefcn/mxarray.in.h, libinterp/corefcn/nproc.cc, libinterp/corefcn/oct-hist.cc, libinterp/corefcn/oct-lvalue.h, libinterp/corefcn/oct-map.cc, libinterp/corefcn/oct-map.h, libinterp/corefcn/oct-obj.h, libinterp/corefcn/oct-prcstrm.h, libinterp/corefcn/oct-stdstrm.h, libinterp/corefcn/oct-stream.cc, libinterp/corefcn/oct-stream.h, libinterp/corefcn/octave-link.cc, libinterp/corefcn/octave-link.h, libinterp/corefcn/pager.cc, libinterp/corefcn/pinv.cc, libinterp/corefcn/pr-output.cc, libinterp/corefcn/procstream.h, libinterp/corefcn/profiler.cc, libinterp/corefcn/pt-jit.cc, libinterp/corefcn/pt-jit.h, libinterp/corefcn/quad.cc, libinterp/corefcn/quadcc.cc, libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/rcond.cc, libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc, libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sighandlers.h, libinterp/corefcn/sparse-xdiv.cc, libinterp/corefcn/sparse-xdiv.h, libinterp/corefcn/sparse-xpow.cc, libinterp/corefcn/sparse.cc, libinterp/corefcn/spparms.cc, libinterp/corefcn/sqrtm.cc, libinterp/corefcn/str2double.cc, libinterp/corefcn/strfind.cc, libinterp/corefcn/strfns.cc, libinterp/corefcn/sub2ind.cc, libinterp/corefcn/svd.cc, libinterp/corefcn/syl.cc, libinterp/corefcn/symtab.cc, libinterp/corefcn/symtab.h, libinterp/corefcn/syscalls.cc, libinterp/corefcn/sysdep.cc, libinterp/corefcn/sysdep.h, libinterp/corefcn/time.cc, libinterp/corefcn/toplev.cc, libinterp/corefcn/toplev.h, libinterp/corefcn/tril.cc, libinterp/corefcn/txt-eng-ft.cc, libinterp/corefcn/txt-eng-ft.h, libinterp/corefcn/txt-eng.h, libinterp/corefcn/typecast.cc, libinterp/corefcn/urlwrite.cc, libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc, libinterp/corefcn/variables.h, libinterp/corefcn/xdiv.cc, libinterp/corefcn/xdiv.h, libinterp/corefcn/xnorm.h, libinterp/corefcn/xpow.cc, libinterp/corefcn/xpow.h, libinterp/corefcn/zfstream.cc, libinterp/corefcn/zfstream.h, libinterp/dldfcn/__delaunayn__.cc, libinterp/dldfcn/__dsearchn__.cc, libinterp/dldfcn/__eigs__.cc, libinterp/dldfcn/__fltk_uigetfile__.cc, libinterp/dldfcn/__glpk__.cc, libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/__init_gnuplot__.cc, libinterp/dldfcn/__magick_read__.cc, libinterp/dldfcn/__voronoi__.cc, libinterp/dldfcn/amd.cc, libinterp/dldfcn/ccolamd.cc, libinterp/dldfcn/chol.cc, libinterp/dldfcn/colamd.cc, libinterp/dldfcn/convhulln.cc, libinterp/dldfcn/dmperm.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc, libinterp/dldfcn/symbfact.cc, libinterp/dldfcn/symrcm.cc, libinterp/dldfcn/tsearch.cc, libinterp/octave-value/ov-base-diag.cc, libinterp/octave-value/ov-base-diag.h, libinterp/octave-value/ov-base-int.cc, libinterp/octave-value/ov-base-int.h, libinterp/octave-value/ov-base-mat.h, libinterp/octave-value/ov-base-scalar.cc, libinterp/octave-value/ov-base-scalar.h, libinterp/octave-value/ov-base-sparse.cc, libinterp/octave-value/ov-base-sparse.h, libinterp/octave-value/ov-base.cc, libinterp/octave-value/ov-base.h, libinterp/octave-value/ov-bool-mat.cc, libinterp/octave-value/ov-bool-mat.h, libinterp/octave-value/ov-bool-sparse.cc, libinterp/octave-value/ov-bool-sparse.h, libinterp/octave-value/ov-bool.cc, libinterp/octave-value/ov-bool.h, libinterp/octave-value/ov-builtin.cc, libinterp/octave-value/ov-builtin.h, libinterp/octave-value/ov-cell.cc, libinterp/octave-value/ov-cell.h, libinterp/octave-value/ov-ch-mat.cc, libinterp/octave-value/ov-ch-mat.h, libinterp/octave-value/ov-class.cc, libinterp/octave-value/ov-class.h, libinterp/octave-value/ov-colon.h, libinterp/octave-value/ov-complex.cc, libinterp/octave-value/ov-complex.h, libinterp/octave-value/ov-cx-diag.cc, libinterp/octave-value/ov-cx-diag.h, libinterp/octave-value/ov-cx-mat.cc, libinterp/octave-value/ov-cx-mat.h, libinterp/octave-value/ov-cx-sparse.cc, libinterp/octave-value/ov-cx-sparse.h, libinterp/octave-value/ov-dld-fcn.h, libinterp/octave-value/ov-fcn-handle.cc, libinterp/octave-value/ov-fcn-handle.h, libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-fcn-inline.h, libinterp/octave-value/ov-fcn.h, libinterp/octave-value/ov-float.cc, libinterp/octave-value/ov-float.h, libinterp/octave-value/ov-flt-complex.cc, libinterp/octave-value/ov-flt-complex.h, libinterp/octave-value/ov-flt-cx-diag.cc, libinterp/octave-value/ov-flt-cx-diag.h, libinterp/octave-value/ov-flt-cx-mat.cc, libinterp/octave-value/ov-flt-cx-mat.h, libinterp/octave-value/ov-flt-re-diag.cc, libinterp/octave-value/ov-flt-re-diag.h, libinterp/octave-value/ov-flt-re-mat.cc, libinterp/octave-value/ov-flt-re-mat.h, libinterp/octave-value/ov-int16.cc, libinterp/octave-value/ov-int32.cc, libinterp/octave-value/ov-int64.cc, libinterp/octave-value/ov-int8.cc, libinterp/octave-value/ov-intx.h, libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-lazy-idx.h, libinterp/octave-value/ov-mex-fcn.cc, libinterp/octave-value/ov-mex-fcn.h, libinterp/octave-value/ov-null-mat.cc, libinterp/octave-value/ov-null-mat.h, libinterp/octave-value/ov-oncleanup.cc, libinterp/octave-value/ov-perm.cc, libinterp/octave-value/ov-perm.h, libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-range.h, libinterp/octave-value/ov-re-diag.cc, libinterp/octave-value/ov-re-diag.h, libinterp/octave-value/ov-re-mat.cc, libinterp/octave-value/ov-re-mat.h, libinterp/octave-value/ov-re-sparse.cc, libinterp/octave-value/ov-re-sparse.h, libinterp/octave-value/ov-scalar.cc, libinterp/octave-value/ov-scalar.h, libinterp/octave-value/ov-str-mat.cc, libinterp/octave-value/ov-str-mat.h, libinterp/octave-value/ov-struct.cc, libinterp/octave-value/ov-struct.h, libinterp/octave-value/ov-type-conv.h, libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov-typeinfo.h, libinterp/octave-value/ov-uint16.cc, libinterp/octave-value/ov-uint32.cc, libinterp/octave-value/ov-uint64.cc, libinterp/octave-value/ov-uint8.cc, libinterp/octave-value/ov-usr-fcn.cc, libinterp/octave-value/ov-usr-fcn.h, libinterp/octave-value/ov.cc, libinterp/octave-value/ov.h, libinterp/octave.cc, libinterp/operators/op-b-bm.cc, libinterp/operators/op-b-sbm.cc, libinterp/operators/op-bm-b.cc, libinterp/operators/op-bm-bm.cc, libinterp/operators/op-cdm-cdm.cc, libinterp/operators/op-chm.cc, libinterp/operators/op-class.cc, libinterp/operators/op-cm-cm.cc, libinterp/operators/op-cm-cs.cc, libinterp/operators/op-cm-s.cc, libinterp/operators/op-cm-scm.cc, libinterp/operators/op-cm-sm.cc, libinterp/operators/op-cs-cm.cc, libinterp/operators/op-cs-cs.cc, libinterp/operators/op-cs-scm.cc, libinterp/operators/op-cs-sm.cc, libinterp/operators/op-dm-dm.cc, libinterp/operators/op-dm-scm.cc, libinterp/operators/op-double-conv.cc, libinterp/operators/op-fcdm-fcdm.cc, libinterp/operators/op-fcm-fcm.cc, libinterp/operators/op-fcm-fcs.cc, libinterp/operators/op-fcm-fm.cc, libinterp/operators/op-fcm-fs.cc, libinterp/operators/op-fcs-fcm.cc, libinterp/operators/op-fcs-fcs.cc, libinterp/operators/op-fcs-fm.cc, libinterp/operators/op-fcs-fs.cc, libinterp/operators/op-fdm-fdm.cc, libinterp/operators/op-float-conv.cc, libinterp/operators/op-fm-fcm.cc, libinterp/operators/op-fm-fcs.cc, libinterp/operators/op-fm-fm.cc, libinterp/operators/op-fm-fs.cc, libinterp/operators/op-fs-fcm.cc, libinterp/operators/op-fs-fcs.cc, libinterp/operators/op-fs-fm.cc, libinterp/operators/op-fs-fs.cc, libinterp/operators/op-m-cm.cc, libinterp/operators/op-m-cs.cc, libinterp/operators/op-m-m.cc, libinterp/operators/op-m-s.cc, libinterp/operators/op-m-scm.cc, libinterp/operators/op-m-sm.cc, libinterp/operators/op-pm-scm.cc, libinterp/operators/op-range.cc, libinterp/operators/op-s-cm.cc, libinterp/operators/op-s-cs.cc, libinterp/operators/op-s-scm.cc, libinterp/operators/op-sbm-b.cc, libinterp/operators/op-sbm-bm.cc, libinterp/operators/op-sbm-sbm.cc, libinterp/operators/op-scm-cm.cc, libinterp/operators/op-scm-cs.cc, libinterp/operators/op-scm-m.cc, libinterp/operators/op-scm-s.cc, libinterp/operators/op-scm-scm.cc, libinterp/operators/op-scm-sm.cc, libinterp/operators/op-sm-cm.cc, libinterp/operators/op-sm-m.cc, libinterp/operators/op-sm-s.cc, libinterp/operators/op-sm-scm.cc, libinterp/operators/op-sm-sm.cc, libinterp/operators/op-str-m.cc, libinterp/operators/op-str-s.cc, libinterp/operators/op-str-str.cc, libinterp/operators/ops.h, libinterp/parse-tree/lex.h, libinterp/parse-tree/parse.h, libinterp/parse-tree/pt-arg-list.cc, libinterp/parse-tree/pt-arg-list.h, libinterp/parse-tree/pt-assign.cc, libinterp/parse-tree/pt-assign.h, libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-binop.h, libinterp/parse-tree/pt-bp.h, libinterp/parse-tree/pt-cbinop.cc, libinterp/parse-tree/pt-check.cc, libinterp/parse-tree/pt-colon.cc, libinterp/parse-tree/pt-colon.h, libinterp/parse-tree/pt-const.cc, libinterp/parse-tree/pt-decl.cc, libinterp/parse-tree/pt-decl.h, libinterp/parse-tree/pt-eval.cc, libinterp/parse-tree/pt-except.h, libinterp/parse-tree/pt-exp.h, libinterp/parse-tree/pt-fcn-handle.cc, libinterp/parse-tree/pt-id.cc, libinterp/parse-tree/pt-id.h, libinterp/parse-tree/pt-idx.cc, libinterp/parse-tree/pt-idx.h, libinterp/parse-tree/pt-loop.h, libinterp/parse-tree/pt-mat.cc, libinterp/parse-tree/pt-misc.cc, libinterp/parse-tree/pt-misc.h, libinterp/parse-tree/pt-pr-code.cc, libinterp/parse-tree/pt-select.h, libinterp/parse-tree/pt-stmt.h, libinterp/parse-tree/token.h, libinterp/version.cc: Use GNU style coding conventions for code in libinterp/
author Rik <rik@octave.org>
date Mon, 28 Oct 2013 19:51:46 -0700
parents d63878346099
children f1b59ef34eda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17290
diff changeset
3 Copyright (C) 1993-2013 John W. Eaton
11012
30b9b0a507f1 add missing copyright
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
4 Copyright (C) 2010 VZLU Prague
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
11 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6694
diff changeset
20 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
23
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 224
diff changeset
24 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1155
diff changeset
25 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
27
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
28 #include <cerrno>
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1345
diff changeset
29 #include <cstring>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
30
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
31 #include <fstream>
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
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
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
34 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
35
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36 #include <sys/types.h>
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37 #include <unistd.h>
367
04d377033730 [project @ 1994-02-16 08:04:52 by jwe]
jwe
parents: 341
diff changeset
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
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
41 #include "quit.h"
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
42
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
43 #include "dir-ops.h"
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
44 #include "file-ops.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
45 #include "file-stat.h"
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
46 #include "lo-mappers.h"
11006
aca961a3f387 provide gethostname function
John W. Eaton <jwe@octave.org>
parents: 10987
diff changeset
47 #include "lo-utils.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
48 #include "oct-cmplx.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2909
diff changeset
49 #include "oct-env.h"
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 3014
diff changeset
50 #include "pathsearch.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
51 #include "str-vec.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1618
diff changeset
52
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
53 #include "Cell.h"
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2442
diff changeset
54 #include <defaults.h>
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
55 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
56 #include "dirfns.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
57 #include "error.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
58 #include "gripes.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
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
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
61 #include "load-path.h"
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
62 #include "oct-errno.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
63 #include "oct-hist.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
64 #include "oct-obj.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
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
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
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
68 #include "sysdep.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
69 #include "toplev.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
70 #include "unwind-prot.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
71 #include "utils.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
72 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
73
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
74 // Return TRUE if S is a valid identifier.
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
75
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
76 bool
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
77 valid_identifier (const char *s)
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
78 {
5290
41273fff034d [project @ 2005-04-21 14:46:50 by jwe]
jwe
parents: 5275
diff changeset
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
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
81
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
82 while (*++s != '\0')
5290
41273fff034d [project @ 2005-04-21 14:46:50 by jwe]
jwe
parents: 5275
diff changeset
83 if (! (isalnum (*s) || *s == '_' || *s == '$'))
4143
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
84 return false;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
85
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
86 return true;
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
87 }
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
88
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
89 bool
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
90 valid_identifier (const std::string& s)
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
91 {
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
92 return valid_identifier (s.c_str ());
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
93 }
62afb31c1f85 [project @ 2002-11-01 17:27:38 by jwe]
jwe
parents: 4135
diff changeset
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\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4783
diff changeset
97 @deftypefn {Built-in Function} {} 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
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
100 @end deftypefn")
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
101 {
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
102 octave_value retval = false;
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
103
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
104 int nargin = args.length ();
4264
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
105
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
106 if (nargin != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
107 print_usage ();
15435
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
108 else if (args(0).is_string ())
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
109 {
13ffb3130b2f Fix isvarname to return false if input is not a string (bug #37389)
Rik <rik@octave.org>
parents: 15215
diff changeset
110 std::string varname = args(0).string_value ();
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
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
113
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
114 return retval;
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
115 }
4e2d2516da22 [project @ 2003-01-03 05:30:34 by jwe]
jwe
parents: 4254
diff changeset
116
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
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)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
124
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
125 %!error isvarname ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
126 %!error isvarname ("foo", "bar");
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
127 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
128
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
129 // Return TRUE if F and G are both names for the same file.
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
130
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
131 bool
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
132 same_file (const std::string& f, const std::string& g)
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
133 {
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6379
diff changeset
134 return same_file_internal (f, g);
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
135 }
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6144
diff changeset
136
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
137 int
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
138 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
139 int case_sens)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
140 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
141 int stdlen = std.length ();
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
142 int slen = s.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
143
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
144 return (slen <= stdlen
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
145 && slen >= min_match_len
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
146 && (case_sens
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
147 ? (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
148 : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0)));
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
149 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
150
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
151 // Ugh.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
152
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
153 int
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
154 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
155 const std::string& s,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
156 int min_toks_to_match, int max_toks)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
157 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
158 int status = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
159 int tok_count = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
160 int toks_matched = 0;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
161
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
162 if (s.empty () || max_toks < 1)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
163 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
164
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
165 char *kw = strsave (s.c_str ());
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
166
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
167 char *t = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
168 while (*t != '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
169 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
170 if (*t == '\t')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
171 *t = ' ';
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
172 t++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
173 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
174
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
175 char *beg = kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
176 while (*beg == ' ')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
177 beg++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
178
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
179 if (*beg == '\0')
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
180 return status;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
181
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
182
3072
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
183 const char **to_match = new const char * [max_toks + 1];
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
184 const char * const *s1 = std;
ca9677cdb62e [project @ 1997-07-15 02:45:42 by jwe]
jwe
parents: 3065
diff changeset
185 const char **s2 = to_match;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
186
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
187 if (! s1 || ! s2)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
188 goto done;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
189
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
190 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
191 char *end;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
192 while ((end = strchr (beg, ' ')) != 0)
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
193 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
194 *end = '\0';
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
195 beg = end + 1;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
196
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
197 while (*beg == ' ')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
198 beg++;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
199
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
200 if (*beg == '\0')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
201 break;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
202
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
203 tok_count++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
204 if (tok_count >= max_toks)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
205 goto done;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
206
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
207 s2[tok_count] = beg;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
208 }
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
209 s2[tok_count+1] = 0;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
210
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
211 s2 = to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
212
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
213 for (;;)
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
214 {
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
215 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
216 goto done;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
217
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
218 toks_matched++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
219
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
220 s1++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
221 s2++;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
222
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
223 if (! *s2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
224 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
225 status = (toks_matched >= min_toks_to_match);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
226 goto done;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
227 }
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
228
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
229 if (! *s1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
230 goto done;
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
231 }
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
232
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
233 done:
287
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
234
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
235 delete [] kw;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
236 delete [] to_match;
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
237
6027a905fc06 [project @ 1994-01-13 01:41:00 by jwe]
jwe
parents: 278
diff changeset
238 return status;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
239 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
240
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
241 // Return non-zero if either NR or NC is zero. Return -1 if this
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
242 // should be considered fatal; return 1 if this is ok.
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
243
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
244 int
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
245 empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc)
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
246 {
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
247 return (nr == 0 || nc == 0);
2234
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
248 }
a174011c96f2 [project @ 1996-05-17 17:51:20 by jwe]
jwe
parents: 2233
diff changeset
249
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
250 // See if the given file is in the path.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
251
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
252 std::string
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
253 search_path_for_file (const std::string& path, const string_vector& names)
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
254 {
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3105
diff changeset
255 dir_path p (path);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
256
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
257 return octave_env::make_absolute (p.find_first_of (names));
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
258 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
259
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
260 // Find all locations of the given file in the path.
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
261
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
262 string_vector
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
263 search_path_for_all_files (const std::string& path, const string_vector& names)
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
264 {
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
265 dir_path p (path);
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
266
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
267 string_vector sv = p.find_all_first_of (names);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
268
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
269 octave_idx_type len = sv.length ();
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
270
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
271 for (octave_idx_type i = 0; i < len; i++)
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
272 sv[i] = octave_env::make_absolute (sv[i]);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
273
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
274 return sv;
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
275 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
276
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
277 static string_vector
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
278 make_absolute (const string_vector& sv)
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
279 {
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
280 octave_idx_type len = sv.length ();
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
281
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
282 string_vector retval (len);
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
283
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
284 for (octave_idx_type i = 0; i < len; i++)
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
285 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
286
6379
41c1deed5613 [project @ 2007-03-02 18:43:20 by jwe]
jwe
parents: 6323
diff changeset
287 return retval;
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
288 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
289
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
290 DEFUN (file_in_loadpath, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
291 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10646
diff changeset
292 @deftypefn {Built-in Function} {} file_in_loadpath (@var{file})\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
293 @deftypefnx {Built-in Function} {} file_in_loadpath (@var{file}, \"all\")\n\
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
294 \n\
5448
ebe5d7d15522 [project @ 2005-09-14 18:55:04 by jwe]
jwe
parents: 5307
diff changeset
295 Return the absolute name of @var{file} if it can be found in\n\
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5794
diff changeset
296 the list of directories specified by @code{path}.\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
297 If no file is found, return an empty character string.\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
298 \n\
5448
ebe5d7d15522 [project @ 2005-09-14 18:55:04 by jwe]
jwe
parents: 5307
diff changeset
299 If the first argument is a cell array of strings, search each\n\
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
300 directory of the loadpath for element of the cell array and return\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
301 the first that matches.\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
302 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16892
diff changeset
303 If the second optional argument @qcode{\"all\"} is supplied, return\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
304 a cell array containing the list of all files that have the same\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
305 name in the path. If no files are found, return an empty cell array.\n\
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5794
diff changeset
306 @seealso{file_in_path, path}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5612
diff changeset
307 @end deftypefn")
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
308 {
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
309 octave_value retval;
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
310
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
311 int nargin = args.length ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
312
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
313 if (nargin == 1 || nargin == 2)
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
314 {
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
315 string_vector names = args(0).all_strings ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
316
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
317 if (! error_state && names.length () > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
318 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
319 if (nargin == 1)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
320 retval =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
321 octave_env::make_absolute (load_path::find_first_of (names));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
322 else if (nargin == 2)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
323 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
324 std::string opt = args(1).string_value ();
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
325
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
326 if (! error_state && opt == "all")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
327 retval = Cell (make_absolute
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
328 (load_path::find_all_first_of (names)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
329 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
330 error ("file_in_loadpath: invalid option");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
331 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
332 }
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
333 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
334 error ("file_in_loadpath: FILE argument must be a string");
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
335 }
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
336 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
337 print_usage ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
338
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
339 return retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
340 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3174
diff changeset
341
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
342 /*
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
343 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
344 %! f = file_in_loadpath ("plot.m");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
345 %! assert (ischar (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
346 %! assert (! isempty (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
347
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
348 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
349 %! f = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
350 %! assert (f, "");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
351
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
352 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
353 %! lst = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$", "all");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
354 %! assert (lst, {});
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
355
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
356 %!error file_in_loadpath ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
357 %!error file_in_loadpath ("foo", "bar", 1)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
358 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
359
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
360 DEFUN (file_in_path, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
361 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10646
diff changeset
362 @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
363 @deftypefnx {Built-in Function} {} file_in_path (@var{path}, @var{file}, \"all\")\n\
5448
ebe5d7d15522 [project @ 2005-09-14 18:55:04 by jwe]
jwe
parents: 5307
diff changeset
364 Return the absolute name of @var{file} if it can be found in\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
365 @var{path}. The value of @var{path} should be a colon-separated list of\n\
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5794
diff changeset
366 directories in the format described for @code{path}. If no file\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10646
diff changeset
367 is found, return an empty character string. For example:\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
368 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
369 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
370 @group\n\
5456
f315234695b1 [project @ 2005-09-19 19:02:41 by jwe]
jwe
parents: 5448
diff changeset
371 file_in_path (EXEC_PATH, \"sh\")\n\
f315234695b1 [project @ 2005-09-19 19:02:41 by jwe]
jwe
parents: 5448
diff changeset
372 @result{} \"/bin/sh\"\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
373 @end group\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
374 @end example\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
375 \n\
5448
ebe5d7d15522 [project @ 2005-09-14 18:55:04 by jwe]
jwe
parents: 5307
diff changeset
376 If the second argument is a cell array of strings, search each\n\
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
377 directory of the path for element of the cell array and return\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
378 the first that matches.\n\
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
379 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16892
diff changeset
380 If the third optional argument @qcode{\"all\"} is supplied, return\n\
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
381 a cell array containing the list of all files that have the same\n\
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
382 name in the path. If no files are found, return an empty cell array.\n\
4249
8a1ef8fe4036 [project @ 2002-12-31 04:42:32 by jwe]
jwe
parents: 4243
diff changeset
383 @seealso{file_in_loadpath}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3225
diff changeset
384 @end deftypefn")
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
385 {
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4212
diff changeset
386 octave_value retval;
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
387
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
388 int nargin = args.length ();
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
389
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
390 if (nargin == 2 || nargin == 3)
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
391 {
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
392 std::string path = args(0).string_value ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
393
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
394 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
395 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
396 string_vector names = args(1).all_strings ();
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
397
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
398 if (! error_state && names.length () > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
399 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
400 if (nargin == 2)
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
401 retval = search_path_for_file (path, names);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
402 else if (nargin == 3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
403 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
404 std::string opt = args(2).string_value ();
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4233
diff changeset
405
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
406 if (! error_state && opt == "all")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
407 retval = Cell (make_absolute
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
408 (search_path_for_all_files (path, names)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
409 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
410 error ("file_in_path: invalid option");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
411 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
412 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
413 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
414 error ("file_in_path: all arguments must be strings");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
415 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
416 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
417 error ("file_in_path: PATH must be a string");
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
418 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
419 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
420 print_usage ();
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
421
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
422 return retval;
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
423 }
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
424
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
425 /*
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
426 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
427 %! f = file_in_path (path (), "plot.m");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
428 %! assert (ischar (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
429 %! assert (! isempty (f));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
430
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
431 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
432 %! f = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
433 %! assert (f, "");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
434
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
435 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
436 %! lst = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$", "all");
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
437 %! assert (lst, {});
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
438
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
439 %!error file_in_path ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
440 %!error file_in_path ("foo")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
441 %!error file_in_path ("foo", "bar", "baz", 1)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
442 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
443
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
444 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
445 file_in_path (const std::string& name, const std::string& suffix)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
446 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
447 std::string nm = name;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
448
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
449 if (! suffix.empty ())
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
450 nm.append (suffix);
686
0faebdd7df57 [project @ 1994-09-09 21:09:24 by jwe]
jwe
parents: 679
diff changeset
451
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
452 return octave_env::make_absolute (load_path::find_file (nm));
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
453 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
454
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
455 // See if there is an function file in the path. If so, return the
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
456 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
457
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
458 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
459 fcn_file_in_path (const std::string& name)
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
460 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
461 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
462
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
463 int len = name.length ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
464
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
465 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
466 {
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
467 if (octave_env::absolute_pathname (name))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
468 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
469 file_stat fs (name);
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
470
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
471 if (fs.exists ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
472 retval = name;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
473 }
15020
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
474 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
475 retval = load_path::find_fcn_file (name.substr (0, len-2));
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
476 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
477 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
478 std::string fname = name;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
479 size_t pos = name.find_first_of (Vfilemarker);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
480 if (pos != std::string::npos)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
481 fname = name.substr (0, pos);
7818
5640a70cbab1 Add Ffilemarker and fix for 'dbstep in'
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
482
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
483 retval = load_path::find_fcn_file (fname);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
484 }
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
485 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
486
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
487 return retval;
526
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
488 }
a01a9db8ab69 [project @ 1994-07-20 18:46:24 by jwe]
jwe
parents: 478
diff changeset
489
8041
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
490 // See if there is a directory called "name" in the path and if it
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
491 // contains a Contents.m file return the full path to this file.
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
492
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
493 std::string
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
494 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
495 {
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
496 std::string retval;
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
497
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
498 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
499 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
500 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
501 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
502
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
503 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
504
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
505 if (fs.exists ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
506 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
507 }
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
508
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
509 return retval;
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
510 }
a14bdf90be55 Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents: 8021
diff changeset
511
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
512 // See if there is a .oct file in the path. If so, return the
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
513 // full path to the file.
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
514
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
515 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
516 oct_file_in_path (const std::string& name)
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
517 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
518 std::string retval;
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
519
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
520 int len = name.length ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
521
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
522 if (len > 0)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
523 {
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
524 if (octave_env::absolute_pathname (name))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
525 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
526 file_stat fs (name);
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
527
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
528 if (fs.exists ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
529 retval = name;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
530 }
15020
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
531 else if (len > 4 && name[len - 4] == '.' && name[len - 3] == 'o'
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
532 && name[len - 2] == 'c' && name[len - 1] == 't')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
533 retval = load_path::find_oct_file (name.substr (0, len-4));
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
534 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
535 retval = load_path::find_oct_file (name);
908
efb4cbdaac26 [project @ 1994-11-09 23:03:37 by jwe]
jwe
parents: 826
diff changeset
536 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
537
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
538 return retval;
572
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
539 }
94fd73d1a0bc [project @ 1994-07-28 05:35:47 by jwe]
jwe
parents: 571
diff changeset
540
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
541 // See if there is a .mex file in the path. If so, return the
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
542 // full path to the file.
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
543
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
544 std::string
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
545 mex_file_in_path (const std::string& name)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
546 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
547 std::string retval;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
548
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
549 int len = name.length ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
550
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
551 if (len > 0)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
552 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
553 if (octave_env::absolute_pathname (name))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
554 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
555 file_stat fs (name);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
556
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
557 if (fs.exists ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
558 retval = name;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
559 }
15020
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
560 else if (len > 4 && name[len - 4] == '.' && name[len - 3] == 'm'
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 14819
diff changeset
561 && name[len - 2] == 'e' && name[len - 1] == 'x')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
562 retval = load_path::find_mex_file (name.substr (0, len-4));
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
563 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
564 retval = load_path::find_mex_file (name);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
565 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
566
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
567 return retval;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
568 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5832
diff changeset
569
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
570 // Replace backslash escapes in a string with the real values.
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
571
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
572 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
573 do_string_escapes (const std::string& s)
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
574 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
575 std::string retval;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
576
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
577 size_t i = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
578 size_t j = 0;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
579 size_t len = s.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
580
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
581 retval.resize (len);
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
582
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
583 while (j < len)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
584 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
585 if (s[j] == '\\' && j+1 < len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
586 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
587 switch (s[++j])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
588 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
589 case '0':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
590 retval[i] = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
591 break;
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
592
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
593 case 'a':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
594 retval[i] = '\a';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
595 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
596
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
597 case 'b': // backspace
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
598 retval[i] = '\b';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
599 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
600
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
601 case 'f': // formfeed
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
602 retval[i] = '\f';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
603 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
604
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
605 case 'n': // newline
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
606 retval[i] = '\n';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
607 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
608
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
609 case 'r': // carriage return
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
610 retval[i] = '\r';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
611 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
612
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
613 case 't': // horizontal tab
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
614 retval[i] = '\t';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
615 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
616
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
617 case 'v': // vertical tab
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
618 retval[i] = '\v';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
619 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
620
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
621 case '\\': // backslash
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
622 retval[i] = '\\';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
623 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
624
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
625 case '\'': // quote
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
626 retval[i] = '\'';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
627 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
628
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
629 case '"': // double quote
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
630 retval[i] = '"';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
631 break;
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
632
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
633 default:
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
634 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
635 converting to '%c'", s[j], s[j]);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
636 retval[i] = s[j];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
637 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
638 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
639 }
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
640 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
641 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
642 retval[i] = s[j];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
643 }
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
644
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
645 i++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
646 j++;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
647 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
648
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3103
diff changeset
649 retval.resize (i);
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
650
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
651 return retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
652 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
653
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
654 DEFUN (do_string_escapes, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
655 "-*- texinfo -*-\n\
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
656 @deftypefn {Built-in Function} {} do_string_escapes (@var{string})\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
657 Convert special characters in @var{string} to their escaped forms.\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3419
diff changeset
658 @end deftypefn")
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
659 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
660 octave_value retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
661
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
662 int nargin = args.length ();
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
663
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
664 if (nargin == 1)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
665 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
666 if (args(0).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
667 retval = do_string_escapes (args(0).string_value ());
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
668 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
669 error ("do_string_escapes: STRING argument must be of type string");
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
670 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
671 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
672 print_usage ();
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
673
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
674 return retval;
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
675 }
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
676
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
677 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
678 %!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
679 %!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
680 %!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
681 %!assert ("foo\nbar", ["foo", char(10), "bar"])
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
682
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
683 %!assert (do_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
684 %!assert (do_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
685 %!assert (do_string_escapes ("\\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
686 %! 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
687 %!assert ("\a\b\f\n\r\t\v", char ([7, 8, 12, 10, 13, 9, 11]))
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
688
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
689 %!error do_string_escapes ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
690 %!error do_string_escapes ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
691 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
692
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
693 const char *
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
694 undo_string_escape (char c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
695 {
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
696 if (! c)
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
697 return "";
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
698
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
699 switch (c)
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
700 {
3893
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
701 case '\0':
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
702 return "\\0";
abd8659eea11 [project @ 2002-04-09 21:36:31 by jwe]
jwe
parents: 3879
diff changeset
703
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
704 case '\a':
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
705 return "\\a";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
706
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
707 case '\b': // backspace
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
708 return "\\b";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
709
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
710 case '\f': // formfeed
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
711 return "\\f";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
712
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
713 case '\n': // newline
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
714 return "\\n";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
715
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
716 case '\r': // carriage return
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
717 return "\\r";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
718
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
719 case '\t': // horizontal tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
720 return "\\t";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
721
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
722 case '\v': // vertical tab
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
723 return "\\v";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
724
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
725 case '\\': // backslash
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
726 return "\\\\";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
727
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
728 case '"': // double quote
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
729 return "\\\"";
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
730
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
731 default:
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
732 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
733 static char retval[2];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
734 retval[0] = c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
735 retval[1] = '\0';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
736 return retval;
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
737 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
738 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
739 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
740
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
741 std::string
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
742 undo_string_escapes (const std::string& s)
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
743 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
744 std::string retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
745
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
746 for (size_t i = 0; i < s.length (); i++)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
747 retval.append (undo_string_escape (s[i]));
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
748
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
749 return retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
750 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
751
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
752 DEFUN (undo_string_escapes, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
753 "-*- texinfo -*-\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
754 @deftypefn {Built-in Function} {} undo_string_escapes (@var{s})\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
755 Convert special characters in strings back to their escaped forms. For\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
756 example, the expression\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
757 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
758 @example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
759 bell = \"\\a\";\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
760 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
761 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
762 @noindent\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
763 assigns the value of the alert character (control-g, ASCII code 7) to\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
764 the string variable @code{bell}. If this string is printed, the\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
765 system will ring the terminal bell (if it is possible). This is\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
766 normally the desired outcome. However, sometimes it is useful to be\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
767 able to print the original representation of the string, with the\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
768 special characters replaced by their escape sequences. For example,\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
769 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
770 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
771 @group\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
772 octave:13> undo_string_escapes (bell)\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
773 ans = \\a\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8929
diff changeset
774 @end group\n\
3361
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
775 @end example\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
776 \n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
777 @noindent\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
778 replaces the unprintable alert character with its printable\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
779 representation.\n\
4f40efa995c1 [project @ 1999-11-19 21:19:37 by jwe]
jwe
parents: 3354
diff changeset
780 @end deftypefn")
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
781 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2010
diff changeset
782 octave_value retval;
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
783
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
784 int nargin = args.length ();
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
785
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
786 if (nargin == 1)
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
787 {
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
788 if (args(0).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
789 retval = undo_string_escapes (args(0).string_value ());
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
790 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
791 error ("undo_string_escapes: S argument must be a string");
3103
98d862e12945 [project @ 1997-11-18 10:46:30 by jwe]
jwe
parents: 3072
diff changeset
792 }
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
793 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
794 print_usage ();
801
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
795
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
796 return retval;
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
797 }
cbc37d8d0fdf [project @ 1994-10-13 17:03:23 by jwe]
jwe
parents: 738
diff changeset
798
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
799 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
800 %!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
801 %!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
802 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
803
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
804 %!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
805 %!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
806 %!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
807 %! "\\a\\b\\f\\n\\r\\t\\v")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
808
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
809 %!error undo_string_escapes ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
810 %!error undo_string_escapes ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
811 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
812
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
813 DEFUN (is_absolute_filename, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
814 "-*- texinfo -*-\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
815 @deftypefn {Built-in Function} {} is_absolute_filename (@var{file})\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
816 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
817 @seealso{is_rooted_relative_filename, make_absolute_filename, isdir}\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
818 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
819 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
820 octave_value retval = false;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
821
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
822 if (args.length () == 1)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
823 retval = (args(0).is_string ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
824 && octave_env::absolute_pathname (args(0).string_value ()));
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
825 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
826 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
827
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
828 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
829 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
830
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
831 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
832 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
833
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
834 %!error is_absolute_filename ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
835 %!error is_absolute_filename ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
836 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
837
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
838 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
839 "-*- texinfo -*-\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
840 @deftypefn {Built-in Function} {} is_rooted_relative_filename (@var{file})\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
841 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
842 @seealso{is_absolute_filename, make_absolute_filename, isdir}\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
843 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
844 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
845 octave_value retval = false;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
846
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
847 if (args.length () == 1)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
848 retval = (args(0).is_string ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
849 && octave_env::rooted_relative_pathname (args(0).string_value ()));
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
850 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
851 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
852
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
853 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
854 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
855
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
856 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
857 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
858
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
859 %!error is_rooted_relative_filename ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
860 %!error is_rooted_relative_filename ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
861 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
862
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
863 DEFUN (make_absolute_filename, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
864 "-*- texinfo -*-\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
865 @deftypefn {Built-in Function} {} 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
866 Return the full name of @var{file} beginning from the root of the file\n\
67b6b47a22f6 doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
867 system. No check is done for the existence of @var{file}.\n\
67b6b47a22f6 doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
868 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isdir}\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
869 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
870 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
871 octave_value retval = std::string ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
872
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
873 if (args.length () == 1)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
874 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
875 std::string nm = args(0).string_value ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
876
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
877 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
878 retval = octave_env::make_absolute (nm);
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
879 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
880 error ("make_absolute_filename: FILE argument must be a file name");
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
881 }
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
882 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
883 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
884
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
885 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
886 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
887
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
888 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
889 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
890
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
891 %!error make_absolute_filename ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
892 %!error make_absolute_filename ("foo", "bar")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
893 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
894
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
895 DEFUN (find_dir_in_path, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
896 "-*- texinfo -*-\n\
12668
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 12573
diff changeset
897 @deftypefn {Built-in Function} {} find_dir_in_path (@var{dir})\n\
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 12573
diff changeset
898 @deftypefnx {Built-in Function} {} find_dir_in_path (@var{dir}, \"all\")\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
899 Return the full name of the path element matching @var{dir}. The\n\
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
900 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
901 @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
902 @nospell{@qcode{\"/some/dir/foo/bar\"}}, but not\n\
17be601bc783 doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents: 17281
diff changeset
903 @nospell{@qcode{\"/some/dir/foo/bar/baz\"}}\n\
17be601bc783 doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents: 17281
diff changeset
904 @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
905 \n\
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
906 The second argument is optional. If it is supplied, return a cell array\n\
12668
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 12573
diff changeset
907 containing all name matches rather than just the first.\n\
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
908 @end deftypefn")
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
909 {
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
910 octave_value retval = std::string ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
911
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
912 int nargin = args.length ();
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
913
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
914 std::string dir;
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
915
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
916 if (nargin == 1 || nargin == 2)
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
917 {
9806
8e345f2fe4d6 improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
918 dir = args(0).string_value ();
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
919
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
920 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
921 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
922 if (nargin == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
923 retval = load_path::find_dir (dir);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
924 else if (nargin == 2)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
925 retval = Cell (load_path::find_matching_dirs (dir));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
926 }
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
927 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
928 error ("find_dir_in_path: DIR must be a directory name");
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
929 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
930 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
931 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
932
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
933 return retval;
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
934 }
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents: 8041
diff changeset
935
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
936 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
937 ## FIXME: We need system-dependent tests here.
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
938
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
939 %!error find_dir_in_path ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
940 %!error find_dir_in_path ("foo", "bar", 1)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
941 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
942
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
943 DEFUNX ("errno", Ferrno, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
944 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10646
diff changeset
945 @deftypefn {Built-in Function} {@var{err} =} errno ()\n\
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
946 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{val})\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
947 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{name})\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
948 Return the current value of the system-dependent variable errno,\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
949 set its value to @var{val} and return the previous value, or return\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
950 the named error code given @var{name} as a character string, or -1\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
951 if @var{name} is not found.\n\
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
952 @end deftypefn")
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
953 {
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
954 octave_value retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
955
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
956 int nargin = args.length ();
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
957
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
958 if (nargin == 1)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
959 {
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
960 if (args(0).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
961 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
962 std::string nm = args(0).string_value ();
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
963
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
964 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
965 retval = octave_errno::lookup (nm);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
966 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
967 error ("errno: expecting character string argument");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
968 }
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
969 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
970 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
971 int val = args(0).int_value ();
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
972
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
973 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
974 retval = octave_errno::set (val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
975 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
976 error ("errno: expecting integer argument");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
977 }
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
978 }
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
979 else if (nargin == 0)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
980 retval = octave_errno::get ();
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
981 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
982 print_usage ();
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
983
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
984 return retval;
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
985 }
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
986
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
987 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
988 %!assert (isnumeric (errno ()))
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
989
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
990 %!test
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
991 %! lst = errno_list ();
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
992 %! fns = fieldnames (lst);
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
993 %! oldval = errno (fns{1});
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
994 %! assert (isnumeric (oldval));
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
995 %! errno (oldval);
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
996 %! newval = errno ();
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
997 %! assert (oldval, newval);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
998
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
999 %!error errno ("foo", 1)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1000 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1001
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1002 DEFUN (errno_list, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1003 "-*- texinfo -*-\n\
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1004 @deftypefn {Built-in Function} {} errno_list ()\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1005 Return a structure containing the system-dependent errno values.\n\
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1006 @end deftypefn")
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1007 {
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1008 octave_value retval;
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1009
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1010 if (args.length () == 0)
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1011 retval = octave_errno::list ();
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1012 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
1013 print_usage ();
5465
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1014
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1015 return retval;
d6163c0effd5 [project @ 2005-09-23 15:42:48 by jwe]
jwe
parents: 5458
diff changeset
1016 }
3716
08fe5f74c7d4 [project @ 2000-09-07 04:59:03 by jwe]
jwe
parents: 3622
diff changeset
1017
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1018 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1019 %!assert (isstruct (errno_list ()))
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1020
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1021 %!error errno_list ("foo")
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1022 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1023
2285
3e0a2661f0a0 [project @ 1996-05-29 02:29:25 by jwe]
jwe
parents: 2234
diff changeset
1024 static void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1025 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor)
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1026 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1027 if (nr < 0 || nc < 0)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1028 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1029 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
1030 "%s: converting negative dimension to zero", warnfor);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1031
4457
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4351
diff changeset
1032 nr = (nr < 0) ? 0 : nr;
d7d9ca19960a [project @ 2003-07-11 03:05:38 by jwe]
jwe
parents: 4351
diff changeset
1033 nc = (nc < 0) ? 0 : nc;
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1034 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1035 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1036
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1037 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4485
diff changeset
1038 check_dimensions (dim_vector& dim, const char *warnfor)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1039 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1040 bool neg = false;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1041
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1042 for (int i = 0; i < dim.length (); i++)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1043 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1044 if (dim(i) < 0)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1045 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1046 dim(i) = 0;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1047 neg = true;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1048 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1049 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1050
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1051 if (neg)
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1052 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
1053 "%s: converting negative dimension to zero", warnfor);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1054 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1055
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1056
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1057 void
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1058 get_dimensions (const octave_value& a, const char *warn_for,
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4485
diff changeset
1059 dim_vector& dim)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1060 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1061 if (a.is_scalar_type ())
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1062 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1063 dim.resize (2);
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
1064 dim(0) = a.int_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1065 dim(1) = dim(0);
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1066 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1067 else
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1068 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1069 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1070 octave_idx_type nc = a.columns ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1071
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1072 if (nr == 1 || nc == 1)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1073 {
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1074 Array<double> v = a.vector_value ();
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1075
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1076 if (error_state)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1077 return;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1078
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1079 octave_idx_type n = v.length ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1080 dim.resize (n);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1081 for (octave_idx_type i = 0; i < n; i++)
4783
55975a3073be [project @ 2004-02-17 17:16:37 by jwe]
jwe
parents: 4732
diff changeset
1082 dim(i) = static_cast<int> (fix (v(i)));
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1083 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1084 else
5257
d957f0ef5aa3 [project @ 2005-03-29 19:08:34 by jwe]
jwe
parents: 5040
diff changeset
1085 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1086 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1087
5258
60999c752276 [project @ 2005-03-29 19:35:34 by jwe]
jwe
parents: 5257
diff changeset
1088 if (! error_state)
60999c752276 [project @ 2005-03-29 19:35:34 by jwe]
jwe
parents: 5257
diff changeset
1089 check_dimensions (dim, warn_for); // May set error_state.
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1090 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1091
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1092
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4478
diff changeset
1093 void
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1094 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
1095 octave_idx_type& nr, octave_idx_type& nc)
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1096 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1097 if (a.is_scalar_type ())
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1098 {
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
1099 nr = nc = a.int_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1100 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1101 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1102 {
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1103 nr = a.rows ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1104 nc = a.columns ();
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1105
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1106 if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1107 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1108 Array<double> v = a.vector_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1109
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1110 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1111 return;
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1112
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1113 nr = static_cast<octave_idx_type> (fix (v (0)));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1114 nc = static_cast<octave_idx_type> (fix (v (1)));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1115 }
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1116 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1117 error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1118 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1119
5258
60999c752276 [project @ 2005-03-29 19:35:34 by jwe]
jwe
parents: 5257
diff changeset
1120 if (! error_state)
60999c752276 [project @ 2005-03-29 19:35:34 by jwe]
jwe
parents: 5257
diff changeset
1121 check_dimensions (nr, nc, warn_for); // May set error_state.
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1122 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1123
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1124 void
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1125 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
1126 const char *warn_for, octave_idx_type& nr, octave_idx_type& nc)
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1127 {
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
1128 nr = a.is_empty () ? 0 : a.int_value ();
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4661
diff changeset
1129 nc = b.is_empty () ? 0 : b.int_value ();
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1130
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1131 if (error_state)
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1132 error ("%s: expecting two scalar arguments", warn_for);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1133 else
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1134 check_dimensions (nr, nc, warn_for); // May set error_state.
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1135 }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3350
diff changeset
1136
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1137 octave_idx_type
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1138 dims_to_numel (const dim_vector& dims, const octave_value_list& idx)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1139 {
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1140 octave_idx_type retval;
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1141
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1142 octave_idx_type len = idx.length ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1143
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1144 if (len == 0)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1145 retval = dims.numel ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1146 else
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1147 {
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1148 const dim_vector dv = dims.redim (len);
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1149 retval = 1;
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1150 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
1151 {
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1152 octave_value idxi = idx(i);
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1153 if (idxi.is_magic_colon ())
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1154 retval *= dv(i);
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1155 else if (idxi.is_numeric_type ())
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1156 retval *= idxi.numel ();
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1157 else
9842
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1158 {
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1159 idx_vector jdx = idxi.index_vector ();
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1160 if (error_state)
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1161 break;
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1162 retval *= jdx.length (dv(i));
10519b4d6507 fix indexed numel for non-numeric indices
Jaroslav Hajek <highegg@gmail.com>
parents: 9806
diff changeset
1163 }
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1164 }
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1165 }
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1166
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1167 return retval;
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1168 }
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9487
diff changeset
1169
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1170 Matrix
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1171 identity_matrix (octave_idx_type nr, octave_idx_type nc)
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1172 {
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1173 Matrix m (nr, nc, 0.0);
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1174
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1175 if (nr > 0 && nc > 0)
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1176 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1177 octave_idx_type n = std::min (nr, nc);
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1178
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5258
diff changeset
1179 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
1180 m (i, i) = 1.0;
4478
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1181 }
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1182
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1183 return m;
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1184 }
7afd4bf05aa8 [project @ 2003-07-30 19:15:31 by jwe]
jwe
parents: 4457
diff changeset
1185
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1186 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1187 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
1188 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1189 FloatMatrix m (nr, nc, 0.0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1190
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1191 if (nr > 0 && nc > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1192 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1193 octave_idx_type n = std::min (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1194
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1195 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
1196 m (i, i) = 1.0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1197 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1198
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1199 return m;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1200 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7481
diff changeset
1201
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1202 size_t
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
1203 octave_format (std::ostream& os, const char *fmt, ...)
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1204 {
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1205 size_t retval;
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1206
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1207 va_list args;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1208 va_start (args, fmt);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1209
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1210 retval = octave_vformat (os, fmt, args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1211
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1212 va_end (args);
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1213
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1214 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1215 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1216
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1217 size_t
3622
52594f1c37b6 [project @ 2000-03-23 06:20:06 by jwe]
jwe
parents: 3621
diff changeset
1218 octave_vformat (std::ostream& os, const char *fmt, va_list args)
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1219 {
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1220 std::string s = octave_vasprintf (fmt, args);
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1221
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1222 os << s;
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1223
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1224 return s.length ();
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1225 }
4135
e865976c2084 [project @ 2002-10-30 01:32:43 by jwe]
jwe
parents: 4124
diff changeset
1226
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1227 std::string
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1228 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
1229 {
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1230 std::string retval;
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1231
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1232 char *result;
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1233
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1234 int status = gnulib::vasprintf (&result, fmt, args);
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1235
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1236 if (status >= 0)
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1237 {
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1238 retval = result;
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1239 ::free (result);
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1240 }
3620
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1241
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1242 return retval;
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1243 }
0886bbb236cb [project @ 2000-03-23 05:17:23 by jwe]
jwe
parents: 3566
diff changeset
1244
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1245 std::string
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1246 octave_asprintf (const char *fmt, ...)
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1247 {
13991
051a8f94b6f8 avoid memory issue with octave_vsnprintf
John W. Eaton <jwe@octave.org>
parents: 13932
diff changeset
1248 std::string retval;
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1249
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1250 va_list args;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1251 va_start (args, fmt);
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1252
14005
f8556baf1949 rename octave_vsnprintf and octave_snprintf
John W. Eaton <jwe@octave.org>
parents: 13991
diff changeset
1253 retval = octave_vasprintf (fmt, args);
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1254
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1255 va_end (args);
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1256
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1257 return retval;
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1258 }
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4264
diff changeset
1259
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1260 void
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1261 octave_sleep (double seconds)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1262 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1263 if (seconds > 0)
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1264 {
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1265 double t;
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1266
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
1267 unsigned int usec
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10257
diff changeset
1268 = static_cast<unsigned int> (modf (seconds, &t) * 1000000);
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1269
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 4086
diff changeset
1270 unsigned int sec
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1271 = ((t > std::numeric_limits<unsigned int>::max ())
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1272 ? std::numeric_limits<unsigned int>::max ()
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
1273 : static_cast<unsigned int> (t));
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1274
5770
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5765
diff changeset
1275 // Versions of these functions that accept unsigned int args are
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5765
diff changeset
1276 // defined in cutils.c.
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1277 octave_sleep (sec);
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1278 octave_usleep (usec);
10070
897e62651c0a correctly handle interrupts in pause()
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
1279
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10086
diff changeset
1280 octave_quit ();
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1281 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1282 }
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4064
diff changeset
1283
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1284 DEFUN (isindex, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1285 "-*- texinfo -*-\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
1286 @deftypefn {Built-in Function} {} isindex (@var{ind})\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
1287 @deftypefnx {Built-in Function} {} isindex (@var{ind}, @var{n})\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
1288 Return true if @var{ind} is a valid index. Valid indices are\n\
11575
d6619410e79c Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11572
diff changeset
1289 either positive integers (although possibly of real data type), or logical\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
1290 arrays. If present, @var{n} specifies the maximum extent of the dimension\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
1291 to be indexed. When possible the internal result is cached so that\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11066
diff changeset
1292 subsequent indexing using @var{ind} will not perform the check again.\n\
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1293 @end deftypefn")
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1294 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1295 octave_value retval;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1296 int nargin = args.length ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1297 octave_idx_type n = 0;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1298
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1299 if (nargin == 2)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1300 n = args(1).idx_type_value ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1301 else if (nargin != 1)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1302 print_usage ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1303
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1304 if (! error_state)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1305 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10033
diff changeset
1306 unwind_protect frame;
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10502
diff changeset
1307
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
1308 frame.protect_var (Vallow_noninteger_range_as_index);
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
1309 Vallow_noninteger_range_as_index = false;
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10502
diff changeset
1310
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10033
diff changeset
1311 frame.protect_var (error_state);
10605
1834132fb50b allow non-integer ranges as indices conditionally
John W. Eaton <jwe@octave.org>
parents: 10502
diff changeset
1312
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10033
diff changeset
1313 frame.protect_var (discard_error_messages);
9487
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1314 discard_error_messages = true;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1315
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1316 try
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1317 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1318 idx_vector idx = args(0).index_vector ();
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1319 if (! error_state)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1320 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1321 if (nargin == 2)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1322 retval = idx.extent (n) <= n;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1323 else
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1324 retval = true;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1325 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1326 else
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1327 retval = false;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1328 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1329 catch (octave_execution_exception)
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1330 {
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1331 retval = false;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1332 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1333 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1334
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1335 return retval;
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1336 }
2894af292e69 implement isindex function
Jaroslav Hajek <highegg@gmail.com>
parents: 9173
diff changeset
1337
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1338 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1339 %!assert (isindex ([1, 2, 3]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1340 %!assert (isindex (1:3))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1341 %!assert (isindex ([1, 2, -3]), false)
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1342
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1343 %!error isindex ()
13094
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1344 */
7d4f5a033330 new tests for utils.cc
John W. Eaton <jwe@octave.org>
parents: 12668
diff changeset
1345
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1346 octave_value_list
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1347 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
1348 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
1349 int nargout)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1350 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1351 octave_value_list new_args = args, retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1352 int nargin = args.length ();
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1353 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
1354 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
1355 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
1356
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1357 const Cell *ccells = cells;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1358
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1359 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
1360 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
1361
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1362 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
1363 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1364 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
1365 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
1366 if (iscell[i])
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1367 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1368 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
1369 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
1370 if (n == 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1371 {
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1372 iscell[i] = false;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1373 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
1374 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1375 else if (numel == 1)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1376 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1377 numel = n;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1378 dims = ccells[i].dims ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1379 }
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1380 else if (dims != ccells[i].dims ())
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1381 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1382 error ("%s: cell arguments must have matching sizes", fun_name);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1383 break;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1384 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1385 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1386 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1387
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1388 if (! error_state)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1389 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1390 for (int i = 0; i < nargout; i++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1391 rcells[i].clear (dims);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1392
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1393 for (octave_idx_type j = 0; j < numel; j++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1394 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1395 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
1396 if (iscell[i])
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1397 new_args(i) = ccells[i](j);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1398
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10086
diff changeset
1399 octave_quit ();
10086
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1400
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1401 const octave_value_list tmp = fun (new_args, nargout);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1402
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1403 if (tmp.length () < nargout)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1404 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1405 error ("%s: do_simple_cellfun: internal error", fun_name);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1406 break;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1407 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1408 else
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1409 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1410 for (int i = 0; i < nargout; i++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1411 rcells[i](j) = tmp(i);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1412 }
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1413 }
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
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1416 if (! error_state)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1417 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1418 retval.resize (nargout);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1419 for (int i = 0; i < nargout; i++)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1420 retval(i) = rcells[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
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1423 return retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1424 }
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 octave_value
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1427 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
1428 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
1429 {
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1430 octave_value retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1431 const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1);
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1432 if (tmp.length () > 0)
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1433 retval = tmp(0);
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 return retval;
76df75b10c80 allow more cells in strfind/strrep + supply a general mechanism
Jaroslav Hajek <highegg@gmail.com>
parents: 10070
diff changeset
1436 }