Mercurial > octave
annotate libinterp/corefcn/file-io.cc @ 31605:e88a07dec498 stable
maint: Use macros to begin/end C++ namespaces.
* oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE,
OCTAVE_END_NAMESPACE) that can be used to start/end a namespace.
* mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc,
__dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc,
__ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc,
auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc,
colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc,
defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc,
display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc,
ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h,
event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc,
fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc,
getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc,
graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc,
help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h,
mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc,
oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h,
oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h,
oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h,
oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy,
ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc,
pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc,
sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h,
stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc,
symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h,
text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc,
toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc,
url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc,
variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh,
mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h,
ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h,
ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc,
op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc,
op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc,
op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc,
op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc,
op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc,
op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc,
op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc,
op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc,
op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc,
oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h,
pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h,
pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h,
pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc,
pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc,
pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc,
pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc,
pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h,
pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h,
range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc,
chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h,
lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h,
oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc,
randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc,
sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc,
child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc,
file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h,
mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h,
oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc,
oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h,
base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h,
file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc,
lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h,
oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h,
oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h,
oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h,
pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h,
url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 14:23:45 -0800 |
parents | 23520a50d74d |
children | aac27ad79be6 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30390
diff
changeset
|
3 // Copyright (C) 1993-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
1 | 25 |
2095 | 26 // Originally written by John C. Campbell <jcc@bevo.che.wisc.edu> |
1230 | 27 // |
2095 | 28 // Thomas Baier <baier@ci.tuwien.ac.at> added the original versions of |
29 // the following functions: | |
1230 | 30 // |
2095 | 31 // popen |
32 // pclose | |
33 // execute (now popen2.m) | |
34 // sync_system (now merged with system) | |
35 // async_system (now merged with system) | |
1230 | 36 |
9322 | 37 // Extensively revised by John W. Eaton <jwe@octave.org>, |
2095 | 38 // April 1996. |
1 | 39 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21634
diff
changeset
|
40 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
41 # include "config.h" |
1 | 42 #endif |
43 | |
4797 | 44 #include <cerrno> |
45 #include <cstdio> | |
1343 | 46 |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
47 #include <iomanip> |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
48 #include <string> |
1350 | 49 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21634
diff
changeset
|
50 #if defined (HAVE_ZLIB_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21127
diff
changeset
|
51 # include <zlib.h> |
5325 | 52 #endif |
53 | |
2926 | 54 #include "file-ops.h" |
6159 | 55 #include "file-stat.h" |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
56 #include "iconv-wrappers.h" |
5102 | 57 #include "lo-ieee.h" |
26642
c942659a57e6
Support opening handles to files with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26640
diff
changeset
|
58 #include "lo-sysdep.h" |
28052
118606de9359
Use the mfile_encoding as default encoding for fopen (bug #55826).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
59 #include "localcharset-wrapper.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
60 #include "mkostemp-wrapper.h" |
6159 | 61 #include "oct-env.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
62 #include "oct-locbuf.h" |
21919
473414a91539
* file-io.cc (cleanup_tmp_files): Use octave_unlink_wrapper.
John W. Eaton <jwe@octave.org>
parents:
21911
diff
changeset
|
63 #include "unistd-wrappers.h" |
2926 | 64 |
23454
30b6eccd6708
use builtin-defun-decls.h to ensure declarations of interpreter functions
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
65 #include "builtin-defun-decls.h" |
1352 | 66 #include "defun.h" |
23454
30b6eccd6708
use builtin-defun-decls.h to ensure declarations of interpreter functions
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
67 #include "error.h" |
21126
ba0a4b4f021d
include errwarn.h in files that use err_disabled_feature conditionally
John W. Eaton <jwe@octave.org>
parents:
21109
diff
changeset
|
68 #include "errwarn.h" |
27542
b8aa62c1deb5
eliminate global tmp_files variable
John W. Eaton <jwe@octave.org>
parents:
27424
diff
changeset
|
69 #include "interpreter-private.h" |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
70 #include "interpreter.h" |
6159 | 71 #include "load-path.h" |
2095 | 72 #include "oct-fstrm.h" |
73 #include "oct-iostrm.h" | |
1377 | 74 #include "oct-map.h" |
2095 | 75 #include "oct-prcstrm.h" |
76 #include "oct-stream.h" | |
77 #include "oct-strstrm.h" | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
78 #include "ov.h" |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
79 #include "ovl.h" |
1 | 80 #include "pager.h" |
444 | 81 #include "sysdep.h" |
1352 | 82 #include "utils.h" |
2370 | 83 #include "variables.h" |
1583 | 84 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31603
diff
changeset
|
85 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
86 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
87 static void |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
88 normalize_fopen_mode (std::string& mode, bool& use_zlib) |
1 | 89 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
90 use_zlib = false; |
896 | 91 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
92 if (! mode.empty ()) |
368 | 93 { |
24418
c23b9af6a664
Remove warnings about 'W', 'A', and 'R' modes in fopen (bug #52644).
Rik <rik@octave.org>
parents:
24417
diff
changeset
|
94 // Matlab uses 'A' and 'W' to indicate that buffered writing should |
c23b9af6a664
Remove warnings about 'W', 'A', and 'R' modes in fopen (bug #52644).
Rik <rik@octave.org>
parents:
24417
diff
changeset
|
95 // take place. Octave already does that. Theoretically, we should |
c23b9af6a664
Remove warnings about 'W', 'A', and 'R' modes in fopen (bug #52644).
Rik <rik@octave.org>
parents:
24417
diff
changeset
|
96 // warn about using 'a', 'r', or 'w' because Octave does not enable |
c23b9af6a664
Remove warnings about 'W', 'A', and 'R' modes in fopen (bug #52644).
Rik <rik@octave.org>
parents:
24417
diff
changeset
|
97 // automatic flushing with these modes. The performance hit is ~4X |
c23b9af6a664
Remove warnings about 'W', 'A', and 'R' modes in fopen (bug #52644).
Rik <rik@octave.org>
parents:
24417
diff
changeset
|
98 // when using automatic flushing and seems completely unnecessary. |
c23b9af6a664
Remove warnings about 'W', 'A', and 'R' modes in fopen (bug #52644).
Rik <rik@octave.org>
parents:
24417
diff
changeset
|
99 // See bug #52644. |
7078 | 100 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
101 std::size_t pos = mode.find ('W'); |
7078 | 102 |
8021 | 103 if (pos != std::string::npos) |
24418
c23b9af6a664
Remove warnings about 'W', 'A', and 'R' modes in fopen (bug #52644).
Rik <rik@octave.org>
parents:
24417
diff
changeset
|
104 mode[pos] = 'w'; |
7078 | 105 |
106 pos = mode.find ('R'); | |
107 | |
8021 | 108 if (pos != std::string::npos) |
24418
c23b9af6a664
Remove warnings about 'W', 'A', and 'R' modes in fopen (bug #52644).
Rik <rik@octave.org>
parents:
24417
diff
changeset
|
109 mode[pos] = 'r'; |
7078 | 110 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
111 pos = mode.find ('A'); |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
112 |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
113 if (pos != std::string::npos) |
24418
c23b9af6a664
Remove warnings about 'W', 'A', and 'R' modes in fopen (bug #52644).
Rik <rik@octave.org>
parents:
24417
diff
changeset
|
114 mode[pos] = 'a'; |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
115 |
7078 | 116 pos = mode.find ('z'); |
5325 | 117 |
8021 | 118 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
119 { |
5325 | 120 #if defined (HAVE_ZLIB) |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
121 use_zlib = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
122 mode.erase (pos, 1); |
5325 | 123 #else |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
124 err_disabled_feature ("", "gzipped files (zlib)"); |
5325 | 125 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
126 } |
5325 | 127 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
128 // Use binary mode if 't' is not specified, but don't add |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
129 // 'b' if it is already present. |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
130 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
131 std::size_t bpos = mode.find ('b'); |
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
132 std::size_t tpos = mode.find ('t'); |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
133 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
134 if (bpos == std::string::npos && tpos == std::string::npos) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
135 mode += 'b'; |
1 | 136 } |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
137 } |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
138 |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
139 static std::ios::openmode |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
140 fopen_mode_to_ios_mode (const std::string& mode) |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
141 { |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
142 std::ios::openmode retval = std::ios::in; |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
143 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
144 if (mode == "rt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
145 retval = std::ios::in; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
146 else if (mode == "wt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
147 retval = std::ios::out | std::ios::trunc; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
148 else if (mode == "at") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
149 retval = std::ios::out | std::ios::app; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
150 else if (mode == "r+t" || mode == "rt+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
151 retval = std::ios::in | std::ios::out; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
152 else if (mode == "w+t" || mode == "wt+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
153 retval = std::ios::in | std::ios::out | std::ios::trunc; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
154 else if (mode == "a+t" || mode == "at+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
155 retval = std::ios::in | std::ios::out | std::ios::app; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
156 else if (mode == "rb" || mode == "r") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
157 retval = std::ios::in | std::ios::binary; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
158 else if (mode == "wb" || mode == "w") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
159 retval = std::ios::out | std::ios::trunc | std::ios::binary; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
160 else if (mode == "ab" || mode == "a") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
161 retval = std::ios::out | std::ios::app | std::ios::binary; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
162 else if (mode == "r+b" || mode == "rb+" || mode == "r+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
163 retval = std::ios::in | std::ios::out | std::ios::binary; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
164 else if (mode == "w+b" || mode == "wb+" || mode == "w+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
165 retval = (std::ios::in | std::ios::out | std::ios::trunc |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
166 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
167 else if (mode == "a+b" || mode == "ab+" || mode == "a+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
168 retval = (std::ios::in | std::ios::out | std::ios::app |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
169 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
170 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
171 error ("invalid mode specified"); |
1 | 172 |
173 return retval; | |
174 } | |
175 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
176 DEFMETHOD (fclose, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
177 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
178 @deftypefn {} {@var{status} =} fclose (@var{fid}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
179 @deftypefnx {} {@var{status} =} fclose ("all") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
180 Close the file specified by the file descriptor @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
181 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
182 If successful, @code{fclose} returns 0, otherwise, it returns -1. The |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
183 second form of the @code{fclose} call closes all open files except |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
184 @code{stdin}, @code{stdout}, @code{stderr}, and any FIDs associated |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
185 with gnuplot. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
186 @seealso{fopen, fflush, freport} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
187 @end deftypefn */) |
529 | 188 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
189 if (args.length () != 1) |
5823 | 190 print_usage (); |
1 | 191 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
192 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
193 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
194 return ovl (streams.remove (args(0), "fclose")); |
1 | 195 } |
196 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
197 DEFMETHOD (fclear, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
198 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
199 @deftypefn {} {} fclear (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
200 Clear the stream state for the file specified by the file descriptor |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
201 @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
202 @seealso{ferror, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
203 @end deftypefn */) |
5144 | 204 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
205 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
206 print_usage (); |
5144 | 207 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
208 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
209 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
210 int fid = streams.get_file_number (args(0)); |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
211 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
212 stream os = streams.lookup (fid, "fclear"); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
213 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
214 os.clearerr (); |
5144 | 215 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
216 return ovl (); |
5144 | 217 } |
218 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
219 DEFMETHOD (fflush, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
220 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
221 @deftypefn {} {@var{status} =} fflush (@var{fid}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
222 Flush output to file descriptor @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
223 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
224 @code{fflush} returns 0 on success and an OS dependent error value |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
225 (@minus{}1 on Unix) on error. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
226 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
227 Programming Note: Flushing is useful for ensuring that all pending output |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
228 makes it to the screen before some other event occurs. For example, it is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
229 always a good idea to flush the standard output stream before calling |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
230 @code{input}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
231 @seealso{fopen, fclose} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
232 @end deftypefn */) |
1181 | 233 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
234 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
235 print_usage (); |
1181 | 236 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
237 octave_value retval = -1; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
238 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
239 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
240 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
241 // FIXME: any way to avoid special case for stdout? |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
242 int fid = streams.get_file_number (args(0)); |
2095 | 243 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
244 if (fid == 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
245 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
246 flush_stdout (); |
2609 | 247 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
248 retval = 0; |
2095 | 249 } |
250 else | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
251 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
252 stream os = streams.lookup (fid, "fflush"); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
253 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
254 retval = os.flush (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
255 } |
1181 | 256 |
257 return retval; | |
258 } | |
259 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
260 DEFMETHOD (fgetl, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
261 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
262 @deftypefn {} {@var{str} =} fgetl (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
263 @deftypefnx {} {@var{str} =} fgetl (@var{fid}, @var{len}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
264 Read characters from a file, stopping after a newline, or EOF, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
265 or @var{len} characters have been read. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
266 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
267 The characters read, excluding the possible trailing newline, are returned |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
268 as a string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
269 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
270 If @var{len} is omitted, @code{fgetl} reads until the next newline |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
271 character. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
272 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
273 If there are no more characters to read, @code{fgetl} returns @minus{}1. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
274 |
28960
e5a1087f15d5
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents:
28715
diff
changeset
|
275 To read a line and return the terminating newline, |
e5a1087f15d5
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents:
28715
diff
changeset
|
276 @pxref{XREFfgets,,@code{fgets}}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
277 @seealso{fgets, fscanf, fread, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
278 @end deftypefn */) |
1339 | 279 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
280 static const std::string who = "fgetl"; |
4468 | 281 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
282 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
283 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
284 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
285 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
286 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
287 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
288 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
289 stream os = streams.lookup (args(0), who); |
1339 | 290 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
291 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); |
2095 | 292 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
293 bool err = false; |
2095 | 294 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
295 std::string tmp = os.getl (len_arg, err, who); |
2095 | 296 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
297 if (! err) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
298 return ovl (tmp, tmp.length ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
299 else |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
300 return ovl (-1, 0); |
1339 | 301 } |
302 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
303 DEFMETHOD (fgets, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
304 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
305 @deftypefn {} {@var{str} =} fgets (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
306 @deftypefnx {} {@var{str} =} fgets (@var{fid}, @var{len}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
307 Read characters from a file, stopping after a newline, or EOF, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
308 or @var{len} characters have been read. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
309 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
310 The characters read, including the possible trailing newline, are returned |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
311 as a string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
312 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
313 If @var{len} is omitted, @code{fgets} reads until the next newline |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
314 character. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
315 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
316 If there are no more characters to read, @code{fgets} returns @minus{}1. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
317 |
28960
e5a1087f15d5
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents:
28715
diff
changeset
|
318 To read a line and discard the terminating newline, |
e5a1087f15d5
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents:
28715
diff
changeset
|
319 @pxref{XREFfgetl,,@code{fgetl}}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
320 @seealso{fputs, fgetl, fscanf, fread, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
321 @end deftypefn */) |
529 | 322 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
323 static const std::string who = "fgets"; |
4468 | 324 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
325 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
326 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
327 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
328 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
329 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
330 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
331 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
332 stream os = streams.lookup (args(0), who); |
529 | 333 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
334 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); |
2095 | 335 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
336 bool err = false; |
2095 | 337 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
338 std::string tmp = os.gets (len_arg, err, who); |
2095 | 339 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
340 if (! err) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
341 return ovl (tmp, tmp.length ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
342 else |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
343 return ovl (-1.0, 0.0); |
529 | 344 } |
345 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
346 DEFMETHOD (fskipl, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
347 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
348 @deftypefn {} {@var{nlines} =} fskipl (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
349 @deftypefnx {} {@var{nlines} =} fskipl (@var{fid}, @var{count}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
350 @deftypefnx {} {@var{nlines} =} fskipl (@var{fid}, Inf) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
351 Read and skip @var{count} lines from the file specified by the file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
352 descriptor @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
353 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
354 @code{fskipl} discards characters until an end-of-line is encountered |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
355 exactly @var{count}-times, or until the end-of-file marker is found. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
356 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
357 If @var{count} is omitted, it defaults to 1. @var{count} may also be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
358 @code{Inf}, in which case lines are skipped until the end of the file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
359 This form is suitable for counting the number of lines in a file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
360 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
361 Returns the number of lines skipped (end-of-line sequences encountered). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
362 @seealso{fgetl, fgets, fscanf, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
363 @end deftypefn */) |
9701 | 364 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
365 static const std::string who = "fskipl"; |
9701 | 366 |
367 int nargin = args.length (); | |
368 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
369 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
370 print_usage (); |
9701 | 371 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
372 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
373 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
374 stream os = streams.lookup (args(0), who); |
9701 | 375 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
376 octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); |
9701 | 377 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
378 bool err = false; |
9701 | 379 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
380 off_t tmp = os.skipl (count_arg, err, who); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
381 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
382 if (! err) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
383 return ovl (tmp); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
384 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
385 return ovl (); |
9701 | 386 } |
387 | |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
388 static stream |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
389 do_stream_open (const std::string& name, const std::string& mode_arg, |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
390 const std::string& arch, std::string encoding, int& fid) |
1 | 391 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
392 stream retval; |
1 | 393 |
2095 | 394 fid = -1; |
1 | 395 |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
396 // Valid names for encodings consist of ASCII characters only. |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
397 std::transform (encoding.begin (), encoding.end (), encoding.begin (), |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
398 ::tolower); |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
399 if (encoding.compare ("utf-8")) |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
400 { |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
401 // check if encoding is valid |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
402 void *codec = octave_iconv_open_wrapper (encoding.c_str (), "utf-8"); |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
403 if (codec == reinterpret_cast<void *> (-1)) |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
404 { |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
405 if (errno == EINVAL) |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
406 error ("fopen: conversion from codepage '%s' not supported", |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
407 encoding.c_str ()); |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
408 } |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
409 else |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
410 octave_iconv_close_wrapper (codec); |
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
411 } |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
412 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
413 std::string mode = mode_arg; |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
414 bool use_zlib = false; |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
415 normalize_fopen_mode (mode, use_zlib); |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
416 |
4036 | 417 std::ios::openmode md = fopen_mode_to_ios_mode (mode); |
1 | 418 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
419 mach_info::float_format flt_fmt |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
420 = mach_info::string_to_float_format (arch); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
421 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
422 std::string fname = sys::file_ops::tilde_expand (name); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
423 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
424 sys::file_stat fs (fname); |
7730
b68e44c90afe
file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents:
7708
diff
changeset
|
425 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
426 if (! (md & std::ios::out)) |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
427 fname = find_data_file_in_load_path ("fopen", fname); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
428 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
429 if (! fs.is_dir ()) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
430 { |
6905 | 431 #if defined (HAVE_ZLIB) |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
432 if (use_zlib) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
433 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
434 FILE *fptr = sys::fopen (fname.c_str (), mode.c_str ()); |
11004
594adb99a25e
cache file id in octave_tstdiostream class
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
435 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
436 if (fptr) |
26378
3f3677540634
file-io.cc: Fix static analyzer detected V595 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
437 { |
3f3677540634
file-io.cc: Fix static analyzer detected V595 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
438 int fd = fileno (fptr); |
3f3677540634
file-io.cc: Fix static analyzer detected V595 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
439 |
3f3677540634
file-io.cc: Fix static analyzer detected V595 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
440 gzFile gzf = ::gzdopen (fd, mode.c_str ()); |
3f3677540634
file-io.cc: Fix static analyzer detected V595 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
441 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
442 retval = zstdiostream::create (fname, gzf, fd, md, flt_fmt, |
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
443 encoding); |
26378
3f3677540634
file-io.cc: Fix static analyzer detected V595 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
444 } |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
445 else |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21919
diff
changeset
|
446 retval.error (std::strerror (errno)); |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
447 } |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
448 else |
5325 | 449 #endif |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
450 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
451 FILE *fptr = sys::fopen (fname, mode); |
5370 | 452 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
453 retval = stdiostream::create (fname, fptr, md, flt_fmt, encoding); |
7730
b68e44c90afe
file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents:
7708
diff
changeset
|
454 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
455 if (! fptr) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21919
diff
changeset
|
456 retval.error (std::strerror (errno)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
457 } |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
458 |
1 | 459 } |
460 | |
2095 | 461 return retval; |
462 } | |
1 | 463 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
464 static stream |
2095 | 465 do_stream_open (const octave_value& tc_name, const octave_value& tc_mode, |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
466 const octave_value& tc_arch, const octave_value& tc_encoding, |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
467 const char *fcn, int& fid) |
2095 | 468 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
469 stream retval; |
2095 | 470 |
471 fid = -1; | |
472 | |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
473 std::string name = tc_name.xstring_value ("%s: filename must be a string", fcn); |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
474 std::string mode = tc_mode.xstring_value ("%s: file mode must be a string", fcn); |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
475 std::string arch = tc_arch.xstring_value ("%s: architecture type must be a string", fcn); |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
476 std::string encoding = tc_encoding.xstring_value ("%s: ENCODING must be a string", fcn); |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
477 |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
478 retval = do_stream_open (name, mode, arch, encoding, fid); |
1 | 479 |
480 return retval; | |
481 } | |
482 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
483 DEFMETHOD (fopen, interp, args, nargout, |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
484 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
485 @deftypefn {} {@var{fid} =} fopen (@var{name}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
486 @deftypefnx {} {@var{fid} =} fopen (@var{name}, @var{mode}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
487 @deftypefnx {} {@var{fid} =} fopen (@var{name}, @var{mode}, @var{arch}) |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
488 @deftypefnx {} {@var{fid} =} fopen (@var{name}, @var{mode}, @var{arch}, @var{encoding}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
489 @deftypefnx {} {[@var{fid}, @var{msg}] =} fopen (@dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
490 @deftypefnx {} {@var{fid_list} =} fopen ("all") |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
491 @deftypefnx {} {[@var{file}, @var{mode}, @var{arch}, @var{encoding}] =} fopen (@var{fid}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
492 Open a file for low-level I/O or query open files and file descriptors. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
493 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
494 The first form of the @code{fopen} function opens the named file with |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
495 the specified mode (read-write, read-only, etc.@:), architecture |
27795
afbaad39d25c
doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents:
27542
diff
changeset
|
496 interpretation (IEEE big endian, IEEE little endian, etc.@:) and file encoding, |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
497 and returns an integer value that may be used to refer to the file later. If |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
498 an error occurs, @var{fid} is set to @minus{}1 and @var{msg} contains the |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
499 corresponding system error message. The @var{mode} is a one or two |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
500 character string that specifies whether the file is to be opened for |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
501 reading, writing, or both. The @var{encoding} is a character string with a |
28052
118606de9359
Use the mfile_encoding as default encoding for fopen (bug #55826).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
502 valid encoding identifier. This encoding is used when strings are read from |
28713
28d2511f2af2
maint: grammarcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents:
28219
diff
changeset
|
503 or written to the file. By default, the same encoding specified for reading |
28d2511f2af2
maint: grammarcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents:
28219
diff
changeset
|
504 @file{.m} files is used for interpreting user files. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
505 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
506 The second form of the @code{fopen} function returns a vector of file ids |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
507 corresponding to all the currently open files, excluding the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
508 @code{stdin}, @code{stdout}, and @code{stderr} streams. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
509 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
510 The third form of the @code{fopen} function returns information about the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
511 open file given its file id. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
512 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
513 For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
514 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
515 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
516 myfile = fopen ("splat.dat", "r", "ieee-le"); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
517 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
518 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
519 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
520 opens the file @file{splat.dat} for reading. If necessary, binary |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
521 numeric values will be read assuming they are stored in IEEE format with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
522 the least significant bit first, and then converted to the native |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
523 representation. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
524 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
525 Opening a file that is already open simply opens it again and returns a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
526 separate file id. It is not an error to open a file several times, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
527 though writing to the same file through several different file ids may |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
528 produce unexpected results. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
529 |
24416
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
530 The possible values of @var{mode} are |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
531 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
532 @table @asis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
533 @item @samp{r} (default) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
534 Open a file for reading. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
535 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
536 @item @samp{w} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
537 Open a file for writing. The previous contents are discarded. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
538 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
539 @item @samp{a} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
540 Open or create a file for writing at the end of the file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
541 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
542 @item @samp{r+} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
543 Open an existing file for reading and writing. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
544 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
545 @item @samp{w+} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
546 Open a file for reading or writing. The previous contents are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
547 discarded. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
548 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
549 @item @samp{a+} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
550 Open or create a file for reading or writing at the end of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
551 file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
552 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
553 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
554 Append a @qcode{"t"} to the mode string to open the file in text mode or a |
24416
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
555 @qcode{"b"} to open in binary mode. On Windows systems, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
556 text mode reading and writing automatically converts linefeeds to the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
557 appropriate line end character for the system (carriage-return linefeed on |
24416
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
558 Windows). The default when no mode is specified is binary. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
559 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
560 Additionally, you may append a @qcode{"z"} to the mode string to open a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
561 gzipped file for reading or writing. For this to be successful, you |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
562 must also open the file in binary mode. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
563 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
564 The parameter @var{arch} is a string specifying the default data format |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
565 for the file. Valid values for @var{arch} are: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
566 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
567 @table @asis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
568 @item @qcode{"native"} or @qcode{"n"} (default) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
569 The format of the current machine. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
570 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
571 @item @qcode{"ieee-be"} or @qcode{"b"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
572 IEEE big endian format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
573 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
574 @item @qcode{"ieee-le"} or @qcode{"l"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
575 IEEE little endian format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
576 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
577 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
578 When opening a new file that does not yet exist, permissions will be set to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
579 @code{0666 - @var{umask}}. |
24416
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
580 |
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
581 Compatibility Note: Octave opens files using buffered I/O. Small writes are |
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
582 accumulated until an internal buffer is filled, and then everything is written |
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
583 in a single operation. This is very efficient and improves performance. |
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
584 @sc{matlab}, however, opens files using flushed I/O where every write operation |
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
585 is immediately performed. If the write operation must be performed immediately |
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
586 after data has been written then the write should be followed by a call to |
d400b09043dd
doc: Explain Matlab compatibility of fopen modes (bug #52644).
Rik <rik@octave.org>
parents:
24303
diff
changeset
|
587 @code{fflush} to flush the internal buffer. |
30329
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29999
diff
changeset
|
588 @seealso{fclose, fgets, fgetl, fscanf, fread, fputs, fdisp, fprintf, fwrite, |
81d26e8481a6
maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29999
diff
changeset
|
589 fskipl, fseek, frewind, ftell, feof, ferror, fclear, fflush, freport, umask} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
590 @end deftypefn */) |
529 | 591 { |
592 int nargin = args.length (); | |
593 | |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
594 if (nargin < 1 || nargin > 4) |
20846
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
595 print_usage (); |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
596 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
597 octave_value_list retval = ovl (-1.0); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
598 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
599 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
600 |
2095 | 601 if (nargin == 1) |
602 { | |
12896
a19b50f6697f
Correctly allow single string input form of fopen() (Bug #33535).
Rik <octave@nomad.inbox5.com>
parents:
12775
diff
changeset
|
603 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
604 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
605 // If there is only one argument and it is a string but it |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
606 // is not the string "all", we assume it is a file to open |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
607 // with MODE = "r". To open a file called "all", you have |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
608 // to supply more than one argument. |
12896
a19b50f6697f
Correctly allow single string input form of fopen() (Bug #33535).
Rik <octave@nomad.inbox5.com>
parents:
12775
diff
changeset
|
609 if (nargout < 2 && args(0).string_value () == "all") |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
610 return streams.open_file_numbers (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
611 } |
2095 | 612 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
613 { |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
614 string_vector tmp = streams.get_info (args(0)); |
529 | 615 |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
616 retval = ovl (tmp(0), tmp(1), tmp(2), tmp(3)); |
3263 | 617 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
618 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
619 } |
1 | 620 } |
621 | |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
622 octave_value mode = (nargin > 1) ? args(1) : octave_value ("r"); |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
623 |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
624 octave_value arch = (nargin > 2) ? args(2) : octave_value ("native"); |
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
625 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
626 input_system& input_sys = interp.get_input_system (); |
28052
118606de9359
Use the mfile_encoding as default encoding for fopen (bug #55826).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
627 octave_value encoding = (nargin > 3) ? args(3) |
118606de9359
Use the mfile_encoding as default encoding for fopen (bug #55826).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
628 : octave_value (input_sys.mfile_encoding ()); |
118606de9359
Use the mfile_encoding as default encoding for fopen (bug #55826).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
629 if (encoding.string_value () == "system") |
118606de9359
Use the mfile_encoding as default encoding for fopen (bug #55826).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
630 encoding = octave_value (octave_locale_charset_wrapper ()); |
2095 | 631 |
20846
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
632 int fid = -1; |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
633 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
634 stream os = do_stream_open (args(0), mode, arch, encoding, "fopen", |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30338
diff
changeset
|
635 fid); |
5370 | 636 |
20846
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
637 if (os) |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
638 retval = ovl (streams.insert (os), ""); |
2095 | 639 else |
20846
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
640 { |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
641 int error_number = 0; |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
642 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
643 retval = ovl (-1.0, os.error (false, error_number)); |
20846
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
644 } |
1 | 645 |
646 return retval; | |
647 } | |
648 | |
22837
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
649 /* |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
650 ## Further tests are in io.tst |
22837
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
651 %!test # Uses hardcoded value of 1 for stdout |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
652 %! [name, mode, arch, encoding] = fopen (1); |
22837
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
653 %! assert (name, "stdout"); |
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
654 %! assert (mode, "w"); |
26705
c13143821eef
Add front-end support for encodings in "fopen" (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26642
diff
changeset
|
655 %! assert (encoding, "utf-8"); |
22837
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
656 |
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
657 %!test # Query of non-existent stream returns all "" |
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
658 %! [name, mode, arch] = fopen (-1); |
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
659 %! assert (name, ""); |
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
660 %! assert (mode, ""); |
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
661 %! assert (arch, ""); |
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
662 */ |
b125351d4243
Return null "" status when querying a bad FID with fopen (bug #49695).
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
663 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
664 DEFMETHOD (freport, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
665 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
666 @deftypefn {} {} freport () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
667 Print a list of which files have been opened, and whether they are open |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
668 for reading, writing, or both. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
669 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
670 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
671 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
672 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
673 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
674 freport () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
675 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
676 @print{} number mode arch name |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
677 @print{} ------ ---- ---- ---- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
678 @print{} 0 r ieee-le stdin |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
679 @print{} 1 w ieee-le stdout |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
680 @print{} 2 w ieee-le stderr |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
681 @print{} 3 r ieee-le myfile |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
682 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
683 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
684 @seealso{fopen, fclose, is_valid_file_id} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
685 @end deftypefn */) |
1181 | 686 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
687 if (args.length () > 0) |
1181 | 688 warning ("freport: ignoring extra arguments"); |
689 | |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
690 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
691 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
692 octave_stdout << streams.list_open_files (); |
1181 | 693 |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
694 return ovl (); |
1181 | 695 } |
696 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
697 DEFMETHOD (frewind, interp, args, nargout, |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
698 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
699 @deftypefn {} {} frewind (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
700 @deftypefnx {} {@var{status} =} frewind (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
701 Move the file pointer to the beginning of the file specified by file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
702 descriptor @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
703 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
704 If an output @var{status} is requested then @code{frewind} returns 0 for |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
705 success, and -1 if an error is encountered. |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
706 |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
707 Programming Note: @code{frewind} is equivalent to |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
708 @code{fseek (@var{fid}, 0, SEEK_SET)}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
709 @seealso{fseek, ftell, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
710 @end deftypefn */) |
529 | 711 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
712 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
713 print_usage (); |
506 | 714 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
715 int result = -1; |
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
716 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
717 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
718 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
719 stream os = streams.lookup (args(0), "frewind"); |
636 | 720 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
721 result = os.rewind (); |
1 | 722 |
4715 | 723 if (nargout > 0) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
724 return ovl (result); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
725 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
726 return ovl (); |
1 | 727 } |
728 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
729 DEFMETHOD (fseek, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
730 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
731 @deftypefn {} {@var{status} =} fseek (@var{fid}, @var{offset}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
732 @deftypefnx {} {@var{status} =} fseek (@var{fid}, @var{offset}, @var{origin}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
733 Set the file pointer to the location @var{offset} within the file @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
734 |
25005
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
735 The pointer is positioned @var{offset} characters from the @var{origin}, which |
25454
41ea5f665659
doc: Use qcode macro to document fseek offsets (bug #51402).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
736 may be one of the predefined variables @w{@qcode{SEEK_SET}} (beginning), |
41ea5f665659
doc: Use qcode macro to document fseek offsets (bug #51402).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
737 @w{@qcode{SEEK_CUR}} (current position), or @w{@qcode{SEEK_END}} (end of file) |
41ea5f665659
doc: Use qcode macro to document fseek offsets (bug #51402).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
738 or strings @nospell{@qcode{"bof"}}, @nospell{@qcode{"cof"}}, or |
41ea5f665659
doc: Use qcode macro to document fseek offsets (bug #51402).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
739 @nospell{@qcode{"eof"}}. If @var{origin} is omitted, @w{@qcode{SEEK_SET}} is |
25003
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24933
diff
changeset
|
740 assumed. @var{offset} may be positive, negative, or zero but not all |
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24933
diff
changeset
|
741 combinations of @var{origin} and @var{offset} can be realized. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
742 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
743 @code{fseek} returns 0 on success and -1 on error. |
25005
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
744 @seealso{fskipl, frewind, ftell, fopen, SEEK_SET, SEEK_CUR, SEEK_END} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
745 @end deftypefn */) |
529 | 746 { |
747 int nargin = args.length (); | |
748 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
749 if (nargin < 2 || nargin > 3) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
750 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
751 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
752 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
753 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
754 stream os = streams.lookup (args(0), "fseek"); |
1181 | 755 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
756 octave_value origin_arg = (nargin == 3) ? args(2) : octave_value (-1.0); |
1 | 757 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
758 return ovl (os.seek (args(1), origin_arg)); |
1 | 759 } |
760 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
761 DEFMETHOD (ftell, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
762 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
763 @deftypefn {} {@var{pos} =} ftell (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
764 Return the position of the file pointer as the number of characters from the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
765 beginning of the file specified by file descriptor @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
766 @seealso{fseek, frewind, feof, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
767 @end deftypefn */) |
1181 | 768 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
769 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
770 print_usage (); |
506 | 771 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
772 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
773 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
774 stream os = streams.lookup (args(0), "ftell"); |
1 | 775 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
776 return ovl (os.tell ()); |
1 | 777 } |
778 | |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
779 static octave_value_list |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
780 printf_internal (interpreter& interp, const std::string& who, |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
781 const octave_value_list& args, int nargout) |
1181 | 782 { |
783 int nargin = args.length (); | |
784 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
785 if (! (nargin > 1 || (nargin > 0 && args(0).is_string ()))) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
786 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
787 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
788 int result; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
789 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
790 stream os; |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
791 int fmt_n = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
792 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
793 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
794 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
795 if (args(0).is_string ()) |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
796 os = streams.lookup (1, who); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
797 else |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
798 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
799 fmt_n = 1; |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
800 os = streams.lookup (args(0), who); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
801 } |
2873 | 802 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
803 if (! args(fmt_n).is_string ()) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
804 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
1181 | 805 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
806 octave_value_list tmp_args; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
807 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
808 if (nargin > 1 + fmt_n) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
809 { |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
810 tmp_args.resize (nargin-fmt_n-1, octave_value ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
811 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
812 for (int i = fmt_n + 1; i < nargin; i++) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
813 tmp_args(i-fmt_n-1) = args(i); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
814 } |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
815 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
816 result = os.printf (args(fmt_n), tmp_args, who); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
817 |
4715 | 818 if (nargout > 0) |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
819 return ovl (result); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
820 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
821 return ovl (); |
1181 | 822 } |
823 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
824 DEFMETHOD (fprintf, interp, args, nargout, |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
825 doc: /* -*- texinfo -*- |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
826 @deftypefn {} {} fprintf (@var{fid}, @var{template}, @dots{}) |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
827 @deftypefnx {} {} fprintf (@var{template}, @dots{}) |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
828 @deftypefnx {} {@var{numbytes} =} fprintf (@dots{}) |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
829 This function is equivalent to @code{printf}, except that the output is |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
830 written to the file descriptor @var{fid} instead of @code{stdout}. |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
831 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
832 If @var{fid} is omitted, the output is written to @code{stdout} making the |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
833 function exactly equivalent to @code{printf}. |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
834 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
835 The optional output @var{numbytes} returns the number of bytes written to the |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
836 file. |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
837 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
838 Implementation Note: For compatibility with @sc{matlab}, escape sequences in |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28960
diff
changeset
|
839 the template string (e.g., @qcode{"@backslashchar{}n"} => newline) are |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
840 expanded even when the template string is defined with single quotes. |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
841 @seealso{fputs, fdisp, fwrite, fscanf, printf, sprintf, fopen} |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
842 @end deftypefn */) |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
843 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
844 static const std::string who = "fprintf"; |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
845 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
846 return printf_internal (interp, who, args, nargout); |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
847 } |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
848 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
849 DEFMETHOD (printf, interp, args, nargout, |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
850 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
851 @deftypefn {} {} printf (@var{template}, @dots{}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
852 @deftypefnx {} {@var{numbytes} =} printf (@dots{}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
853 Print optional arguments under the control of the template string |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
854 @var{template} to the stream @code{stdout} and return the number of characters |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
855 printed. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
856 @ifclear OCTAVE_MANUAL |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
857 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
858 See the Formatted Output section of the GNU Octave manual for a complete |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
859 description of the syntax of the template string. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
860 @end ifclear |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
861 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
862 The optional output @var{numbytes} returns the number of bytes printed. |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
863 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
864 Implementation Note: For compatibility with @sc{matlab}, escape sequences in |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28960
diff
changeset
|
865 the template string (e.g., @qcode{"@backslashchar{}n"} => newline) are |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
866 expanded even when the template string is defined with single quotes. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
867 @seealso{fprintf, sprintf, scanf} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
868 @end deftypefn */) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
869 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
870 static const std::string who = "printf"; |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
871 |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
872 octave_value_list tmp_args = args; |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
873 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
874 return printf_internal (interp, who, tmp_args.prepend (octave_value (1)), |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
875 nargout); |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
876 } |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
877 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
878 static octave_value_list |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
879 puts_internal (interpreter& interp, const std::string& who, |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
880 const octave_value_list& args) |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
881 { |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
882 if (args.length () != 2) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
883 print_usage (); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
884 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
885 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
886 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
887 stream os = streams.lookup (args(0), who); |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
888 |
31135
05a64f60bc1e
Return -1 rather than platform-dependent EOF from puts, fputs (bug #62725)
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
889 return ovl (- (os.puts (args(1), who) < 0)); |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
890 } |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
891 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
892 DEFMETHOD (fputs, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
893 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
894 @deftypefn {} {@var{status} =} fputs (@var{fid}, @var{string}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
895 Write the string @var{string} to the file with file descriptor @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
896 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
897 The string is written to the file with no additional formatting. Use |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
898 @code{fdisp} instead to automatically append a newline character appropriate |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
899 for the local machine. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
900 |
31135
05a64f60bc1e
Return -1 rather than platform-dependent EOF from puts, fputs (bug #62725)
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
901 The optional output @var{status} is 0 for success, or -1 if an error was |
05a64f60bc1e
Return -1 rather than platform-dependent EOF from puts, fputs (bug #62725)
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
902 encountered. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
903 @seealso{fdisp, fprintf, fwrite, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
904 @end deftypefn */) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
905 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
906 static const std::string who = "fputs"; |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
907 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
908 return puts_internal (interp, who, args); |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
909 } |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
910 |
30822
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
911 /* |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
912 ## Check if text is correctly converted to output encoding |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
913 %!test <*61839> |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
914 %! str = "aäöu"; # string with non-ASCII characters |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
915 %! fname = tempname (); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
916 %! fid = fopen (fname, "wt", "n", "ISO-8859-1"); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
917 %! unwind_protect |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
918 %! fprintf (fid, '%s\n', str); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
919 %! fdisp (fid, str); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
920 %! fputs (fid, str); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
921 %! fclose (fid); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
922 %! ## re-open file for reading in binary mode |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
923 %! fid = fopen (fname, "rb"); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
924 %! fb = fread (fid); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
925 %! fclose (fid); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
926 %! ## check file content |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
927 %! encoded = [97 228 246 117]; # original string in ISO-8859-1 encoding |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
928 %! if (ispc ()) |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
929 %! eol = double ("\r\n"); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
930 %! else |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
931 %! eol = double ("\n"); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
932 %! endif |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
933 %! assert (fb.', [encoded eol encoded eol encoded]) |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
934 %! unwind_protect_cleanup |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
935 %! unlink (fname); |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
936 %! end_unwind_protect |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
937 */ |
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
938 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
939 DEFMETHOD (puts, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
940 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
941 @deftypefn {} {@var{status} =} puts (@var{string}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
942 Write a string to the standard output with no formatting. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
943 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
944 The string is written verbatim to the standard output. Use @code{disp} to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
945 automatically append a newline character appropriate for the local machine. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
946 |
31135
05a64f60bc1e
Return -1 rather than platform-dependent EOF from puts, fputs (bug #62725)
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
947 The optional output @var{status} is 0 for success, or -1 if an error was |
05a64f60bc1e
Return -1 rather than platform-dependent EOF from puts, fputs (bug #62725)
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
948 encountered. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
949 @seealso{fputs, disp} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
950 @end deftypefn */) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
951 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
952 static const std::string who = "puts"; |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
953 |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
954 octave_value_list tmp_args = args; |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
955 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
956 return puts_internal (interp, who, tmp_args.prepend (octave_value (1))); |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
957 } |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
958 |
2095 | 959 DEFUN (sprintf, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
960 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
961 @deftypefn {} {@var{str} =} sprintf (@var{template}, @dots{}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
962 This is like @code{printf}, except that the output is returned as a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
963 string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
964 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
965 Unlike the C library function, which requires you to provide a suitably |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
966 sized string as an argument, Octave's @code{sprintf} function returns the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
967 string, automatically sized to hold all of the items converted. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
968 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
969 Implementation Note: For compatibility with @sc{matlab}, escape sequences in |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28960
diff
changeset
|
970 the template string (e.g., @qcode{"@backslashchar{}n"} => newline) are |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
971 expanded even when the template string is defined with single quotes. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
972 @seealso{printf, fprintf, sscanf} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
973 @end deftypefn */) |
1 | 974 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
975 static const std::string who = "sprintf"; |
4468 | 976 |
2095 | 977 int nargin = args.length (); |
1 | 978 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
979 if (nargin == 0) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
980 print_usage (); |
2116 | 981 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
982 // We don't use ostrstream::create here because need direct |
21506
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
983 // access to the OSTR object so that we can extract a string object |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
984 // from it to return. |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
985 ostrstream *ostr = new ostrstream (); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
986 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
987 // The stream destructor will delete OSTR for us. |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
988 stream os (ostr); |
628 | 989 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
990 if (! os.is_valid ()) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
991 error ("%s: unable to create output buffer", who.c_str ()); |
1 | 992 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
993 octave_value fmt_arg = args(0); |
1 | 994 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
995 if (! fmt_arg.is_string ()) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
996 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
628 | 997 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
998 octave_value_list retval (3); |
19727
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
999 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1000 octave_value_list tmp_args; |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1001 if (nargin > 1) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1002 { |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1003 tmp_args.resize (nargin-1, octave_value ()); |
19727
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1004 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1005 for (int i = 1; i < nargin; i++) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1006 tmp_args(i-1) = args(i); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1007 } |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1008 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1009 // NOTE: Call to os.error must precede next call to ostr which might reset it. |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1010 retval(2) = os.printf (fmt_arg, tmp_args, who); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1011 retval(1) = os.error (); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1012 |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1013 std::string result = ostr->str (); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1014 char type = (fmt_arg.is_sq_string () ? '\'' : '"'); |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1015 |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1016 retval(0) = (result.empty () ? octave_value (charMatrix (1, 0), type) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
1017 : octave_value (result, type)); |
1 | 1018 |
1019 return retval; | |
1020 } | |
1021 | |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1022 static octave_value_list |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1023 scanf_internal (interpreter& interp, const std::string& who, |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1024 const octave_value_list& args) |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1025 { |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1026 int nargin = args.length (); |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1027 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1028 if (nargin < 2 || nargin > 3) |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1029 print_usage (); |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1030 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1031 octave_value_list retval; |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1032 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1033 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1034 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1035 stream os = streams.lookup (args(0), who); |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1036 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1037 if (! args(1).is_string ()) |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1038 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1039 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1040 if (nargin == 3 && args(2).is_string ()) |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1041 { |
23924
0519eaf0cca6
fix remaining spurious octave_value_list conversions (bug #51767)
Mike Miller <mtmiller@octave.org>
parents:
23803
diff
changeset
|
1042 retval = os.oscanf (args(1), who); |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1043 } |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1044 else |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1045 { |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1046 octave_idx_type count = 0; |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1047 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1048 Array<double> size |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1049 = (nargin == 3 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1050 ? args(2).vector_value () |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1051 : Array<double> (dim_vector (1, 1), lo_ieee_inf_value ())); |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1052 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1053 octave_value tmp = os.scanf (args(1), size, count, who); |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1054 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1055 retval = ovl (tmp, count, os.error ()); |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1056 } |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1057 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1058 return retval; |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1059 } |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1060 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1061 DEFMETHOD (fscanf, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1062 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1063 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, @var{size}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1064 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, "C") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1065 In the first form, read from @var{fid} according to @var{template}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1066 returning the result in the matrix @var{val}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1067 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1068 The optional argument @var{size} specifies the amount of data to read |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1069 and may be one of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1070 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1071 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1072 @item Inf |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1073 Read as much as possible, returning a column vector. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1074 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1075 @item @var{nr} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1076 Read up to @var{nr} elements, returning a column vector. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1077 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1078 @item [@var{nr}, Inf] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1079 Read as much as possible, returning a matrix with @var{nr} rows. If the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1080 number of elements read is not an exact multiple of @var{nr}, the last |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1081 column is padded with zeros. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1082 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1083 @item [@var{nr}, @var{nc}] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1084 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1085 @var{nr} rows. If the number of elements read is not an exact multiple |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1086 of @var{nr}, the last column is padded with zeros. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1087 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1088 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1089 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1090 If @var{size} is omitted, a value of @code{Inf} is assumed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1091 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1092 A string is returned if @var{template} specifies only character conversions. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1093 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1094 The number of items successfully read is returned in @var{count}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1095 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1096 If an error occurs, @var{errmsg} contains a system-dependent error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1097 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1098 In the second form, read from @var{fid} according to @var{template}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1099 with each conversion specifier in @var{template} corresponding to a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1100 single scalar return value. This form is more ``C-like'', and also |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1101 compatible with previous versions of Octave. The number of successful |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1102 conversions is returned in @var{count} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1103 @ifclear OCTAVE_MANUAL |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1104 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1105 See the Formatted Input section of the GNU Octave manual for a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1106 complete description of the syntax of the template string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1107 @end ifclear |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1108 @seealso{fgets, fgetl, fread, scanf, sscanf, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1109 @end deftypefn */) |
1181 | 1110 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
1111 static const std::string who = "fscanf"; |
4468 | 1112 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1113 return scanf_internal (interp, who, args); |
1181 | 1114 } |
1115 | |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1116 static std::string |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1117 get_scan_string_data (const octave_value& val, const std::string& who) |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1118 { |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1119 std::string retval; |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1120 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
1121 if (! val.is_string ()) |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1122 error ("%s: argument STRING must be a string", who.c_str ()); |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1123 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
1124 octave_value tmp = val.reshape (dim_vector (1, val.numel ())); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
1125 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
1126 retval = tmp.string_value (); |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1127 |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1128 return retval; |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1129 } |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1130 |
2095 | 1131 DEFUN (sscanf, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1132 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1133 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}, @var{pos}] =} sscanf (@var{string}, @var{template}, @var{size}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1134 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} sscanf (@var{string}, @var{template}, "C") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1135 This is like @code{fscanf}, except that the characters are taken from the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1136 string @var{string} instead of from a stream. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1137 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1138 Reaching the end of the string is treated as an end-of-file condition. In |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1139 addition to the values returned by @code{fscanf}, the index of the next |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1140 character to be read is returned in @var{pos}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1141 @seealso{fscanf, scanf, sprintf} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1142 @end deftypefn */) |
444 | 1143 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
1144 static const std::string who = "sscanf"; |
4468 | 1145 |
506 | 1146 int nargin = args.length (); |
1147 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1148 if (nargin < 2 || nargin > 3) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1149 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1150 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1151 octave_value_list retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1152 |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1153 std::string data = get_scan_string_data (args(0), who); |
21506
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1154 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
1155 stream os = istrstream::create (data); |
21506
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1156 |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1157 if (! os.is_valid ()) |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1158 error ("%s: unable to create temporary input buffer", who.c_str ()); |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1159 |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1160 if (! args(1).is_string ()) |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1161 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1162 |
2215 | 1163 if (nargin == 3 && args(2).is_string ()) |
2095 | 1164 { |
23924
0519eaf0cca6
fix remaining spurious octave_value_list conversions (bug #51767)
Mike Miller <mtmiller@octave.org>
parents:
23803
diff
changeset
|
1165 retval = os.oscanf (args(1), who); |
444 | 1166 } |
1167 else | |
2215 | 1168 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1169 octave_idx_type count = 0; |
2215 | 1170 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1171 Array<double> size = (nargin == 3) ? args(2).vector_value () |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1172 : Array<double> (dim_vector (1, 1), |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1173 lo_ieee_inf_value ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1174 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1175 octave_value tmp = os.scanf (args(1), size, count, who); |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
1176 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1177 // FIXME: is this the right thing to do? |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1178 // Extract error message first, because getting |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1179 // position will clear it. |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1180 std::string errmsg = os.error (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1181 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1182 retval = ovl (tmp, count, errmsg, |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1183 (os.eof () ? data.length () : os.tell ()) + 1); |
2215 | 1184 } |
444 | 1185 |
1186 return retval; | |
1187 } | |
1188 | |
27137
30f53f7a7293
Return correct error messages on octave-streams when scanf fails (bug #56396)
Rik <rik@octave.org>
parents:
26946
diff
changeset
|
1189 /* |
30f53f7a7293
Return correct error messages on octave-streams when scanf fails (bug #56396)
Rik <rik@octave.org>
parents:
26946
diff
changeset
|
1190 %!test <*56396> |
30f53f7a7293
Return correct error messages on octave-streams when scanf fails (bug #56396)
Rik <rik@octave.org>
parents:
26946
diff
changeset
|
1191 %! [val, count, errmsg, nextpos] = sscanf ('1234a6', '%2d', 3); |
30f53f7a7293
Return correct error messages on octave-streams when scanf fails (bug #56396)
Rik <rik@octave.org>
parents:
26946
diff
changeset
|
1192 %! assert (val, [12; 34]); |
30f53f7a7293
Return correct error messages on octave-streams when scanf fails (bug #56396)
Rik <rik@octave.org>
parents:
26946
diff
changeset
|
1193 %! assert (count, 2); |
30f53f7a7293
Return correct error messages on octave-streams when scanf fails (bug #56396)
Rik <rik@octave.org>
parents:
26946
diff
changeset
|
1194 %! assert (errmsg, "sscanf: format failed to match"); |
30f53f7a7293
Return correct error messages on octave-streams when scanf fails (bug #56396)
Rik <rik@octave.org>
parents:
26946
diff
changeset
|
1195 %! assert (nextpos, 5); |
30f53f7a7293
Return correct error messages on octave-streams when scanf fails (bug #56396)
Rik <rik@octave.org>
parents:
26946
diff
changeset
|
1196 */ |
30f53f7a7293
Return correct error messages on octave-streams when scanf fails (bug #56396)
Rik <rik@octave.org>
parents:
26946
diff
changeset
|
1197 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1198 DEFMETHOD (scanf, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1199 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1200 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} scanf (@var{template}, @var{size}) |
24466
746081e3cbdd
doc: Delete extra ']' in scanf docstring (bug #52742).
Rik <rik@octave.org>
parents:
24416
diff
changeset
|
1201 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} scanf (@var{template}, "C") |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1202 This is equivalent to calling @code{fscanf} with @var{fid} = @code{stdin}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1203 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1204 It is currently not useful to call @code{scanf} in interactive programs. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1205 @seealso{fscanf, sscanf, printf} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1206 @end deftypefn */) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1207 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
1208 static const std::string who = "scanf"; |
23737
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1209 |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1210 octave_value_list tmp_args = args; |
7fb957d36357
refactor fprintf, printf, fputs, puts, fscanf, and scanf functions
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
1211 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1212 return scanf_internal (interp, who, tmp_args.prepend (octave_value (0))); |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1213 } |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1214 |
21504 | 1215 static octave_value_list |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1216 textscan_internal (interpreter& interp, const std::string& who, |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1217 const octave_value_list& args) |
21504 | 1218 { |
1219 if (args.length () < 1) | |
1220 print_usage (who); | |
1221 | |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1222 stream os; |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1223 |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1224 if (args(0).is_string ()) |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1225 { |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1226 std::string data = get_scan_string_data (args(0), who); |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1227 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
1228 os = istrstream::create (data); |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1229 |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1230 if (! os.is_valid ()) |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1231 error ("%s: unable to create temporary input buffer", who.c_str ()); |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1232 } |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1233 else |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1234 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1235 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1236 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1237 os = streams.lookup (args(0), who); |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1238 } |
21504 | 1239 |
1240 int nskip = 1; | |
1241 | |
1242 std::string fmt; | |
1243 | |
1244 if (args.length () == 1) | |
1245 { | |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26642
diff
changeset
|
1246 // omitted format = %f. explicit "" = width from file |
21504 | 1247 fmt = "%f"; |
1248 } | |
1249 else if (args(1).is_string ()) | |
1250 { | |
1251 fmt = args(1).string_value (); | |
1252 | |
1253 if (args(1).is_sq_string ()) | |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1254 fmt = do_string_escapes (fmt); |
21504 | 1255 |
1256 nskip++; | |
1257 } | |
1258 else | |
1259 error ("%s: FORMAT must be a string", who.c_str ()); | |
1260 | |
1261 octave_idx_type ntimes = -1; | |
1262 | |
1263 if (args.length () > 2) | |
1264 { | |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
1265 if (args(2).isnumeric ()) |
21504 | 1266 { |
1267 ntimes = args(2).idx_type_value (); | |
1268 | |
1269 if (ntimes < args(2).double_value ()) | |
1270 error ("%s: REPEAT = %g is too large", | |
1271 who.c_str (), args(2).double_value ()); | |
1272 | |
1273 nskip++; | |
1274 } | |
1275 } | |
1276 | |
1277 octave_value_list options = args.splice (0, nskip); | |
1278 | |
1279 octave_idx_type count = 0; | |
1280 | |
1281 octave_value result = os.textscan (fmt, ntimes, options, who, count); | |
1282 | |
1283 std::string errmsg = os.error (); | |
1284 | |
1285 return ovl (result, count, errmsg); | |
1286 } | |
1287 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1288 DEFMETHOD (textscan, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1289 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1290 @deftypefn {} {@var{C} =} textscan (@var{fid}, @var{format}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1291 @deftypefnx {} {@var{C} =} textscan (@var{fid}, @var{format}, @var{repeat}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1292 @deftypefnx {} {@var{C} =} textscan (@var{fid}, @var{format}, @var{param}, @var{value}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1293 @deftypefnx {} {@var{C} =} textscan (@var{fid}, @var{format}, @var{repeat}, @var{param}, @var{value}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1294 @deftypefnx {} {@var{C} =} textscan (@var{str}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1295 @deftypefnx {} {[@var{C}, @var{position}, @var{errmsg}] =} textscan (@dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1296 Read data from a text file or string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1297 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1298 The string @var{str} or file associated with @var{fid} is read from and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1299 parsed according to @var{format}. The function is an extension of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1300 @code{strread} and @code{textread}. Differences include: the ability to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1301 read from either a file or a string, additional options, and additional |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1302 format specifiers. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1303 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1304 The input is interpreted as a sequence of words, delimiters (such as |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1305 whitespace), and literals. The characters that form delimiters and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1306 whitespace are determined by the options. The format consists of format |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1307 specifiers interspersed between literals. In the format, whitespace forms |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1308 a delimiter between consecutive literals, but is otherwise ignored. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1309 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1310 The output @var{C} is a cell array where the number of columns is determined |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1311 by the number of format specifiers. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1312 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1313 The first word of the input is matched to the first specifier of the format |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1314 and placed in the first column of the output; the second is matched to the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1315 second specifier and placed in the second column and so forth. If there |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1316 are more words than specifiers then the process is repeated until all words |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1317 have been processed or the limit imposed by @var{repeat} has been met (see |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1318 below). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1319 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1320 The string @var{format} describes how the words in @var{str} should be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1321 parsed. As in @var{fscanf}, any (non-whitespace) text in the format that is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1322 not one of these specifiers is considered a literal. If there is a literal |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1323 between two format specifiers then that same literal must appear in the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1324 input stream between the matching words. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1325 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1326 The following specifiers are valid: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1327 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1328 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1329 @item %f |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1330 @itemx %f64 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1331 @itemx %n |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1332 The word is parsed as a number and converted to double. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1333 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1334 @item %f32 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1335 The word is parsed as a number and converted to single (float). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1336 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1337 @item %d |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1338 @itemx %d8 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1339 @itemx %d16 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1340 @itemx %d32 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1341 @itemx %d64 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1342 The word is parsed as a number and converted to int8, int16, int32, or |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1343 int64. If no size is specified then int32 is used. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1344 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1345 @item %u |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1346 @itemx %u8 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1347 @itemx %u16 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1348 @itemx %u32 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1349 @itemx %u64 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1350 The word is parsed as a number and converted to uint8, uint16, uint32, or |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1351 uint64. If no size is specified then uint32 is used. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1352 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1353 @item %s |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1354 The word is parsed as a string ending at the last character before |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1355 whitespace, an end-of-line, or a delimiter specified in the options. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1356 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1357 @item %q |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1358 The word is parsed as a "quoted string". |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1359 If the first character of the string is a double quote (") then the string |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1360 includes everything until a matching double quote---including whitespace, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1361 delimiters, and end-of-line characters. If a pair of consecutive double |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1362 quotes appears in the input, it is replaced in the output by a single |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1363 double quote. For examples, the input "He said ""Hello""" would |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1364 return the value 'He said "Hello"'. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1365 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1366 @item %c |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1367 The next character of the input is read. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1368 This includes delimiters, whitespace, and end-of-line characters. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1369 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1370 @item %[@dots{}] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1371 @itemx %[^@dots{}] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1372 In the first form, the word consists of the longest run consisting of only |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1373 characters between the brackets. Ranges of characters can be specified by |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1374 a hyphen; for example, %[0-9a-zA-Z] matches all alphanumeric characters (if |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1375 the underlying character set is ASCII). Since @sc{matlab} treats hyphens |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1376 literally, this expansion only applies to alphanumeric characters. To |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1377 include '-' in the set, it should appear first or last in the brackets; to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1378 include ']', it should be the first character. If the first character is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1379 '^' then the word consists of characters @strong{not} listed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1380 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1381 @item %N@dots{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1382 For %s, %c %d, %f, %n, %u, an optional width can be specified as %Ns, etc. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1383 where N is an integer > 1. For %c, this causes exactly N characters to be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1384 read instead of a single character. For the other specifiers, it is an |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1385 upper bound on the number of characters read; normal delimiters can cause |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1386 fewer characters to be read. For complex numbers, this limit applies to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1387 the real and imaginary components individually. For %f and %n, format |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1388 specifiers like %N.Mf are allowed, where M is an upper bound on number of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1389 characters after the decimal point to be considered; subsequent digits are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1390 skipped. For example, the specifier %8.2f would read 12.345e6 as 1.234e7. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1391 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1392 @item %*@dots{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1393 The word specified by the remainder of the conversion specifier is skipped. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1394 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1395 @item literals |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1396 In addition the format may contain literal character strings; these will be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1397 skipped during reading. If the input string does not match this literal, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1398 the processing terminates. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1399 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1400 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1401 Parsed words corresponding to the first specifier are returned in the first |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1402 output argument and likewise for the rest of the specifiers. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1403 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1404 By default, if there is only one input argument, @var{format} is @t{"%f"}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1405 This means that numbers are read from the input into a single column vector. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1406 If @var{format} is explicitly empty (@qcode{""}) then textscan will |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1407 return data in a number of columns matching the number of fields on the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1408 first data line of the input. Either of these is suitable only when the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1409 input is exclusively numeric. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1410 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1411 For example, the string |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1412 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1413 @smallexample |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1414 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1415 @var{str} = "\ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1416 Bunny Bugs 5.5\n\ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1417 Duck Daffy -7.5e-5\n\ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1418 Penguin Tux 6" |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1419 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1420 @end smallexample |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1421 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1422 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1423 can be read using |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1424 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1425 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1426 @var{a} = textscan (@var{str}, "%s %s %f"); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1427 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1428 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1429 The optional numeric argument @var{repeat} can be used for limiting the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1430 number of items read: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1431 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1432 @table @asis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1433 @item -1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1434 Read all of the string or file until the end (default). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1435 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1436 @item N |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1437 Read until the first of two conditions occurs: 1) the format has been |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1438 processed N times, or 2) N lines of the input have been processed. Zero |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1439 (0) is an acceptable value for @var{repeat}. Currently, end-of-line |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1440 characters inside %q, %c, and %[@dots{}]$ conversions do not contribute to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1441 the line count. This is incompatible with @sc{matlab} and may change in |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1442 future. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1443 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1444 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1445 The behavior of @code{textscan} can be changed via property/value pairs. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1446 The following properties are recognized: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1447 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1448 @table @asis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1449 @item @qcode{"BufSize"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1450 This specifies the number of bytes to use for the internal buffer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1451 A modest speed improvement may be obtained by setting this to a large value |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1452 when reading a large file, especially if the input contains long strings. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1453 The default is 4096, or a value dependent on @var{n} if that is specified. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1454 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1455 @item @qcode{"CollectOutput"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1456 A value of 1 or true instructs @code{textscan} to concatenate consecutive |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1457 columns of the same class in the output cell array. A value of 0 or false |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1458 (default) leaves output in distinct columns. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1459 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1460 @item @qcode{"CommentStyle"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1461 Specify parts of the input which are considered comments and will be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1462 skipped. @var{value} is the comment style and can be either (1) A string |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1463 or 1x1 cell string, to skip everything to the right of it; (2) A cell array |
21992
03c692adf563
maint: strip trailing whitespace from files.
John W. Eaton <jwe@octave.org>
parents:
21991
diff
changeset
|
1464 of two strings, to skip everything between the first and second strings. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1465 Comments are only parsed where whitespace is accepted and do not act as |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1466 delimiters. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1467 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1468 @item @qcode{"Delimiter"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1469 If @var{value} is a string, any character in @var{value} will be used to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1470 split the input into words. If @var{value} is a cell array of strings, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1471 any string in the array will be used to split the input into words. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1472 (default value = any whitespace.) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1473 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1474 @item @qcode{"EmptyValue"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1475 Value to return for empty numeric values in non-whitespace delimited data. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1476 The default is NaN@. When the data type does not support NaN (int32 for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1477 example), then the default is zero. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1478 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1479 @item @qcode{"EndOfLine"} |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26642
diff
changeset
|
1480 @var{value} can be either an empty or one character specifying the |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1481 end-of-line character, or the pair |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28960
diff
changeset
|
1482 @qcode{"@backslashchar{}r@backslashchar{}n"} (CRLF). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1483 In the latter case, any of |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28960
diff
changeset
|
1484 @qcode{"@backslashchar{}r"}, @qcode{"@backslashchar{}n"} or |
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28960
diff
changeset
|
1485 @qcode{"@backslashchar{}r@backslashchar{}n"} is counted as a (single) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1486 newline. If no value is given, |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28960
diff
changeset
|
1487 @qcode{"@backslashchar{}r@backslashchar{}n"} is used. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1488 @c If set to "" (empty string) EOLs are ignored as delimiters and added |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1489 @c to whitespace. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1490 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1491 @c When reading from a character string, optional input argument @var{n} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1492 @c specifies the number of times @var{format} should be used (i.e., to limit |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1493 @c the amount of data read). |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1494 @c When reading from file, @var{n} specifies the number of data lines to read; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1495 @c in this sense it differs slightly from the format repeat count in strread. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1496 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1497 @item @qcode{"HeaderLines"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1498 The first @var{value} number of lines of @var{fid} are skipped. Note that |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1499 this does not refer to the first non-comment lines, but the first lines of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1500 any type. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1501 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1502 @item @qcode{"MultipleDelimsAsOne"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1503 If @var{value} is nonzero, treat a series of consecutive delimiters, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1504 without whitespace in between, as a single delimiter. Consecutive |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1505 delimiter series need not be vertically aligned. Without this option, a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1506 single delimiter before the end of the line does not cause the line to be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1507 considered to end with an empty value, but a single delimiter at the start |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1508 of a line causes the line to be considered to start with an empty value. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1509 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1510 @item @qcode{"TreatAsEmpty"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1511 Treat single occurrences (surrounded by delimiters or whitespace) of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1512 string(s) in @var{value} as missing values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1513 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1514 @item @qcode{"ReturnOnError"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1515 If set to numerical 1 or true, return normally as soon as an error is |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22022
diff
changeset
|
1516 encountered, such as trying to read a string using @code{%f}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1517 If set to 0 or false, return an error and no data. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1518 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1519 @item @qcode{"Whitespace"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1520 Any character in @var{value} will be interpreted as whitespace and trimmed; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1521 The default value for whitespace is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1522 @c Note: the next line specifically has a newline which generates a space |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1523 @c in the output of qcode, but keeps the next line < 80 characters. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1524 @qcode{" |
29117
10a35049bad7
doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents:
28960
diff
changeset
|
1525 @backslashchar{}b@backslashchar{}r@backslashchar{}n@backslashchar{}t"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1526 (note the space). Unless whitespace is set to @qcode{""} (empty) AND at |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1527 least one @qcode{"%s"} format conversion specifier is supplied, a space is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1528 always part of whitespace. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1529 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1530 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1531 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1532 When the number of words in @var{str} or @var{fid} doesn't match an exact |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1533 multiple of the number of format conversion specifiers, @code{textscan}'s |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1534 behavior depends on whether the last character of the string or file is an |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1535 end-of-line as specified by the @code{EndOfLine} option: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1536 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1537 @table @asis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1538 @item last character = end-of-line |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1539 Data columns are padded with empty fields, NaN or 0 (for integer fields) so |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1540 that all columns have equal length |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1541 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1542 @item last character is not end-of-line |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1543 Data columns are not padded; @code{textscan} returns columns of unequal |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1544 length |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1545 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1546 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1547 The second output @var{position} provides the location, in characters |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1548 from the beginning of the file or string, where processing stopped. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1549 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1550 @seealso{dlmread, fscanf, load, strread, textread} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1551 @end deftypefn */) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1552 { |
27167
ec6d31ef6bb6
* file-io.cc: Declare local constant "who" names "static const".
John W. Eaton <jwe@octave.org>
parents:
27137
diff
changeset
|
1553 static const std::string who = "textscan"; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1554 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1555 return textscan_internal (interp, who, args); |
21504 | 1556 } |
1557 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1558 DEFMETHOD (__textscan__, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1559 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1560 @deftypefn {} {@var{C} =} __textscan__ (@var{who}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1561 Like @code{textscan} but accept additional argument @var{who} to use |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1562 as the name of the function when reporting errors. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1563 @end deftypefn */) |
21504 | 1564 { |
1565 if (args.length () == 0) | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1566 print_usage (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1567 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1568 return textscan_internal (interp, args(0).string_value (), |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
1569 args.splice (0, 1)); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1570 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1571 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1572 /* |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1573 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1574 %! str = "1, 2, 3, 4\n 5, , , 8\n 9, 10, 11, 12"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1575 %! fmtstr = "%f %d %f %s"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1576 %! c = textscan (str, fmtstr, 2, "delimiter", ",", "emptyvalue", -Inf); |
21625 | 1577 %! assert (c{1}, [1;5]); |
1578 %! assert (c{3}, [3; -Inf]); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1579 %! assert (iscellstr (c{4})); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1580 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1581 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1582 %! b = [10:10:100]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1583 %! b = [b; 8*b/5]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1584 %! str = sprintf ("%g miles/hr = %g kilometers/hr\n", b); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1585 %! fmt = "%f miles/hr = %f kilometers/hr"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1586 %! c = textscan (str, fmt); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1587 %! assert (c{1}, b(1,:)', 1e-5); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1588 %! assert (c{2}, b(2,:)', 1e-5); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1589 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1590 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1591 %! str = "13, -, NA, str1, -25\r\n// Middle line\r\n36, na, 05, str3, 6"; |
21625 | 1592 %! c = textscan (str, "%d %n %f %s %n", "delimiter", ",", |
1593 %! "treatAsEmpty", {"NA", "na", "-"}, "commentStyle", "//"); | |
1594 %! assert (c{1}, int32 ([13; 36])); | |
1595 %! assert (c{2}, [NaN; NaN]); | |
1596 %! assert (c{3}, [NaN; 5]); | |
1597 %! assert (c{4}, {"str1"; "str3"}); | |
1598 %! assert (c{5}, [-25; 6]); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1599 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1600 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1601 %! str = "Km:10 = hhhBjjj miles16hour\r\n"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1602 %! str = [str "Km:15 = hhhJjjj miles241hour\r\n"]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1603 %! str = [str "Km:2 = hhhRjjj miles3hour\r\n"]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1604 %! str = [str "Km:25 = hhhZ\r\n"]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1605 %! fmt = "Km:%d = hhh%1sjjj miles%dhour"; |
21625 | 1606 %! c = textscan (str, fmt, "delimiter", " "); |
1607 %! assert (c{1}', int32 ([10, 15, 2, 25])); | |
1608 %! assert (c{2}', {'B' 'J' 'R' 'Z'}); | |
1609 %! assert (c{3}', int32 ([16, 241, 3, 0])); | |
1610 | |
1611 ## Test with default EndOfLine parameter | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1612 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1613 %! c = textscan ("L1\nL2", "%s"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1614 %! assert (c{:}, {"L1"; "L2"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1615 |
21625 | 1616 ## Test with EndofLine parameter set to "" (empty) - newline should be in word |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1617 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1618 %! c = textscan ("L1\nL2", "%s", "endofline", ""); |
21625 | 1619 %! assert (int8 ([c{:}{:}]), int8 ([76, 49, 10, 76, 50])); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1620 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1621 ## Matlab fails this test. A literal after a conversion is not a delimiter |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1622 %!#test |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1623 %! ## No delimiters at all besides EOL. Skip fields, even empty fields |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1624 %! str = "Text1Text2Text\nTextText4Text\nText57Text"; |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1625 %! c = textscan (str, "Text%*dText%dText"); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1626 %! assert (c{1}, int32 ([2; 4; 0])); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1627 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1628 ## CollectOutput test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1629 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1630 %! b = [10:10:100]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1631 %! b = [b; 8*b/5; 8*b*1000/5]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1632 %! str = sprintf ("%g miles/hr = %g (%g) kilometers (meters)/hr\n", b); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1633 %! fmt = "%f miles%s %s %f (%f) kilometers %*s"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1634 %! c = textscan (str, fmt, "collectoutput", 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1635 %! assert (size (c{3}), [10, 2]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1636 %! assert (size (c{2}), [10, 2]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1637 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1638 ## CollectOutput test with uneven column length files |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1639 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1640 %! b = [10:10:100]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1641 %! b = [b; 8*b/5; 8*b*1000/5]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1642 %! str = sprintf ("%g miles/hr = %g (%g) kilometers (meters)/hr\n", b); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1643 %! str = [str "110 miles/hr"]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1644 %! fmt = "%f miles%s %s %f (%f) kilometers %*s"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1645 %! c = textscan (str, fmt, "collectoutput", 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1646 %! assert (size (c{1}), [11, 1]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1647 %! assert (size (c{3}), [11, 2]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1648 %! assert (size (c{2}), [11, 2]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1649 %! assert (c{3}(end), NaN); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1650 %! assert (c{2}{11, 1}, "/hr"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1651 %! assert (isempty (c{2}{11, 2}), true); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1652 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1653 ## Double quoted string |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1654 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1655 %! str = 'First "the second called ""the middle""" third'; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1656 %! fmt = "%q"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1657 %! c = textscan (str, fmt); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1658 %! assert (c{1}, {"First"; 'the second called "the middle"'; "third"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1659 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1660 ## Arbitrary character |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1661 %!test |
21625 | 1662 %! c = textscan ("a first, \n second, third", "%s %c %11c", "delimiter", " ,"); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1663 %! assert (c{1}, {"a"; "ond"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1664 %! assert (c{2}, {"f"; "t"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1665 %! assert (c{3}, {"irst, \n sec"; "hird"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1666 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1667 ## Field width and non-standard delimiters |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1668 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1669 %! str = "12;34;123456789;7"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1670 %! c = textscan (str, "%4d %4d", "delimiter", ";", "collectOutput", 1); |
21625 | 1671 %! assert (c, {[12, 34; 1234, 5678; 9, 7]}); |
1672 | |
1673 ## Field width and non-standard delimiters (2) | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1674 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1675 %! str = "12;34;123456789;7"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1676 %! c = textscan (str, "%4f %f", "delimiter", ";", "collectOutput", 1); |
21625 | 1677 %! assert (c, {[12, 34; 1234, 56789; 7, NaN]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1678 |
28183
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
1679 ## FIXME: Not Matlab compatible. Matlab prioritizes precision over field width |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
1680 ## so "12.234e+2", when read with "%10.2f %f", yields "12.23" and "4e+2". |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1681 ## Ignore trailing delimiter, but use leading one |
28183
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
1682 %!#test |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1683 %! str = "12.234e+2,34, \n12345.789-9876j,78\n,10|3"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1684 %! c = textscan (str, "%10.2f %f", "delimiter", ",", "collectOutput", 1, |
21625 | 1685 %! "expChars", "e|"); |
1686 %! assert (c, {[1223, 34; 12345.79-9876j, 78; NaN, 10000]}, 1e-6); | |
1687 | |
1688 ## Multi-character delimiter | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1689 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1690 %! str = "99end2 space88gap 4564"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1691 %! c = textscan (str, "%d %s", "delimiter", {"end", "gap", "space"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1692 %! assert (c{1}, int32 ([99; 88])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1693 %! assert (c{2}, {"2 "; "4564"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1694 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1695 ## FIXME: Following two tests still fail (4/13/2016). |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1696 ## Delimiters as part of literals, and following literals |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1697 %!#test |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1698 %! str = "12 R&D & 7"; |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1699 %! c = textscan (str, "%f R&D %f", "delimiter", "&", "collectOutput", 1, |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1700 %! "EmptyValue", -99); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1701 %! assert (c, {[12, -99; 7, -99]}); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1702 |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1703 ## Delimiters as part of literals, and before literals |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1704 %!#test |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1705 %! str = "12 & R&D 7"; |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1706 %! c = textscan (str, "%f R&D %f", "delimiter", "&", "collectOutput", 1); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1707 %! assert (c, {[12 7]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1708 |
21625 | 1709 ## Check number of lines read, not number of passes through format string |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1710 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1711 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1712 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1713 %! fprintf (fid, "1\n2\n3\n4\n5\n6"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1714 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1715 %! c = textscan (fid, "%f %f", 2); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1716 %! E = feof (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1717 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1718 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1719 %! assert (c, {1, 2}); |
21625 | 1720 %! assert (! E); |
1721 | |
1722 ## Check number of lines read, not number of passes through format string | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1723 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1724 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1725 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1726 %! fprintf (fid, "1\r\n2\r3\n4\r\n5\n6"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1727 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1728 %! c = textscan (fid, "%f %f", 4); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1729 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1730 %! unlink (f); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1731 %! assert (c, {[1;3], [2;4]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1732 |
21625 | 1733 ## Check number of lines read, with multiple delimiters |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1734 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1735 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1736 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1737 %! fprintf (fid, "1-\r\n-2\r3-\n-4\r\n5\n6"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1738 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1739 %! c = textscan (fid, "%f %f", 4, "delimiter", "-", "multipleDelimsAsOne", 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1740 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1741 %! unlink (f); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1742 %! assert (c, {[1;3], [2;4]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1743 |
21625 | 1744 ## Check ReturnOnError |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1745 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1746 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1747 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1748 %! str = "1 2 3\n4 s 6"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1749 %! fprintf (fid, str); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1750 %! fseek (fid, 0, "bof"); |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1751 %! c = textscan (fid, "%f %f %f", "ReturnOnError", 1); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1752 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1753 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1754 %! unlink (f); |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1755 %! u = textscan (str, "%f %f %f", "ReturnOnError", 1); |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1756 %! assert (c, {[1;4], [2], [3]}); |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1757 %! assert (u, {[1;4], [2], [3]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1758 |
21625 | 1759 %! ## Check ReturnOnError (2) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1760 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1761 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1762 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1763 %! str = "1 2 3\n4 s 6\n"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1764 %! fprintf (fid, str); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1765 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1766 %! c = textscan (fid, "%f %f %f", "ReturnOnError", 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1767 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1768 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1769 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1770 %! u = textscan (str, "%f %f %f", "ReturnOnError", 1); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1771 %! assert (c, {[1;4], 2, 3}); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1772 %! assert (u, {[1;4], 2, 3}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1773 |
21625 | 1774 %!error <Read error in field 2 of row 2> |
1775 %! textscan ("1 2 3\n4 s 6", "%f %f %f", "ReturnOnError", 0); | |
1776 | |
1777 ## Check ReturnOnError (3) | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1778 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1779 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1780 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1781 %! fprintf (fid, "1 s 3\n4 5 6"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1782 %! fseek (fid, 0, "bof"); |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1783 %! c = textscan (fid, "", "ReturnOnError", 1); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1784 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1785 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1786 %! unlink (f); |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1787 %! assert (c, {1}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1788 |
21625 | 1789 ## Check ReturnOnError with empty fields |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1790 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1791 %! c = textscan ("1,,3\n4,5,6", "", "Delimiter", ",", "ReturnOnError", 1); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1792 %! assert (c, {[1;4], [NaN;5], [3;6]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1793 |
21625 | 1794 ## Check ReturnOnError with empty fields (2) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1795 %!test |
21625 | 1796 %! c = textscan ("1,,3\n4,5,6", "%f %f %f", "Delimiter", ",", |
1797 %! "ReturnOnError", 1); | |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1798 %! assert (c, {[1;4], [NaN;5], [3;6]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1799 |
21625 | 1800 ## Check ReturnOnError in first column |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1801 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1802 %! c = textscan ("1 2 3\ns 5 6", "", "ReturnOnError", 1); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1803 %! assert (c, {1, 2, 3}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1804 |
21625 | 1805 ## FIXME: This test fails (4/14/16) |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1806 ## Test incomplete first data line |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1807 %!#test |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1808 %! R = textscan (['Empty1' char(10)], 'Empty%d %f'); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1809 %! assert (R{1}, int32 (1)); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1810 %! assert (isempty (R{2}), true); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1811 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1812 %!test <*37023> |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1813 %! data = textscan (" 1. 1 \n 2 3\n", '%f %f'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1814 %! assert (data{1}, [1; 2], 1e-15); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1815 %! assert (data{2}, [1; 3], 1e-15); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1816 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1817 ## Whitespace test using delimiter ";" |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1818 %!test <*37333> |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1819 %! tc{1, 1} = "C:/code;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1820 %! tc{1, end+1} = "C:/code/meas;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1821 %! tc{1, end+1} = " C:/code/sim;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1822 %! tc{1, end+1} = "C:/code/utils;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1823 %! string = [tc{:}]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1824 %! c = textscan (string, "%s", "delimiter", ";"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1825 %! for k = 1:max (numel (c{1}), numel (tc)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1826 %! lh = c{1}{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1827 %! rh = tc{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1828 %! rh(rh == ";") = ""; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1829 %! rh = strtrim (rh); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1830 %! assert (strcmp (lh, rh)); |
21625 | 1831 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1832 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
1833 ## Whitespace test, adding multipleDelimsAsOne true arg |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1834 %!test <*37333> |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1835 %! tc{1, 1} = "C:/code;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1836 %! tc{1, end+1} = " C:/code/meas;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1837 %! tc{1, end+1} = "C:/code/sim;;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1838 %! tc{1, end+1} = "C:/code/utils;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1839 %! string = [tc{:}]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1840 %! c = textscan (string, "%s", "delimiter", ";", "multipleDelimsAsOne", 1); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1841 %! for k = 1:max (numel (c{1}), numel (tc)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1842 %! lh = c{1}{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1843 %! rh = tc{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1844 %! rh(rh == ";") = ""; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1845 %! rh = strtrim (rh); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1846 %! assert (strcmp (lh, rh)); |
21625 | 1847 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1848 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1849 ## Whitespace test (bug #37333), adding multipleDelimsAsOne false arg |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1850 %!test <*37333> |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1851 %! tc{1, 1} = "C:/code;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1852 %! tc{1, end+1} = " C:/code/meas;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1853 %! tc{1, end+1} = "C:/code/sim;;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1854 %! tc{1, end+1} = ""; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1855 %! tc{1, end+1} = "C:/code/utils;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1856 %! string = [tc{:}]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1857 %! c = textscan (string, "%s", "delimiter", ";", "multipleDelimsAsOne", 0); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1858 %! for k = 1:max (numel (c{1}), numel (tc)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1859 %! lh = c{1}{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1860 %! rh = tc{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1861 %! rh(rh == ";") = ""; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1862 %! rh = strtrim (rh); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1863 %! assert (strcmp (lh, rh)); |
21625 | 1864 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1865 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1866 ## Whitespace test (bug #37333) whitespace "" arg |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1867 %!test <*37333> |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1868 %! tc{1, 1} = "C:/code;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1869 %! tc{1, end+1} = " C:/code/meas;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1870 %! tc{1, end+1} = "C:/code/sim;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1871 %! tc{1, end+1} = "C:/code/utils;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1872 %! string = [tc{:}]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1873 %! c = textscan (string, "%s", "delimiter", ";", "whitespace", ""); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1874 %! for k = 1:max (numel (c{1}), numel (tc)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1875 %! lh = c{1}{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1876 %! rh = tc{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1877 %! rh(rh == ";") = ""; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1878 %! assert (strcmp (lh, rh)); |
21625 | 1879 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1880 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1881 ## Whitespace test (bug #37333), whitespace " " arg |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1882 %!test <*37333> |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1883 %! tc{1, 1} = "C:/code;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1884 %! tc{1, end+1} = " C:/code/meas;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1885 %! tc{1, end+1} = "C:/code/sim;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1886 %! tc{1, end+1} = "C:/code/utils;"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1887 %! string = [tc{:}]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1888 %! c = textscan (string, "%s", "delimiter", ";", "whitespace", " "); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1889 %! for k = 1:max (numel (c{1}), numel (tc)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1890 %! lh = c{1}{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1891 %! rh = tc{k}; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1892 %! rh(rh == ";") = ""; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1893 %! rh = strtrim (rh); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1894 %! assert (strcmp (lh, rh)); |
21625 | 1895 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1896 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1897 ## Tests reading with empty format, should return proper nr of columns |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1898 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1899 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1900 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1901 %! fprintf (fid, " 1 2 3 4\n5 6 7 8"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1902 %! fseek (fid, 0, "bof"); |
21625 | 1903 %! C = textscan (fid, ""); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1904 %! E = feof (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1905 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1906 %! unlink (f); |
21625 | 1907 %! assert (C{1}, [1 ; 5], 1e-6); |
1908 %! assert (C{2}, [2 ; 6], 1e-6); | |
1909 %! assert (C{3}, [3 ; 7], 1e-6); | |
1910 %! assert (C{4}, [4 ; 8], 1e-6); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1911 %! assert (E); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1912 |
21621
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1913 ## Test leaving the file at the correct position on exit |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1914 %!test |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1915 %! f = tempname (); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1916 %! fid = fopen (f, "w+"); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1917 %! fprintf (fid, "1,2\n3,4\n"); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1918 %! fseek (fid, 0, "bof"); |
21625 | 1919 %! C = textscan (fid, "%s %f", 2, "Delimiter", ","); |
21621
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1920 %! E = ftell (fid); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1921 %! fclose (fid); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1922 %! unlink (f); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1923 %! assert (E, 8); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1924 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1925 ## Tests reading with empty format; empty fields & incomplete lower row |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1926 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1927 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1928 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1929 %! fprintf (fid, " ,2,,4\n5,6"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1930 %! fseek (fid, 0, "bof"); |
21625 | 1931 %! C = textscan (fid, "", "delimiter", ",", "EmptyValue", 999, |
1932 %! "CollectOutput" , 1); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1933 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1934 %! unlink (f); |
21625 | 1935 %! assert (C{1}, [999, 2, 999, 4; 5, 6, 999, 999], 1e-6); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1936 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1937 ## Error message tests |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1938 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1939 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1940 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1941 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1942 %! msg1 = "textscan: 1 parameters given, but only 0 values"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1943 %! try |
21625 | 1944 %! C = textscan (fid, "", "headerlines"); |
31564
332a6ccac881
maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents:
31135
diff
changeset
|
1945 %! end_try_catch |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
1946 %! assert (! feof (fid)); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1947 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1948 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1949 %! assert (msg1, lasterr); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1950 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1951 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1952 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1953 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1954 %! msg1 = "textscan: HeaderLines must be numeric"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1955 %! try |
21625 | 1956 %! C = textscan (fid, "", "headerlines", "hh"); |
31564
332a6ccac881
maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents:
31135
diff
changeset
|
1957 %! end_try_catch |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1958 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1959 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1960 %! assert (msg1, lasterr); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1961 |
21625 | 1962 ## Skip headerlines |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1963 %!test |
21625 | 1964 %! C = textscan ("field 1 field2\n 1 2\n3 4", "", "headerlines", 1, |
1965 %! "collectOutput", 1); | |
1966 %! assert (C, {[1 2; 3 4]}); | |
1967 | |
1968 ## Skip headerlines with non-default EOL | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1969 %!test |
21625 | 1970 %! C = textscan ("field 1 field2\r 1 2\r3 4", "", "headerlines", 2, |
1971 %! "collectOutput", 1, "EndOfLine", '\r'); | |
1972 %! assert (C, {[3 4]}); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1973 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1974 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1975 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1976 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1977 %! fprintf (fid,"some_string"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1978 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1979 %! msg1 = "textscan: EndOfLine must be at most one character or '\\r\\n'"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1980 %! try |
21625 | 1981 %! C = textscan (fid, "%f", "EndOfLine", "\n\r"); |
31564
332a6ccac881
maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents:
31135
diff
changeset
|
1982 %! end_try_catch |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1983 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1984 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1985 %! assert (msg1, lasterr); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1986 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1987 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1988 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1989 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1990 %! fprintf (fid,"some_string"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1991 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1992 %! msg1 = "textscan: EndOfLine must be at most one character or '\\r\\n'"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1993 %! try |
21625 | 1994 %! C = textscan (fid, "%f", "EndOfLine", 33); |
31564
332a6ccac881
maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents:
31135
diff
changeset
|
1995 %! end_try_catch |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1996 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1997 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1998 %! assert (msg1, lasterr); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1999 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
2000 %!assert <*41824> (textscan ("123", "", "whitespace", " "){:}, 123); |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
2001 |
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
2002 ## just test supplied emptyvalue |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
2003 %!assert <*42343> (textscan (",NaN", "", "delimiter", "," ,"emptyValue" ,Inf), |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
2004 %! {Inf, NaN}) |
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
2005 |
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
2006 ## test padding with supplied emptyvalue |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
2007 %!test <*42343> |
21625 | 2008 %! c = textscan (",1,,4\nInf, ,NaN\n", "", "delimiter", ",", |
2009 %! "emptyvalue", -10); | |
2010 %! assert (cell2mat (c), [-10, 1, -10, 4; Inf, -10, NaN, -10]); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2011 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
2012 %!test <*42528> |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2013 %! assert (textscan ("1i", ""){1}, 0+1i); |
21625 | 2014 %! C = textscan ("3, 2-4i, NaN\n -i, 1, 23.4+2.2i\n 1+1 1+1j", "", |
2015 %! "delimiter", ","); | |
2016 %! assert (cell2mat (C), [3+0i, 2-4i, NaN+0i; 0-i, 1+0i, 23.4+2.2i; 1 1 1+1i]); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2017 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2018 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2019 %! ## TreatAsEmpty |
21625 | 2020 %! C = textscan ("1,2,3,NN,5,6\n", "%d%d%d%f", "delimiter", ",", |
2021 %! "TreatAsEmpty", "NN"); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2022 %! assert (C{3}(1), int32 (3)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2023 %! assert (C{4}(1), NaN); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2024 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2025 ## MultipleDelimsAsOne |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2026 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2027 %! str = "11, 12, 13,, 15\n21,, 23, 24, 25\n,, 33, 34, 35\n"; |
21625 | 2028 %! C = textscan (str, "%f %f %f %f", "delimiter", ",", |
2029 %! "multipledelimsasone", 1, "endofline", "\n"); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2030 %! assert (C{1}', [11, 21, 33]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2031 %! assert (C{2}', [12, 23, 34]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2032 %! assert (C{3}', [13, 24, 35]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2033 %! assert (C{4}', [15, 25, NaN]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2034 |
21551
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
2035 ## Single-quoted escape sequences |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
2036 %!test |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
2037 %! str = "11\t12\t13\r21\t22\t23"; |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
2038 %! c = textscan (str, "", "delimiter", '\t', "EndOfLine", '\r'); |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
2039 %! assert (c{1}', [11, 21]); |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
2040 %! assert (c{2}', [12, 22]); |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
2041 %! assert (c{3}', [13, 23]); |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
2042 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
2043 %!test <*44750> |
21625 | 2044 %! c = textscan ("/home/foo/", "%s", "delimiter", "/", |
2045 %! "MultipleDelimsAsOne", 1); | |
2046 %! assert (c{1}, {"home"; "foo"}); | |
2047 | |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2048 ## FIXME: Test still fails (4/13/2016). |
21625 | 2049 ## Allow cuddling %sliteral, but warn it is ambiguous |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2050 %!#test |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2051 %! C = textscan ("abcxyz51\nxyz83\n##xyz101", "%s xyz %d"); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2052 %! assert (C{1}([1 3]), {"abc"; "##"}); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2053 %! assert (isempty (C{1}{2}), true); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2054 %! assert (C{2}, int32 ([51; 83; 101])); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2055 |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2056 ## Literals are not delimiters. |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2057 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2058 ## Test for false positives in check for non-supported format specifiers |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2059 %!test |
21625 | 2060 %! c = textscan ("Total: 32.5 % (of cm values)", |
2061 %! "Total: %f %% (of cm values)"); | |
2062 %! assert (c{1}, 32.5, 1e-5); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2063 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
2064 ## Test various forms of string format specifiers |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
2065 %!test <*45712> |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2066 %! str = "14 :1 z:2 z:3 z:5 z:11"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2067 %! C = textscan (str, "%f %s %*s %3s %*3s %f", "delimiter", ":"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2068 %! assert (C, {14, {"1 z"}, {"3 z"}, 11}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2069 |
21625 | 2070 ## Bit width, fixed width conversion specifiers |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2071 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2072 %! str2 = "123456789012345 "; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2073 %! str2 = [str2 str2 str2 str2 str2 str2 str2 str2]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2074 %! str2 = [str2 "123456789.01234 1234567890.1234 12345.678901234 12345.678901234"]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2075 %! pttrn = "%3u8%*s %5u16%*s %10u32%*s %15u64 %3d8%*s %5d16%*s %10d32%*s %15d64 %9f32%*s %14f64%*s %10.2f32%*s %12.2f64%*s"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2076 %! C = textscan (str2, pttrn, "delimiter", " "); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2077 %! assert (C{1}, uint8 (123)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2078 %! assert (C{2}, uint16 (12345)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2079 %! assert (C{3}, uint32 (1234567890)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2080 %! assert (C{4}, uint64 (123456789012345)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2081 %! assert (C{5}, int8 (123)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2082 %! assert (C{6}, int16 (12345)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2083 %! assert (C{7}, int32 (1234567890)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2084 %! assert (C{8}, int64 (123456789012345)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2085 %! assert (C{9}, single (123456789), 1e-12); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2086 %! assert (C{10}, double (1234567890.123), 1e-15); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2087 %! assert (C{11}, single (12345.68), 1e-5); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2088 %! assert (C{12}, double (12345.68), 1e-11); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2089 |
21625 | 2090 ## Bit width, fixed width conv. specifiers -- check the right amount is left |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2091 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2092 %! str2 = "123456789012345 "; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2093 %! str2 = [str2 str2 "123456789.01234"]; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2094 %! pttrn = "%3u8 %5u16 %10u32 %3d8 %5d16 %10d32 %9f32 %9f"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2095 %! C = textscan (str2, pttrn, "delimiter", " "); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2096 %! assert (C{1}, uint8 (123)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2097 %! assert (C{2}, uint16 (45678)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2098 %! assert (C{3}, uint32 (9012345)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2099 %! assert (C{4}, int8 (123)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2100 %! assert (C{5}, int16 (45678)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2101 %! assert (C{6}, int32 (9012345)); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2102 %! assert (C{7}, single (123456789), 1e-12); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2103 %! assert (C{8}, double (0.01234), 1e-12); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2104 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2105 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2106 %! C = textscan ("123.123", "%2f %3f %3f"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2107 %! assert (C{1}, 12); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2108 %! assert (C{2}, 3.1, 1e-11); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2109 %! assert (C{3}, 23); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2110 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2111 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2112 %! C = textscan ("123.123", "%3f %3f %3f"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2113 %! assert (C{1}, 123); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2114 %! assert (C{2}, 0.12, 1e-11); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2115 %! assert (C{3}, 3); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2116 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2117 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2118 %! C = textscan ("123.123", "%4f %3f"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2119 %! assert (C{1}, 123); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2120 %! assert (C{2}, 123); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2121 |
21625 | 2122 ## field width interrupts exponent. (Matlab incorrectly gives [12, 2e12]) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2123 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2124 %! assert (textscan ("12e12", "%4f"), {[120; 2]}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2125 %! assert (textscan ("12e+12", "%5f"), {[120; 2]}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2126 %! assert (textscan ("125e-12","%6f"), {[12.5; 2]}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2127 |
21625 | 2128 ## %[] tests |
2129 ## Plain [..] and *[..] | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2130 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2131 %! ar = "abcdefguvwxAny\nacegxyzTrailing\nJunk"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2132 %! C = textscan (ar, "%[abcdefg] %*[uvwxyz] %s"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2133 %! assert (C{1}, {"abcdefg"; "aceg"; ""}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2134 %! assert (C{2}, {"Any"; "Trailing"; "Junk"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2135 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2136 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2137 %! assert (textscan ("A2 B2 C3", "%*[ABC]%d", 3), {int32([2; 2; 3])}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2138 |
21625 | 2139 ## [^..] and *[^..] |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2140 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2141 %! br = "abcdefguvwx1Any\nacegxyz2Trailing\n3Junk"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2142 %! C = textscan (br, "%[abcdefg] %*[^0123456789] %s"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2143 %! assert (C{1}, {"abcdefg"; "aceg"; ""}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2144 %! assert (C{2}, {"1Any"; "2Trailing"; "3Junk"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2145 |
21625 | 2146 ## [..] and [^..] containing delimiters |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2147 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2148 %! cr = "ab cd efguv wx1Any\na ce gx yz2Trailing\n 3Junk"; |
21625 | 2149 %! C = textscan (cr, "%[ abcdefg] %*[^0123456789] %s", "delimiter", " \n", |
2150 %! "whitespace", ""); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2151 %! assert (C{1}, {"ab cd efg"; "a ce g"; " "}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2152 %! assert (C{2}, {"1Any"; "2Trailing"; "3Junk"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2153 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
2154 %!assert <*36464> (textscan ("1 2 3 4 5 6", "%*n%n%*[^\n]"){1}, 2); |
21625 | 2155 |
2156 ## test %[]] and %[^]] | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2157 %!test |
21625 | 2158 %! assert (textscan ("345]", "%*[123456]%[]]"){1}{1}, "]"); |
2159 %! assert (textscan ("345]", "%*[^]]%s"){1}{1}, "]"); | |
2160 | |
2161 ## Test that "-i" checks the next two characters | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2162 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2163 %! C = textscan ("-i -in -inf -infinity", "%f %f%s %f %f %s"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2164 %! assert (C, {-i, -i, {"n"}, -Inf, -Inf, {"inity"}}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2165 |
21625 | 2166 ## Again for "+i", this time with custom parser |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2167 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2168 %! C = textscan ("+i +in +inf +infinity", "%f %f%s %f %f %s", "ExpChars", "eE"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2169 %! assert (C, {i, i, {"n"}, Inf, Inf, {"inity"}}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2170 |
21625 | 2171 ## Check single quoted format interprets control sequences |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2172 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2173 %! C = textscan ("1 2\t3 4", '%f %[^\t] %f %f'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2174 %! assert (C, {1, {"2"}, 3, 4}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2175 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2176 ## Check a non-empty line with no valid conversion registers empytValue |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2177 %!test |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2178 %! C = textscan ("Empty\n", "Empty%f %f"); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
2179 %! assert (C, { NaN, NaN }); |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2180 |
21625 | 2181 ## Check overflow and underflow of integer types |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2182 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2183 %! a = "-1e90 "; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2184 %! b = "1e90 "; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2185 %! fmt = "%d8 %d16 %d32 %d64 %u8 %u16 %u32 %u64 "; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2186 %! C = textscan ([a a a a a a a a b b b b b b b b], fmt); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2187 %! assert (C{1}, int8 ([-128; 127])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2188 %! assert (C{2}, int16 ([-32768; 32767])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2189 %! assert (C{3}, int32 ([-2147483648; 2147483647])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2190 %! assert (C{4}, int64 ([-9223372036854775808; 9223372036854775807])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2191 %! assert (C{5}, uint8 ([0; 255])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2192 %! assert (C{6}, uint16 ([0; 65535])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2193 %! assert (C{7}, uint32 ([0; 4294967295])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2194 %! assert (C{8}, uint64 ([0; 18446744073709551615])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2195 |
21625 | 2196 ## Tests from Matlab (does The MathWorks have any copyright over the input?) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2197 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2198 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2199 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2200 %! fprintf (fid,"09/12/2005 Level1 12.34 45 1.23e10 inf Nan Yes 5.1+3i\n"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2201 %! fprintf (fid,"10/12/2005 Level2 23.54 60 9e19 -inf 0.001 No 2.2-.5i\n"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2202 %! fprintf (fid,"11/12/2005 Level3 34.90 12 2e5 10 100 No 3.1+.1i\n"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2203 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2204 %! C = textscan (fid,"%s %s %f32 %d8 %u %f %f %s %f"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2205 %! %assert (C{1}, {"09/12/2005";"10/12/2005";"11/12/2005"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2206 %! assert (C{2}, {"Level1";"Level2";"Level3"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2207 %! assert (C{3}, [single(12.34);single(23.54);single(34.90)]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2208 %! assert (C{4}, [int8(45);int8(60);int8(12)]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2209 %! assert (C{5}, [uint32(4294967295);uint32(4294967295);uint32(200000)]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2210 %! assert (C{6}, [inf;-inf;10]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2211 %! assert (C{7}, [NaN;0.001;100], eps); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2212 %! assert (C{8}, {"Yes";"No";"No"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2213 %! assert (C{9}, [5.1+3i;2.2-0.5i;3.1+0.1i]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2214 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2215 %! C = textscan (fid,"%s Level%d %f32 %d8 %u %f %f %s %f"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2216 %! assert (C{2}, [int32(1);int32(2);int32(3)]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2217 %! assert (C{3}, [single(12.34);single(23.54);single(34.90)]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2218 %! fseek (fid, 0, "bof"); |
21625 | 2219 %! C = textscan (fid, '%s %*[^\n]'); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2220 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2221 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2222 %! assert (C, {{"09/12/2005";"10/12/2005";"11/12/2005"}}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2223 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2224 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2225 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2226 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2227 %! fprintf (fid,"1, 2, 3, 4, , 6\n"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2228 %! fprintf (fid,"7, 8, 9, , 11, 12\n"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2229 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2230 %! C = textscan (fid,"%f %f %f %f %u8 %f", "Delimiter",",","EmptyValue",-Inf); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2231 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2232 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2233 %! assert (C{4}, [4; -Inf]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2234 %! assert (C{5}, uint8 ([0; 11])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2235 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2236 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2237 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2238 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2239 %! fprintf (fid,"abc, 2, NA, 3, 4\n"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2240 %! fprintf (fid,"// Comment Here\n"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2241 %! fprintf (fid,"def, na, 5, 6, 7\n"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2242 %! fseek (fid, 0, "bof"); |
21625 | 2243 %! C = textscan (fid, "%s %n %n %n %n", "Delimiter", ",", |
2244 %! "TreatAsEmpty", {"NA","na"}, "CommentStyle", "//"); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2245 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2246 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2247 %! assert (C{1}, {"abc";"def"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2248 %! assert (C{2}, [2; NaN]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2249 %! assert (C{3}, [NaN; 5]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2250 %! assert (C{4}, [3; 6]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2251 %! assert (C{5}, [4; 7]); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2252 |
21625 | 2253 ## FIXME: Almost passes. Second return value is {"/"}. Tested 4/14/16. |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2254 ## Test start of comment as string |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2255 %!#test |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2256 %! c = textscan ("1 / 2 // 3", "%n %s %u8", "CommentStyle", {"//"}); |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22725
diff
changeset
|
2257 %! assert (c(1), {1, "/", 2}); |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
2258 |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
2259 %!assert (textscan (["1 2 3 4"; "5 6 7 8"], "%f"), {[15; 26; 37; 48]}) |
21566
02826fb0f261
textscan: Fix bug in exponent parsing
Mike Miller <mtmiller@octave.org>
parents:
21551
diff
changeset
|
2260 |
21625 | 2261 ## Check for delimiter after exponent |
21566
02826fb0f261
textscan: Fix bug in exponent parsing
Mike Miller <mtmiller@octave.org>
parents:
21551
diff
changeset
|
2262 %!assert (textscan ("1e-3|42", "%f", "delimiter", "|"), {[1e-3; 42]}) |
24303
ddc91a2ee0e0
Remove all delimiters from whitespace list in textscan function (bug #52479).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
2263 |
ddc91a2ee0e0
Remove all delimiters from whitespace list in textscan function (bug #52479).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
2264 %!test <*52479> |
ddc91a2ee0e0
Remove all delimiters from whitespace list in textscan function (bug #52479).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
2265 %! str = "\t\ta\tb\tc\n"; |
ddc91a2ee0e0
Remove all delimiters from whitespace list in textscan function (bug #52479).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
2266 %! ret = textscan (str, "%s", "delimiter", "\t"); |
24346
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2267 %! assert (ret, { {''; ''; 'a'; 'b'; 'c'} }); |
24303
ddc91a2ee0e0
Remove all delimiters from whitespace list in textscan function (bug #52479).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
2268 |
26946
04e5cb5e2cb3
update bug status in tests
John W. Eaton <jwe@octave.org>
parents:
26867
diff
changeset
|
2269 %!test <*52479> |
24303
ddc91a2ee0e0
Remove all delimiters from whitespace list in textscan function (bug #52479).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
2270 %! str = "\t\ta\tb\tc\n"; |
ddc91a2ee0e0
Remove all delimiters from whitespace list in textscan function (bug #52479).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
2271 %! ret = textscan (str, "%s", "delimiter", {"\t"}); |
24346
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2272 %! assert (ret, { {''; ''; 'a'; 'b'; 'c'} }); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2273 |
26946
04e5cb5e2cb3
update bug status in tests
John W. Eaton <jwe@octave.org>
parents:
26867
diff
changeset
|
2274 %!test <*52550> |
24346
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2275 %! str = ",,1,2,3\n"; |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2276 %! obs = textscan (str, "%d", "delimiter", ","); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2277 %! assert (obs, { [0; 0; 1; 2; 3] }); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2278 %! obs = textscan (str, "%d", "delimiter", {","}); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2279 %! assert (obs, { [0; 0; 1; 2; 3] }); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2280 |
26946
04e5cb5e2cb3
update bug status in tests
John W. Eaton <jwe@octave.org>
parents:
26867
diff
changeset
|
2281 %!test <*52550> |
24346
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2282 %! str = " , ,1,2,3\n"; |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2283 %! obs = textscan (str, "%d", "delimiter", ","); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2284 %! assert (obs, { [0; 0; 1; 2; 3] }); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2285 %! textscan (str, "%d", "delimiter", {","}); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2286 %! assert (obs, { [0; 0; 1; 2; 3] }); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2287 |
26946
04e5cb5e2cb3
update bug status in tests
John W. Eaton <jwe@octave.org>
parents:
26867
diff
changeset
|
2288 %!test <*52550> |
24346
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2289 %! str = " 0 , 5+6j , -INF+INFj ,NaN,3\n"; |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2290 %! obs = textscan (str, "%f", "delimiter", ","); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2291 %! assert (obs, { [0; 5+6i; complex(-Inf,Inf); NaN; 3] }); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2292 %! obs = textscan (str, "%f", "delimiter", {","}); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2293 %! assert (obs, { [0; 5+6i; complex(-Inf,Inf); NaN; 3] }); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2294 |
26946
04e5cb5e2cb3
update bug status in tests
John W. Eaton <jwe@octave.org>
parents:
26867
diff
changeset
|
2295 %!test <*52550> |
24346
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2296 %! str = " 0;,;,1;,2;,3\n"; |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2297 %! assert (textscan (str, "%f", "delimiter", {";,"}), { [0; NaN; 1; 2; 3] }); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2298 |
26946
04e5cb5e2cb3
update bug status in tests
John W. Eaton <jwe@octave.org>
parents:
26867
diff
changeset
|
2299 %!test <*52550> |
24346
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2300 %! str = " 0 ;1 , $ 2 ;3\n"; |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2301 %! obs = textscan (str, "%f", "delimiter", ",;$"); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2302 %! assert (obs, { [0; 1; NaN; 2; 3] }); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2303 %! obs = textscan (str, "%f", "delimiter", {",",";","$"}); |
f77da8da0f3f
Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24310
diff
changeset
|
2304 %! assert (obs, { [0; 1; NaN; 2; 3] }); |
24303
ddc91a2ee0e0
Remove all delimiters from whitespace list in textscan function (bug #52479).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
2305 |
26706
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2306 ## file stream with encoding |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2307 %!test |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2308 %! f = tempname (); |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2309 %! fid = fopen (f, "w+", "n", "iso-8859-1"); |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2310 %! unwind_protect |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2311 %! fprintf (fid, "abc,äöü\n"); |
30822
0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30790
diff
changeset
|
2312 %! fflush (fid); |
26706
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2313 %! fseek (fid, 0, "bof"); |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2314 %! obs = textscan (fid, "%s", "delimiter", ","); |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2315 %! fclose (fid); |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2316 %! assert (obs, { {"abc"; "äöü"} }); |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2317 %! unwind_protect_cleanup |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2318 %! unlink (f); |
ccea3574f36b
Support encoding of file streams in textscan (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26705
diff
changeset
|
2319 %! end_unwind_protect |
27424
17b915ad4b73
Fix error with %q format and textscan (bug #56917).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
2320 |
17b915ad4b73
Fix error with %q format and textscan (bug #56917).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
2321 %!test <*56917> |
17b915ad4b73
Fix error with %q format and textscan (bug #56917).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
2322 %! str = '"a,b","c"'; |
17b915ad4b73
Fix error with %q format and textscan (bug #56917).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
2323 %! obs = textscan (str, "%q", "delimiter", ","); |
17b915ad4b73
Fix error with %q format and textscan (bug #56917).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
2324 %! assert (obs, { { "a,b"; "c" } }); |
17b915ad4b73
Fix error with %q format and textscan (bug #56917).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
2325 |
28182
56349d9ca566
Fix textscan when literal and delimiter might be the same character (bug #58008).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
2326 %!test <*58008> |
56349d9ca566
Fix textscan when literal and delimiter might be the same character (bug #58008).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
2327 %! txt = sprintf ('literal_other_1_1;literal_other_1_2\nliteral_other_2_1;literal_other_2_2\nliteral_other_3_1;literal_other_3_2'); |
56349d9ca566
Fix textscan when literal and delimiter might be the same character (bug #58008).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
2328 %! nm1 = textscan (txt, 'literal%s literal%s', 'Delimiter', ';'); |
56349d9ca566
Fix textscan when literal and delimiter might be the same character (bug #58008).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
2329 %! assert (nm1{1}, {"_other_1_1" ; "_other_2_1" ; "_other_3_1"}); |
56349d9ca566
Fix textscan when literal and delimiter might be the same character (bug #58008).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
2330 %! assert (nm1{2}, {"_other_1_2" ; "_other_2_2" ; "_other_3_2"}); |
56349d9ca566
Fix textscan when literal and delimiter might be the same character (bug #58008).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
2331 %! nm2 = textscan (txt, 'literal%s;literal%s', 'Delimiter', ';'); |
56349d9ca566
Fix textscan when literal and delimiter might be the same character (bug #58008).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
2332 %! assert (nm1, nm2); |
56349d9ca566
Fix textscan when literal and delimiter might be the same character (bug #58008).
Rik <rik@octave.org>
parents:
28087
diff
changeset
|
2333 |
28183
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2334 %!test <*57612> |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2335 %! str = sprintf (['101,' '\n' '201,']); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2336 %! C = textscan (str, '%s%q', 'Delimiter', ','); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2337 %! assert (size (C), [1, 2]); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2338 %! assert (C{1}, { "101"; "201" }); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2339 %! assert (C{2}, { ""; "" }); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2340 |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2341 %!test <*57612> |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2342 %! str = sprintf (['101,' '\n' '201,']); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2343 %! C = textscan (str, '%s%f', 'Delimiter', ','); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2344 %! assert (size (C), [1, 2]); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2345 %! assert (C{1}, { "101"; "201" }); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2346 %! assert (C{2}, [ NaN; NaN ]); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2347 |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2348 %!test <*57612> |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2349 %! str = sprintf (['101,' '\n' '201,']); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2350 %! C = textscan (str, '%s%d', 'Delimiter', ','); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2351 %! assert (size (C), [1, 2]); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2352 %! assert (C{1}, { "101"; "201" }); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2353 %! assert (C{2}, int32 ([ 0; 0 ])); |
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2354 |
28184
c805c1b541fa
test: Add BIST test for textscan (Bug #51093).
Rik <rik@octave.org>
parents:
28183
diff
changeset
|
2355 %!test <*51093> |
c805c1b541fa
test: Add BIST test for textscan (Bug #51093).
Rik <rik@octave.org>
parents:
28183
diff
changeset
|
2356 %! str = sprintf ('a\t\tb\tc'); |
c805c1b541fa
test: Add BIST test for textscan (Bug #51093).
Rik <rik@octave.org>
parents:
28183
diff
changeset
|
2357 %! C = textscan (str, '%s', 'Delimiter', '\t', 'MultipleDelimsAsOne', false); |
c805c1b541fa
test: Add BIST test for textscan (Bug #51093).
Rik <rik@octave.org>
parents:
28183
diff
changeset
|
2358 %! assert (C{1}, {'a'; ''; 'b'; 'c'}); |
c805c1b541fa
test: Add BIST test for textscan (Bug #51093).
Rik <rik@octave.org>
parents:
28183
diff
changeset
|
2359 |
29494
76269aa97398
if bug number is supplied, prefer '%!test' over '%!xtest'
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
2360 %!test <50743> |
28185
493d46a02edc
test: Add %!xtest for bug #50743 so it is not forgotten (bug #50743).
Rik <rik@octave.org>
parents:
28184
diff
changeset
|
2361 %! C = textscan ('5973459727478852968', '%u64'); |
493d46a02edc
test: Add %!xtest for bug #50743 so it is not forgotten (bug #50743).
Rik <rik@octave.org>
parents:
28184
diff
changeset
|
2362 %! assert (C{1}, uint64 (5973459727478852968)); |
493d46a02edc
test: Add %!xtest for bug #50743 so it is not forgotten (bug #50743).
Rik <rik@octave.org>
parents:
28184
diff
changeset
|
2363 |
30790
5fbc41f7a8d1
textscan: Reposition scan pointer after reading a single `.` (bug #60711).
Gaël Bonithon <gael@xfce.org>
parents:
30565
diff
changeset
|
2364 %!assert <*60711> (textscan('1,.,2', '%f', 'Delimiter', ','), {1}); |
5fbc41f7a8d1
textscan: Reposition scan pointer after reading a single `.` (bug #60711).
Gaël Bonithon <gael@xfce.org>
parents:
30565
diff
changeset
|
2365 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2366 */ |
28183
abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
Rik <rik@octave.org>
parents:
28182
diff
changeset
|
2367 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2368 // These tests have end-comment sequences, so can't just be in a comment |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2369 #if 0 |
21625 | 2370 ## Test unfinished comment |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2371 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2372 %! c = textscan ("1 2 /* half comment", "%n %u8", "CommentStyle", {"/*", "*/"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2373 %! assert (c, {1, 2}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2374 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2375 ## Test reading from a real file |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2376 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2377 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2378 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2379 %! d = rand (1, 4); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2380 %! fprintf (fid, " %f %f /* comment */ %f %f ", d); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2381 %! fseek (fid, 0, "bof"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2382 %! A = textscan (fid, "%f %f", "CommentStyle", {"/*", "*/"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2383 %! E = feof (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2384 %! fclose (fid); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2385 %! unlink (f); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2386 %! assert (A{1}, [d(1); d(3)], 1e-6); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2387 %! assert (A{2}, [d(2); d(4)], 1e-6); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2388 %! assert (E); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2389 #endif |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2390 |
21625 | 2391 /* |
2392 ## Test input validation | |
2393 %!error textscan () | |
26640
c18e59476795
file id must not be single for textscan and other file I/O funcs (bug #55577)
Mike Miller <mtmiller@octave.org>
parents:
26378
diff
changeset
|
2394 %!error <file id must be> textscan (single (4)) |
c18e59476795
file id must not be single for textscan and other file I/O funcs (bug #55577)
Mike Miller <mtmiller@octave.org>
parents:
26378
diff
changeset
|
2395 %!error <file id must be> textscan ({4}) |
21625 | 2396 %!error <must be a string> textscan ("Hello World", 2) |
2397 %!error <at most one character or> | |
2398 %! textscan ("Hello World", "%s", "EndOfLine", 3); | |
2399 %!error <'%z' is not a valid format specifier> textscan ("1.0", "%z") | |
2400 %!error <no valid format conversion specifiers> textscan ("1.0", "foo") | |
2401 */ | |
2402 | |
2116 | 2403 static octave_value |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2404 do_fread (stream& os, const octave_value& size_arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2405 const octave_value& prec_arg, const octave_value& skip_arg, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2406 const octave_value& arch_arg, octave_idx_type& count) |
2116 | 2407 { |
2408 count = -1; | |
2409 | |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2410 Array<double> size = size_arg.xvector_value ("fread: invalid SIZE specified"); |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2411 |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2412 std::string prec = prec_arg.xstring_value ("fread: PRECISION must be a string"); |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2413 |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2414 int block_size = 1; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2415 oct_data_conv::data_type input_type; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2416 oct_data_conv::data_type output_type; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2417 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2418 try |
2116 | 2419 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2420 oct_data_conv::string_to_data_type (prec, block_size, |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2421 input_type, output_type); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2422 } |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2423 catch (execution_exception& ee) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2424 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29117
diff
changeset
|
2425 error (ee, "fread: invalid PRECISION specified"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2426 } |
4944 | 2427 |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
2428 int skip = 0; |
3202 | 2429 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2430 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2431 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2432 skip = skip_arg.int_value (true); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2433 } |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2434 catch (execution_exception& ee) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2435 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29117
diff
changeset
|
2436 error (ee, "fread: SKIP must be an integer"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2437 } |
2116 | 2438 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2439 std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string"); |
2116 | 2440 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2441 mach_info::float_format flt_fmt |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2442 = mach_info::string_to_float_format (arch); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2443 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2444 return os.read (size, block_size, input_type, output_type, skip, |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2445 flt_fmt, count); |
2116 | 2446 } |
2447 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2448 DEFMETHOD (fread, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2449 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2450 @deftypefn {} {@var{val} =} fread (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2451 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2452 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2453 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2454 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip}, @var{arch}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2455 @deftypefnx {} {[@var{val}, @var{count}] =} fread (@dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2456 Read binary data from the file specified by the file descriptor @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2457 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2458 The optional argument @var{size} specifies the amount of data to read |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2459 and may be one of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2460 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2461 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2462 @item Inf |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2463 Read as much as possible, returning a column vector. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2464 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2465 @item @var{nr} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2466 Read up to @var{nr} elements, returning a column vector. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2467 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2468 @item [@var{nr}, Inf] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2469 Read as much as possible, returning a matrix with @var{nr} rows. If the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2470 number of elements read is not an exact multiple of @var{nr}, the last |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2471 column is padded with zeros. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2472 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2473 @item [@var{nr}, @var{nc}] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2474 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2475 @var{nr} rows. If the number of elements read is not an exact multiple |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2476 of @var{nr}, the last column is padded with zeros. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2477 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2478 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2479 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2480 If @var{size} is omitted, a value of @code{Inf} is assumed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2481 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2482 The optional argument @var{precision} is a string specifying the type of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2483 data to read and may be one of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2484 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2485 @table @asis |
23982
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2486 @item @qcode{"uint8"} (default) |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2487 8-bit unsigned integer. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2488 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2489 @item @qcode{"int8"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2490 @itemx @qcode{"integer*1"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2491 8-bit signed integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2492 |
23982
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2493 @item @qcode{"uint16"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2494 @itemx @qcode{"ushort"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2495 @itemx @qcode{"unsigned short"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2496 16-bit unsigned integer. |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2497 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2498 @item @qcode{"int16"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2499 @itemx @qcode{"integer*2"} |
23982
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2500 @itemx @qcode{"short"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2501 16-bit signed integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2502 |
23982
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2503 @item @qcode{"uint"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2504 @itemx @qcode{"uint32"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2505 @itemx @qcode{"unsigned int"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2506 @itemx @qcode{"ulong"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2507 @itemx @qcode{"unsigned long"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2508 32-bit unsigned integer. |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2509 |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2510 @item @qcode{"int"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2511 @itemx @qcode{"int32"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2512 @itemx @qcode{"integer*4"} |
23982
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2513 @itemx @qcode{"long"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2514 32-bit signed integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2515 |
23982
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2516 @item @qcode{"uint64"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2517 64-bit unsigned integer. |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2518 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2519 @item @qcode{"int64"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2520 @itemx @qcode{"integer*8"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2521 64-bit signed integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2522 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2523 @item @qcode{"single"} |
23949
58435a400d4e
Document that fread 'float' size is 32 bits (bug #41672).
Rik <rik@octave.org>
parents:
23924
diff
changeset
|
2524 @itemx @qcode{"float"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2525 @itemx @qcode{"float32"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2526 @itemx @qcode{"real*4"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2527 32-bit floating point number. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2528 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2529 @item @qcode{"double"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2530 @itemx @qcode{"float64"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2531 @itemx @qcode{"real*8"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2532 64-bit floating point number. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2533 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2534 @item @qcode{"char"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2535 @itemx @qcode{"char*1"} |
23982
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2536 8-bit single character. |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2537 |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2538 @item @qcode{"uchar"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2539 @itemx @qcode{"unsigned char"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2540 8-bit unsigned character. |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2541 |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2542 @item @qcode{"schar"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2543 @itemx @qcode{"signed char"} |
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2544 8-bit signed character. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2545 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2546 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2547 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2548 @noindent |
23982
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2549 The default precision is @qcode{"uint8"}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2550 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2551 The @var{precision} argument may also specify an optional repeat |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2552 count. For example, @samp{32*single} causes @code{fread} to read |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2553 a block of 32 single precision floating point numbers. Reading in |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2554 blocks is useful in combination with the @var{skip} argument. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2555 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2556 The @var{precision} argument may also specify a type conversion. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2557 For example, @samp{int16=>int32} causes @code{fread} to read 16-bit |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2558 integer values and return an array of 32-bit integer values. By |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2559 default, @code{fread} returns a double precision array. The special |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2560 form @samp{*TYPE} is shorthand for @samp{TYPE=>TYPE}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2561 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2562 The conversion and repeat counts may be combined. For example, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2563 specification @samp{32*single=>single} causes @code{fread} to read |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2564 blocks of single precision floating point values and return an array |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2565 of single precision values instead of the default array of double |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2566 precision values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2567 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2568 The optional argument @var{skip} specifies the number of bytes to skip |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2569 after each element (or block of elements) is read. If it is not |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2570 specified, a value of 0 is assumed. If the final block read is not |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2571 complete, the final skip is omitted. For example, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2572 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2573 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2574 fread (f, 10, "3*single=>single", 8) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2575 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2576 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2577 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2578 will omit the final 8-byte skip because the last read will not be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2579 a complete block of 3 values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2580 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2581 The optional argument @var{arch} is a string specifying the data format |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2582 for the file. Valid values are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2583 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2584 @table @asis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2585 @item @qcode{"native"} or @qcode{"n"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2586 The format of the current machine. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2587 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2588 @item @qcode{"ieee-be"} or @qcode{"b"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2589 IEEE big endian. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2590 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2591 @item @qcode{"ieee-le"} or @qcode{"l"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2592 IEEE little endian. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2593 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2594 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2595 If no @var{arch} is given the value used in the call to @code{fopen} which |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2596 created the file descriptor is used. Otherwise, the value specified with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2597 @code{fread} overrides that of @code{fopen} and determines the data format. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2598 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2599 The output argument @var{val} contains the data read from the file. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2600 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2601 The optional return value @var{count} contains the number of elements read. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2602 @seealso{fwrite, fgets, fgetl, fscanf, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2603 @end deftypefn */) |
529 | 2604 { |
2116 | 2605 int nargin = args.length (); |
2606 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2607 if (nargin < 1 || nargin > 5) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2608 print_usage (); |
2116 | 2609 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2610 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2611 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2612 stream os = streams.lookup (args(0), "fread"); |
2116 | 2613 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2614 octave_value size = lo_ieee_inf_value (); |
23982
3706091dc91c
Make fread, fwrite precisions compatible with Matlab (bug #41672).
Rik <rik@octave.org>
parents:
23949
diff
changeset
|
2615 octave_value prec = "uint8"; |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2616 octave_value skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2617 octave_value arch = "unknown"; |
2116 | 2618 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2619 int idx = 1; |
2116 | 2620 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2621 if (nargin > idx && ! args(idx).is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2622 size = args(idx++); |
2116 | 2623 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2624 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2625 prec = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2626 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2627 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2628 skip = args(idx++); |
4257 | 2629 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2630 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2631 arch = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2632 else if (skip.is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2633 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2634 arch = skip; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2635 skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2636 } |
2116 | 2637 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2638 octave_idx_type count = -1; |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
2639 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2640 octave_value tmp = do_fread (os, size, prec, skip, arch, count); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2641 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2642 return ovl (tmp, count); |
529 | 2643 } |
2644 | |
2116 | 2645 static int |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2646 do_fwrite (stream& os, const octave_value& data, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2647 const octave_value& prec_arg, const octave_value& skip_arg, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2648 const octave_value& arch_arg) |
2116 | 2649 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
2650 std::string prec = prec_arg.xstring_value ("fwrite: PRECISION must be a string"); |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
2651 |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
2652 int block_size = 1; |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
2653 oct_data_conv::data_type output_type; |
2116 | 2654 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2655 try |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
2656 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2657 oct_data_conv::string_to_data_type (prec, block_size, output_type); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2658 } |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2659 catch (execution_exception& ee) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2660 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29117
diff
changeset
|
2661 error (ee, "fwrite: invalid PRECISION specified"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2662 } |
2116 | 2663 |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
2664 int skip = 0; |
3202 | 2665 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2666 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2667 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2668 skip = skip_arg.int_value (true); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2669 } |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2670 catch (execution_exception& ee) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2671 { |
29163
8f67ad8b3103
maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents:
29117
diff
changeset
|
2672 error (ee, "fwrite: SKIP must be an integer"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2673 } |
2116 | 2674 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2675 std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string"); |
2116 | 2676 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2677 mach_info::float_format flt_fmt |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2678 = mach_info::string_to_float_format (arch); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2679 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2680 return os.write (data, block_size, output_type, skip, flt_fmt); |
2116 | 2681 } |
2682 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2683 DEFMETHOD (fwrite, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2684 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2685 @deftypefn {} {@var{count} =} fwrite (@var{fid}, @var{data}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2686 @deftypefnx {} {@var{count} =} fwrite (@var{fid}, @var{data}, @var{precision}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2687 @deftypefnx {} {@var{count} =} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2688 @deftypefnx {} {@var{count} =} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip}, @var{arch}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2689 Write data in binary form to the file specified by the file descriptor |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2690 @var{fid}. |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2691 |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2692 The argument @var{data} is a matrix of values that are to be written to the |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2693 file. The values are extracted in column-major order. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2694 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2695 The remaining arguments @var{precision}, @var{skip}, and @var{arch} are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2696 optional, and are interpreted as described for @code{fread}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2697 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2698 The output @var{count} is the number of data items successfully written. |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2699 |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2700 Programming Note: The behavior of @code{fwrite} is undefined if the values in |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2701 @var{data} are too large to fit in the specified precision. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2702 @seealso{fread, fputs, fprintf, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2703 @end deftypefn */) |
1181 | 2704 { |
2116 | 2705 int nargin = args.length (); |
2706 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2707 if (nargin < 2 || nargin > 5) |
5823 | 2708 print_usage (); |
2116 | 2709 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2710 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2711 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2712 stream os = streams.lookup (args(0), "fwrite"); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2713 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2714 octave_value prec = "uchar"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2715 octave_value skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2716 octave_value arch = "unknown"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2717 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2718 int idx = 1; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2719 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2720 octave_value data = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2721 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2722 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2723 prec = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2724 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2725 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2726 skip = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2727 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2728 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2729 arch = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2730 else if (skip.is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2731 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2732 arch = skip; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2733 skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2734 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2735 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
2736 return ovl (do_fwrite (os, data, prec, skip, arch)); |
1181 | 2737 } |
2738 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2739 DEFMETHODX ("feof", Ffeof, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2740 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2741 @deftypefn {} {@var{status} =} feof (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2742 Return 1 if an end-of-file condition has been encountered for the file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2743 specified by file descriptor @var{fid} and 0 otherwise. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2744 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2745 Note that @code{feof} will only return 1 if the end of the file has already |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2746 been encountered, not if the next read operation will result in an |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2747 end-of-file condition. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2748 @seealso{fread, frewind, fseek, fclear, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2749 @end deftypefn */) |
529 | 2750 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2751 if (args.length () != 1) |
5823 | 2752 print_usage (); |
444 | 2753 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2754 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2755 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2756 stream os = streams.lookup (args(0), "feof"); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2757 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
2758 return ovl (os.eof () ? 1.0 : 0.0); |
444 | 2759 } |
2760 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2761 DEFMETHODX ("ferror", Fferror, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2762 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2763 @deftypefn {} {@var{msg} =} ferror (@var{fid}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2764 @deftypefnx {} {[@var{msg}, @var{err}] =} ferror (@var{fid}) |
22725
37e53505e2eb
doc: Use Texinfo dots macro to create ellipses.
Rik <rik@octave.org>
parents:
22720
diff
changeset
|
2765 @deftypefnx {} {[@dots{}] =} ferror (@var{fid}, "clear") |
24933
75a748cb08a6
doc: end first sentences of doc strings with a period (bug #53388)
Mike Miller <mtmiller@octave.org>
parents:
24801
diff
changeset
|
2766 Query the error status of the stream specified by file descriptor @var{fid}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2767 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2768 If an error condition exists then return a string @var{msg} describing the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2769 error. Otherwise, return an empty string @qcode{""}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2770 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2771 The second input @qcode{"clear"} is optional. If supplied, the error |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2772 state on the stream will be cleared. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2773 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2774 The optional second output is a numeric indication of the error status. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2775 @var{err} is 1 if an error condition has been encountered and 0 otherwise. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2776 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2777 Note that @code{ferror} indicates if an error has already occurred, not |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2778 whether the next operation will result in an error condition. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2779 @seealso{fclear, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2780 @end deftypefn */) |
1230 | 2781 { |
2095 | 2782 int nargin = args.length (); |
1230 | 2783 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2784 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2785 print_usage (); |
1230 | 2786 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2787 stream_list& streams = interp.get_stream_list (); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2788 |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2789 stream os = streams.lookup (args(0), "ferror"); |
1230 | 2790 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2791 bool clear = false; |
2095 | 2792 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2793 if (nargin == 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2794 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2795 std::string opt = args(1).string_value (); |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
2796 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2797 clear = (opt == "clear"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2798 } |
1755 | 2799 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2800 int error_number = 0; |
1230 | 2801 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2802 std::string error_message = os.error (clear, error_number); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2803 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2804 return ovl (error_message, error_number); |
1230 | 2805 } |
2806 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2807 DEFMETHODX ("popen", Fpopen, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2808 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2809 @deftypefn {} {@var{fid} =} popen (@var{command}, @var{mode}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2810 Start a process and create a pipe. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2811 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2812 The name of the command to run is given by @var{command}. The argument |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2813 @var{mode} may be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2814 |
22720
766b0163b3b7
doc: Don't create @tables of type @code with @qcode entries.
Rik <rik@octave.org>
parents:
22511
diff
changeset
|
2815 @table @asis |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2816 @item @qcode{"r"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2817 The pipe will be connected to the standard output of the process, and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2818 open for reading. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2819 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2820 @item @qcode{"w"} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2821 The pipe will be connected to the standard input of the process, and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2822 open for writing. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2823 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2824 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2825 The file identifier corresponding to the input or output stream of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2826 process is returned in @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2827 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2828 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2829 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2830 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2831 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2832 fid = popen ("ls -ltr / | tail -3", "r"); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2833 while (ischar (s = fgets (fid))) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2834 fputs (stdout, s); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2835 endwhile |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2836 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2837 @print{} drwxr-xr-x 33 root root 3072 Feb 15 13:28 etc |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2838 @print{} drwxr-xr-x 3 root root 1024 Feb 15 13:28 lib |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2839 @print{} drwxrwxrwt 15 root root 2048 Feb 17 14:53 tmp |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2840 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2841 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2842 @seealso{popen2} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2843 @end deftypefn */) |
1230 | 2844 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2845 if (args.length () != 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2846 print_usage (); |
1230 | 2847 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2848 std::string name = args(0).xstring_value ("popen: COMMAND must be a string"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2849 std::string mode = args(1).xstring_value ("popen: MODE must be a string"); |
1230 | 2850 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2851 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2852 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2853 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2854 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2855 if (mode == "r") |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2856 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2857 stream ips = octave_iprocstream::create (name); |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22837
diff
changeset
|
2858 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2859 retval = streams.insert (ips); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2860 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2861 else if (mode == "w") |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2862 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2863 stream ops = octave_oprocstream::create (name); |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22837
diff
changeset
|
2864 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2865 retval = streams.insert (ops); |
2095 | 2866 } |
1230 | 2867 else |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2868 error ("popen: invalid MODE specified"); |
1230 | 2869 |
2870 return retval; | |
2871 } | |
2872 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2873 DEFMETHODX ("pclose", Fpclose, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2874 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2875 @deftypefn {} {@var{status} =} pclose (@var{fid}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2876 Close a file identifier @var{fid} that was opened by @code{popen}. |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2877 |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2878 If successful, @code{fclose} returns 0, otherwise, it returns -1. |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2879 |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2880 Programming Note: The function @code{fclose} may also be used for the same |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
2881 purpose. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2882 @seealso{fclose, popen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2883 @end deftypefn */) |
1230 | 2884 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2885 if (args.length () != 1) |
5823 | 2886 print_usage (); |
1379 | 2887 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2888 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2889 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
2890 return ovl (streams.remove (args(0), "pclose")); |
1379 | 2891 } |
2892 | |
30881
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2893 DEFUN (tempdir, args, , |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2894 doc: /* -*- texinfo -*- |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2895 @deftypefn {} {@var{dir} =} tempdir () |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2896 Return the name of the host system's directory for temporary files. |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2897 |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2898 The directory name is taken first from the environment variable @env{TMPDIR}. |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2899 If that does not exist, the environment variable @env{TMP} (and on Windows |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2900 platforms also with higher priority the environment variable @env{TEMP}) is |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2901 checked. If none of those are set, the system default returned by |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2902 @code{P_tmpdir} is used. |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2903 @seealso{P_tmpdir, tempname, mkstemp, tmpfile} |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2904 @end deftypefn */) |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2905 { |
31603
23520a50d74d
maint: Review C++ files for style and coding conventions.
Rik <rik@octave.org>
parents:
31564
diff
changeset
|
2906 if (args.length () > 0) |
30881
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2907 print_usage (); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2908 |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2909 std::string tmpdir = sys::env::get_temp_directory (); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2910 |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2911 if (! sys::file_ops::is_dir_sep (tmpdir.back ())) |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2912 tmpdir += sys::file_ops::dir_sep_str (); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2913 |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2914 return ovl (tmpdir); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2915 } |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2916 |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2917 /* |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2918 %!assert (ischar (tempdir ())) |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2919 |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2920 %!test |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2921 %! old_wstate = warning ("off"); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2922 %! old_tmpdir = getenv ("TMPDIR"); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2923 %! unwind_protect |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2924 %! setenv ("TMPDIR", "__MY_TMP_DIR__"); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2925 %! assert (tempdir (), ["__MY_TMP_DIR__" filesep()]); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2926 %! unwind_protect_cleanup |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2927 %! if (! isempty (old_tmpdir)) |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2928 %! setenv ("TMPDIR", old_tmpdir); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2929 %! else |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2930 %! unsetenv ("TMPDIR"); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2931 %! endif |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2932 %! warning (old_wstate); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2933 %! end_unwind_protect |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2934 */ |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
2935 |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2936 DEFUN (tempname, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2937 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2938 @deftypefn {} {@var{fname} =} tempname () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2939 @deftypefnx {} {@var{fname} =} tempname (@var{dir}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2940 @deftypefnx {} {@var{fname} =} tempname (@var{dir}, @var{prefix}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2941 Return a unique temporary filename as a string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2942 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2943 If @var{prefix} is omitted, a value of @qcode{"oct-"} is used. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2944 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2945 If @var{dir} is also omitted, the default directory for temporary files |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2946 (@code{P_tmpdir}) is used. If @var{dir} is provided, it must exist, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2947 otherwise the default directory for temporary files is used. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2948 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2949 Programming Note: Because the named file is not opened by @code{tempname}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2950 it is possible, though relatively unlikely, that it will not be available |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2951 by the time your program attempts to open it. If this is a concern, |
28960
e5a1087f15d5
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents:
28715
diff
changeset
|
2952 @pxref{XREFtmpfile,,@code{tmpfile}}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2953 @seealso{mkstemp, tempdir, P_tmpdir, tmpfile} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
2954 @end deftypefn */) |
1802 | 2955 { |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2956 int nargin = args.length (); |
2936 | 2957 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2958 if (nargin > 2) |
5823 | 2959 print_usage (); |
1802 | 2960 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2961 std::string dir; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2962 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2963 if (nargin > 0) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2964 dir = args(0).xstring_value ("tempname: DIR must be a string"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2965 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2966 std::string pfx ("oct-"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2967 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2968 if (nargin > 1) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2969 pfx = args(1).xstring_value ("tempname: PREFIX must be a string"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2970 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2971 return ovl (sys::tempnam (dir, pfx)); |
1802 | 2972 } |
2973 | |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2974 /* |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2975 %!test |
24662
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2976 %! envvar = {"TMPDIR", "TMP"}; |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2977 %! envdir = cellfun (@(x) getenv (x), envvar, "uniformoutput", false); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2978 %! unwind_protect |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2979 %! cellfun (@(x) unsetenv (x), envvar); |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2980 %! envname = "TMPDIR"; |
24662
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2981 %! def_tmpdir = P_tmpdir; |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2982 %! ## Strip trailing file separators from P_tmpdir |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2983 %! while (length (def_tmpdir) > 2 && any (def_tmpdir(end) == filesep ("all"))) |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2984 %! def_tmpdir(end) = []; |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2985 %! endwhile |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
2986 %! |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2987 %! ## Test 0-argument form |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2988 %! fname = tempname (); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2989 %! [tmpdir, tmpfname] = fileparts (fname); |
21457
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2990 %! assert (tmpdir, def_tmpdir); |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2991 %! assert (tmpfname (1:4), "oct-"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2992 %! ## Test 1-argument form |
21457
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2993 %! tmp_tmpdir = [def_tmpdir filesep() substr(tmpfname, -5)]; |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2994 %! mkdir (tmp_tmpdir) || error ("Unable to create tmp dir"); |
21457
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2995 %! setenv (envname, def_tmpdir); |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2996 %! fname = tempname (tmp_tmpdir); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2997 %! [tmpdir, tmpfname] = fileparts (fname); |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2998 %! assert (tmpdir, tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2999 %! assert (tmpfname (1:4), "oct-"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3000 %! ## Test 1-argument form w/null tmpdir |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3001 %! fname = tempname (""); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
3002 %! [tmpdir, tmpfname] = fileparts (fname); |
21457
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
3003 %! assert (tmpdir, def_tmpdir); |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3004 %! assert (tmpfname (1:4), "oct-"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
3005 %! ## Test 2-argument form |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3006 %! fname = tempname (tmp_tmpdir, "pfx-"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
3007 %! [tmpdir, tmpfname] = fileparts (fname); |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3008 %! assert (tmpdir, tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3009 %! assert (tmpfname (1:4), "pfx-"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3010 %! ## Test 2-argument form w/null prefix |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3011 %! fname = tempname (tmp_tmpdir, ""); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
3012 %! [tmpdir, tmpfname] = fileparts (fname); |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3013 %! assert (tmpdir, tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3014 %! assert (tmpfname (1:4), "file"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3015 %! unwind_protect_cleanup |
28087
9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents:
28052
diff
changeset
|
3016 %! sts = rmdir (tmp_tmpdir); |
24662
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
3017 %! for i = 1:numel (envvar) |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
3018 %! if (isempty (envdir{i})) |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
3019 %! unsetenv (envvar{i}); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
3020 %! else |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
3021 %! setenv (envvar{i}, envdir{i}); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
3022 %! endif |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
3023 %! endfor |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3024 %! end_unwind_protect |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3025 */ |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
3026 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3027 DEFMETHOD (tmpfile, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3028 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3029 @deftypefn {} {[@var{fid}, @var{msg}] =} tmpfile () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3030 Return the file ID corresponding to a new temporary file with a unique |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3031 name. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3032 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3033 The file is opened in binary read/write (@qcode{"w+b"}) mode and will be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3034 deleted automatically when it is closed or when Octave exits. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3035 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3036 If successful, @var{fid} is a valid file ID and @var{msg} is an empty |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3037 string. Otherwise, @var{fid} is -1 and @var{msg} contains a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3038 system-dependent error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3039 @seealso{tempname, mkstemp, tempdir, P_tmpdir} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3040 @end deftypefn */) |
4326 | 3041 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3042 if (args.length () != 0) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3043 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3044 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
3045 octave_value_list retval; |
4326 | 3046 |
30881
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
3047 std::string tmpfile (sys::tempnam (sys::env::get_temp_directory (), "oct-")); |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
3048 |
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
3049 FILE *fid = sys::fopen_tmp (tmpfile, "w+b"); |
4326 | 3050 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3051 if (fid) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3052 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3053 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); |
4326 | 3054 |
30881
1921d9d0e62b
Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30822
diff
changeset
|
3055 stream s = stdiostream::create (tmpfile, fid, md); |
4326 | 3056 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
3057 if (! s) |
23741
3bb1c94b41f2
* file-io.cc (Ftmpfile): Close tmp file if stream creation fails.
John W. Eaton <jwe@octave.org>
parents:
23738
diff
changeset
|
3058 { |
3bb1c94b41f2
* file-io.cc (Ftmpfile): Close tmp file if stream creation fails.
John W. Eaton <jwe@octave.org>
parents:
23738
diff
changeset
|
3059 fclose (fid); |
3bb1c94b41f2
* file-io.cc (Ftmpfile): Close tmp file if stream creation fails.
John W. Eaton <jwe@octave.org>
parents:
23738
diff
changeset
|
3060 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
3061 error ("tmpfile: failed to create stdiostream object"); |
23741
3bb1c94b41f2
* file-io.cc (Ftmpfile): Close tmp file if stream creation fails.
John W. Eaton <jwe@octave.org>
parents:
23738
diff
changeset
|
3062 } |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3063 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
3064 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3065 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3066 retval = ovl (streams.insert (s), ""); |
4326 | 3067 } |
3068 else | |
23741
3bb1c94b41f2
* file-io.cc (Ftmpfile): Close tmp file if stream creation fails.
John W. Eaton <jwe@octave.org>
parents:
23738
diff
changeset
|
3069 retval = ovl (-1, std::strerror (errno)); |
4326 | 3070 |
3071 return retval; | |
3072 } | |
3073 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3074 DEFMETHOD (mkstemp, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3075 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3076 @deftypefn {} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp ("@var{template}") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3077 @deftypefnx {} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp ("@var{template}", @var{delete}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3078 Return the file descriptor @var{fid} corresponding to a new temporary file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3079 with a unique name created from @var{template}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3080 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3081 The last six characters of @var{template} must be @qcode{"XXXXXX"} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3082 these are replaced with a string that makes the filename unique. The file |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3083 is then created with mode read/write and permissions that are system |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3084 dependent (on GNU/Linux systems, the permissions will be 0600 for versions |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3085 of glibc 2.0.7 and later). The file is opened in binary mode and with the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3086 @w{@code{O_EXCL}} flag. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3087 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3088 If the optional argument @var{delete} is supplied and is true, the file will |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3089 be deleted automatically when Octave exits. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3090 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3091 If successful, @var{fid} is a valid file ID, @var{name} is the name of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3092 file, and @var{msg} is an empty string. Otherwise, @var{fid} is -1, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3093 @var{name} is empty, and @var{msg} contains a system-dependent error |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3094 message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3095 @seealso{tempname, tempdir, P_tmpdir, tmpfile, fopen} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3096 @end deftypefn */) |
4326 | 3097 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3098 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3099 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3100 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3101 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3102 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3103 std::string tmpl8 = args(0).xstring_value ("mkstemp: TEMPLATE argument must be a string"); |
4326 | 3104 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3105 octave_value_list retval = ovl (-1, "", ""); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3106 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3107 OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3108 strcpy (tmp, tmpl8.c_str ()); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3109 |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
3110 int fd = octave_mkostemp_wrapper (tmp); |
4326 | 3111 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3112 if (fd < 0) |
4326 | 3113 { |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3114 retval(0) = fd; |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21919
diff
changeset
|
3115 retval(2) = std::strerror (errno); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3116 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3117 else |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3118 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3119 const char *fopen_mode = "w+b"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3120 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3121 FILE *fid = fdopen (fd, fopen_mode); |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
3122 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3123 if (! fid) |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3124 { |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3125 retval(0) = -1; |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21919
diff
changeset
|
3126 retval(2) = std::strerror (errno); |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3127 } |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3128 else |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3129 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3130 std::string nm = tmp; |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
3131 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3132 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3133 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
3134 stream s = stdiostream::create (nm, fid, md); |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
3135 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3136 if (! s) |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29961
diff
changeset
|
3137 error ("mkstemp: failed to create stdiostream object"); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3138 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
3139 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3140 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3141 retval(0) = streams.insert (s); |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3142 retval(1) = nm; |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3143 |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
3144 if (nargin == 2 && args(1).is_true ()) |
27542
b8aa62c1deb5
eliminate global tmp_files variable
John W. Eaton <jwe@octave.org>
parents:
27424
diff
changeset
|
3145 interp.mark_for_deletion (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
3146 } |
4326 | 3147 } |
3148 | |
3149 return retval; | |
3150 } | |
3151 | |
20200
d9f35ceff9e1
Change mkfifo to use an octal argument for MODE (bug #45054).
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
3152 // FIXME: This routine also exists verbatim in syscalls.cc. |
d9f35ceff9e1
Change mkfifo to use an octal argument for MODE (bug #45054).
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
3153 // Maybe change to be a general utility routine. |
1400 | 3154 static int |
3155 convert (int x, int ibase, int obase) | |
3156 { | |
3157 int retval = 0; | |
3158 | |
3159 int tmp = x % obase; | |
3160 | |
3161 if (tmp > ibase - 1) | |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20200
diff
changeset
|
3162 error ("umask: invalid digit"); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3163 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3164 retval = tmp; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3165 int mult = ibase; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3166 while ((x = (x - tmp) / obase)) |
1400 | 3167 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3168 tmp = x % obase; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3169 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3170 if (tmp > ibase - 1) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3171 error ("umask: invalid digit"); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3172 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3173 retval += mult * tmp; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
3174 mult *= ibase; |
1400 | 3175 } |
3176 | |
3177 return retval; | |
3178 } | |
3179 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
3180 DEFUNX ("umask", Fumask, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3181 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
3182 @deftypefn {} {@var{oldmask} =} umask (@var{mask}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3183 Set the permission mask for file creation. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3184 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3185 The parameter @var{mask} is an integer, interpreted as an octal number. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3186 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3187 If successful, returns the previous value of the mask (as an integer to be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3188 interpreted as an octal number); otherwise an error message is printed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3189 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3190 The permission mask is a UNIX concept used when creating new objects on a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3191 file system such as files, directories, or named FIFOs. The object to be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3192 created has base permissions in an octal number @var{mode} which are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3193 modified according to the octal value of @var{mask}. The final permissions |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3194 for the new object are @code{@var{mode} - @var{mask}}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3195 @seealso{fopen, mkdir, mkfifo} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3196 @end deftypefn */) |
1400 | 3197 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3198 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3199 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3200 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3201 int mask = args(0).xint_value ("umask: MASK must be an integer"); |
1400 | 3202 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3203 if (mask < 0) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
3204 error ("umask: MASK must be a positive integer value"); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3205 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
3206 int oct_mask = convert (mask, 8, 10); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
3207 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
3208 int status = convert (sys::umask (oct_mask), 10, 8); |
1400 | 3209 |
3210 if (status >= 0) | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
3211 return ovl (status); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
3212 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
3213 return ovl (); |
1400 | 3214 } |
3215 | |
5749 | 3216 static octave_value |
6483 | 3217 const_value (const char *, const octave_value_list& args, int val) |
2189 | 3218 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3219 if (args.length () != 0) |
5823 | 3220 print_usage (); |
5749 | 3221 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3222 return octave_value (val); |
5749 | 3223 } |
3224 | |
3225 DEFUNX ("P_tmpdir", FP_tmpdir, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3226 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
3227 @deftypefn {} {@var{sys_tmpdir} =} P_tmpdir () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3228 Return the name of the host system's @strong{default} directory for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3229 temporary files. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3230 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3231 Programming Note: The value returned by @code{P_tmpdir} is always the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3232 default location. This value may not agree with that returned from |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3233 @code{tempdir} if the user has overridden the default with the @env{TMPDIR} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3234 environment variable. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3235 @seealso{tempdir, tempname, mkstemp, tmpfile} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3236 @end deftypefn */) |
5749 | 3237 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3238 if (args.length () != 0) |
5823 | 3239 print_usage (); |
5749 | 3240 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
3241 return ovl (get_P_tmpdir ()); |
5749 | 3242 } |
2341 | 3243 |
5749 | 3244 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be |
25005
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3245 // this way for Matlab compatibility. |
5749 | 3246 |
3247 DEFUNX ("SEEK_SET", FSEEK_SET, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3248 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
3249 @deftypefn {} {@var{fseek_origin} =} SEEK_SET () |
25005
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3250 Return the numerical value to pass to @code{fseek} to position the file pointer |
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3251 relative to the beginning of the file. |
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3252 @seealso{SEEK_CUR, SEEK_END, fseek} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3253 @end deftypefn */) |
5749 | 3254 { |
3255 return const_value ("SEEK_SET", args, -1); | |
3256 } | |
2189 | 3257 |
5749 | 3258 DEFUNX ("SEEK_CUR", FSEEK_CUR, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3259 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
3260 @deftypefn {} {@var{fseek_origin} =} SEEK_CUR () |
25005
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3261 Return the numerical value to pass to @code{fseek} to position the file pointer |
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3262 relative to the current position. |
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3263 @seealso{SEEK_SET, SEEK_END, fseek} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3264 @end deftypefn */) |
5749 | 3265 { |
3266 return const_value ("SEEK_CUR", args, 0); | |
3267 } | |
2189 | 3268 |
5749 | 3269 DEFUNX ("SEEK_END", FSEEK_END, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3270 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
3271 @deftypefn {} {@var{fseek_origin} =} SEEK_END () |
25005
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3272 Return the numerical value to pass to @code{fseek} to position the file pointer |
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3273 relative to the end of the file. |
db1e3f3664f4
doc: Update documentation for SEEK_SET, SEEK_CUR, SEEK_END.
Rik <rik@octave.org>
parents:
25003
diff
changeset
|
3274 @seealso{SEEK_SET, SEEK_CUR, fseek} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3275 @end deftypefn */) |
5749 | 3276 { |
3277 return const_value ("SEEK_END", args, 1); | |
3278 } | |
3279 | |
3280 static octave_value | |
6483 | 3281 const_value (const char *, const octave_value_list& args, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
3282 const octave_value& val) |
5749 | 3283 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3284 if (args.length () != 0) |
5823 | 3285 print_usage (); |
5749 | 3286 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3287 return octave_value (val); |
5749 | 3288 } |
3289 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3290 DEFMETHODX ("stdin", Fstdin, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3291 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
3292 @deftypefn {} {@var{fid} =} stdin () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3293 Return the numeric value corresponding to the standard input stream. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3294 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3295 When Octave is used interactively, stdin is filtered through the command |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3296 line editing functions. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3297 @seealso{stdout, stderr} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3298 @end deftypefn */) |
5749 | 3299 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
3300 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3301 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3302 return const_value ("stdin", args, streams.stdin_file ()); |
5749 | 3303 } |
2189 | 3304 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3305 DEFMETHODX ("stdout", Fstdout, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3306 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
3307 @deftypefn {} {@var{fid} =} stdout () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3308 Return the numeric value corresponding to the standard output stream. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3309 |
24801
daf61c7dfcae
Change default status of pager to "off" (bug #53217).
Rik <rik@octave.org>
parents:
24662
diff
changeset
|
3310 Data written to the standard output may be filtered through the pager. |
daf61c7dfcae
Change default status of pager to "off" (bug #53217).
Rik <rik@octave.org>
parents:
24662
diff
changeset
|
3311 @seealso{stdin, stderr, page_screen_output} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3312 @end deftypefn */) |
5749 | 3313 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
3314 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3315 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3316 return const_value ("stdout", args, streams.stdout_file ()); |
5749 | 3317 } |
2189 | 3318 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3319 DEFMETHODX ("stderr", Fstderr, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3320 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30881
diff
changeset
|
3321 @deftypefn {} {@var{fid} =} stderr () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3322 Return the numeric value corresponding to the standard error stream. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3323 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3324 Even if paging is turned on, the standard error is not sent to the pager. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3325 It is useful for error messages and prompts. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3326 @seealso{stdin, stdout} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3327 @end deftypefn */) |
5749 | 3328 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
3329 stream_list& streams = interp.get_stream_list (); |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3330 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23737
diff
changeset
|
3331 return const_value ("stderr", args, streams.stderr_file ()); |
2189 | 3332 } |
27542
b8aa62c1deb5
eliminate global tmp_files variable
John W. Eaton <jwe@octave.org>
parents:
27424
diff
changeset
|
3333 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31603
diff
changeset
|
3334 OCTAVE_END_NAMESPACE(octave) |