Mercurial > octave
annotate libinterp/corefcn/file-io.cc @ 21919:473414a91539
* file-io.cc (cleanup_tmp_files): Use octave_unlink_wrapper.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 16 Jun 2016 01:01:53 -0400 |
parents | c66c156e1d1d |
children | aab79a1885cc |
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 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21634
diff
changeset
|
37 #if defined (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 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21634
diff
changeset
|
50 #if defined (HAVE_ZLIB_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21127
diff
changeset
|
51 # include <zlib.h> |
5325 | 52 #endif |
53 | |
5102 | 54 #include "error.h" |
2926 | 55 #include "file-ops.h" |
6159 | 56 #include "file-stat.h" |
5102 | 57 #include "lo-ieee.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
58 #include "mkostemp-wrapper.h" |
6159 | 59 #include "oct-env.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
60 #include "oct-locbuf.h" |
21919
473414a91539
* file-io.cc (cleanup_tmp_files): Use octave_unlink_wrapper.
John W. Eaton <jwe@octave.org>
parents:
21911
diff
changeset
|
61 #include "unistd-wrappers.h" |
2926 | 62 |
1352 | 63 #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
|
64 #include "errwarn.h" |
6108 | 65 #include "file-io.h" |
6159 | 66 #include "load-path.h" |
2095 | 67 #include "oct-fstrm.h" |
68 #include "oct-iostrm.h" | |
1377 | 69 #include "oct-map.h" |
2095 | 70 #include "oct-prcstrm.h" |
71 #include "oct-stream.h" | |
72 #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
|
73 #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
|
74 #include "ovl.h" |
1 | 75 #include "pager.h" |
444 | 76 #include "sysdep.h" |
1352 | 77 #include "utils.h" |
2370 | 78 #include "variables.h" |
1583 | 79 |
2902 | 80 static octave_value stdin_file; |
81 static octave_value stdout_file; | |
82 static octave_value stderr_file; | |
83 | |
4468 | 84 static octave_stream stdin_stream; |
85 static octave_stream stdout_stream; | |
86 static octave_stream stderr_stream; | |
87 | |
1 | 88 void |
164 | 89 initialize_file_io (void) |
1 | 90 { |
4468 | 91 stdin_stream = octave_istream::create (&std::cin, "stdin"); |
2116 | 92 |
3531 | 93 // This uses octave_stdout (see pager.h), not std::cout so that Octave's |
2116 | 94 // standard output stream will pass through the pager. |
95 | |
4468 | 96 stdout_stream = octave_ostream::create (&octave_stdout, "stdout"); |
2116 | 97 |
4468 | 98 stderr_stream = octave_ostream::create (&std::cerr, "stderr"); |
1 | 99 |
2902 | 100 stdin_file = octave_stream_list::insert (stdin_stream); |
101 stdout_file = octave_stream_list::insert (stdout_stream); | |
102 stderr_file = octave_stream_list::insert (stderr_stream); | |
1 | 103 } |
104 | |
2095 | 105 void |
106 close_files (void) | |
1 | 107 { |
2095 | 108 octave_stream_list::clear (); |
109 } | |
636 | 110 |
5102 | 111 // List of files to delete when we exit or crash. |
112 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 // FIXME: this should really be static, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
114 // but that causes problems on some systems. |
5102 | 115 std::stack <std::string> tmp_files; |
116 | |
117 void | |
118 mark_for_deletion (const std::string& file) | |
119 { | |
120 tmp_files.push (file); | |
121 } | |
122 | |
123 void | |
124 cleanup_tmp_files (void) | |
125 { | |
126 while (! tmp_files.empty ()) | |
127 { | |
128 std::string filename = tmp_files.top (); | |
129 tmp_files.pop (); | |
21919
473414a91539
* file-io.cc (cleanup_tmp_files): Use octave_unlink_wrapper.
John W. Eaton <jwe@octave.org>
parents:
21911
diff
changeset
|
130 octave_unlink_wrapper (filename.c_str ()); |
5102 | 131 } |
132 } | |
133 | |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
134 static void |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
135 normalize_fopen_mode (std::string& mode, bool& use_zlib) |
1 | 136 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
137 use_zlib = false; |
896 | 138 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
139 if (! mode.empty ()) |
368 | 140 { |
2095 | 141 // Could probably be faster, but does it really matter? |
1766 | 142 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
143 // 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
|
144 // 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
|
145 // flushing" but we don't know precisely what action that implies. |
7078 | 146 |
147 size_t pos = mode.find ('W'); | |
148 | |
8021 | 149 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
150 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
151 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
|
152 "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
|
153 mode[pos] = 'w'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
154 } |
7078 | 155 |
156 pos = mode.find ('R'); | |
157 | |
8021 | 158 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
159 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
160 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
|
161 "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
|
162 mode[pos] = 'r'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
163 } |
7078 | 164 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
165 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
|
166 |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
167 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
|
168 { |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
169 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
|
170 "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
|
171 mode[pos] = 'a'; |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
172 } |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
173 |
7078 | 174 pos = mode.find ('z'); |
5325 | 175 |
8021 | 176 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
177 { |
5325 | 178 #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
|
179 use_zlib = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
180 mode.erase (pos, 1); |
5325 | 181 #else |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
182 err_disabled_feature ("", "gzipped files (zlib)"); |
5325 | 183 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
184 } |
5325 | 185 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
186 // 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
|
187 // '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
|
188 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
189 size_t bpos = mode.find ('b'); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
190 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
|
191 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
192 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
|
193 mode += 'b'; |
1 | 194 } |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
195 } |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
196 |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
197 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
|
198 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
|
199 { |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
200 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
|
201 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
202 if (mode == "rt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
203 retval = std::ios::in; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
204 else if (mode == "wt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
205 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
|
206 else if (mode == "at") |
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::app; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 else if (mode == "rb" || mode == "r") |
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::binary; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
216 else if (mode == "wb" || mode == "w") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
217 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
|
218 else if (mode == "ab" || mode == "a") |
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::app | 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 == "r+b" || mode == "rb+" || mode == "r+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
225 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
|
226 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
|
227 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
228 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
229 error ("invalid mode specified"); |
1 | 230 |
231 return retval; | |
232 } | |
233 | |
1957 | 234 DEFUN (fclose, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
235 "-*- 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
|
236 @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
|
237 @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
|
238 @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
|
239 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
|
240 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
241 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
|
242 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
|
243 @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
|
244 with gnuplot.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
245 @seealso{fopen, fflush, freport}\n\ |
5642 | 246 @end deftypefn") |
529 | 247 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
248 if (args.length () != 1) |
5823 | 249 print_usage (); |
1 | 250 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
251 return ovl (octave_stream_list::remove (args(0), "fclose")); |
1 | 252 } |
253 | |
5144 | 254 DEFUN (fclear, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
255 "-*- 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
|
256 @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
|
257 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
|
258 @var{fid}.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
259 @seealso{ferror, fopen}\n\ |
5144 | 260 @end deftypefn") |
261 { | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
262 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
263 print_usage (); |
5144 | 264 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
265 int fid = octave_stream_list::get_file_number (args(0)); |
5144 | 266 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
267 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
|
268 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
269 os.clearerr (); |
5144 | 270 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
271 return ovl (); |
5144 | 272 } |
273 | |
1957 | 274 DEFUN (fflush, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
275 "-*- 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
|
276 @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
|
277 Flush output to file descriptor @var{fid}.\n\ |
5095 | 278 \n\ |
279 @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
|
280 (@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
|
281 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
282 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
|
283 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
|
284 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
|
285 @code{input}.\n\ |
5642 | 286 @seealso{fopen, fclose}\n\ |
287 @end deftypefn") | |
1181 | 288 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
289 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
290 print_usage (); |
1181 | 291 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
292 octave_value retval = -1; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
293 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
294 // 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
|
295 int fid = octave_stream_list::get_file_number (args(0)); |
2095 | 296 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
297 if (fid == 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
298 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
299 flush_octave_stdout (); |
2609 | 300 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
301 retval = 0; |
2095 | 302 } |
303 else | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
304 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
305 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
|
306 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
307 retval = os.flush (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
308 } |
1181 | 309 |
310 return retval; | |
311 } | |
312 | |
2095 | 313 DEFUN (fgetl, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
314 "-*- 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
|
315 @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
|
316 @deftypefnx {} {@var{str} =} fgetl (@var{fid}, @var{len})\n\ |
3372 | 317 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
|
318 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
|
319 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
320 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
|
321 as a string.\n\ |
1339 | 322 \n\ |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
323 If @var{len} is omitted, @code{fgetl} reads until the next newline\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
324 character.\n\ |
3372 | 325 \n\ |
326 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
|
327 \n\ |
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
328 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
|
329 @seealso{fgets, fscanf, fread, fopen}\n\ |
5642 | 330 @end deftypefn") |
1339 | 331 { |
4468 | 332 static std::string who = "fgetl"; |
333 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
334 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
335 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
336 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
337 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
338 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
339 octave_stream os = octave_stream_list::lookup (args(0), who); |
1339 | 340 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
341 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); |
2095 | 342 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
343 bool err = false; |
2095 | 344 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
345 std::string tmp = os.getl (len_arg, err, who); |
2095 | 346 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
347 if (! err) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
348 return ovl (tmp, tmp.length ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
349 else |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
350 return ovl (-1, 0); |
1339 | 351 } |
352 | |
2095 | 353 DEFUN (fgets, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
354 "-*- 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
|
355 @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
|
356 @deftypefnx {} {@var{str} =} fgets (@var{fid}, @var{len})\n\ |
3372 | 357 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
|
358 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
|
359 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
360 The 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
|
361 as a string.\n\ |
529 | 362 \n\ |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
363 If @var{len} is omitted, @code{fgets} reads until the next newline\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
364 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\ |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
401 @code{fskipl} discards characters until an end-of-line is encountered\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
402 exactly @var{count}-times, or until the end-of-file marker is found.\n\ |
14436
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 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
448 octave::mach_info::float_format flt_fmt = |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
449 octave::mach_info::string_to_float_format (arch); |
1 | 450 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
451 std::string fname = octave::sys::file_ops::tilde_expand (name); |
6159 | 452 |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
453 octave::sys::file_stat fs (fname); |
7730
b68e44c90afe
file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents:
7708
diff
changeset
|
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\ |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
577 @qcode{\"b\"} to open in binary mode. On Windows and Macintosh systems,\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
578 text mode reading and writing automatically converts linefeeds to the\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
579 appropriate line end character for the system (carriage-return linefeed on\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
580 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\ |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
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 | |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
825 DEFUN (printf, args, nargout, |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
826 "-*- texinfo -*-\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
827 @deftypefn {} {} printf (@var{template}, @dots{})\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
828 Print optional arguments under the control of the template string\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
829 @var{template} to the stream @code{stdout} and return the number of\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
830 characters printed.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
831 @ifclear OCTAVE_MANUAL\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
832 \n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
833 See the Formatted Output section of the GNU Octave manual for a\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
834 complete description of the syntax of the template string.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
835 @end ifclear\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
836 \n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
837 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
838 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
839 expanded even when the template string is defined with single quotes.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
840 @seealso{fprintf, sprintf, scanf}\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
841 @end deftypefn") |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
842 { |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
843 static std::string who = "printf"; |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
844 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
845 int nargin = args.length (); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
846 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
847 if (nargin == 0) |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
848 print_usage (); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
849 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
850 int result; |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
851 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
852 if (! args(0).is_string ()) |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
853 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
854 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
855 octave_value_list tmp_args; |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
856 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
857 if (nargin > 1) |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
858 { |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
859 tmp_args.resize (nargin-1, octave_value ()); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
860 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
861 for (int i = 1; i < nargin; i++) |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
862 tmp_args(i-1) = args(i); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
863 } |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
864 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
865 result = stdout_stream.printf (args(0), tmp_args, who); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
866 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
867 if (nargout > 0) |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
868 return ovl (result); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
869 else |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
870 return ovl (); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
871 } |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
872 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
873 DEFUN (fputs, args, , |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
874 "-*- texinfo -*-\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
875 @deftypefn {} {} fputs (@var{fid}, @var{string})\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
876 @deftypefnx {} {@var{status} =} fputs (@var{fid}, @var{string})\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
877 Write the string @var{string} to the file with file descriptor @var{fid}.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
878 \n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
879 The string is written to the file with no additional formatting. Use\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
880 @code{fdisp} instead to automatically append a newline character appropriate\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
881 for the local machine.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
882 \n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
883 Return a non-negative number on success or EOF on error.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
884 @seealso{fdisp, fprintf, fwrite, fopen}\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
885 @end deftypefn") |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
886 { |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
887 static std::string who = "fputs"; |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
888 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
889 if (args.length () != 2) |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
890 print_usage (); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
891 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
892 octave_stream os = octave_stream_list::lookup (args(0), who); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
893 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
894 return ovl (os.puts (args(1), who)); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
895 } |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
896 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
897 DEFUN (puts, args, , |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
898 "-*- texinfo -*-\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
899 @deftypefn {} {} puts (@var{string})\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
900 @deftypefnx {} {@var{status} =} puts (@var{string})\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
901 Write a string to the standard output with no formatting.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
902 \n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
903 The string is written verbatim to the standard output. Use @code{disp} to\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
904 automatically append a newline character appropriate for the local machine.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
905 \n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
906 Return a non-negative number on success and EOF on error.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
907 @seealso{fputs, disp}\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
908 @end deftypefn") |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
909 { |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
910 static std::string who = "puts"; |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
911 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
912 if (args.length () != 1) |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
913 print_usage (); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
914 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
915 return ovl (stdout_stream.puts (args(0), who)); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
916 } |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
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\ |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
931 @seealso{printf, fprintf, sscanf}\n\ |
5642 | 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\ | |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
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\ |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1091 @seealso{fscanf, scanf, sprintf}\n\ |
5642 | 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 | |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1139 DEFUN (scanf, args, nargout, |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1140 "-*- texinfo -*-\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1141 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} scanf (@var{template}, @var{size})\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1142 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}]] =} scanf (@var{template}, \"C\")\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1143 This is equivalent to calling @code{fscanf} with @var{fid} = @code{stdin}.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1144 \n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1145 It is currently not useful to call @code{scanf} in interactive programs.\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1146 @seealso{fscanf, sscanf, printf}\n\ |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1147 @end deftypefn") |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1148 { |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1149 int nargin = args.length (); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1150 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1151 octave_value_list tmp_args (nargin+1, octave_value ()); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1152 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1153 tmp_args (0) = 0.0; |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1154 for (int i = 0; i < nargin; i++) |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1155 tmp_args(i+1) = args(i); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1156 |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1157 return Ffscanf (tmp_args, nargout); |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
1158 } |
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
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\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1239 parsed according to @var{format}. The function is an extension of\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1240 @code{strread} and @code{textread}. Differences include: the ability to\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1241 read from either a file or a string, additional options, and additional\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1242 format specifiers.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1243 \n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1244 The input is interpreted as a sequence of words, delimiters (such as\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1245 whitespace), and literals. The characters that form delimiters and\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1246 whitespace are determined by the options. The format consists of format\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1247 specifiers interspersed between literals. In the format, whitespace forms\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1248 a delimiter between consecutive literals, but is otherwise ignored.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1249 \n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1250 The output @var{C} is a cell array where the number of columns is determined\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1251 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
|
1252 \n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1253 The first word of the input is matched to the first specifier of the format\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1254 and placed in the first column of the output; the second is matched to the\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1255 second specifier and placed in the second column and so forth. If there\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1256 are more words than specifiers then the process is repeated until all words\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1257 have been processed or the limit imposed by @var{repeat} has been met (see\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1258 below).\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1259 \n\ |
7a19c5678f91
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 The string @var{format} describes how the words in @var{str} should be\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1261 parsed. As in @var{fscanf}, any (non-whitespace) text in the format that is\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1262 not one of these specifiers is considered a literal. If there is a literal\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1263 between two format specifiers then that same literal must appear in the\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1264 input stream between the matching words.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1265 \n\ |
7a19c5678f91
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 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
|
1267 \n\ |
7a19c5678f91
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 @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
|
1269 @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
|
1270 @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
|
1271 @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
|
1272 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
|
1273 \n\ |
7a19c5678f91
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 @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
|
1275 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
|
1276 \n\ |
7a19c5678f91
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 @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
|
1278 @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
|
1279 @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
|
1280 @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
|
1281 @itemx %d64\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1282 The word is parsed as a number and converted to int8, int16, int32, or\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1283 int64. If no size is specified then int32 is used.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1284 \n\ |
7a19c5678f91
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 @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
|
1286 @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
|
1287 @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
|
1288 @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
|
1289 @itemx %u64\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1290 The word is parsed as a number and converted to uint8, uint16, uint32, or\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1291 uint64. If no size is specified then uint32 is used.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1292 \n\ |
7a19c5678f91
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 @item %s\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1294 The word is parsed as a string ending at the last character before\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1295 whitespace, an end-of-line, or a delimiter specified in the options.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
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 %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
|
1298 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
|
1299 If the first character of the string is a double quote (\") then the string\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1300 includes everything until a matching double quote---including whitespace,\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1301 delimiters, and end-of-line characters. If a pair of consecutive double\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1302 quotes appears in the input, it is replaced in the output by a single\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1303 double quote. For examples, the input \"He said \"\"Hello\"\"\" would\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1304 return the value 'He said \"Hello\"'.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1305 \n\ |
7a19c5678f91
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 @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
|
1307 The next character of the input is read.\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1308 This includes delimiters, whitespace, and end-of-line characters.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1309 \n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1310 @item %[@dots{}]\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1311 @itemx %[^@dots{}]\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1312 In the first form, the word consists of the longest run consisting of only\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1313 characters between the brackets. Ranges of characters can be specified by\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1314 a hyphen; for example, %[0-9a-zA-Z] matches all alphanumeric characters (if\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1315 the underlying character set is ASCII). Since @sc{matlab} treats hyphens\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1316 literally, this expansion only applies to alphanumeric characters. To\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1317 include '-' in the set, it should appear first or last in the brackets; to\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1318 include ']', it should be the first character. If the first character is\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1319 '^' then the word consists of characters @strong{not} listed.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1320 \n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1321 @item %N@dots{}\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1322 For %s, %c %d, %f, %n, %u, an optional width can be specified as %Ns, etc.\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1323 where N is an integer > 1. For %c, this causes exactly N characters to be\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1324 read instead of a single character. For the other specifiers, it is an\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1325 upper bound on the number of characters read; normal delimiters can cause\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1326 fewer characters to be read. For complex numbers, this limit applies to\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1327 the real and imaginary components individually. For %f and %n, format\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1328 specifiers like %N.Mf are allowed, where M is an upper bound on number of\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1329 characters after the decimal point to be considered; subsequent digits are\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1330 skipped. For example, the specifier %8.2f would read 12.345e6 as 1.234e7.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1331 \n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1332 @item %*@dots{}\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1333 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
|
1334 \n\ |
7a19c5678f91
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 @item literals\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1336 In addition the format may contain literal character strings; these will be\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1337 skipped during reading. If the input string does not match this literal,\n\ |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1338 the processing terminates.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1339 @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
|
1340 \n\ |
7a19c5678f91
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 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
|
1342 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
|
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 By default, if there is only one input argument, @var{format} is @t{\"%f\"}.\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1345 This means that numbers are read from the input into a single column vector.\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1346 If @var{format} is explicitly empty (@qcode{\"\"}) then textscan will\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1347 return data in a number of columns matching the number of fields on the\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1348 first data line of the input. Either of these is suitable only when the\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1349 input is exclusively numeric.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1350 \n\ |
7a19c5678f91
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 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
|
1352 \n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1353 @smallexample\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1354 @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
|
1355 @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
|
1356 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
|
1357 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
|
1358 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
|
1359 @end group\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1360 @end smallexample\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1361 \n\ |
7a19c5678f91
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 @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
|
1363 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
|
1364 \n\ |
7a19c5678f91
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 @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
|
1366 @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
|
1367 @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
|
1368 \n\ |
7a19c5678f91
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 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
|
1370 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
|
1371 \n\ |
7a19c5678f91
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 @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
|
1373 @item -1\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1374 Read all of the string or file until the end (default).\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1375 \n\ |
7a19c5678f91
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 @item N\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1377 Read until the first of two conditions occurs: 1) the format has been\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1378 processed N times, or 2) N lines of the input have been processed. Zero\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1379 (0) is an acceptable value for @var{repeat}. Currently, end-of-line\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1380 characters inside %q, %c, and %[@dots{}]$ conversions do not contribute to\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1381 the line count. This is incompatible with @sc{matlab} and may change in\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1382 future.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1383 @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
|
1384 \n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1385 The behavior of @code{textscan} can be changed via property/value pairs.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1386 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
|
1387 \n\ |
7a19c5678f91
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 @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
|
1389 @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
|
1390 This specifies the number of bytes to use for the internal buffer.\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1391 A modest speed improvement may be obtained by setting this to a large value\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1392 when reading a large file, especially if the input contains long strings.\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1393 The default is 4096, or a value dependent on @var{n} if that is specified.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1394 \n\ |
7a19c5678f91
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 @item @qcode{\"CollectOutput\"}\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1396 A value of 1 or true instructs @code{textscan} to concatenate consecutive\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1397 columns of the same class in the output cell array. A value of 0 or false\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1398 (default) leaves output in distinct columns.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1399 \n\ |
7a19c5678f91
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 @item @qcode{\"CommentStyle\"}\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1401 Specify parts of the input which are considered comments and will be\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1402 skipped. @var{value} is the comment style and can be either (1) A string\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1403 or 1x1 cell string, to skip everything to the right of it; (2) A cell array\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1404 of two strings, to skip everything between the first and second strings. \n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1405 Comments are only parsed where whitespace is accepted and do not act as\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1406 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
|
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{\"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
|
1409 If @var{value} is a string, any character in @var{value} will be used to\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1410 split the input into words. If @var{value} is a cell array of strings,\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1411 any string in the array will be used to split the input into words.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1412 (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
|
1413 \n\ |
7a19c5678f91
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 @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
|
1415 Value to return for empty numeric values in non-whitespace delimited data.\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1416 The default is NaN@. When the data type does not support NaN (int32 for\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1417 example), then the default is zero.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1418 \n\ |
7a19c5678f91
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 @item @qcode{\"EndOfLine\"}\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1420 @var{value} can be either an emtpy or one character specifying the\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1421 end-of-line character, or the pair\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1422 @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
|
1423 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
|
1424 @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
|
1425 @qcode{\"@xbackslashchar{}r@xbackslashchar{}n\"} is counted as a (single)\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1426 newline. If no value is given,\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1427 @qcode{\"@xbackslashchar{}r@xbackslashchar{}n\"} is used.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1428 @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
|
1429 @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
|
1430 \n\ |
7a19c5678f91
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 @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
|
1432 @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
|
1433 @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
|
1434 @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
|
1435 @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
|
1436 \n\ |
7a19c5678f91
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 @item @qcode{\"HeaderLines\"}\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1438 The first @var{value} number of lines of @var{fid} are skipped. Note that\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1439 this does not refer to the first non-comment lines, but the first lines of\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1440 any type.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1441 \n\ |
7a19c5678f91
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 @item @qcode{\"MultipleDelimsAsOne\"}\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1443 If @var{value} is nonzero, treat a series of consecutive delimiters,\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1444 without whitespace in between, as a single delimiter. Consecutive\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1445 delimiter series need not be vertically aligned. Without this option, a\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1446 single delimiter before the end of the line does not cause the line to be\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1447 considered to end with an empty value, but a single delimiter at the start\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1448 of a line causes the line to be considered to start with an empty value.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1449 \n\ |
7a19c5678f91
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 @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
|
1451 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
|
1452 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
|
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{\"ReturnOnError\"}\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1455 If set to numerical 1 or true, return normally as soon as an error is\n\ |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1456 encountered, such as trying to read a string using @qcode{%f}.\n\ |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1457 If set to 0 or false, return an error and no data.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
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{\"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
|
1460 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
|
1461 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
|
1462 @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
|
1463 @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
|
1464 @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
|
1465 @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
|
1466 (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
|
1467 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
|
1468 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
|
1469 \n\ |
7a19c5678f91
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 @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
|
1471 \n\ |
7a19c5678f91
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 When the number of words in @var{str} or @var{fid} doesn't match an exact\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1473 multiple of the number of format conversion specifiers, @code{textscan}'s\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1474 behavior depends on whether the last character of the string or file is an\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1475 end-of-line as specified by the @code{EndOfLine} option:\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1476 \n\ |
7a19c5678f91
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 @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
|
1478 @item last character = end-of-line\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1479 Data columns are padded with empty fields, NaN or 0 (for integer fields) so\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1480 that all columns have equal length\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1481 \n\ |
7a19c5678f91
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 @item last character is not end-of-line\n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1483 Data columns are not padded; @code{textscan} returns columns of unequal\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1484 length\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1485 @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
|
1486 \n\ |
7a19c5678f91
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 \n\ |
21548
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1488 The second output @var{position} provides the location, in characters\n\ |
f044dc45b8b1
doc: grammarcheck and spellcheck new textscan docstring.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1489 from the beginning of the file or string, where processing stopped.\n\ |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
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 @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
|
1492 @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
|
1493 { |
7a19c5678f91
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 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
|
1495 |
21504 | 1496 return textscan_internal (who, args); |
1497 } | |
1498 | |
1499 DEFUN (__textscan__, args, , | |
1500 "-*- texinfo -*-\n\ | |
1501 @deftypefn {} {@var{C} =} __textscan__ (@var{who}, @dots{})\n\ | |
1502 Like @code{textscan} but accept additional argument @var{who} to use\n\ | |
1503 as the name of the function when reporting errors.\n\ | |
1504 @end deftypefn") | |
1505 { | |
1506 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
|
1507 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
|
1508 |
21504 | 1509 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
|
1510 } |
7a19c5678f91
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 |
7a19c5678f91
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 /* |
7a19c5678f91
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 %!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
|
1514 %! 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
|
1515 %! 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
|
1516 %! c = textscan (str, fmtstr, 2, "delimiter", ",", "emptyvalue", -Inf); |
21625 | 1517 %! assert (c{1}, [1;5]); |
1518 %! assert (c{3}, [3; -Inf]); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1519 %! 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
|
1520 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1521 %!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
|
1522 %! 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
|
1523 %! 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
|
1524 %! 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
|
1525 %! 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
|
1526 %! 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
|
1527 %! 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
|
1528 %! 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
|
1529 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1530 %!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
|
1531 %! str = "13, -, NA, str1, -25\r\n// Middle line\r\n36, na, 05, str3, 6"; |
21625 | 1532 %! c = textscan (str, "%d %n %f %s %n", "delimiter", ",", |
1533 %! "treatAsEmpty", {"NA", "na", "-"}, "commentStyle", "//"); | |
1534 %! assert (c{1}, int32 ([13; 36])); | |
1535 %! assert (c{2}, [NaN; NaN]); | |
1536 %! assert (c{3}, [NaN; 5]); | |
1537 %! assert (c{4}, {"str1"; "str3"}); | |
1538 %! assert (c{5}, [-25; 6]); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1539 |
7a19c5678f91
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 %!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
|
1541 %! 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
|
1542 %! 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
|
1543 %! 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
|
1544 %! 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
|
1545 %! fmt = "Km:%d = hhh%1sjjj miles%dhour"; |
21625 | 1546 %! c = textscan (str, fmt, "delimiter", " "); |
1547 %! assert (c{1}', int32 ([10, 15, 2, 25])); | |
1548 %! assert (c{2}', {'B' 'J' 'R' 'Z'}); | |
1549 %! assert (c{3}', int32 ([16, 241, 3, 0])); | |
1550 | |
1551 ## Test with default EndOfLine parameter | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
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 %! 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
|
1554 %! 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
|
1555 |
21625 | 1556 ## Test with EndofLine parameter set to "" (empty) - newline should be in word |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1557 %!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
|
1558 %! c = textscan ("L1\nL2", "%s", "endofline", ""); |
21625 | 1559 %! assert (int8 ([c{:}{:}]), int8 ([76, 49, 10, 76, 50])); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1560 |
7a19c5678f91
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 ### 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
|
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 #%! ## 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
|
1564 #%! 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
|
1565 #%! 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
|
1566 #%! 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
|
1567 |
7a19c5678f91
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 ## 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
|
1569 %!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
|
1570 %! 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
|
1571 %! 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
|
1572 %! 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
|
1573 %! 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
|
1574 %! 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
|
1575 %! 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
|
1576 %! 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
|
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 ## 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
|
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 %! 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
|
1581 %! 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
|
1582 %! 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
|
1583 %! 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
|
1584 %! 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
|
1585 %! 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
|
1586 %! 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
|
1587 %! 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
|
1588 %! 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
|
1589 %! 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
|
1590 %! 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
|
1591 %! 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
|
1592 |
7a19c5678f91
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 ## 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
|
1594 %!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
|
1595 %! 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
|
1596 %! 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
|
1597 %! 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
|
1598 %! 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
|
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 ## 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
|
1601 %!test |
21625 | 1602 %! c = textscan ("a first, \n second, third", "%s %c %11c", "delimiter", " ,"); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1603 %! 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
|
1604 %! 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
|
1605 %! 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
|
1606 |
7a19c5678f91
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 ## 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
|
1608 %!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
|
1609 %! 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
|
1610 %! c = textscan (str, "%4d %4d", "delimiter", ";", "collectOutput", 1); |
21625 | 1611 %! assert (c, {[12, 34; 1234, 5678; 9, 7]}); |
1612 | |
1613 ## Field width and non-standard delimiters (2) | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1614 %!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
|
1615 %! 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
|
1616 %! c = textscan (str, "%4f %f", "delimiter", ";", "collectOutput", 1); |
21625 | 1617 %! assert (c, {[12, 34; 1234, 56789; 7, NaN]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1618 |
7a19c5678f91
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 ## 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
|
1620 %!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
|
1621 %! 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
|
1622 %! c = textscan (str, "%10.2f %f", "delimiter", ",", "collectOutput", 1, |
21625 | 1623 %! "expChars", "e|"); |
1624 %! assert (c, {[1223, 34; 12345.79-9876j, 78; NaN, 10000]}, 1e-6); | |
1625 | |
1626 ## Multi-character delimiter | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1627 %!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
|
1628 %! 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
|
1629 %! 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
|
1630 %! 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
|
1631 %! 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
|
1632 |
21625 | 1633 ## FIXME: Following two tests still fail (4/13/2016)? |
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
|
1634 ### 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
|
1635 #%!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
|
1636 #%! str = "12 R&D & 7"; |
21625 | 1637 #%! c = textscan (str, "%f R&D %f", "delimiter", "&", "collectOutput", 1, |
1638 #%! "EmptyValue", -99); | |
1639 #%! assert (c, {[12, -99; 7, -99]}); | |
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
|
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 ### 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
|
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 & 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
|
1644 #%! 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
|
1645 #%! 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
|
1646 |
21625 | 1647 ## Check number of lines read, not number of passes through format string |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
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 %! 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
|
1650 %! 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
|
1651 %! 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
|
1652 %! 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
|
1653 %! 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
|
1654 %! 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
|
1655 %! 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
|
1656 %! 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
|
1657 %! assert (c, {1, 2}); |
21625 | 1658 %! assert (! E); |
1659 | |
1660 ## Check number of lines read, not number of passes through format string | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1661 %!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
|
1662 %! 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
|
1663 %! 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
|
1664 %! 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
|
1665 %! 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
|
1666 %! 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
|
1667 %! 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
|
1668 %! unlink (f); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1669 %! assert (c, {[1;3], [2;4]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1670 |
21625 | 1671 ## Check number of lines read, with multiple delimiters |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1672 %!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
|
1673 %! 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
|
1674 %! 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
|
1675 %! 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
|
1676 %! 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
|
1677 %! 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
|
1678 %! 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
|
1679 %! unlink (f); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1680 %! assert (c, {[1;3], [2;4]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1681 |
21625 | 1682 ## Check ReturnOnError |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1683 %!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
|
1684 %! 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
|
1685 %! 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
|
1686 %! 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
|
1687 %! 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
|
1688 %! fseek (fid, 0, "bof"); |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1689 %! c = textscan (fid, "%f %f %f", "ReturnOnError", 1); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1690 %! 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
|
1691 %! 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
|
1692 %! unlink (f); |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1693 %! u = textscan (str, "%f %f %f", "ReturnOnError", 1); |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1694 %! assert (c, {[1;4], [2], [3]}); |
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1695 %! assert (u, {[1;4], [2], [3]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1696 |
21625 | 1697 %! ## Check ReturnOnError (2) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1698 %!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
|
1699 %! 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
|
1700 %! 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
|
1701 %! 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
|
1702 %! 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
|
1703 %! 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
|
1704 %! 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
|
1705 %! 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
|
1706 %! 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
|
1707 %! 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
|
1708 %! u = textscan (str, "%f %f %f", "ReturnOnError", 1); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1709 %! assert (c, {[1;4], 2, 3}); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1710 %! assert (u, {[1;4], 2, 3}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1711 |
21625 | 1712 %!error <Read error in field 2 of row 2> |
1713 %! textscan ("1 2 3\n4 s 6", "%f %f %f", "ReturnOnError", 0); | |
1714 | |
1715 ## Check ReturnOnError (3) | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1716 %!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
|
1717 %! 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
|
1718 %! 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
|
1719 %! 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
|
1720 %! fseek (fid, 0, "bof"); |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1721 %! c = textscan (fid, "", "ReturnOnError", 1); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1722 %! 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
|
1723 %! 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
|
1724 %! unlink (f); |
21622
fed1111e1899
textscan: eliminate ReturnOnError="continue" mode (bug #47538)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21621
diff
changeset
|
1725 %! assert (c, {1}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1726 |
21625 | 1727 ## Check ReturnOnError with empty fields |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1728 %!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
|
1729 %! c = textscan ("1,,3\n4,5,6", "", "Delimiter", ",", "ReturnOnError", 1); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1730 %! assert (c, {[1;4], [NaN;5], [3;6]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1731 |
21625 | 1732 ## Check ReturnOnError with empty fields (2) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1733 %!test |
21625 | 1734 %! c = textscan ("1,,3\n4,5,6", "%f %f %f", "Delimiter", ",", |
1735 %! "ReturnOnError", 1); | |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1736 %! assert (c, {[1;4], [NaN;5], [3;6]}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1737 |
21625 | 1738 ## Check ReturnOnError in first column |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
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 %! c = textscan ("1 2 3\ns 5 6", "", "ReturnOnError", 1); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
1741 %! assert (c, {1, 2, 3}); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1742 |
21625 | 1743 ## FIXME: This test fails (4/14/16) |
1744 ### Test incomplete first data line | |
1745 #%!test | |
1746 #%! R = textscan (['Empty1' char(10)], 'Empty%d %f'); | |
1747 #%! assert (R{1}, int32 (1)); | |
1748 #%! assert (isempty (R{2}), true); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1749 |
7a19c5678f91
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 ## 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
|
1751 %!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
|
1752 %! 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
|
1753 %! 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
|
1754 %! 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
|
1755 |
7a19c5678f91
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 ## 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
|
1757 %!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
|
1758 %! 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
|
1759 %! 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
|
1760 %! 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
|
1761 %! 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
|
1762 %! 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
|
1763 %! 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
|
1764 %! 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
|
1765 %! 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
|
1766 %! 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
|
1767 %! 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
|
1768 %! 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
|
1769 %! assert (strcmp (lh, rh)); |
21625 | 1770 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1771 |
7a19c5678f91
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 ## 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
|
1773 %!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
|
1774 %! 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
|
1775 %! 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
|
1776 %! 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
|
1777 %! 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
|
1778 %! 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
|
1779 %! 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
|
1780 %! 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
|
1781 %! 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
|
1782 %! 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
|
1783 %! 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
|
1784 %! 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
|
1785 %! assert (strcmp (lh, rh)); |
21625 | 1786 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1787 |
7a19c5678f91
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 ## 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
|
1789 %!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
|
1790 %! 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
|
1791 %! 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
|
1792 %! 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
|
1793 %! 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
|
1794 %! 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
|
1795 %! 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
|
1796 %! 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
|
1797 %! 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
|
1798 %! 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
|
1799 %! 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
|
1800 %! 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
|
1801 %! 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
|
1802 %! assert (strcmp (lh, rh)); |
21625 | 1803 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1804 |
7a19c5678f91
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 ## 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
|
1806 %!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
|
1807 %! 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
|
1808 %! 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
|
1809 %! 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
|
1810 %! 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
|
1811 %! 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
|
1812 %! 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
|
1813 %! 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
|
1814 %! 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
|
1815 %! 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
|
1816 %! 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
|
1817 %! assert (strcmp (lh, rh)); |
21625 | 1818 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1819 |
7a19c5678f91
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 ## 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
|
1821 %!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
|
1822 %! 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
|
1823 %! 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
|
1824 %! 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
|
1825 %! 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
|
1826 %! 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
|
1827 %! 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
|
1828 %! 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
|
1829 %! 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
|
1830 %! 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
|
1831 %! 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
|
1832 %! 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
|
1833 %! assert (strcmp (lh, rh)); |
21625 | 1834 %! endfor |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1835 |
7a19c5678f91
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 ## 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
|
1837 %!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
|
1838 %! 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
|
1839 %! 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
|
1840 %! 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
|
1841 %! fseek (fid, 0, "bof"); |
21625 | 1842 %! C = textscan (fid, ""); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1843 %! 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
|
1844 %! 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
|
1845 %! unlink (f); |
21625 | 1846 %! assert (C{1}, [1 ; 5], 1e-6); |
1847 %! assert (C{2}, [2 ; 6], 1e-6); | |
1848 %! assert (C{3}, [3 ; 7], 1e-6); | |
1849 %! assert (C{4}, [4 ; 8], 1e-6); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1850 %! 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
|
1851 |
21621
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1852 ## Test leaving the file at the correct position on exit |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1853 %!test |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1854 %! f = tempname (); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1855 %! fid = fopen (f, "w+"); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1856 %! fprintf (fid, "1,2\n3,4\n"); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1857 %! fseek (fid, 0, "bof"); |
21625 | 1858 %! C = textscan (fid, "%s %f", 2, "Delimiter", ","); |
21621
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1859 %! E = ftell (fid); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1860 %! fclose (fid); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1861 %! unlink (f); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1862 %! assert (E, 8); |
fe0a6de805e4
textscan: Leave file read position correct at exit (bug #47671)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21581
diff
changeset
|
1863 |
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
|
1864 ## 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
|
1865 %!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
|
1866 %! 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
|
1867 %! 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
|
1868 %! 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
|
1869 %! fseek (fid, 0, "bof"); |
21625 | 1870 %! C = textscan (fid, "", "delimiter", ",", "EmptyValue", 999, |
1871 %! "CollectOutput" , 1); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1872 %! 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
|
1873 %! unlink (f); |
21625 | 1874 %! assert (C{1}, [999, 2, 999, 4; 5, 6, 999, 999], 1e-6); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1875 |
7a19c5678f91
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 ## 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
|
1877 |
7a19c5678f91
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 %!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
|
1879 %! 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
|
1880 %! 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
|
1881 %! 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
|
1882 %! try |
21625 | 1883 %! C = textscan (fid, "", "headerlines"); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1884 %! 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
|
1885 %! 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
|
1886 %! 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
|
1887 %! 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
|
1888 %! 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
|
1889 |
7a19c5678f91
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 %!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
|
1891 %! 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
|
1892 %! 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
|
1893 %! 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
|
1894 %! try |
21625 | 1895 %! C = textscan (fid, "", "headerlines", "hh"); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1896 %! 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
|
1897 %! 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
|
1898 %! 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
|
1899 %! 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
|
1900 |
21625 | 1901 ## Skip headerlines |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1902 %!test |
21625 | 1903 %! C = textscan ("field 1 field2\n 1 2\n3 4", "", "headerlines", 1, |
1904 %! "collectOutput", 1); | |
1905 %! assert (C, {[1 2; 3 4]}); | |
1906 | |
1907 ## Skip headerlines with non-default EOL | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1908 %!test |
21625 | 1909 %! C = textscan ("field 1 field2\r 1 2\r3 4", "", "headerlines", 2, |
1910 %! "collectOutput", 1, "EndOfLine", '\r'); | |
1911 %! assert (C, {[3 4]}); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1912 |
7a19c5678f91
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 %!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
|
1914 %! 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
|
1915 %! 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
|
1916 %! 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
|
1917 %! 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
|
1918 %! 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
|
1919 %! try |
21625 | 1920 %! C = textscan (fid, "%f", "EndOfLine", "\n\r"); |
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
|
1921 %! 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
|
1922 %! 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
|
1923 %! 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
|
1924 %! 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
|
1925 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1926 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1927 %! f = tempname (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1928 %! fid = fopen (f, "w+"); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1929 %! fprintf (fid,"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
|
1930 %! 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
|
1931 %! 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
|
1932 %! try |
21625 | 1933 %! C = textscan (fid, "%f", "EndOfLine", 33); |
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
|
1934 %! 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
|
1935 %! 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
|
1936 %! 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
|
1937 %! 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
|
1938 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1939 ## Bug #41824 |
21625 | 1940 %!assert (textscan ("123", "", "whitespace", " "){:}, 123); |
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
|
1941 |
7a19c5678f91
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 ## Bug #42343-1, just test supplied emptyvalue |
21625 | 1943 %!assert (textscan (",NaN", "", "delimiter", "," ,"emptyValue" ,Inf), |
1944 %! {Inf, NaN}) | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1945 |
7a19c5678f91
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 ## 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
|
1947 %!test |
21625 | 1948 %! c = textscan (",1,,4\nInf, ,NaN\n", "", "delimiter", ",", |
1949 %! "emptyvalue", -10); | |
1950 %! assert (cell2mat (c), [-10, 1, -10, 4; Inf, -10, NaN, -10]); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1951 |
7a19c5678f91
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 ## 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
|
1953 %!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
|
1954 %! assert (textscan ("1i", ""){1}, 0+1i); |
21625 | 1955 %! C = textscan ("3, 2-4i, NaN\n -i, 1, 23.4+2.2i\n 1+1 1+1j", "", |
1956 %! "delimiter", ","); | |
1957 %! assert (cell2mat (C), [3+0i, 2-4i, NaN+0i; 0-i, 1+0i, 23.4+2.2i; 1 1 1+1i]); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1958 |
7a19c5678f91
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 %!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
|
1960 %! ## TreatAsEmpty |
21625 | 1961 %! C = textscan ("1,2,3,NN,5,6\n", "%d%d%d%f", "delimiter", ",", |
1962 %! "TreatAsEmpty", "NN"); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1963 %! 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
|
1964 %! 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
|
1965 |
7a19c5678f91
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 ## 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
|
1967 %!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
|
1968 %! str = "11, 12, 13,, 15\n21,, 23, 24, 25\n,, 33, 34, 35\n"; |
21625 | 1969 %! C = textscan (str, "%f %f %f %f", "delimiter", ",", |
1970 %! "multipledelimsasone", 1, "endofline", "\n"); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
1971 %! 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
|
1972 %! 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
|
1973 %! 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
|
1974 %! 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
|
1975 |
21551
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
1976 ## Single-quoted escape sequences |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
1977 %!test |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
1978 %! str = "11\t12\t13\r21\t22\t23"; |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
1979 %! c = textscan (str, "", "delimiter", '\t', "EndOfLine", '\r'); |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
1980 %! assert (c{1}', [11, 21]); |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
1981 %! assert (c{2}', [12, 22]); |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
1982 %! assert (c{3}', [13, 23]); |
990c6c31a684
Accept escape sequences in single quoted strings for "delimiter" (bug #47539)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21548
diff
changeset
|
1983 |
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
|
1984 ## 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
|
1985 %!test |
21625 | 1986 %! c = textscan ("/home/foo/", "%s", "delimiter", "/", |
1987 %! "MultipleDelimsAsOne", 1); | |
1988 %! assert (c{1}, {"home"; "foo"}); | |
1989 | |
1990 ## FIXME: Test still fails (4/13/2016)? | |
1991 ## Allow cuddling %sliteral, but warn it is ambiguous | |
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
|
1992 #%!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
|
1993 #%! 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
|
1994 #%! 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
|
1995 #%! 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
|
1996 #%! 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
|
1997 ### 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
|
1998 |
7a19c5678f91
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 ## 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
|
2000 %!test |
21625 | 2001 %! c = textscan ("Total: 32.5 % (of cm values)", |
2002 %! "Total: %f %% (of cm values)"); | |
2003 %! assert (c{1}, 32.5, 1e-5); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2004 |
7a19c5678f91
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 ## 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
|
2006 %!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
|
2007 %! 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
|
2008 %! 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
|
2009 %! 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
|
2010 |
21625 | 2011 ## Bit width, fixed width conversion specifiers |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2012 %!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
|
2013 %! 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
|
2014 %! 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
|
2015 %! 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
|
2016 %! 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
|
2017 %! 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
|
2018 %! 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
|
2019 %! 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
|
2020 %! 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
|
2021 %! 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
|
2022 %! 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
|
2023 %! 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
|
2024 %! 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
|
2025 %! 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
|
2026 %! 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
|
2027 %! 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
|
2028 %! 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
|
2029 %! 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
|
2030 |
21625 | 2031 ## Bit width, fixed width conv. specifiers -- check the right amount is left |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2032 %!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
|
2033 %! 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
|
2034 %! 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
|
2035 %! 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
|
2036 %! 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
|
2037 %! 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
|
2038 %! 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
|
2039 %! 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
|
2040 %! 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
|
2041 %! 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
|
2042 %! 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
|
2043 %! 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
|
2044 %! 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
|
2045 |
7a19c5678f91
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 %!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
|
2047 %! 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
|
2048 %! 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
|
2049 %! 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
|
2050 %! 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
|
2051 |
7a19c5678f91
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 %!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
|
2053 %! 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
|
2054 %! 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
|
2055 %! 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
|
2056 %! 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
|
2057 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2058 %!test |
7a19c5678f91
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 %! 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
|
2060 %! 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
|
2061 %! 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
|
2062 |
21625 | 2063 ## field width interrupts exponent. (Matlab incorrectly gives [12, 2e12]) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2064 %!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
|
2065 %! 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
|
2066 %! 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
|
2067 %! 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
|
2068 |
21625 | 2069 ## %[] tests |
2070 ## Plain [..] and *[..] | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2071 %!test |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2072 %! 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
|
2073 %! 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
|
2074 %! 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
|
2075 %! 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
|
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 %!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
|
2078 %! 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
|
2079 |
21625 | 2080 ## [^..] and *[^..] |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2081 %!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
|
2082 %! 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
|
2083 %! 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
|
2084 %! 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
|
2085 %! 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
|
2086 |
21625 | 2087 ## [..] and [^..] containing delimiters |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2088 %!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
|
2089 %! cr = "ab cd efguv wx1Any\na ce gx yz2Trailing\n 3Junk"; |
21625 | 2090 %! C = textscan (cr, "%[ abcdefg] %*[^0123456789] %s", "delimiter", " \n", |
2091 %! "whitespace", ""); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2092 %! 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
|
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 |
21625 | 2095 ## Bug #36464 |
2096 %!assert (textscan ("1 2 3 4 5 6", "%*n%n%*[^\n]"){1}, 2); | |
2097 | |
2098 ## test %[]] and %[^]] | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2099 %!test |
21625 | 2100 %! assert (textscan ("345]", "%*[123456]%[]]"){1}{1}, "]"); |
2101 %! assert (textscan ("345]", "%*[^]]%s"){1}{1}, "]"); | |
2102 | |
2103 ## Test that "-i" checks the next two characters | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2104 %!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
|
2105 %! 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
|
2106 %! 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
|
2107 |
21625 | 2108 ## Again for "+i", this time with custom parser |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2109 %!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
|
2110 %! 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
|
2111 %! 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
|
2112 |
21625 | 2113 ## Check single quoted format interprets control sequences |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2114 %!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
|
2115 %! 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
|
2116 %! 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
|
2117 |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2118 %% 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
|
2119 %!test |
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2120 %! C = textscan ("Empty\n", "Empty%f %f"); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21566
diff
changeset
|
2121 %! assert (C, { NaN, NaN }); |
21532
936ab0fca2f7
Textscan returns emptyVal for rows with literal but no conversion (bug #47458)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21507
diff
changeset
|
2122 |
21625 | 2123 ## Check overflow and underflow of integer types |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2124 %!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
|
2125 %! 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
|
2126 %! 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
|
2127 %! 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
|
2128 %! 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
|
2129 %! 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
|
2130 %! 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
|
2131 %! 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
|
2132 %! 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
|
2133 %! 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
|
2134 %! 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
|
2135 %! 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
|
2136 %! 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
|
2137 |
21625 | 2138 ## Tests from Matlab (does The MathWorks have any copyright over the input?) |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2139 %!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
|
2140 %! 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
|
2141 %! 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
|
2142 %! 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
|
2143 %! 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
|
2144 %! 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
|
2145 %! 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
|
2146 %! 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
|
2147 %! %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
|
2148 %! 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
|
2149 %! 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
|
2150 %! 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
|
2151 %! 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
|
2152 %! 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
|
2153 %! 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
|
2154 %! 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
|
2155 %! 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
|
2156 %! 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
|
2157 %! 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
|
2158 %! 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
|
2159 %! 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
|
2160 %! fseek (fid, 0, "bof"); |
21625 | 2161 %! C = textscan (fid, '%s %*[^\n]'); |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2162 %! 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
|
2163 %! 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
|
2164 %! 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
|
2165 |
7a19c5678f91
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 %!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
|
2167 %! 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
|
2168 %! 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
|
2169 %! 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
|
2170 %! 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
|
2171 %! 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
|
2172 %! 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
|
2173 %! 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
|
2174 %! 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
|
2175 %! 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
|
2176 %! 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
|
2177 |
7a19c5678f91
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 %!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
|
2179 %! 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
|
2180 %! 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
|
2181 %! 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
|
2182 %! 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
|
2183 %! 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
|
2184 %! fseek (fid, 0, "bof"); |
21625 | 2185 %! C = textscan (fid, "%s %n %n %n %n", "Delimiter", ",", |
2186 %! "TreatAsEmpty", {"NA","na"}, "CommentStyle", "//"); | |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2187 %! 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
|
2188 %! 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
|
2189 %! 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
|
2190 %! 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
|
2191 %! 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
|
2192 %! 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
|
2193 %! 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
|
2194 |
21625 | 2195 ## FIXME: Almost passes. Second return value is {"/"}. Tested 4/14/16. |
2196 ### Test start of comment as string | |
2197 #%!test | |
2198 #%! c = textscan ("1 / 2 // 3", "%n %s %u8", "CommentStyle", {"//"}); | |
2199 #%! assert (c(1), {1, "/", 2}); | |
21507
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
2200 |
2cdbae31c022
improve compatibility of textscan for character arrays
John W. Eaton <jwe@octave.org>
parents:
21506
diff
changeset
|
2201 %!assert (textscan (["1 2 3 4"; "5 6 7 8"], "%f"), {[15; 26; 37; 48]}) |
21566
02826fb0f261
textscan: Fix bug in exponent parsing
Mike Miller <mtmiller@octave.org>
parents:
21551
diff
changeset
|
2202 |
21625 | 2203 ## Check for delimiter after exponent |
21566
02826fb0f261
textscan: Fix bug in exponent parsing
Mike Miller <mtmiller@octave.org>
parents:
21551
diff
changeset
|
2204 %!assert (textscan ("1e-3|42", "%f", "delimiter", "|"), {[1e-3; 42]}) |
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
|
2205 */ |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2206 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2207 // 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
|
2208 #if 0 |
21625 | 2209 ## Test unfinished comment |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21457
diff
changeset
|
2210 %!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
|
2211 %! 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
|
2212 %! 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
|
2213 |
7a19c5678f91
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 ## 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
|
2215 %!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
|
2216 %! 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
|
2217 %! 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
|
2218 %! 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
|
2219 %! 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
|
2220 %! 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
|
2221 %! 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
|
2222 %! 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
|
2223 %! 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
|
2224 %! 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
|
2225 %! 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
|
2226 %! 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
|
2227 %! 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
|
2228 #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
|
2229 |
21625 | 2230 /* |
2231 ## Test input validation | |
2232 %!error textscan () | |
2233 %!error textscan (single (40)) | |
2234 %!error textscan ({40}) | |
2235 %!error <must be a string> textscan ("Hello World", 2) | |
2236 %!error <at most one character or> | |
2237 %! textscan ("Hello World", "%s", "EndOfLine", 3); | |
2238 %!error <'%z' is not a valid format specifier> textscan ("1.0", "%z") | |
2239 %!error <no valid format conversion specifiers> textscan ("1.0", "foo") | |
2240 */ | |
2241 | |
2116 | 2242 static octave_value |
2243 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
|
2244 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
|
2245 const octave_value& arch_arg, octave_idx_type& count) |
2116 | 2246 { |
2247 count = -1; | |
2248 | |
20703
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2249 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
|
2250 |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2251 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
|
2252 |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2253 int block_size = 1; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2254 oct_data_conv::data_type input_type; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2255 oct_data_conv::data_type output_type; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2256 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2257 try |
2116 | 2258 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2259 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
|
2260 input_type, output_type); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2261 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
2262 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2263 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2264 error (e, "fread: invalid PRECISION specified"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2265 } |
4944 | 2266 |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
2267 int skip = 0; |
3202 | 2268 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2269 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2270 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2271 skip = skip_arg.int_value (true); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2272 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
2273 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2274 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2275 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
|
2276 } |
2116 | 2277 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2278 std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string"); |
2116 | 2279 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
2280 octave::mach_info::float_format flt_fmt |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
2281 = octave::mach_info::string_to_float_format (arch); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2282 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2283 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
|
2284 flt_fmt, count); |
2116 | 2285 } |
2286 | |
2287 DEFUN (fread, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2288 "-*- 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
|
2289 @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
|
2290 @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
|
2291 @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
|
2292 @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
|
2293 @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
|
2294 @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
|
2295 Read binary data from the file specified by the file descriptor @var{fid}.\n\ |
3372 | 2296 \n\ |
2297 The optional argument @var{size} specifies the amount of data to read\n\ | |
2298 and may be one of\n\ | |
2299 \n\ | |
2300 @table @code\n\ | |
2301 @item Inf\n\ | |
2302 Read as much as possible, returning a column vector.\n\ | |
529 | 2303 \n\ |
3372 | 2304 @item @var{nr}\n\ |
2305 Read up to @var{nr} elements, returning a column vector.\n\ | |
2306 \n\ | |
2307 @item [@var{nr}, Inf]\n\ | |
2308 Read as much as possible, returning a matrix with @var{nr} rows. If the\n\ | |
2309 number of elements read is not an exact multiple of @var{nr}, the last\n\ | |
2310 column is padded with zeros.\n\ | |
2311 \n\ | |
2312 @item [@var{nr}, @var{nc}]\n\ | |
2313 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with\n\ | |
2314 @var{nr} rows. If the number of elements read is not an exact multiple\n\ | |
2315 of @var{nr}, the last column is padded with zeros.\n\ | |
2316 @end table\n\ | |
2317 \n\ | |
2318 @noindent\n\ | |
2319 If @var{size} is omitted, a value of @code{Inf} is assumed.\n\ | |
2318 | 2320 \n\ |
3372 | 2321 The optional argument @var{precision} is a string specifying the type of\n\ |
2322 data to read and may be one of\n\ | |
2323 \n\ | |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
2324 @table @asis\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2325 @item @qcode{\"schar\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2326 @itemx @qcode{\"signed char\"}\n\ |
3372 | 2327 Signed character.\n\ |
529 | 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{\"uchar\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2330 @itemx @qcode{\"unsigned char\"}\n\ |
3372 | 2331 Unsigned character.\n\ |
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{\"int8\"}\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*1\"}\n\ |
4944 | 2335 \n\ |
2336 8-bit signed integer.\n\ | |
2318 | 2337 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2338 @item @qcode{\"int16\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2339 @itemx @qcode{\"integer*2\"}\n\ |
4944 | 2340 16-bit signed integer.\n\ |
3372 | 2341 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2342 @item @qcode{\"int32\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2343 @itemx @qcode{\"integer*4\"}\n\ |
4944 | 2344 32-bit signed integer.\n\ |
3372 | 2345 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2346 @item @qcode{\"int64\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2347 @itemx @qcode{\"integer*8\"}\n\ |
4944 | 2348 64-bit signed integer.\n\ |
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{\"uint8\"}\n\ |
4944 | 2351 8-bit unsigned integer.\n\ |
529 | 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{\"uint16\"}\n\ |
4944 | 2354 16-bit unsigned integer.\n\ |
3372 | 2355 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2356 @item @qcode{\"uint32\"}\n\ |
4944 | 2357 32-bit unsigned integer.\n\ |
3372 | 2358 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2359 @item @qcode{\"uint64\"}\n\ |
4944 | 2360 64-bit unsigned integer.\n\ |
2361 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2362 @item @qcode{\"single\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2363 @itemx @qcode{\"float32\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2364 @itemx @qcode{\"real*4\"}\n\ |
4944 | 2365 32-bit floating point number.\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{\"double\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2368 @itemx @qcode{\"float64\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2369 @itemx @qcode{\"real*8\"}\n\ |
4944 | 2370 64-bit floating point number.\n\ |
2371 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2372 @item @qcode{\"char\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2373 @itemx @qcode{\"char*1\"}\n\ |
4944 | 2374 Single character.\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{\"short\"}\n\ |
4944 | 2377 Short integer (size is platform dependent).\n\ |
2378 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2379 @item @qcode{\"int\"}\n\ |
4944 | 2380 Integer (size is platform dependent).\n\ |
2381 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2382 @item @qcode{\"long\"}\n\ |
4944 | 2383 Long integer (size is platform dependent).\n\ |
3372 | 2384 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2385 @item @qcode{\"ushort\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2386 @itemx @qcode{\"unsigned short\"}\n\ |
4944 | 2387 Unsigned short integer (size is platform dependent).\n\ |
4610 | 2388 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2389 @item @qcode{\"uint\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2390 @itemx @qcode{\"unsigned int\"}\n\ |
4944 | 2391 Unsigned integer (size is platform dependent).\n\ |
4610 | 2392 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2393 @item @qcode{\"ulong\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2394 @itemx @qcode{\"unsigned long\"}\n\ |
4944 | 2395 Unsigned long integer (size is platform dependent).\n\ |
2396 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2397 @item @qcode{\"float\"}\n\ |
4944 | 2398 Single precision floating point number (size is platform dependent).\n\ |
3372 | 2399 @end table\n\ |
2400 \n\ | |
2401 @noindent\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2402 The default precision is @qcode{\"uchar\"}.\n\ |
2318 | 2403 \n\ |
4944 | 2404 The @var{precision} argument may also specify an optional repeat\n\ |
2405 count. For example, @samp{32*single} causes @code{fread} to read\n\ | |
2406 a block of 32 single precision floating point numbers. Reading in\n\ | |
2407 blocks is useful in combination with the @var{skip} argument.\n\ | |
2408 \n\ | |
2409 The @var{precision} argument may also specify a type conversion.\n\ | |
2410 For example, @samp{int16=>int32} causes @code{fread} to read 16-bit\n\ | |
2411 integer values and return an array of 32-bit integer values. By\n\ | |
2412 default, @code{fread} returns a double precision array. The special\n\ | |
2413 form @samp{*TYPE} is shorthand for @samp{TYPE=>TYPE}.\n\ | |
2414 \n\ | |
7096 | 2415 The conversion and repeat counts may be combined. For example, the\n\ |
2416 specification @samp{32*single=>single} causes @code{fread} to read\n\ | |
2417 blocks of single precision floating point values and return an array\n\ | |
2418 of single precision values instead of the default array of double\n\ | |
2419 precision values.\n\ | |
4944 | 2420 \n\ |
3372 | 2421 The optional argument @var{skip} specifies the number of bytes to skip\n\ |
4944 | 2422 after each element (or block of elements) is read. If it is not\n\ |
2423 specified, a value of 0 is assumed. If the final block read is not\n\ | |
2424 complete, the final skip is omitted. For example,\n\ | |
2425 \n\ | |
2426 @example\n\ | |
2427 fread (f, 10, \"3*single=>single\", 8)\n\ | |
2428 @end example\n\ | |
2429 \n\ | |
2430 @noindent\n\ | |
2431 will omit the final 8-byte skip because the last read will not be\n\ | |
2432 a complete block of 3 values.\n\ | |
3372 | 2433 \n\ |
2434 The optional argument @var{arch} is a string specifying the data format\n\ | |
2435 for the file. Valid values are\n\ | |
529 | 2436 \n\ |
18078
b06a9768b643
doc: Don't use @table @qcode to avoid problems with Texinfo 5.2.
Rik <rik@octave.org>
parents:
18040
diff
changeset
|
2437 @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
|
2438 @item @qcode{\"native\"} or @qcode{\"n\"}\n\ |
3372 | 2439 The format of the current machine.\n\ |
2440 \n\ | |
20431
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
2441 @item @qcode{\"ieee-be\"} or @qcode{\"b\"}\n\ |
3372 | 2442 IEEE big endian.\n\ |
2443 \n\ | |
20431
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
2444 @item @qcode{\"ieee-le\"} or @qcode{\"l\"}\n\ |
3372 | 2445 IEEE little endian.\n\ |
2446 @end table\n\ | |
2318 | 2447 \n\ |
20439
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20431
diff
changeset
|
2448 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
|
2449 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
|
2450 @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
|
2451 \n\ |
18208
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
2452 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
|
2453 \n\ |
18208
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
2454 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
|
2455 @seealso{fwrite, fgets, fgetl, fscanf, fopen}\n\ |
5642 | 2456 @end deftypefn") |
529 | 2457 { |
2116 | 2458 int nargin = args.length (); |
2459 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2460 if (nargin < 1 || nargin > 5) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2461 print_usage (); |
2116 | 2462 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2463 octave_stream os = octave_stream_list::lookup (args(0), "fread"); |
2116 | 2464 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2465 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
|
2466 octave_value prec = "uchar"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2467 octave_value skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2468 octave_value arch = "unknown"; |
2116 | 2469 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2470 int idx = 1; |
2116 | 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 && ! args(idx).is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2473 size = args(idx++); |
2116 | 2474 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2475 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2476 prec = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2477 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2478 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2479 skip = args(idx++); |
4257 | 2480 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2481 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2482 arch = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2483 else if (skip.is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2484 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2485 arch = skip; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2486 skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2487 } |
2116 | 2488 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2489 octave_idx_type count = -1; |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20457
diff
changeset
|
2490 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2491 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
|
2492 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2493 return ovl (tmp, count); |
529 | 2494 } |
2495 | |
2116 | 2496 static int |
2497 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
|
2498 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
|
2499 const octave_value& arch_arg) |
2116 | 2500 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20687
diff
changeset
|
2501 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
|
2502 |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
2503 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
|
2504 oct_data_conv::data_type output_type; |
2116 | 2505 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2506 try |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
2507 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2508 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
|
2509 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
2510 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2511 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2512 error (e, "fwrite: invalid PRECISION specified"); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2513 } |
2116 | 2514 |
20747
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
2515 int skip = 0; |
3202 | 2516 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2517 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2518 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2519 skip = skip_arg.int_value (true); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2520 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20764
diff
changeset
|
2521 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2522 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2523 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
|
2524 } |
2116 | 2525 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2526 std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string"); |
2116 | 2527 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
2528 octave::mach_info::float_format flt_fmt |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
2529 = octave::mach_info::string_to_float_format (arch); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2530 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20713
diff
changeset
|
2531 return os.write (data, block_size, output_type, skip, flt_fmt); |
2116 | 2532 } |
2533 | |
2534 DEFUN (fwrite, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2535 "-*- 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
|
2536 @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
|
2537 @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
|
2538 @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
|
2539 @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
|
2540 @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
|
2541 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
|
2542 @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
|
2543 to the file.\n\ |
1181 | 2544 \n\ |
3372 | 2545 The argument @var{data} is a matrix of values that are to be written to\n\ |
2546 the file. The values are extracted in column-major order.\n\ | |
1181 | 2547 \n\ |
3372 | 2548 The remaining arguments @var{precision}, @var{skip}, and @var{arch} are\n\ |
2549 optional, and are interpreted as described for @code{fread}.\n\ | |
1181 | 2550 \n\ |
3372 | 2551 The behavior of @code{fwrite} is undefined if the values in @var{data}\n\ |
2552 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
|
2553 @seealso{fread, fputs, fprintf, fopen}\n\ |
5642 | 2554 @end deftypefn") |
1181 | 2555 { |
2116 | 2556 int nargin = args.length (); |
2557 | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2558 if (nargin < 2 || nargin > 5) |
5823 | 2559 print_usage (); |
2116 | 2560 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2561 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
|
2562 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2563 octave_value prec = "uchar"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2564 octave_value skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2565 octave_value arch = "unknown"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2566 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2567 int idx = 1; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2568 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2569 octave_value data = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2570 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2571 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2572 prec = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2573 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2574 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2575 skip = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2576 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2577 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2578 arch = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2579 else if (skip.is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2580 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2581 arch = skip; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2582 skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2583 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2584 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
2585 return ovl (do_fwrite (os, data, prec, skip, arch)); |
1181 | 2586 } |
2587 | |
5906 | 2588 DEFUNX ("feof", Ffeof, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2589 "-*- 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
|
2590 @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
|
2591 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
|
2592 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
|
2593 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19123
diff
changeset
|
2594 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
|
2595 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
|
2596 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
|
2597 @seealso{fread, frewind, fseek, fclear, fopen}\n\ |
5642 | 2598 @end deftypefn") |
529 | 2599 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2600 if (args.length () != 1) |
5823 | 2601 print_usage (); |
444 | 2602 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2603 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
|
2604 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
2605 return ovl (os.eof () ? 1.0 : 0.0); |
444 | 2606 } |
2607 | |
5906 | 2608 DEFUNX ("ferror", Fferror, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2609 "-*- 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
|
2610 @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
|
2611 @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
|
2612 @deftypefnx {} {[@var{dots}] =} ferror (@var{fid}, \"clear\")\n\ |
19150 | 2613 Query the error status of the stream specified by file descriptor @var{fid}\n\ |
2614 \n\ | |
2615 If an error condition exists then return a string @var{msg} describing the\n\ | |
2616 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
|
2617 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2618 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
|
2619 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
|
2620 \n\ |
19150 | 2621 The optional second output is a numeric indication of the error status.\n\ |
2622 @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
|
2623 \n\ |
19150 | 2624 Note that @code{ferror} indicates if an error has already occurred, not\n\ |
2625 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
|
2626 @seealso{fclear, fopen}\n\ |
3372 | 2627 @end deftypefn") |
1230 | 2628 { |
2095 | 2629 int nargin = args.length (); |
1230 | 2630 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2631 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2632 print_usage (); |
1230 | 2633 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2634 octave_stream os = octave_stream_list::lookup (args(0), "ferror"); |
1230 | 2635 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2636 bool clear = false; |
2095 | 2637 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2638 if (nargin == 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2639 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2640 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
|
2641 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2642 clear = (opt == "clear"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2643 } |
1755 | 2644 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2645 int error_number = 0; |
1230 | 2646 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2647 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
|
2648 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2649 return ovl (error_message, error_number); |
1230 | 2650 } |
2651 | |
18477
aa7ca90ce746
avoid problems if popen is a macro
John W. Eaton <jwe@octave.org>
parents:
18040
diff
changeset
|
2652 DEFUNX ("popen", Fpopen, args, , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19727
diff
changeset
|
2653 "-*- 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
|
2654 @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
|
2655 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
|
2656 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2657 The name of the command to run is given by @var{command}. The argument\n\ |
3301 | 2658 @var{mode} may be\n\ |
2659 \n\ | |
2660 @table @code\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2661 @item @qcode{\"r\"}\n\ |
3301 | 2662 The pipe will be connected to the standard output of the process, and\n\ |
2663 open for reading.\n\ | |
1230 | 2664 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2665 @item @qcode{\"w\"}\n\ |
3301 | 2666 The pipe will be connected to the standard input of the process, and\n\ |
2667 open for writing.\n\ | |
2668 @end table\n\ | |
2669 \n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2670 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
|
2671 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
|
2672 \n\ |
10840 | 2673 For example:\n\ |
1230 | 2674 \n\ |
3301 | 2675 @example\n\ |
2676 @group\n\ | |
2677 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
|
2678 while (ischar (s = fgets (fid)))\n\ |
3301 | 2679 fputs (stdout, s);\n\ |
2680 endwhile\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
2681 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
2682 @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
|
2683 @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
|
2684 @print{} drwxrwxrwt 15 root root 2048 Feb 17 14:53 tmp\n\ |
3301 | 2685 @end group\n\ |
2686 @end example\n\ | |
18950
ed3cb9f81145
file-io.cc (popen): Add seealso popen2
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18487
diff
changeset
|
2687 @seealso{popen2}\n\ |
3301 | 2688 @end deftypefn") |
1230 | 2689 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2690 if (args.length () != 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2691 print_usage (); |
1230 | 2692 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2693 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
|
2694 std::string mode = args(1).xstring_value ("popen: MODE must be a string"); |
1230 | 2695 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2696 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2697 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2698 if (mode == "r") |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2699 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2700 octave_stream ips = octave_iprocstream::create (name); |
1230 | 2701 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2702 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
|
2703 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2704 else if (mode == "w") |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2705 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2706 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
|
2707 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2708 retval = octave_stream_list::insert (ops); |
2095 | 2709 } |
1230 | 2710 else |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2711 error ("popen: invalid MODE specified"); |
1230 | 2712 |
2713 return retval; | |
2714 } | |
2715 | |
16308
122c1a7a3004
avoid trouble if pclose is a macro
John W. Eaton <jwe@octave.org>
parents:
16099
diff
changeset
|
2716 DEFUNX ("pclose", Fpclose, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2717 "-*- 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
|
2718 @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
|
2719 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
|
2720 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2721 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
|
2722 @seealso{fclose, popen}\n\ |
3301 | 2723 @end deftypefn") |
1230 | 2724 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2725 if (args.length () != 1) |
5823 | 2726 print_usage (); |
1379 | 2727 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
2728 return ovl (octave_stream_list::remove (args(0), "pclose")); |
1379 | 2729 } |
2730 | |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2731 DEFUN (tempname, args, , |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2732 "-*- 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
|
2733 @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
|
2734 @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
|
2735 @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
|
2736 Return a unique temporary filename as a string.\n\ |
3372 | 2737 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
2738 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
|
2739 \n\ |
4267 | 2740 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
|
2741 (@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
|
2742 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
|
2743 \n\ |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2744 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
|
2745 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
|
2746 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
|
2747 see @code{tmpfile}.\n\ |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2748 @seealso{mkstemp, tempdir, P_tmpdir, tmpfile}\n\ |
5642 | 2749 @end deftypefn") |
1802 | 2750 { |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2751 int nargin = args.length (); |
2936 | 2752 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2753 if (nargin > 2) |
5823 | 2754 print_usage (); |
1802 | 2755 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2756 std::string dir; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2757 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2758 if (nargin > 0) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2759 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
|
2760 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2761 std::string pfx ("oct-"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2762 |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20805
diff
changeset
|
2763 if (nargin > 1) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2764 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
|
2765 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
2766 return ovl (octave::sys::tempnam (dir, pfx)); |
1802 | 2767 } |
2768 | |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2769 /* |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2770 %!test |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2771 %! if (ispc ()) |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2772 %! envname = "TMP"; |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2773 %! else |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2774 %! envname = "TMPDIR"; |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2775 %! endif |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2776 %! 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
|
2777 %! unsetenv (envname); |
21457
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2778 %! ## 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
|
2779 %! 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
|
2780 %! 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
|
2781 %! def_tmpdir(end) = []; |
05ffef4ebf62
tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents:
21301
diff
changeset
|
2782 %! endwhile |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2783 %! unwind_protect |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2784 %! ## 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
|
2785 %! fname = tempname (); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2786 %! [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
|
2787 %! 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
|
2788 %! assert (tmpfname (1:4), "oct-"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2789 %! ## 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
|
2790 %! 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
|
2791 %! 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
|
2792 %! 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
|
2793 %! fname = tempname (tmp_tmpdir); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2794 %! [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
|
2795 %! 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
|
2796 %! 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
|
2797 %! ## 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
|
2798 %! fname = tempname (""); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2799 %! [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
|
2800 %! 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
|
2801 %! assert (tmpfname (1:4), "oct-"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2802 %! ## 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
|
2803 %! fname = tempname (tmp_tmpdir, "pfx-"); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2804 %! [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
|
2805 %! 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
|
2806 %! 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
|
2807 %! ## 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
|
2808 %! fname = tempname (tmp_tmpdir, ""); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19420
diff
changeset
|
2809 %! [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
|
2810 %! 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
|
2811 %! 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
|
2812 %! 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
|
2813 %! 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
|
2814 %! 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
|
2815 %! unsetenv (envname); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2816 %! else |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2817 %! 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
|
2818 %! endif |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2819 %! 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
|
2820 */ |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
2821 |
4326 | 2822 DEFUN (tmpfile, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2823 "-*- 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
|
2824 @deftypefn {} {[@var{fid}, @var{msg}] =} tmpfile ()\n\ |
4326 | 2825 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
|
2826 name.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2827 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2828 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
|
2829 deleted automatically when it is closed or when Octave exits.\n\ |
4326 | 2830 \n\ |
2831 If successful, @var{fid} is a valid file ID and @var{msg} is an empty\n\ | |
2832 string. Otherwise, @var{fid} is -1 and @var{msg} contains a\n\ | |
2833 system-dependent error message.\n\ | |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2834 @seealso{tempname, mkstemp, tempdir, P_tmpdir}\n\ |
5642 | 2835 @end deftypefn") |
4326 | 2836 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2837 if (args.length () != 0) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2838 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2839 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2840 octave_value_list retval; |
4326 | 2841 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2842 FILE *fid = gnulib::tmpfile (); |
4326 | 2843 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2844 if (fid) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2845 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2846 std::string nm; |
4326 | 2847 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2848 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); |
4326 | 2849 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2850 octave_stream s = octave_stdiostream::create (nm, fid, md); |
4326 | 2851 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2852 if (! s) |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2853 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
|
2854 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2855 retval = ovl (octave_stream_list::insert (s), ""); |
4326 | 2856 } |
2857 else | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2858 { |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2859 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
|
2860 } |
4326 | 2861 |
2862 return retval; | |
2863 } | |
2864 | |
2865 DEFUN (mkstemp, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2866 "-*- 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
|
2867 @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
|
2868 @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
|
2869 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
|
2870 with a unique name created from @var{template}.\n\ |
4326 | 2871 \n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
2872 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
|
2873 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
|
2874 is then created with mode read/write and permissions that are system\n\ |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
2875 dependent (on GNU/Linux systems, the permissions will be 0600 for versions\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
2876 of 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
|
2877 @w{@code{O_EXCL}} flag.\n\ |
4326 | 2878 \n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2879 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
|
2880 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
|
2881 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
2882 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
|
2883 file, and @var{msg} is an empty string. Otherwise, @var{fid} is -1,\n\ |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
2884 @var{name} is empty, and @var{msg} contains a system-dependent error\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21532
diff
changeset
|
2885 message.\n\ |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
2886 @seealso{tempname, tempdir, P_tmpdir, tmpfile, fopen}\n\ |
5642 | 2887 @end deftypefn") |
4326 | 2888 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2889 int nargin = args.length (); |
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 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2892 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2893 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2894 std::string tmpl8 = args(0).xstring_value ("mkstemp: TEMPLATE argument must be a string"); |
4326 | 2895 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2896 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
|
2897 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2898 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
|
2899 strcpy (tmp, tmpl8.c_str ()); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2900 |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
2901 int fd = octave_mkostemp_wrapper (tmp); |
4326 | 2902 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2903 if (fd < 0) |
4326 | 2904 { |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2905 retval(0) = fd; |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2906 retval(2) = gnulib::strerror (errno); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2907 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2908 else |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2909 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2910 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
|
2911 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2912 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
|
2913 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2914 if (! fid) |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2915 { |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2916 retval(0) = -1; |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2917 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
|
2918 } |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2919 else |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2920 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2921 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
|
2922 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2923 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
|
2924 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2925 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
|
2926 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2927 if (! s) |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2928 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
|
2929 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2930 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
|
2931 retval(1) = nm; |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2932 |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20861
diff
changeset
|
2933 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
|
2934 mark_for_deletion (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2935 } |
4326 | 2936 } |
2937 | |
2938 return retval; | |
2939 } | |
2940 | |
20200
d9f35ceff9e1
Change mkfifo to use an octal argument for MODE (bug #45054).
Rik <rik@octave.org>
parents:
20198
diff
changeset
|
2941 // 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
|
2942 // Maybe change to be a general utility routine. |
1400 | 2943 static int |
2944 convert (int x, int ibase, int obase) | |
2945 { | |
2946 int retval = 0; | |
2947 | |
2948 int tmp = x % obase; | |
2949 | |
2950 if (tmp > ibase - 1) | |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20200
diff
changeset
|
2951 error ("umask: invalid digit"); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2952 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2953 retval = tmp; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2954 int mult = ibase; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2955 while ((x = (x - tmp) / obase)) |
1400 | 2956 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2957 tmp = x % obase; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2958 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2959 if (tmp > ibase - 1) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2960 error ("umask: invalid digit"); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2961 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2962 retval += mult * tmp; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20962
diff
changeset
|
2963 mult *= ibase; |
1400 | 2964 } |
2965 | |
2966 return retval; | |
2967 } | |
2968 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2969 DEFUNX ("umask", Fumask, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2970 "-*- 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
|
2971 @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
|
2972 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
|
2973 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2974 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
|
2975 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20101
diff
changeset
|
2976 If successful, returns the previous value of the mask (as an integer to be\n\ |
4715 | 2977 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
|
2978 \n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
2979 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
|
2980 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
|
2981 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
|
2982 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
|
2983 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
|
2984 @seealso{fopen, mkdir, mkfifo}\n\ |
3301 | 2985 @end deftypefn") |
1400 | 2986 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2987 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2988 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2989 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2990 int mask = args(0).xint_value ("umask: MASK must be an integer"); |
1400 | 2991 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2992 if (mask < 0) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2993 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
|
2994 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2995 int oct_mask = convert (mask, 8, 10); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
2996 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
2997 int status = convert (octave::sys::umask (oct_mask), 10, 8); |
1400 | 2998 |
2999 if (status >= 0) | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
3000 return ovl (status); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
3001 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
3002 return ovl (); |
1400 | 3003 } |
3004 | |
5749 | 3005 static octave_value |
6483 | 3006 const_value (const char *, const octave_value_list& args, int val) |
2189 | 3007 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3008 if (args.length () != 0) |
5823 | 3009 print_usage (); |
5749 | 3010 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3011 return octave_value (val); |
5749 | 3012 } |
3013 | |
3014 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
|
3015 "-*- 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
|
3016 @deftypefn {} {} P_tmpdir ()\n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
3017 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
|
3018 temporary files.\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3019 \n\ |
19210
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19150
diff
changeset
|
3020 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
|
3021 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
|
3022 @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
|
3023 environment variable.\n\ |
19278
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19268
diff
changeset
|
3024 @seealso{tempdir, tempname, mkstemp, tmpfile}\n\ |
5749 | 3025 @end deftypefn") |
3026 { | |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3027 if (args.length () != 0) |
5823 | 3028 print_usage (); |
5749 | 3029 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21126
diff
changeset
|
3030 return ovl (get_P_tmpdir ()); |
5749 | 3031 } |
2341 | 3032 |
5749 | 3033 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be |
3034 // this way for Matlab compatibility. | |
3035 | |
3036 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
|
3037 "-*- 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
|
3038 @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
|
3039 @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
|
3040 @deftypefnx {} {} SEEK_END ()\n\ |
19109
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3041 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
|
3042 following actions:\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14365
diff
changeset
|
3043 \n\ |
3372 | 3044 @table @code\n\ |
3045 @item SEEK_SET\n\ | |
3046 Position file relative to the beginning.\n\ | |
3047 \n\ | |
3048 @item SEEK_CUR\n\ | |
3049 Position file relative to the current position.\n\ | |
3050 \n\ | |
3051 @item SEEK_END\n\ | |
5749 | 3052 Position file relative to the end.\n\ |
3372 | 3053 @end table\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3054 @seealso{fseek}\n\ |
5749 | 3055 @end deftypefn") |
3056 { | |
3057 return const_value ("SEEK_SET", args, -1); | |
3058 } | |
2189 | 3059 |
5749 | 3060 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
|
3061 "-*- 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
|
3062 @deftypefn {} {} SEEK_CUR ()\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3063 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
|
3064 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
|
3065 @seealso{SEEK_SET, SEEK_END}\n\ |
5749 | 3066 @end deftypefn") |
3067 { | |
3068 return const_value ("SEEK_CUR", args, 0); | |
3069 } | |
2189 | 3070 |
5749 | 3071 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
|
3072 "-*- 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
|
3073 @deftypefn {} {} SEEK_END ()\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3074 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
|
3075 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
|
3076 @seealso{SEEK_SET, SEEK_CUR}\n\ |
5749 | 3077 @end deftypefn") |
3078 { | |
3079 return const_value ("SEEK_END", args, 1); | |
3080 } | |
3081 | |
3082 static octave_value | |
6483 | 3083 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
|
3084 const octave_value& val) |
5749 | 3085 { |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3086 if (args.length () != 0) |
5823 | 3087 print_usage (); |
5749 | 3088 |
20805
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3089 return octave_value (val); |
5749 | 3090 } |
3091 | |
3092 DEFUNX ("stdin", Fstdin, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3093 "-*- 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
|
3094 @deftypefn {} {} stdin ()\n\ |
5749 | 3095 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
|
3096 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3097 When Octave is used interactively, stdin is filtered through the command\n\ |
5749 | 3098 line editing functions.\n\ |
5333 | 3099 @seealso{stdout, stderr}\n\ |
5749 | 3100 @end deftypefn") |
3101 { | |
3102 return const_value ("stdin", args, stdin_file); | |
3103 } | |
2189 | 3104 |
5749 | 3105 DEFUNX ("stdout", Fstdout, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3106 "-*- 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
|
3107 @deftypefn {} {} stdout ()\n\ |
5749 | 3108 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
|
3109 \n\ |
5749 | 3110 Data written to the standard output is normally filtered through the pager.\n\ |
5333 | 3111 @seealso{stdin, stderr}\n\ |
5749 | 3112 @end deftypefn") |
3113 { | |
3114 return const_value ("stdout", args, stdout_file); | |
3115 } | |
2189 | 3116 |
5749 | 3117 DEFUNX ("stderr", Fstderr, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3118 "-*- 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
|
3119 @deftypefn {} {} stderr ()\n\ |
5749 | 3120 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
|
3121 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19030
diff
changeset
|
3122 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
|
3123 It is useful for error messages and prompts.\n\ |
5333 | 3124 @seealso{stdin, stdout}\n\ |
5749 | 3125 @end deftypefn") |
3126 { | |
3127 return const_value ("stderr", args, stderr_file); | |
2189 | 3128 } |