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