Mercurial > octave
annotate libinterp/corefcn/file-io.cc @ 21532:936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
* oct-stream.cc (scan): only skip final line if nothing worked (err & 8)
* oct-stream.cc (read_format_once): Record whether anything worked.
* file-io.cc: Add built-in self test.
author | Lachlan Andrew <lachlanbis@gmail.com> |
---|---|
date | Tue, 22 Mar 2016 20:39:16 +1100 |
parents | 2cdbae31c022 |
children | ad0599a0acc6 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19597
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
2095 | 23 // Originally written by John C. Campbell <jcc@bevo.che.wisc.edu> |
1230 | 24 // |
2095 | 25 // Thomas Baier <baier@ci.tuwien.ac.at> added the original versions of |
26 // the following functions: | |
1230 | 27 // |
2095 | 28 // popen |
29 // pclose | |
30 // execute (now popen2.m) | |
31 // sync_system (now merged with system) | |
32 // async_system (now merged with system) | |
1230 | 33 |
9322 | 34 // Extensively revised by John W. Eaton <jwe@octave.org>, |
2095 | 35 // April 1996. |
1 | 36 |
240 | 37 #ifdef HAVE_CONFIG_H |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
38 # include "config.h" |
1 | 39 #endif |
40 | |
4797 | 41 #include <cerrno> |
42 #include <cstdio> | |
1343 | 43 |
3503 | 44 #include <iostream> |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
45 #include <limits> |
7336 | 46 #include <stack> |
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
|
47 #include <string> |
4726 | 48 #include <vector> |
1350 | 49 |
13958
cb15c5185b6a
mkstemp: open file in binary mode (bug #33669)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
50 #include <fcntl.h> |
1230 | 51 #include <sys/types.h> |
1 | 52 #include <unistd.h> |
1350 | 53 |
5325 | 54 #ifdef HAVE_ZLIB_H |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21127
diff
changeset
|
55 # include <zlib.h> |
5325 | 56 #endif |
57 | |
5102 | 58 #include "error.h" |
2926 | 59 #include "file-ops.h" |
6159 | 60 #include "file-stat.h" |
5102 | 61 #include "lo-ieee.h" |
6159 | 62 #include "oct-env.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
63 #include "oct-locbuf.h" |
2926 | 64 |
1352 | 65 #include "defun.h" |
21126
ba0a4b4f021d
include errwarn.h in files that use err_disabled_feature conditionally
John W. Eaton <jwe@octave.org>
parents:
21109
diff
changeset
|
66 #include "errwarn.h" |
6108 | 67 #include "file-io.h" |
6159 | 68 #include "load-path.h" |
2095 | 69 #include "oct-fstrm.h" |
70 #include "oct-iostrm.h" | |
1377 | 71 #include "oct-map.h" |
2095 | 72 #include "oct-prcstrm.h" |
73 #include "oct-stream.h" | |
74 #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
|
75 #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
|
76 #include "ovl.h" |
1 | 77 #include "pager.h" |
444 | 78 #include "sysdep.h" |
1352 | 79 #include "utils.h" |
2370 | 80 #include "variables.h" |
1583 | 81 |
2902 | 82 static octave_value stdin_file; |
83 static octave_value stdout_file; | |
84 static octave_value stderr_file; | |
85 | |
4468 | 86 static octave_stream stdin_stream; |
87 static octave_stream stdout_stream; | |
88 static octave_stream stderr_stream; | |
89 | |
1 | 90 void |
164 | 91 initialize_file_io (void) |
1 | 92 { |
4468 | 93 stdin_stream = octave_istream::create (&std::cin, "stdin"); |
2116 | 94 |
3531 | 95 // This uses octave_stdout (see pager.h), not std::cout so that Octave's |
2116 | 96 // standard output stream will pass through the pager. |
97 | |
4468 | 98 stdout_stream = octave_ostream::create (&octave_stdout, "stdout"); |
2116 | 99 |
4468 | 100 stderr_stream = octave_ostream::create (&std::cerr, "stderr"); |
1 | 101 |
2902 | 102 stdin_file = octave_stream_list::insert (stdin_stream); |
103 stdout_file = octave_stream_list::insert (stdout_stream); | |
104 stderr_file = octave_stream_list::insert (stderr_stream); | |
1 | 105 } |
106 | |
2095 | 107 void |
108 close_files (void) | |
1 | 109 { |
2095 | 110 octave_stream_list::clear (); |
111 } | |
636 | 112 |
5102 | 113 // List of files to delete when we exit or crash. |
114 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
115 // FIXME: this should really be static, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
116 // but that causes problems on some systems. |
5102 | 117 std::stack <std::string> tmp_files; |
118 | |
119 void | |
120 mark_for_deletion (const std::string& file) | |
121 { | |
122 tmp_files.push (file); | |
123 } | |
124 | |
125 void | |
126 cleanup_tmp_files (void) | |
127 { | |
128 while (! tmp_files.empty ()) | |
129 { | |
130 std::string filename = tmp_files.top (); | |
131 tmp_files.pop (); | |
10411 | 132 gnulib::unlink (filename.c_str ()); |
5102 | 133 } |
134 } | |
135 | |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
136 static void |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
137 normalize_fopen_mode (std::string& mode, bool& use_zlib) |
1 | 138 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
139 use_zlib = false; |
896 | 140 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
141 if (! mode.empty ()) |
368 | 142 { |
2095 | 143 // Could probably be faster, but does it really matter? |
1766 | 144 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
145 // Accept 'W', 'R', and 'A' as 'w', 'r', and 'a' but we warn about |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
146 // them because Matlab says they don't perform "automatic |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
147 // flushing" but we don't know precisely what action that implies. |
7078 | 148 |
149 size_t pos = mode.find ('W'); | |
150 | |
8021 | 151 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
152 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
153 warning_with_id ("Octave:fopen-mode", |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
154 "fopen: treating mode \"W\" as equivalent to \"w\""); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
155 mode[pos] = 'w'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
156 } |
7078 | 157 |
158 pos = mode.find ('R'); | |
159 | |
8021 | 160 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
161 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
162 warning_with_id ("Octave:fopen-mode", |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
163 "fopen: treating mode \"R\" as equivalent to \"r\""); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
164 mode[pos] = 'r'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
165 } |
7078 | 166 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
167 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
|
168 |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
169 if (pos != std::string::npos) |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
170 { |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
171 warning_with_id ("Octave:fopen-mode", |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
172 "fopen: treating mode \"A\" as equivalent to \"a\""); |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
173 mode[pos] = 'a'; |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
174 } |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
175 |
7078 | 176 pos = mode.find ('z'); |
5325 | 177 |
8021 | 178 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
179 { |
5325 | 180 #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
|
181 use_zlib = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
182 mode.erase (pos, 1); |
5325 | 183 #else |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
184 err_disabled_feature ("", "gzipped files (zlib)"); |
5325 | 185 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
186 } |
5325 | 187 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
188 // 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
|
189 // '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
|
190 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
191 size_t bpos = mode.find ('b'); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
192 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
|
193 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
194 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
|
195 mode += 'b'; |
1 | 196 } |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
197 } |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
198 |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
199 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
|
200 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
|
201 { |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
202 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
|
203 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
204 if (mode == "rt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
205 retval = std::ios::in; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
206 else if (mode == "wt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
207 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
|
208 else if (mode == "at") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 else if (mode == "rb" || mode == "r") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
217 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
|
218 else if (mode == "wb" || mode == "w") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
219 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
|
220 else if (mode == "ab" || mode == "a") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
227 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
|
228 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
|
229 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
230 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
231 error ("invalid mode specified"); |
1 | 232 |
233 return retval; | |
234 } | |
235 | |
1957 | 236 DEFUN (fclose, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
237 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
238 @deftypefn {} {} fclose (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
239 @deftypefnx {} {} fclose (\"all\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
240 @deftypefnx {} {@var{status} =} fclose (\"all\")\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
241 Close the file specified by the file descriptor @var{fid}.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
242 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
243 If successful, @code{fclose} returns 0, otherwise, it returns -1. The\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
244 second form of the @code{fclose} call closes all open files except\n\ |
20764
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
245 @code{stdin}, @code{stdout}, @code{stderr}, and any FIDs associated\n\ |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20756
diff
changeset
|
246 with gnuplot.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
247 @seealso{fopen, fflush, freport}\n\ |
5642 | 248 @end deftypefn") |
529 | 249 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
250 if (args.length () != 1) |
5823 | 251 print_usage (); |
1 | 252 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
253 return ovl (octave_stream_list::remove (args(0), "fclose")); |
1 | 254 } |
255 | |
5144 | 256 DEFUN (fclear, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
257 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
258 @deftypefn {} {} fclear (@var{fid})\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
259 Clear the stream state for the file specified by the file descriptor\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
260 @var{fid}.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
261 @seealso{ferror, fopen}\n\ |
5144 | 262 @end deftypefn") |
263 { | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
264 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
265 print_usage (); |
5144 | 266 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
267 int fid = octave_stream_list::get_file_number (args(0)); |
5144 | 268 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
269 octave_stream os = octave_stream_list::lookup (fid, "fclear"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
270 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
271 os.clearerr (); |
5144 | 272 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
273 return ovl (); |
5144 | 274 } |
275 | |
1957 | 276 DEFUN (fflush, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
277 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
278 @deftypefn {} {} fflush (@var{fid})\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
279 Flush output to file descriptor @var{fid}.\n\ |
5095 | 280 \n\ |
281 @code{fflush} returns 0 on success and an OS dependent error value\n\ | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10411
diff
changeset
|
282 (@minus{}1 on Unix) on error.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
283 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
284 Programming Note: Flushing is useful for ensuring that all pending output\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
285 makes it to the screen before some other event occurs. For example, it is\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
286 always a good idea to flush the standard output stream before calling\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
287 @code{input}.\n\ |
5642 | 288 @seealso{fopen, fclose}\n\ |
289 @end deftypefn") | |
1181 | 290 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
291 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
292 print_usage (); |
1181 | 293 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
294 octave_value retval = -1; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
295 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
296 // FIXME: any way to avoid special case for stdout? |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
297 int fid = octave_stream_list::get_file_number (args(0)); |
2095 | 298 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
299 if (fid == 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
300 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
301 flush_octave_stdout (); |
2609 | 302 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
303 retval = 0; |
2095 | 304 } |
305 else | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
306 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
307 octave_stream os = octave_stream_list::lookup (fid, "fflush"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
308 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
309 retval = os.flush (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
310 } |
1181 | 311 |
312 return retval; | |
313 } | |
314 | |
2095 | 315 DEFUN (fgetl, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
316 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
317 @deftypefn {} {@var{str} =} fgetl (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
318 @deftypefnx {} {@var{str} =} fgetl (@var{fid}, @var{len})\n\ |
3372 | 319 Read characters from a file, stopping after a newline, or EOF,\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
320 or @var{len} characters have been read.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
321 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
322 The characters read, excluding the possible trailing newline, are returned\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
323 as a string.\n\ |
1339 | 324 \n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
325 If @var{len} is omitted, @code{fgetl} reads until the next newline character.\n\ |
3372 | 326 \n\ |
327 If there are no more characters to read, @code{fgetl} returns @minus{}1.\n\ | |
14435
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
328 \n\ |
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
329 To read a line and return the terminating newline see @code{fgets}.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
330 @seealso{fgets, fscanf, fread, fopen}\n\ |
5642 | 331 @end deftypefn") |
1339 | 332 { |
4468 | 333 static std::string who = "fgetl"; |
334 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
335 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
336 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
337 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
338 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
339 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
340 octave_stream os = octave_stream_list::lookup (args(0), who); |
1339 | 341 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
342 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); |
2095 | 343 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
344 bool err = false; |
2095 | 345 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
346 std::string tmp = os.getl (len_arg, err, who); |
2095 | 347 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
348 if (! err) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
349 return ovl (tmp, tmp.length ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
350 else |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
351 return ovl (-1, 0); |
1339 | 352 } |
353 | |
2095 | 354 DEFUN (fgets, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
355 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
356 @deftypefn {} {@var{str} =} fgets (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
357 @deftypefnx {} {@var{str} =} fgets (@var{fid}, @var{len})\n\ |
3372 | 358 Read characters from a file, stopping after a newline, or EOF,\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
359 or @var{len} characters have been read.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
360 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
361 The characters read, including the possible trailing newline, are returned\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
362 as a string.\n\ |
529 | 363 \n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
364 If @var{len} is omitted, @code{fgets} reads until the next newline character.\n\ |
3372 | 365 \n\ |
366 If there are no more characters to read, @code{fgets} returns @minus{}1.\n\ | |
14435
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
367 \n\ |
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
368 To read a line and discard the terminating newline see @code{fgetl}.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
369 @seealso{fputs, fgetl, fscanf, fread, fopen}\n\ |
5642 | 370 @end deftypefn") |
529 | 371 { |
4468 | 372 static std::string who = "fgets"; |
373 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
374 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
375 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
376 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
377 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
378 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
379 octave_stream os = octave_stream_list::lookup (args(0), who); |
529 | 380 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
381 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); |
2095 | 382 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
383 bool err = false; |
2095 | 384 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
385 std::string tmp = os.gets (len_arg, err, who); |
2095 | 386 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
387 if (! err) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
388 return ovl (tmp, tmp.length ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
389 else |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
390 return ovl (-1.0, 0.0); |
529 | 391 } |
392 | |
9701 | 393 DEFUN (fskipl, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
394 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
395 @deftypefn {} {@var{nlines} =} fskipl (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
396 @deftypefnx {} {@var{nlines} =} fskipl (@var{fid}, @var{count})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
397 @deftypefnx {} {@var{nlines} =} fskipl (@var{fid}, Inf)\n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
398 Read and skip @var{count} lines from the file specified by the file\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
399 descriptor @var{fid}.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
400 \n\ |
14436
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
401 @code{fskipl} discards characters until an end-of-line is encountered exactly\n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
402 @var{count}-times, or until the end-of-file marker is found.\n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
403 \n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
404 If @var{count} is omitted, it defaults to 1. @var{count} may also be\n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
405 @code{Inf}, in which case lines are skipped until the end of the file.\n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
406 This form is suitable for counting the number of lines in a file.\n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
407 \n\ |
9701 | 408 Returns the number of lines skipped (end-of-line sequences encountered).\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
409 @seealso{fgetl, fgets, fscanf, fopen}\n\ |
9701 | 410 @end deftypefn") |
411 { | |
412 static std::string who = "fskipl"; | |
413 | |
414 int nargin = args.length (); | |
415 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
416 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
417 print_usage (); |
9701 | 418 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
419 octave_stream os = octave_stream_list::lookup (args(0), who); |
9701 | 420 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
421 octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); |
9701 | 422 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
423 bool err = false; |
9701 | 424 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
425 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
|
426 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
427 if (! err) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
428 return ovl (tmp); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
429 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
430 return ovl (); |
9701 | 431 } |
432 | |
433 | |
3340 | 434 static octave_stream |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
435 do_stream_open (const std::string& name, const std::string& mode_arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
436 const std::string& arch, int& fid) |
1 | 437 { |
3340 | 438 octave_stream retval; |
1 | 439 |
2095 | 440 fid = -1; |
1 | 441 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
442 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
|
443 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
|
444 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
|
445 |
4036 | 446 std::ios::openmode md = fopen_mode_to_ios_mode (mode); |
1 | 447 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
448 oct_mach_info::float_format flt_fmt = |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
449 oct_mach_info::string_to_float_format (arch); |
1 | 450 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
451 std::string fname = file_ops::tilde_expand (name); |
6159 | 452 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
453 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
|
454 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
455 if (! (md & std::ios::out)) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
456 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
|
457 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
458 if (! fs.is_dir ()) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
459 { |
6905 | 460 #if defined (HAVE_ZLIB) |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
461 if (use_zlib) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
462 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
463 FILE *fptr = gnulib::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
|
464 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
465 int fd = fileno (fptr); |
11004
594adb99a25e
cache file id in octave_tstdiostream class
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
466 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
467 gzFile gzf = ::gzdopen (fd, mode.c_str ()); |
5325 | 468 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
469 if (fptr) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
470 retval = octave_zstdiostream::create (fname, gzf, fd, |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
471 md, flt_fmt); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
472 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
473 retval.error (gnulib::strerror (errno)); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
474 } |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
475 else |
5325 | 476 #endif |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
477 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
478 FILE *fptr = gnulib::fopen (fname.c_str (), mode.c_str ()); |
5370 | 479 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
480 retval = octave_stdiostream::create (fname, fptr, md, |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
481 flt_fmt); |
7730
b68e44c90afe
file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents:
7708
diff
changeset
|
482 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
483 if (! fptr) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
484 retval.error (gnulib::strerror (errno)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
485 } |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
486 |
1 | 487 } |
488 | |
2095 | 489 return retval; |
490 } | |
1 | 491 |
3340 | 492 static octave_stream |
2095 | 493 do_stream_open (const octave_value& tc_name, const octave_value& tc_mode, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
494 const octave_value& tc_arch, const char *fcn, int& fid) |
2095 | 495 { |
3340 | 496 octave_stream retval; |
2095 | 497 |
498 fid = -1; | |
499 | |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
500 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
|
501 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
|
502 std::string arch = tc_arch.xstring_value ("%s: architecture type must be a string", fcn); |
1 | 503 |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
504 retval = do_stream_open (name, mode, arch, fid); |
1 | 505 |
506 return retval; | |
507 } | |
508 | |
11146
69b2f237060e
file-io.cc (Ffopen): argument parsing tweak
John W. Eaton <jwe@octave.org>
parents:
11081
diff
changeset
|
509 DEFUN (fopen, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
510 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
511 @deftypefn {} {@var{fid} =} fopen (@var{name})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
512 @deftypefnx {} {@var{fid} =} fopen (@var{name}, @var{mode})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
513 @deftypefnx {} {@var{fid} =} fopen (@var{name}, @var{mode}, @var{arch})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
514 @deftypefnx {} {[@var{fid}, @var{msg}] =} fopen (@dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
515 @deftypefnx {} {@var{fid_list} =} fopen (\"all\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
516 @deftypefnx {} {[@var{file}, @var{mode}, @var{arch}] =} fopen (@var{fid})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
517 Open a file for low-level I/O or query open files and file descriptors.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
518 \n\ |
3372 | 519 The first form of the @code{fopen} function opens the named file with\n\ |
520 the specified mode (read-write, read-only, etc.) and architecture\n\ | |
521 interpretation (IEEE big endian, IEEE little endian, etc.), and returns\n\ | |
522 an integer value that may be used to refer to the file later. If an\n\ | |
523 error occurs, @var{fid} is set to @minus{}1 and @var{msg} contains the\n\ | |
524 corresponding system error message. The @var{mode} is a one or two\n\ | |
525 character string that specifies whether the file is to be opened for\n\ | |
526 reading, writing, or both.\n\ | |
1181 | 527 \n\ |
3372 | 528 The second form of the @code{fopen} function returns a vector of file ids\n\ |
529 corresponding to all the currently open files, excluding the\n\ | |
530 @code{stdin}, @code{stdout}, and @code{stderr} streams.\n\ | |
2318 | 531 \n\ |
5353 | 532 The third form of the @code{fopen} function returns information about the\n\ |
533 open file given its file id.\n\ | |
1181 | 534 \n\ |
3372 | 535 For example,\n\ |
536 \n\ | |
537 @example\n\ | |
538 myfile = fopen (\"splat.dat\", \"r\", \"ieee-le\");\n\ | |
539 @end example\n\ | |
2095 | 540 \n\ |
3372 | 541 @noindent\n\ |
542 opens the file @file{splat.dat} for reading. If necessary, binary\n\ | |
543 numeric values will be read assuming they are stored in IEEE format with\n\ | |
544 the least significant bit first, and then converted to the native\n\ | |
545 representation.\n\ | |
2318 | 546 \n\ |
3372 | 547 Opening a file that is already open simply opens it again and returns a\n\ |
548 separate file id. It is not an error to open a file several times,\n\ | |
549 though writing to the same file through several different file ids may\n\ | |
550 produce unexpected results.\n\ | |
551 \n\ | |
552 The possible values @samp{mode} may have are\n\ | |
553 \n\ | |
554 @table @asis\n\ | |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
555 @item @samp{r} (default)\n\ |
3372 | 556 Open a file for reading.\n\ |
3263 | 557 \n\ |
3372 | 558 @item @samp{w}\n\ |
7001 | 559 Open a file for writing. The previous contents are discarded.\n\ |
3372 | 560 \n\ |
561 @item @samp{a}\n\ | |
562 Open or create a file for writing at the end of the file.\n\ | |
563 \n\ | |
564 @item @samp{r+}\n\ | |
565 Open an existing file for reading and writing.\n\ | |
566 \n\ | |
567 @item @samp{w+}\n\ | |
568 Open a file for reading or writing. The previous contents are\n\ | |
569 discarded.\n\ | |
570 \n\ | |
571 @item @samp{a+}\n\ | |
572 Open or create a file for reading or writing at the end of the\n\ | |
573 file.\n\ | |
574 @end table\n\ | |
575 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
576 Append a @qcode{\"t\"} to the mode string to open the file in text mode or a\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
577 @qcode{\"b\"} to open in binary mode. On Windows and Macintosh systems, text\n\ |
4865 | 578 mode reading and writing automatically converts linefeeds to the\n\ |
579 appropriate line end character for the system (carriage-return linefeed\n\ | |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
580 on Windows, carriage-return on Macintosh). The default when no mode is\n\ |
4865 | 581 specified is binary mode.\n\ |
582 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
583 Additionally, you may append a @qcode{\"z\"} to the mode string to open a\n\ |
5325 | 584 gzipped file for reading or writing. For this to be successful, you\n\ |
585 must also open the file in binary mode.\n\ | |
586 \n\ | |
3372 | 587 The parameter @var{arch} is a string specifying the default data format\n\ |
588 for the file. Valid values for @var{arch} are:\n\ | |
2318 | 589 \n\ |
20431
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
590 @table @asis\n\ |
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
591 @item @qcode{\"native\"} or @qcode{\"n\"} (default)\n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
592 The format of the current machine.\n\ |
3372 | 593 \n\ |
20431
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
594 @item @qcode{\"ieee-be\"} or @qcode{\"b\"}\n\ |
3372 | 595 IEEE big endian format.\n\ |
596 \n\ | |
20431
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
597 @item @qcode{\"ieee-le\"} or @qcode{\"l\"}\n\ |
3372 | 598 IEEE little endian format.\n\ |
599 @end table\n\ | |
600 \n\ | |
601 @noindent\n\ | |
20431
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
602 However, conversions are currently only supported for @samp{native},\n\ |
3372 | 603 @samp{ieee-be}, and @samp{ieee-le} formats.\n\ |
20198
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
604 \n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
605 When opening a new file that does not yet exist, permissions will be set to\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
606 @code{0666 - @var{umask}}.\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
607 @seealso{fclose, fgets, fgetl, fscanf, fread, fputs, fdisp, fprintf, fwrite, fskipl, fseek, frewind, ftell, feof, ferror, fclear, fflush, freport, umask}\n\ |
5642 | 608 @end deftypefn") |
529 | 609 { |
610 int nargin = args.length (); | |
611 | |
20861
6774cc464ea0
* file-io.cc (Ffopen): Fix nargin range check, fixes cset f2cd811f0f9e
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
612 if (nargin < 1 || nargin > 3) |
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
|
613 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
|
614 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
615 octave_value_list retval = ovl (-1.0); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
616 |
2095 | 617 if (nargin == 1) |
618 { | |
12896
a19b50f6697f
Correctly allow single string input form of fopen() (Bug #33535).
Rik <octave@nomad.inbox5.com>
parents:
12775
diff
changeset
|
619 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
620 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
621 // 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
|
622 // 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
|
623 // 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
|
624 // 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
|
625 if (nargout < 2 && args(0).string_value () == "all") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
626 return octave_stream_list::open_file_numbers (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
627 } |
2095 | 628 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
629 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
630 string_vector tmp = octave_stream_list::get_info (args(0)); |
529 | 631 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
632 retval = ovl (tmp(0), tmp(1), tmp(2)); |
3263 | 633 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
634 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
635 } |
1 | 636 } |
637 | |
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
|
638 octave_value mode = (nargin == 2 || nargin == 3) |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
639 ? args(1) : octave_value ("r"); |
2095 | 640 |
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
|
641 octave_value arch = (nargin == 3) |
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 ? args(2) : octave_value ("native"); |
2095 | 643 |
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 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
|
645 |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
646 octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid); |
5370 | 647 |
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
|
648 if (os) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
649 retval = ovl (octave_stream_list::insert (os), ""); |
2095 | 650 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
|
651 { |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20819
diff
changeset
|
652 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
|
653 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
654 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
|
655 } |
1 | 656 |
657 return retval; | |
658 } | |
659 | |
1957 | 660 DEFUN (freport, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
661 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
662 @deftypefn {} {} freport ()\n\ |
3372 | 663 Print a list of which files have been opened, and whether they are open\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
664 for reading, writing, or both.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
665 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
666 For example:\n\ |
3372 | 667 \n\ |
668 @example\n\ | |
669 @group\n\ | |
670 freport ()\n\ | |
671 \n\ | |
19123 | 672 @print{} number mode arch name\n\ |
673 @print{} ------ ---- ---- ----\n\ | |
674 @print{} 0 r ieee-le stdin\n\ | |
675 @print{} 1 w ieee-le stdout\n\ | |
676 @print{} 2 w ieee-le stderr\n\ | |
677 @print{} 3 r ieee-le myfile\n\ | |
3372 | 678 @end group\n\ |
679 @end example\n\ | |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
680 @seealso{fopen, fclose, is_valid_file_id}\n\ |
3372 | 681 @end deftypefn") |
1181 | 682 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
683 if (args.length () > 0) |
1181 | 684 warning ("freport: ignoring extra arguments"); |
685 | |
2095 | 686 octave_stdout << octave_stream_list::list_open_files (); |
1181 | 687 |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
688 return ovl (); |
1181 | 689 } |
690 | |
4715 | 691 DEFUN (frewind, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
692 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
693 @deftypefn {} {} frewind (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
694 @deftypefnx {} {@var{status} =} frewind (@var{fid})\n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
695 Move the file pointer to the beginning of the file specified by file\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
696 descriptor @var{fid}.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
697 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
698 @code{frewind} returns 0 for success, and -1 if an error is encountered. It\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
699 is equivalent to @code{fseek (@var{fid}, 0, SEEK_SET)}.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
700 @seealso{fseek, ftell, fopen}\n\ |
3372 | 701 @end deftypefn") |
529 | 702 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
703 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
704 print_usage (); |
506 | 705 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
706 int result = -1; |
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
707 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
708 octave_stream os = octave_stream_list::lookup (args(0), "frewind"); |
636 | 709 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
710 result = os.rewind (); |
1 | 711 |
4715 | 712 if (nargout > 0) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
713 return ovl (result); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
714 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
715 return ovl (); |
1 | 716 } |
717 | |
1957 | 718 DEFUN (fseek, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
719 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
720 @deftypefn {} {} fseek (@var{fid}, @var{offset})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
721 @deftypefnx {} {} fseek (@var{fid}, @var{offset}, @var{origin})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
722 @deftypefnx {} {@var{status} =} fseek (@dots{})\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
723 Set the file pointer to the location @var{offset} within the file @var{fid}.\n\ |
5095 | 724 \n\ |
725 The pointer is positioned @var{offset} characters from the @var{origin},\n\ | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
726 which may be one of the predefined variables @w{@code{SEEK_CUR}} (current\n\ |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
727 position), @w{@code{SEEK_SET}} (beginning), or @w{@code{SEEK_END}} (end of\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
728 file) or strings @qcode{\"cof\"}, @qcode{\"bof\"} or @qcode{\"eof\"}. If\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
729 @var{origin} is omitted, @w{@code{SEEK_SET}} is assumed. @var{offset} may\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
730 be positive, negative, or zero but not all combinations of @var{origin} and\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
731 @var{offset} can be realized.\n\ |
5095 | 732 \n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
733 @code{fseek} returns 0 on success and -1 on error.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
734 @seealso{fskipl, frewind, ftell, fopen}\n\ |
5642 | 735 @end deftypefn") |
529 | 736 { |
737 int nargin = args.length (); | |
738 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
739 if (nargin < 2 || nargin > 3) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
740 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
741 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
742 octave_stream os = octave_stream_list::lookup (args(0), "fseek"); |
1181 | 743 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
744 octave_value origin_arg = (nargin == 3) ? args(2) : octave_value (-1.0); |
1 | 745 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
746 return ovl (os.seek (args(1), origin_arg)); |
1 | 747 } |
748 | |
1957 | 749 DEFUN (ftell, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
750 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
751 @deftypefn {} {@var{pos} =} ftell (@var{fid})\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
752 Return the position of the file pointer as the number of characters from the\n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
753 beginning of the file specified by file descriptor @var{fid}.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
754 @seealso{fseek, frewind, feof, fopen}\n\ |
5642 | 755 @end deftypefn") |
1181 | 756 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
757 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
758 print_usage (); |
506 | 759 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
760 octave_stream os = octave_stream_list::lookup (args(0), "ftell"); |
1 | 761 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
762 return ovl (os.tell ()); |
1 | 763 } |
764 | |
3737 | 765 DEFUN (fprintf, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
766 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
767 @deftypefn {} {} fprintf (@var{fid}, @var{template}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
768 @deftypefnx {} {} fprintf (@var{template}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
769 @deftypefnx {} {@var{numbytes} =} fprintf (@dots{})\n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
770 This function is equivalent to @code{printf}, except that the output is\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
771 written to the file descriptor @var{fid} instead of @code{stdout}.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
772 \n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
773 If @var{fid} is omitted, the output is written to @code{stdout} making the\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
774 function exactly equivalent to @code{printf}.\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
775 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
776 The optional output returns the number of bytes written to the file.\n\ |
20041
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
777 \n\ |
20097
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20041
diff
changeset
|
778 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
20101
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20097
diff
changeset
|
779 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20097
diff
changeset
|
780 expanded even when the template string is defined with single quotes.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
781 @seealso{fputs, fdisp, fwrite, fscanf, printf, sprintf, fopen}\n\ |
5642 | 782 @end deftypefn") |
1181 | 783 { |
4468 | 784 static std::string who = "fprintf"; |
785 | |
1181 | 786 int nargin = args.length (); |
787 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
788 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
|
789 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
790 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
791 int result; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
792 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
793 octave_stream os; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
794 int fmt_n = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
795 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
796 if (args(0).is_string ()) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
797 os = octave_stream_list::lookup (1, who); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
798 else |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
799 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
800 fmt_n = 1; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
801 os = octave_stream_list::lookup (args(0), who); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
802 } |
2873 | 803 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
804 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
|
805 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
1181 | 806 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
807 octave_value_list tmp_args; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
808 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
809 if (nargin > 1 + fmt_n) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
810 { |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
811 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
|
812 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
813 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
|
814 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
|
815 } |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
816 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
817 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
|
818 |
4715 | 819 if (nargout > 0) |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
820 return ovl (result); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
821 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
822 return ovl (); |
1181 | 823 } |
824 | |
4715 | 825 DEFUN (printf, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
826 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
827 @deftypefn {} {} printf (@var{template}, @dots{})\n\ |
4468 | 828 Print optional arguments under the control of the template string\n\ |
5653 | 829 @var{template} to the stream @code{stdout} and return the number of\n\ |
830 characters printed.\n\ | |
831 @ifclear OCTAVE_MANUAL\n\ | |
5095 | 832 \n\ |
5653 | 833 See the Formatted Output section of the GNU Octave manual for a\n\ |
834 complete description of the syntax of the template string.\n\ | |
835 @end ifclear\n\ | |
20041
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
836 \n\ |
20097
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20041
diff
changeset
|
837 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
20101
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20097
diff
changeset
|
838 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20097
diff
changeset
|
839 expanded even when the template string is defined with single quotes.\n\ |
5642 | 840 @seealso{fprintf, sprintf, scanf}\n\ |
841 @end deftypefn") | |
4468 | 842 { |
843 static std::string who = "printf"; | |
844 | |
845 int nargin = args.length (); | |
846 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
847 if (nargin == 0) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
848 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
849 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
850 int result; |
4468 | 851 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
852 if (! args(0).is_string ()) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
853 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
4468 | 854 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
855 octave_value_list tmp_args; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
856 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
857 if (nargin > 1) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
858 { |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
859 tmp_args.resize (nargin-1, octave_value ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
860 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
861 for (int i = 1; i < nargin; i++) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
862 tmp_args(i-1) = args(i); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
863 } |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
864 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
865 result = stdout_stream.printf (args(0), tmp_args, who); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
866 |
4715 | 867 if (nargout > 0) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
868 return ovl (result); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
869 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
870 return ovl (); |
4468 | 871 } |
872 | |
2095 | 873 DEFUN (fputs, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
874 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
875 @deftypefn {} {} fputs (@var{fid}, @var{string})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
876 @deftypefnx {} {@var{status} =} fputs (@var{fid}, @var{string})\n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
877 Write the string @var{string} to the file with file descriptor @var{fid}.\n\ |
5095 | 878 \n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
879 The string is written to the file with no additional formatting. Use\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
880 @code{fdisp} instead to automatically append a newline character appropriate\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
881 for the local machine.\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
882 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
883 Return a non-negative number on success or EOF on error.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
884 @seealso{fdisp, fprintf, fwrite, fopen}\n\ |
3372 | 885 @end deftypefn") |
1181 | 886 { |
4468 | 887 static std::string who = "fputs"; |
888 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
889 if (args.length () != 2) |
5823 | 890 print_usage (); |
4468 | 891 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
892 octave_stream os = octave_stream_list::lookup (args(0), who); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
893 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
894 return ovl (os.puts (args(1), who)); |
4468 | 895 } |
896 | |
897 DEFUN (puts, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
898 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
899 @deftypefn {} {} puts (@var{string})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
900 @deftypefnx {} {@var{status} =} puts (@var{string})\n\ |
4468 | 901 Write a string to the standard output with no formatting.\n\ |
5095 | 902 \n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
903 The string is written verbatim to the standard output. Use @code{disp} to\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
904 automatically append a newline character appropriate for the local machine.\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
905 \n\ |
5095 | 906 Return a non-negative number on success and EOF on error.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
907 @seealso{fputs, disp}\n\ |
4468 | 908 @end deftypefn") |
909 { | |
910 static std::string who = "puts"; | |
911 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
912 if (args.length () != 1) |
5823 | 913 print_usage (); |
1181 | 914 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
915 return ovl (stdout_stream.puts (args(0), who)); |
1181 | 916 } |
917 | |
2095 | 918 DEFUN (sprintf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
919 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
920 @deftypefn {} {} sprintf (@var{template}, @dots{})\n\ |
3372 | 921 This is like @code{printf}, except that the output is returned as a\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
922 string.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
923 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
924 Unlike the C library function, which requires you to provide a suitably\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
925 sized string as an argument, Octave's @code{sprintf} function returns the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
926 string, automatically sized to hold all of the items converted.\n\ |
20041
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
927 \n\ |
20097
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20041
diff
changeset
|
928 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
20101
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20097
diff
changeset
|
929 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20097
diff
changeset
|
930 expanded even when the template string is defined with single quotes.\n\ |
5642 | 931 @seealso{printf, fprintf, sscanf}\n\ |
932 @end deftypefn") | |
1 | 933 { |
4468 | 934 static std::string who = "sprintf"; |
935 | |
2095 | 936 int nargin = args.length (); |
1 | 937 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
938 if (nargin == 0) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
939 print_usage (); |
2116 | 940 |
21506
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
941 // We don't use octave_ostrstream::create here because need direct |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
942 // 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
|
943 // from it to return. |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
944 octave_ostrstream *ostr = new octave_ostrstream (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
945 |
21506
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
946 // The octave_stream destructor will delete OSTR for us. |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
947 octave_stream os (ostr); |
628 | 948 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
949 if (! os.is_valid ()) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
950 error ("%s: unable to create output buffer", who.c_str ()); |
1 | 951 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
952 octave_value fmt_arg = args(0); |
1 | 953 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
954 if (! fmt_arg.is_string ()) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
955 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
628 | 956 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
957 octave_value_list retval (3); |
19727
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
958 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
959 octave_value_list tmp_args; |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
960 if (nargin > 1) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
961 { |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
962 tmp_args.resize (nargin-1, octave_value ()); |
19727
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
963 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
964 for (int i = 1; i < nargin; i++) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
965 tmp_args(i-1) = args(i); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
966 } |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
967 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
968 // 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
|
969 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
|
970 retval(1) = os.error (); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
971 |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
972 std::string result = ostr->str (); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
973 char type = fmt_arg.is_sq_string () ? '\'' : '"'; |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
974 |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
975 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
|
976 : octave_value (result, type)); |
1 | 977 |
978 return retval; | |
979 } | |
980 | |
2095 | 981 DEFUN (fscanf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
982 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
983 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, @var{size})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
984 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, \"C\")\n\ |
3372 | 985 In the first form, read from @var{fid} according to @var{template},\n\ |
986 returning the result in the matrix @var{val}.\n\ | |
2122 | 987 \n\ |
3372 | 988 The optional argument @var{size} specifies the amount of data to read\n\ |
989 and may be one of\n\ | |
990 \n\ | |
991 @table @code\n\ | |
992 @item Inf\n\ | |
993 Read as much as possible, returning a column vector.\n\ | |
994 \n\ | |
995 @item @var{nr}\n\ | |
996 Read up to @var{nr} elements, returning a column vector.\n\ | |
2122 | 997 \n\ |
3372 | 998 @item [@var{nr}, Inf]\n\ |
999 Read as much as possible, returning a matrix with @var{nr} rows. If the\n\ | |
1000 number of elements read is not an exact multiple of @var{nr}, the last\n\ | |
1001 column is padded with zeros.\n\ | |
1002 \n\ | |
1003 @item [@var{nr}, @var{nc}]\n\ | |
1004 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with\n\ | |
1005 @var{nr} rows. If the number of elements read is not an exact multiple\n\ | |
1006 of @var{nr}, the last column is padded with zeros.\n\ | |
1007 @end table\n\ | |
2122 | 1008 \n\ |
3372 | 1009 @noindent\n\ |
1010 If @var{size} is omitted, a value of @code{Inf} is assumed.\n\ | |
2122 | 1011 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1012 A string is returned if @var{template} specifies only character conversions.\n\ |
2215 | 1013 \n\ |
3372 | 1014 The number of items successfully read is returned in @var{count}.\n\ |
2215 | 1015 \n\ |
13271
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1016 If an error occurs, @var{errmsg} contains a system-dependent error message.\n\ |
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1017 \n\ |
3372 | 1018 In the second form, read from @var{fid} according to @var{template},\n\ |
1019 with each conversion specifier in @var{template} corresponding to a\n\ | |
16766
7268845c0a1e
avoid backquote in error messages, some uses in doc strings
John W. Eaton <jwe@octave.org>
parents:
16590
diff
changeset
|
1020 single scalar return value. This form is more ``C-like'', and also\n\ |
3491 | 1021 compatible with previous versions of Octave. The number of successful\n\ |
16099
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
1022 conversions is returned in @var{count}\n\ |
5653 | 1023 @ifclear OCTAVE_MANUAL\n\ |
1024 \n\ | |
1025 See the Formatted Input section of the GNU Octave manual for a\n\ | |
1026 complete description of the syntax of the template string.\n\ | |
1027 @end ifclear\n\ | |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
1028 @seealso{fgets, fgetl, fread, scanf, sscanf, fopen}\n\ |
5642 | 1029 @end deftypefn") |
1181 | 1030 { |
4468 | 1031 static std::string who = "fscanf"; |
1032 | |
1181 | 1033 int nargin = args.length (); |
1034 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1035 if (nargin < 2 || nargin > 3) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1036 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1037 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1038 octave_value_list retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1039 |
21506
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1040 octave_stream os = octave_stream_list::lookup (args(0), who); |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1041 |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1042 if (! args(1).is_string ()) |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1043 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
|
1044 |
2215 | 1045 if (nargin == 3 && args(2).is_string ()) |
2095 | 1046 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1047 retval = ovl (os.oscanf (args(1), who)); |
2095 | 1048 } |
1181 | 1049 else |
2215 | 1050 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1051 octave_idx_type count = 0; |
2215 | 1052 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1053 Array<double> size = (nargin == 3) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1054 ? args(2).vector_value () |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1055 : Array<double> (dim_vector (1, 1), |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1056 lo_ieee_inf_value ()); |
2215 | 1057 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1058 octave_value tmp = os.scanf (args(1), size, count, who); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1059 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1060 retval = ovl (tmp, count, os.error ()); |
2215 | 1061 } |
1181 | 1062 |
1063 return retval; | |
1064 } | |
1065 | |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1066 static std::string |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1067 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
|
1068 { |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1069 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
|
1070 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
1071 if (! val.is_string ()) |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1072 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
|
1073 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
1074 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
|
1075 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
1076 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
|
1077 |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1078 return retval; |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1079 } |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1080 |
2095 | 1081 DEFUN (sscanf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1082 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
1083 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}, @var{pos}] =} sscanf (@var{string}, @var{template}, @var{size})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
1084 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} sscanf (@var{string}, @var{template}, \"C\")\n\ |
3372 | 1085 This is like @code{fscanf}, except that the characters are taken from the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1086 string @var{string} instead of from a stream.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1087 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1088 Reaching the end of the string is treated as an end-of-file condition. In\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1089 addition to the values returned by @code{fscanf}, the index of the next\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
1090 character to be read is returned in @var{pos}.\n\ |
5642 | 1091 @seealso{fscanf, scanf, sprintf}\n\ |
1092 @end deftypefn") | |
444 | 1093 { |
4468 | 1094 static std::string who = "sscanf"; |
1095 | |
506 | 1096 int nargin = args.length (); |
1097 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1098 if (nargin < 2 || nargin > 3) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1099 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1100 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1101 octave_value_list retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1102 |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1103 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
|
1104 |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1105 octave_stream os = octave_istrstream::create (data); |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1106 |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1107 if (! os.is_valid ()) |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1108 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
|
1109 |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1110 if (! args(1).is_string ()) |
128703a29388
avoid some duplicate code in file-io functions
John W. Eaton <jwe@octave.org>
parents:
21504
diff
changeset
|
1111 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
|
1112 |
2215 | 1113 if (nargin == 3 && args(2).is_string ()) |
2095 | 1114 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1115 retval = ovl (os.oscanf (args(1), who)); |
444 | 1116 } |
1117 else | |
2215 | 1118 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1119 octave_idx_type count = 0; |
2215 | 1120 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1121 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
|
1122 : Array<double> (dim_vector (1, 1), |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1123 lo_ieee_inf_value ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1124 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1125 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
|
1126 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1127 // 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
|
1128 // Extract error message first, because getting |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1129 // position will clear it. |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1130 std::string errmsg = os.error (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1131 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1132 retval = ovl (tmp, count, errmsg, |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1133 (os.eof () ? data.length () : os.tell ()) + 1); |
2215 | 1134 } |
444 | 1135 |
1136 return retval; | |
1137 } | |
1138 | |
2215 | 1139 DEFUN (scanf, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1140 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
1141 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} scanf (@var{template}, @var{size})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
1142 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}]] =} scanf (@var{template}, \"C\")\n\ |
3372 | 1143 This is equivalent to calling @code{fscanf} with @var{fid} = @code{stdin}.\n\ |
1144 \n\ | |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
1145 It is currently not useful to call @code{scanf} in interactive programs.\n\ |
5642 | 1146 @seealso{fscanf, sscanf, printf}\n\ |
1147 @end deftypefn") | |
2215 | 1148 { |
1149 int nargin = args.length (); | |
1150 | |
1151 octave_value_list tmp_args (nargin+1, octave_value ()); | |
1152 | |
1153 tmp_args (0) = 0.0; | |
1154 for (int i = 0; i < nargin; i++) | |
18112
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18078
diff
changeset
|
1155 tmp_args(i+1) = args(i); |
2215 | 1156 |
1157 return Ffscanf (tmp_args, nargout); | |
1158 } | |
1159 | |
21504 | 1160 static octave_value_list |
1161 textscan_internal (const std::string& who, const octave_value_list& args) | |
1162 { | |
1163 if (args.length () < 1) | |
1164 print_usage (who); | |
1165 | |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1166 octave_stream os; |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1167 |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1168 if (args(0).is_string ()) |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1169 { |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1170 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
|
1171 |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1172 os = octave_istrstream::create (data); |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1173 |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1174 if (! os.is_valid ()) |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1175 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
|
1176 } |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1177 else |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
1178 os =octave_stream_list::lookup (args(0), who); |
21504 | 1179 |
1180 int nskip = 1; | |
1181 | |
1182 std::string fmt; | |
1183 | |
1184 if (args.length () == 1) | |
1185 { | |
1186 // ommited format = %f. explicit "" = width from file | |
1187 fmt = "%f"; | |
1188 } | |
1189 else if (args(1).is_string ()) | |
1190 { | |
1191 fmt = args(1).string_value (); | |
1192 | |
1193 if (args(1).is_sq_string ()) | |
1194 fmt = do_string_escapes (fmt); | |
1195 | |
1196 nskip++; | |
1197 } | |
1198 else | |
1199 error ("%s: FORMAT must be a string", who.c_str ()); | |
1200 | |
1201 octave_idx_type ntimes = -1; | |
1202 | |
1203 if (args.length () > 2) | |
1204 { | |
1205 if (args(2).is_numeric_type ()) | |
1206 { | |
1207 ntimes = args(2).idx_type_value (); | |
1208 | |
1209 if (ntimes < args(2).double_value ()) | |
1210 error ("%s: REPEAT = %g is too large", | |
1211 who.c_str (), args(2).double_value ()); | |
1212 | |
1213 nskip++; | |
1214 } | |
1215 } | |
1216 | |
1217 octave_value_list options = args.splice (0, nskip); | |
1218 | |
1219 octave_idx_type count = 0; | |
1220 | |
1221 octave_value result = os.textscan (fmt, ntimes, options, who, count); | |
1222 | |
1223 std::string errmsg = os.error (); | |
1224 | |
1225 return ovl (result, count, errmsg); | |
1226 } | |
1227 | |
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
|
1228 DEFUN (textscan, args, , |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1229 "-*- texinfo -*-\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
|
1230 @deftypefn {} {@var{C} =} textscan (@var{fid}, @var{format})\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
|
1231 @deftypefnx {} {@var{C} =} textscan (@var{fid}, @var{format}, @var{repeat})\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
|
1232 @deftypefnx {} {@var{C} =} textscan (@var{fid}, @var{format}, @var{param}, @var{value}, @dots{})\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
|
1233 @deftypefnx {} {@var{C} =} textscan (@var{fid}, @var{format}, @var{repeat}, @var{param}, @var{value}, @dots{})\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
|
1234 @deftypefnx {} {@var{C} =} textscan (@var{str}, @dots{})\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
|
1235 @deftypefnx {} {[@var{C}, @var{position}, @var{errmsg}] =} textscan (@dots{})\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
|
1236 Read data from a text file or string.\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
|
1237 \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
|
1238 The string @var{str} or file associated with @var{fid} is read from and\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
|
1239 parsed according to @var{format}.\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
|
1240 The function is an extension of @code{strread} and @code{textread}.\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
|
1241 Differences include: the ability to read from either a file or a string,\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
|
1242 additional options, and additional format specifiers.\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
|
1243 \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
|
1244 The input is interpreted as a sequence of \"words\", delimiters\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
|
1245 (such as whitespace) and literals.\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
|
1246 The characters that form delimiters and whitespace are determined\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
|
1247 by the options.\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
|
1248 The format consists of format specifiers interspersed between literals.\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
|
1249 In the format, whitespace forms a delimiter between consecutive literals,\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
|
1250 but is otherwise ignored.\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
|
1251 \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
|
1252 The output @var{C} is a cell array whose second dimension is determined\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
|
1253 by the number of format specifiers.\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
|
1254 \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
|
1255 The first word of the input is matched to the first specifier of the\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
|
1256 format and placed in the first column of the output;\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
|
1257 the second is matched to the second specifier and placed in the second column\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
|
1258 and so forth.\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
|
1259 If there are more words than specifiers, the process is repeated until all\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
|
1260 words have been processed or the limit imposed by @var{repeat} has been met\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
|
1261 (see below).\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
|
1262 \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
|
1263 The string @var{format} describes how the words in @var{str} should be\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
|
1264 parsed.\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
|
1265 As in @var{fscanf}, any (non-whitespace) text in the format that is\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
|
1266 not one of these specifiers is considered a literal;\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
|
1267 if there is a literal between two format specifiers then that same literal\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
|
1268 must appear in the input stream between the matching words.\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
|
1269 \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
|
1270 The following specifiers are valid:\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
|
1271 \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
|
1272 @table @code\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
|
1273 @item %f\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
|
1274 @itemx %f64\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
|
1275 @itemx %n\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
|
1276 The word is parsed as a number and converted to double.\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
|
1277 \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
|
1278 @item %f32\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
|
1279 The word is parsed as a number and converted to single (float).\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
|
1280 \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
|
1281 @item %d\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
|
1282 @itemx %d8\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
|
1283 @itemx %d16\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
|
1284 @itemx %d32\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
|
1285 @itemx %d64\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
|
1286 The word is parsed as a number and converted to int8, int16, int32 or int64.\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
|
1287 If not size is specified, int32 is used.\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
|
1288 \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
|
1289 @item %u\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
|
1290 @itemx %u8\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
|
1291 @itemx %u16\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
|
1292 @itemx %u32\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
|
1293 @itemx %u64\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
|
1294 The word is parsed as a number and converted to uint8, uint16, uint32 or\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
|
1295 uint64. If not size is specified, uint32 is used.\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
|
1296 \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
|
1297 @item %s\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
|
1298 The word is parsed as a string, ending at the last character before\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
|
1299 whitespace, an end-of-line or a delimiter specified in the options.\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
|
1300 \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
|
1301 @item %q\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
|
1302 The word is parsed as a \"quoted string\".\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
|
1303 If the first character of the string is a double quote (\") then the string\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
|
1304 includes everything until a matching double quote, including whitespace,\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
|
1305 delimiters and end of line characters.\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
|
1306 If a pair of consecutive double quotes appears in the input,\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
|
1307 it is replaced in the output by a single double quote.\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
|
1308 That is, the input \"He said \"\"Hello\"\"\" would return the value\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
|
1309 'He said \"Hello\"'.\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
|
1310 \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
|
1311 @item %c\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
|
1312 The next character of the input is read.\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
|
1313 This includes delimiters, whitespace and end of line characters.\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
|
1314 \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
|
1315 @item %[...]\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
|
1316 @itemx %[^...]\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
|
1317 In the first form, the word consists of the longest run consisting of only\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
|
1318 characters between the brackets.\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
|
1319 Ranges of characters can be specified by a hyphen;\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
|
1320 for example, %[0-9a-zA-Z] matches all alphanumeric characters\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
|
1321 (if the underlying character set is ASCII).\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
|
1322 Since Matlab treats hyphens literally, this expansion only applies to\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
|
1323 alphanumeric characters.\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
|
1324 To include '-' in the set, it should appear first or last in the brackets;\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
|
1325 to include ']', it should be the first character.\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
|
1326 If the first character is '^' then the word consists of characters\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
|
1327 NOT listed.\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
|
1328 \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
|
1329 @item %N...\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
|
1330 For %s, %c %d, %f, %n, %u, an optional width can be specified as %Ns etc.\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
|
1331 where N is an integer > 1.\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
|
1332 For %c, this causes exactly the next N characters to be read instead of\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
|
1333 a single character.\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
|
1334 For the other specifiers, it is an upper bound on the\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
|
1335 number of characters read;\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
|
1336 normal delimiters can cause fewer characters to be read.\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
|
1337 For complex numbers, this limit applies to the real and imaginary\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
|
1338 components individually.\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
|
1339 For %f and %n, format specifiers like %N.Mf are allowed, where M is an upper\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
|
1340 bound on number of characters after the decimal point to be considered;\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
|
1341 subsequent digits are skipped.\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
|
1342 For example, the specifier %8.2f would read 12.345e6 as 1.234e7.\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
|
1343 \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
|
1344 @item %*...\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
|
1345 The word specified by the remainder of the conversion specifier is skipped.\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
|
1346 \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
|
1347 @item literals\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
|
1348 In addition the format may contain literal character strings;\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
|
1349 these will be skipped during reading.\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
|
1350 If the input string does not match this literal, the processing terminates,\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
|
1351 unless \"ReturnOnError\" is set to \"continue\".\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
|
1352 @end table\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
|
1353 \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
|
1354 Parsed words corresponding to the first specifier are returned in the first\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
|
1355 output argument and likewise for the rest of the specifiers.\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
|
1356 \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
|
1357 By default, if there is only one input argument, @var{format} is @t{\"%f\"}.\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
|
1358 This means that numbers are read from @var{str} into a single column vector.\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
|
1359 If @var{format} is explicitly empty, \"\", then textscan will return data\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
|
1360 in a number of columns matching the number of fields on the first data\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
|
1361 line of the input.\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
|
1362 Either of these is suitable only if @var{str} contains only numeric fields.\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
|
1363 \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
|
1364 For example, the string\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
|
1365 \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
|
1366 @example\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
|
1367 @group\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
|
1368 @var{str} = \"\\\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
|
1369 Bunny Bugs 5.5\\n\\\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
|
1370 Duck Daffy -7.5e-5\\n\\\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
|
1371 Penguin Tux 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
|
1372 @end group\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
|
1373 @end example\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
|
1374 \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
|
1375 @noindent\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
|
1376 can be read using\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
|
1377 \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
|
1378 @example\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
|
1379 @var{a} = textscan (@var{str}, \"%s %s %f\");\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
|
1380 @end example\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
|
1381 \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
|
1382 The optional numeric argument @var{repeat} can be used for limiting the\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
|
1383 number of items read:\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
|
1384 \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
|
1385 @table @asis\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
|
1386 @item -1\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
|
1387 (default) read all of the string or file until the end.\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
|
1388 \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
|
1389 @item N\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
|
1390 Read until the first of two conditions occurs: the format has been processed\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
|
1391 N times, or N lines of the input have been processed.\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
|
1392 Zero (0) is an acceptable value for @var{repeat}.\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
|
1393 Currently, end-of-line characters inside %q, %c, and %[...]$ conversions\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
|
1394 do not contribute to the line count.\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
|
1395 This is incompatible with Matlab and may change in future.\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
|
1396 @end table\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
|
1397 \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
|
1398 The behavior of @code{textscan} can be changed via property-value pairs.\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
|
1399 The following properties are recognized:\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
|
1400 \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
|
1401 @table @asis\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
|
1402 @item @qcode{\"BufSize\"}\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
|
1403 This specifies the number of bytes to use for the internal buffer.\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
|
1404 A modest speed improvement is obtained by setting this to a large value\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
|
1405 when reading a large file, especially the input contains long strings.\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
|
1406 The default is 4096, or a value dependent on @var{n} is that is specified.\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
|
1407 \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
|
1408 @item @qcode{\"CollectOutput\"}\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
|
1409 A value of 1 or true instructs textscan to concatenate consecutive columns\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
|
1410 of the same class in the output cell array.\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
|
1411 A value of 0 or false (default) leaves output in distinct columns.\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
|
1412 \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
|
1413 @item @qcode{\"CommentStyle\"}\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
|
1414 Parts of @var{str} are considered comments and will be skipped.\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
|
1415 @var{value} is the comment style and can be either\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
|
1416 (1) One string, or 1x1 cell string, to skip everything to the right of it;\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
|
1417 (2) A cell array of two strings, to skip everything between the first and\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
|
1418 second strings.\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
|
1419 Comments are only parsed where whitespace is accepted, and do not act as\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
|
1420 delimiters.\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
|
1421 \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
|
1422 @item @qcode{\"Delimiter\"}\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
|
1423 If @var{value} is a string, any character in @var{value} will be used to\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
|
1424 split @var{str} into words.\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
|
1425 If @var{value} is a cell array of strings,\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
|
1426 any string in the array will be used to split @var{str} into words.\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
|
1427 (default value = any whitespace.)\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
|
1428 \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
|
1429 @item @qcode{\"EmptyValue\"}\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
|
1430 Value to return for empty numeric values in non-whitespace delimited data.\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
|
1431 The default is NaN@.\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
|
1432 When the data type does not support NaN (int32 for example),\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
|
1433 then default is zero.\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
|
1434 \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
|
1435 @item @qcode{\"EndOfLine\"}\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
|
1436 @var{value} can be either a emtpy or one character specifying the\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
|
1437 end of line character, or the pair\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
|
1438 @qcode{\"@xbackslashchar{}r@xbackslashchar{}n\"} (CRLF).\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
|
1439 In the latter case, any of\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
|
1440 @qcode{\"@xbackslashchar{}r\"}, @qcode{\"@xbackslashchar{}n\"} or\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
|
1441 @qcode{\"@xbackslashchar{}r@xbackslashchar{}n\"} is counted as a (single)\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
|
1442 newline.\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
|
1443 If no value is given, @qcode{\"@xbackslashchar{}r@xbackslashchar{}n\"} is\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
|
1444 used.\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
|
1445 @c If set to \"\" (empty string) EOLs are ignored as delimiters and added\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
|
1446 @c to whitespace.\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
|
1447 \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
|
1448 @c When reading from a character string, optional input argument @var{n}\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
|
1449 @c specifies the number of times @var{format} should be used (i.e., to limit\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
|
1450 @c the amount of data read).\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
|
1451 @c When reading from file, @var{n} specifies the number of data lines to read;\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
|
1452 @c in this sense it differs slightly from the format repeat count in strread.\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
|
1453 \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
|
1454 @item @qcode{\"HeaderLines\"}\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
|
1455 The first @var{value} number of lines of @var{fid} are skipped.\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
|
1456 Note that this does not refer to the first non-comment lines, but the first\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
|
1457 lines of any type.\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
|
1458 \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
|
1459 @item @qcode{\"MultipleDelimsAsOne\"}\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
|
1460 If @var{value} is non-zero,\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
|
1461 treat a series of consecutive delimiters, without whitespace in between,\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
|
1462 as a single delimiter.\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
|
1463 Consecutive delimiter series need not be vertically @qcode{\"aligned\"}.\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
|
1464 Without this option, a single delimiter before the end of the line does\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
|
1465 not cause the line to be considered to end with an empty value,\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
|
1466 but a single delimiter at the start of a line causes the line\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
|
1467 to be considered to start with an empty value.\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
|
1468 \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
|
1469 @item @qcode{\"TreatAsEmpty\"}\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
|
1470 Treat single occurrences (surrounded by delimiters or whitespace) of the\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
|
1471 string(s) in @var{value} as missing values.\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
|
1472 \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
|
1473 @item @qcode{\"ReturnOnError\"}\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
|
1474 If set to numerical 1 or true, return normally as soon as an error\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
|
1475 is encountered, such as trying to read a string using @qcode{%f}.\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
|
1476 If set to 0 or false, return an error and no data.\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
|
1477 If set to \"continue\" (default), textscan attempts to continue reading\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
|
1478 beyond the location; however, this may cause the parsing to get out of sync.\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
|
1479 \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
|
1480 @item @qcode{\"Whitespace\"}\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
|
1481 Any character in @var{value} will be interpreted as whitespace and trimmed;\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
|
1482 The default value for whitespace is\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
|
1483 @c Note: the next line specifically has a newline which generates a space\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
|
1484 @c in the output of qcode, but keeps the next line < 80 characters.\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
|
1485 @qcode{\"\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
|
1486 @xbackslashchar{}b@xbackslashchar{}r@xbackslashchar{}n@xbackslashchar{}t\"}\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
|
1487 (note the space). Unless whitespace is set to @qcode{\"\"} (empty) AND at\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
|
1488 least one @qcode{\"%s\"} format conversion specifier is supplied, a space is\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
|
1489 always part of whitespace.\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
|
1490 \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
|
1491 @end table\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
|
1492 \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
|
1493 When the number of words in @var{str} or @var{fid} doesn't match an exact\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
|
1494 multiple of the number of format conversion specifiers,\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
|
1495 textscan's behavior depends on\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
|
1496 whether the last character of the string or file is\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
|
1497 an end-of-line as specified by the EndOfLine option:\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
|
1498 \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
|
1499 @table @asis\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
|
1500 @item last character = end-of-line\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
|
1501 Data columns are padded with empty fields, NaN or 0 (for integer fields)\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
|
1502 so that all columns have equal length\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
|
1503 \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
|
1504 @item last character is not end-of-line\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
|
1505 Data columns are not padded; textscan returns columns of unequal length\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
|
1506 @end table\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
|
1507 \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
|
1508 \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
|
1509 The second output, @var{position}, provides the position, in characters\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
|
1510 from the beginning of the file or string, at which the processing stopped.\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
|
1511 \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
|
1512 @seealso{dlmread, fscanf, load, strread, textread}\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
|
1513 @end deftypefn") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1514 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1515 static std::string who = "textscan"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1516 |
21504 | 1517 return textscan_internal (who, args); |
1518 } | |
1519 | |
1520 DEFUN (__textscan__, args, , | |
1521 "-*- texinfo -*-\n\ | |
1522 @deftypefn {} {@var{C} =} __textscan__ (@var{who}, @dots{})\n\ | |
1523 Like @code{textscan} but accept additional argument @var{who} to use\n\ | |
1524 as the name of the function when reporting errors.\n\ | |
1525 @end deftypefn") | |
1526 { | |
1527 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
|
1528 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
|
1529 |
21504 | 1530 return textscan_internal (args(0).string_value (), 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
|
1531 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1532 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1533 /* |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1534 %!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
|
1535 %! 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
|
1536 %! 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
|
1537 %! c = textscan (str, fmtstr, 2, "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
|
1538 %! assert (isequal (c{1}, [1;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
|
1539 %! assert (length (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
|
1540 %! 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
|
1541 %! assert (isequal (c{3}, [3; -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
|
1542 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1543 %!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
|
1544 %! 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
|
1545 %! 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
|
1546 %! 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
|
1547 %! 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
|
1548 %! 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
|
1549 %! 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
|
1550 %! 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
|
1551 |
7a19c5678f91
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 %!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
|
1553 %! str = "13, -, NA, str1, -25\r\n// Middle line\r\n36, na, 05, str3, 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
|
1554 %! a = textscan (str, "%d %n %f %s %n", "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
|
1555 %! "treatAsEmpty", {"NA", "na", "-"},"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
|
1556 %! assert (a{1}, int32 ([13; 36])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1557 %! assert (a{2}, [NaN; 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
|
1558 %! assert (a{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
|
1559 %! assert (a{4}, {"str1"; "str3"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1560 %! assert (a{5}, [-25; 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
|
1561 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1562 %!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
|
1563 %! 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
|
1564 %! 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
|
1565 %! 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
|
1566 %! 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
|
1567 %! fmt = "Km:%d = hhh%1sjjj miles%dhour"; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1568 %! a = textscan (str, fmt, "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
|
1569 %! assert (a{1}', int32 ([10 15 2 25])); |
7a19c5678f91
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 %! assert (a{2}', {'B' 'J' 'R' 'Z'}); |
7a19c5678f91
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 %! assert (a{3}', int32 ([16 241 3 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
|
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 with default endofline parameter |
7a19c5678f91
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 %!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
|
1575 %! 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
|
1576 %! 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
|
1577 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1578 ## Test with endofline parameter set to "" (empty) - newline should be in word |
7a19c5678f91
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 %!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
|
1580 %! c = textscan ("L1\nL2", "%s", "endofline", ""); |
7a19c5678f91
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 %! assert (int8 ([c{:}{:}]), int8 ([ 76, 49, 10, 76, 50 ])); |
7a19c5678f91
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 |
7a19c5678f91
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 ### Matlab fails this test. A literal after a conversion is not a 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
|
1584 #%!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
|
1585 #%! ## No delimiters at all besides EOL. Skip fields, even empty fields |
7a19c5678f91
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 #%! str = "Text1Text2Text\nTextText4Text\nText57Text"; |
7a19c5678f91
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 #%! c = textscan (str, "Text%*dText%dText"); |
7a19c5678f91
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{1}, int32 ([2; 4; 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
|
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 ## 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
|
1591 %!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
|
1592 %! 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
|
1593 %! 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
|
1594 %! 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
|
1595 %! 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
|
1596 %! 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
|
1597 %! 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
|
1598 %! 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
|
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 ## 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
|
1601 %!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
|
1602 %! 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
|
1603 %! 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
|
1604 %! 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
|
1605 %! 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
|
1606 %! 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
|
1607 %! 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
|
1608 %! 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
|
1609 %! 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
|
1610 %! 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
|
1611 %! 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
|
1612 %! 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
|
1613 %! 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
|
1614 |
7a19c5678f91
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 ## 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
|
1616 %!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
|
1617 %! 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
|
1618 %! 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
|
1619 %! 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
|
1620 %! 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
|
1621 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1622 ## 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
|
1623 %!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
|
1624 %! c = textscan ("a first, \n second, third", "%s %c %11c", '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
|
1625 %! 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
|
1626 %! 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
|
1627 %! 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
|
1628 |
7a19c5678f91
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 ## 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
|
1630 %!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
|
1631 %! 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
|
1632 %! c = textscan (str, "%4d %4d", "delimiter", ";", "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
|
1633 %! assert (c, {[12 34; 1234 5678; 9 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
|
1634 |
7a19c5678f91
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 ## 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
|
1636 %!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
|
1637 %! 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
|
1638 %! c = textscan (str, "%4f %f", "delimiter", ";", "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
|
1639 %! assert (c, {[12 34; 1234 56789; 7 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
|
1640 |
7a19c5678f91
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 ## Ignore trailing delimiter, but use leading one |
7a19c5678f91
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 %!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
|
1643 %! 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
|
1644 %! c = textscan (str, "%10.2f %f", "delimiter", ",", "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
|
1645 %! "expChars", "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
|
1646 %! assert (c, {[1223 34; 12345.79-9876j 78; NaN 10000]}, 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
|
1647 |
7a19c5678f91
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 %!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
|
1649 %! ## Multi-character 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
|
1650 %! 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
|
1651 %! 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
|
1652 %! 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
|
1653 %! 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
|
1654 |
7a19c5678f91
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 ### Delimiters as part of literals, and following literals |
7a19c5678f91
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 #%!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
|
1657 #%! str = "12 R&D & 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
|
1658 #%! c = textscan (str, "%f R&D %f", "delimiter", "&", "collectOutput", 1, "EmptyValue", -99); |
7a19c5678f91
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 #%! assert (c, {[12 -99; 7 -99]}); |
7a19c5678f91
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 # |
7a19c5678f91
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 ### Delimiters as part of literals, and before literals |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1662 #%!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
|
1663 #%! str = "12 & R&D 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
|
1664 #%! c = textscan (str, "%f R&D %f", "delimiter", "&", "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
|
1665 #%! assert (c, {[12 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
|
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 %!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
|
1668 %! ## Check number of lines read, not number of passes through format 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
|
1669 %! 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
|
1670 %! 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
|
1671 %! 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
|
1672 %! 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
|
1673 %! 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
|
1674 %! 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
|
1675 %! 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
|
1676 %! 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
|
1677 %! 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
|
1678 %! 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
|
1679 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1680 %!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
|
1681 %! ## Check number of lines read, not number of passes through format 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
|
1682 %! 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
|
1683 %! 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
|
1684 %! 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
|
1685 %! 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
|
1686 %! 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
|
1687 %! 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
|
1688 %! 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
|
1689 %! assert (c, {[1;3], [2;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
|
1690 |
7a19c5678f91
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 %!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
|
1692 %! ## Check number of lines read, with multiple 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
|
1693 %! 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
|
1694 %! 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
|
1695 %! 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
|
1696 %! 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
|
1697 %! 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
|
1698 %! 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
|
1699 %! 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
|
1700 %! assert (c, {[1;3], [2;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
|
1701 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1702 %!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
|
1703 %! ## Check ReturnOnError |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1704 %! 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
|
1705 %! 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
|
1706 %! 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
|
1707 %! 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
|
1708 %! 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
|
1709 %! c = textscan (fid, "%f %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
|
1710 %! 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
|
1711 %! d = 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
|
1712 %! 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
|
1713 %! 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
|
1714 %! 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
|
1715 %! u = textscan (str, "%f %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
|
1716 %! v = textscan (str, "%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
|
1717 %! assert (c, {[1;4], [2;NaN], [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
|
1718 %! assert (d, {[1;4], [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
|
1719 %! assert (u, {[1;4], [2;NaN], [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
|
1720 %! assert (v, {[1;4], [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
|
1721 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1722 %!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
|
1723 %! ## Check ReturnOnError |
7a19c5678f91
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 %! 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
|
1727 %! 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
|
1728 %! 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
|
1729 %! 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
|
1730 %! 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
|
1731 %! 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
|
1732 %! 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
|
1733 %! u = textscan (str, "%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
|
1734 %! assert (c, {[1;4], 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
|
1735 %! assert (u, {[1;4], 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
|
1736 |
7a19c5678f91
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 %!error <Read error in field 2 of row 2> textscan ("1 2 3\n4 s 6", "%f %f %f", "ReturnOnError", 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
|
1738 |
7a19c5678f91
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 %!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
|
1740 %! ## Check ReturnOnError |
7a19c5678f91
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 %! 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
|
1742 %! 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
|
1743 %! 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
|
1744 %! 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
|
1745 %! c = textscan (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
|
1746 %! 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
|
1747 %! d = textscan (fid, "", "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
|
1748 %! 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
|
1749 %! 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
|
1750 %! 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
|
1751 %! assert (c, {[1;4], [NaN;5], [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
|
1752 %! assert (d, {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
|
1753 |
7a19c5678f91
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 %!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
|
1755 %! ## Check ReturnOnError with empty fields |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1756 %! c = textscan ("1,,3\n4,5,6", "", "Delimiter", ",", "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
|
1757 %! assert (c, {[1;4], [NaN;5], [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
|
1758 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1759 %!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
|
1760 %! ## Check ReturnOnError with empty fields |
7a19c5678f91
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 %! c = textscan ("1,,3\n4,5,6", "%f %f %f", "Delimiter", ",", "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
|
1762 %! assert (c, {[1;4], [NaN;5], [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
|
1763 |
7a19c5678f91
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 %!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
|
1765 %! ## Check ReturnOnError in first column |
7a19c5678f91
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 ("1 2 3\ns 5 6", "", "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 %! assert (c, {1, 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
|
1768 |
7a19c5678f91
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 ## Test input validation |
7a19c5678f91
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 %!error textscan () |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1771 %!error textscan (single (40)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1772 %!error textscan ({40}) |
7a19c5678f91
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 %!error <must be a string> textscan ("Hello World", 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
|
1774 #%!error <cannot provide position information> [C, pos] = textscan ("Hello World") |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1775 %!error <at most one character or> textscan ("Hello World", '%s', 'EndOfLine', 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
|
1776 %!error <'%z' is not a valid format specifier> textscan ("1.0", "%z"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1777 %!error <no valid format conversion specifiers> textscan ("1.0", "foo"); |
7a19c5678f91
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 |
7a19c5678f91
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 ## Test incomplete first data line |
7a19c5678f91
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 %! R = textscan (['Empty1' char(10)], 'Empty%d %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
|
1781 %! assert (R{1}, int32 (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
|
1782 %! assert (isempty (R{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
|
1783 |
7a19c5678f91
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 ## bug #37023 |
7a19c5678f91
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 %!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
|
1786 %! 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
|
1787 %! 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
|
1788 %! 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
|
1789 |
7a19c5678f91
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 ## Whitespace test (bug #37333) using 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
|
1791 %!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
|
1792 %! 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
|
1793 %! 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
|
1794 %! 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
|
1795 %! 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
|
1796 %! 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
|
1797 %! 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
|
1798 %! 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
|
1799 %! 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
|
1800 %! 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
|
1801 %! 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
|
1802 %! 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
|
1803 %! 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
|
1804 %! assert (strcmp (lh, 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
|
1805 %! end |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1806 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1807 ## Whitespace test (bug #37333), adding multipleDelimsAsOne true arg |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1808 %!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
|
1809 %! 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
|
1810 %! 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
|
1811 %! 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
|
1812 %! 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
|
1813 %! 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
|
1814 %! 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
|
1815 %! 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
|
1816 %! 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
|
1817 %! 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
|
1818 %! 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
|
1819 %! 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
|
1820 %! 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
|
1821 %! assert (strcmp (lh, 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
|
1822 %! end |
7a19c5678f91
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 |
7a19c5678f91
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 ## Whitespace test (bug #37333), adding multipleDelimsAsOne false arg |
7a19c5678f91
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 %!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
|
1826 %! 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
|
1827 %! 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
|
1828 %! 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
|
1829 %! 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
|
1830 %! 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
|
1831 %! 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
|
1832 %! 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
|
1833 %! 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
|
1834 %! 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
|
1835 %! 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
|
1836 %! 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
|
1837 %! 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
|
1838 %! 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
|
1839 %! assert (strcmp (lh, 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
|
1840 %! end |
7a19c5678f91
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 |
7a19c5678f91
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 ## Whitespace test (bug #37333) whitespace "" arg |
7a19c5678f91
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 %!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
|
1844 %! 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
|
1845 %! 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
|
1846 %! 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
|
1847 %! 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
|
1848 %! 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
|
1849 %! 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
|
1850 %! 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
|
1851 %! 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
|
1852 %! 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
|
1853 %! 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
|
1854 %! 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
|
1855 %! assert (strcmp (lh, 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
|
1856 %! end |
7a19c5678f91
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 |
7a19c5678f91
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 ## Whitespace test (bug #37333), whitespace " " arg |
7a19c5678f91
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 %!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
|
1860 %! 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
|
1861 %! 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
|
1862 %! 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
|
1863 %! 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
|
1864 %! 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
|
1865 %! 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
|
1866 %! 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
|
1867 %! 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
|
1868 %! 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
|
1869 %! 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
|
1870 %! 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
|
1871 %! 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
|
1872 %! assert (strcmp (lh, 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
|
1873 %! end |
7a19c5678f91
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 |
7a19c5678f91
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 ## 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
|
1876 %!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
|
1877 %! 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
|
1878 %! 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
|
1879 %! 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
|
1880 %! 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
|
1881 %! A = textscan (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
|
1882 %! 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
|
1883 %! 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
|
1884 %! 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
|
1885 %! assert (A{1}, [1 ; 5], 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
|
1886 %! assert (A{2}, [2 ; 6], 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
|
1887 %! assert (A{3}, [3 ; 7], 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
|
1888 %! assert (A{4}, [4 ; 8], 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
|
1889 %! 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
|
1890 |
7a19c5678f91
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 ## 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
|
1892 %!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
|
1893 %! 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
|
1894 %! 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
|
1895 %! 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
|
1896 %! 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
|
1897 %! A = textscan (fid, "", "delimiter", ",", "EmptyValue", 999, "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
|
1898 %! 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
|
1899 %! 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
|
1900 %! assert (A{1}, [999, 2, 999, 4; 5, 6, 999, 999], 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
|
1901 |
7a19c5678f91
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 ## 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
|
1903 |
7a19c5678f91
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 %!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
|
1905 %! 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
|
1906 %! 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
|
1907 %! 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
|
1908 %! try |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1909 %! A = textscan (fid, "", "headerlines"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1910 %! end_try_catch; |
7a19c5678f91
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 (!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
|
1912 %! 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
|
1913 %! 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
|
1914 %! 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
|
1915 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1916 %!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
|
1917 %! 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
|
1918 %! 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
|
1919 %! 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
|
1920 %! try |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1921 %! A = textscan (fid, "", "headerlines", "hh"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1922 %! end_try_catch; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1923 %! 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
|
1924 %! 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
|
1925 %! 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
|
1926 |
7a19c5678f91
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 %!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
|
1928 %! ## Skip headerlines |
7a19c5678f91
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 %! A = textscan ("field 1 field2\n 1 2\n3 4", "", "headerlines", 1, "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
|
1930 %! assert (A, {[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
|
1931 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1932 %!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
|
1933 %! ## Skip headerlines with non-default EOL |
7a19c5678f91
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 %! A = textscan ("field 1 field2\r 1 2\r3 4", "", "headerlines", 2, "collectOutput", 1, "EndOfLine", '\r'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1935 %! assert (A, {[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
|
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 %!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
|
1938 %! 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
|
1939 %! 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
|
1940 %! 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
|
1941 %! 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
|
1942 %! 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
|
1943 %! try |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1944 %! A = textscan (fid, "%f", "EndOfLine", "\n\r"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1945 %! end_try_catch; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1946 %! 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
|
1947 %! 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
|
1948 %! 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
|
1949 |
7a19c5678f91
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 %!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
|
1951 %! 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
|
1952 %! 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
|
1953 %! 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
|
1954 %! 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
|
1955 %! 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
|
1956 %! try |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1957 %! A = textscan (fid, "%f", "EndOfLine", 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
|
1958 %! end_try_catch; |
7a19c5678f91
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 %! 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
|
1960 %! 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
|
1961 %! 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
|
1962 |
7a19c5678f91
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 ## Bug #41824 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1964 %!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
|
1965 %! assert (textscan ("123", "", "whitespace", " "){:}, 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
|
1966 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1967 ## Bug #42343-1, just test supplied emptyvalue |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1968 %!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
|
1969 %! assert (textscan (",NaN", "", "delimiter", "," ,"emptyValue" ,Inf), {Inf, 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
|
1970 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1971 ## Bug #42343-2, test padding with supplied emptyvalue |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1972 %!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
|
1973 %! a = textscan (",1,,4\nInf, ,NaN\n", "", "delimiter", ",", "emptyvalue", -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
|
1974 %! assert (cell2mat (a), [-10, 1, -10, 4; Inf, -10, NaN, -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
|
1975 |
7a19c5678f91
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 ## Bug #42528 |
7a19c5678f91
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 %!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
|
1978 %! assert (textscan ("1i", ""){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
|
1979 %! assert (cell2mat (textscan ("3, 2-4i, NaN\n -i, 1, 23.4+2.2i\n 1+1 1+1j", "", "delimiter", ",")), [3+0i, 2-4i, NaN+0i; 0-i, 1+0i, 23.4+2.2i; 1 1 1+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
|
1980 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1981 %!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
|
1982 %! ## TreatAsEmpty |
7a19c5678f91
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 %! C = textscan ("1,2,3,NN,5,6\n", "%d%d%d%f", "delimiter", ",", "TreatAsEmpty", "NN"); |
7a19c5678f91
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 %! 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
|
1985 %! 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
|
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 ## 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
|
1988 %!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
|
1989 %! str = "11, 12, 13,, 15\n21,, 23, 24, 25\n,, 33, 34, 35\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
|
1990 %! C = textscan (str, "%f %f %f %f", "delimiter", ",", "multipledelimsasone", 1, "endofline", "\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
|
1991 %! 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
|
1992 %! 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
|
1993 %! 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
|
1994 %! 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
|
1995 |
7a19c5678f91
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 ## Bug #44750 |
7a19c5678f91
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 %!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
|
1998 %! assert (textscan ("/home/foo/", "%s", "delimiter", "/", "MultipleDelimsAsOne", 1){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
|
1999 %! {"home"; "foo"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2000 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2001 ### Allow cuddling %sliteral but warn it is ambiguous |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2002 #%!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
|
2003 #%! C = textscan ("abcxyz51\nxyz83\n##xyz101", "%s xyz %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
|
2004 #%! assert (C{1}([1 3]), {"abc"; "##"}); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2005 #%! assert (isempty (C{1}{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
|
2006 #%! assert (C{2}, int32 ([51; 83; 101])); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2007 ### Literals are not 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
|
2008 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2009 ## 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
|
2010 %!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
|
2011 %! assert (textscan ("Total: 32.5 % (of cm values)", "Total: %f %% (of cm values)"){1}, 32.5, 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
|
2012 |
7a19c5678f91
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 ## Test various forms of string format specifiers (bug #45712) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2014 %!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
|
2015 %! 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
|
2016 %! 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
|
2017 %! 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
|
2018 |
7a19c5678f91
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 %% Bit width, fixed width conv. 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
|
2020 %!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
|
2021 %! 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
|
2022 %! 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
|
2023 %! 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
|
2024 %! 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
|
2025 %! 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
|
2026 %! 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
|
2027 %! 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
|
2028 %! 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
|
2029 %! 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
|
2030 %! 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
|
2031 %! 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
|
2032 %! 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
|
2033 %! 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
|
2034 %! 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
|
2035 %! 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
|
2036 %! 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
|
2037 %! 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
|
2038 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2039 %% Bit width, fixed width conv. specifiers -- check the right amount is left |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2040 %!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
|
2041 %! 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
|
2042 %! 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
|
2043 %! 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
|
2044 %! 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
|
2045 %! 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
|
2046 %! 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
|
2047 %! 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
|
2048 %! 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
|
2049 %! 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
|
2050 %! 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
|
2051 %! 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
|
2052 %! 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
|
2053 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2054 %!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
|
2055 %! 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
|
2056 %! 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
|
2057 %! 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
|
2058 %! 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
|
2059 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2060 %!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
|
2061 %! 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
|
2062 %! 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
|
2063 %! 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
|
2064 %! 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
|
2065 |
7a19c5678f91
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 %!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
|
2067 %! 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
|
2068 %! 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
|
2069 %! 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
|
2070 |
7a19c5678f91
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 %% field width interrupts exponent. (Matlab incorrectly gives [12, 2e12]) |
7a19c5678f91
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 %!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
|
2073 %! 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
|
2074 %! 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
|
2075 %! 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
|
2076 |
7a19c5678f91
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 %% %[] 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
|
2078 %% Plain [..] and *[..] |
7a19c5678f91
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 %!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
|
2080 %! 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
|
2081 %! 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
|
2082 %! 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
|
2083 %! 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
|
2084 |
7a19c5678f91
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 %!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
|
2086 %! 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
|
2087 |
7a19c5678f91
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 %% [^..] and *[^..] |
7a19c5678f91
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 %!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
|
2090 %! 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
|
2091 %! 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
|
2092 %! 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
|
2093 %! 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
|
2094 |
7a19c5678f91
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 %% [..] and [^..] containing 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
|
2096 %!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
|
2097 %! cr = "ab cd efguv wx1Any\na ce gx yz2Trailing\n 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
|
2098 %! C = textscan (cr, "%[ abcdefg] %*[^0123456789] %s", "delimiter", " \n", "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
|
2099 %! 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
|
2100 %! 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
|
2101 |
7a19c5678f91
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 %% Bug #36464 |
7a19c5678f91
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 %!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
|
2104 %! assert (textscan ('1 2 3 4 5 6', "%*n%n%*[^\n]"){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
|
2105 |
7a19c5678f91
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 %% test %[]] and %[^]] |
7a19c5678f91
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 %!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
|
2108 %! assert (textscan ('345]', "%*[123456]%[]]"){1}{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
|
2109 %! assert (textscan ('345]', "%*[^]]%s"){1}{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
|
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 that "-i" checks the next two characters |
7a19c5678f91
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 %!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
|
2113 %! 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
|
2114 %! 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
|
2115 |
7a19c5678f91
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 %% Again for "+i", this time with custom parser |
7a19c5678f91
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 ("+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
|
2119 %! 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
|
2120 |
7a19c5678f91
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 %% Check single quoted format interprets control sequences |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2122 %!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
|
2123 %! 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
|
2124 %! 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
|
2125 |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2126 %% Check a non-empty line with no valid conversion registers empytValue |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2127 %!test |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2128 %! C = textscan ("Empty\n", "Empty%f %f"); |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2129 %! assert (C, { NaN, NaN }) |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2130 |
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
|
2131 %% Check overflow and underflow of integer types |
7a19c5678f91
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 %!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
|
2133 %! 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
|
2134 %! 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
|
2135 %! 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
|
2136 %! 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
|
2137 %! 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
|
2138 %! 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
|
2139 %! 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
|
2140 %! 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
|
2141 %! 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
|
2142 %! 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
|
2143 %! 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
|
2144 %! 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
|
2145 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2146 %% Tests from Matlab (does The MathWorks have any copyright over the input?) |
7a19c5678f91
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 %! 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
|
2149 %! 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
|
2150 %! 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
|
2151 %! 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
|
2152 %! 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
|
2153 %! 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
|
2154 %! 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
|
2155 %! %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
|
2156 %! 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
|
2157 %! 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
|
2158 %! 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
|
2159 %! 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
|
2160 %! 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
|
2161 %! 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
|
2162 %! 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
|
2163 %! 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
|
2164 %! 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
|
2165 %! 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
|
2166 %! 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
|
2167 %! 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
|
2168 %! 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
|
2169 %! C = textscan (fid,'%s %*[^\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
|
2170 %! 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
|
2171 %! 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
|
2172 %! 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
|
2173 |
7a19c5678f91
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 %!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
|
2175 %! 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
|
2176 %! 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
|
2177 %! 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
|
2178 %! 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
|
2179 %! 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
|
2180 %! 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
|
2181 %! 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
|
2182 %! 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
|
2183 %! 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
|
2184 %! 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
|
2185 |
7a19c5678f91
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 %!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
|
2187 %! 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
|
2188 %! 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
|
2189 %! 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
|
2190 %! 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
|
2191 %! 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
|
2192 %! 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
|
2193 %! C = textscan (fid,"%s %n %n %n %n","Delimiter",",","TreatAsEmpty",{"NA","na"},"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
|
2194 %! 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
|
2195 %! 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
|
2196 %! 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
|
2197 %! 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
|
2198 %! 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
|
2199 %! 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
|
2200 %! 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
|
2201 |
7a19c5678f91
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 %!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
|
2203 %!## Test start of comment as 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
|
2204 %! c = textscan ("1 / 2 // 3", "%n %s %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
|
2205 %! assert (c, {1, "/", 2}); |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
2206 |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
2207 %!assert (textscan (["1 2 3 4"; "5 6 7 8"], "%f"), {[15; 26; 37; 48]}) |
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
|
2208 */ |
7a19c5678f91
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 |
7a19c5678f91
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 // 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
|
2211 #if 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
|
2212 %!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
|
2213 %!## Test unfinished 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
|
2214 %! 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
|
2215 %! 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
|
2216 |
7a19c5678f91
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 ## 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
|
2218 %!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
|
2219 %! 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
|
2220 %! 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
|
2221 %! 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
|
2222 %! 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
|
2223 %! 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
|
2224 %! 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
|
2225 %! 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
|
2226 %! 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
|
2227 %! 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
|
2228 %! 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
|
2229 %! 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
|
2230 %! 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
|
2231 #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
|
2232 |
2116 | 2233 static octave_value |
2234 do_fread (octave_stream& os, const octave_value& size_arg, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2235 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
|
2236 const octave_value& arch_arg, octave_idx_type& count) |
2116 | 2237 { |
2238 count = -1; | |
2239 | |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2240 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
|
2241 |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2242 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
|
2243 |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2244 int block_size = 1; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2245 oct_data_conv::data_type input_type; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2246 oct_data_conv::data_type output_type; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2247 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2248 try |
2116 | 2249 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2250 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
|
2251 input_type, output_type); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2252 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
2253 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2254 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2255 error (e, "fread: invalid PRECISION specified"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2256 } |
4944 | 2257 |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
2258 int skip = 0; |
3202 | 2259 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2260 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2261 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2262 skip = skip_arg.int_value (true); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2263 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
2264 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2265 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2266 error (e, "fread: SKIP must be an integer"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2267 } |
2116 | 2268 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2269 std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string"); |
2116 | 2270 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2271 oct_mach_info::float_format flt_fmt |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2272 = oct_mach_info::string_to_float_format (arch); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2273 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2274 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
|
2275 flt_fmt, count); |
2116 | 2276 } |
2277 | |
2278 DEFUN (fread, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2279 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2280 @deftypefn {} {@var{val} =} fread (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2281 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2282 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2283 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2284 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip}, @var{arch})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2285 @deftypefnx {} {[@var{val}, @var{count}] =} fread (@dots{})\n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2286 Read binary data from the file specified by the file descriptor @var{fid}.\n\ |
3372 | 2287 \n\ |
2288 The optional argument @var{size} specifies the amount of data to read\n\ | |
2289 and may be one of\n\ | |
2290 \n\ | |
2291 @table @code\n\ | |
2292 @item Inf\n\ | |
2293 Read as much as possible, returning a column vector.\n\ | |
529 | 2294 \n\ |
3372 | 2295 @item @var{nr}\n\ |
2296 Read up to @var{nr} elements, returning a column vector.\n\ | |
2297 \n\ | |
2298 @item [@var{nr}, Inf]\n\ | |
2299 Read as much as possible, returning a matrix with @var{nr} rows. If the\n\ | |
2300 number of elements read is not an exact multiple of @var{nr}, the last\n\ | |
2301 column is padded with zeros.\n\ | |
2302 \n\ | |
2303 @item [@var{nr}, @var{nc}]\n\ | |
2304 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with\n\ | |
2305 @var{nr} rows. If the number of elements read is not an exact multiple\n\ | |
2306 of @var{nr}, the last column is padded with zeros.\n\ | |
2307 @end table\n\ | |
2308 \n\ | |
2309 @noindent\n\ | |
2310 If @var{size} is omitted, a value of @code{Inf} is assumed.\n\ | |
2318 | 2311 \n\ |
3372 | 2312 The optional argument @var{precision} is a string specifying the type of\n\ |
2313 data to read and may be one of\n\ | |
2314 \n\ | |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
2315 @table @asis\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2316 @item @qcode{\"schar\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2317 @itemx @qcode{\"signed char\"}\n\ |
3372 | 2318 Signed character.\n\ |
529 | 2319 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2320 @item @qcode{\"uchar\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2321 @itemx @qcode{\"unsigned char\"}\n\ |
3372 | 2322 Unsigned character.\n\ |
2323 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2324 @item @qcode{\"int8\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2325 @itemx @qcode{\"integer*1\"}\n\ |
4944 | 2326 \n\ |
2327 8-bit signed integer.\n\ | |
2318 | 2328 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2329 @item @qcode{\"int16\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2330 @itemx @qcode{\"integer*2\"}\n\ |
4944 | 2331 16-bit signed integer.\n\ |
3372 | 2332 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2333 @item @qcode{\"int32\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2334 @itemx @qcode{\"integer*4\"}\n\ |
4944 | 2335 32-bit signed integer.\n\ |
3372 | 2336 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2337 @item @qcode{\"int64\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2338 @itemx @qcode{\"integer*8\"}\n\ |
4944 | 2339 64-bit signed integer.\n\ |
2340 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2341 @item @qcode{\"uint8\"}\n\ |
4944 | 2342 8-bit unsigned integer.\n\ |
529 | 2343 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2344 @item @qcode{\"uint16\"}\n\ |
4944 | 2345 16-bit unsigned integer.\n\ |
3372 | 2346 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2347 @item @qcode{\"uint32\"}\n\ |
4944 | 2348 32-bit unsigned integer.\n\ |
3372 | 2349 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2350 @item @qcode{\"uint64\"}\n\ |
4944 | 2351 64-bit unsigned integer.\n\ |
2352 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2353 @item @qcode{\"single\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2354 @itemx @qcode{\"float32\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2355 @itemx @qcode{\"real*4\"}\n\ |
4944 | 2356 32-bit floating point number.\n\ |
3372 | 2357 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2358 @item @qcode{\"double\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2359 @itemx @qcode{\"float64\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2360 @itemx @qcode{\"real*8\"}\n\ |
4944 | 2361 64-bit floating point number.\n\ |
2362 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2363 @item @qcode{\"char\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2364 @itemx @qcode{\"char*1\"}\n\ |
4944 | 2365 Single character.\n\ |
3372 | 2366 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2367 @item @qcode{\"short\"}\n\ |
4944 | 2368 Short integer (size is platform dependent).\n\ |
2369 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2370 @item @qcode{\"int\"}\n\ |
4944 | 2371 Integer (size is platform dependent).\n\ |
2372 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2373 @item @qcode{\"long\"}\n\ |
4944 | 2374 Long integer (size is platform dependent).\n\ |
3372 | 2375 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2376 @item @qcode{\"ushort\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2377 @itemx @qcode{\"unsigned short\"}\n\ |
4944 | 2378 Unsigned short integer (size is platform dependent).\n\ |
4610 | 2379 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2380 @item @qcode{\"uint\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2381 @itemx @qcode{\"unsigned int\"}\n\ |
4944 | 2382 Unsigned integer (size is platform dependent).\n\ |
4610 | 2383 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2384 @item @qcode{\"ulong\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2385 @itemx @qcode{\"unsigned long\"}\n\ |
4944 | 2386 Unsigned long integer (size is platform dependent).\n\ |
2387 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2388 @item @qcode{\"float\"}\n\ |
4944 | 2389 Single precision floating point number (size is platform dependent).\n\ |
3372 | 2390 @end table\n\ |
2391 \n\ | |
2392 @noindent\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2393 The default precision is @qcode{\"uchar\"}.\n\ |
2318 | 2394 \n\ |
4944 | 2395 The @var{precision} argument may also specify an optional repeat\n\ |
2396 count. For example, @samp{32*single} causes @code{fread} to read\n\ | |
2397 a block of 32 single precision floating point numbers. Reading in\n\ | |
2398 blocks is useful in combination with the @var{skip} argument.\n\ | |
2399 \n\ | |
2400 The @var{precision} argument may also specify a type conversion.\n\ | |
2401 For example, @samp{int16=>int32} causes @code{fread} to read 16-bit\n\ | |
2402 integer values and return an array of 32-bit integer values. By\n\ | |
2403 default, @code{fread} returns a double precision array. The special\n\ | |
2404 form @samp{*TYPE} is shorthand for @samp{TYPE=>TYPE}.\n\ | |
2405 \n\ | |
7096 | 2406 The conversion and repeat counts may be combined. For example, the\n\ |
2407 specification @samp{32*single=>single} causes @code{fread} to read\n\ | |
2408 blocks of single precision floating point values and return an array\n\ | |
2409 of single precision values instead of the default array of double\n\ | |
2410 precision values.\n\ | |
4944 | 2411 \n\ |
3372 | 2412 The optional argument @var{skip} specifies the number of bytes to skip\n\ |
4944 | 2413 after each element (or block of elements) is read. If it is not\n\ |
2414 specified, a value of 0 is assumed. If the final block read is not\n\ | |
2415 complete, the final skip is omitted. For example,\n\ | |
2416 \n\ | |
2417 @example\n\ | |
2418 fread (f, 10, \"3*single=>single\", 8)\n\ | |
2419 @end example\n\ | |
2420 \n\ | |
2421 @noindent\n\ | |
2422 will omit the final 8-byte skip because the last read will not be\n\ | |
2423 a complete block of 3 values.\n\ | |
3372 | 2424 \n\ |
2425 The optional argument @var{arch} is a string specifying the data format\n\ | |
2426 for the file. Valid values are\n\ | |
529 | 2427 \n\ |
18078
b06a9768b643
doc: Don't use @table @qcode to avoid problems with Texinfo 5.2.
Rik <rik@octave.org>
parents:
18040
diff
changeset
|
2428 @table @asis\n\ |
20431
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
2429 @item @qcode{\"native\"} or @qcode{\"n\"}\n\ |
3372 | 2430 The format of the current machine.\n\ |
2431 \n\ | |
20431
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
2432 @item @qcode{\"ieee-be\"} or @qcode{\"b\"}\n\ |
3372 | 2433 IEEE big endian.\n\ |
2434 \n\ | |
20431
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
2435 @item @qcode{\"ieee-le\"} or @qcode{\"l\"}\n\ |
3372 | 2436 IEEE little endian.\n\ |
2437 @end table\n\ | |
2318 | 2438 \n\ |
20439
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20431
diff
changeset
|
2439 If no @var{arch} is given the value used in the call to @code{fopen} which\n\ |
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20431
diff
changeset
|
2440 created the file descriptor is used. Otherwise, the value specified with\n\ |
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20431
diff
changeset
|
2441 @code{fread} overrides that of @code{fopen} and determines the data format.\n\ |
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20431
diff
changeset
|
2442 \n\ |
18208
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
2443 The output argument @var{val} contains the data read from the file.\n\ |
20439
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20431
diff
changeset
|
2444 \n\ |
18208
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
2445 The optional return value @var{count} contains the number of elements read.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
2446 @seealso{fwrite, fgets, fgetl, fscanf, fopen}\n\ |
5642 | 2447 @end deftypefn") |
529 | 2448 { |
2116 | 2449 int nargin = args.length (); |
2450 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2451 if (nargin < 1 || nargin > 5) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2452 print_usage (); |
2116 | 2453 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2454 octave_stream os = octave_stream_list::lookup (args(0), "fread"); |
2116 | 2455 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2456 octave_value size = lo_ieee_inf_value (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2457 octave_value prec = "uchar"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2458 octave_value skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2459 octave_value arch = "unknown"; |
2116 | 2460 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2461 int idx = 1; |
2116 | 2462 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2463 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
|
2464 size = args(idx++); |
2116 | 2465 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2466 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2467 prec = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2468 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2469 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2470 skip = args(idx++); |
4257 | 2471 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2472 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2473 arch = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2474 else if (skip.is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2475 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2476 arch = skip; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2477 skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2478 } |
2116 | 2479 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2480 octave_idx_type count = -1; |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
2481 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2482 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
|
2483 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2484 return ovl (tmp, count); |
529 | 2485 } |
2486 | |
2116 | 2487 static int |
2488 do_fwrite (octave_stream& os, const octave_value& data, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2489 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
|
2490 const octave_value& arch_arg) |
2116 | 2491 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
2492 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
|
2493 |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
2494 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
|
2495 oct_data_conv::data_type output_type; |
2116 | 2496 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2497 try |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
2498 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2499 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
|
2500 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
2501 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2502 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2503 error (e, "fwrite: invalid PRECISION specified"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2504 } |
2116 | 2505 |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
2506 int skip = 0; |
3202 | 2507 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2508 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2509 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2510 skip = skip_arg.int_value (true); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2511 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
2512 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2513 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2514 error (e, "fwrite: SKIP must be an integer"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2515 } |
2116 | 2516 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2517 std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string"); |
2116 | 2518 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2519 oct_mach_info::float_format flt_fmt |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2520 = oct_mach_info::string_to_float_format (arch); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2521 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2522 return os.write (data, block_size, output_type, skip, flt_fmt); |
2116 | 2523 } |
2524 | |
2525 DEFUN (fwrite, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2526 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2527 @deftypefn {} {} fwrite (@var{fid}, @var{data})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2528 @deftypefnx {} {} fwrite (@var{fid}, @var{data}, @var{precision})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2529 @deftypefnx {} {} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2530 @deftypefnx {} {} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip}, @var{arch})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2531 @deftypefnx {} {@var{count} =} fwrite (@dots{})\n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2532 Write data in binary form to the file specified by the file descriptor\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2533 @var{fid}, returning the number of values @var{count} successfully written\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2534 to the file.\n\ |
1181 | 2535 \n\ |
3372 | 2536 The argument @var{data} is a matrix of values that are to be written to\n\ |
2537 the file. The values are extracted in column-major order.\n\ | |
1181 | 2538 \n\ |
3372 | 2539 The remaining arguments @var{precision}, @var{skip}, and @var{arch} are\n\ |
2540 optional, and are interpreted as described for @code{fread}.\n\ | |
1181 | 2541 \n\ |
3372 | 2542 The behavior of @code{fwrite} is undefined if the values in @var{data}\n\ |
2543 are too large to fit in the specified precision.\n\ | |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
2544 @seealso{fread, fputs, fprintf, fopen}\n\ |
5642 | 2545 @end deftypefn") |
1181 | 2546 { |
2116 | 2547 int nargin = args.length (); |
2548 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2549 if (nargin < 2 || nargin > 5) |
5823 | 2550 print_usage (); |
2116 | 2551 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2552 octave_stream os = octave_stream_list::lookup (args(0), "fwrite"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2553 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2554 octave_value prec = "uchar"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2555 octave_value skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2556 octave_value arch = "unknown"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2557 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2558 int idx = 1; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2559 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2560 octave_value data = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2561 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2562 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2563 prec = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2564 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2565 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2566 skip = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2567 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2568 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2569 arch = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2570 else if (skip.is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2571 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2572 arch = skip; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2573 skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2574 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2575 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
2576 return ovl (do_fwrite (os, data, prec, skip, arch)); |
1181 | 2577 } |
2578 | |
5906 | 2579 DEFUNX ("feof", Ffeof, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2580 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2581 @deftypefn {} {@var{status} =} feof (@var{fid})\n\ |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2582 Return 1 if an end-of-file condition has been encountered for the file\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2583 specified by file descriptor @var{fid} and 0 otherwise.\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2584 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2585 Note that @code{feof} will only return 1 if the end of the file has already\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2586 been encountered, not if the next read operation will result in an\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2587 end-of-file condition.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2588 @seealso{fread, frewind, fseek, fclear, fopen}\n\ |
5642 | 2589 @end deftypefn") |
529 | 2590 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2591 if (args.length () != 1) |
5823 | 2592 print_usage (); |
444 | 2593 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2594 octave_stream os = octave_stream_list::lookup (args(0), "feof"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2595 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
2596 return ovl (os.eof () ? 1.0 : 0.0); |
444 | 2597 } |
2598 | |
5906 | 2599 DEFUNX ("ferror", Fferror, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2600 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2601 @deftypefn {} {@var{msg} =} ferror (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2602 @deftypefnx {} {[@var{msg}, @var{err}] =} ferror (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2603 @deftypefnx {} {[@var{dots}] =} ferror (@var{fid}, \"clear\")\n\ |
19150 | 2604 Query the error status of the stream specified by file descriptor @var{fid}\n\ |
2605 \n\ | |
2606 If an error condition exists then return a string @var{msg} describing the\n\ | |
2607 error. Otherwise, return an empty string @qcode{\"\"}.\n\ | |
9797
f569f46a1c34
update ferror doc string, take 2
John W. Eaton <jwe@octave.org>
parents:
9796
diff
changeset
|
2608 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2609 The second input @qcode{\"clear\"} is optional. If supplied, the error\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2610 state on the stream will be cleared.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2611 \n\ |
19150 | 2612 The optional second output is a numeric indication of the error status.\n\ |
2613 @var{err} is 1 if an error condition has been encountered and 0 otherwise.\n\ | |
19127
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2614 \n\ |
19150 | 2615 Note that @code{ferror} indicates if an error has already occurred, not\n\ |
2616 whether the next operation will result in an error condition.\n\ | |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
2617 @seealso{fclear, fopen}\n\ |
3372 | 2618 @end deftypefn") |
1230 | 2619 { |
2095 | 2620 int nargin = args.length (); |
1230 | 2621 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2622 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2623 print_usage (); |
1230 | 2624 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2625 octave_stream os = octave_stream_list::lookup (args(0), "ferror"); |
1230 | 2626 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2627 bool clear = false; |
2095 | 2628 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2629 if (nargin == 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2630 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2631 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
|
2632 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2633 clear = (opt == "clear"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2634 } |
1755 | 2635 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2636 int error_number = 0; |
1230 | 2637 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2638 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
|
2639 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2640 return ovl (error_message, error_number); |
1230 | 2641 } |
2642 | |
18477
aa7ca90ce746
avoid problems if popen is a macro
John W. Eaton <jwe@octave.org>
parents:
18040
diff
changeset
|
2643 DEFUNX ("popen", Fpopen, args, , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19727
diff
changeset
|
2644 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2645 @deftypefn {} {@var{fid} =} popen (@var{command}, @var{mode})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2646 Start a process and create a pipe.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2647 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2648 The name of the command to run is given by @var{command}. The argument\n\ |
3301 | 2649 @var{mode} may be\n\ |
2650 \n\ | |
2651 @table @code\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2652 @item @qcode{\"r\"}\n\ |
3301 | 2653 The pipe will be connected to the standard output of the process, and\n\ |
2654 open for reading.\n\ | |
1230 | 2655 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2656 @item @qcode{\"w\"}\n\ |
3301 | 2657 The pipe will be connected to the standard input of the process, and\n\ |
2658 open for writing.\n\ | |
2659 @end table\n\ | |
2660 \n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2661 The file identifier corresponding to the input or output stream of the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2662 process is returned in @var{fid}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2663 \n\ |
10840 | 2664 For example:\n\ |
1230 | 2665 \n\ |
3301 | 2666 @example\n\ |
2667 @group\n\ | |
2668 fid = popen (\"ls -ltr / | tail -3\", \"r\");\n\ | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7730
diff
changeset
|
2669 while (ischar (s = fgets (fid)))\n\ |
3301 | 2670 fputs (stdout, s);\n\ |
2671 endwhile\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
2672 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
2673 @print{} drwxr-xr-x 33 root root 3072 Feb 15 13:28 etc\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
2674 @print{} drwxr-xr-x 3 root root 1024 Feb 15 13:28 lib\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
2675 @print{} drwxrwxrwt 15 root root 2048 Feb 17 14:53 tmp\n\ |
3301 | 2676 @end group\n\ |
2677 @end example\n\ | |
18950
ed3cb9f81145
file-io.cc (popen): Add seealso popen2
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18487
diff
changeset
|
2678 @seealso{popen2}\n\ |
3301 | 2679 @end deftypefn") |
1230 | 2680 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2681 if (args.length () != 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2682 print_usage (); |
1230 | 2683 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2684 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
|
2685 std::string mode = args(1).xstring_value ("popen: MODE must be a string"); |
1230 | 2686 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2687 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2688 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2689 if (mode == "r") |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2690 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2691 octave_stream ips = octave_iprocstream::create (name); |
1230 | 2692 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2693 retval = octave_stream_list::insert (ips); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2694 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2695 else if (mode == "w") |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2696 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2697 octave_stream ops = octave_oprocstream::create (name); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2698 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2699 retval = octave_stream_list::insert (ops); |
2095 | 2700 } |
1230 | 2701 else |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2702 error ("popen: invalid MODE specified"); |
1230 | 2703 |
2704 return retval; | |
2705 } | |
2706 | |
16308
122c1a7a3004
avoid trouble if pclose is a macro
John W. Eaton <jwe@octave.org>
parents:
16099
diff
changeset
|
2707 DEFUNX ("pclose", Fpclose, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2708 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2709 @deftypefn {} {} pclose (@var{fid})\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2710 Close a file identifier that was opened by @code{popen}.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2711 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2712 The function @code{fclose} may also be used for the same purpose.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2713 @seealso{fclose, popen}\n\ |
3301 | 2714 @end deftypefn") |
1230 | 2715 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2716 if (args.length () != 1) |
5823 | 2717 print_usage (); |
1379 | 2718 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
2719 return ovl (octave_stream_list::remove (args(0), "pclose")); |
1379 | 2720 } |
2721 | |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2722 DEFUN (tempname, args, , |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2723 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2724 @deftypefn {} {@var{fname} =} tempname ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2725 @deftypefnx {} {@var{fname} =} tempname (@var{dir})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2726 @deftypefnx {} {@var{fname} =} tempname (@var{dir}, @var{prefix})\n\ |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
2727 Return a unique temporary filename as a string.\n\ |
3372 | 2728 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2729 If @var{prefix} is omitted, a value of @qcode{\"oct-\"} is used.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2730 \n\ |
4267 | 2731 If @var{dir} is also omitted, the default directory for temporary files\n\ |
19385
3b4d6780d6b8
doc: Add missing closing parenthesis in tempname docstring.
Rik <rik@octave.org>
parents:
19278
diff
changeset
|
2732 (@code{P_tmpdir}) is used. If @var{dir} is provided, it must exist,\n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2733 otherwise the default directory for temporary files is used.\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2734 \n\ |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2735 Programming Note: Because the named file is not opened by @code{tempname},\n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2736 it is possible, though relatively unlikely, that it will not be available\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2737 by the time your program attempts to open it. If this is a concern,\n\ |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2738 see @code{tmpfile}.\n\ |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2739 @seealso{mkstemp, tempdir, P_tmpdir, tmpfile}\n\ |
5642 | 2740 @end deftypefn") |
1802 | 2741 { |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2742 int nargin = args.length (); |
2936 | 2743 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2744 if (nargin > 2) |
5823 | 2745 print_usage (); |
1802 | 2746 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2747 std::string dir; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2748 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2749 if (nargin > 0) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2750 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
|
2751 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2752 std::string pfx ("oct-"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2753 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2754 if (nargin > 1) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2755 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
|
2756 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
2757 return ovl (octave_tempnam (dir, pfx)); |
1802 | 2758 } |
2759 | |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2760 /* |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2761 %!test |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2762 %! if (ispc ()) |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2763 %! envname = "TMP"; |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2764 %! else |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2765 %! envname = "TMPDIR"; |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2766 %! endif |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2767 %! envdir = getenv (envname); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2768 %! unsetenv (envname); |
21457
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2769 %! ## Strip trailing file separators from P_tmpdir |
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2770 %! def_tmpdir = P_tmpdir; |
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2771 %! while (length (def_tmpdir) > 2 && strfind (filesep ("all"), def_tmpdir(end))) |
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2772 %! def_tmpdir(end) = []; |
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2773 %! endwhile |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2774 %! unwind_protect |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2775 %! ## 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
|
2776 %! fname = tempname (); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2777 %! [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
|
2778 %! 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
|
2779 %! assert (tmpfname (1:4), "oct-"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2780 %! ## 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
|
2781 %! 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
|
2782 %! 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
|
2783 %! 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
|
2784 %! fname = tempname (tmp_tmpdir); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2785 %! [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
|
2786 %! 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
|
2787 %! 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
|
2788 %! ## 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
|
2789 %! fname = tempname (""); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2790 %! [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
|
2791 %! 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
|
2792 %! assert (tmpfname (1:4), "oct-"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2793 %! ## 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
|
2794 %! fname = tempname (tmp_tmpdir, "pfx-"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2795 %! [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
|
2796 %! 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
|
2797 %! 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
|
2798 %! ## 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
|
2799 %! fname = tempname (tmp_tmpdir, ""); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2800 %! [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
|
2801 %! 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
|
2802 %! 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
|
2803 %! unwind_protect_cleanup |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2804 %! rmdir (tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2805 %! if (isempty (envdir)) |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2806 %! unsetenv (envname); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2807 %! else |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2808 %! setenv (envname, envdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2809 %! endif |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2810 %! 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
|
2811 */ |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2812 |
4326 | 2813 DEFUN (tmpfile, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2814 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2815 @deftypefn {} {[@var{fid}, @var{msg}] =} tmpfile ()\n\ |
4326 | 2816 Return the file ID corresponding to a new temporary file with a unique\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2817 name.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2818 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2819 The file is opened in binary read/write (@qcode{\"w+b\"}) mode and will be\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2820 deleted automatically when it is closed or when Octave exits.\n\ |
4326 | 2821 \n\ |
2822 If successful, @var{fid} is a valid file ID and @var{msg} is an empty\n\ | |
2823 string. Otherwise, @var{fid} is -1 and @var{msg} contains a\n\ | |
2824 system-dependent error message.\n\ | |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2825 @seealso{tempname, mkstemp, tempdir, P_tmpdir}\n\ |
5642 | 2826 @end deftypefn") |
4326 | 2827 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2828 if (args.length () != 0) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2829 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2830 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2831 octave_value_list retval; |
4326 | 2832 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2833 FILE *fid = gnulib::tmpfile (); |
4326 | 2834 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2835 if (fid) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2836 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2837 std::string nm; |
4326 | 2838 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2839 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); |
4326 | 2840 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2841 octave_stream s = octave_stdiostream::create (nm, fid, md); |
4326 | 2842 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2843 if (! s) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2844 error ("tmpfile: failed to create octave_stdiostream object"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2845 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2846 retval = ovl (octave_stream_list::insert (s), ""); |
4326 | 2847 } |
2848 else | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2849 { |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2850 retval = ovl (-1, gnulib::strerror (errno)); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2851 } |
4326 | 2852 |
2853 return retval; | |
2854 } | |
2855 | |
2856 DEFUN (mkstemp, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2857 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2858 @deftypefn {} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (\"@var{template}\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2859 @deftypefnx {} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (\"@var{template}\", @var{delete})\n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2860 Return the file descriptor @var{fid} corresponding to a new temporary file\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2861 with a unique name created from @var{template}.\n\ |
4326 | 2862 \n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2863 The last six characters of @var{template} must be @qcode{\"XXXXXX\"} and\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2864 these are replaced with a string that makes the filename unique. The file\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2865 is then created with mode read/write and permissions that are system\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2866 dependent (on GNU/Linux systems, the permissions will be 0600 for versions of\n\ |
19230
cfa9996afcbf
doc: fix stray escape sequence in mkstemp's docstring
Mike Miller <mtmiller@ieee.org>
parents:
19210
diff
changeset
|
2867 glibc 2.0.7 and later). The file is opened in binary mode and with the\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2868 @w{@code{O_EXCL}} flag.\n\ |
4326 | 2869 \n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2870 If the optional argument @var{delete} is supplied and is true, the file will\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2871 be deleted automatically when Octave exits.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2872 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2873 If successful, @var{fid} is a valid file ID, @var{name} is the name of the\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2874 file, and @var{msg} is an empty string. Otherwise, @var{fid} is -1,\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2875 @var{name} is empty, and @var{msg} contains a system-dependent error message.\n\ |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2876 @seealso{tempname, tempdir, P_tmpdir, tmpfile, fopen}\n\ |
5642 | 2877 @end deftypefn") |
4326 | 2878 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2879 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2880 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2881 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2882 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2883 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2884 std::string tmpl8 = args(0).xstring_value ("mkstemp: TEMPLATE argument must be a string"); |
4326 | 2885 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2886 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
|
2887 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2888 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
|
2889 strcpy (tmp, tmpl8.c_str ()); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2890 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2891 int fd = gnulib::mkostemp (tmp, O_BINARY); |
4326 | 2892 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2893 if (fd < 0) |
4326 | 2894 { |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2895 retval(0) = fd; |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2896 retval(2) = gnulib::strerror (errno); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2897 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2898 else |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2899 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2900 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
|
2901 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2902 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
|
2903 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2904 if (! fid) |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2905 { |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2906 retval(0) = -1; |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2907 retval(2) = gnulib::strerror (errno); |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2908 } |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2909 else |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2910 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2911 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
|
2912 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2913 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
|
2914 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2915 octave_stream s = octave_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
|
2916 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2917 if (! s) |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2918 error ("mkstemp: failed to create octave_stdiostream object"); |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2919 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2920 retval(0) = octave_stream_list::insert (s); |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2921 retval(1) = nm; |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2922 |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2923 if (nargin == 2 && args(1).is_true ()) |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2924 mark_for_deletion (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2925 } |
4326 | 2926 } |
2927 | |
2928 return retval; | |
2929 } | |
2930 | |
20200
d9f35ceff9e1
Change mkfifo to use an octal argument for MODE (bug #45054).
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
2931 // 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
|
2932 // Maybe change to be a general utility routine. |
1400 | 2933 static int |
2934 convert (int x, int ibase, int obase) | |
2935 { | |
2936 int retval = 0; | |
2937 | |
2938 int tmp = x % obase; | |
2939 | |
2940 if (tmp > ibase - 1) | |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20200
diff
changeset
|
2941 error ("umask: invalid digit"); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2942 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2943 retval = tmp; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2944 int mult = ibase; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2945 while ((x = (x - tmp) / obase)) |
1400 | 2946 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2947 tmp = x % obase; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2948 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2949 if (tmp > ibase - 1) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2950 error ("umask: invalid digit"); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2951 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2952 retval += mult * tmp; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2953 mult *= ibase; |
1400 | 2954 } |
2955 | |
2956 return retval; | |
2957 } | |
2958 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2959 DEFUNX ("umask", Fumask, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2960 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
2961 @deftypefn {} {} umask (@var{mask})\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2962 Set the permission mask for file creation.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2963 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2964 The parameter @var{mask} is an integer, interpreted as an octal number.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2965 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2966 If successful, returns the previous value of the mask (as an integer to be\n\ |
4715 | 2967 interpreted as an octal number); otherwise an error message is printed.\n\ |
20198
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
2968 \n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
2969 The permission mask is a UNIX concept used when creating new objects on a\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
2970 file system such as files, directories, or named FIFOs. The object to be\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
2971 created has base permissions in an octal number @var{mode} which are\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
2972 modified according to the octal value of @var{mask}. The final permissions\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
2973 for the new object are @code{@var{mode} - @var{mask}}.\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
2974 @seealso{fopen, mkdir, mkfifo}\n\ |
3301 | 2975 @end deftypefn") |
1400 | 2976 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2977 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2978 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2979 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2980 int mask = args(0).xint_value ("umask: MASK must be an integer"); |
1400 | 2981 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2982 if (mask < 0) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2983 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
|
2984 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2985 int oct_mask = convert (mask, 8, 10); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2986 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2987 int status = convert (octave_umask (oct_mask), 10, 8); |
1400 | 2988 |
2989 if (status >= 0) | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2990 return ovl (status); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2991 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
2992 return ovl (); |
1400 | 2993 } |
2994 | |
5749 | 2995 static octave_value |
6483 | 2996 const_value (const char *, const octave_value_list& args, int val) |
2189 | 2997 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2998 if (args.length () != 0) |
5823 | 2999 print_usage (); |
5749 | 3000 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3001 return octave_value (val); |
5749 | 3002 } |
3003 | |
3004 DEFUNX ("P_tmpdir", FP_tmpdir, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3005 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
3006 @deftypefn {} {} P_tmpdir ()\n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
3007 Return the name of the host system's @strong{default} directory for\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
3008 temporary files.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3009 \n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
3010 Programming Note: The value returned by @code{P_tmpdir} is always the\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
3011 default location. This value may not agree with that returned from\n\ |
20097
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20041
diff
changeset
|
3012 @code{tempdir} if the user has overridden the default with the @env{TMPDIR}\n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
3013 environment variable.\n\ |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
3014 @seealso{tempdir, tempname, mkstemp, tmpfile}\n\ |
5749 | 3015 @end deftypefn") |
3016 { | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3017 if (args.length () != 0) |
5823 | 3018 print_usage (); |
5749 | 3019 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
3020 return ovl (get_P_tmpdir ()); |
5749 | 3021 } |
2341 | 3022 |
5749 | 3023 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be |
3024 // this way for Matlab compatibility. | |
3025 | |
3026 DEFUNX ("SEEK_SET", FSEEK_SET, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3027 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
3028 @deftypefn {} {} SEEK_SET ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
3029 @deftypefnx {} {} SEEK_CUR ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
3030 @deftypefnx {} {} SEEK_END ()\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3031 Return the numerical value to pass to @code{fseek} to perform one of the\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3032 following actions:\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14365
diff
changeset
|
3033 \n\ |
3372 | 3034 @table @code\n\ |
3035 @item SEEK_SET\n\ | |
3036 Position file relative to the beginning.\n\ | |
3037 \n\ | |
3038 @item SEEK_CUR\n\ | |
3039 Position file relative to the current position.\n\ | |
3040 \n\ | |
3041 @item SEEK_END\n\ | |
5749 | 3042 Position file relative to the end.\n\ |
3372 | 3043 @end table\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3044 @seealso{fseek}\n\ |
5749 | 3045 @end deftypefn") |
3046 { | |
3047 return const_value ("SEEK_SET", args, -1); | |
3048 } | |
2189 | 3049 |
5749 | 3050 DEFUNX ("SEEK_CUR", FSEEK_CUR, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3051 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
3052 @deftypefn {} {} SEEK_CUR ()\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3053 Return the numerical value to pass to @code{fseek} to\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3054 position the file pointer relative to the current position.\n\ |
18040
62f94ef938b4
don't use period after end of @seealso{...}
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3055 @seealso{SEEK_SET, SEEK_END}\n\ |
5749 | 3056 @end deftypefn") |
3057 { | |
3058 return const_value ("SEEK_CUR", args, 0); | |
3059 } | |
2189 | 3060 |
5749 | 3061 DEFUNX ("SEEK_END", FSEEK_END, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3062 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
3063 @deftypefn {} {} SEEK_END ()\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3064 Return the numerical value to pass to @code{fseek} to\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3065 position the file pointer relative to the end of the file.\n\ |
18040
62f94ef938b4
don't use period after end of @seealso{...}
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3066 @seealso{SEEK_SET, SEEK_CUR}\n\ |
5749 | 3067 @end deftypefn") |
3068 { | |
3069 return const_value ("SEEK_END", args, 1); | |
3070 } | |
3071 | |
3072 static octave_value | |
6483 | 3073 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
|
3074 const octave_value& val) |
5749 | 3075 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3076 if (args.length () != 0) |
5823 | 3077 print_usage (); |
5749 | 3078 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3079 return octave_value (val); |
5749 | 3080 } |
3081 | |
3082 DEFUNX ("stdin", Fstdin, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3083 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
3084 @deftypefn {} {} stdin ()\n\ |
5749 | 3085 Return the numeric value corresponding to the standard input stream.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3086 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3087 When Octave is used interactively, stdin is filtered through the command\n\ |
5749 | 3088 line editing functions.\n\ |
5333 | 3089 @seealso{stdout, stderr}\n\ |
5749 | 3090 @end deftypefn") |
3091 { | |
3092 return const_value ("stdin", args, stdin_file); | |
3093 } | |
2189 | 3094 |
5749 | 3095 DEFUNX ("stdout", Fstdout, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3096 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
3097 @deftypefn {} {} stdout ()\n\ |
5749 | 3098 Return the numeric value corresponding to the standard output stream.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3099 \n\ |
5749 | 3100 Data written to the standard output is normally filtered through the pager.\n\ |
5333 | 3101 @seealso{stdin, stderr}\n\ |
5749 | 3102 @end deftypefn") |
3103 { | |
3104 return const_value ("stdout", args, stdout_file); | |
3105 } | |
2189 | 3106 |
5749 | 3107 DEFUNX ("stderr", Fstderr, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3108 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20846
diff
changeset
|
3109 @deftypefn {} {} stderr ()\n\ |
5749 | 3110 Return the numeric value corresponding to the standard error stream.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3111 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3112 Even if paging is turned on, the standard error is not sent to the pager.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3113 It is useful for error messages and prompts.\n\ |
5333 | 3114 @seealso{stdin, stdout}\n\ |
5749 | 3115 @end deftypefn") |
3116 { | |
3117 return const_value ("stderr", args, stderr_file); | |
2189 | 3118 } |