Mercurial > octave-nkf
annotate libinterp/corefcn/file-io.cc @ 20593:c41595061186
eliminate more simple uses of error_state
* betainc.cc, file-io.cc, ov-class.cc, ov-struct.cc:
Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Oct 2015 23:09:54 -0400 |
parents | 642ce72cf1ab |
children | fd0efcdb3718 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19631
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
2095 | 23 // Originally written by John C. Campbell <jcc@bevo.che.wisc.edu> |
1230 | 24 // |
2095 | 25 // Thomas Baier <baier@ci.tuwien.ac.at> added the original versions of |
26 // the following functions: | |
1230 | 27 // |
2095 | 28 // popen |
29 // pclose | |
30 // execute (now popen2.m) | |
31 // sync_system (now merged with system) | |
32 // async_system (now merged with system) | |
1230 | 33 |
9322 | 34 // Extensively revised by John W. Eaton <jwe@octave.org>, |
2095 | 35 // April 1996. |
1 | 36 |
240 | 37 #ifdef HAVE_CONFIG_H |
1230 | 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> |
4726 | 47 #include <vector> |
1350 | 48 |
13958
cb15c5185b6a
mkstemp: open file in binary mode (bug #33669)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
49 #include <fcntl.h> |
1230 | 50 #include <sys/types.h> |
1 | 51 #include <unistd.h> |
1350 | 52 |
5325 | 53 #ifdef HAVE_ZLIB_H |
54 #include <zlib.h> | |
55 #endif | |
56 | |
5102 | 57 #include "error.h" |
2926 | 58 #include "file-ops.h" |
6159 | 59 #include "file-stat.h" |
5102 | 60 #include "lo-ieee.h" |
6159 | 61 #include "oct-env.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
62 #include "oct-locbuf.h" |
2926 | 63 |
1352 | 64 #include "defun.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" |
1750 | 70 #include "oct-obj.h" |
2095 | 71 #include "oct-prcstrm.h" |
72 #include "oct-stream.h" | |
73 #include "oct-strstrm.h" | |
1 | 74 #include "pager.h" |
444 | 75 #include "sysdep.h" |
1352 | 76 #include "utils.h" |
2370 | 77 #include "variables.h" |
1583 | 78 |
2902 | 79 static octave_value stdin_file; |
80 static octave_value stdout_file; | |
81 static octave_value stderr_file; | |
82 | |
4468 | 83 static octave_stream stdin_stream; |
84 static octave_stream stdout_stream; | |
85 static octave_stream stderr_stream; | |
86 | |
1 | 87 void |
164 | 88 initialize_file_io (void) |
1 | 89 { |
4468 | 90 stdin_stream = octave_istream::create (&std::cin, "stdin"); |
2116 | 91 |
3531 | 92 // This uses octave_stdout (see pager.h), not std::cout so that Octave's |
2116 | 93 // standard output stream will pass through the pager. |
94 | |
4468 | 95 stdout_stream = octave_ostream::create (&octave_stdout, "stdout"); |
2116 | 96 |
4468 | 97 stderr_stream = octave_ostream::create (&std::cerr, "stderr"); |
1 | 98 |
2902 | 99 stdin_file = octave_stream_list::insert (stdin_stream); |
100 stdout_file = octave_stream_list::insert (stdout_stream); | |
101 stderr_file = octave_stream_list::insert (stderr_stream); | |
1 | 102 } |
103 | |
2095 | 104 void |
105 close_files (void) | |
1 | 106 { |
2095 | 107 octave_stream_list::clear (); |
108 } | |
636 | 109 |
5102 | 110 // List of files to delete when we exit or crash. |
111 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
112 // FIXME: this should really be static, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 // but that causes problems on some systems. |
5102 | 114 std::stack <std::string> tmp_files; |
115 | |
116 void | |
117 mark_for_deletion (const std::string& file) | |
118 { | |
119 tmp_files.push (file); | |
120 } | |
121 | |
122 void | |
123 cleanup_tmp_files (void) | |
124 { | |
125 while (! tmp_files.empty ()) | |
126 { | |
127 std::string filename = tmp_files.top (); | |
128 tmp_files.pop (); | |
10411 | 129 gnulib::unlink (filename.c_str ()); |
5102 | 130 } |
131 } | |
132 | |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
133 static void |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
134 normalize_fopen_mode (std::string& mode, bool& use_zlib) |
1 | 135 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
136 use_zlib = false; |
896 | 137 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
138 if (! mode.empty ()) |
368 | 139 { |
2095 | 140 // Could probably be faster, but does it really matter? |
1766 | 141 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
142 // 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
|
143 // 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
|
144 // flushing" but we don't know precisely what action that implies. |
7078 | 145 |
146 size_t pos = mode.find ('W'); | |
147 | |
8021 | 148 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
149 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
150 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
|
151 "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
|
152 mode[pos] = 'w'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
153 } |
7078 | 154 |
155 pos = mode.find ('R'); | |
156 | |
8021 | 157 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
158 { |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
159 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
|
160 "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
|
161 mode[pos] = 'r'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
162 } |
7078 | 163 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
164 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
|
165 |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
166 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
|
167 { |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
168 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
|
169 "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
|
170 mode[pos] = 'a'; |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
171 } |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
172 |
7078 | 173 pos = mode.find ('z'); |
5325 | 174 |
8021 | 175 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
176 { |
5325 | 177 #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
|
178 use_zlib = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
179 mode.erase (pos, 1); |
5325 | 180 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
181 error ("this version of Octave does not support gzipped files"); |
5325 | 182 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
183 } |
5325 | 184 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
185 // 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:
20492
diff
changeset
|
186 // '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
|
187 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
188 size_t bpos = mode.find ('b'); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
189 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
|
190 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
191 if (bpos == std::string::npos && tpos == std::string::npos) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
192 mode += 'b'; |
1 | 193 } |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
194 } |
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 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
|
197 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
|
198 { |
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
199 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
|
200 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
201 if (mode == "rt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
202 retval = std::ios::in; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
203 else if (mode == "wt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
204 retval = std::ios::out | std::ios::trunc; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
205 else if (mode == "at") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
206 retval = std::ios::out | std::ios::app; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
207 else if (mode == "r+t" || mode == "rt+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
208 retval = std::ios::in | std::ios::out; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
209 else if (mode == "w+t" || mode == "wt+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
210 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:
20492
diff
changeset
|
211 else if (mode == "a+t" || mode == "at+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
212 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:
20492
diff
changeset
|
213 else if (mode == "rb" || mode == "r") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
214 retval = std::ios::in | std::ios::binary; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
215 else if (mode == "wb" || mode == "w") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
216 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:
20492
diff
changeset
|
217 else if (mode == "ab" || mode == "a") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
218 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:
20492
diff
changeset
|
219 else if (mode == "r+b" || mode == "rb+" || mode == "r+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
220 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:
20492
diff
changeset
|
221 else if (mode == "w+b" || mode == "wb+" || mode == "w+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
222 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:
20492
diff
changeset
|
223 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
224 else if (mode == "a+b" || mode == "ab+" || mode == "a+") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
225 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:
20492
diff
changeset
|
226 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
227 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
228 error ("invalid mode specified"); |
1 | 229 |
230 return retval; | |
231 } | |
232 | |
1957 | 233 DEFUN (fclose, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
234 "-*- texinfo -*-\n\ |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
12552
diff
changeset
|
235 @deftypefn {Built-in Function} {} fclose (@var{fid})\n\ |
12552
1cfa3d9adf0a
Document the "all" parameter to fclose.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12546
diff
changeset
|
236 @deftypefnx {Built-in Function} {} fclose (\"all\")\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
237 @deftypefnx {Built-in Function} {@var{status} =} fclose (\"all\")\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
238 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:
19064
diff
changeset
|
239 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
240 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:
19064
diff
changeset
|
241 second form of the @code{fclose} call closes all open files except\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
242 @code{stdout}, @code{stderr}, and @code{stdin}.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
243 \n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
244 Programming Note: When using @qcode{\"all\"} the file descriptors associated\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
245 with gnuplot will also be closed. This will prevent further plotting with\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
246 gnuplot until Octave is closed and restarted.\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
247 @seealso{fopen, fflush, freport}\n\ |
5642 | 248 @end deftypefn") |
529 | 249 { |
4233 | 250 octave_value retval = -1; |
529 | 251 |
252 int nargin = args.length (); | |
253 | |
2095 | 254 if (nargin == 1) |
4233 | 255 retval = octave_stream_list::remove (args(0), "fclose"); |
1 | 256 else |
5823 | 257 print_usage (); |
1 | 258 |
259 return retval; | |
260 } | |
261 | |
5144 | 262 DEFUN (fclear, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
263 "-*- texinfo -*-\n\ |
5144 | 264 @deftypefn {Built-in Function} {} fclear (@var{fid})\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
265 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:
19064
diff
changeset
|
266 @var{fid}.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
267 @seealso{ferror, fopen}\n\ |
5144 | 268 @end deftypefn") |
269 { | |
270 octave_value retval; | |
271 | |
272 int nargin = args.length (); | |
273 | |
274 if (nargin == 1) | |
275 { | |
18111
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18078
diff
changeset
|
276 int fid = octave_stream_list::get_file_number (args(0)); |
5144 | 277 |
278 octave_stream os = octave_stream_list::lookup (fid, "fclear"); | |
279 | |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
280 os.clearerr (); |
5144 | 281 } |
282 else | |
5823 | 283 print_usage (); |
5144 | 284 |
285 return retval; | |
286 } | |
287 | |
1957 | 288 DEFUN (fflush, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
289 "-*- texinfo -*-\n\ |
3372 | 290 @deftypefn {Built-in Function} {} fflush (@var{fid})\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
291 Flush output to file descriptor @var{fid}.\n\ |
5095 | 292 \n\ |
293 @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
|
294 (@minus{}1 on Unix) on error.\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
295 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
296 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:
19064
diff
changeset
|
297 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:
19064
diff
changeset
|
298 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:
19064
diff
changeset
|
299 @code{input}.\n\ |
5642 | 300 @seealso{fopen, fclose}\n\ |
301 @end deftypefn") | |
1181 | 302 { |
4233 | 303 octave_value retval = -1; |
1181 | 304 |
305 int nargin = args.length (); | |
306 | |
2095 | 307 if (nargin == 1) |
308 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
309 // FIXME: any way to avoid special case for stdout? |
2609 | 310 |
18111
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18078
diff
changeset
|
311 int fid = octave_stream_list::get_file_number (args(0)); |
2609 | 312 |
313 if (fid == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
314 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
315 flush_octave_stdout (); |
2095 | 316 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
317 retval = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
318 } |
2095 | 319 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
320 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
321 octave_stream os = octave_stream_list::lookup (fid, "fflush"); |
2609 | 322 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
323 retval = os.flush (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
324 } |
2095 | 325 } |
326 else | |
5823 | 327 print_usage (); |
1181 | 328 |
329 return retval; | |
330 } | |
331 | |
2095 | 332 DEFUN (fgetl, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
333 "-*- texinfo -*-\n\ |
14435
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
334 @deftypefn {Built-in Function} {@var{str} =} fgetl (@var{fid})\n\ |
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
335 @deftypefnx {Built-in Function} {@var{str} =} fgetl (@var{fid}, @var{len})\n\ |
3372 | 336 Read characters from a file, stopping after a newline, or EOF,\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
337 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:
20136
diff
changeset
|
338 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
339 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:
20136
diff
changeset
|
340 as a string.\n\ |
1339 | 341 \n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
342 If @var{len} is omitted, @code{fgetl} reads until the next newline character.\n\ |
3372 | 343 \n\ |
344 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
|
345 \n\ |
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
346 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
|
347 @seealso{fgets, fscanf, fread, fopen}\n\ |
5642 | 348 @end deftypefn") |
1339 | 349 { |
4468 | 350 static std::string who = "fgetl"; |
351 | |
2599 | 352 octave_value_list retval; |
353 | |
4233 | 354 retval(1) = 0; |
355 retval(0) = -1; | |
1339 | 356 |
357 int nargin = args.length (); | |
358 | |
359 if (nargin == 1 || nargin == 2) | |
2095 | 360 { |
4468 | 361 octave_stream os = octave_stream_list::lookup (args(0), who); |
2095 | 362 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
363 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); |
2095 | 364 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
365 bool err = false; |
2095 | 366 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
367 std::string tmp = os.getl (len_arg, err, who); |
2095 | 368 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
369 if (! err) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
370 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
371 retval(1) = tmp.length (); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
372 retval(0) = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
373 } |
2095 | 374 } |
1339 | 375 else |
5823 | 376 print_usage (); |
1339 | 377 |
378 return retval; | |
379 } | |
380 | |
2095 | 381 DEFUN (fgets, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
382 "-*- texinfo -*-\n\ |
14435
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
383 @deftypefn {Built-in Function} {@var{str} =} fgets (@var{fid})\n\ |
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
384 @deftypefnx {Built-in Function} {@var{str} =} fgets (@var{fid}, @var{len})\n\ |
3372 | 385 Read characters from a file, stopping after a newline, or EOF,\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
386 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:
20136
diff
changeset
|
387 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
388 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:
20136
diff
changeset
|
389 as a string.\n\ |
529 | 390 \n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
391 If @var{len} is omitted, @code{fgets} reads until the next newline character.\n\ |
3372 | 392 \n\ |
393 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
|
394 \n\ |
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
395 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
|
396 @seealso{fputs, fgetl, fscanf, fread, fopen}\n\ |
5642 | 397 @end deftypefn") |
529 | 398 { |
4468 | 399 static std::string who = "fgets"; |
400 | |
2599 | 401 octave_value_list retval; |
402 | |
403 retval(1) = 0.0; | |
404 retval(0) = -1.0; | |
529 | 405 |
406 int nargin = args.length (); | |
407 | |
1338 | 408 if (nargin == 1 || nargin == 2) |
2095 | 409 { |
4468 | 410 octave_stream os = octave_stream_list::lookup (args(0), who); |
2095 | 411 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
412 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); |
2095 | 413 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
414 bool err = false; |
2095 | 415 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
416 std::string tmp = os.gets (len_arg, err, who); |
2095 | 417 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
418 if (! err) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
419 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
420 retval(1) = tmp.length (); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
421 retval(0) = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
422 } |
2095 | 423 } |
1338 | 424 else |
5823 | 425 print_usage (); |
529 | 426 |
427 return retval; | |
428 } | |
429 | |
9701 | 430 DEFUN (fskipl, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
431 "-*- texinfo -*-\n\ |
14436
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
432 @deftypefn {Built-in Function} {@var{nlines} =} fskipl (@var{fid})\n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
433 @deftypefnx {Built-in Function} {@var{nlines} =} fskipl (@var{fid}, @var{count})\n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
434 @deftypefnx {Built-in Function} {@var{nlines} =} fskipl (@var{fid}, Inf)\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
435 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:
19157
diff
changeset
|
436 descriptor @var{fid}.\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
437 \n\ |
14436
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
438 @code{fskipl} discards characters until an end-of-line is encountered exactly\n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
439 @var{count}-times, or until the end-of-file marker is found.\n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
440 \n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
441 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
|
442 @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
|
443 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
|
444 \n\ |
9701 | 445 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
|
446 @seealso{fgetl, fgets, fscanf, fopen}\n\ |
9701 | 447 @end deftypefn") |
448 { | |
449 static std::string who = "fskipl"; | |
450 | |
451 octave_value retval; | |
452 | |
453 int nargin = args.length (); | |
454 | |
455 if (nargin == 1 || nargin == 2) | |
456 { | |
457 octave_stream os = octave_stream_list::lookup (args(0), who); | |
458 | |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
459 octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); |
9701 | 460 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
461 bool err = false; |
9701 | 462 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
463 off_t tmp = os.skipl (count_arg, err, who); |
9701 | 464 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
465 if (! err) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
466 retval = tmp; |
9701 | 467 } |
468 else | |
469 print_usage (); | |
470 | |
471 return retval; | |
472 } | |
473 | |
474 | |
3340 | 475 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
|
476 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
|
477 const std::string& arch, int& fid) |
1 | 478 { |
3340 | 479 octave_stream retval; |
1 | 480 |
2095 | 481 fid = -1; |
1 | 482 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
483 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
|
484 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
|
485 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
|
486 |
4036 | 487 std::ios::openmode md = fopen_mode_to_ios_mode (mode); |
1 | 488 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
489 oct_mach_info::float_format flt_fmt = |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
490 oct_mach_info::string_to_float_format (arch); |
1 | 491 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
492 std::string fname = file_ops::tilde_expand (name); |
6159 | 493 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
494 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
|
495 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
496 if (! (md & std::ios::out)) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
497 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
|
498 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
499 if (! fs.is_dir ()) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
500 { |
6905 | 501 #if defined (HAVE_ZLIB) |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
502 if (use_zlib) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
503 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
504 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
|
505 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
506 int fd = fileno (fptr); |
11004
594adb99a25e
cache file id in octave_tstdiostream class
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
507 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
508 gzFile gzf = ::gzdopen (fd, mode.c_str ()); |
5325 | 509 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
510 if (fptr) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
511 retval = octave_zstdiostream::create (fname, gzf, fd, |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
512 md, flt_fmt); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
513 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
514 retval.error (gnulib::strerror (errno)); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
515 } |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
516 else |
5325 | 517 #endif |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
518 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
519 FILE *fptr = gnulib::fopen (fname.c_str (), mode.c_str ()); |
5370 | 520 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
521 retval = octave_stdiostream::create (fname, fptr, md, |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
522 flt_fmt); |
7730
b68e44c90afe
file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents:
7708
diff
changeset
|
523 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
524 if (! fptr) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
525 retval.error (gnulib::strerror (errno)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
526 } |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
527 |
1 | 528 } |
529 | |
2095 | 530 return retval; |
531 } | |
1 | 532 |
3340 | 533 static octave_stream |
2095 | 534 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
|
535 const octave_value& tc_arch, const char *fcn, int& fid) |
2095 | 536 { |
3340 | 537 octave_stream retval; |
2095 | 538 |
539 fid = -1; | |
540 | |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
541 if (tc_name.is_string ()) |
1 | 542 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
543 std::string name = tc_name.string_value (); |
2095 | 544 |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
545 if (tc_mode.is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
546 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
547 std::string mode = tc_mode.string_value (); |
1 | 548 |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
549 if (tc_arch.is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
550 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
551 std::string arch = tc_arch.string_value (); |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
552 |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
553 retval = do_stream_open (name, mode, arch, fid); |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
554 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
555 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
556 error ("%s: architecture type must be a string", fcn); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
557 } |
2095 | 558 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
559 error ("%s: file mode must be a string", fcn); |
1 | 560 } |
2095 | 561 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
562 error ("%s: file name must be a string", fcn); |
1 | 563 |
564 return retval; | |
565 } | |
566 | |
11146
69b2f237060e
file-io.cc (Ffopen): argument parsing tweak
John W. Eaton <jwe@octave.org>
parents:
11081
diff
changeset
|
567 DEFUN (fopen, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
568 "-*- texinfo -*-\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
569 @deftypefn {Built-in Function} {@var{fid} =} fopen (@var{name})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
570 @deftypefnx {Built-in Function} {@var{fid} =} fopen (@var{name}, @var{mode})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
571 @deftypefnx {Built-in Function} {@var{fid} =} fopen (@var{name}, @var{mode}, @var{arch})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
572 @deftypefnx {Built-in Function} {[@var{fid}, @var{msg}] =} fopen (@dots{})\n\ |
3372 | 573 @deftypefnx {Built-in Function} {@var{fid_list} =} fopen (\"all\")\n\ |
5353 | 574 @deftypefnx {Built-in Function} {[@var{file}, @var{mode}, @var{arch}] =} fopen (@var{fid})\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
575 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:
20136
diff
changeset
|
576 \n\ |
3372 | 577 The first form of the @code{fopen} function opens the named file with\n\ |
578 the specified mode (read-write, read-only, etc.) and architecture\n\ | |
579 interpretation (IEEE big endian, IEEE little endian, etc.), and returns\n\ | |
580 an integer value that may be used to refer to the file later. If an\n\ | |
581 error occurs, @var{fid} is set to @minus{}1 and @var{msg} contains the\n\ | |
582 corresponding system error message. The @var{mode} is a one or two\n\ | |
583 character string that specifies whether the file is to be opened for\n\ | |
584 reading, writing, or both.\n\ | |
1181 | 585 \n\ |
3372 | 586 The second form of the @code{fopen} function returns a vector of file ids\n\ |
587 corresponding to all the currently open files, excluding the\n\ | |
588 @code{stdin}, @code{stdout}, and @code{stderr} streams.\n\ | |
2318 | 589 \n\ |
5353 | 590 The third form of the @code{fopen} function returns information about the\n\ |
591 open file given its file id.\n\ | |
1181 | 592 \n\ |
3372 | 593 For example,\n\ |
594 \n\ | |
595 @example\n\ | |
596 myfile = fopen (\"splat.dat\", \"r\", \"ieee-le\");\n\ | |
597 @end example\n\ | |
2095 | 598 \n\ |
3372 | 599 @noindent\n\ |
600 opens the file @file{splat.dat} for reading. If necessary, binary\n\ | |
601 numeric values will be read assuming they are stored in IEEE format with\n\ | |
602 the least significant bit first, and then converted to the native\n\ | |
603 representation.\n\ | |
2318 | 604 \n\ |
3372 | 605 Opening a file that is already open simply opens it again and returns a\n\ |
606 separate file id. It is not an error to open a file several times,\n\ | |
607 though writing to the same file through several different file ids may\n\ | |
608 produce unexpected results.\n\ | |
609 \n\ | |
610 The possible values @samp{mode} may have are\n\ | |
611 \n\ | |
612 @table @asis\n\ | |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
613 @item @samp{r} (default)\n\ |
3372 | 614 Open a file for reading.\n\ |
3263 | 615 \n\ |
3372 | 616 @item @samp{w}\n\ |
7001 | 617 Open a file for writing. The previous contents are discarded.\n\ |
3372 | 618 \n\ |
619 @item @samp{a}\n\ | |
620 Open or create a file for writing at the end of the file.\n\ | |
621 \n\ | |
622 @item @samp{r+}\n\ | |
623 Open an existing file for reading and writing.\n\ | |
624 \n\ | |
625 @item @samp{w+}\n\ | |
626 Open a file for reading or writing. The previous contents are\n\ | |
627 discarded.\n\ | |
628 \n\ | |
629 @item @samp{a+}\n\ | |
630 Open or create a file for reading or writing at the end of the\n\ | |
631 file.\n\ | |
632 @end table\n\ | |
633 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
634 Append a @qcode{\"t\"} to the mode string to open the file in text mode or a\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
635 @qcode{\"b\"} to open in binary mode. On Windows and Macintosh systems, text\n\ |
4865 | 636 mode reading and writing automatically converts linefeeds to the\n\ |
637 appropriate line end character for the system (carriage-return linefeed\n\ | |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
638 on Windows, carriage-return on Macintosh). The default when no mode is\n\ |
4865 | 639 specified is binary mode.\n\ |
640 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
641 Additionally, you may append a @qcode{\"z\"} to the mode string to open a\n\ |
5325 | 642 gzipped file for reading or writing. For this to be successful, you\n\ |
643 must also open the file in binary mode.\n\ | |
644 \n\ | |
3372 | 645 The parameter @var{arch} is a string specifying the default data format\n\ |
646 for the file. Valid values for @var{arch} are:\n\ | |
2318 | 647 \n\ |
20466
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20233
diff
changeset
|
648 @table @asis\n\ |
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20233
diff
changeset
|
649 @item @qcode{\"native\"} or @qcode{\"n\"} (default)\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
650 The format of the current machine.\n\ |
3372 | 651 \n\ |
20466
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20233
diff
changeset
|
652 @item @qcode{\"ieee-be\"} or @qcode{\"b\"}\n\ |
3372 | 653 IEEE big endian format.\n\ |
654 \n\ | |
20466
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20233
diff
changeset
|
655 @item @qcode{\"ieee-le\"} or @qcode{\"l\"}\n\ |
3372 | 656 IEEE little endian format.\n\ |
657 @end table\n\ | |
658 \n\ | |
659 @noindent\n\ | |
20466
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20233
diff
changeset
|
660 However, conversions are currently only supported for @samp{native},\n\ |
3372 | 661 @samp{ieee-be}, and @samp{ieee-le} formats.\n\ |
20233
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20207
diff
changeset
|
662 \n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20207
diff
changeset
|
663 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:
20207
diff
changeset
|
664 @code{0666 - @var{umask}}.\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20207
diff
changeset
|
665 @seealso{fclose, fgets, fgetl, fscanf, fread, fputs, fdisp, fprintf, fwrite, fskipl, fseek, frewind, ftell, feof, ferror, fclear, fflush, freport, umask}\n\ |
5642 | 666 @end deftypefn") |
529 | 667 { |
2599 | 668 octave_value_list retval; |
669 | |
670 retval(0) = -1.0; | |
529 | 671 |
672 int nargin = args.length (); | |
673 | |
2095 | 674 if (nargin == 1) |
675 { | |
12896
a19b50f6697f
Correctly allow single string input form of fopen() (Bug #33535).
Rik <octave@nomad.inbox5.com>
parents:
12775
diff
changeset
|
676 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
677 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
678 // 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
|
679 // 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
|
680 // 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
|
681 // to supply more than one argument. |
3263 | 682 |
12896
a19b50f6697f
Correctly allow single string input form of fopen() (Bug #33535).
Rik <octave@nomad.inbox5.com>
parents:
12775
diff
changeset
|
683 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
|
684 return octave_stream_list::open_file_numbers (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
685 } |
2095 | 686 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
687 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
688 string_vector tmp = octave_stream_list::get_info (args(0)); |
529 | 689 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
690 retval(2) = tmp(2); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
691 retval(1) = tmp(1); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
692 retval(0) = tmp(0); |
3263 | 693 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
694 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
695 } |
1 | 696 } |
697 | |
2095 | 698 if (nargin > 0 && nargin < 4) |
699 { | |
700 octave_value mode = (nargin == 2 || nargin == 3) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
701 ? args(1) : octave_value ("r"); |
2095 | 702 |
703 octave_value arch = (nargin == 3) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
704 ? args(2) : octave_value ("native"); |
2095 | 705 |
706 int fid = -1; | |
707 | |
3340 | 708 octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid); |
2095 | 709 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
710 if (os) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
711 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
712 retval(1) = ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
713 retval(0) = octave_stream_list::insert (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
714 } |
2095 | 715 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
716 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
717 int error_number = 0; |
5370 | 718 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
719 retval(1) = os.error (false, error_number); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
720 retval(0) = -1.0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
721 } |
2095 | 722 } |
723 else | |
5823 | 724 print_usage (); |
1 | 725 |
726 return retval; | |
727 } | |
728 | |
1957 | 729 DEFUN (freport, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
730 "-*- texinfo -*-\n\ |
3372 | 731 @deftypefn {Built-in Function} {} freport ()\n\ |
732 Print a list of which files have been opened, and whether they are open\n\ | |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
733 for reading, writing, or both.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
734 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
735 For example:\n\ |
3372 | 736 \n\ |
737 @example\n\ | |
738 @group\n\ | |
739 freport ()\n\ | |
740 \n\ | |
19157 | 741 @print{} number mode arch name\n\ |
742 @print{} ------ ---- ---- ----\n\ | |
743 @print{} 0 r ieee-le stdin\n\ | |
744 @print{} 1 w ieee-le stdout\n\ | |
745 @print{} 2 w ieee-le stderr\n\ | |
746 @print{} 3 r ieee-le myfile\n\ | |
3372 | 747 @end group\n\ |
748 @end example\n\ | |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
749 @seealso{fopen, fclose, is_valid_file_id}\n\ |
3372 | 750 @end deftypefn") |
1181 | 751 { |
2095 | 752 octave_value_list retval; |
1181 | 753 |
754 int nargin = args.length (); | |
755 | |
756 if (nargin > 0) | |
757 warning ("freport: ignoring extra arguments"); | |
758 | |
2095 | 759 octave_stdout << octave_stream_list::list_open_files (); |
1181 | 760 |
761 return retval; | |
762 } | |
763 | |
4715 | 764 DEFUN (frewind, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
765 "-*- texinfo -*-\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
766 @deftypefn {Built-in Function} {} frewind (@var{fid})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
767 @deftypefnx {Built-in Function} {@var{status} =} frewind (@var{fid})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
768 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:
19157
diff
changeset
|
769 descriptor @var{fid}.\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
770 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
771 @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:
19064
diff
changeset
|
772 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
|
773 @seealso{fseek, ftell, fopen}\n\ |
3372 | 774 @end deftypefn") |
529 | 775 { |
4715 | 776 octave_value retval; |
777 | |
778 int result = -1; | |
1 | 779 |
506 | 780 int nargin = args.length (); |
781 | |
2095 | 782 if (nargin == 1) |
1086 | 783 { |
3341 | 784 octave_stream os = octave_stream_list::lookup (args(0), "frewind"); |
636 | 785 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
786 result = os.rewind (); |
1 | 787 } |
788 else | |
5823 | 789 print_usage (); |
1 | 790 |
4715 | 791 if (nargout > 0) |
792 retval = result; | |
793 | |
1 | 794 return retval; |
795 } | |
796 | |
1957 | 797 DEFUN (fseek, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
798 "-*- texinfo -*-\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
799 @deftypefn {Built-in Function} {} fseek (@var{fid}, @var{offset})\n\ |
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
800 @deftypefnx {Built-in Function} {} fseek (@var{fid}, @var{offset}, @var{origin})\n\ |
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
801 @deftypefnx {Built-in Function} {@var{status} =} fseek (@dots{})\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
802 Set the file pointer to the location @var{offset} within the file @var{fid}.\n\ |
5095 | 803 \n\ |
804 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
|
805 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
|
806 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
|
807 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
|
808 @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
|
809 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
|
810 @var{offset} can be realized.\n\ |
5095 | 811 \n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
812 @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
|
813 @seealso{fskipl, frewind, ftell, fopen}\n\ |
5642 | 814 @end deftypefn") |
529 | 815 { |
4233 | 816 octave_value retval = -1; |
529 | 817 |
818 int nargin = args.length (); | |
819 | |
2095 | 820 if (nargin == 2 || nargin == 3) |
821 { | |
3341 | 822 octave_stream os = octave_stream_list::lookup (args(0), "fseek"); |
1181 | 823 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
824 octave_value origin_arg = (nargin == 3) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
825 ? args(2) : octave_value (-1.0); |
1 | 826 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
827 retval = os.seek (args(1), origin_arg); |
368 | 828 } |
2095 | 829 else |
5823 | 830 print_usage (); |
1 | 831 |
832 return retval; | |
833 } | |
834 | |
1957 | 835 DEFUN (ftell, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
836 "-*- texinfo -*-\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
837 @deftypefn {Built-in Function} {@var{pos} =} ftell (@var{fid})\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
838 Return the position of the file pointer as the number of characters from the\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
839 beginning of the file specified by file descriptor @var{fid}.\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
840 @seealso{fseek, frewind, feof, fopen}\n\ |
5642 | 841 @end deftypefn") |
1181 | 842 { |
4797 | 843 octave_value retval = -1; |
1 | 844 |
506 | 845 int nargin = args.length (); |
846 | |
2095 | 847 if (nargin == 1) |
1 | 848 { |
3341 | 849 octave_stream os = octave_stream_list::lookup (args(0), "ftell"); |
1 | 850 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
851 retval = os.tell (); |
1 | 852 } |
853 else | |
5823 | 854 print_usage (); |
1 | 855 |
856 return retval; | |
857 } | |
858 | |
3737 | 859 DEFUN (fprintf, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
860 "-*- texinfo -*-\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
861 @deftypefn {Built-in Function} {} fprintf (@var{fid}, @var{template}, @dots{})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
862 @deftypefnx {Built-in Function} {} fprintf (@var{template}, @dots{})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
863 @deftypefnx {Built-in Function} {@var{numbytes} =} fprintf (@dots{})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
864 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:
19157
diff
changeset
|
865 written to the file descriptor @var{fid} instead of @code{stdout}.\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
866 \n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
867 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:
19157
diff
changeset
|
868 function exactly equivalent to @code{printf}.\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
869 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
870 The optional output returns the number of bytes written to the file.\n\ |
20076
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19895
diff
changeset
|
871 \n\ |
20132
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20076
diff
changeset
|
872 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
20136
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20132
diff
changeset
|
873 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20132
diff
changeset
|
874 expanded even when the template string is defined with single quotes.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
875 @seealso{fputs, fdisp, fwrite, fscanf, printf, sprintf, fopen}\n\ |
5642 | 876 @end deftypefn") |
1181 | 877 { |
4468 | 878 static std::string who = "fprintf"; |
879 | |
4715 | 880 octave_value retval; |
881 | |
882 int result = -1; | |
4468 | 883 |
1181 | 884 int nargin = args.length (); |
885 | |
2875 | 886 if (nargin > 1 || (nargin > 0 && args(0).is_string ())) |
2095 | 887 { |
3340 | 888 octave_stream os; |
2873 | 889 int fmt_n = 0; |
890 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
891 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
892 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
893 os = octave_stream_list::lookup (1, who); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
894 } |
2873 | 895 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
896 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
897 fmt_n = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
898 os = octave_stream_list::lookup (args(0), who); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
899 } |
2095 | 900 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
901 if (args(fmt_n).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
902 { |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
903 octave_value_list tmp_args; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
904 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
905 if (nargin > 1 + fmt_n) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
906 { |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
907 tmp_args.resize (nargin-fmt_n-1, octave_value ()); |
2095 | 908 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
909 for (int i = fmt_n + 1; i < nargin; i++) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
910 tmp_args(i-fmt_n-1) = args(i); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
911 } |
2095 | 912 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
913 result = os.printf (args(fmt_n), tmp_args, who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
914 } |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
915 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
916 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
2095 | 917 } |
918 else | |
5823 | 919 print_usage (); |
1181 | 920 |
4715 | 921 if (nargout > 0) |
922 retval = result; | |
923 | |
924 return retval; | |
1181 | 925 } |
926 | |
4715 | 927 DEFUN (printf, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
928 "-*- texinfo -*-\n\ |
5095 | 929 @deftypefn {Built-in Function} {} printf (@var{template}, @dots{})\n\ |
4468 | 930 Print optional arguments under the control of the template string\n\ |
5653 | 931 @var{template} to the stream @code{stdout} and return the number of\n\ |
932 characters printed.\n\ | |
933 @ifclear OCTAVE_MANUAL\n\ | |
5095 | 934 \n\ |
5653 | 935 See the Formatted Output section of the GNU Octave manual for a\n\ |
936 complete description of the syntax of the template string.\n\ | |
937 @end ifclear\n\ | |
20076
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19895
diff
changeset
|
938 \n\ |
20132
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20076
diff
changeset
|
939 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
20136
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20132
diff
changeset
|
940 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20132
diff
changeset
|
941 expanded even when the template string is defined with single quotes.\n\ |
5642 | 942 @seealso{fprintf, sprintf, scanf}\n\ |
943 @end deftypefn") | |
4468 | 944 { |
945 static std::string who = "printf"; | |
946 | |
4715 | 947 octave_value retval; |
948 | |
949 int result = -1; | |
4468 | 950 |
951 int nargin = args.length (); | |
952 | |
953 if (nargin > 0) | |
954 { | |
955 if (args(0).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
956 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
957 octave_value_list tmp_args; |
4468 | 958 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
959 if (nargin > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
960 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
961 tmp_args.resize (nargin-1, octave_value ()); |
4468 | 962 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
963 for (int i = 1; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
964 tmp_args(i-1) = args(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
965 } |
4468 | 966 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
967 result = stdout_stream.printf (args(0), tmp_args, who); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
968 } |
4468 | 969 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
970 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
4468 | 971 } |
972 else | |
5823 | 973 print_usage (); |
4468 | 974 |
4715 | 975 if (nargout > 0) |
976 retval = result; | |
977 | |
4468 | 978 return retval; |
979 } | |
980 | |
2095 | 981 DEFUN (fputs, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
982 "-*- texinfo -*-\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
983 @deftypefn {Built-in Function} {} fputs (@var{fid}, @var{string})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
984 @deftypefnx {Built-in Function} {@var{status} =} fputs (@var{fid}, @var{string})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
985 Write the string @var{string} to the file with file descriptor @var{fid}.\n\ |
5095 | 986 \n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
987 The string is written to the file with no additional formatting. Use\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
988 @code{fdisp} instead to automatically append a newline character appropriate\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
989 for the local machine.\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
990 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
991 Return a non-negative number on success or EOF on error.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
992 @seealso{fdisp, fprintf, fwrite, fopen}\n\ |
3372 | 993 @end deftypefn") |
1181 | 994 { |
4468 | 995 static std::string who = "fputs"; |
996 | |
4233 | 997 octave_value retval = -1; |
1181 | 998 |
999 int nargin = args.length (); | |
1000 | |
2095 | 1001 if (nargin == 2) |
1002 { | |
4468 | 1003 octave_stream os = octave_stream_list::lookup (args(0), who); |
1181 | 1004 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1005 retval = os.puts (args(1), who); |
2095 | 1006 } |
1181 | 1007 else |
5823 | 1008 print_usage (); |
4468 | 1009 |
1010 return retval; | |
1011 } | |
1012 | |
1013 DEFUN (puts, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1014 "-*- texinfo -*-\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1015 @deftypefn {Built-in Function} {} puts (@var{string})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1016 @deftypefnx {Built-in Function} {@var{status} =} puts (@var{string})\n\ |
4468 | 1017 Write a string to the standard output with no formatting.\n\ |
5095 | 1018 \n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1019 The string is written verbatim to the standard output. Use @code{disp} to\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1020 automatically append a newline character appropriate for the local machine.\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1021 \n\ |
5095 | 1022 Return a non-negative number on success and EOF on error.\n\ |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
1023 @seealso{fputs, disp}\n\ |
4468 | 1024 @end deftypefn") |
1025 { | |
1026 static std::string who = "puts"; | |
1027 | |
1028 octave_value retval = -1; | |
1029 | |
1030 if (args.length () == 1) | |
1031 retval = stdout_stream.puts (args(0), who); | |
1032 else | |
5823 | 1033 print_usage (); |
1181 | 1034 |
1035 return retval; | |
1036 } | |
1037 | |
2095 | 1038 DEFUN (sprintf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1039 "-*- texinfo -*-\n\ |
3372 | 1040 @deftypefn {Built-in Function} {} sprintf (@var{template}, @dots{})\n\ |
1041 This is like @code{printf}, except that the output is returned as a\n\ | |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1042 string.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1043 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1044 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:
20136
diff
changeset
|
1045 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:
20136
diff
changeset
|
1046 string, automatically sized to hold all of the items converted.\n\ |
20076
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19895
diff
changeset
|
1047 \n\ |
20132
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20076
diff
changeset
|
1048 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
20136
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20132
diff
changeset
|
1049 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20132
diff
changeset
|
1050 expanded even when the template string is defined with single quotes.\n\ |
5642 | 1051 @seealso{printf, fprintf, sscanf}\n\ |
1052 @end deftypefn") | |
1 | 1053 { |
4468 | 1054 static std::string who = "sprintf"; |
1055 | |
2095 | 1056 octave_value_list retval; |
1 | 1057 |
2095 | 1058 int nargin = args.length (); |
1 | 1059 |
2095 | 1060 if (nargin > 0) |
1 | 1061 { |
2116 | 1062 retval(2) = -1.0; |
1063 retval(1) = "unknown error"; | |
1064 retval(0) = ""; | |
1065 | |
3340 | 1066 octave_ostrstream *ostr = new octave_ostrstream (); |
1 | 1067 |
3340 | 1068 octave_stream os (ostr); |
628 | 1069 |
3340 | 1070 if (os.is_valid ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1071 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1072 octave_value fmt_arg = args(0); |
6007 | 1073 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1074 if (fmt_arg.is_string ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1075 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1076 octave_value_list tmp_args; |
1 | 1077 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1078 if (nargin > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1079 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1080 tmp_args.resize (nargin-1, octave_value ()); |
1 | 1081 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1082 for (int i = 1; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1083 tmp_args(i-1) = args(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1084 } |
628 | 1085 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1086 retval(2) = os.printf (fmt_arg, tmp_args, who); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1087 retval(1) = os.error (); |
19761
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1088 |
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1089 std::string result = ostr->str (); |
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1090 char type = fmt_arg.is_sq_string () ? '\'' : '"'; |
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1091 |
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1092 retval(0) = (result.empty () |
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1093 ? octave_value (charMatrix (1, 0), type) |
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1094 : octave_value (result, type)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1095 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1096 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1097 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1098 } |
2095 | 1099 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1100 error ("%s: unable to create output buffer", who.c_str ()); |
1 | 1101 } |
1102 else | |
5823 | 1103 print_usage (); |
1 | 1104 |
1105 return retval; | |
1106 } | |
1107 | |
2095 | 1108 DEFUN (fscanf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1109 "-*- texinfo -*-\n\ |
13271
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1110 @deftypefn {Built-in Function} {[@var{val}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, @var{size})\n\ |
16099
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
1111 @deftypefnx {Built-in Function} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, \"C\")\n\ |
3372 | 1112 In the first form, read from @var{fid} according to @var{template},\n\ |
1113 returning the result in the matrix @var{val}.\n\ | |
2122 | 1114 \n\ |
3372 | 1115 The optional argument @var{size} specifies the amount of data to read\n\ |
1116 and may be one of\n\ | |
1117 \n\ | |
1118 @table @code\n\ | |
1119 @item Inf\n\ | |
1120 Read as much as possible, returning a column vector.\n\ | |
1121 \n\ | |
1122 @item @var{nr}\n\ | |
1123 Read up to @var{nr} elements, returning a column vector.\n\ | |
2122 | 1124 \n\ |
3372 | 1125 @item [@var{nr}, Inf]\n\ |
1126 Read as much as possible, returning a matrix with @var{nr} rows. If the\n\ | |
1127 number of elements read is not an exact multiple of @var{nr}, the last\n\ | |
1128 column is padded with zeros.\n\ | |
1129 \n\ | |
1130 @item [@var{nr}, @var{nc}]\n\ | |
1131 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with\n\ | |
1132 @var{nr} rows. If the number of elements read is not an exact multiple\n\ | |
1133 of @var{nr}, the last column is padded with zeros.\n\ | |
1134 @end table\n\ | |
2122 | 1135 \n\ |
3372 | 1136 @noindent\n\ |
1137 If @var{size} is omitted, a value of @code{Inf} is assumed.\n\ | |
2122 | 1138 \n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1139 A string is returned if @var{template} specifies only character conversions.\n\ |
2215 | 1140 \n\ |
3372 | 1141 The number of items successfully read is returned in @var{count}.\n\ |
2215 | 1142 \n\ |
13271
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1143 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
|
1144 \n\ |
3372 | 1145 In the second form, read from @var{fid} according to @var{template},\n\ |
1146 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
|
1147 single scalar return value. This form is more ``C-like'', and also\n\ |
3491 | 1148 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
|
1149 conversions is returned in @var{count}\n\ |
5653 | 1150 @ifclear OCTAVE_MANUAL\n\ |
1151 \n\ | |
1152 See the Formatted Input section of the GNU Octave manual for a\n\ | |
1153 complete description of the syntax of the template string.\n\ | |
1154 @end ifclear\n\ | |
14438
6a8c3cd326fd
doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents:
14436
diff
changeset
|
1155 @seealso{fgets, fgetl, fread, scanf, sscanf, fopen}\n\ |
5642 | 1156 @end deftypefn") |
1181 | 1157 { |
4468 | 1158 static std::string who = "fscanf"; |
1159 | |
2095 | 1160 octave_value_list retval; |
1181 | 1161 |
1162 int nargin = args.length (); | |
1163 | |
2215 | 1164 if (nargin == 3 && args(2).is_string ()) |
2095 | 1165 { |
4468 | 1166 octave_stream os = octave_stream_list::lookup (args(0), who); |
1181 | 1167 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1168 if (args(1).is_string ()) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1169 retval = os.oscanf (args(1), who); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1170 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1171 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
2095 | 1172 } |
1181 | 1173 else |
2215 | 1174 { |
13271
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1175 retval(2) = "unknown error"; |
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1176 retval(1) = 0.0; |
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1177 retval(0) = Matrix (); |
2215 | 1178 |
1179 if (nargin == 2 || nargin == 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1180 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1181 octave_stream os = octave_stream_list::lookup (args(0), who); |
2215 | 1182 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1183 if (args(1).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1184 { |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1185 octave_idx_type count = 0; |
2215 | 1186 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1187 Array<double> size = (nargin == 3) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1188 ? args(2).vector_value () |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1189 : Array<double> (dim_vector (1, 1), |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1190 lo_ieee_inf_value ()); |
2215 | 1191 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1192 octave_value tmp = os.scanf (args(1), size, count, who); |
2215 | 1193 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1194 retval(2) = os.error (); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1195 retval(1) = count; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1196 retval(0) = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1197 } |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1198 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1199 error ("%s: format must be a string", who.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1200 } |
2215 | 1201 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1202 print_usage (); |
2215 | 1203 } |
1181 | 1204 |
1205 return retval; | |
1206 } | |
1207 | |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1208 static std::string |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1209 get_sscanf_data (const octave_value& val) |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1210 { |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1211 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
|
1212 |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1213 if (val.is_string ()) |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1214 { |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1215 octave_value tmp = val.reshape (dim_vector (1, val.numel ())); |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1216 |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1217 retval = tmp.string_value (); |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1218 } |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1219 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1220 error ("sscanf: argument STRING must be a string"); |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1221 |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1222 return retval; |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1223 } |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1224 |
2095 | 1225 DEFUN (sscanf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1226 "-*- texinfo -*-\n\ |
13271
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1227 @deftypefn {Built-in Function} {[@var{val}, @var{count}, @var{errmsg}, @var{pos}] =} sscanf (@var{string}, @var{template}, @var{size})\n\ |
16099
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
1228 @deftypefnx {Built-in Function} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} sscanf (@var{string}, @var{template}, \"C\")\n\ |
3372 | 1229 This is like @code{fscanf}, except that the characters are taken from the\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1230 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:
20136
diff
changeset
|
1231 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1232 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:
20136
diff
changeset
|
1233 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:
20136
diff
changeset
|
1234 character to be read is returned in @var{pos}.\n\ |
5642 | 1235 @seealso{fscanf, scanf, sprintf}\n\ |
1236 @end deftypefn") | |
444 | 1237 { |
4468 | 1238 static std::string who = "sscanf"; |
1239 | |
2095 | 1240 octave_value_list retval; |
444 | 1241 |
506 | 1242 int nargin = args.length (); |
1243 | |
2215 | 1244 if (nargin == 3 && args(2).is_string ()) |
2095 | 1245 { |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1246 std::string data = get_sscanf_data (args(0)); |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1247 |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1248 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1249 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1250 octave_stream os = octave_istrstream::create (data); |
1358 | 1251 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1252 if (os.is_valid ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1253 { |
16099
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
1254 if (args(1).is_string ()) |
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
1255 retval = os.oscanf (args(1), who); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1256 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1257 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1258 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1259 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1260 error ("%s: unable to create temporary input buffer", who.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1261 } |
636 | 1262 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1263 error ("%s: argument STRING must be a string", who.c_str ()); |
444 | 1264 } |
1265 else | |
2215 | 1266 { |
1267 if (nargin == 2 || nargin == 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1268 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1269 retval(3) = -1.0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1270 retval(2) = "unknown error"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1271 retval(1) = 0.0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1272 retval(0) = Matrix (); |
2215 | 1273 |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1274 std::string data = get_sscanf_data (args(0)); |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1275 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1276 octave_stream os = octave_istrstream::create (data); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1277 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1278 if (os.is_valid ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1279 { |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1280 if (args(1).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1281 { |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1282 octave_idx_type count = 0; |
2215 | 1283 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1284 Array<double> size = (nargin == 3) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1285 ? args(2).vector_value () |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1286 : Array<double> (dim_vector (1, 1), |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1287 lo_ieee_inf_value ()); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1288 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1289 octave_value tmp = os.scanf (args(1), size, count, who); |
2215 | 1290 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1291 // FIXME: is this the right thing to do? |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1292 // Extract error message first, because getting |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1293 // position will clear it. |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1294 std::string errmsg = os.error (); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1295 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1296 retval(3) = (os.eof () ? data.length () : os.tell ()) + 1; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1297 retval(2) = errmsg; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1298 retval(1) = count; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1299 retval(0) = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1300 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1301 else |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1302 error ("%s: format TEMPLATE must be a string", |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1303 who.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1304 } |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1305 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1306 error ("%s: unable to create temporary input buffer", |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1307 who.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1308 } |
2215 | 1309 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1310 print_usage (); |
2215 | 1311 } |
444 | 1312 |
1313 return retval; | |
1314 } | |
1315 | |
2215 | 1316 DEFUN (scanf, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1317 "-*- texinfo -*-\n\ |
13271
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1318 @deftypefn {Built-in Function} {[@var{val}, @var{count}, @var{errmsg}] =} scanf (@var{template}, @var{size})\n\ |
16099
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
1319 @deftypefnx {Built-in Function} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}]] =} scanf (@var{template}, \"C\")\n\ |
3372 | 1320 This is equivalent to calling @code{fscanf} with @var{fid} = @code{stdin}.\n\ |
1321 \n\ | |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
1322 It is currently not useful to call @code{scanf} in interactive programs.\n\ |
5642 | 1323 @seealso{fscanf, sscanf, printf}\n\ |
1324 @end deftypefn") | |
2215 | 1325 { |
1326 int nargin = args.length (); | |
1327 | |
1328 octave_value_list tmp_args (nargin+1, octave_value ()); | |
1329 | |
1330 tmp_args (0) = 0.0; | |
1331 for (int i = 0; i < nargin; i++) | |
18111
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18078
diff
changeset
|
1332 tmp_args(i+1) = args(i); |
2215 | 1333 |
1334 return Ffscanf (tmp_args, nargout); | |
1335 } | |
1336 | |
2116 | 1337 static octave_value |
1338 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
|
1339 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
|
1340 const octave_value& arch_arg, octave_idx_type& count) |
2116 | 1341 { |
1342 octave_value retval; | |
1343 | |
1344 count = -1; | |
1345 | |
3810 | 1346 Array<double> size = size_arg.vector_value (); |
2116 | 1347 |
1348 if (! error_state) | |
1349 { | |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1350 if (prec_arg.is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1351 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1352 std::string prec = prec_arg.string_value (); |
2116 | 1353 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1354 int block_size = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1355 oct_data_conv::data_type input_type; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1356 oct_data_conv::data_type output_type; |
4944 | 1357 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1358 oct_data_conv::string_to_data_type (prec, block_size, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1359 input_type, output_type); |
2116 | 1360 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1361 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1362 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1363 int skip = skip_arg.int_value (true); |
2116 | 1364 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1365 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1366 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1367 if (arch_arg.is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1368 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1369 std::string arch = arch_arg.string_value (); |
3202 | 1370 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1371 oct_mach_info::float_format flt_fmt |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1372 = oct_mach_info::string_to_float_format (arch); |
2116 | 1373 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1374 retval = os.read (size, block_size, input_type, |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1375 output_type, skip, flt_fmt, count); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1376 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1377 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1378 error ("fread: ARCH architecture type must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1379 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1380 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1381 error ("fread: SKIP must be an integer"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1382 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1383 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1384 error ("fread: invalid PRECISION specified"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1385 } |
2116 | 1386 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1387 error ("fread: PRECISION must be a string"); |
2116 | 1388 } |
1389 else | |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1390 error ("fread: invalid SIZE specified"); |
2116 | 1391 |
1392 return retval; | |
1393 } | |
1394 | |
1395 DEFUN (fread, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1396 "-*- texinfo -*-\n\ |
18207
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1397 @deftypefn {Built-in Function} {@var{val} =} fread (@var{fid})\n\ |
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1398 @deftypefnx {Built-in Function} {@var{val} =} fread (@var{fid}, @var{size})\n\ |
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1399 @deftypefnx {Built-in Function} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision})\n\ |
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1400 @deftypefnx {Built-in Function} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip})\n\ |
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1401 @deftypefnx {Built-in Function} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip}, @var{arch})\n\ |
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1402 @deftypefnx {Built-in Function} {[@var{val}, @var{count}] =} fread (@dots{})\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1403 Read binary data from the file specified by the file descriptor @var{fid}.\n\ |
3372 | 1404 \n\ |
1405 The optional argument @var{size} specifies the amount of data to read\n\ | |
1406 and may be one of\n\ | |
1407 \n\ | |
1408 @table @code\n\ | |
1409 @item Inf\n\ | |
1410 Read as much as possible, returning a column vector.\n\ | |
529 | 1411 \n\ |
3372 | 1412 @item @var{nr}\n\ |
1413 Read up to @var{nr} elements, returning a column vector.\n\ | |
1414 \n\ | |
1415 @item [@var{nr}, Inf]\n\ | |
1416 Read as much as possible, returning a matrix with @var{nr} rows. If the\n\ | |
1417 number of elements read is not an exact multiple of @var{nr}, the last\n\ | |
1418 column is padded with zeros.\n\ | |
1419 \n\ | |
1420 @item [@var{nr}, @var{nc}]\n\ | |
1421 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with\n\ | |
1422 @var{nr} rows. If the number of elements read is not an exact multiple\n\ | |
1423 of @var{nr}, the last column is padded with zeros.\n\ | |
1424 @end table\n\ | |
1425 \n\ | |
1426 @noindent\n\ | |
1427 If @var{size} is omitted, a value of @code{Inf} is assumed.\n\ | |
2318 | 1428 \n\ |
3372 | 1429 The optional argument @var{precision} is a string specifying the type of\n\ |
1430 data to read and may be one of\n\ | |
1431 \n\ | |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1432 @table @asis\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1433 @item @qcode{\"schar\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1434 @itemx @qcode{\"signed char\"}\n\ |
3372 | 1435 Signed character.\n\ |
529 | 1436 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1437 @item @qcode{\"uchar\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1438 @itemx @qcode{\"unsigned char\"}\n\ |
3372 | 1439 Unsigned character.\n\ |
1440 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1441 @item @qcode{\"int8\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1442 @itemx @qcode{\"integer*1\"}\n\ |
4944 | 1443 \n\ |
1444 8-bit signed integer.\n\ | |
2318 | 1445 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1446 @item @qcode{\"int16\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1447 @itemx @qcode{\"integer*2\"}\n\ |
4944 | 1448 16-bit signed integer.\n\ |
3372 | 1449 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1450 @item @qcode{\"int32\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1451 @itemx @qcode{\"integer*4\"}\n\ |
4944 | 1452 32-bit signed integer.\n\ |
3372 | 1453 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1454 @item @qcode{\"int64\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1455 @itemx @qcode{\"integer*8\"}\n\ |
4944 | 1456 64-bit signed integer.\n\ |
1457 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1458 @item @qcode{\"uint8\"}\n\ |
4944 | 1459 8-bit unsigned integer.\n\ |
529 | 1460 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1461 @item @qcode{\"uint16\"}\n\ |
4944 | 1462 16-bit unsigned integer.\n\ |
3372 | 1463 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1464 @item @qcode{\"uint32\"}\n\ |
4944 | 1465 32-bit unsigned integer.\n\ |
3372 | 1466 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1467 @item @qcode{\"uint64\"}\n\ |
4944 | 1468 64-bit unsigned integer.\n\ |
1469 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1470 @item @qcode{\"single\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1471 @itemx @qcode{\"float32\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1472 @itemx @qcode{\"real*4\"}\n\ |
4944 | 1473 32-bit floating point number.\n\ |
3372 | 1474 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1475 @item @qcode{\"double\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1476 @itemx @qcode{\"float64\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1477 @itemx @qcode{\"real*8\"}\n\ |
4944 | 1478 64-bit floating point number.\n\ |
1479 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1480 @item @qcode{\"char\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1481 @itemx @qcode{\"char*1\"}\n\ |
4944 | 1482 Single character.\n\ |
3372 | 1483 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1484 @item @qcode{\"short\"}\n\ |
4944 | 1485 Short integer (size is platform dependent).\n\ |
1486 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1487 @item @qcode{\"int\"}\n\ |
4944 | 1488 Integer (size is platform dependent).\n\ |
1489 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1490 @item @qcode{\"long\"}\n\ |
4944 | 1491 Long integer (size is platform dependent).\n\ |
3372 | 1492 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1493 @item @qcode{\"ushort\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1494 @itemx @qcode{\"unsigned short\"}\n\ |
4944 | 1495 Unsigned short integer (size is platform dependent).\n\ |
4610 | 1496 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1497 @item @qcode{\"uint\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1498 @itemx @qcode{\"unsigned int\"}\n\ |
4944 | 1499 Unsigned integer (size is platform dependent).\n\ |
4610 | 1500 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1501 @item @qcode{\"ulong\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1502 @itemx @qcode{\"unsigned long\"}\n\ |
4944 | 1503 Unsigned long integer (size is platform dependent).\n\ |
1504 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1505 @item @qcode{\"float\"}\n\ |
4944 | 1506 Single precision floating point number (size is platform dependent).\n\ |
3372 | 1507 @end table\n\ |
1508 \n\ | |
1509 @noindent\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1510 The default precision is @qcode{\"uchar\"}.\n\ |
2318 | 1511 \n\ |
4944 | 1512 The @var{precision} argument may also specify an optional repeat\n\ |
1513 count. For example, @samp{32*single} causes @code{fread} to read\n\ | |
1514 a block of 32 single precision floating point numbers. Reading in\n\ | |
1515 blocks is useful in combination with the @var{skip} argument.\n\ | |
1516 \n\ | |
1517 The @var{precision} argument may also specify a type conversion.\n\ | |
1518 For example, @samp{int16=>int32} causes @code{fread} to read 16-bit\n\ | |
1519 integer values and return an array of 32-bit integer values. By\n\ | |
1520 default, @code{fread} returns a double precision array. The special\n\ | |
1521 form @samp{*TYPE} is shorthand for @samp{TYPE=>TYPE}.\n\ | |
1522 \n\ | |
7096 | 1523 The conversion and repeat counts may be combined. For example, the\n\ |
1524 specification @samp{32*single=>single} causes @code{fread} to read\n\ | |
1525 blocks of single precision floating point values and return an array\n\ | |
1526 of single precision values instead of the default array of double\n\ | |
1527 precision values.\n\ | |
4944 | 1528 \n\ |
3372 | 1529 The optional argument @var{skip} specifies the number of bytes to skip\n\ |
4944 | 1530 after each element (or block of elements) is read. If it is not\n\ |
1531 specified, a value of 0 is assumed. If the final block read is not\n\ | |
1532 complete, the final skip is omitted. For example,\n\ | |
1533 \n\ | |
1534 @example\n\ | |
1535 fread (f, 10, \"3*single=>single\", 8)\n\ | |
1536 @end example\n\ | |
1537 \n\ | |
1538 @noindent\n\ | |
1539 will omit the final 8-byte skip because the last read will not be\n\ | |
1540 a complete block of 3 values.\n\ | |
3372 | 1541 \n\ |
1542 The optional argument @var{arch} is a string specifying the data format\n\ | |
1543 for the file. Valid values are\n\ | |
529 | 1544 \n\ |
18078
b06a9768b643
doc: Don't use @table @qcode to avoid problems with Texinfo 5.2.
Rik <rik@octave.org>
parents:
18040
diff
changeset
|
1545 @table @asis\n\ |
20466
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20233
diff
changeset
|
1546 @item @qcode{\"native\"} or @qcode{\"n\"}\n\ |
3372 | 1547 The format of the current machine.\n\ |
1548 \n\ | |
20466
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20233
diff
changeset
|
1549 @item @qcode{\"ieee-be\"} or @qcode{\"b\"}\n\ |
3372 | 1550 IEEE big endian.\n\ |
1551 \n\ | |
20466
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20233
diff
changeset
|
1552 @item @qcode{\"ieee-le\"} or @qcode{\"l\"}\n\ |
3372 | 1553 IEEE little endian.\n\ |
1554 @end table\n\ | |
2318 | 1555 \n\ |
20474
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20466
diff
changeset
|
1556 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:
20466
diff
changeset
|
1557 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:
20466
diff
changeset
|
1558 @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:
20466
diff
changeset
|
1559 \n\ |
18207
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1560 The output argument @var{val} contains the data read from the file.\n\ |
20474
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20466
diff
changeset
|
1561 \n\ |
18207
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1562 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
|
1563 @seealso{fwrite, fgets, fgetl, fscanf, fopen}\n\ |
5642 | 1564 @end deftypefn") |
529 | 1565 { |
2095 | 1566 octave_value_list retval; |
2116 | 1567 |
1568 int nargin = args.length (); | |
1569 | |
2318 | 1570 if (nargin > 0 && nargin < 6) |
2116 | 1571 { |
1572 retval(1) = -1.0; | |
1573 retval(0) = Matrix (); | |
1574 | |
3341 | 1575 octave_stream os = octave_stream_list::lookup (args(0), "fread"); |
2116 | 1576 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1577 octave_value size = lo_ieee_inf_value (); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1578 octave_value prec = "uchar"; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1579 octave_value skip = 0; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1580 octave_value arch = "unknown"; |
2116 | 1581 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1582 int idx = 1; |
2116 | 1583 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1584 if (nargin > idx && ! args(idx).is_string ()) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1585 size = args(idx++); |
4257 | 1586 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1587 if (nargin > idx) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1588 prec = args(idx++); |
2116 | 1589 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1590 if (nargin > idx) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1591 skip = args(idx++); |
4257 | 1592 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1593 if (nargin > idx) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1594 arch = args(idx++); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1595 else if (skip.is_string ()) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1596 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1597 arch = skip; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1598 skip = 0; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1599 } |
2116 | 1600 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1601 octave_idx_type count = -1; |
2116 | 1602 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1603 octave_value tmp = do_fread (os, size, prec, skip, arch, count); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1604 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1605 retval(1) = count; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1606 retval(0) = tmp; |
2116 | 1607 } |
1608 else | |
5823 | 1609 print_usage (); |
2116 | 1610 |
529 | 1611 return retval; |
1612 } | |
1613 | |
2116 | 1614 static int |
1615 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
|
1616 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
|
1617 const octave_value& arch_arg) |
2116 | 1618 { |
1619 int retval = -1; | |
1620 | |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1621 if (prec_arg.is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1622 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1623 std::string prec = prec_arg.string_value (); |
2116 | 1624 |
4944 | 1625 int block_size = 1; |
1626 oct_data_conv::data_type output_type; | |
1627 | |
1628 oct_data_conv::string_to_data_type (prec, block_size, output_type); | |
2116 | 1629 |
1630 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1631 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1632 int skip = skip_arg.int_value (true); |
2116 | 1633 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1634 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1635 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1636 if (arch_arg.is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1637 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1638 std::string arch = arch_arg.string_value (); |
3202 | 1639 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1640 oct_mach_info::float_format flt_fmt |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1641 = oct_mach_info::string_to_float_format (arch); |
2116 | 1642 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1643 retval = os.write (data, block_size, output_type, |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1644 skip, flt_fmt); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1645 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1646 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1647 error ("fwrite: ARCH architecture type must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1648 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1649 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1650 error ("fwrite: SKIP must be an integer"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1651 } |
3202 | 1652 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1653 error ("fwrite: invalid PRECISION specified"); |
2116 | 1654 } |
1655 else | |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1656 error ("fwrite: PRECISION must be a string"); |
2116 | 1657 |
1658 return retval; | |
1659 } | |
1660 | |
1661 DEFUN (fwrite, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1662 "-*- texinfo -*-\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1663 @deftypefn {Built-in Function} {} fwrite (@var{fid}, @var{data})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1664 @deftypefnx {Built-in Function} {} fwrite (@var{fid}, @var{data}, @var{precision})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1665 @deftypefnx {Built-in Function} {} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1666 @deftypefnx {Built-in Function} {} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip}, @var{arch})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1667 @deftypefnx {Built-in Function} {@var{count} =} fwrite (@dots{})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1668 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:
19157
diff
changeset
|
1669 @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:
19157
diff
changeset
|
1670 to the file.\n\ |
1181 | 1671 \n\ |
3372 | 1672 The argument @var{data} is a matrix of values that are to be written to\n\ |
1673 the file. The values are extracted in column-major order.\n\ | |
1181 | 1674 \n\ |
3372 | 1675 The remaining arguments @var{precision}, @var{skip}, and @var{arch} are\n\ |
1676 optional, and are interpreted as described for @code{fread}.\n\ | |
1181 | 1677 \n\ |
3372 | 1678 The behavior of @code{fwrite} is undefined if the values in @var{data}\n\ |
1679 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
|
1680 @seealso{fread, fputs, fprintf, fopen}\n\ |
5642 | 1681 @end deftypefn") |
1181 | 1682 { |
4233 | 1683 octave_value retval = -1; |
2116 | 1684 |
1685 int nargin = args.length (); | |
1686 | |
1687 if (nargin > 1 && nargin < 6) | |
1688 { | |
3341 | 1689 octave_stream os = octave_stream_list::lookup (args(0), "fwrite"); |
2116 | 1690 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1691 octave_value prec = "uchar"; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1692 octave_value skip = 0; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1693 octave_value arch = "unknown"; |
2318 | 1694 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1695 int idx = 1; |
7708
b42abee70a98
fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents:
7650
diff
changeset
|
1696 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1697 octave_value data = args(idx++); |
7708
b42abee70a98
fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents:
7650
diff
changeset
|
1698 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1699 if (nargin > idx) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1700 prec = args(idx++); |
2318 | 1701 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1702 if (nargin > idx) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1703 skip = args(idx++); |
2318 | 1704 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1705 if (nargin > idx) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1706 arch = args(idx++); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1707 else if (skip.is_string ()) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1708 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1709 arch = skip; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1710 skip = 0; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1711 } |
2116 | 1712 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1713 double status = do_fwrite (os, data, prec, skip, arch); |
2825 | 1714 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1715 retval = status; |
2116 | 1716 } |
1717 else | |
5823 | 1718 print_usage (); |
2116 | 1719 |
1181 | 1720 return retval; |
1721 } | |
1722 | |
5906 | 1723 DEFUNX ("feof", Ffeof, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1724 "-*- texinfo -*-\n\ |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1725 @deftypefn {Built-in Function} {@var{status} =} feof (@var{fid})\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1726 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:
19157
diff
changeset
|
1727 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:
19157
diff
changeset
|
1728 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1729 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:
19157
diff
changeset
|
1730 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:
19157
diff
changeset
|
1731 end-of-file condition.\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
1732 @seealso{fread, frewind, fseek, fclear, fopen}\n\ |
5642 | 1733 @end deftypefn") |
529 | 1734 { |
4233 | 1735 octave_value retval = -1; |
529 | 1736 |
1737 int nargin = args.length (); | |
1738 | |
2095 | 1739 if (nargin == 1) |
1740 { | |
3341 | 1741 octave_stream os = octave_stream_list::lookup (args(0), "feof"); |
444 | 1742 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1743 retval = os.eof () ? 1.0 : 0.0; |
2095 | 1744 } |
529 | 1745 else |
5823 | 1746 print_usage (); |
444 | 1747 |
1748 return retval; | |
1749 } | |
1750 | |
5906 | 1751 DEFUNX ("ferror", Fferror, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1752 "-*- texinfo -*-\n\ |
19184 | 1753 @deftypefn {Built-in Function} {@var{msg} =} ferror (@var{fid})\n\ |
1754 @deftypefnx {Built-in Function} {[@var{msg}, @var{err}] =} ferror (@var{fid})\n\ | |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1755 @deftypefnx {Built-in Function} {[@var{dots}] =} ferror (@var{fid}, \"clear\")\n\ |
19184 | 1756 Query the error status of the stream specified by file descriptor @var{fid}\n\ |
1757 \n\ | |
1758 If an error condition exists then return a string @var{msg} describing the\n\ | |
1759 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
|
1760 \n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1761 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:
20136
diff
changeset
|
1762 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:
20136
diff
changeset
|
1763 \n\ |
19184 | 1764 The optional second output is a numeric indication of the error status.\n\ |
1765 @var{err} is 1 if an error condition has been encountered and 0 otherwise.\n\ | |
19161
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19157
diff
changeset
|
1766 \n\ |
19184 | 1767 Note that @code{ferror} indicates if an error has already occurred, not\n\ |
1768 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
|
1769 @seealso{fclear, fopen}\n\ |
3372 | 1770 @end deftypefn") |
1230 | 1771 { |
2095 | 1772 octave_value_list retval; |
1230 | 1773 |
2095 | 1774 int nargin = args.length (); |
1230 | 1775 |
2095 | 1776 if (nargin == 1 || nargin == 2) |
1777 { | |
3341 | 1778 octave_stream os = octave_stream_list::lookup (args(0), "ferror"); |
1230 | 1779 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1780 bool clear = false; |
1230 | 1781 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1782 if (nargin == 2) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1783 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1784 std::string opt = args(1).string_value (); |
2095 | 1785 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1786 clear = (opt == "clear"); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1787 } |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1788 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1789 int error_number = 0; |
1755 | 1790 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1791 std::string error_message = os.error (clear, error_number); |
1230 | 1792 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1793 retval(1) = error_number; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
1794 retval(0) = error_message; |
1230 | 1795 } |
2095 | 1796 else |
5823 | 1797 print_usage (); |
1230 | 1798 |
1799 return retval; | |
1800 } | |
1801 | |
18477
aa7ca90ce746
avoid problems if popen is a macro
John W. Eaton <jwe@octave.org>
parents:
18040
diff
changeset
|
1802 DEFUNX ("popen", Fpopen, args, , |
19895
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19761
diff
changeset
|
1803 "-*- texinfo -*-\n\ |
4326 | 1804 @deftypefn {Built-in Function} {@var{fid} =} popen (@var{command}, @var{mode})\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1805 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:
20136
diff
changeset
|
1806 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1807 The name of the command to run is given by @var{command}. The argument\n\ |
3301 | 1808 @var{mode} may be\n\ |
1809 \n\ | |
1810 @table @code\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1811 @item @qcode{\"r\"}\n\ |
3301 | 1812 The pipe will be connected to the standard output of the process, and\n\ |
1813 open for reading.\n\ | |
1230 | 1814 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1815 @item @qcode{\"w\"}\n\ |
3301 | 1816 The pipe will be connected to the standard input of the process, and\n\ |
1817 open for writing.\n\ | |
1818 @end table\n\ | |
1819 \n\ | |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1820 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:
20136
diff
changeset
|
1821 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:
20136
diff
changeset
|
1822 \n\ |
10840 | 1823 For example:\n\ |
1230 | 1824 \n\ |
3301 | 1825 @example\n\ |
1826 @group\n\ | |
1827 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
|
1828 while (ischar (s = fgets (fid)))\n\ |
3301 | 1829 fputs (stdout, s);\n\ |
1830 endwhile\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
1831 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
1832 @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
|
1833 @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
|
1834 @print{} drwxrwxrwt 15 root root 2048 Feb 17 14:53 tmp\n\ |
3301 | 1835 @end group\n\ |
1836 @end example\n\ | |
18984
ed3cb9f81145
file-io.cc (popen): Add seealso popen2
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18487
diff
changeset
|
1837 @seealso{popen2}\n\ |
3301 | 1838 @end deftypefn") |
1230 | 1839 { |
4233 | 1840 octave_value retval = -1; |
1230 | 1841 |
1842 int nargin = args.length (); | |
1843 | |
2095 | 1844 if (nargin == 2) |
1845 { | |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1846 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1847 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1848 std::string name = args(0).string_value (); |
1230 | 1849 |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1850 if (args(1).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1851 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1852 std::string mode = args(1).string_value (); |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1853 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1854 if (mode == "r") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1855 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1856 octave_stream ips = octave_iprocstream::create (name); |
1230 | 1857 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1858 retval = octave_stream_list::insert (ips); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1859 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1860 else if (mode == "w") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1861 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1862 octave_stream ops = octave_oprocstream::create (name); |
1230 | 1863 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1864 retval = octave_stream_list::insert (ops); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1865 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1866 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1867 error ("popen: invalid MODE specified"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1868 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1869 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1870 error ("popen: MODE must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1871 } |
2095 | 1872 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1873 error ("popen: COMMAND must be a string"); |
2095 | 1874 } |
1230 | 1875 else |
5823 | 1876 print_usage (); |
1230 | 1877 |
1878 return retval; | |
1879 } | |
1880 | |
16308
122c1a7a3004
avoid trouble if pclose is a macro
John W. Eaton <jwe@octave.org>
parents:
16099
diff
changeset
|
1881 DEFUNX ("pclose", Fpclose, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1882 "-*- texinfo -*-\n\ |
3301 | 1883 @deftypefn {Built-in Function} {} pclose (@var{fid})\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
1884 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:
19064
diff
changeset
|
1885 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
1886 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:
19064
diff
changeset
|
1887 @seealso{fclose, popen}\n\ |
3301 | 1888 @end deftypefn") |
1230 | 1889 { |
4233 | 1890 octave_value retval = -1; |
1230 | 1891 |
1892 int nargin = args.length (); | |
1893 | |
2095 | 1894 if (nargin == 1) |
4233 | 1895 retval = octave_stream_list::remove (args(0), "pclose"); |
1377 | 1896 else |
5823 | 1897 print_usage (); |
1379 | 1898 |
1899 return retval; | |
1900 } | |
1901 | |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
1902 DEFUN (tempname, args, , |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
1903 "-*- texinfo -*-\n\ |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
1904 @deftypefn {Built-in Function} {@var{fname} =} tempname ()\n\ |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
1905 @deftypefnx {Built-in Function} {@var{fname} =} tempname (@var{dir})\n\ |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
1906 @deftypefnx {Built-in Function} {@var{fname} =} tempname (@var{dir}, @var{prefix})\n\ |
3372 | 1907 Return a unique temporary file name as a string.\n\ |
1908 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1909 If @var{prefix} is omitted, a value of @qcode{\"oct-\"} is used.\n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
1910 \n\ |
4267 | 1911 If @var{dir} is also omitted, the default directory for temporary files\n\ |
19419
3b4d6780d6b8
doc: Add missing closing parenthesis in tempname docstring.
Rik <rik@octave.org>
parents:
19312
diff
changeset
|
1912 (@code{P_tmpdir}) is used. If @var{dir} is provided, it must exist,\n\ |
19244
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
1913 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:
19184
diff
changeset
|
1914 \n\ |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
1915 Programming Note: Because the named file is not opened by @code{tempname},\n\ |
19244
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
1916 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:
19184
diff
changeset
|
1917 by the time your program attempts to open it. If this is a concern,\n\ |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
1918 see @code{tmpfile}.\n\ |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
1919 @seealso{mkstemp, tempdir, P_tmpdir, tmpfile}\n\ |
5642 | 1920 @end deftypefn") |
1802 | 1921 { |
2095 | 1922 octave_value retval; |
1802 | 1923 |
2936 | 1924 int len = args.length (); |
1925 | |
1926 if (len < 3) | |
1927 { | |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1928 std::string dir; |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1929 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1930 { |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1931 if (args(0).is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1932 dir = args(0).string_value (); |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1933 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1934 error ("DIR must be a string"); |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1935 } |
4267 | 1936 |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1937 std::string pfx ("oct-"); |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1938 if (len > 1) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1939 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1940 if (args(1).is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1941 pfx = args(1).string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1942 else |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
1943 error ("PREFIX must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1944 } |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1945 |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
1946 retval = octave_tempnam (dir, pfx); |
2936 | 1947 } |
1802 | 1948 else |
5823 | 1949 print_usage (); |
1802 | 1950 |
1951 return retval; | |
1952 } | |
1953 | |
19454
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1954 /* |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1955 %!test |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1956 %! if (ispc ()) |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1957 %! envname = "TMP"; |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1958 %! else |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1959 %! envname = "TMPDIR"; |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1960 %! endif |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1961 %! envdir = getenv (envname); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1962 %! unsetenv (envname); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1963 %! unwind_protect |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1964 %! ## Test 0-argument form |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1965 %! fname = tempname (); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19454
diff
changeset
|
1966 %! [tmpdir, tmpfname] = fileparts (fname); |
19454
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1967 %! assert (tmpdir, P_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1968 %! assert (tmpfname (1:4), "oct-"); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19454
diff
changeset
|
1969 %! ## Test 1-argument form |
19454
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1970 %! tmp_tmpdir = [P_tmpdir filesep() substr(tmpfname, -5)]; |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1971 %! mkdir (tmp_tmpdir) || error ("Unable to create tmp dir"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1972 %! setenv (envname, P_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1973 %! fname = tempname (tmp_tmpdir); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19454
diff
changeset
|
1974 %! [tmpdir, tmpfname] = fileparts (fname); |
19454
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1975 %! assert (tmpdir, tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1976 %! assert (tmpfname (1:4), "oct-"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1977 %! ## 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:
19437
diff
changeset
|
1978 %! fname = tempname (""); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19454
diff
changeset
|
1979 %! [tmpdir, tmpfname] = fileparts (fname); |
19454
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1980 %! assert (tmpdir, P_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1981 %! assert (tmpfname (1:4), "oct-"); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19454
diff
changeset
|
1982 %! ## Test 2-argument form |
19454
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1983 %! fname = tempname (tmp_tmpdir, "pfx-"); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19454
diff
changeset
|
1984 %! [tmpdir, tmpfname] = fileparts (fname); |
19454
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1985 %! assert (tmpdir, tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1986 %! assert (tmpfname (1:4), "pfx-"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1987 %! ## 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:
19437
diff
changeset
|
1988 %! fname = tempname (tmp_tmpdir, ""); |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19454
diff
changeset
|
1989 %! [tmpdir, tmpfname] = fileparts (fname); |
19454
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1990 %! assert (tmpdir, tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1991 %! assert (tmpfname (1:4), "file"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1992 %! unwind_protect_cleanup |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1993 %! rmdir (tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1994 %! if (isempty (envdir)) |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1995 %! unsetenv (envname); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1996 %! else |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1997 %! setenv (envname, envdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1998 %! endif |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
1999 %! end_unwind_protect |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
2000 */ |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19437
diff
changeset
|
2001 |
4326 | 2002 DEFUN (tmpfile, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2003 "-*- texinfo -*-\n\ |
4326 | 2004 @deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} tmpfile ()\n\ |
2005 Return the file ID corresponding to a new temporary file with a unique\n\ | |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2006 name.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2007 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2008 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:
19064
diff
changeset
|
2009 deleted automatically when it is closed or when Octave exits.\n\ |
4326 | 2010 \n\ |
2011 If successful, @var{fid} is a valid file ID and @var{msg} is an empty\n\ | |
2012 string. Otherwise, @var{fid} is -1 and @var{msg} contains a\n\ | |
2013 system-dependent error message.\n\ | |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
2014 @seealso{tempname, mkstemp, tempdir, P_tmpdir}\n\ |
5642 | 2015 @end deftypefn") |
4326 | 2016 { |
2017 octave_value_list retval; | |
2018 | |
2019 retval(1) = std::string (); | |
2020 retval(0) = -1; | |
2021 | |
2022 int nargin = args.length (); | |
2023 | |
2024 if (nargin == 0) | |
2025 { | |
12775 | 2026 FILE *fid = gnulib::tmpfile (); |
4326 | 2027 |
2028 if (fid) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2029 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2030 std::string nm; |
4326 | 2031 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2032 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); |
4326 | 2033 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2034 octave_stream s = octave_stdiostream::create (nm, fid, md); |
4326 | 2035 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2036 if (s) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2037 retval(0) = octave_stream_list::insert (s); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2038 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2039 error ("tmpfile: failed to create octave_stdiostream object"); |
4326 | 2040 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2041 } |
4326 | 2042 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2043 { |
10411 | 2044 retval(1) = gnulib::strerror (errno); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2045 retval(0) = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2046 } |
4326 | 2047 } |
2048 else | |
5823 | 2049 print_usage (); |
4326 | 2050 |
2051 return retval; | |
2052 } | |
2053 | |
2054 DEFUN (mkstemp, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2055 "-*- texinfo -*-\n\ |
19244
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
2056 @deftypefn {Built-in Function} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (\"@var{template}\")\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
2057 @deftypefnx {Built-in Function} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (\"@var{template}\", @var{delete})\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
2058 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:
19184
diff
changeset
|
2059 with a unique name created from @var{template}.\n\ |
4326 | 2060 \n\ |
19244
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
2061 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:
19184
diff
changeset
|
2062 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:
19184
diff
changeset
|
2063 is then created with mode read/write and permissions that are system\n\ |
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
2064 dependent (on GNU/Linux systems, the permissions will be 0600 for versions of\n\ |
19264
cfa9996afcbf
doc: fix stray escape sequence in mkstemp's docstring
Mike Miller <mtmiller@ieee.org>
parents:
19244
diff
changeset
|
2065 glibc 2.0.7 and later). The file is opened in binary mode and with the\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2066 @w{@code{O_EXCL}} flag.\n\ |
4326 | 2067 \n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2068 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:
19064
diff
changeset
|
2069 be deleted automatically when Octave exits.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2070 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2071 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:
19064
diff
changeset
|
2072 file, and @var{msg} is an empty string. Otherwise, @var{fid} is -1,\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2073 @var{name} is empty, and @var{msg} contains a system-dependent error message.\n\ |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
2074 @seealso{tempname, tempdir, P_tmpdir, tmpfile, fopen}\n\ |
5642 | 2075 @end deftypefn") |
4326 | 2076 { |
2077 octave_value_list retval; | |
2078 | |
2079 retval(2) = std::string (); | |
2080 retval(1) = std::string (); | |
2081 retval(0) = -1; | |
2082 | |
2083 int nargin = args.length (); | |
2084 | |
2085 if (nargin == 1 || nargin == 2) | |
2086 { | |
19437
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
2087 if (args(0).is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
2088 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19419
diff
changeset
|
2089 std::string tmpl8 = args(0).string_value (); |
4326 | 2090 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2091 OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2092 strcpy (tmp, tmpl8.c_str ()); |
4326 | 2093 |
13958
cb15c5185b6a
mkstemp: open file in binary mode (bug #33669)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
2094 int fd = gnulib::mkostemp (tmp, O_BINARY); |
4326 | 2095 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2096 if (fd < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2097 { |
10411 | 2098 retval(2) = gnulib::strerror (errno); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2099 retval(0) = fd; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2100 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2101 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2102 { |
13958
cb15c5185b6a
mkstemp: open file in binary mode (bug #33669)
John W. Eaton <jwe@octave.org>
parents:
13929
diff
changeset
|
2103 const char *fopen_mode = "w+b"; |
4326 | 2104 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2105 FILE *fid = fdopen (fd, fopen_mode); |
4326 | 2106 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2107 if (fid) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2108 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2109 std::string nm = tmp; |
4326 | 2110 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2111 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); |
4326 | 2112 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2113 octave_stream s = octave_stdiostream::create (nm, fid, md); |
4326 | 2114 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2115 if (s) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2116 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2117 retval(1) = nm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2118 retval(0) = octave_stream_list::insert (s); |
4326 | 2119 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2120 if (nargin == 2 && args(1).is_true ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2121 mark_for_deletion (nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2122 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2123 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2124 error ("mkstemp: failed to create octave_stdiostream object"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2125 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2126 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2127 { |
10411 | 2128 retval(2) = gnulib::strerror (errno); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2129 retval(0) = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2130 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2131 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2132 } |
4326 | 2133 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12228
diff
changeset
|
2134 error ("mkstemp: TEMPLATE argument must be a string"); |
4326 | 2135 } |
2136 else | |
5823 | 2137 print_usage (); |
4326 | 2138 |
2139 return retval; | |
2140 } | |
2141 | |
20235
d9f35ceff9e1
Change mkfifo to use an octal argument for MODE (bug #45054).
Rik <rik@octave.org>
parents:
20233
diff
changeset
|
2142 // 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:
20233
diff
changeset
|
2143 // Maybe change to be a general utility routine. |
1400 | 2144 static int |
2145 convert (int x, int ibase, int obase) | |
2146 { | |
2147 int retval = 0; | |
2148 | |
2149 int tmp = x % obase; | |
2150 | |
2151 if (tmp > ibase - 1) | |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
2152 error ("umask: invalid digit"); |
1400 | 2153 else |
2154 { | |
2155 retval = tmp; | |
2156 int mult = ibase; | |
2157 while ((x = (x - tmp) / obase)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2158 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2159 tmp = x % obase; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2160 if (tmp > ibase - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2161 { |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
2162 error ("umask: invalid digit"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2163 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2164 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2165 retval += mult * tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2166 mult *= ibase; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2167 } |
1400 | 2168 } |
2169 | |
2170 return retval; | |
2171 } | |
2172 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2173 DEFUNX ("umask", Fumask, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2174 "-*- texinfo -*-\n\ |
3301 | 2175 @deftypefn {Built-in Function} {} umask (@var{mask})\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2176 Set the permission mask for file creation.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2177 \n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
2178 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:
20136
diff
changeset
|
2179 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20136
diff
changeset
|
2180 If successful, returns the previous value of the mask (as an integer to be\n\ |
4715 | 2181 interpreted as an octal number); otherwise an error message is printed.\n\ |
20233
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20207
diff
changeset
|
2182 \n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20207
diff
changeset
|
2183 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:
20207
diff
changeset
|
2184 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:
20207
diff
changeset
|
2185 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:
20207
diff
changeset
|
2186 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:
20207
diff
changeset
|
2187 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:
20207
diff
changeset
|
2188 @seealso{fopen, mkdir, mkfifo}\n\ |
3301 | 2189 @end deftypefn") |
1400 | 2190 { |
2095 | 2191 octave_value_list retval; |
1400 | 2192 |
2193 int status = 0; | |
2194 | |
2195 if (args.length () == 1) | |
2196 { | |
3202 | 2197 int mask = args(0).int_value (true); |
1400 | 2198 |
3202 | 2199 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2201 if (mask < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2202 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2203 status = -1; |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
2204 error ("umask: MASK must be a positive integer value"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2205 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2206 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2207 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2208 int oct_mask = convert (mask, 8, 10); |
1400 | 2209 |
20593
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20492
diff
changeset
|
2210 status = convert (octave_umask (oct_mask), 10, 8); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2211 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2212 } |
3202 | 2213 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2214 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2215 status = -1; |
20463
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20235
diff
changeset
|
2216 error ("umask: MASK must be an integer"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
2217 } |
1400 | 2218 } |
2219 else | |
5823 | 2220 print_usage (); |
1400 | 2221 |
2222 if (status >= 0) | |
4233 | 2223 retval(0) = status; |
1400 | 2224 |
2225 return retval; | |
2226 } | |
2227 | |
5749 | 2228 static octave_value |
6483 | 2229 const_value (const char *, const octave_value_list& args, int val) |
2189 | 2230 { |
5749 | 2231 octave_value retval; |
2232 | |
2233 int nargin = args.length (); | |
2234 | |
2235 if (nargin == 0) | |
2236 retval = val; | |
2237 else | |
5823 | 2238 print_usage (); |
5749 | 2239 |
2240 return retval; | |
2241 } | |
2242 | |
2243 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
|
2244 "-*- texinfo -*-\n\ |
5749 | 2245 @deftypefn {Built-in Function} {} P_tmpdir ()\n\ |
19244
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
2246 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:
19184
diff
changeset
|
2247 temporary files.\n\ |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2248 \n\ |
19244
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
2249 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:
19184
diff
changeset
|
2250 default location. This value may not agree with that returned from\n\ |
20132
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20076
diff
changeset
|
2251 @code{tempdir} if the user has overridden the default with the @env{TMPDIR}\n\ |
19244
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19184
diff
changeset
|
2252 environment variable.\n\ |
19312
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19302
diff
changeset
|
2253 @seealso{tempdir, tempname, mkstemp, tmpfile}\n\ |
5749 | 2254 @end deftypefn") |
2255 { | |
2256 octave_value retval; | |
2257 | |
2258 int nargin = args.length (); | |
4267 | 2259 |
5749 | 2260 if (nargin == 0) |
12228
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
12211
diff
changeset
|
2261 retval = get_P_tmpdir (); |
5749 | 2262 else |
5823 | 2263 print_usage (); |
5749 | 2264 |
2265 return retval; | |
2266 } | |
2341 | 2267 |
5749 | 2268 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be |
2269 // this way for Matlab compatibility. | |
2270 | |
2271 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
|
2272 "-*- texinfo -*-\n\ |
10840 | 2273 @deftypefn {Built-in Function} {} SEEK_SET ()\n\ |
5749 | 2274 @deftypefnx {Built-in Function} {} SEEK_CUR ()\n\ |
2275 @deftypefnx {Built-in Function} {} SEEK_END ()\n\ | |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2276 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:
19064
diff
changeset
|
2277 following actions:\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14365
diff
changeset
|
2278 \n\ |
3372 | 2279 @table @code\n\ |
2280 @item SEEK_SET\n\ | |
2281 Position file relative to the beginning.\n\ | |
2282 \n\ | |
2283 @item SEEK_CUR\n\ | |
2284 Position file relative to the current position.\n\ | |
2285 \n\ | |
2286 @item SEEK_END\n\ | |
5749 | 2287 Position file relative to the end.\n\ |
3372 | 2288 @end table\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2289 @seealso{fseek}\n\ |
5749 | 2290 @end deftypefn") |
2291 { | |
2292 return const_value ("SEEK_SET", args, -1); | |
2293 } | |
2189 | 2294 |
5749 | 2295 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
|
2296 "-*- texinfo -*-\n\ |
5749 | 2297 @deftypefn {Built-in Function} {} SEEK_CUR ()\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2298 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
|
2299 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
|
2300 @seealso{SEEK_SET, SEEK_END}\n\ |
5749 | 2301 @end deftypefn") |
2302 { | |
2303 return const_value ("SEEK_CUR", args, 0); | |
2304 } | |
2189 | 2305 |
5749 | 2306 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
|
2307 "-*- texinfo -*-\n\ |
5749 | 2308 @deftypefn {Built-in Function} {} SEEK_END ()\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2309 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
|
2310 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
|
2311 @seealso{SEEK_SET, SEEK_CUR}\n\ |
5749 | 2312 @end deftypefn") |
2313 { | |
2314 return const_value ("SEEK_END", args, 1); | |
2315 } | |
2316 | |
2317 static octave_value | |
6483 | 2318 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
|
2319 const octave_value& val) |
5749 | 2320 { |
2321 octave_value retval; | |
2322 | |
2323 int nargin = args.length (); | |
2189 | 2324 |
5749 | 2325 if (nargin == 0) |
2326 retval = val; | |
2327 else | |
5823 | 2328 print_usage (); |
5749 | 2329 |
2330 return retval; | |
2331 } | |
2332 | |
2333 DEFUNX ("stdin", Fstdin, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2334 "-*- texinfo -*-\n\ |
5749 | 2335 @deftypefn {Built-in Function} {} stdin ()\n\ |
2336 Return the numeric value corresponding to the standard input stream.\n\ | |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2337 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2338 When Octave is used interactively, stdin is filtered through the command\n\ |
5749 | 2339 line editing functions.\n\ |
5333 | 2340 @seealso{stdout, stderr}\n\ |
5749 | 2341 @end deftypefn") |
2342 { | |
2343 return const_value ("stdin", args, stdin_file); | |
2344 } | |
2189 | 2345 |
5749 | 2346 DEFUNX ("stdout", Fstdout, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2347 "-*- texinfo -*-\n\ |
5749 | 2348 @deftypefn {Built-in Function} {} stdout ()\n\ |
2349 Return the numeric value corresponding to the standard output stream.\n\ | |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2350 \n\ |
5749 | 2351 Data written to the standard output is normally filtered through the pager.\n\ |
5333 | 2352 @seealso{stdin, stderr}\n\ |
5749 | 2353 @end deftypefn") |
2354 { | |
2355 return const_value ("stdout", args, stdout_file); | |
2356 } | |
2189 | 2357 |
5749 | 2358 DEFUNX ("stderr", Fstderr, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2359 "-*- texinfo -*-\n\ |
5749 | 2360 @deftypefn {Built-in Function} {} stderr ()\n\ |
2361 Return the numeric value corresponding to the standard error stream.\n\ | |
19143
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2362 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19064
diff
changeset
|
2363 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:
19064
diff
changeset
|
2364 It is useful for error messages and prompts.\n\ |
5333 | 2365 @seealso{stdin, stdout}\n\ |
5749 | 2366 @end deftypefn") |
2367 { | |
2368 return const_value ("stderr", args, stderr_file); | |
2189 | 2369 } |