Mercurial > hg > octave-jordi
annotate libinterp/corefcn/file-io.cc @ 21052:b702efa70fb5 draft default tip shane
Adding --json-sock option; publishes octave_link events to a UNIX socket.
author | Shane F. Carr <shane.carr@wustl.edu> |
---|---|
date | Mon, 04 Jan 2016 08:51:31 +0000 |
parents | 3aa293be0e8d |
children |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19696
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19596
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" |
20939
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20917
diff
changeset
|
70 #include "ovl.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 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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:
20456
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 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
188 size_t bpos = mode.find ('b'); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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:
20456
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 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
201 if (mode == "rt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
202 retval = std::ios::in; |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
203 else if (mode == "wt") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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:
20456
diff
changeset
|
205 else if (mode == "at") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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:
20456
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:
20456
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:
20456
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:
20456
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:
20456
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:
20456
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:
20456
diff
changeset
|
213 else if (mode == "rb" || mode == "r") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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:
20456
diff
changeset
|
215 else if (mode == "wb" || mode == "w") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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:
20456
diff
changeset
|
217 else if (mode == "ab" || mode == "a") |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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:
20456
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:
20456
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:
20456
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:
20456
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:
20456
diff
changeset
|
223 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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:
20456
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:
20456
diff
changeset
|
226 | std::ios::binary); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
227 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
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\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
235 @deftypefn {} {} fclose (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
236 @deftypefnx {} {} fclose (\"all\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
237 @deftypefnx {} {@var{status} =} fclose (\"all\")\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
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:
19029
diff
changeset
|
239 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
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:
19029
diff
changeset
|
241 second form of the @code{fclose} call closes all open files except\n\ |
20763
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20755
diff
changeset
|
242 @code{stdin}, @code{stdout}, @code{stderr}, and any FIDs associated\n\ |
0ad449bc8848
Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents:
20755
diff
changeset
|
243 with gnuplot.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
244 @seealso{fopen, fflush, freport}\n\ |
5642 | 245 @end deftypefn") |
529 | 246 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
247 if (args.length () != 1) |
5823 | 248 print_usage (); |
1 | 249 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
250 return octave_value (octave_stream_list::remove (args(0), "fclose")); |
1 | 251 } |
252 | |
5144 | 253 DEFUN (fclear, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
254 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
255 @deftypefn {} {} fclear (@var{fid})\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
256 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:
19029
diff
changeset
|
257 @var{fid}.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
258 @seealso{ferror, fopen}\n\ |
5144 | 259 @end deftypefn") |
260 { | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
261 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
262 print_usage (); |
5144 | 263 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
264 int fid = octave_stream_list::get_file_number (args(0)); |
5144 | 265 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
266 octave_stream os = octave_stream_list::lookup (fid, "fclear"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
267 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
268 os.clearerr (); |
5144 | 269 |
20940
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
270 return ovl (); |
5144 | 271 } |
272 | |
1957 | 273 DEFUN (fflush, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
274 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
275 @deftypefn {} {} fflush (@var{fid})\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
276 Flush output to file descriptor @var{fid}.\n\ |
5095 | 277 \n\ |
278 @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
|
279 (@minus{}1 on Unix) on error.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
280 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
281 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:
19029
diff
changeset
|
282 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:
19029
diff
changeset
|
283 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:
19029
diff
changeset
|
284 @code{input}.\n\ |
5642 | 285 @seealso{fopen, fclose}\n\ |
286 @end deftypefn") | |
1181 | 287 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
288 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
289 print_usage (); |
1181 | 290 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
291 octave_value retval = -1; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
292 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
293 // FIXME: any way to avoid special case for stdout? |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
294 int fid = octave_stream_list::get_file_number (args(0)); |
2095 | 295 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
296 if (fid == 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
297 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
298 flush_octave_stdout (); |
2609 | 299 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
300 retval = 0; |
2095 | 301 } |
302 else | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
303 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
304 octave_stream os = octave_stream_list::lookup (fid, "fflush"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
305 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
306 retval = os.flush (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
307 } |
1181 | 308 |
309 return retval; | |
310 } | |
311 | |
2095 | 312 DEFUN (fgetl, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
313 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
314 @deftypefn {} {@var{str} =} fgetl (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
315 @deftypefnx {} {@var{str} =} fgetl (@var{fid}, @var{len})\n\ |
3372 | 316 Read characters from a file, stopping after a newline, or EOF,\n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
317 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:
20100
diff
changeset
|
318 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
319 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:
20100
diff
changeset
|
320 as a string.\n\ |
1339 | 321 \n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
322 If @var{len} is omitted, @code{fgetl} reads until the next newline character.\n\ |
3372 | 323 \n\ |
324 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
|
325 \n\ |
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
326 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
|
327 @seealso{fgets, fscanf, fread, fopen}\n\ |
5642 | 328 @end deftypefn") |
1339 | 329 { |
4468 | 330 static std::string who = "fgetl"; |
331 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
332 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
333 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
334 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
335 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
336 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
337 octave_stream os = octave_stream_list::lookup (args(0), who); |
1339 | 338 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
339 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); |
2095 | 340 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
341 bool err = false; |
2095 | 342 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
343 std::string tmp = os.getl (len_arg, err, who); |
2095 | 344 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
345 if (! err) |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
346 return ovl (tmp, tmp.length ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
347 else |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
348 return ovl (-1, 0); |
1339 | 349 } |
350 | |
2095 | 351 DEFUN (fgets, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
352 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
353 @deftypefn {} {@var{str} =} fgets (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
354 @deftypefnx {} {@var{str} =} fgets (@var{fid}, @var{len})\n\ |
3372 | 355 Read characters from a file, stopping after a newline, or EOF,\n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
356 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:
20100
diff
changeset
|
357 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
358 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:
20100
diff
changeset
|
359 as a string.\n\ |
529 | 360 \n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
361 If @var{len} is omitted, @code{fgets} reads until the next newline character.\n\ |
3372 | 362 \n\ |
363 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
|
364 \n\ |
f312918f16d2
doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
365 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
|
366 @seealso{fputs, fgetl, fscanf, fread, fopen}\n\ |
5642 | 367 @end deftypefn") |
529 | 368 { |
4468 | 369 static std::string who = "fgets"; |
370 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
371 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
372 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
373 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
374 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
375 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
376 octave_stream os = octave_stream_list::lookup (args(0), who); |
529 | 377 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
378 octave_value len_arg = (nargin == 2) ? args(1) : octave_value (); |
2095 | 379 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
380 bool err = false; |
2095 | 381 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
382 std::string tmp = os.gets (len_arg, err, who); |
2095 | 383 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
384 if (! err) |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
385 return ovl (tmp, tmp.length ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
386 else |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
387 return ovl (-1.0, 0.0); |
529 | 388 } |
389 | |
9701 | 390 DEFUN (fskipl, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
391 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
392 @deftypefn {} {@var{nlines} =} fskipl (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
393 @deftypefnx {} {@var{nlines} =} fskipl (@var{fid}, @var{count})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
394 @deftypefnx {} {@var{nlines} =} fskipl (@var{fid}, Inf)\n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
395 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:
19122
diff
changeset
|
396 descriptor @var{fid}.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
397 \n\ |
14436
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
398 @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
|
399 @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
|
400 \n\ |
12097d20a23e
doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents:
14435
diff
changeset
|
401 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
|
402 @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
|
403 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
|
404 \n\ |
9701 | 405 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
|
406 @seealso{fgetl, fgets, fscanf, fopen}\n\ |
9701 | 407 @end deftypefn") |
408 { | |
409 static std::string who = "fskipl"; | |
410 | |
411 int nargin = args.length (); | |
412 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
413 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
414 print_usage (); |
9701 | 415 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
416 octave_stream os = octave_stream_list::lookup (args(0), who); |
9701 | 417 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
418 octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); |
9701 | 419 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
420 bool err = false; |
9701 | 421 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
422 off_t tmp = os.skipl (count_arg, err, who); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
423 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
424 if (! err) |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
425 return ovl (tmp); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
426 else |
20940
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
427 return ovl (); |
9701 | 428 } |
429 | |
430 | |
3340 | 431 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
|
432 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
|
433 const std::string& arch, int& fid) |
1 | 434 { |
3340 | 435 octave_stream retval; |
1 | 436 |
2095 | 437 fid = -1; |
1 | 438 |
16590
2d968b7830d6
handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents:
16308
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 |
4036 | 443 std::ios::openmode md = fopen_mode_to_ios_mode (mode); |
1 | 444 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
445 oct_mach_info::float_format flt_fmt = |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
446 oct_mach_info::string_to_float_format (arch); |
1 | 447 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
448 std::string fname = file_ops::tilde_expand (name); |
6159 | 449 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
450 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
|
451 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
452 if (! (md & std::ios::out)) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
453 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
|
454 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
455 if (! fs.is_dir ()) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
456 { |
6905 | 457 #if defined (HAVE_ZLIB) |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
458 if (use_zlib) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
459 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
460 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
|
461 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
462 int fd = fileno (fptr); |
11004
594adb99a25e
cache file id in octave_tstdiostream class
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
463 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
464 gzFile gzf = ::gzdopen (fd, mode.c_str ()); |
5325 | 465 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
466 if (fptr) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
467 retval = octave_zstdiostream::create (fname, gzf, fd, |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
468 md, flt_fmt); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
469 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
470 retval.error (gnulib::strerror (errno)); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
471 } |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
472 else |
5325 | 473 #endif |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
474 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
475 FILE *fptr = gnulib::fopen (fname.c_str (), mode.c_str ()); |
5370 | 476 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
477 retval = octave_stdiostream::create (fname, fptr, md, |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
478 flt_fmt); |
7730
b68e44c90afe
file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents:
7708
diff
changeset
|
479 |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
480 if (! fptr) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
481 retval.error (gnulib::strerror (errno)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
482 } |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
483 |
1 | 484 } |
485 | |
2095 | 486 return retval; |
487 } | |
1 | 488 |
3340 | 489 static octave_stream |
2095 | 490 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
|
491 const octave_value& tc_arch, const char *fcn, int& fid) |
2095 | 492 { |
3340 | 493 octave_stream retval; |
2095 | 494 |
495 fid = -1; | |
496 | |
20712
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
497 std::string name = tc_name.xstring_value ("%s: filename must be a string", fcn); |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20686
diff
changeset
|
498 std::string mode = tc_mode.xstring_value ("%s: file mode must be a string", fcn); |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20686
diff
changeset
|
499 std::string arch = tc_arch.xstring_value ("%s: architecture type must be a string", fcn); |
1 | 500 |
20580
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20560
diff
changeset
|
501 retval = do_stream_open (name, mode, arch, fid); |
1 | 502 |
503 return retval; | |
504 } | |
505 | |
11146
69b2f237060e
file-io.cc (Ffopen): argument parsing tweak
John W. Eaton <jwe@octave.org>
parents:
11081
diff
changeset
|
506 DEFUN (fopen, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
507 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
508 @deftypefn {} {@var{fid} =} fopen (@var{name})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
509 @deftypefnx {} {@var{fid} =} fopen (@var{name}, @var{mode})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
510 @deftypefnx {} {@var{fid} =} fopen (@var{name}, @var{mode}, @var{arch})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
511 @deftypefnx {} {[@var{fid}, @var{msg}] =} fopen (@dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
512 @deftypefnx {} {@var{fid_list} =} fopen (\"all\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
513 @deftypefnx {} {[@var{file}, @var{mode}, @var{arch}] =} fopen (@var{fid})\n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
514 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:
20100
diff
changeset
|
515 \n\ |
3372 | 516 The first form of the @code{fopen} function opens the named file with\n\ |
517 the specified mode (read-write, read-only, etc.) and architecture\n\ | |
518 interpretation (IEEE big endian, IEEE little endian, etc.), and returns\n\ | |
519 an integer value that may be used to refer to the file later. If an\n\ | |
520 error occurs, @var{fid} is set to @minus{}1 and @var{msg} contains the\n\ | |
521 corresponding system error message. The @var{mode} is a one or two\n\ | |
522 character string that specifies whether the file is to be opened for\n\ | |
523 reading, writing, or both.\n\ | |
1181 | 524 \n\ |
3372 | 525 The second form of the @code{fopen} function returns a vector of file ids\n\ |
526 corresponding to all the currently open files, excluding the\n\ | |
527 @code{stdin}, @code{stdout}, and @code{stderr} streams.\n\ | |
2318 | 528 \n\ |
5353 | 529 The third form of the @code{fopen} function returns information about the\n\ |
530 open file given its file id.\n\ | |
1181 | 531 \n\ |
3372 | 532 For example,\n\ |
533 \n\ | |
534 @example\n\ | |
535 myfile = fopen (\"splat.dat\", \"r\", \"ieee-le\");\n\ | |
536 @end example\n\ | |
2095 | 537 \n\ |
3372 | 538 @noindent\n\ |
539 opens the file @file{splat.dat} for reading. If necessary, binary\n\ | |
540 numeric values will be read assuming they are stored in IEEE format with\n\ | |
541 the least significant bit first, and then converted to the native\n\ | |
542 representation.\n\ | |
2318 | 543 \n\ |
3372 | 544 Opening a file that is already open simply opens it again and returns a\n\ |
545 separate file id. It is not an error to open a file several times,\n\ | |
546 though writing to the same file through several different file ids may\n\ | |
547 produce unexpected results.\n\ | |
548 \n\ | |
549 The possible values @samp{mode} may have are\n\ | |
550 \n\ | |
551 @table @asis\n\ | |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
552 @item @samp{r} (default)\n\ |
3372 | 553 Open a file for reading.\n\ |
3263 | 554 \n\ |
3372 | 555 @item @samp{w}\n\ |
7001 | 556 Open a file for writing. The previous contents are discarded.\n\ |
3372 | 557 \n\ |
558 @item @samp{a}\n\ | |
559 Open or create a file for writing at the end of the file.\n\ | |
560 \n\ | |
561 @item @samp{r+}\n\ | |
562 Open an existing file for reading and writing.\n\ | |
563 \n\ | |
564 @item @samp{w+}\n\ | |
565 Open a file for reading or writing. The previous contents are\n\ | |
566 discarded.\n\ | |
567 \n\ | |
568 @item @samp{a+}\n\ | |
569 Open or create a file for reading or writing at the end of the\n\ | |
570 file.\n\ | |
571 @end table\n\ | |
572 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
573 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
|
574 @qcode{\"b\"} to open in binary mode. On Windows and Macintosh systems, text\n\ |
4865 | 575 mode reading and writing automatically converts linefeeds to the\n\ |
576 appropriate line end character for the system (carriage-return linefeed\n\ | |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
577 on Windows, carriage-return on Macintosh). The default when no mode is\n\ |
4865 | 578 specified is binary mode.\n\ |
579 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
580 Additionally, you may append a @qcode{\"z\"} to the mode string to open a\n\ |
5325 | 581 gzipped file for reading or writing. For this to be successful, you\n\ |
582 must also open the file in binary mode.\n\ | |
583 \n\ | |
3372 | 584 The parameter @var{arch} is a string specifying the default data format\n\ |
585 for the file. Valid values for @var{arch} are:\n\ | |
2318 | 586 \n\ |
20430
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20197
diff
changeset
|
587 @table @asis\n\ |
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20197
diff
changeset
|
588 @item @qcode{\"native\"} or @qcode{\"n\"} (default)\n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
589 The format of the current machine.\n\ |
3372 | 590 \n\ |
20430
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20197
diff
changeset
|
591 @item @qcode{\"ieee-be\"} or @qcode{\"b\"}\n\ |
3372 | 592 IEEE big endian format.\n\ |
593 \n\ | |
20430
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20197
diff
changeset
|
594 @item @qcode{\"ieee-le\"} or @qcode{\"l\"}\n\ |
3372 | 595 IEEE little endian format.\n\ |
596 @end table\n\ | |
597 \n\ | |
598 @noindent\n\ | |
20430
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20197
diff
changeset
|
599 However, conversions are currently only supported for @samp{native},\n\ |
3372 | 600 @samp{ieee-be}, and @samp{ieee-le} formats.\n\ |
20197
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20171
diff
changeset
|
601 \n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20171
diff
changeset
|
602 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:
20171
diff
changeset
|
603 @code{0666 - @var{umask}}.\n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20171
diff
changeset
|
604 @seealso{fclose, fgets, fgetl, fscanf, fread, fputs, fdisp, fprintf, fwrite, fskipl, fseek, frewind, ftell, feof, ferror, fclear, fflush, freport, umask}\n\ |
5642 | 605 @end deftypefn") |
529 | 606 { |
607 int nargin = args.length (); | |
608 | |
20860
6774cc464ea0
* file-io.cc (Ffopen): Fix nargin range check, fixes cset f2cd811f0f9e
Mike Miller <mtmiller@octave.org>
parents:
20852
diff
changeset
|
609 if (nargin < 1 || nargin > 3) |
20845
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
610 print_usage (); |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
611 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
612 octave_value_list retval = ovl (-1.0); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
613 |
2095 | 614 if (nargin == 1) |
615 { | |
12896
a19b50f6697f
Correctly allow single string input form of fopen() (Bug #33535).
Rik <octave@nomad.inbox5.com>
parents:
12775
diff
changeset
|
616 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
617 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
618 // 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
|
619 // 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
|
620 // 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
|
621 // to supply more than one argument. |
12896
a19b50f6697f
Correctly allow single string input form of fopen() (Bug #33535).
Rik <octave@nomad.inbox5.com>
parents:
12775
diff
changeset
|
622 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
|
623 return octave_stream_list::open_file_numbers (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
624 } |
2095 | 625 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
626 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
627 string_vector tmp = octave_stream_list::get_info (args(0)); |
529 | 628 |
20883
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
629 retval = ovl (tmp(0), tmp(1), tmp(2)); |
3263 | 630 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
631 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
632 } |
1 | 633 } |
634 | |
20845
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
635 octave_value mode = (nargin == 2 || nargin == 3) |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
636 ? args(1) : octave_value ("r"); |
2095 | 637 |
20845
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
638 octave_value arch = (nargin == 3) |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
639 ? args(2) : octave_value ("native"); |
2095 | 640 |
20845
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
641 int fid = -1; |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
642 |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
643 octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid); |
5370 | 644 |
20845
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
645 if (os) |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
646 retval = ovl (octave_stream_list::insert (os), ""); |
2095 | 647 else |
20845
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
648 { |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
649 int error_number = 0; |
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
650 |
20883
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
651 retval = ovl (-1.0, os.error (false, error_number)); |
20845
f2cd811f0f9e
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
652 } |
1 | 653 |
654 return retval; | |
655 } | |
656 | |
1957 | 657 DEFUN (freport, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
658 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
659 @deftypefn {} {} freport ()\n\ |
3372 | 660 Print a list of which files have been opened, and whether they are open\n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
661 for reading, writing, or both.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
662 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
663 For example:\n\ |
3372 | 664 \n\ |
665 @example\n\ | |
666 @group\n\ | |
667 freport ()\n\ | |
668 \n\ | |
19122 | 669 @print{} number mode arch name\n\ |
670 @print{} ------ ---- ---- ----\n\ | |
671 @print{} 0 r ieee-le stdin\n\ | |
672 @print{} 1 w ieee-le stdout\n\ | |
673 @print{} 2 w ieee-le stderr\n\ | |
674 @print{} 3 r ieee-le myfile\n\ | |
3372 | 675 @end group\n\ |
676 @end example\n\ | |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
677 @seealso{fopen, fclose, is_valid_file_id}\n\ |
3372 | 678 @end deftypefn") |
1181 | 679 { |
2095 | 680 octave_value_list retval; |
1181 | 681 |
20818
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20811
diff
changeset
|
682 if (args.length () > 0) |
1181 | 683 warning ("freport: ignoring extra arguments"); |
684 | |
2095 | 685 octave_stdout << octave_stream_list::list_open_files (); |
1181 | 686 |
687 return retval; | |
688 } | |
689 | |
4715 | 690 DEFUN (frewind, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
691 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
692 @deftypefn {} {} frewind (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
693 @deftypefnx {} {@var{status} =} frewind (@var{fid})\n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
694 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:
19122
diff
changeset
|
695 descriptor @var{fid}.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
696 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
697 @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:
19029
diff
changeset
|
698 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
|
699 @seealso{fseek, ftell, fopen}\n\ |
3372 | 700 @end deftypefn") |
529 | 701 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
702 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
703 print_usage (); |
506 | 704 |
20811
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
705 int result = -1; |
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
706 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
707 octave_stream os = octave_stream_list::lookup (args(0), "frewind"); |
636 | 708 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
709 result = os.rewind (); |
1 | 710 |
4715 | 711 if (nargout > 0) |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
712 return ovl (result); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
713 else |
20940
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
714 return ovl (); |
1 | 715 } |
716 | |
1957 | 717 DEFUN (fseek, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
718 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
719 @deftypefn {} {} fseek (@var{fid}, @var{offset})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
720 @deftypefnx {} {} fseek (@var{fid}, @var{offset}, @var{origin})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
721 @deftypefnx {} {@var{status} =} fseek (@dots{})\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
722 Set the file pointer to the location @var{offset} within the file @var{fid}.\n\ |
5095 | 723 \n\ |
724 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
|
725 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
|
726 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
|
727 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
|
728 @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
|
729 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
|
730 @var{offset} can be realized.\n\ |
5095 | 731 \n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
732 @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
|
733 @seealso{fskipl, frewind, ftell, fopen}\n\ |
5642 | 734 @end deftypefn") |
529 | 735 { |
736 int nargin = args.length (); | |
737 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
738 if (nargin < 2 || nargin > 3) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
739 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
740 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
741 octave_stream os = octave_stream_list::lookup (args(0), "fseek"); |
1181 | 742 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
743 octave_value origin_arg = (nargin == 3) ? args(2) : octave_value (-1.0); |
1 | 744 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
745 return octave_value (os.seek (args(1), origin_arg)); |
1 | 746 } |
747 | |
1957 | 748 DEFUN (ftell, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
749 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
750 @deftypefn {} {@var{pos} =} ftell (@var{fid})\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
751 Return the position of the file pointer as the number of characters from the\n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
752 beginning of the file specified by file descriptor @var{fid}.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
753 @seealso{fseek, frewind, feof, fopen}\n\ |
5642 | 754 @end deftypefn") |
1181 | 755 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
756 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
757 print_usage (); |
506 | 758 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
759 octave_stream os = octave_stream_list::lookup (args(0), "ftell"); |
1 | 760 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
761 return octave_value (os.tell ()); |
1 | 762 } |
763 | |
3737 | 764 DEFUN (fprintf, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
765 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
766 @deftypefn {} {} fprintf (@var{fid}, @var{template}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
767 @deftypefnx {} {} fprintf (@var{template}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
768 @deftypefnx {} {@var{numbytes} =} fprintf (@dots{})\n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
769 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:
19122
diff
changeset
|
770 written to the file descriptor @var{fid} instead of @code{stdout}.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
771 \n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
772 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:
19122
diff
changeset
|
773 function exactly equivalent to @code{printf}.\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
774 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
775 The optional output returns the number of bytes written to the file.\n\ |
20040
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19860
diff
changeset
|
776 \n\ |
20096
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20040
diff
changeset
|
777 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
20100
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20096
diff
changeset
|
778 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20096
diff
changeset
|
779 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
|
780 @seealso{fputs, fdisp, fwrite, fscanf, printf, sprintf, fopen}\n\ |
5642 | 781 @end deftypefn") |
1181 | 782 { |
4468 | 783 static std::string who = "fprintf"; |
784 | |
1181 | 785 int nargin = args.length (); |
786 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
787 if (! (nargin > 1 || (nargin > 0 && args(0).is_string ()))) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
788 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
789 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
790 int result; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
791 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
792 octave_stream os; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
793 int fmt_n = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
794 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
795 if (args(0).is_string ()) |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
796 os = octave_stream_list::lookup (1, who); |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
797 else |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
798 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
799 fmt_n = 1; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
800 os = octave_stream_list::lookup (args(0), who); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
801 } |
2873 | 802 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
803 if (! args(fmt_n).is_string ()) |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
804 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
1181 | 805 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
806 octave_value_list tmp_args; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
807 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
808 if (nargin > 1 + fmt_n) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
809 { |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
810 tmp_args.resize (nargin-fmt_n-1, octave_value ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
811 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
812 for (int i = fmt_n + 1; i < nargin; i++) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
813 tmp_args(i-fmt_n-1) = args(i); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
814 } |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
815 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
816 result = os.printf (args(fmt_n), tmp_args, who); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
817 |
4715 | 818 if (nargout > 0) |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
819 return octave_value (result); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
820 else |
20940
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
821 return ovl (); |
1181 | 822 } |
823 | |
4715 | 824 DEFUN (printf, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
825 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
826 @deftypefn {} {} printf (@var{template}, @dots{})\n\ |
4468 | 827 Print optional arguments under the control of the template string\n\ |
5653 | 828 @var{template} to the stream @code{stdout} and return the number of\n\ |
829 characters printed.\n\ | |
830 @ifclear OCTAVE_MANUAL\n\ | |
5095 | 831 \n\ |
5653 | 832 See the Formatted Output section of the GNU Octave manual for a\n\ |
833 complete description of the syntax of the template string.\n\ | |
834 @end ifclear\n\ | |
20040
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19860
diff
changeset
|
835 \n\ |
20096
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20040
diff
changeset
|
836 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
20100
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20096
diff
changeset
|
837 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20096
diff
changeset
|
838 expanded even when the template string is defined with single quotes.\n\ |
5642 | 839 @seealso{fprintf, sprintf, scanf}\n\ |
840 @end deftypefn") | |
4468 | 841 { |
842 static std::string who = "printf"; | |
843 | |
844 int nargin = args.length (); | |
845 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
846 if (nargin == 0) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
847 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
848 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
849 int result; |
4468 | 850 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
851 if (! args(0).is_string ()) |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
852 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
4468 | 853 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
854 octave_value_list tmp_args; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
855 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
856 if (nargin > 1) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
857 { |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
858 tmp_args.resize (nargin-1, octave_value ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
859 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
860 for (int i = 1; i < nargin; i++) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
861 tmp_args(i-1) = args(i); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
862 } |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
863 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
864 result = stdout_stream.printf (args(0), tmp_args, who); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
865 |
4715 | 866 if (nargout > 0) |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
867 return ovl (result); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
868 else |
20940
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
869 return ovl (); |
4468 | 870 } |
871 | |
2095 | 872 DEFUN (fputs, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
873 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
874 @deftypefn {} {} fputs (@var{fid}, @var{string})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
875 @deftypefnx {} {@var{status} =} fputs (@var{fid}, @var{string})\n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
876 Write the string @var{string} to the file with file descriptor @var{fid}.\n\ |
5095 | 877 \n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
878 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:
19122
diff
changeset
|
879 @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:
19122
diff
changeset
|
880 for the local machine.\n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
881 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
882 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
|
883 @seealso{fdisp, fprintf, fwrite, fopen}\n\ |
3372 | 884 @end deftypefn") |
1181 | 885 { |
4468 | 886 static std::string who = "fputs"; |
887 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
888 if (args.length () != 2) |
5823 | 889 print_usage (); |
4468 | 890 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
891 octave_stream os = octave_stream_list::lookup (args(0), who); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
892 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
893 return octave_value (os.puts (args(1), who)); |
4468 | 894 } |
895 | |
896 DEFUN (puts, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
897 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
898 @deftypefn {} {} puts (@var{string})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
899 @deftypefnx {} {@var{status} =} puts (@var{string})\n\ |
4468 | 900 Write a string to the standard output with no formatting.\n\ |
5095 | 901 \n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
902 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:
19122
diff
changeset
|
903 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:
19122
diff
changeset
|
904 \n\ |
5095 | 905 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
|
906 @seealso{fputs, disp}\n\ |
4468 | 907 @end deftypefn") |
908 { | |
909 static std::string who = "puts"; | |
910 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
911 if (args.length () != 1) |
5823 | 912 print_usage (); |
1181 | 913 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
914 return octave_value (stdout_stream.puts (args(0), who)); |
1181 | 915 } |
916 | |
2095 | 917 DEFUN (sprintf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
918 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
919 @deftypefn {} {} sprintf (@var{template}, @dots{})\n\ |
3372 | 920 This is like @code{printf}, except that the output is returned as a\n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
921 string.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
922 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
923 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:
20100
diff
changeset
|
924 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:
20100
diff
changeset
|
925 string, automatically sized to hold all of the items converted.\n\ |
20040
dbf2418a46dd
Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents:
19860
diff
changeset
|
926 \n\ |
20096
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20040
diff
changeset
|
927 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\ |
20100
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20096
diff
changeset
|
928 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\ |
e51473fdb622
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
20096
diff
changeset
|
929 expanded even when the template string is defined with single quotes.\n\ |
5642 | 930 @seealso{printf, fprintf, sscanf}\n\ |
931 @end deftypefn") | |
1 | 932 { |
4468 | 933 static std::string who = "sprintf"; |
934 | |
2095 | 935 int nargin = args.length (); |
1 | 936 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
937 if (nargin == 0) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
938 print_usage (); |
2116 | 939 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
940 octave_ostrstream *ostr = new octave_ostrstream (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
941 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
942 octave_stream os (ostr); |
628 | 943 |
20897
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
944 if (! os.is_valid ()) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
945 error ("%s: unable to create output buffer", who.c_str ()); |
1 | 946 |
20897
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
947 octave_value fmt_arg = args(0); |
1 | 948 |
20897
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
949 if (! fmt_arg.is_string ()) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
950 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
628 | 951 |
20897
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
952 octave_value_list retval (3); |
19726
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19696
diff
changeset
|
953 |
20897
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
954 octave_value_list tmp_args; |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
955 if (nargin > 1) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
956 { |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
957 tmp_args.resize (nargin-1, octave_value ()); |
19726
3c3b9fce7d2b
improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents:
19696
diff
changeset
|
958 |
20897
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
959 for (int i = 1; i < nargin; i++) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
960 tmp_args(i-1) = args(i); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
961 } |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
962 |
20897
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
963 // NOTE: Call to os.error must precede next call to ostr which might reset it. |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
964 retval(2) = os.printf (fmt_arg, tmp_args, who); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
965 retval(1) = os.error (); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
966 |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
967 std::string result = ostr->str (); |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
968 char type = fmt_arg.is_sq_string () ? '\'' : '"'; |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
969 |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
970 retval(0) = (result.empty () ? octave_value (charMatrix (1, 0), type) |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20883
diff
changeset
|
971 : octave_value (result, type)); |
1 | 972 |
973 return retval; | |
974 } | |
975 | |
2095 | 976 DEFUN (fscanf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
977 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
978 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, @var{size})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
979 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, \"C\")\n\ |
3372 | 980 In the first form, read from @var{fid} according to @var{template},\n\ |
981 returning the result in the matrix @var{val}.\n\ | |
2122 | 982 \n\ |
3372 | 983 The optional argument @var{size} specifies the amount of data to read\n\ |
984 and may be one of\n\ | |
985 \n\ | |
986 @table @code\n\ | |
987 @item Inf\n\ | |
988 Read as much as possible, returning a column vector.\n\ | |
989 \n\ | |
990 @item @var{nr}\n\ | |
991 Read up to @var{nr} elements, returning a column vector.\n\ | |
2122 | 992 \n\ |
3372 | 993 @item [@var{nr}, Inf]\n\ |
994 Read as much as possible, returning a matrix with @var{nr} rows. If the\n\ | |
995 number of elements read is not an exact multiple of @var{nr}, the last\n\ | |
996 column is padded with zeros.\n\ | |
997 \n\ | |
998 @item [@var{nr}, @var{nc}]\n\ | |
999 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with\n\ | |
1000 @var{nr} rows. If the number of elements read is not an exact multiple\n\ | |
1001 of @var{nr}, the last column is padded with zeros.\n\ | |
1002 @end table\n\ | |
2122 | 1003 \n\ |
3372 | 1004 @noindent\n\ |
1005 If @var{size} is omitted, a value of @code{Inf} is assumed.\n\ | |
2122 | 1006 \n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1007 A string is returned if @var{template} specifies only character conversions.\n\ |
2215 | 1008 \n\ |
3372 | 1009 The number of items successfully read is returned in @var{count}.\n\ |
2215 | 1010 \n\ |
13271
fba2cc36b762
return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents:
13194
diff
changeset
|
1011 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
|
1012 \n\ |
3372 | 1013 In the second form, read from @var{fid} according to @var{template},\n\ |
1014 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
|
1015 single scalar return value. This form is more ``C-like'', and also\n\ |
3491 | 1016 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
|
1017 conversions is returned in @var{count}\n\ |
5653 | 1018 @ifclear OCTAVE_MANUAL\n\ |
1019 \n\ | |
1020 See the Formatted Input section of the GNU Octave manual for a\n\ | |
1021 complete description of the syntax of the template string.\n\ | |
1022 @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
|
1023 @seealso{fgets, fgetl, fread, scanf, sscanf, fopen}\n\ |
5642 | 1024 @end deftypefn") |
1181 | 1025 { |
4468 | 1026 static std::string who = "fscanf"; |
1027 | |
1181 | 1028 int nargin = args.length (); |
1029 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1030 if (nargin < 2 || nargin > 3) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1031 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1032 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1033 octave_value_list retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1034 |
2215 | 1035 if (nargin == 3 && args(2).is_string ()) |
2095 | 1036 { |
4468 | 1037 octave_stream os = octave_stream_list::lookup (args(0), who); |
1181 | 1038 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1039 if (! args(1).is_string ()) |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
1040 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1041 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1042 retval = ovl (os.oscanf (args(1), who)); |
2095 | 1043 } |
1181 | 1044 else |
2215 | 1045 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1046 octave_stream os = octave_stream_list::lookup (args(0), who); |
2215 | 1047 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1048 if (! args(1).is_string ()) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1049 error ("%s: format must be a string", who.c_str ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1050 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1051 octave_idx_type count = 0; |
2215 | 1052 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1053 Array<double> size = (nargin == 3) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1054 ? args(2).vector_value () |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1055 : Array<double> (dim_vector (1, 1), |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1056 lo_ieee_inf_value ()); |
2215 | 1057 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1058 octave_value tmp = os.scanf (args(1), size, count, who); |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1059 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1060 retval = ovl (tmp, count, os.error ()); |
2215 | 1061 } |
1181 | 1062 |
1063 return retval; | |
1064 } | |
1065 | |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1066 static std::string |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1067 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
|
1068 { |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1069 std::string retval; |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1070 |
20961
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1071 if (! val.is_string ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1072 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
|
1073 |
20961
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1074 octave_value tmp = val.reshape (dim_vector (1, val.numel ())); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1075 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1076 retval = tmp.string_value (); |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1077 |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1078 return retval; |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1079 } |
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1080 |
2095 | 1081 DEFUN (sscanf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1082 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1083 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}, @var{pos}] =} sscanf (@var{string}, @var{template}, @var{size})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1084 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} sscanf (@var{string}, @var{template}, \"C\")\n\ |
3372 | 1085 This is like @code{fscanf}, except that the characters are taken from the\n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1086 string @var{string} instead of from a stream.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1087 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1088 Reaching the end of the string is treated as an end-of-file condition. In\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1089 addition to the values returned by @code{fscanf}, the index of the next\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1090 character to be read is returned in @var{pos}.\n\ |
5642 | 1091 @seealso{fscanf, scanf, sprintf}\n\ |
1092 @end deftypefn") | |
444 | 1093 { |
4468 | 1094 static std::string who = "sscanf"; |
1095 | |
506 | 1096 int nargin = args.length (); |
1097 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1098 if (nargin < 2 || nargin > 3) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1099 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1100 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1101 octave_value_list retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1102 |
2215 | 1103 if (nargin == 3 && args(2).is_string ()) |
2095 | 1104 { |
13194
3e1871badab9
allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents:
12998
diff
changeset
|
1105 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
|
1106 |
20677
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
1107 octave_stream os = octave_istrstream::create (data); |
1358 | 1108 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1109 if (! os.is_valid ()) |
20677
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
1110 error ("%s: unable to create temporary input buffer", who.c_str ()); |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1111 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1112 if (! args(1).is_string ()) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1113 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1114 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1115 retval = ovl (os.oscanf (args(1), who)); |
444 | 1116 } |
1117 else | |
2215 | 1118 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1119 std::string data = get_sscanf_data (args(0)); |
2215 | 1120 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1121 octave_stream os = octave_istrstream::create (data); |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
1122 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1123 if (! os.is_valid ()) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1124 error ("%s: unable to create temporary input buffer", who.c_str ()); |
2215 | 1125 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1126 if (! args(1).is_string ()) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1127 error ("%s: format TEMPLATE must be a string", who.c_str ()); |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
1128 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1129 octave_idx_type count = 0; |
2215 | 1130 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1131 Array<double> size = (nargin == 3) ? args(2).vector_value () |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1132 : Array<double> (dim_vector (1, 1), |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1133 lo_ieee_inf_value ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1134 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1135 octave_value tmp = os.scanf (args(1), size, count, who); |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
1136 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1137 // FIXME: is this the right thing to do? |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1138 // Extract error message first, because getting |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1139 // position will clear it. |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1140 std::string errmsg = os.error (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1141 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1142 retval = ovl (tmp, count, errmsg, |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1143 (os.eof () ? data.length () : os.tell ()) + 1); |
2215 | 1144 } |
444 | 1145 |
1146 return retval; | |
1147 } | |
1148 | |
2215 | 1149 DEFUN (scanf, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1150 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1151 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} scanf (@var{template}, @var{size})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1152 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}]] =} scanf (@var{template}, \"C\")\n\ |
3372 | 1153 This is equivalent to calling @code{fscanf} with @var{fid} = @code{stdin}.\n\ |
1154 \n\ | |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1155 It is currently not useful to call @code{scanf} in interactive programs.\n\ |
5642 | 1156 @seealso{fscanf, sscanf, printf}\n\ |
1157 @end deftypefn") | |
2215 | 1158 { |
1159 int nargin = args.length (); | |
1160 | |
1161 octave_value_list tmp_args (nargin+1, octave_value ()); | |
1162 | |
1163 tmp_args (0) = 0.0; | |
1164 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
|
1165 tmp_args(i+1) = args(i); |
2215 | 1166 |
1167 return Ffscanf (tmp_args, nargout); | |
1168 } | |
1169 | |
2116 | 1170 static octave_value |
1171 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
|
1172 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
|
1173 const octave_value& arch_arg, octave_idx_type& count) |
2116 | 1174 { |
1175 count = -1; | |
1176 | |
20702
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20699
diff
changeset
|
1177 Array<double> size = size_arg.xvector_value ("fread: invalid SIZE specified"); |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20699
diff
changeset
|
1178 |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20699
diff
changeset
|
1179 std::string prec = prec_arg.xstring_value ("fread: PRECISION must be a string"); |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20699
diff
changeset
|
1180 |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20699
diff
changeset
|
1181 int block_size = 1; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20699
diff
changeset
|
1182 oct_data_conv::data_type input_type; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20699
diff
changeset
|
1183 oct_data_conv::data_type output_type; |
85e5efae848a
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20699
diff
changeset
|
1184 |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1185 try |
2116 | 1186 { |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1187 oct_data_conv::string_to_data_type (prec, block_size, |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1188 input_type, output_type); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1189 } |
20784
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20763
diff
changeset
|
1190 catch (octave_execution_exception& e) |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1191 { |
20755
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20746
diff
changeset
|
1192 error (e, "fread: invalid PRECISION specified"); |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1193 } |
4944 | 1194 |
20746
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20740
diff
changeset
|
1195 int skip = 0; |
3202 | 1196 |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1197 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1198 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1199 skip = skip_arg.int_value (true); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1200 } |
20784
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20763
diff
changeset
|
1201 catch (octave_execution_exception& e) |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1202 { |
20755
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20746
diff
changeset
|
1203 error (e, "fread: SKIP must be an integer"); |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1204 } |
2116 | 1205 |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1206 std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string"); |
2116 | 1207 |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1208 oct_mach_info::float_format flt_fmt |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1209 = oct_mach_info::string_to_float_format (arch); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1210 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1211 return os.read (size, block_size, input_type, output_type, skip, |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1212 flt_fmt, count); |
2116 | 1213 } |
1214 | |
1215 DEFUN (fread, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1216 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1217 @deftypefn {} {@var{val} =} fread (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1218 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1219 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1220 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1221 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip}, @var{arch})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1222 @deftypefnx {} {[@var{val}, @var{count}] =} fread (@dots{})\n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
1223 Read binary data from the file specified by the file descriptor @var{fid}.\n\ |
3372 | 1224 \n\ |
1225 The optional argument @var{size} specifies the amount of data to read\n\ | |
1226 and may be one of\n\ | |
1227 \n\ | |
1228 @table @code\n\ | |
1229 @item Inf\n\ | |
1230 Read as much as possible, returning a column vector.\n\ | |
529 | 1231 \n\ |
3372 | 1232 @item @var{nr}\n\ |
1233 Read up to @var{nr} elements, returning a column vector.\n\ | |
1234 \n\ | |
1235 @item [@var{nr}, Inf]\n\ | |
1236 Read as much as possible, returning a matrix with @var{nr} rows. If the\n\ | |
1237 number of elements read is not an exact multiple of @var{nr}, the last\n\ | |
1238 column is padded with zeros.\n\ | |
1239 \n\ | |
1240 @item [@var{nr}, @var{nc}]\n\ | |
1241 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with\n\ | |
1242 @var{nr} rows. If the number of elements read is not an exact multiple\n\ | |
1243 of @var{nr}, the last column is padded with zeros.\n\ | |
1244 @end table\n\ | |
1245 \n\ | |
1246 @noindent\n\ | |
1247 If @var{size} is omitted, a value of @code{Inf} is assumed.\n\ | |
2318 | 1248 \n\ |
3372 | 1249 The optional argument @var{precision} is a string specifying the type of\n\ |
1250 data to read and may be one of\n\ | |
1251 \n\ | |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1252 @table @asis\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1253 @item @qcode{\"schar\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1254 @itemx @qcode{\"signed char\"}\n\ |
3372 | 1255 Signed character.\n\ |
529 | 1256 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1257 @item @qcode{\"uchar\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1258 @itemx @qcode{\"unsigned char\"}\n\ |
3372 | 1259 Unsigned character.\n\ |
1260 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1261 @item @qcode{\"int8\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1262 @itemx @qcode{\"integer*1\"}\n\ |
4944 | 1263 \n\ |
1264 8-bit signed integer.\n\ | |
2318 | 1265 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1266 @item @qcode{\"int16\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1267 @itemx @qcode{\"integer*2\"}\n\ |
4944 | 1268 16-bit signed integer.\n\ |
3372 | 1269 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1270 @item @qcode{\"int32\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1271 @itemx @qcode{\"integer*4\"}\n\ |
4944 | 1272 32-bit signed integer.\n\ |
3372 | 1273 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1274 @item @qcode{\"int64\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1275 @itemx @qcode{\"integer*8\"}\n\ |
4944 | 1276 64-bit signed integer.\n\ |
1277 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1278 @item @qcode{\"uint8\"}\n\ |
4944 | 1279 8-bit unsigned integer.\n\ |
529 | 1280 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1281 @item @qcode{\"uint16\"}\n\ |
4944 | 1282 16-bit unsigned integer.\n\ |
3372 | 1283 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1284 @item @qcode{\"uint32\"}\n\ |
4944 | 1285 32-bit unsigned integer.\n\ |
3372 | 1286 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1287 @item @qcode{\"uint64\"}\n\ |
4944 | 1288 64-bit unsigned integer.\n\ |
1289 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1290 @item @qcode{\"single\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1291 @itemx @qcode{\"float32\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1292 @itemx @qcode{\"real*4\"}\n\ |
4944 | 1293 32-bit floating point number.\n\ |
3372 | 1294 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1295 @item @qcode{\"double\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1296 @itemx @qcode{\"float64\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1297 @itemx @qcode{\"real*8\"}\n\ |
4944 | 1298 64-bit floating point number.\n\ |
1299 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1300 @item @qcode{\"char\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1301 @itemx @qcode{\"char*1\"}\n\ |
4944 | 1302 Single character.\n\ |
3372 | 1303 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1304 @item @qcode{\"short\"}\n\ |
4944 | 1305 Short integer (size is platform dependent).\n\ |
1306 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1307 @item @qcode{\"int\"}\n\ |
4944 | 1308 Integer (size is platform dependent).\n\ |
1309 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1310 @item @qcode{\"long\"}\n\ |
4944 | 1311 Long integer (size is platform dependent).\n\ |
3372 | 1312 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1313 @item @qcode{\"ushort\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1314 @itemx @qcode{\"unsigned short\"}\n\ |
4944 | 1315 Unsigned short integer (size is platform dependent).\n\ |
4610 | 1316 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1317 @item @qcode{\"uint\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1318 @itemx @qcode{\"unsigned int\"}\n\ |
4944 | 1319 Unsigned integer (size is platform dependent).\n\ |
4610 | 1320 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1321 @item @qcode{\"ulong\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1322 @itemx @qcode{\"unsigned long\"}\n\ |
4944 | 1323 Unsigned long integer (size is platform dependent).\n\ |
1324 \n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1325 @item @qcode{\"float\"}\n\ |
4944 | 1326 Single precision floating point number (size is platform dependent).\n\ |
3372 | 1327 @end table\n\ |
1328 \n\ | |
1329 @noindent\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1330 The default precision is @qcode{\"uchar\"}.\n\ |
2318 | 1331 \n\ |
4944 | 1332 The @var{precision} argument may also specify an optional repeat\n\ |
1333 count. For example, @samp{32*single} causes @code{fread} to read\n\ | |
1334 a block of 32 single precision floating point numbers. Reading in\n\ | |
1335 blocks is useful in combination with the @var{skip} argument.\n\ | |
1336 \n\ | |
1337 The @var{precision} argument may also specify a type conversion.\n\ | |
1338 For example, @samp{int16=>int32} causes @code{fread} to read 16-bit\n\ | |
1339 integer values and return an array of 32-bit integer values. By\n\ | |
1340 default, @code{fread} returns a double precision array. The special\n\ | |
1341 form @samp{*TYPE} is shorthand for @samp{TYPE=>TYPE}.\n\ | |
1342 \n\ | |
7096 | 1343 The conversion and repeat counts may be combined. For example, the\n\ |
1344 specification @samp{32*single=>single} causes @code{fread} to read\n\ | |
1345 blocks of single precision floating point values and return an array\n\ | |
1346 of single precision values instead of the default array of double\n\ | |
1347 precision values.\n\ | |
4944 | 1348 \n\ |
3372 | 1349 The optional argument @var{skip} specifies the number of bytes to skip\n\ |
4944 | 1350 after each element (or block of elements) is read. If it is not\n\ |
1351 specified, a value of 0 is assumed. If the final block read is not\n\ | |
1352 complete, the final skip is omitted. For example,\n\ | |
1353 \n\ | |
1354 @example\n\ | |
1355 fread (f, 10, \"3*single=>single\", 8)\n\ | |
1356 @end example\n\ | |
1357 \n\ | |
1358 @noindent\n\ | |
1359 will omit the final 8-byte skip because the last read will not be\n\ | |
1360 a complete block of 3 values.\n\ | |
3372 | 1361 \n\ |
1362 The optional argument @var{arch} is a string specifying the data format\n\ | |
1363 for the file. Valid values are\n\ | |
529 | 1364 \n\ |
18078
b06a9768b643
doc: Don't use @table @qcode to avoid problems with Texinfo 5.2.
Rik <rik@octave.org>
parents:
18040
diff
changeset
|
1365 @table @asis\n\ |
20430
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20197
diff
changeset
|
1366 @item @qcode{\"native\"} or @qcode{\"n\"}\n\ |
3372 | 1367 The format of the current machine.\n\ |
1368 \n\ | |
20430
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20197
diff
changeset
|
1369 @item @qcode{\"ieee-be\"} or @qcode{\"b\"}\n\ |
3372 | 1370 IEEE big endian.\n\ |
1371 \n\ | |
20430
f02c22f71cdb
doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents:
20197
diff
changeset
|
1372 @item @qcode{\"ieee-le\"} or @qcode{\"l\"}\n\ |
3372 | 1373 IEEE little endian.\n\ |
1374 @end table\n\ | |
2318 | 1375 \n\ |
20438
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20430
diff
changeset
|
1376 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:
20430
diff
changeset
|
1377 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:
20430
diff
changeset
|
1378 @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:
20430
diff
changeset
|
1379 \n\ |
18207
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1380 The output argument @var{val} contains the data read from the file.\n\ |
20438
97edbce9b975
doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents:
20430
diff
changeset
|
1381 \n\ |
18207
bea06b5d4423
doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents:
18111
diff
changeset
|
1382 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
|
1383 @seealso{fwrite, fgets, fgetl, fscanf, fopen}\n\ |
5642 | 1384 @end deftypefn") |
529 | 1385 { |
2116 | 1386 int nargin = args.length (); |
1387 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1388 if (nargin < 1 || nargin > 5) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1389 print_usage (); |
2116 | 1390 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1391 octave_stream os = octave_stream_list::lookup (args(0), "fread"); |
2116 | 1392 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1393 octave_value size = lo_ieee_inf_value (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1394 octave_value prec = "uchar"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1395 octave_value skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1396 octave_value arch = "unknown"; |
2116 | 1397 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1398 int idx = 1; |
2116 | 1399 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1400 if (nargin > idx && ! args(idx).is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1401 size = args(idx++); |
2116 | 1402 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1403 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1404 prec = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1405 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1406 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1407 skip = args(idx++); |
4257 | 1408 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1409 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1410 arch = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1411 else if (skip.is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1412 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1413 arch = skip; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1414 skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1415 } |
2116 | 1416 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1417 octave_idx_type count = -1; |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
1418 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1419 octave_value tmp = do_fread (os, size, prec, skip, arch, count); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1420 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1421 return ovl (tmp, count); |
529 | 1422 } |
1423 | |
2116 | 1424 static int |
1425 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
|
1426 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
|
1427 const octave_value& arch_arg) |
2116 | 1428 { |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20686
diff
changeset
|
1429 std::string prec = prec_arg.xstring_value ("fwrite: PRECISION must be a string"); |
20580
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20560
diff
changeset
|
1430 |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20560
diff
changeset
|
1431 int block_size = 1; |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20560
diff
changeset
|
1432 oct_data_conv::data_type output_type; |
2116 | 1433 |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1434 try |
20580
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20560
diff
changeset
|
1435 { |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1436 oct_data_conv::string_to_data_type (prec, block_size, output_type); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1437 } |
20784
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20763
diff
changeset
|
1438 catch (octave_execution_exception& e) |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1439 { |
20755
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20746
diff
changeset
|
1440 error (e, "fwrite: invalid PRECISION specified"); |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1441 } |
2116 | 1442 |
20746
ee2743bd07a8
eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents:
20740
diff
changeset
|
1443 int skip = 0; |
3202 | 1444 |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1445 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1446 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1447 skip = skip_arg.int_value (true); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1448 } |
20784
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20763
diff
changeset
|
1449 catch (octave_execution_exception& e) |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1450 { |
20755
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20746
diff
changeset
|
1451 error (e, "fwrite: SKIP must be an integer"); |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1452 } |
2116 | 1453 |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1454 std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string"); |
2116 | 1455 |
20740
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1456 oct_mach_info::float_format flt_fmt |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1457 = oct_mach_info::string_to_float_format (arch); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1458 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20712
diff
changeset
|
1459 return os.write (data, block_size, output_type, skip, flt_fmt); |
2116 | 1460 } |
1461 | |
1462 DEFUN (fwrite, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1463 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1464 @deftypefn {} {} fwrite (@var{fid}, @var{data})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1465 @deftypefnx {} {} fwrite (@var{fid}, @var{data}, @var{precision})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1466 @deftypefnx {} {} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1467 @deftypefnx {} {} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip}, @var{arch})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1468 @deftypefnx {} {@var{count} =} fwrite (@dots{})\n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
1469 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:
19122
diff
changeset
|
1470 @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:
19122
diff
changeset
|
1471 to the file.\n\ |
1181 | 1472 \n\ |
3372 | 1473 The argument @var{data} is a matrix of values that are to be written to\n\ |
1474 the file. The values are extracted in column-major order.\n\ | |
1181 | 1475 \n\ |
3372 | 1476 The remaining arguments @var{precision}, @var{skip}, and @var{arch} are\n\ |
1477 optional, and are interpreted as described for @code{fread}.\n\ | |
1181 | 1478 \n\ |
3372 | 1479 The behavior of @code{fwrite} is undefined if the values in @var{data}\n\ |
1480 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
|
1481 @seealso{fread, fputs, fprintf, fopen}\n\ |
5642 | 1482 @end deftypefn") |
1181 | 1483 { |
2116 | 1484 int nargin = args.length (); |
1485 | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1486 if (nargin < 2 || nargin > 5) |
5823 | 1487 print_usage (); |
2116 | 1488 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1489 octave_stream os = octave_stream_list::lookup (args(0), "fwrite"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1490 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1491 octave_value prec = "uchar"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1492 octave_value skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1493 octave_value arch = "unknown"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1494 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1495 int idx = 1; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1496 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1497 octave_value data = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1498 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1499 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1500 prec = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1501 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1502 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1503 skip = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1504 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1505 if (nargin > idx) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1506 arch = args(idx++); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1507 else if (skip.is_string ()) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1508 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1509 arch = skip; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1510 skip = 0; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1511 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1512 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1513 return octave_value (do_fwrite (os, data, prec, skip, arch)); |
1181 | 1514 } |
1515 | |
5906 | 1516 DEFUNX ("feof", Ffeof, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1517 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1518 @deftypefn {} {@var{status} =} feof (@var{fid})\n\ |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
1519 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:
19122
diff
changeset
|
1520 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:
19122
diff
changeset
|
1521 \n\ |
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
1522 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:
19122
diff
changeset
|
1523 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:
19122
diff
changeset
|
1524 end-of-file condition.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1525 @seealso{fread, frewind, fseek, fclear, fopen}\n\ |
5642 | 1526 @end deftypefn") |
529 | 1527 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1528 if (args.length () != 1) |
5823 | 1529 print_usage (); |
444 | 1530 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1531 octave_stream os = octave_stream_list::lookup (args(0), "feof"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1532 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1533 return octave_value (os.eof () ? 1.0 : 0.0); |
444 | 1534 } |
1535 | |
5906 | 1536 DEFUNX ("ferror", Fferror, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1537 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1538 @deftypefn {} {@var{msg} =} ferror (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1539 @deftypefnx {} {[@var{msg}, @var{err}] =} ferror (@var{fid})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1540 @deftypefnx {} {[@var{dots}] =} ferror (@var{fid}, \"clear\")\n\ |
19149 | 1541 Query the error status of the stream specified by file descriptor @var{fid}\n\ |
1542 \n\ | |
1543 If an error condition exists then return a string @var{msg} describing the\n\ | |
1544 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
|
1545 \n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1546 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:
20100
diff
changeset
|
1547 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:
20100
diff
changeset
|
1548 \n\ |
19149 | 1549 The optional second output is a numeric indication of the error status.\n\ |
1550 @var{err} is 1 if an error condition has been encountered and 0 otherwise.\n\ | |
19126
df5e4024ec18
doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents:
19122
diff
changeset
|
1551 \n\ |
19149 | 1552 Note that @code{ferror} indicates if an error has already occurred, not\n\ |
1553 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
|
1554 @seealso{fclear, fopen}\n\ |
3372 | 1555 @end deftypefn") |
1230 | 1556 { |
2095 | 1557 int nargin = args.length (); |
1230 | 1558 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1559 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1560 print_usage (); |
1230 | 1561 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1562 octave_stream os = octave_stream_list::lookup (args(0), "ferror"); |
1230 | 1563 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1564 bool clear = false; |
2095 | 1565 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1566 if (nargin == 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1567 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1568 std::string opt = args(1).string_value (); |
20560
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20456
diff
changeset
|
1569 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1570 clear = (opt == "clear"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1571 } |
1755 | 1572 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1573 int error_number = 0; |
1230 | 1574 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1575 std::string error_message = os.error (clear, error_number); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1576 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1577 return ovl (error_message, error_number); |
1230 | 1578 } |
1579 | |
18476
aa7ca90ce746
avoid problems if popen is a macro
John W. Eaton <jwe@octave.org>
parents:
18040
diff
changeset
|
1580 DEFUNX ("popen", Fpopen, args, , |
19860
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19726
diff
changeset
|
1581 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1582 @deftypefn {} {@var{fid} =} popen (@var{command}, @var{mode})\n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1583 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:
20100
diff
changeset
|
1584 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1585 The name of the command to run is given by @var{command}. The argument\n\ |
3301 | 1586 @var{mode} may be\n\ |
1587 \n\ | |
1588 @table @code\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1589 @item @qcode{\"r\"}\n\ |
3301 | 1590 The pipe will be connected to the standard output of the process, and\n\ |
1591 open for reading.\n\ | |
1230 | 1592 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1593 @item @qcode{\"w\"}\n\ |
3301 | 1594 The pipe will be connected to the standard input of the process, and\n\ |
1595 open for writing.\n\ | |
1596 @end table\n\ | |
1597 \n\ | |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1598 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:
20100
diff
changeset
|
1599 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:
20100
diff
changeset
|
1600 \n\ |
10840 | 1601 For example:\n\ |
1230 | 1602 \n\ |
3301 | 1603 @example\n\ |
1604 @group\n\ | |
1605 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
|
1606 while (ischar (s = fgets (fid)))\n\ |
3301 | 1607 fputs (stdout, s);\n\ |
1608 endwhile\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
1609 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14210
diff
changeset
|
1610 @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
|
1611 @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
|
1612 @print{} drwxrwxrwt 15 root root 2048 Feb 17 14:53 tmp\n\ |
3301 | 1613 @end group\n\ |
1614 @end example\n\ | |
18949
ed3cb9f81145
file-io.cc (popen): Add seealso popen2
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18486
diff
changeset
|
1615 @seealso{popen2}\n\ |
3301 | 1616 @end deftypefn") |
1230 | 1617 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1618 if (args.length () != 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1619 print_usage (); |
1230 | 1620 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1621 std::string name = args(0).xstring_value ("popen: COMMAND must be a string"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1622 std::string mode = args(1).xstring_value ("popen: MODE must be a string"); |
1230 | 1623 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1624 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1625 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1626 if (mode == "r") |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1627 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1628 octave_stream ips = octave_iprocstream::create (name); |
1230 | 1629 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1630 retval = octave_stream_list::insert (ips); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1631 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1632 else if (mode == "w") |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1633 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1634 octave_stream ops = octave_oprocstream::create (name); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1635 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1636 retval = octave_stream_list::insert (ops); |
2095 | 1637 } |
1230 | 1638 else |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1639 error ("popen: invalid MODE specified"); |
1230 | 1640 |
1641 return retval; | |
1642 } | |
1643 | |
16308
122c1a7a3004
avoid trouble if pclose is a macro
John W. Eaton <jwe@octave.org>
parents:
16099
diff
changeset
|
1644 DEFUNX ("pclose", Fpclose, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1645 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1646 @deftypefn {} {} pclose (@var{fid})\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1647 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:
19029
diff
changeset
|
1648 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1649 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:
19029
diff
changeset
|
1650 @seealso{fclose, popen}\n\ |
3301 | 1651 @end deftypefn") |
1230 | 1652 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1653 if (args.length () != 1) |
5823 | 1654 print_usage (); |
1379 | 1655 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1656 return octave_value (octave_stream_list::remove (args(0), "pclose")); |
1379 | 1657 } |
1658 | |
19277
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19267
diff
changeset
|
1659 DEFUN (tempname, args, , |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19267
diff
changeset
|
1660 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1661 @deftypefn {} {@var{fname} =} tempname ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1662 @deftypefnx {} {@var{fname} =} tempname (@var{dir})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1663 @deftypefnx {} {@var{fname} =} tempname (@var{dir}, @var{prefix})\n\ |
20712
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20703
diff
changeset
|
1664 Return a unique temporary filename as a string.\n\ |
3372 | 1665 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1666 If @var{prefix} is omitted, a value of @qcode{\"oct-\"} is used.\n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1667 \n\ |
4267 | 1668 If @var{dir} is also omitted, the default directory for temporary files\n\ |
19384
3b4d6780d6b8
doc: Add missing closing parenthesis in tempname docstring.
Rik <rik@octave.org>
parents:
19277
diff
changeset
|
1669 (@code{P_tmpdir}) is used. If @var{dir} is provided, it must exist,\n\ |
19209
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19149
diff
changeset
|
1670 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:
19149
diff
changeset
|
1671 \n\ |
19277
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19267
diff
changeset
|
1672 Programming Note: Because the named file is not opened by @code{tempname},\n\ |
19209
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19149
diff
changeset
|
1673 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:
19149
diff
changeset
|
1674 by the time your program attempts to open it. If this is a concern,\n\ |
19277
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19267
diff
changeset
|
1675 see @code{tmpfile}.\n\ |
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19267
diff
changeset
|
1676 @seealso{mkstemp, tempdir, P_tmpdir, tmpfile}\n\ |
5642 | 1677 @end deftypefn") |
1802 | 1678 { |
20811
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
1679 int nargin = args.length (); |
2936 | 1680 |
20811
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
1681 if (nargin > 2) |
5823 | 1682 print_usage (); |
1802 | 1683 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1684 std::string dir; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1685 |
20811
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
1686 if (nargin > 0) |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1687 dir = args(0).xstring_value ("tempname: DIR must be a string"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1688 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1689 std::string pfx ("oct-"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1690 |
20811
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20804
diff
changeset
|
1691 if (nargin > 1) |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1692 pfx = args(1).xstring_value ("tempname: PREFIX must be a string"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1693 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1694 return octave_value (octave_tempnam (dir, pfx)); |
1802 | 1695 } |
1696 | |
19419
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1697 /* |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1698 %!test |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1699 %! if (ispc ()) |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1700 %! envname = "TMP"; |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1701 %! else |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1702 %! envname = "TMPDIR"; |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1703 %! endif |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1704 %! envdir = getenv (envname); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1705 %! unsetenv (envname); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1706 %! unwind_protect |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1707 %! ## Test 0-argument form |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1708 %! fname = tempname (); |
19596
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19419
diff
changeset
|
1709 %! [tmpdir, tmpfname] = fileparts (fname); |
19419
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1710 %! assert (tmpdir, P_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1711 %! assert (tmpfname (1:4), "oct-"); |
19596
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19419
diff
changeset
|
1712 %! ## Test 1-argument form |
19419
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1713 %! 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:
19402
diff
changeset
|
1714 %! 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:
19402
diff
changeset
|
1715 %! setenv (envname, P_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1716 %! fname = tempname (tmp_tmpdir); |
19596
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19419
diff
changeset
|
1717 %! [tmpdir, tmpfname] = fileparts (fname); |
19419
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1718 %! assert (tmpdir, tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1719 %! assert (tmpfname (1:4), "oct-"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1720 %! ## 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:
19402
diff
changeset
|
1721 %! fname = tempname (""); |
19596
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19419
diff
changeset
|
1722 %! [tmpdir, tmpfname] = fileparts (fname); |
19419
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1723 %! assert (tmpdir, P_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1724 %! assert (tmpfname (1:4), "oct-"); |
19596
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19419
diff
changeset
|
1725 %! ## Test 2-argument form |
19419
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1726 %! fname = tempname (tmp_tmpdir, "pfx-"); |
19596
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19419
diff
changeset
|
1727 %! [tmpdir, tmpfname] = fileparts (fname); |
19419
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1728 %! assert (tmpdir, tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1729 %! assert (tmpfname (1:4), "pfx-"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1730 %! ## 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:
19402
diff
changeset
|
1731 %! fname = tempname (tmp_tmpdir, ""); |
19596
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19419
diff
changeset
|
1732 %! [tmpdir, tmpfname] = fileparts (fname); |
19419
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1733 %! assert (tmpdir, tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1734 %! assert (tmpfname (1:4), "file"); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1735 %! unwind_protect_cleanup |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1736 %! rmdir (tmp_tmpdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1737 %! if (isempty (envdir)) |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1738 %! unsetenv (envname); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1739 %! else |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1740 %! setenv (envname, envdir); |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1741 %! endif |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1742 %! end_unwind_protect |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1743 */ |
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
1744 |
4326 | 1745 DEFUN (tmpfile, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1746 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1747 @deftypefn {} {[@var{fid}, @var{msg}] =} tmpfile ()\n\ |
4326 | 1748 Return the file ID corresponding to a new temporary file with a unique\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1749 name.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1750 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1751 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:
19029
diff
changeset
|
1752 deleted automatically when it is closed or when Octave exits.\n\ |
4326 | 1753 \n\ |
1754 If successful, @var{fid} is a valid file ID and @var{msg} is an empty\n\ | |
1755 string. Otherwise, @var{fid} is -1 and @var{msg} contains a\n\ | |
1756 system-dependent error message.\n\ | |
19277
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19267
diff
changeset
|
1757 @seealso{tempname, mkstemp, tempdir, P_tmpdir}\n\ |
5642 | 1758 @end deftypefn") |
4326 | 1759 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1760 if (args.length () != 0) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1761 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1762 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1763 octave_value_list retval; |
4326 | 1764 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1765 FILE *fid = gnulib::tmpfile (); |
4326 | 1766 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1767 if (fid) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1768 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1769 std::string nm; |
4326 | 1770 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1771 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); |
4326 | 1772 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1773 octave_stream s = octave_stdiostream::create (nm, fid, md); |
4326 | 1774 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1775 if (! s) |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1776 error ("tmpfile: failed to create octave_stdiostream object"); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1777 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1778 retval = ovl (octave_stream_list::insert (s), ""); |
4326 | 1779 } |
1780 else | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1781 { |
20883
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1782 retval = ovl (-1, gnulib::strerror (errno)); |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1783 } |
4326 | 1784 |
1785 return retval; | |
1786 } | |
1787 | |
1788 DEFUN (mkstemp, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1789 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1790 @deftypefn {} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (\"@var{template}\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1791 @deftypefnx {} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (\"@var{template}\", @var{delete})\n\ |
19209
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19149
diff
changeset
|
1792 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:
19149
diff
changeset
|
1793 with a unique name created from @var{template}.\n\ |
4326 | 1794 \n\ |
19209
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19149
diff
changeset
|
1795 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:
19149
diff
changeset
|
1796 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:
19149
diff
changeset
|
1797 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:
19149
diff
changeset
|
1798 dependent (on GNU/Linux systems, the permissions will be 0600 for versions of\n\ |
19229
cfa9996afcbf
doc: fix stray escape sequence in mkstemp's docstring
Mike Miller <mtmiller@ieee.org>
parents:
19209
diff
changeset
|
1799 glibc 2.0.7 and later). The file is opened in binary mode and with the\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1800 @w{@code{O_EXCL}} flag.\n\ |
4326 | 1801 \n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1802 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:
19029
diff
changeset
|
1803 be deleted automatically when Octave exits.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1804 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1805 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:
19029
diff
changeset
|
1806 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:
19029
diff
changeset
|
1807 @var{name} is empty, and @var{msg} contains a system-dependent error message.\n\ |
19277
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19267
diff
changeset
|
1808 @seealso{tempname, tempdir, P_tmpdir, tmpfile, fopen}\n\ |
5642 | 1809 @end deftypefn") |
4326 | 1810 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1811 int nargin = args.length (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1812 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1813 if (nargin < 1 || nargin > 2) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1814 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1815 |
20883
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1816 std::string tmpl8 = args(0).xstring_value ("mkstemp: TEMPLATE argument must be a string"); |
4326 | 1817 |
20883
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1818 octave_value_list retval = ovl (-1, "", ""); |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1819 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1820 OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1821 strcpy (tmp, tmpl8.c_str ()); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1822 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1823 int fd = gnulib::mkostemp (tmp, O_BINARY); |
4326 | 1824 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1825 if (fd < 0) |
4326 | 1826 { |
20883
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1827 retval(0) = fd; |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1828 retval(2) = gnulib::strerror (errno); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1829 } |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1830 else |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1831 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1832 const char *fopen_mode = "w+b"; |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1833 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1834 FILE *fid = fdopen (fd, fopen_mode); |
20580
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20560
diff
changeset
|
1835 |
20883
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1836 if (! fid) |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1837 { |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1838 retval(0) = -1; |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1839 retval(2) = gnulib::strerror (errno); |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1840 } |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1841 else |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1842 { |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1843 std::string nm = tmp; |
20580
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20560
diff
changeset
|
1844 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1845 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1846 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1847 octave_stream s = octave_stdiostream::create (nm, fid, md); |
20580
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20560
diff
changeset
|
1848 |
20883
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1849 if (! s) |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1850 error ("mkstemp: failed to create octave_stdiostream object"); |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1851 |
20883
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1852 retval(0) = octave_stream_list::insert (s); |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1853 retval(1) = nm; |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1854 |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1855 if (nargin == 2 && args(1).is_true ()) |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20860
diff
changeset
|
1856 mark_for_deletion (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1857 } |
4326 | 1858 } |
1859 | |
1860 return retval; | |
1861 } | |
1862 | |
20199
d9f35ceff9e1
Change mkfifo to use an octal argument for MODE (bug #45054).
Rik <rik@octave.org>
parents:
20197
diff
changeset
|
1863 // 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:
20197
diff
changeset
|
1864 // Maybe change to be a general utility routine. |
1400 | 1865 static int |
1866 convert (int x, int ibase, int obase) | |
1867 { | |
1868 int retval = 0; | |
1869 | |
1870 int tmp = x % obase; | |
1871 | |
1872 if (tmp > ibase - 1) | |
20427
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20199
diff
changeset
|
1873 error ("umask: invalid digit"); |
1400 | 1874 else |
1875 { | |
1876 retval = tmp; | |
1877 int mult = ibase; | |
1878 while ((x = (x - tmp) / obase)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1879 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1880 tmp = x % obase; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1881 if (tmp > ibase - 1) |
20955
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1882 error ("umask: invalid digit"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1883 retval += mult * tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1884 mult *= ibase; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10259
diff
changeset
|
1885 } |
1400 | 1886 } |
1887 | |
1888 return retval; | |
1889 } | |
1890 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1891 DEFUNX ("umask", Fumask, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1892 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1893 @deftypefn {} {} umask (@var{mask})\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1894 Set the permission mask for file creation.\n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1895 \n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1896 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:
20100
diff
changeset
|
1897 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20100
diff
changeset
|
1898 If successful, returns the previous value of the mask (as an integer to be\n\ |
4715 | 1899 interpreted as an octal number); otherwise an error message is printed.\n\ |
20197
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20171
diff
changeset
|
1900 \n\ |
b597bd161a5f
doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents:
20171
diff
changeset
|
1901 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:
20171
diff
changeset
|
1902 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:
20171
diff
changeset
|
1903 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:
20171
diff
changeset
|
1904 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:
20171
diff
changeset
|
1905 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:
20171
diff
changeset
|
1906 @seealso{fopen, mkdir, mkfifo}\n\ |
3301 | 1907 @end deftypefn") |
1400 | 1908 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1909 if (args.length () != 1) |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1910 print_usage (); |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1911 |
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1912 int mask = args(0).xint_value ("umask: MASK must be an integer"); |
1400 | 1913 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1914 if (mask < 0) |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1915 error ("umask: MASK must be a positive integer value"); |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1916 |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1917 int oct_mask = convert (mask, 8, 10); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1918 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1919 int status = convert (octave_umask (oct_mask), 10, 8); |
1400 | 1920 |
1921 if (status >= 0) | |
20917
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1922 return ovl (status); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1923 else |
20940
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
1924 return ovl (); |
1400 | 1925 } |
1926 | |
5749 | 1927 static octave_value |
6483 | 1928 const_value (const char *, const octave_value_list& args, int val) |
2189 | 1929 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1930 if (args.length () != 0) |
5823 | 1931 print_usage (); |
5749 | 1932 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1933 return octave_value (val); |
5749 | 1934 } |
1935 | |
1936 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
|
1937 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1938 @deftypefn {} {} P_tmpdir ()\n\ |
19209
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19149
diff
changeset
|
1939 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:
19149
diff
changeset
|
1940 temporary files.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1941 \n\ |
19209
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19149
diff
changeset
|
1942 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:
19149
diff
changeset
|
1943 default location. This value may not agree with that returned from\n\ |
20096
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20040
diff
changeset
|
1944 @code{tempdir} if the user has overridden the default with the @env{TMPDIR}\n\ |
19209
841d8f606bcd
doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents:
19149
diff
changeset
|
1945 environment variable.\n\ |
19277
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19267
diff
changeset
|
1946 @seealso{tempdir, tempname, mkstemp, tmpfile}\n\ |
5749 | 1947 @end deftypefn") |
1948 { | |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1949 if (args.length () != 0) |
5823 | 1950 print_usage (); |
5749 | 1951 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
1952 return octave_value (get_P_tmpdir ()); |
5749 | 1953 } |
2341 | 1954 |
5749 | 1955 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be |
1956 // this way for Matlab compatibility. | |
1957 | |
1958 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
|
1959 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1960 @deftypefn {} {} SEEK_SET ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1961 @deftypefnx {} {} SEEK_CUR ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1962 @deftypefnx {} {} SEEK_END ()\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
1963 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:
19029
diff
changeset
|
1964 following actions:\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14365
diff
changeset
|
1965 \n\ |
3372 | 1966 @table @code\n\ |
1967 @item SEEK_SET\n\ | |
1968 Position file relative to the beginning.\n\ | |
1969 \n\ | |
1970 @item SEEK_CUR\n\ | |
1971 Position file relative to the current position.\n\ | |
1972 \n\ | |
1973 @item SEEK_END\n\ | |
5749 | 1974 Position file relative to the end.\n\ |
3372 | 1975 @end table\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1976 @seealso{fseek}\n\ |
5749 | 1977 @end deftypefn") |
1978 { | |
1979 return const_value ("SEEK_SET", args, -1); | |
1980 } | |
2189 | 1981 |
5749 | 1982 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
|
1983 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1984 @deftypefn {} {} SEEK_CUR ()\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1985 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
|
1986 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
|
1987 @seealso{SEEK_SET, SEEK_END}\n\ |
5749 | 1988 @end deftypefn") |
1989 { | |
1990 return const_value ("SEEK_CUR", args, 0); | |
1991 } | |
2189 | 1992 |
5749 | 1993 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
|
1994 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
1995 @deftypefn {} {} SEEK_END ()\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1996 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
|
1997 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
|
1998 @seealso{SEEK_SET, SEEK_CUR}\n\ |
5749 | 1999 @end deftypefn") |
2000 { | |
2001 return const_value ("SEEK_END", args, 1); | |
2002 } | |
2003 | |
2004 static octave_value | |
6483 | 2005 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
|
2006 const octave_value& val) |
5749 | 2007 { |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
2008 if (args.length () != 0) |
5823 | 2009 print_usage (); |
5749 | 2010 |
20804
2d6ddb2b157c
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20784
diff
changeset
|
2011 return octave_value (val); |
5749 | 2012 } |
2013 | |
2014 DEFUNX ("stdin", Fstdin, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2015 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
2016 @deftypefn {} {} stdin ()\n\ |
5749 | 2017 Return the numeric value corresponding to the standard input stream.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
2018 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
2019 When Octave is used interactively, stdin is filtered through the command\n\ |
5749 | 2020 line editing functions.\n\ |
5333 | 2021 @seealso{stdout, stderr}\n\ |
5749 | 2022 @end deftypefn") |
2023 { | |
2024 return const_value ("stdin", args, stdin_file); | |
2025 } | |
2189 | 2026 |
5749 | 2027 DEFUNX ("stdout", Fstdout, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2028 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
2029 @deftypefn {} {} stdout ()\n\ |
5749 | 2030 Return the numeric value corresponding to the standard output stream.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
2031 \n\ |
5749 | 2032 Data written to the standard output is normally filtered through the pager.\n\ |
5333 | 2033 @seealso{stdin, stderr}\n\ |
5749 | 2034 @end deftypefn") |
2035 { | |
2036 return const_value ("stdout", args, stdout_file); | |
2037 } | |
2189 | 2038 |
5749 | 2039 DEFUNX ("stderr", Fstderr, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2040 "-*- texinfo -*-\n\ |
20852
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20845
diff
changeset
|
2041 @deftypefn {} {} stderr ()\n\ |
5749 | 2042 Return the numeric value corresponding to the standard error stream.\n\ |
19108
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
2043 \n\ |
e90bfaadb489
doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents:
19029
diff
changeset
|
2044 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:
19029
diff
changeset
|
2045 It is useful for error messages and prompts.\n\ |
5333 | 2046 @seealso{stdin, stdout}\n\ |
5749 | 2047 @end deftypefn") |
2048 { | |
2049 return const_value ("stderr", args, stderr_file); | |
2189 | 2050 } |