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