1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
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 |
2095
|
34 // Completely rewritten by John W. Eaton <jwe@bevo.che.wisc.edu>, |
|
35 // April 1996. |
1
|
36 |
240
|
37 #ifdef HAVE_CONFIG_H |
1230
|
38 #include <config.h> |
1
|
39 #endif |
|
40 |
2095
|
41 #include <climits> |
4341
|
42 #include <cerrno> |
1343
|
43 |
3503
|
44 #include <iostream> |
4383
|
45 #include <memory> |
1350
|
46 |
|
47 #ifdef HAVE_UNISTD_H |
2442
|
48 #ifdef HAVE_SYS_TYPES_H |
1230
|
49 #include <sys/types.h> |
2442
|
50 #endif |
1
|
51 #include <unistd.h> |
1343
|
52 #endif |
1350
|
53 |
2926
|
54 #include "file-ops.h" |
|
55 |
1352
|
56 #include "defun.h" |
1
|
57 #include "error.h" |
2116
|
58 #include "lo-ieee.h" |
2095
|
59 #include "oct-fstrm.h" |
|
60 #include "oct-iostrm.h" |
1377
|
61 #include "oct-map.h" |
1750
|
62 #include "oct-obj.h" |
2095
|
63 #include "oct-prcstrm.h" |
|
64 #include "oct-stream.h" |
|
65 #include "oct-strstrm.h" |
1
|
66 #include "pager.h" |
4326
|
67 #include "pt-plot.h" |
444
|
68 #include "sysdep.h" |
1352
|
69 #include "utils.h" |
2370
|
70 #include "variables.h" |
1583
|
71 |
2902
|
72 static octave_value stdin_file; |
|
73 static octave_value stdout_file; |
|
74 static octave_value stderr_file; |
|
75 |
1
|
76 void |
164
|
77 initialize_file_io (void) |
1
|
78 { |
3531
|
79 octave_stream stdin_stream = octave_istream::create (&std::cin, "stdin"); |
2116
|
80 |
3531
|
81 // This uses octave_stdout (see pager.h), not std::cout so that Octave's |
2116
|
82 // standard output stream will pass through the pager. |
|
83 |
3340
|
84 octave_stream stdout_stream |
|
85 = octave_ostream::create (&octave_stdout, "stdout"); |
2116
|
86 |
3531
|
87 octave_stream stderr_stream = octave_ostream::create (&std::cerr, "stderr"); |
1
|
88 |
2902
|
89 stdin_file = octave_stream_list::insert (stdin_stream); |
|
90 stdout_file = octave_stream_list::insert (stdout_stream); |
|
91 stderr_file = octave_stream_list::insert (stderr_stream); |
1
|
92 } |
|
93 |
2095
|
94 void |
|
95 close_files (void) |
1
|
96 { |
2095
|
97 octave_stream_list::clear (); |
|
98 } |
636
|
99 |
4036
|
100 static std::ios::openmode |
3523
|
101 fopen_mode_to_ios_mode (const std::string& mode) |
1
|
102 { |
4036
|
103 std::ios::openmode retval = std::ios::in; |
896
|
104 |
2095
|
105 if (! mode.empty ()) |
368
|
106 { |
2095
|
107 // Could probably be faster, but does it really matter? |
1766
|
108 |
2095
|
109 if (mode == "r") |
3544
|
110 retval = std::ios::in; |
2095
|
111 else if (mode == "w") |
3544
|
112 retval = std::ios::out | std::ios::trunc; |
2095
|
113 else if (mode == "a") |
3544
|
114 retval = std::ios::out | std::ios::app; |
2095
|
115 else if (mode == "r+") |
3544
|
116 retval = std::ios::in | std::ios::out; |
2095
|
117 else if (mode == "w+") |
3544
|
118 retval = std::ios::in | std::ios::out | std::ios::trunc; |
2095
|
119 else if (mode == "a+") |
4070
|
120 retval = std::ios::in | std::ios::out | std::ios::ate; |
2095
|
121 else if (mode == "rb") |
3569
|
122 retval = std::ios::in | std::ios::binary; |
2095
|
123 else if (mode == "wb") |
3569
|
124 retval = std::ios::out | std::ios::trunc | std::ios::binary; |
2095
|
125 else if (mode == "ab") |
3569
|
126 retval = std::ios::out | std::ios::app | std::ios::binary; |
2095
|
127 else if (mode == "r+b") |
3569
|
128 retval = std::ios::in | std::ios::out | std::ios::binary; |
2095
|
129 else if (mode == "w+b") |
4036
|
130 retval = (std::ios::in | std::ios::out | std::ios::trunc |
|
131 | std::ios::binary); |
2095
|
132 else if (mode == "a+b") |
4070
|
133 retval = (std::ios::in | std::ios::out | std::ios::ate |
4036
|
134 | std::ios::binary); |
368
|
135 else |
2095
|
136 ::error ("invalid mode specified"); |
1
|
137 } |
|
138 |
|
139 return retval; |
|
140 } |
|
141 |
4028
|
142 DEFUN (isstream, args, , |
3448
|
143 "-*- texinfo -*-\n\ |
4028
|
144 @deftypefn {Built-in Function} {} isstream (@var{x})\n\ |
3448
|
145 Return true if @var{x} is a stream object. Otherwise, return false.\n\ |
|
146 @end deftypefn") |
3340
|
147 { |
|
148 octave_value retval; |
|
149 |
|
150 if (args.length () == 1) |
|
151 retval = args(0).is_stream (); |
|
152 else |
4028
|
153 print_usage ("isstream"); |
3340
|
154 |
|
155 return retval; |
|
156 } |
|
157 |
1957
|
158 DEFUN (fclose, args, , |
3372
|
159 "-*- texinfo -*-\n\ |
|
160 @deftypefn {Built-in Function} {} fclose (@var{fid})\n\ |
|
161 Closes the specified file. If an error is encountered while trying to\n\ |
|
162 close the file, an error message is printed and @code{fclose} returns\n\ |
|
163 0. Otherwise, it returns 1.\n\ |
|
164 @end deftypefn") |
529
|
165 { |
4233
|
166 octave_value retval = -1; |
529
|
167 |
|
168 int nargin = args.length (); |
|
169 |
2095
|
170 if (nargin == 1) |
4233
|
171 retval = octave_stream_list::remove (args(0), "fclose"); |
1
|
172 else |
2095
|
173 print_usage ("fclose"); |
1
|
174 |
|
175 return retval; |
|
176 } |
|
177 |
1957
|
178 DEFUN (fflush, args, , |
3372
|
179 "-*- texinfo -*-\n\ |
|
180 @deftypefn {Built-in Function} {} fflush (@var{fid})\n\ |
|
181 Flush output to @var{fid}. This is useful for ensuring that all\n\ |
|
182 pending output makes it to the screen before some other event occurs.\n\ |
|
183 For example, it is always a good idea to flush the standard output\n\ |
|
184 stream before calling @code{input}.\n\ |
|
185 @end deftypefn") |
1181
|
186 { |
4233
|
187 octave_value retval = -1; |
1181
|
188 |
|
189 int nargin = args.length (); |
|
190 |
2095
|
191 if (nargin == 1) |
|
192 { |
2609
|
193 // XXX FIXME XXX -- any way to avoid special case for stdout? |
|
194 |
|
195 int fid = octave_stream_list::get_file_number (args (0)); |
|
196 |
|
197 if (fid == 1) |
|
198 { |
|
199 flush_octave_stdout (); |
2095
|
200 |
4233
|
201 retval = 0; |
2609
|
202 } |
2095
|
203 else |
2609
|
204 { |
3341
|
205 octave_stream os = octave_stream_list::lookup (fid, "fflush"); |
2609
|
206 |
3341
|
207 if (! error_state) |
4233
|
208 retval = os.flush (); |
2609
|
209 } |
2095
|
210 } |
|
211 else |
1181
|
212 print_usage ("fflush"); |
|
213 |
|
214 return retval; |
|
215 } |
|
216 |
2095
|
217 DEFUN (fgetl, args, , |
3372
|
218 "-*- texinfo -*-\n\ |
|
219 @deftypefn {Built-in Function} {} fgetl (@var{fid}, @var{len})\n\ |
|
220 Read characters from a file, stopping after a newline, or EOF,\n\ |
|
221 or @var{len} characters have been read. The characters read, excluding\n\ |
|
222 the possible trailing newline, are returned as a string.\n\ |
1339
|
223 \n\ |
3372
|
224 If @var{len} is omitted, @code{fgetl} reads until the next newline\n\ |
|
225 character.\n\ |
|
226 \n\ |
|
227 If there are no more characters to read, @code{fgetl} returns @minus{}1.\n\ |
|
228 @end deftypefn") |
1339
|
229 { |
2599
|
230 octave_value_list retval; |
|
231 |
4233
|
232 retval(1) = 0; |
|
233 retval(0) = -1; |
1339
|
234 |
|
235 int nargin = args.length (); |
|
236 |
|
237 if (nargin == 1 || nargin == 2) |
2095
|
238 { |
3341
|
239 octave_stream os = octave_stream_list::lookup (args(0), "fgetl"); |
2095
|
240 |
3341
|
241 if (! error_state) |
2095
|
242 { |
|
243 octave_value len_arg = (nargin == 2) |
4233
|
244 ? args(1) : octave_value (INT_MAX); |
2095
|
245 |
|
246 bool err = false; |
|
247 |
3523
|
248 std::string tmp = os.getl (len_arg, err); |
2095
|
249 |
|
250 if (! err) |
2599
|
251 { |
4254
|
252 retval(1) = tmp.length (); |
2599
|
253 retval(0) = tmp; |
|
254 } |
2095
|
255 } |
|
256 } |
1339
|
257 else |
|
258 print_usage ("fgetl"); |
|
259 |
|
260 return retval; |
|
261 } |
|
262 |
2095
|
263 DEFUN (fgets, args, , |
3372
|
264 "-*- texinfo -*-\n\ |
|
265 @deftypefn {Built-in Function} {} fgets (@var{fid}, @var{len})\n\ |
|
266 Read characters from a file, stopping after a newline, or EOF,\n\ |
|
267 or @var{len} characters have been read. The characters read, including\n\ |
|
268 the possible trailing newline, are returned as a string.\n\ |
529
|
269 \n\ |
3372
|
270 If @var{len} is omitted, @code{fgets} reads until the next newline\n\ |
|
271 character.\n\ |
|
272 \n\ |
|
273 If there are no more characters to read, @code{fgets} returns @minus{}1.\n\ |
|
274 @end deftypefn") |
529
|
275 { |
2599
|
276 octave_value_list retval; |
|
277 |
|
278 retval(1) = 0.0; |
|
279 retval(0) = -1.0; |
529
|
280 |
|
281 int nargin = args.length (); |
|
282 |
1338
|
283 if (nargin == 1 || nargin == 2) |
2095
|
284 { |
3341
|
285 octave_stream os = octave_stream_list::lookup (args(0), "fgets"); |
2095
|
286 |
3341
|
287 if (! error_state) |
2095
|
288 { |
|
289 octave_value len_arg = (nargin == 2) |
4233
|
290 ? args(1) : octave_value (INT_MAX); |
2095
|
291 |
|
292 bool err = false; |
|
293 |
3523
|
294 std::string tmp = os.gets (len_arg, err); |
2095
|
295 |
|
296 if (! err) |
2599
|
297 { |
4254
|
298 retval(1) = tmp.length (); |
2599
|
299 retval(0) = tmp; |
|
300 } |
2095
|
301 } |
|
302 } |
1338
|
303 else |
1181
|
304 print_usage ("fgets"); |
529
|
305 |
|
306 return retval; |
|
307 } |
|
308 |
3340
|
309 static octave_stream |
3523
|
310 do_stream_open (const std::string& name, const std::string& mode, |
|
311 const std::string& arch, int& fid) |
1
|
312 { |
3340
|
313 octave_stream retval; |
1
|
314 |
2095
|
315 fid = -1; |
1
|
316 |
4036
|
317 std::ios::openmode md = fopen_mode_to_ios_mode (mode); |
1
|
318 |
2095
|
319 if (! error_state) |
|
320 { |
2318
|
321 oct_mach_info::float_format flt_fmt = |
|
322 oct_mach_info::string_to_float_format (arch); |
1
|
323 |
2095
|
324 if (! error_state) |
4036
|
325 retval = octave_fstream::create (name, md, flt_fmt); |
1
|
326 } |
|
327 |
2095
|
328 return retval; |
|
329 } |
1
|
330 |
3340
|
331 static octave_stream |
2095
|
332 do_stream_open (const octave_value& tc_name, const octave_value& tc_mode, |
|
333 const octave_value& tc_arch, const char *fcn, int& fid) |
|
334 { |
3340
|
335 octave_stream retval; |
2095
|
336 |
|
337 fid = -1; |
|
338 |
3523
|
339 std::string name = tc_name.string_value (); |
2095
|
340 |
|
341 if (! error_state) |
1
|
342 { |
3523
|
343 std::string mode = tc_mode.string_value (); |
2095
|
344 |
|
345 if (! error_state) |
|
346 { |
3523
|
347 std::string arch = tc_arch.string_value (); |
1
|
348 |
2095
|
349 if (! error_state) |
|
350 retval = do_stream_open (name, mode, arch, fid); |
|
351 else |
|
352 ::error ("%s: architecture type must be a string", fcn); |
|
353 } |
|
354 else |
|
355 ::error ("%s: file mode must be a string", fcn); |
1
|
356 } |
2095
|
357 else |
|
358 ::error ("%s: file name must be a string", fcn); |
1
|
359 |
|
360 return retval; |
|
361 } |
|
362 |
1957
|
363 DEFUN (fopen, args, , |
3372
|
364 "-*- texinfo -*-\n\ |
|
365 @deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} fopen (@var{name}, @var{mode}, @var{arch})\n\ |
|
366 @deftypefnx {Built-in Function} {@var{fid_list} =} fopen (\"all\")\n\ |
|
367 @deftypefnx {Built-in Function} {@var{file} =} fopen (@var{fid})\n\ |
|
368 The first form of the @code{fopen} function opens the named file with\n\ |
|
369 the specified mode (read-write, read-only, etc.) and architecture\n\ |
|
370 interpretation (IEEE big endian, IEEE little endian, etc.), and returns\n\ |
|
371 an integer value that may be used to refer to the file later. If an\n\ |
|
372 error occurs, @var{fid} is set to @minus{}1 and @var{msg} contains the\n\ |
|
373 corresponding system error message. The @var{mode} is a one or two\n\ |
|
374 character string that specifies whether the file is to be opened for\n\ |
|
375 reading, writing, or both.\n\ |
1181
|
376 \n\ |
3372
|
377 The second form of the @code{fopen} function returns a vector of file ids\n\ |
|
378 corresponding to all the currently open files, excluding the\n\ |
|
379 @code{stdin}, @code{stdout}, and @code{stderr} streams.\n\ |
2318
|
380 \n\ |
3372
|
381 The third form of the @code{fopen} function returns the name of a\n\ |
|
382 currently open file given its file id.\n\ |
1181
|
383 \n\ |
3372
|
384 For example,\n\ |
|
385 \n\ |
|
386 @example\n\ |
|
387 myfile = fopen (\"splat.dat\", \"r\", \"ieee-le\");\n\ |
|
388 @end example\n\ |
2095
|
389 \n\ |
3372
|
390 @noindent\n\ |
|
391 opens the file @file{splat.dat} for reading. If necessary, binary\n\ |
|
392 numeric values will be read assuming they are stored in IEEE format with\n\ |
|
393 the least significant bit first, and then converted to the native\n\ |
|
394 representation.\n\ |
2318
|
395 \n\ |
3372
|
396 Opening a file that is already open simply opens it again and returns a\n\ |
|
397 separate file id. It is not an error to open a file several times,\n\ |
|
398 though writing to the same file through several different file ids may\n\ |
|
399 produce unexpected results.\n\ |
|
400 \n\ |
|
401 The possible values @samp{mode} may have are\n\ |
|
402 \n\ |
|
403 @table @asis\n\ |
|
404 @item @samp{r}\n\ |
|
405 Open a file for reading.\n\ |
3263
|
406 \n\ |
3372
|
407 @item @samp{w}\n\ |
|
408 Open a file for writing. The previous contents are discared.\n\ |
|
409 \n\ |
|
410 @item @samp{a}\n\ |
|
411 Open or create a file for writing at the end of the file.\n\ |
|
412 \n\ |
|
413 @item @samp{r+}\n\ |
|
414 Open an existing file for reading and writing.\n\ |
|
415 \n\ |
|
416 @item @samp{w+}\n\ |
|
417 Open a file for reading or writing. The previous contents are\n\ |
|
418 discarded.\n\ |
|
419 \n\ |
|
420 @item @samp{a+}\n\ |
|
421 Open or create a file for reading or writing at the end of the\n\ |
|
422 file.\n\ |
|
423 @end table\n\ |
|
424 \n\ |
|
425 The parameter @var{arch} is a string specifying the default data format\n\ |
|
426 for the file. Valid values for @var{arch} are:\n\ |
2318
|
427 \n\ |
3372
|
428 @table @asis\n\ |
|
429 @samp{native}\n\ |
|
430 The format of the current machine (this is the default).\n\ |
|
431 \n\ |
4082
|
432 @samp{ieee-be}\n\ |
3372
|
433 IEEE big endian format.\n\ |
|
434 \n\ |
4082
|
435 @samp{ieee-le}\n\ |
3372
|
436 IEEE little endian format.\n\ |
2318
|
437 \n\ |
3372
|
438 @samp{vaxd}\n\ |
|
439 VAX D floating format.\n\ |
2318
|
440 \n\ |
3372
|
441 @samp{vaxg}\n\ |
|
442 VAX G floating format.\n\ |
2318
|
443 \n\ |
3372
|
444 @samp{cray}\n\ |
|
445 Cray floating format.\n\ |
|
446 @end table\n\ |
|
447 \n\ |
|
448 @noindent\n\ |
|
449 however, conversions are currently only supported for @samp{native}\n\ |
|
450 @samp{ieee-be}, and @samp{ieee-le} formats.\n\ |
|
451 @end deftypefn") |
529
|
452 { |
2599
|
453 octave_value_list retval; |
|
454 |
|
455 retval(0) = -1.0; |
529
|
456 |
|
457 int nargin = args.length (); |
|
458 |
2095
|
459 if (nargin == 1) |
|
460 { |
3263
|
461 if (args(0).is_string ()) |
|
462 { |
|
463 // If there is only one argument and it is a string but it |
|
464 // is not the string "all", we assume it is a file to open |
|
465 // with MODE = "r". To open a file called "all", you have |
|
466 // to supply more than one argument. |
|
467 |
|
468 if (args(0).string_value () == "all") |
|
469 return octave_stream_list::open_file_numbers (); |
|
470 } |
2095
|
471 else |
|
472 { |
|
473 string_vector tmp = octave_stream_list::get_info (args(0)); |
529
|
474 |
2095
|
475 if (! error_state) |
|
476 { |
|
477 retval(2) = tmp(2); |
|
478 retval(1) = tmp(1); |
|
479 retval(0) = tmp(0); |
|
480 } |
3263
|
481 |
|
482 return retval; |
2432
|
483 } |
1
|
484 } |
|
485 |
2095
|
486 if (nargin > 0 && nargin < 4) |
|
487 { |
|
488 octave_value mode = (nargin == 2 || nargin == 3) |
|
489 ? args(1) : octave_value ("r"); |
|
490 |
|
491 octave_value arch = (nargin == 3) |
|
492 ? args(2) : octave_value ("native"); |
|
493 |
|
494 int fid = -1; |
|
495 |
3340
|
496 octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid); |
2095
|
497 |
3340
|
498 if (os.is_valid ()) |
2095
|
499 { |
3340
|
500 if (os && ! error_state) |
2095
|
501 { |
|
502 retval(1) = ""; |
2902
|
503 retval(0) = octave_stream_list::insert (os); |
2095
|
504 } |
|
505 else |
|
506 { |
3162
|
507 int error_number = 0; |
|
508 |
3340
|
509 retval(1) = os.error (false, error_number); |
2095
|
510 retval(0) = -1.0; |
|
511 } |
|
512 } |
|
513 else |
3340
|
514 error ("fopen: internal error"); |
2095
|
515 } |
|
516 else |
|
517 print_usage ("fopen"); |
1
|
518 |
|
519 return retval; |
|
520 } |
|
521 |
1957
|
522 DEFUN (freport, args, , |
3372
|
523 "-*- texinfo -*-\n\ |
|
524 @deftypefn {Built-in Function} {} freport ()\n\ |
|
525 Print a list of which files have been opened, and whether they are open\n\ |
|
526 for reading, writing, or both. For example,\n\ |
|
527 \n\ |
|
528 @example\n\ |
|
529 @group\n\ |
|
530 freport ()\n\ |
|
531 \n\ |
|
532 @print{} number mode name\n\ |
|
533 @print{} \n\ |
|
534 @print{} 0 r stdin\n\ |
|
535 @print{} 1 w stdout\n\ |
|
536 @print{} 2 w stderr\n\ |
|
537 @print{} 3 r myfile\n\ |
|
538 @end group\n\ |
|
539 @end example\n\ |
|
540 @end deftypefn") |
1181
|
541 { |
2095
|
542 octave_value_list retval; |
1181
|
543 |
|
544 int nargin = args.length (); |
|
545 |
|
546 if (nargin > 0) |
|
547 warning ("freport: ignoring extra arguments"); |
|
548 |
2095
|
549 octave_stdout << octave_stream_list::list_open_files (); |
1181
|
550 |
|
551 return retval; |
|
552 } |
|
553 |
1957
|
554 DEFUN (frewind, args, , |
3372
|
555 "-*- texinfo -*-\n\ |
|
556 @deftypefn {Built-in Function} {} frewind (@var{fid})\n\ |
|
557 Move the file pointer to the beginning of the file @var{fid}, returning\n\ |
|
558 1 for success, and 0 if an error was encountered. It is equivalent to\n\ |
|
559 @code{fseek (@var{fid}, 0, SEEK_SET)}.\n\ |
|
560 @end deftypefn") |
529
|
561 { |
4233
|
562 octave_value retval = -1; |
1
|
563 |
506
|
564 int nargin = args.length (); |
|
565 |
2095
|
566 if (nargin == 1) |
1086
|
567 { |
3341
|
568 octave_stream os = octave_stream_list::lookup (args(0), "frewind"); |
636
|
569 |
3341
|
570 if (! error_state) |
4233
|
571 retval = os.rewind (); |
1
|
572 } |
|
573 else |
2095
|
574 print_usage ("frewind"); |
1
|
575 |
|
576 return retval; |
|
577 } |
|
578 |
1957
|
579 DEFUN (fseek, args, , |
3372
|
580 "-*- texinfo -*-\n\ |
|
581 @deftypefn {Built-in Function} {} fseek (@var{fid}, @var{offset}, @var{origin})\n\ |
|
582 Set the file pointer to any location within the file @var{fid}. The\n\ |
|
583 pointer is positioned @var{offset} characters from the @var{origin},\n\ |
|
584 which may be one of the predefined variables @code{SEEK_CUR} (current\n\ |
|
585 position), @code{SEEK_SET} (beginning), or @code{SEEK_END} (end of\n\ |
|
586 file). If @var{origin} is omitted, @code{SEEK_SET} is assumed. The\n\ |
|
587 offset must be zero, or a value returned by @code{ftell} (in which case\n\ |
|
588 @var{origin} must be @code{SEEK_SET}.\n\ |
|
589 @end deftypefn") |
529
|
590 { |
4233
|
591 octave_value retval = -1; |
529
|
592 |
|
593 int nargin = args.length (); |
|
594 |
2095
|
595 if (nargin == 2 || nargin == 3) |
|
596 { |
3341
|
597 octave_stream os = octave_stream_list::lookup (args(0), "fseek"); |
1181
|
598 |
3341
|
599 if (! error_state) |
2095
|
600 { |
|
601 octave_value origin_arg = (nargin == 3) |
2341
|
602 ? args(2) : octave_value (-1.0); |
1
|
603 |
4233
|
604 retval = os.seek (args(1), origin_arg); |
2095
|
605 } |
368
|
606 } |
2095
|
607 else |
|
608 print_usage ("fseek"); |
1
|
609 |
|
610 return retval; |
|
611 } |
|
612 |
1957
|
613 DEFUN (ftell, args, , |
3372
|
614 "-*- texinfo -*-\n\ |
|
615 @deftypefn {Built-in Function} {} ftell (@var{fid})\n\ |
|
616 Return the position of the file pointer as the number of characters\n\ |
|
617 from the beginning of the file @var{fid}.\n\ |
|
618 @end deftypefn") |
1181
|
619 { |
4233
|
620 octave_value retval = -1; |
1
|
621 |
506
|
622 int nargin = args.length (); |
|
623 |
2095
|
624 if (nargin == 1) |
1
|
625 { |
3341
|
626 octave_stream os = octave_stream_list::lookup (args(0), "ftell"); |
1
|
627 |
3341
|
628 if (! error_state) |
4254
|
629 retval = os.tell (); |
1
|
630 } |
|
631 else |
2095
|
632 print_usage ("ftell"); |
1
|
633 |
|
634 return retval; |
|
635 } |
|
636 |
3737
|
637 DEFUN (fprintf, args, nargout, |
3372
|
638 "-*- texinfo -*-\n\ |
|
639 @deftypefn {Built-in Function} {} fprintf (@var{fid}, @var{template}, @dots{})\n\ |
|
640 This function is just like @code{printf}, except that the output is\n\ |
|
641 written to the stream @var{fid} instead of @code{stdout}.\n\ |
|
642 @end deftypefn") |
1181
|
643 { |
4233
|
644 octave_value retval = -1; |
3737
|
645 bool return_char_count = true; |
1181
|
646 |
|
647 int nargin = args.length (); |
|
648 |
2875
|
649 if (nargin > 1 || (nargin > 0 && args(0).is_string ())) |
2095
|
650 { |
3340
|
651 octave_stream os; |
2873
|
652 int fmt_n = 0; |
|
653 |
3737
|
654 if (args(0).is_string ()) |
|
655 { |
|
656 os = octave_stream_list::lookup (1, "fprintf"); |
|
657 |
|
658 // For compatibility with Matlab, which does not return the |
|
659 // character count when behaving like printf (no file id |
|
660 // parameter). |
|
661 |
|
662 return_char_count = (nargout != 0); |
|
663 } |
2873
|
664 else |
|
665 { |
|
666 fmt_n = 1; |
3341
|
667 os = octave_stream_list::lookup (args(0), "fprintf"); |
2873
|
668 } |
2095
|
669 |
3341
|
670 if (! error_state) |
2095
|
671 { |
2873
|
672 if (args(fmt_n).is_string ()) |
2095
|
673 { |
3523
|
674 std::string fmt = args(fmt_n).string_value (); |
2095
|
675 |
|
676 octave_value_list tmp_args; |
|
677 |
2873
|
678 if (nargin > 1 + fmt_n) |
2095
|
679 { |
2873
|
680 tmp_args.resize (nargin-fmt_n-1, octave_value ()); |
2095
|
681 |
2873
|
682 for (int i = fmt_n + 1; i < nargin; i++) |
|
683 tmp_args(i-fmt_n-1) = args(i); |
2095
|
684 } |
|
685 |
3340
|
686 retval = os.printf (fmt, tmp_args); |
2095
|
687 } |
|
688 else |
|
689 ::error ("fprintf: format must be a string"); |
|
690 } |
|
691 } |
|
692 else |
1181
|
693 print_usage ("fprintf"); |
|
694 |
3737
|
695 if (return_char_count) |
|
696 return retval; |
|
697 else |
|
698 return octave_value(); |
1181
|
699 } |
|
700 |
2095
|
701 DEFUN (fputs, args, , |
3372
|
702 "-*- texinfo -*-\n\ |
|
703 @deftypefn {Built-in Function} {} fputs (@var{fid}, @var{string})\n\ |
|
704 Write a string to a file with no formatting.\n\ |
|
705 @end deftypefn") |
1181
|
706 { |
4233
|
707 octave_value retval = -1; |
1181
|
708 |
|
709 int nargin = args.length (); |
|
710 |
2095
|
711 if (nargin == 2) |
|
712 { |
3341
|
713 octave_stream os = octave_stream_list::lookup (args(0), "fputs"); |
1181
|
714 |
3341
|
715 if (! error_state) |
3340
|
716 retval = os.puts (args(1)); |
2095
|
717 } |
1181
|
718 else |
2095
|
719 print_usage ("fputs"); |
1181
|
720 |
|
721 return retval; |
|
722 } |
|
723 |
2095
|
724 DEFUN (sprintf, args, , |
3372
|
725 "-*- texinfo -*-\n\ |
|
726 @deftypefn {Built-in Function} {} sprintf (@var{template}, @dots{})\n\ |
|
727 This is like @code{printf}, except that the output is returned as a\n\ |
|
728 string. Unlike the C library function, which requires you to provide a\n\ |
|
729 suitably sized string as an argument, Octave's @code{sprintf} function\n\ |
|
730 returns the string, automatically sized to hold all of the items\n\ |
|
731 converted.\n\ |
|
732 @end deftypefn") |
1
|
733 { |
2095
|
734 octave_value_list retval; |
1
|
735 |
2095
|
736 int nargin = args.length (); |
1
|
737 |
2095
|
738 if (nargin > 0) |
1
|
739 { |
2116
|
740 retval(2) = -1.0; |
|
741 retval(1) = "unknown error"; |
|
742 retval(0) = ""; |
|
743 |
3340
|
744 octave_ostrstream *ostr = new octave_ostrstream (); |
1
|
745 |
3340
|
746 octave_stream os (ostr); |
628
|
747 |
3340
|
748 if (os.is_valid ()) |
2095
|
749 { |
|
750 if (args(0).is_string ()) |
|
751 { |
3523
|
752 std::string fmt = args(0).string_value (); |
628
|
753 |
2095
|
754 octave_value_list tmp_args; |
1
|
755 |
2095
|
756 if (nargin > 1) |
|
757 { |
|
758 tmp_args.resize (nargin-1, octave_value ()); |
1
|
759 |
2095
|
760 for (int i = 1; i < nargin; i++) |
|
761 tmp_args(i-1) = args(i); |
|
762 } |
628
|
763 |
4233
|
764 retval(2) = os.printf (fmt, tmp_args); |
2095
|
765 retval(1) = os.error (); |
3340
|
766 retval(0) = ostr->str (); |
2095
|
767 } |
|
768 else |
|
769 ::error ("sprintf: format must be a string"); |
|
770 } |
|
771 else |
|
772 ::error ("sprintf: unable to create output buffer"); |
1
|
773 } |
|
774 else |
2095
|
775 print_usage ("sprintf"); |
1
|
776 |
|
777 return retval; |
|
778 } |
|
779 |
2095
|
780 DEFUN (fscanf, args, , |
3372
|
781 "-*- texinfo -*-\n\ |
|
782 @deftypefn {Built-in Function} {[@var{val}, @var{count}] =} fscanf (@var{fid}, @var{template}, @var{size})\n\ |
3491
|
783 @deftypefnx {Built-in Function} {[@var{v1}, @var{v2}, @dots{}, @var{count}] = } fscanf (@var{fid}, @var{template}, \"C\")\n\ |
3372
|
784 In the first form, read from @var{fid} according to @var{template},\n\ |
|
785 returning the result in the matrix @var{val}.\n\ |
2122
|
786 \n\ |
3372
|
787 The optional argument @var{size} specifies the amount of data to read\n\ |
|
788 and may be one of\n\ |
|
789 \n\ |
|
790 @table @code\n\ |
|
791 @item Inf\n\ |
|
792 Read as much as possible, returning a column vector.\n\ |
|
793 \n\ |
|
794 @item @var{nr}\n\ |
|
795 Read up to @var{nr} elements, returning a column vector.\n\ |
2122
|
796 \n\ |
3372
|
797 @item [@var{nr}, Inf]\n\ |
|
798 Read as much as possible, returning a matrix with @var{nr} rows. If the\n\ |
|
799 number of elements read is not an exact multiple of @var{nr}, the last\n\ |
|
800 column is padded with zeros.\n\ |
|
801 \n\ |
|
802 @item [@var{nr}, @var{nc}]\n\ |
|
803 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with\n\ |
|
804 @var{nr} rows. If the number of elements read is not an exact multiple\n\ |
|
805 of @var{nr}, the last column is padded with zeros.\n\ |
|
806 @end table\n\ |
2122
|
807 \n\ |
3372
|
808 @noindent\n\ |
|
809 If @var{size} is omitted, a value of @code{Inf} is assumed.\n\ |
2122
|
810 \n\ |
3372
|
811 A string is returned if @var{template} specifies only character\n\ |
|
812 conversions.\n\ |
2215
|
813 \n\ |
3372
|
814 The number of items successfully read is returned in @var{count}.\n\ |
2215
|
815 \n\ |
3372
|
816 In the second form, read from @var{fid} according to @var{template},\n\ |
|
817 with each conversion specifier in @var{template} corresponding to a\n\ |
|
818 single scalar return value. This form is more `C-like', and also\n\ |
3491
|
819 compatible with previous versions of Octave. The number of successful\n\ |
|
820 conversions is returned in @var{count}\n\ |
3372
|
821 @end deftypefn") |
1181
|
822 { |
2095
|
823 octave_value_list retval; |
1181
|
824 |
|
825 int nargin = args.length (); |
|
826 |
2215
|
827 if (nargin == 3 && args(2).is_string ()) |
2095
|
828 { |
3341
|
829 octave_stream os = octave_stream_list::lookup (args(0), "fscanf"); |
1181
|
830 |
3341
|
831 if (! error_state) |
2095
|
832 { |
|
833 if (args(1).is_string ()) |
|
834 { |
3523
|
835 std::string fmt = args(1).string_value (); |
1181
|
836 |
3340
|
837 retval = os.oscanf (fmt); |
2095
|
838 } |
|
839 else |
|
840 ::error ("fscanf: format must be a string"); |
|
841 } |
|
842 } |
1181
|
843 else |
2215
|
844 { |
|
845 retval (1) = 0.0; |
|
846 retval (0) = Matrix (); |
|
847 |
|
848 if (nargin == 2 || nargin == 3) |
|
849 { |
3341
|
850 octave_stream os = octave_stream_list::lookup (args(0), "fscanf"); |
2215
|
851 |
3342
|
852 if (! error_state) |
2215
|
853 { |
|
854 if (args(1).is_string ()) |
|
855 { |
3523
|
856 std::string fmt = args(1).string_value (); |
2215
|
857 |
|
858 int count = 0; |
|
859 |
3810
|
860 Array<double> size = (nargin == 3) |
4102
|
861 ? args(2).vector_value () |
|
862 : Array<double> (1, lo_ieee_inf_value ()); |
2215
|
863 |
|
864 if (! error_state) |
|
865 { |
3340
|
866 octave_value tmp = os.scanf (fmt, size, count); |
2215
|
867 |
4233
|
868 retval(1) = count; |
2215
|
869 retval(0) = tmp; |
|
870 } |
|
871 } |
|
872 else |
|
873 ::error ("fscanf: format must be a string"); |
|
874 } |
|
875 } |
|
876 else |
|
877 print_usage ("fscanf"); |
|
878 } |
1181
|
879 |
|
880 return retval; |
|
881 } |
|
882 |
2095
|
883 DEFUN (sscanf, args, , |
3372
|
884 "-*- texinfo -*-\n\ |
|
885 @deftypefn {Built-in Function} {[@var{val}, @var{count}] =} sscanf (@var{string}, @var{template}, @var{size})\n\ |
3491
|
886 @deftypefnx {Built-in Function} {[@var{v1}, @var{v2}, @dots{}, @var{count}] = } sscanf (@var{string}, @var{template}, \"C\")\n\ |
3372
|
887 This is like @code{fscanf}, except that the characters are taken from the\n\ |
|
888 string @var{string} instead of from a stream. Reaching the end of the\n\ |
|
889 string is treated as an end-of-file condition.\n\ |
|
890 @end deftypefn") |
444
|
891 { |
2095
|
892 octave_value_list retval; |
444
|
893 |
506
|
894 int nargin = args.length (); |
|
895 |
2215
|
896 if (nargin == 3 && args(2).is_string ()) |
2095
|
897 { |
|
898 if (args(0).is_string ()) |
|
899 { |
3523
|
900 std::string data = args(0).string_value (); |
444
|
901 |
3340
|
902 octave_stream os = octave_istrstream::create (data); |
1358
|
903 |
3340
|
904 if (os.is_valid ()) |
2095
|
905 { |
|
906 if (args(1).is_string ()) |
|
907 { |
3523
|
908 std::string fmt = args(1).string_value (); |
444
|
909 |
2215
|
910 retval = os.oscanf (fmt); |
2095
|
911 } |
|
912 else |
|
913 ::error ("sscanf: format must be a string"); |
|
914 } |
|
915 else |
|
916 ::error ("sscanf: unable to create temporary input buffer"); |
444
|
917 } |
636
|
918 else |
2095
|
919 ::error ("sscanf: first argument must be a string"); |
444
|
920 } |
|
921 else |
2215
|
922 { |
|
923 if (nargin == 2 || nargin == 3) |
|
924 { |
|
925 retval(3) = -1.0; |
|
926 retval(2) = "unknown error"; |
|
927 retval(1) = 0.0; |
|
928 retval(0) = Matrix (); |
|
929 |
|
930 if (args(0).is_string ()) |
|
931 { |
3523
|
932 std::string data = args(0).string_value (); |
2215
|
933 |
3340
|
934 octave_stream os = octave_istrstream::create (data); |
2215
|
935 |
3340
|
936 if (os.is_valid ()) |
2215
|
937 { |
|
938 if (args(1).is_string ()) |
|
939 { |
3523
|
940 std::string fmt = args(1).string_value (); |
2215
|
941 |
|
942 int count = 0; |
|
943 |
3810
|
944 Array<double> size = (nargin == 3) |
|
945 ? args(2).vector_value () |
4102
|
946 : Array<double> (1, lo_ieee_inf_value ()); |
2215
|
947 |
|
948 octave_value tmp = os.scanf (fmt, size, count); |
|
949 |
|
950 // XXX FIXME XXX -- is this the right thing to do? |
|
951 // Extract error message first, because getting |
|
952 // position will clear it. |
3523
|
953 std::string errmsg = os.error (); |
2215
|
954 |
4254
|
955 retval(3) = os.tell () + 1; |
2215
|
956 retval(2) = errmsg; |
4233
|
957 retval(1) = count; |
2215
|
958 retval(0) = tmp; |
|
959 } |
|
960 else |
|
961 ::error ("sscanf: format must be a string"); |
|
962 } |
|
963 else |
|
964 ::error ("sscanf: unable to create temporary input buffer"); |
|
965 } |
|
966 else |
|
967 ::error ("sscanf: first argument must be a string"); |
|
968 } |
|
969 else |
|
970 print_usage ("sscanf"); |
|
971 } |
444
|
972 |
|
973 return retval; |
|
974 } |
|
975 |
2215
|
976 DEFUN (scanf, args, nargout, |
3372
|
977 "-*- texinfo -*-\n\ |
|
978 @deftypefn {Built-in Function} {[@var{val}, @var{count}] =} scanf (@var{template}, @var{size})\n\ |
3491
|
979 @deftypefnx {Built-in Function} {[@var{v1}, @var{v2}, @dots{}, @var{count}]] = } scanf (@var{template}, \"C\")\n\ |
3372
|
980 This is equivalent to calling @code{fscanf} with @var{fid} = @code{stdin}.\n\ |
|
981 \n\ |
|
982 It is currently not useful to call @code{scanf} in interactive\n\ |
|
983 programs.\n\ |
|
984 @end deftypefn") |
2215
|
985 { |
|
986 int nargin = args.length (); |
|
987 |
|
988 octave_value_list tmp_args (nargin+1, octave_value ()); |
|
989 |
|
990 tmp_args (0) = 0.0; |
|
991 for (int i = 0; i < nargin; i++) |
|
992 tmp_args (i+1) = args (i); |
|
993 |
|
994 return Ffscanf (tmp_args, nargout); |
|
995 } |
|
996 |
2116
|
997 static octave_value |
|
998 do_fread (octave_stream& os, const octave_value& size_arg, |
|
999 const octave_value& prec_arg, const octave_value& skip_arg, |
|
1000 const octave_value& arch_arg, int& count) |
|
1001 { |
|
1002 octave_value retval; |
|
1003 |
|
1004 count = -1; |
|
1005 |
3810
|
1006 Array<double> size = size_arg.vector_value (); |
2116
|
1007 |
|
1008 if (! error_state) |
|
1009 { |
3523
|
1010 std::string prec = prec_arg.string_value (); |
2116
|
1011 |
|
1012 if (! error_state) |
|
1013 { |
2318
|
1014 oct_data_conv::data_type dt |
|
1015 = oct_data_conv::string_to_data_type (prec); |
2116
|
1016 |
|
1017 if (! error_state) |
|
1018 { |
3202
|
1019 int skip = skip_arg.int_value (true); |
2116
|
1020 |
|
1021 if (! error_state) |
|
1022 { |
3523
|
1023 std::string arch = arch_arg.string_value (); |
3202
|
1024 |
|
1025 if (! error_state) |
2116
|
1026 { |
3202
|
1027 oct_mach_info::float_format flt_fmt |
|
1028 = oct_mach_info::string_to_float_format (arch); |
2116
|
1029 |
|
1030 if (! error_state) |
3202
|
1031 retval = os.read (size, dt, skip, flt_fmt, count); |
2116
|
1032 } |
|
1033 else |
3202
|
1034 ::error ("fread: architecture type must be a string"); |
2116
|
1035 } |
|
1036 else |
3202
|
1037 ::error ("fread: skip must be an integer"); |
2116
|
1038 } |
|
1039 else |
|
1040 ::error ("fread: invalid data type specified"); |
|
1041 } |
|
1042 else |
|
1043 ::error ("fread: precision must be a string"); |
|
1044 } |
|
1045 else |
|
1046 ::error ("fread: invalid size specified"); |
|
1047 |
|
1048 return retval; |
|
1049 } |
|
1050 |
|
1051 DEFUN (fread, args, , |
3372
|
1052 "-*- texinfo -*-\n\ |
|
1053 @deftypefn {Built-in Function} {[@var{val}, @var{count}] =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip}, @var{arch})\n\ |
|
1054 Read binary data of type @var{precision} from the specified file ID\n\ |
|
1055 @var{fid}.\n\ |
|
1056 \n\ |
|
1057 The optional argument @var{size} specifies the amount of data to read\n\ |
|
1058 and may be one of\n\ |
|
1059 \n\ |
|
1060 @table @code\n\ |
|
1061 @item Inf\n\ |
|
1062 Read as much as possible, returning a column vector.\n\ |
529
|
1063 \n\ |
3372
|
1064 @item @var{nr}\n\ |
|
1065 Read up to @var{nr} elements, returning a column vector.\n\ |
|
1066 \n\ |
|
1067 @item [@var{nr}, Inf]\n\ |
|
1068 Read as much as possible, returning a matrix with @var{nr} rows. If the\n\ |
|
1069 number of elements read is not an exact multiple of @var{nr}, the last\n\ |
|
1070 column is padded with zeros.\n\ |
|
1071 \n\ |
|
1072 @item [@var{nr}, @var{nc}]\n\ |
|
1073 Read up to @code{@var{nr} * @var{nc}} elements, returning a matrix with\n\ |
|
1074 @var{nr} rows. If the number of elements read is not an exact multiple\n\ |
|
1075 of @var{nr}, the last column is padded with zeros.\n\ |
|
1076 @end table\n\ |
|
1077 \n\ |
|
1078 @noindent\n\ |
|
1079 If @var{size} is omitted, a value of @code{Inf} is assumed.\n\ |
2318
|
1080 \n\ |
3372
|
1081 The optional argument @var{precision} is a string specifying the type of\n\ |
|
1082 data to read and may be one of\n\ |
|
1083 \n\ |
|
1084 @table @code\n\ |
|
1085 @item \"char\"\n\ |
|
1086 @itemx \"char*1\"\n\ |
|
1087 @itemx \"integer*1\"\n\ |
|
1088 @itemx \"int8\"\n\ |
|
1089 Single character.\n\ |
|
1090 \n\ |
|
1091 @item \"signed char\"\n\ |
|
1092 @itemx \"schar\"\n\ |
|
1093 Signed character.\n\ |
529
|
1094 \n\ |
3372
|
1095 @item \"unsigned char\"\n\ |
|
1096 @itemx \"uchar\"\n\ |
|
1097 Unsigned character.\n\ |
|
1098 \n\ |
|
1099 @item \"short\"\n\ |
|
1100 Short integer.\n\ |
2318
|
1101 \n\ |
3372
|
1102 @item \"unsigned short\"\n\ |
|
1103 @itemx \"ushort\"\n\ |
|
1104 Unsigned short integer.\n\ |
|
1105 \n\ |
|
1106 @item \"int\"\n\ |
|
1107 Integer.\n\ |
|
1108 \n\ |
|
1109 @item \"unsigned int\"\n\ |
|
1110 @itemx \"uint\"\n\ |
|
1111 Unsigned integer.\n\ |
529
|
1112 \n\ |
3372
|
1113 @item \"long\"\n\ |
|
1114 Long integer.\n\ |
|
1115 \n\ |
|
1116 @item \"unsigned long\"\n\ |
|
1117 @itemx \"ulong\"\n\ |
|
1118 Unsigned long integer.\n\ |
|
1119 \n\ |
|
1120 @item \"float\"\n\ |
|
1121 @itemx \"float32\"\n\ |
|
1122 @itemx \"real*4\"\n\ |
|
1123 Single precision float.\n\ |
|
1124 \n\ |
|
1125 @item \"double\"\n\ |
|
1126 @itemx \"float64\"\n\ |
|
1127 @itemx \"real*8\"\n\ |
|
1128 Double precision float.\n\ |
|
1129 \n\ |
|
1130 @item \"integer*2\"\n\ |
|
1131 @itemx \"int16\"\n\ |
|
1132 Two byte integer.\n\ |
|
1133 \n\ |
|
1134 @item \"integer*4\"\n\ |
|
1135 @itemx \"int32\"\n\ |
|
1136 Four byte integer.\n\ |
|
1137 @end table\n\ |
|
1138 \n\ |
|
1139 @noindent\n\ |
|
1140 The default precision is @code{\"uchar\"}.\n\ |
2318
|
1141 \n\ |
3372
|
1142 The optional argument @var{skip} specifies the number of bytes to skip\n\ |
4101
|
1143 after each element is read. If it is not specified, a value of 0 is\n\ |
3372
|
1144 assumed.\n\ |
|
1145 \n\ |
|
1146 The optional argument @var{arch} is a string specifying the data format\n\ |
|
1147 for the file. Valid values are\n\ |
529
|
1148 \n\ |
3372
|
1149 @table @code\n\ |
|
1150 @item \"native\"\n\ |
|
1151 The format of the current machine.\n\ |
|
1152 \n\ |
|
1153 @item \"ieee-le\"\n\ |
|
1154 IEEE big endian.\n\ |
|
1155 \n\ |
|
1156 @item \"ieee-be\"\n\ |
|
1157 IEEE little endian.\n\ |
2318
|
1158 \n\ |
3372
|
1159 @item \"vaxd\"\n\ |
|
1160 VAX D floating format.\n\ |
|
1161 \n\ |
|
1162 @item \"vaxg\"\n\ |
|
1163 VAX G floating format.\n\ |
2318
|
1164 \n\ |
3372
|
1165 @item \"cray\"\n\ |
|
1166 Cray floating format.\n\ |
|
1167 @end table\n\ |
2318
|
1168 \n\ |
3372
|
1169 @noindent\n\ |
|
1170 Conversions are currently only supported for @code{\"ieee-be\"} and\n\ |
|
1171 @code{\"ieee-le\"} formats.\n\ |
2318
|
1172 \n\ |
3372
|
1173 The data read from the file is returned in @var{val}, and the number of\n\ |
|
1174 values read is returned in @code{count}\n\ |
|
1175 @end deftypefn") |
529
|
1176 { |
2095
|
1177 octave_value_list retval; |
2116
|
1178 |
|
1179 int nargin = args.length (); |
|
1180 |
2318
|
1181 if (nargin > 0 && nargin < 6) |
2116
|
1182 { |
|
1183 retval(1) = -1.0; |
|
1184 retval(0) = Matrix (); |
|
1185 |
3341
|
1186 octave_stream os = octave_stream_list::lookup (args(0), "fread"); |
2116
|
1187 |
3341
|
1188 if (! error_state) |
2116
|
1189 { |
4257
|
1190 octave_value size = lo_ieee_inf_value (); |
|
1191 octave_value prec = "uchar"; |
|
1192 octave_value skip = 0; |
|
1193 octave_value arch = "unknown"; |
2116
|
1194 |
4257
|
1195 int idx = 1; |
2116
|
1196 |
4257
|
1197 if (nargin > 1 && ! args(idx).is_string ()) |
|
1198 size = args(idx++); |
|
1199 |
|
1200 if (nargin > idx) |
|
1201 prec = args(idx++); |
2116
|
1202 |
4257
|
1203 if (nargin > idx) |
|
1204 skip = args(idx++); |
|
1205 |
|
1206 if (nargin > idx) |
|
1207 arch = args(idx++); |
2116
|
1208 |
|
1209 int count = -1; |
|
1210 |
3340
|
1211 octave_value tmp = do_fread (os, size, prec, skip, arch, count); |
2116
|
1212 |
4233
|
1213 retval(1) = count; |
2116
|
1214 retval(0) = tmp; |
|
1215 } |
|
1216 } |
|
1217 else |
|
1218 print_usage ("fread"); |
|
1219 |
529
|
1220 return retval; |
|
1221 } |
|
1222 |
2116
|
1223 static int |
|
1224 do_fwrite (octave_stream& os, const octave_value& data, |
|
1225 const octave_value& prec_arg, const octave_value& skip_arg, |
|
1226 const octave_value& arch_arg) |
|
1227 { |
|
1228 int retval = -1; |
|
1229 |
3523
|
1230 std::string prec = prec_arg.string_value (); |
2116
|
1231 |
|
1232 if (! error_state) |
|
1233 { |
2318
|
1234 oct_data_conv::data_type dt |
|
1235 = oct_data_conv::string_to_data_type (prec); |
2116
|
1236 |
|
1237 if (! error_state) |
|
1238 { |
3202
|
1239 int skip = skip_arg.int_value (true); |
2116
|
1240 |
|
1241 if (! error_state) |
|
1242 { |
3523
|
1243 std::string arch = arch_arg.string_value (); |
3202
|
1244 |
|
1245 if (! error_state) |
2116
|
1246 { |
3202
|
1247 oct_mach_info::float_format flt_fmt |
|
1248 = oct_mach_info::string_to_float_format (arch); |
2116
|
1249 |
|
1250 if (! error_state) |
3202
|
1251 retval = os.write (data, dt, skip, flt_fmt); |
2116
|
1252 } |
|
1253 else |
3202
|
1254 ::error ("fwrite: architecture type must be a string"); |
2116
|
1255 } |
|
1256 else |
3202
|
1257 ::error ("fwrite: skip must be an integer"); |
2116
|
1258 } |
3202
|
1259 else |
|
1260 ::error ("fwrite: invalid precision specified"); |
2116
|
1261 } |
|
1262 else |
|
1263 ::error ("fwrite: precision must be a string"); |
|
1264 |
|
1265 return retval; |
|
1266 } |
|
1267 |
|
1268 DEFUN (fwrite, args, , |
3372
|
1269 "-*- texinfo -*-\n\ |
|
1270 @deftypefn {Built-in Function} {@var{count} =} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip}, @var{arch})\n\ |
|
1271 Write data in binary form of type @var{precision} to the specified file\n\ |
|
1272 ID @var{fid}, returning the number of values successfully written to the\n\ |
|
1273 file.\n\ |
1181
|
1274 \n\ |
3372
|
1275 The argument @var{data} is a matrix of values that are to be written to\n\ |
|
1276 the file. The values are extracted in column-major order.\n\ |
1181
|
1277 \n\ |
3372
|
1278 The remaining arguments @var{precision}, @var{skip}, and @var{arch} are\n\ |
|
1279 optional, and are interpreted as described for @code{fread}.\n\ |
1181
|
1280 \n\ |
3372
|
1281 The behavior of @code{fwrite} is undefined if the values in @var{data}\n\ |
|
1282 are too large to fit in the specified precision.\n\ |
|
1283 @end deftypefn") |
1181
|
1284 { |
4233
|
1285 octave_value retval = -1; |
2116
|
1286 |
|
1287 int nargin = args.length (); |
|
1288 |
|
1289 if (nargin > 1 && nargin < 6) |
|
1290 { |
3341
|
1291 octave_stream os = octave_stream_list::lookup (args(0), "fwrite"); |
2116
|
1292 |
3341
|
1293 if (! error_state) |
2116
|
1294 { |
|
1295 octave_value data = args(1); |
2318
|
1296 |
|
1297 octave_value prec = (nargin > 2) |
|
1298 ? args(2) : octave_value ("uchar"); |
|
1299 |
|
1300 octave_value skip = (nargin > 3) |
|
1301 ? args(3) : octave_value (0.0); |
|
1302 |
|
1303 octave_value arch = (nargin > 4) |
|
1304 ? args(4) : octave_value ("unknown"); |
2116
|
1305 |
3340
|
1306 double status = do_fwrite (os, data, prec, skip, arch); |
2825
|
1307 |
|
1308 retval = status; |
2116
|
1309 } |
|
1310 } |
|
1311 else |
|
1312 print_usage ("fwrite"); |
|
1313 |
1181
|
1314 return retval; |
|
1315 } |
|
1316 |
1957
|
1317 DEFUN (feof, args, , |
3372
|
1318 "-*- texinfo -*-\n\ |
|
1319 @deftypefn {Built-in Function} {} feof (@var{fid})\n\ |
|
1320 Return 1 if an end-of-file condition has been encountered for a given\n\ |
|
1321 file and 0 otherwise. Note that it will only return 1 if the end of the\n\ |
|
1322 file has already been encountered, not if the next read operation will\n\ |
|
1323 result in an end-of-file condition.\n\ |
|
1324 @end deftypefn") |
529
|
1325 { |
4233
|
1326 octave_value retval = -1; |
529
|
1327 |
|
1328 int nargin = args.length (); |
|
1329 |
2095
|
1330 if (nargin == 1) |
|
1331 { |
3341
|
1332 octave_stream os = octave_stream_list::lookup (args(0), "feof"); |
444
|
1333 |
3341
|
1334 if (! error_state) |
3340
|
1335 retval = os.eof () ? 1.0 : 0.0; |
2095
|
1336 } |
529
|
1337 else |
2095
|
1338 print_usage ("feof"); |
444
|
1339 |
|
1340 return retval; |
|
1341 } |
|
1342 |
2095
|
1343 DEFUN (ferror, args, , |
3372
|
1344 "-*- texinfo -*-\n\ |
|
1345 @deftypefn {Built-in Function} {} ferror (@var{fid})\n\ |
|
1346 Return 1 if an error condition has been encountered for a given file\n\ |
|
1347 and 0 otherwise. Note that it will only return 1 if an error has\n\ |
|
1348 already been encountered, not if the next operation will result in an\n\ |
|
1349 error condition.\n\ |
|
1350 @end deftypefn") |
1230
|
1351 { |
2095
|
1352 octave_value_list retval; |
1230
|
1353 |
2095
|
1354 int nargin = args.length (); |
1230
|
1355 |
2095
|
1356 if (nargin == 1 || nargin == 2) |
|
1357 { |
3341
|
1358 octave_stream os = octave_stream_list::lookup (args(0), "ferror"); |
1230
|
1359 |
3341
|
1360 if (! error_state) |
2095
|
1361 { |
|
1362 bool clear = false; |
1230
|
1363 |
2095
|
1364 if (nargin == 2) |
|
1365 { |
3523
|
1366 std::string opt = args(1).string_value (); |
2095
|
1367 |
|
1368 if (! error_state) |
|
1369 clear = (opt == "clear"); |
|
1370 else |
|
1371 return retval; |
|
1372 } |
1755
|
1373 |
2095
|
1374 int error_number = 0; |
|
1375 |
3523
|
1376 std::string error_message = os.error (clear, error_number); |
1230
|
1377 |
4233
|
1378 retval(1) = error_number; |
2095
|
1379 retval(0) = error_message; |
|
1380 } |
1230
|
1381 } |
2095
|
1382 else |
|
1383 print_usage ("ferror"); |
1230
|
1384 |
|
1385 return retval; |
|
1386 } |
|
1387 |
1957
|
1388 DEFUN (popen, args, , |
3301
|
1389 "-*- texinfo -*-\n\ |
4326
|
1390 @deftypefn {Built-in Function} {@var{fid} =} popen (@var{command}, @var{mode})\n\ |
3301
|
1391 Start a process and create a pipe. The name of the command to run is\n\ |
|
1392 given by @var{command}. The file identifier corresponding to the input\n\ |
|
1393 or output stream of the process is returned in @var{fid}. The argument\n\ |
|
1394 @var{mode} may be\n\ |
|
1395 \n\ |
|
1396 @table @code\n\ |
|
1397 @item \"r\"\n\ |
|
1398 The pipe will be connected to the standard output of the process, and\n\ |
|
1399 open for reading.\n\ |
1230
|
1400 \n\ |
3301
|
1401 @item \"w\"\n\ |
|
1402 The pipe will be connected to the standard input of the process, and\n\ |
|
1403 open for writing.\n\ |
|
1404 @end table\n\ |
|
1405 \n\ |
|
1406 For example,\n\ |
1230
|
1407 \n\ |
3301
|
1408 @example\n\ |
|
1409 @group\n\ |
|
1410 fid = popen (\"ls -ltr / | tail -3\", \"r\");\n\ |
|
1411 while (isstr (s = fgets (fid)))\n\ |
|
1412 fputs (stdout, s);\n\ |
|
1413 endwhile\n\ |
|
1414 @print{} drwxr-xr-x 33 root root 3072 Feb 15 13:28 etc\n\ |
|
1415 @print{} drwxr-xr-x 3 root root 1024 Feb 15 13:28 lib\n\ |
|
1416 @print{} drwxrwxrwt 15 root root 2048 Feb 17 14:53 tmp\n\ |
|
1417 @end group\n\ |
|
1418 @end example\n\ |
|
1419 @end deftypefn") |
1230
|
1420 { |
4233
|
1421 octave_value retval = -1; |
1230
|
1422 |
|
1423 int nargin = args.length (); |
|
1424 |
2095
|
1425 if (nargin == 2) |
|
1426 { |
3523
|
1427 std::string name = args(0).string_value (); |
1230
|
1428 |
2095
|
1429 if (! error_state) |
|
1430 { |
3523
|
1431 std::string mode = args(1).string_value (); |
1230
|
1432 |
2095
|
1433 if (! error_state) |
|
1434 { |
|
1435 if (mode == "r") |
|
1436 { |
3340
|
1437 octave_stream ips = octave_iprocstream::create (name); |
1230
|
1438 |
2095
|
1439 retval = octave_stream_list::insert (ips); |
|
1440 } |
|
1441 else if (mode == "w") |
|
1442 { |
3340
|
1443 octave_stream ops = octave_oprocstream::create (name); |
1230
|
1444 |
2095
|
1445 retval = octave_stream_list::insert (ops); |
|
1446 } |
|
1447 else |
|
1448 ::error ("popen: invalid mode specified"); |
|
1449 } |
|
1450 else |
|
1451 ::error ("popen: mode must be a string"); |
|
1452 } |
|
1453 else |
|
1454 ::error ("popen: name must be a string"); |
|
1455 } |
1230
|
1456 else |
2095
|
1457 print_usage ("popen"); |
1230
|
1458 |
|
1459 return retval; |
|
1460 } |
|
1461 |
1957
|
1462 DEFUN (pclose, args, , |
3381
|
1463 "-*- texinfo -*-\n\ |
3301
|
1464 @deftypefn {Built-in Function} {} pclose (@var{fid})\n\ |
|
1465 Close a file identifier that was opened by @code{popen}. You may also\n\ |
|
1466 use @code{fclose} for the same purpose.\n\ |
|
1467 @end deftypefn") |
1230
|
1468 { |
4233
|
1469 octave_value retval = -1; |
1230
|
1470 |
|
1471 int nargin = args.length (); |
|
1472 |
2095
|
1473 if (nargin == 1) |
4233
|
1474 retval = octave_stream_list::remove (args(0), "pclose"); |
1377
|
1475 else |
2095
|
1476 print_usage ("pclose"); |
1379
|
1477 |
|
1478 return retval; |
|
1479 } |
|
1480 |
2458
|
1481 DEFUN (tmpnam, args, , |
3372
|
1482 "-*- texinfo -*-\n\ |
4267
|
1483 @deftypefn {Built-in Function} {} tmpnam (@var{dir}, @var{prefix})\n\ |
3372
|
1484 Return a unique temporary file name as a string.\n\ |
|
1485 \n\ |
4267
|
1486 If @var{prefix} is omitted, a value of @code{\"oct-\"} is used.\n\ |
|
1487 If @var{dir} is also omitted, the default directory for temporary files\n\ |
|
1488 is used. If @var{dir} is provided, it must exist, otherwise the default\n\ |
|
1489 directory for temporary files is used. Since the named file is not\n\ |
|
1490 opened, by @code{tmpnam}, it is possible (though relatively unlikely)\n\ |
|
1491 that it will not be available by the time your program attempts to open it.\n\ |
4326
|
1492 @end deftypefn\n\ |
|
1493 @seealso{tmpfile, mkstemp, and P_tmpdir}") |
1802
|
1494 { |
2095
|
1495 octave_value retval; |
1802
|
1496 |
2936
|
1497 int len = args.length (); |
|
1498 |
|
1499 if (len < 3) |
|
1500 { |
3523
|
1501 std::string dir = len > 0 ? args(0).string_value () : std::string (); |
2936
|
1502 |
|
1503 if (! error_state) |
4267
|
1504 { |
|
1505 std::string pfx |
|
1506 = len > 1 ? args(1).string_value () : std::string ("oct-"); |
|
1507 |
|
1508 if (! error_state) |
|
1509 retval = file_ops::tempnam (dir, pfx); |
|
1510 else |
|
1511 ::error ("expecting second argument to be a string"); |
|
1512 } |
|
1513 else |
|
1514 ::error ("expecting first argument to be a string"); |
2936
|
1515 } |
1802
|
1516 else |
2458
|
1517 print_usage ("tmpnam"); |
1802
|
1518 |
|
1519 return retval; |
|
1520 } |
|
1521 |
2458
|
1522 DEFALIAS (octave_tmp_file_name, tmpnam); |
|
1523 |
4326
|
1524 DEFUN (tmpfile, args, , |
|
1525 "-*- texinfo -*-\n\ |
|
1526 @deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} tmpfile ()\n\ |
|
1527 Return the file ID corresponding to a new temporary file with a unique\n\ |
|
1528 name. The file is opened in binary read/write (@code{\"w+b\"}) mode.\n\ |
|
1529 The file will be deleted automatically when it is closed or when Octave\n\ |
|
1530 exits.\n\ |
|
1531 \n\ |
|
1532 If successful, @var{fid} is a valid file ID and @var{msg} is an empty\n\ |
|
1533 string. Otherwise, @var{fid} is -1 and @var{msg} contains a\n\ |
|
1534 system-dependent error message.\n\ |
|
1535 @end deftypefn\n\ |
|
1536 @seealso{tmpnam, mkstemp, and P_tmpdir}") |
|
1537 { |
|
1538 octave_value_list retval; |
|
1539 |
|
1540 retval(1) = std::string (); |
|
1541 retval(0) = -1; |
|
1542 |
|
1543 int nargin = args.length (); |
|
1544 |
|
1545 if (nargin == 0) |
|
1546 { |
|
1547 FILE *fid = tmpfile (); |
|
1548 |
|
1549 if (fid) |
|
1550 { |
|
1551 std::string nm; |
|
1552 |
|
1553 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b"); |
|
1554 |
4327
|
1555 octave_stream s = octave_stdiostream::create (nm, fid, md); |
4326
|
1556 |
|
1557 if (s) |
|
1558 retval(0) = octave_stream_list::insert (s); |
|
1559 else |
4327
|
1560 error ("tmpfile: failed to create octave_stdiostream object"); |
4326
|
1561 |
|
1562 } |
|
1563 else |
|
1564 { |
|
1565 using namespace std; |
|
1566 retval(1) = ::strerror (errno); |
|
1567 retval(0) = -1; |
|
1568 } |
|
1569 } |
|
1570 else |
|
1571 print_usage ("tmpfile"); |
|
1572 |
|
1573 return retval; |
|
1574 } |
|
1575 |
|
1576 DEFUN (mkstemp, args, , |
|
1577 "-*- texinfo -*-\n\ |
|
1578 @deftypefn {Built-in Function} {[@var{fid}, @var{name}, @var{msg}] =} tmpfile (@var{template}, @var{delete})\n\ |
|
1579 Return the file ID corresponding to a new temporary file with a unique\n\ |
|
1580 name created from @var{template}. The last six characters of @var{template}\n\ |
|
1581 must be @code{XXXXXX} and tehse are replaced with a string that makes the\n\ |
|
1582 filename unique. The file is then created with mode read/write and\n\ |
|
1583 permissions that are system dependent (on GNU/Linux systems, the permissions\n\ |
|
1584 will be 0600 for versions of glibc 2.0.7 and later). The file is opened\n\ |
|
1585 with the @code{O_EXCL} flag.\n\ |
|
1586 \n\ |
|
1587 If the optional argument @var{delete} is supplied and is true,\n\ |
|
1588 the file will be deleted automatically when Octave exits, or when\n\ |
|
1589 the function @code{purge_tmp_files} is called.\n\ |
|
1590 \n\ |
|
1591 If successful, @var{fid} is a valid file ID, @var{name} is the name of\n\ |
|
1592 the file, and and @var{msg} is an empty string. Otherwise, @var{fid}\n\ |
|
1593 is -1, @var{name} is empty, and @var{msg} contains a system-dependent\n\ |
|
1594 error message.\n\ |
|
1595 @end deftypefn\n\ |
|
1596 @seealso{tmpfile, tmpnam, and P_tmpdir}") |
|
1597 { |
|
1598 octave_value_list retval; |
|
1599 |
|
1600 retval(2) = std::string (); |
|
1601 retval(1) = std::string (); |
|
1602 retval(0) = -1; |
|
1603 |
|
1604 #if defined (HAVE_MKSTEMP) |
|
1605 |
|
1606 int nargin = args.length (); |
|
1607 |
|
1608 if (nargin == 1 || nargin == 2) |
|
1609 { |
|
1610 std::string tmpl8 = args(0).string_value (); |
|
1611 |
|
1612 if (! error_state) |
|
1613 { |
4354
|
1614 OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); |
|
1615 strcpy (tmp, tmpl8.c_str ()); |
4326
|
1616 |
|
1617 int fd = mkstemp (tmp); |
|
1618 |
|
1619 if (fd < 0) |
|
1620 { |
|
1621 using namespace std; |
|
1622 retval(1) = ::strerror (errno); |
|
1623 retval(0) = fd; |
|
1624 } |
|
1625 else |
|
1626 { |
|
1627 const char *fopen_mode = "w+"; |
|
1628 |
|
1629 FILE *fid = fdopen (fd, fopen_mode); |
|
1630 |
|
1631 if (fid) |
|
1632 { |
|
1633 std::string nm = tmp; |
|
1634 |
|
1635 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode); |
|
1636 |
4327
|
1637 octave_stream s = octave_stdiostream::create (nm, fid, md); |
4326
|
1638 |
|
1639 if (s) |
|
1640 { |
|
1641 retval(1) = nm; |
|
1642 retval(0) = octave_stream_list::insert (s); |
|
1643 |
|
1644 if (nargin == 2) |
|
1645 mark_for_deletion (nm); |
|
1646 } |
|
1647 else |
4327
|
1648 error ("mkstemp: failed to create octave_stdiostream object"); |
4326
|
1649 } |
|
1650 else |
|
1651 { |
|
1652 using namespace std; |
|
1653 retval(1) = ::strerror (errno); |
|
1654 retval(0) = -1; |
|
1655 } |
|
1656 } |
|
1657 } |
|
1658 else |
|
1659 error ("mkstemp: expecting string as first argument"); |
|
1660 } |
|
1661 else |
|
1662 print_usage ("mkstemp"); |
|
1663 |
|
1664 #else |
|
1665 retval(2) = "mkstemp: not supported on this sytem"; |
|
1666 #endif |
|
1667 |
|
1668 return retval; |
|
1669 } |
|
1670 |
1400
|
1671 static int |
|
1672 convert (int x, int ibase, int obase) |
|
1673 { |
|
1674 int retval = 0; |
|
1675 |
|
1676 int tmp = x % obase; |
|
1677 |
|
1678 if (tmp > ibase - 1) |
2095
|
1679 ::error ("umask: invalid digit"); |
1400
|
1680 else |
|
1681 { |
|
1682 retval = tmp; |
|
1683 int mult = ibase; |
|
1684 while ((x = (x - tmp) / obase)) |
|
1685 { |
|
1686 tmp = x % obase; |
|
1687 if (tmp > ibase - 1) |
|
1688 { |
2095
|
1689 ::error ("umask: invalid digit"); |
1400
|
1690 break; |
|
1691 } |
|
1692 retval += mult * tmp; |
|
1693 mult *= ibase; |
|
1694 } |
|
1695 } |
|
1696 |
|
1697 return retval; |
|
1698 } |
|
1699 |
1957
|
1700 DEFUN (umask, args, , |
3301
|
1701 "-*- texinfo -*-\n\ |
|
1702 @deftypefn {Built-in Function} {} umask (@var{mask})\n\ |
|
1703 Set the permission mask for file creation. The parameter @var{mask}\n\ |
|
1704 is an integer, interpreted as an octal number. If successful,\n\ |
|
1705 returns the previous value of the mask (as an integer to be\n\ |
|
1706 interpreted as an octal number); otherwise an error message is printed.\n\ |
|
1707 @end deftypefn") |
1400
|
1708 { |
2095
|
1709 octave_value_list retval; |
1400
|
1710 |
|
1711 int status = 0; |
|
1712 |
|
1713 if (args.length () == 1) |
|
1714 { |
3202
|
1715 int mask = args(0).int_value (true); |
1400
|
1716 |
3202
|
1717 if (! error_state) |
1400
|
1718 { |
3202
|
1719 if (mask < 0) |
1400
|
1720 { |
|
1721 status = -1; |
2095
|
1722 ::error ("umask: MASK must be a positive integer value"); |
1400
|
1723 } |
|
1724 else |
|
1725 { |
|
1726 int oct_mask = convert (mask, 8, 10); |
|
1727 |
|
1728 if (! error_state) |
2926
|
1729 status = convert (file_ops::umask (oct_mask), 10, 8); |
1400
|
1730 } |
|
1731 } |
3202
|
1732 else |
|
1733 { |
|
1734 status = -1; |
|
1735 ::error ("umask: expecting integer argument"); |
|
1736 } |
1400
|
1737 } |
|
1738 else |
|
1739 print_usage ("umask"); |
|
1740 |
|
1741 if (status >= 0) |
4233
|
1742 retval(0) = status; |
1400
|
1743 |
|
1744 return retval; |
|
1745 } |
|
1746 |
2189
|
1747 void |
|
1748 symbols_of_file_io (void) |
|
1749 { |
4267
|
1750 #if ! defined (P_tmpdir) |
|
1751 #define P_tmpdir "/tmp" |
|
1752 #endif |
|
1753 |
|
1754 DEFCONSTX ("P_tmpdir", SBV_P_tmpdir, P_tmpdir, |
|
1755 "-*- texinfo -*-\n\ |
|
1756 @defvr {Built-in Variable} P_tmpdir\n\ |
|
1757 The default name of the directory for temporary files on this system.\n\ |
|
1758 of this variable is system dependent.\n\ |
|
1759 @end defvr"); |
|
1760 |
2341
|
1761 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be |
|
1762 // this way for Matlab compatibility. |
|
1763 |
4233
|
1764 DEFCONSTX ("SEEK_SET", SBV_SEEK_SET, -1, |
3372
|
1765 "-*- texinfo -*-\n\ |
|
1766 @defvr {Built-in Variable} SEEK_SET\n\ |
|
1767 @defvrx {Built-in Variable} SEEK_CUR\n\ |
|
1768 @defvrx {Built-in Variable} SEEK_END\n\ |
|
1769 These variables may be used as the optional third argument for the\n\ |
|
1770 function @code{fseek}.\n\ |
|
1771 \n\ |
|
1772 @table @code\n\ |
|
1773 @item SEEK_SET\n\ |
|
1774 Position file relative to the beginning.\n\ |
|
1775 \n\ |
|
1776 @item SEEK_CUR\n\ |
|
1777 Position file relative to the current position.\n\ |
|
1778 \n\ |
|
1779 @item SEEK_END\n\ |
|
1780 used with fseek to position file relative to the end.\n\ |
|
1781 @end table\n\ |
|
1782 @end defvr"); |
2189
|
1783 |
4233
|
1784 DEFCONSTX ("SEEK_CUR", SBV_SEEK_CUR, 0, |
3458
|
1785 "-*- texinfo -*-\n\ |
|
1786 @defvr {Built-in Variable} SEEK_CUR\n\ |
|
1787 See SEEK_SET.\n\ |
|
1788 @end defvr"); |
2189
|
1789 |
4233
|
1790 DEFCONSTX ("SEEK_END", SBV_SEEK_END, 1, |
3458
|
1791 "-*- texinfo -*-\n\ |
|
1792 @defvr {Built-in Variable} SEEK_END\n\ |
|
1793 See SEEK_SET.\n\ |
|
1794 @end defvr"); |
2189
|
1795 |
3141
|
1796 DEFCONSTX ("stdin", SBV_stdin, stdin_file, |
3372
|
1797 "-*- texinfo -*-\n\ |
|
1798 @defvr {Built-in Variable} stdin\n\ |
|
1799 The standard input stream (file id 0). When Octave is used\n\ |
|
1800 interactively, this is filtered through the command line editing\n\ |
|
1801 functions.\n\ |
|
1802 @end defvr"); |
2189
|
1803 |
3141
|
1804 DEFCONSTX ("stdout", SBV_stdout, stdout_file, |
3372
|
1805 "-*- texinfo -*-\n\ |
|
1806 @defvr {Built-in Variable} stdout\n\ |
|
1807 The standard output stream (file id 1). Data written to the\n\ |
|
1808 standard output is normally filtered through the pager.\n\ |
|
1809 @end defvr"); |
2189
|
1810 |
3141
|
1811 DEFCONSTX ("stderr", SBV_stderr, stderr_file, |
3372
|
1812 "-*- texinfo -*-\n\ |
|
1813 @defvr {Built-in Variable} stderr\n\ |
|
1814 The standard error stream (file id 2). Even if paging is turned on,\n\ |
|
1815 the standard error is not sent to the pager. It is useful for error\n\ |
|
1816 messages and prompts.\n\ |
|
1817 @end defvr"); |
|
1818 |
2189
|
1819 } |
|
1820 |
444
|
1821 /* |
1
|
1822 ;;; Local Variables: *** |
|
1823 ;;; mode: C++ *** |
|
1824 ;;; End: *** |
|
1825 */ |