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