1
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 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 |
2095
|
43 #include <iostream.h> |
1350
|
44 |
|
45 #ifdef HAVE_UNISTD_H |
1230
|
46 #include <sys/types.h> |
1
|
47 #include <unistd.h> |
1343
|
48 #endif |
1350
|
49 |
1352
|
50 #include "defun.h" |
1
|
51 #include "error.h" |
1766
|
52 #include "file-ops.h" |
542
|
53 #include "help.h" |
2116
|
54 #include "lo-ieee.h" |
2095
|
55 #include "oct-fstrm.h" |
|
56 #include "oct-iostrm.h" |
1377
|
57 #include "oct-map.h" |
1750
|
58 #include "oct-obj.h" |
2095
|
59 #include "oct-prcstrm.h" |
|
60 #include "oct-stream.h" |
|
61 #include "oct-strstrm.h" |
1
|
62 #include "pager.h" |
444
|
63 #include "sysdep.h" |
1352
|
64 #include "syswait.h" |
|
65 #include "utils.h" |
2370
|
66 #include "variables.h" |
1583
|
67 |
1
|
68 void |
164
|
69 initialize_file_io (void) |
1
|
70 { |
2116
|
71 octave_istream *stdin_stream |
|
72 = new octave_istream (&cin, "stdin"); |
|
73 |
|
74 // This uses octave_stdout (see pager.h), not cout so that Octave's |
|
75 // standard output stream will pass through the pager. |
|
76 |
|
77 octave_ostream *stdout_stream |
|
78 = new octave_ostream (&octave_stdout, "stdout"); |
|
79 |
|
80 octave_ostream *stderr_stream |
|
81 = new octave_ostream (&cerr, "stderr"); |
1
|
82 |
2095
|
83 octave_stream_list::insert (stdin_stream); |
|
84 octave_stream_list::insert (stdout_stream); |
|
85 octave_stream_list::insert (stderr_stream); |
1
|
86 } |
|
87 |
2095
|
88 void |
|
89 close_files (void) |
1
|
90 { |
2095
|
91 octave_stream_list::clear (); |
|
92 } |
636
|
93 |
2095
|
94 static void |
|
95 gripe_invalid_file_id (const char *fcn) |
|
96 { |
|
97 ::error ("%s: invalid file id", fcn); |
1
|
98 } |
|
99 |
2095
|
100 static int |
|
101 fopen_mode_to_ios_mode (const string& mode) |
1
|
102 { |
2095
|
103 int retval = 0; |
896
|
104 |
2095
|
105 if (! mode.empty ()) |
368
|
106 { |
2095
|
107 // Could probably be faster, but does it really matter? |
1766
|
108 |
2095
|
109 if (mode == "r") |
|
110 retval = ios::in; |
|
111 else if (mode == "w") |
|
112 retval = ios::out | ios::trunc; |
|
113 else if (mode == "a") |
|
114 retval = ios::out | ios::app; |
|
115 else if (mode == "r+") |
|
116 retval = ios::in | ios::out; |
|
117 else if (mode == "w+") |
|
118 retval = ios::in | ios::out | ios::trunc; |
|
119 else if (mode == "a+") |
|
120 retval = ios::in | ios::out | ios::app; |
|
121 else if (mode == "rb") |
|
122 retval = ios::in | ios::bin; |
|
123 else if (mode == "wb") |
|
124 retval = ios::out | ios::trunc | ios::bin; |
|
125 else if (mode == "ab") |
|
126 retval = ios::out | ios::app | ios::bin; |
|
127 else if (mode == "r+b") |
|
128 retval = ios::in | ios::out | ios::bin; |
|
129 else if (mode == "w+b") |
|
130 retval = ios::in | ios::out | ios::trunc | ios::bin; |
|
131 else if (mode == "a+b") |
|
132 retval = ios::in | ios::out | ios::app | ios::bin; |
368
|
133 else |
2095
|
134 ::error ("invalid mode specified"); |
1
|
135 } |
|
136 |
|
137 return retval; |
|
138 } |
|
139 |
1957
|
140 DEFUN (fclose, args, , |
2116
|
141 "fclose (FILENUM): close a file") |
529
|
142 { |
2095
|
143 double retval = -1.0; |
529
|
144 |
|
145 int nargin = args.length (); |
|
146 |
2095
|
147 if (nargin == 1) |
|
148 { |
|
149 retval = (double) octave_stream_list::remove (args(0)); |
1
|
150 |
2095
|
151 if (retval < 0) |
|
152 gripe_invalid_file_id ("fclose"); |
1
|
153 } |
|
154 else |
2095
|
155 print_usage ("fclose"); |
1
|
156 |
|
157 return retval; |
|
158 } |
|
159 |
1957
|
160 DEFUN (fflush, args, , |
2116
|
161 "fflush (FILENUM): flush buffered data to output file") |
1181
|
162 { |
2095
|
163 double retval = -1.0; |
1181
|
164 |
|
165 int nargin = args.length (); |
|
166 |
2095
|
167 if (nargin == 1) |
|
168 { |
|
169 octave_stream *os = octave_stream_list::lookup (args(0)); |
|
170 |
|
171 if (os) |
|
172 retval = (double) os->flush (); |
|
173 else |
|
174 gripe_invalid_file_id ("fflush"); |
|
175 } |
|
176 else |
1181
|
177 print_usage ("fflush"); |
|
178 |
|
179 return retval; |
|
180 } |
|
181 |
2095
|
182 DEFUN (fgetl, args, , |
2116
|
183 "STRING = fgetl (FILENUM [, LENGTH])\n\ |
1339
|
184 \n\ |
|
185 read a string from a file") |
|
186 { |
2095
|
187 octave_value retval = -1.0; |
1339
|
188 |
|
189 int nargin = args.length (); |
|
190 |
|
191 if (nargin == 1 || nargin == 2) |
2095
|
192 { |
|
193 octave_stream *os = octave_stream_list::lookup (args(0)); |
|
194 |
|
195 if (os) |
|
196 { |
|
197 octave_value len_arg = (nargin == 2) |
|
198 ? args(1) : octave_value ((double) INT_MAX); |
|
199 |
|
200 bool err = false; |
|
201 |
|
202 string tmp = os->getl (len_arg, err); |
|
203 |
|
204 if (! err) |
|
205 retval = tmp; |
|
206 } |
|
207 else |
|
208 gripe_invalid_file_id ("fgetl"); |
|
209 } |
1339
|
210 else |
|
211 print_usage ("fgetl"); |
|
212 |
|
213 return retval; |
|
214 } |
|
215 |
2095
|
216 DEFUN (fgets, args, , |
2116
|
217 "STRING = fgets (FILENUM [, LENGTH])\n\ |
529
|
218 \n\ |
1181
|
219 read a string from a file") |
529
|
220 { |
2095
|
221 octave_value retval = -1.0; |
529
|
222 |
|
223 int nargin = args.length (); |
|
224 |
1338
|
225 if (nargin == 1 || nargin == 2) |
2095
|
226 { |
|
227 octave_stream *os = octave_stream_list::lookup (args(0)); |
|
228 |
|
229 if (os) |
|
230 { |
|
231 octave_value len_arg = (nargin == 2) |
|
232 ? args(1) : octave_value ((double) INT_MAX); |
|
233 |
|
234 bool err = false; |
|
235 |
|
236 string tmp = os->gets (len_arg, err); |
|
237 |
|
238 if (! err) |
|
239 retval = tmp; |
|
240 } |
|
241 else |
|
242 gripe_invalid_file_id ("fgets"); |
|
243 } |
1338
|
244 else |
1181
|
245 print_usage ("fgets"); |
529
|
246 |
|
247 return retval; |
|
248 } |
|
249 |
2095
|
250 static octave_base_stream * |
|
251 do_stream_open (const string& name, const string& mode, |
|
252 const string& arch, int& fid) |
1
|
253 { |
2095
|
254 octave_base_stream *retval = 0; |
1
|
255 |
2095
|
256 fid = -1; |
1
|
257 |
2095
|
258 int md = fopen_mode_to_ios_mode (mode); |
1
|
259 |
2095
|
260 if (! error_state) |
|
261 { |
2318
|
262 oct_mach_info::float_format flt_fmt = |
|
263 oct_mach_info::string_to_float_format (arch); |
1
|
264 |
2095
|
265 if (! error_state) |
2318
|
266 retval = new octave_fstream (name, md, flt_fmt); |
1
|
267 } |
|
268 |
2095
|
269 return retval; |
|
270 } |
1
|
271 |
2095
|
272 static octave_base_stream * |
|
273 do_stream_open (const octave_value& tc_name, const octave_value& tc_mode, |
|
274 const octave_value& tc_arch, const char *fcn, int& fid) |
|
275 { |
|
276 octave_base_stream *retval = 0; |
|
277 |
|
278 fid = -1; |
|
279 |
|
280 string name = tc_name.string_value (); |
|
281 |
|
282 if (! error_state) |
1
|
283 { |
2095
|
284 string mode = tc_mode.string_value (); |
|
285 |
|
286 if (! error_state) |
|
287 { |
|
288 string arch = tc_arch.string_value (); |
1
|
289 |
2095
|
290 if (! error_state) |
|
291 retval = do_stream_open (name, mode, arch, fid); |
|
292 else |
|
293 ::error ("%s: architecture type must be a string", fcn); |
|
294 } |
|
295 else |
|
296 ::error ("%s: file mode must be a string", fcn); |
1
|
297 } |
2095
|
298 else |
|
299 ::error ("%s: file name must be a string", fcn); |
1
|
300 |
|
301 return retval; |
|
302 } |
|
303 |
1957
|
304 DEFUN (fopen, args, , |
2318
|
305 "[FILENUM, ERRMSG] = fopen (FILENAME, MODE [, ARCH]): open a file\n\ |
1181
|
306 \n\ |
2318
|
307 FILENAME is a string specifying the name of the file.\n\ |
|
308 \n\ |
|
309 MODE is a string specifying whether the file should be opened for\n\ |
|
310 reading, writing, or both. Valid values for MODE include:\n\ |
1181
|
311 \n\ |
2095
|
312 r : open text file for reading\n\ |
|
313 w : open text file for writing; discard previous contents if any\n\ |
|
314 a : append; open or create text file for writing at end of file\n\ |
|
315 r+ : open text file for update (i.e., reading and writing)\n\ |
|
316 w+ : create text file for update; discard previous contents if any\n\ |
|
317 a+ : append; open or create text file for update, writing at end\n\ |
|
318 \n\ |
2318
|
319 Update mode permits reading from and writing to the same file.\n\ |
|
320 \n\ |
|
321 ARCH is a string specifying the default data format for the file.\n\ |
|
322 Valid values for ARCH are:\n\ |
|
323 \n\ |
|
324 native -- the format of the current machine (this is the default)\n\ |
|
325 ieee-le -- IEEE big endian\n\ |
|
326 ieee-be -- IEEE little endian\n\ |
|
327 vaxd -- VAX D floating format\n\ |
|
328 vaxg -- VAX G floating format\n\ |
2324
|
329 cray -- Cray floating format\n\ |
2318
|
330 \n\ |
|
331 however, conversions are currently only supported for ieee-be, and\n\ |
|
332 ieee-le formats.\n\ |
|
333 \n\ |
|
334 \n\ |
|
335 FILENUM is a number that can be used to refer to the open file.\n\ |
|
336 If fopen fails, FILENUM is set to -1 and ERRMSG contains a\n\ |
|
337 system-dependent error message") |
529
|
338 { |
2095
|
339 octave_value_list retval = -1.0; |
529
|
340 |
|
341 int nargin = args.length (); |
|
342 |
2095
|
343 if (nargin == 1) |
|
344 { |
|
345 if (args(0).is_string () && args(0).string_value () == "all") |
2432
|
346 retval(0) = octave_stream_list::open_file_numbers (); |
2095
|
347 else |
|
348 { |
|
349 string_vector tmp = octave_stream_list::get_info (args(0)); |
529
|
350 |
2095
|
351 if (! error_state) |
|
352 { |
|
353 retval(2) = tmp(2); |
|
354 retval(1) = tmp(1); |
|
355 retval(0) = tmp(0); |
|
356 } |
2432
|
357 } |
1
|
358 |
2432
|
359 return retval; |
1
|
360 } |
|
361 |
2095
|
362 if (nargin > 0 && nargin < 4) |
|
363 { |
|
364 octave_value mode = (nargin == 2 || nargin == 3) |
|
365 ? args(1) : octave_value ("r"); |
|
366 |
|
367 octave_value arch = (nargin == 3) |
|
368 ? args(2) : octave_value ("native"); |
|
369 |
|
370 int fid = -1; |
|
371 |
|
372 octave_base_stream *os |
|
373 = do_stream_open (args(0), mode, arch, "fopen", fid); |
|
374 |
|
375 if (os) |
|
376 { |
|
377 if (os->ok () && ! error_state) |
|
378 { |
|
379 retval(1) = ""; |
|
380 retval(0) = (double) octave_stream_list::insert (os); |
|
381 } |
|
382 else |
|
383 { |
|
384 int errno = 0; |
|
385 retval(1) = os->error (false, errno); |
|
386 retval(0) = -1.0; |
|
387 } |
|
388 } |
|
389 else |
|
390 ::error ("fopen: internal error"); |
|
391 } |
|
392 else |
|
393 print_usage ("fopen"); |
1
|
394 |
|
395 return retval; |
|
396 } |
|
397 |
1957
|
398 DEFUN (freport, args, , |
1181
|
399 "freport (): list open files and their status") |
|
400 { |
2095
|
401 octave_value_list retval; |
1181
|
402 |
|
403 int nargin = args.length (); |
|
404 |
|
405 if (nargin > 0) |
|
406 warning ("freport: ignoring extra arguments"); |
|
407 |
2095
|
408 octave_stdout << octave_stream_list::list_open_files (); |
1181
|
409 |
|
410 return retval; |
|
411 } |
|
412 |
1957
|
413 DEFUN (frewind, args, , |
2116
|
414 "frewind (FILENUM): set file position at beginning of file") |
529
|
415 { |
2095
|
416 double retval = -1.0; |
1
|
417 |
506
|
418 int nargin = args.length (); |
|
419 |
2095
|
420 if (nargin == 1) |
1086
|
421 { |
2095
|
422 octave_stream *os = octave_stream_list::lookup (args(0)); |
636
|
423 |
2095
|
424 if (os) |
|
425 retval = (double) os->rewind (); |
1
|
426 else |
2095
|
427 gripe_invalid_file_id ("frewind"); |
1
|
428 } |
|
429 else |
2095
|
430 print_usage ("frewind"); |
1
|
431 |
|
432 return retval; |
|
433 } |
|
434 |
1957
|
435 DEFUN (fseek, args, , |
2116
|
436 "fseek (FILENUM, OFFSET [, ORIGIN])\n\ |
1181
|
437 \n\ |
2341
|
438 set file position for reading or writing.\n\ |
|
439 \n\ |
|
440 ORIGIN may be one of:\n\ |
|
441 \n\ |
|
442 SEEK_SET : offset is relative to the beginning of the file (default)\n\ |
|
443 SEEK_CUR : offset is relative to the current position\n\ |
|
444 SEEK_END : offset is relative to the end of the file") |
529
|
445 { |
2095
|
446 double retval = -1.0; |
529
|
447 |
|
448 int nargin = args.length (); |
|
449 |
2095
|
450 if (nargin == 2 || nargin == 3) |
|
451 { |
|
452 octave_stream *os = octave_stream_list::lookup (args(0)); |
1181
|
453 |
2095
|
454 if (os) |
|
455 { |
|
456 octave_value origin_arg = (nargin == 3) |
2341
|
457 ? args(2) : octave_value (-1.0); |
1
|
458 |
2095
|
459 retval = (double) os->seek (args(1), origin_arg); |
|
460 } |
|
461 else |
|
462 ::error ("fseek: invalid file id"); |
368
|
463 } |
2095
|
464 else |
|
465 print_usage ("fseek"); |
1
|
466 |
|
467 return retval; |
|
468 } |
|
469 |
1957
|
470 DEFUN (ftell, args, , |
2116
|
471 "POSITION = ftell (FILENUM): returns the current file position") |
1181
|
472 { |
2095
|
473 double retval = -1.0; |
1
|
474 |
506
|
475 int nargin = args.length (); |
|
476 |
2095
|
477 if (nargin == 1) |
1
|
478 { |
2095
|
479 octave_stream *os = octave_stream_list::lookup (args(0)); |
1
|
480 |
2095
|
481 if (os) |
|
482 retval = (double) os->tell (); |
|
483 else |
|
484 gripe_invalid_file_id ("ftell"); |
1
|
485 } |
|
486 else |
2095
|
487 print_usage ("ftell"); |
1
|
488 |
|
489 return retval; |
|
490 } |
|
491 |
1957
|
492 DEFUN (fprintf, args, , |
2116
|
493 "fprintf (FILENUM, FORMAT, ...)") |
1181
|
494 { |
2095
|
495 double retval = -1.0; |
1181
|
496 |
|
497 int nargin = args.length (); |
|
498 |
2095
|
499 if (nargin > 1) |
|
500 { |
|
501 octave_stream *os = octave_stream_list::lookup (args(0)); |
|
502 |
|
503 if (os) |
|
504 { |
|
505 if (args(1).is_string ()) |
|
506 { |
|
507 string fmt = args(1).string_value (); |
|
508 |
|
509 octave_value_list tmp_args; |
|
510 |
|
511 if (nargin > 2) |
|
512 { |
|
513 tmp_args.resize (nargin-2, octave_value ()); |
|
514 |
|
515 for (int i = 2; i < nargin; i++) |
|
516 tmp_args(i-2) = args(i); |
|
517 } |
|
518 |
|
519 retval = os->printf (fmt, tmp_args); |
|
520 } |
|
521 else |
|
522 ::error ("fprintf: format must be a string"); |
|
523 } |
|
524 else |
|
525 gripe_invalid_file_id ("fprintf"); |
|
526 } |
|
527 else |
1181
|
528 print_usage ("fprintf"); |
|
529 |
|
530 return retval; |
|
531 } |
|
532 |
2095
|
533 DEFUN (fputs, args, , |
2116
|
534 "fputs (FILENUM, STRING)") |
1181
|
535 { |
2095
|
536 double retval = -1.0; |
1181
|
537 |
|
538 int nargin = args.length (); |
|
539 |
2095
|
540 if (nargin == 2) |
|
541 { |
|
542 octave_stream *os = octave_stream_list::lookup (args(0)); |
1181
|
543 |
2095
|
544 if (os) |
|
545 retval = os->puts (args(1)); |
|
546 else |
|
547 gripe_invalid_file_id ("fputs"); |
|
548 } |
1181
|
549 else |
2095
|
550 print_usage ("fputs"); |
1181
|
551 |
|
552 return retval; |
|
553 } |
|
554 |
2095
|
555 DEFUN (sprintf, args, , |
|
556 "[s, errmsg, status] = sprintf (FORMAT, ...)") |
1
|
557 { |
2095
|
558 octave_value_list retval; |
1
|
559 |
2095
|
560 int nargin = args.length (); |
1
|
561 |
2095
|
562 if (nargin > 0) |
1
|
563 { |
2116
|
564 retval(2) = -1.0; |
|
565 retval(1) = "unknown error"; |
|
566 retval(0) = ""; |
|
567 |
2095
|
568 octave_ostrstream ostr; |
1
|
569 |
2148
|
570 octave_stream os (&ostr, true); |
628
|
571 |
2095
|
572 if (os) |
|
573 { |
|
574 if (args(0).is_string ()) |
|
575 { |
|
576 string fmt = args(0).string_value (); |
628
|
577 |
2095
|
578 octave_value_list tmp_args; |
1
|
579 |
2095
|
580 if (nargin > 1) |
|
581 { |
|
582 tmp_args.resize (nargin-1, octave_value ()); |
1
|
583 |
2095
|
584 for (int i = 1; i < nargin; i++) |
|
585 tmp_args(i-1) = args(i); |
|
586 } |
628
|
587 |
2095
|
588 retval(2) = os.printf (fmt, tmp_args); |
|
589 retval(1) = os.error (); |
|
590 char *tmp = ostr.str (); |
|
591 retval(0) = tmp; |
|
592 delete [] tmp; |
|
593 } |
|
594 else |
|
595 ::error ("sprintf: format must be a string"); |
|
596 } |
|
597 else |
|
598 ::error ("sprintf: unable to create output buffer"); |
1
|
599 } |
|
600 else |
2095
|
601 print_usage ("sprintf"); |
1
|
602 |
|
603 return retval; |
|
604 } |
|
605 |
2095
|
606 DEFUN (fscanf, args, , |
2122
|
607 "[A, COUNT] = fscanf (FILENUM, FORMAT [, SIZE])\n\ |
|
608 \n\ |
|
609 Read from FILENUM according to FORMAT, returning the result in the\n\ |
|
610 matrix A. SIZE is optional. If present, it can be one of\n\ |
|
611 \n\ |
|
612 Inf : read as much as possible, returning a column vector\n\ |
|
613 (unless doing all character conversions, in which case a\n\ |
|
614 string is returned)\n\ |
|
615 NR : read as much as possible, returning a matrix with NR rows\n\ |
|
616 [NR, NC] : read up to NR x NC elements, returning a matrix with NR rows\n\ |
|
617 [NR, Inf] : same as NR\n\ |
|
618 \n\ |
|
619 If it is omitted, a value of Inf is assumed.\n\ |
|
620 \n\ |
2215
|
621 The number of items successfully read is returned in COUNT.\n\ |
|
622 \n\ |
|
623 [A, B, ...] = fscanf (FILENUM, FORMAT, \"C\")\n\ |
|
624 \n\ |
|
625 Read from FILENUM according to FORMAT, with each conversion specifier\n\ |
|
626 in FORMAT corresponding to a single scalar return value. This form is\n\ |
|
627 more `C-like', and also compatible with previous versions of Octave") |
1181
|
628 { |
2095
|
629 octave_value_list retval; |
1181
|
630 |
|
631 int nargin = args.length (); |
|
632 |
2215
|
633 if (nargin == 3 && args(2).is_string ()) |
2095
|
634 { |
|
635 octave_stream *os = octave_stream_list::lookup (args(0)); |
1181
|
636 |
2095
|
637 if (os) |
|
638 { |
|
639 if (args(1).is_string ()) |
|
640 { |
|
641 string fmt = args(1).string_value (); |
1181
|
642 |
2215
|
643 retval = os->oscanf (fmt); |
2095
|
644 } |
|
645 else |
|
646 ::error ("fscanf: format must be a string"); |
|
647 } |
|
648 else |
|
649 gripe_invalid_file_id ("fscanf"); |
|
650 } |
1181
|
651 else |
2215
|
652 { |
|
653 retval (1) = 0.0; |
|
654 retval (0) = Matrix (); |
|
655 |
|
656 if (nargin == 2 || nargin == 3) |
|
657 { |
|
658 octave_stream *os = octave_stream_list::lookup (args(0)); |
|
659 |
|
660 if (os) |
|
661 { |
|
662 if (args(1).is_string ()) |
|
663 { |
|
664 string fmt = args(1).string_value (); |
|
665 |
|
666 int count = 0; |
|
667 |
|
668 Matrix size = (nargin == 3) |
|
669 ? args(2).matrix_value () : Matrix (1, 1, octave_Inf); |
|
670 |
|
671 if (! error_state) |
|
672 { |
|
673 octave_value tmp = os->scanf (fmt, size, count); |
|
674 |
|
675 retval(1) = (double) count; |
|
676 retval(0) = tmp; |
|
677 } |
|
678 } |
|
679 else |
|
680 ::error ("fscanf: format must be a string"); |
|
681 } |
|
682 else |
|
683 gripe_invalid_file_id ("fscanf"); |
|
684 } |
|
685 else |
|
686 print_usage ("fscanf"); |
|
687 } |
1181
|
688 |
|
689 return retval; |
|
690 } |
|
691 |
2095
|
692 DEFUN (sscanf, args, , |
2122
|
693 "[A, COUNT, ERRMSG, INDEX] = sscanf (STRING, FORMAT, SIZE)\n\ |
|
694 \n\ |
2215
|
695 Read from STRING according to FORMAT, returning the result in the\n\ |
2122
|
696 matrix A. SIZE is optional. If present, it can be one of\n\ |
|
697 \n\ |
|
698 Inf : read as much as possible, returning a column vector\n\ |
|
699 (unless doing all character conversions, in which case a\n\ |
|
700 string is returned)\n\ |
|
701 NR : read as much as possible, returning a matrix with NR rows\n\ |
|
702 [NR, NC] : read up to NR x NC elements, returning a matrix with NR rows\n\ |
|
703 [NR, Inf] : same as NR\n\ |
|
704 \n\ |
|
705 If it is omitted, a value of Inf is assumed.\n\ |
|
706 \n\ |
|
707 The number of items successfully read is returned in COUNT. If an\n\ |
|
708 error occurs, ERRMSG contains the text of the corresponding error\n\ |
|
709 message. INDEX contains the index of the next character to be read\n\ |
2215
|
710 from STRING\n\ |
|
711 \n\ |
|
712 [A, B, ...] = sscanf (STRING, FORMAT, \"C\")\n\ |
|
713 \n\ |
|
714 Read from STRING according to FORMAT, with each conversion specifier\n\ |
|
715 in FORMAT corresponding to a single scalar return value. This form is\n\ |
|
716 more `C-like', and also compatible with previous versions of Octave") |
444
|
717 { |
2095
|
718 octave_value_list retval; |
444
|
719 |
506
|
720 int nargin = args.length (); |
|
721 |
2215
|
722 if (nargin == 3 && args(2).is_string ()) |
2095
|
723 { |
|
724 if (args(0).is_string ()) |
|
725 { |
|
726 string data = args(0).string_value (); |
444
|
727 |
2095
|
728 octave_istrstream istr (data); |
1358
|
729 |
2148
|
730 octave_stream os (&istr, true); |
636
|
731 |
2095
|
732 if (os) |
|
733 { |
|
734 if (args(1).is_string ()) |
|
735 { |
|
736 string fmt = args(1).string_value (); |
444
|
737 |
2215
|
738 retval = os.oscanf (fmt); |
2095
|
739 } |
|
740 else |
|
741 ::error ("sscanf: format must be a string"); |
|
742 } |
|
743 else |
|
744 ::error ("sscanf: unable to create temporary input buffer"); |
444
|
745 } |
636
|
746 else |
2095
|
747 ::error ("sscanf: first argument must be a string"); |
444
|
748 } |
|
749 else |
2215
|
750 { |
|
751 if (nargin == 2 || nargin == 3) |
|
752 { |
|
753 retval(3) = -1.0; |
|
754 retval(2) = "unknown error"; |
|
755 retval(1) = 0.0; |
|
756 retval(0) = Matrix (); |
|
757 |
|
758 if (args(0).is_string ()) |
|
759 { |
|
760 string data = args(0).string_value (); |
|
761 |
|
762 octave_istrstream istr (data); |
|
763 |
|
764 octave_stream os (&istr, true); |
|
765 |
|
766 if (os) |
|
767 { |
|
768 if (args(1).is_string ()) |
|
769 { |
|
770 string fmt = args(1).string_value (); |
|
771 |
|
772 int count = 0; |
|
773 |
|
774 Matrix size = (nargin == 3) |
|
775 ? args(2).matrix_value () : Matrix (1, 1, octave_Inf); |
|
776 |
|
777 octave_value tmp = os.scanf (fmt, size, count); |
|
778 |
|
779 // XXX FIXME XXX -- is this the right thing to do? |
|
780 // Extract error message first, because getting |
|
781 // position will clear it. |
|
782 string errmsg = os.error (); |
|
783 |
|
784 retval(3) = (double) (os.tell () + 1); |
|
785 retval(2) = errmsg; |
|
786 retval(1) = (double) count; |
|
787 retval(0) = tmp; |
|
788 } |
|
789 else |
|
790 ::error ("sscanf: format must be a string"); |
|
791 } |
|
792 else |
|
793 ::error ("sscanf: unable to create temporary input buffer"); |
|
794 } |
|
795 else |
|
796 ::error ("sscanf: first argument must be a string"); |
|
797 } |
|
798 else |
|
799 print_usage ("sscanf"); |
|
800 } |
444
|
801 |
|
802 return retval; |
|
803 } |
|
804 |
2215
|
805 DEFUN (scanf, args, nargout, |
|
806 "scanf (FORMAT) is equivalent to fscanf (stdin, FORMAT)") |
|
807 { |
|
808 int nargin = args.length (); |
|
809 |
|
810 octave_value_list tmp_args (nargin+1, octave_value ()); |
|
811 |
|
812 tmp_args (0) = 0.0; |
|
813 for (int i = 0; i < nargin; i++) |
|
814 tmp_args (i+1) = args (i); |
|
815 |
|
816 return Ffscanf (tmp_args, nargout); |
|
817 } |
|
818 |
2116
|
819 static octave_value |
|
820 do_fread (octave_stream& os, const octave_value& size_arg, |
|
821 const octave_value& prec_arg, const octave_value& skip_arg, |
|
822 const octave_value& arch_arg, int& count) |
|
823 { |
|
824 octave_value retval; |
|
825 |
|
826 count = -1; |
|
827 |
|
828 Matrix size = size_arg.matrix_value (); |
|
829 |
|
830 if (! error_state) |
|
831 { |
|
832 string prec = prec_arg.string_value (); |
|
833 |
|
834 if (! error_state) |
|
835 { |
2318
|
836 oct_data_conv::data_type dt |
|
837 = oct_data_conv::string_to_data_type (prec); |
2116
|
838 |
|
839 if (! error_state) |
|
840 { |
|
841 double dskip = skip_arg.double_value (); |
|
842 |
|
843 if (! error_state) |
|
844 { |
|
845 if (D_NINT (dskip) == dskip) |
|
846 { |
|
847 int skip = NINT (dskip); |
|
848 |
|
849 string arch = arch_arg.string_value (); |
|
850 |
|
851 if (! error_state) |
|
852 { |
2318
|
853 oct_mach_info::float_format flt_fmt |
|
854 = oct_mach_info::string_to_float_format (arch); |
2116
|
855 |
|
856 if (! error_state) |
2318
|
857 retval = os.read (size, dt, skip, flt_fmt, count); |
2116
|
858 } |
|
859 else |
|
860 ::error ("fread: architecture type must be a string"); |
|
861 } |
|
862 else |
|
863 ::error ("fread: skip must be an integer"); |
|
864 } |
|
865 else |
|
866 ::error ("fread: invalid skip specified"); |
|
867 } |
|
868 else |
|
869 ::error ("fread: invalid data type specified"); |
|
870 } |
|
871 else |
|
872 ::error ("fread: precision must be a string"); |
|
873 } |
|
874 else |
|
875 ::error ("fread: invalid size specified"); |
|
876 |
|
877 return retval; |
|
878 } |
|
879 |
|
880 DEFUN (fread, args, , |
|
881 "[DATA, COUNT] = fread (FILENUM [, SIZE] [, PRECISION] [, SKIP] [, ARCH])\n\ |
529
|
882 \n\ |
2318
|
883 Reads data in binary form of type PRECISION from a file.\n\ |
|
884 \n\ |
|
885 FILENUM : file number from fopen\n\ |
529
|
886 \n\ |
2318
|
887 SIZE : size specification for the data matrix\n\ |
|
888 \n\ |
|
889 PRECISION : string specifying type of data to read, valid types are\n\ |
529
|
890 \n\ |
2318
|
891 char, char*1, integer*1, int8 -- character\n\ |
|
892 schar, signed char -- signed character\n\ |
|
893 uchar, unsigned char -- unsigned character (default)\n\ |
|
894 short -- short integer\n\ |
|
895 ushort, unsigned short -- unsigned short integer\n\ |
|
896 int -- integer\n\ |
|
897 uint, unsigned int -- unsigned integer\n\ |
|
898 long -- long integer\n\ |
|
899 ulong, unsigned long -- unsigned long integer\n\ |
|
900 float, float32, real*4 -- single precision float\n\ |
|
901 double, float64, real*8 -- double precision float\n\ |
|
902 int16, integer*2 -- two byte integer\n\ |
|
903 int32, integer*4 -- four byte integer\n\ |
|
904 \n\ |
|
905 SKIP : number of bytes to skip before each element is read\n\ |
|
906 (default is 0)\n\ |
529
|
907 \n\ |
2318
|
908 ARCH : string specifying the data format for the file. Valid |
|
909 values are\n\ |
|
910 \n\ |
|
911 native -- the format of the current machine (default)\n\ |
|
912 ieee-le -- IEEE big endian\n\ |
|
913 ieee-be -- IEEE little endian\n\ |
|
914 vaxd -- VAX D floating format\n\ |
|
915 vaxg -- VAX G floating format\n\ |
2324
|
916 cray -- Cray floating format\n\ |
2318
|
917 \n\ |
2324
|
918 however, conversions are currently only supported for\n\ |
|
919 ieee-be, and ieee-le formats.\n\ |
2318
|
920 \n\ |
|
921 \n\ |
|
922 DATA : matrix in which the data is stored\n\ |
|
923 \n\ |
|
924 COUNT : number of elements read") |
529
|
925 { |
2095
|
926 octave_value_list retval; |
2116
|
927 |
|
928 int nargin = args.length (); |
|
929 |
2318
|
930 if (nargin > 0 && nargin < 6) |
2116
|
931 { |
|
932 retval(1) = -1.0; |
|
933 retval(0) = Matrix (); |
|
934 |
|
935 octave_stream *os = octave_stream_list::lookup (args(0)); |
|
936 |
|
937 if (os) |
|
938 { |
|
939 octave_value size = (nargin > 1) |
|
940 ? args(1) : octave_value (octave_Inf); |
|
941 |
|
942 octave_value prec = (nargin > 2) |
|
943 ? args(2) : octave_value ("uchar"); |
|
944 |
|
945 octave_value skip = (nargin > 3) |
|
946 ? args(3) : octave_value (0.0); |
|
947 |
|
948 octave_value arch = (nargin > 4) |
2318
|
949 ? args(4) : octave_value ("unknown"); |
2116
|
950 |
|
951 int count = -1; |
|
952 |
|
953 octave_value tmp = do_fread (*os, size, prec, skip, arch, count); |
|
954 |
|
955 retval(1) = (double) count; |
|
956 retval(0) = tmp; |
|
957 } |
|
958 else |
|
959 gripe_invalid_file_id ("fread"); |
|
960 } |
|
961 else |
|
962 print_usage ("fread"); |
|
963 |
529
|
964 return retval; |
|
965 } |
|
966 |
2116
|
967 static int |
|
968 do_fwrite (octave_stream& os, const octave_value& data, |
|
969 const octave_value& prec_arg, const octave_value& skip_arg, |
|
970 const octave_value& arch_arg) |
|
971 { |
|
972 int retval = -1; |
|
973 |
|
974 string prec = prec_arg.string_value (); |
|
975 |
|
976 if (! error_state) |
|
977 { |
2318
|
978 oct_data_conv::data_type dt |
|
979 = oct_data_conv::string_to_data_type (prec); |
2116
|
980 |
|
981 if (! error_state) |
|
982 { |
|
983 double dskip = skip_arg.double_value (); |
|
984 |
|
985 if (! error_state) |
|
986 { |
|
987 if (D_NINT (dskip) == dskip) |
|
988 { |
|
989 int skip = NINT (dskip); |
|
990 |
|
991 string arch = arch_arg.string_value (); |
|
992 |
|
993 if (! error_state) |
|
994 { |
2318
|
995 oct_mach_info::float_format flt_fmt |
|
996 = oct_mach_info::string_to_float_format (arch); |
2116
|
997 |
|
998 if (! error_state) |
2318
|
999 retval = os.write (data, dt, skip, flt_fmt); |
2116
|
1000 } |
|
1001 else |
|
1002 ::error ("fwrite: architecture type must be a string"); |
|
1003 } |
|
1004 else |
|
1005 ::error ("fwrite: skip must be an integer"); |
|
1006 } |
|
1007 else |
|
1008 ::error ("fwrite: invalid skip specified"); |
|
1009 } |
|
1010 } |
|
1011 else |
|
1012 ::error ("fwrite: precision must be a string"); |
|
1013 |
|
1014 return retval; |
|
1015 } |
|
1016 |
|
1017 DEFUN (fwrite, args, , |
|
1018 "COUNT = fwrite (FILENUM, DATA [, PRECISION] [, SKIP] [, ARCH])\n\ |
1181
|
1019 \n\ |
2318
|
1020 Writes data to a file in binary form of size PRECISION\n\ |
|
1021 \n\ |
|
1022 FILENUM : file number from fopen\n\ |
|
1023 \n\ |
|
1024 DATA : matrix of elements to be written\n\ |
|
1025 \n\ |
|
1026 PRECISION : string specifying type of data to read, valid types are\n\ |
1181
|
1027 \n\ |
2318
|
1028 char, char*1, integer*1, int8 -- character\n\ |
|
1029 schar, signed char -- signed character\n\ |
|
1030 uchar, unsigned char -- unsigned character (default)\n\ |
|
1031 short -- short integer\n\ |
|
1032 ushort, unsigned short -- unsigned short integer\n\ |
|
1033 int -- integer\n\ |
|
1034 uint, unsigned int -- unsigned integer\n\ |
|
1035 long -- long integer\n\ |
|
1036 ulong, unsigned long -- unsigned long integer\n\ |
|
1037 float, float32, real*4 -- single precision float\n\ |
|
1038 double, float64, real*8 -- double precision float\n\ |
|
1039 int16, integer*2 -- two byte integer\n\ |
|
1040 int32, integer*4 -- four byte integer\n\ |
1181
|
1041 \n\ |
2318
|
1042 SKIP : number of bytes to skip before each element is read\n\ |
|
1043 (the default is 0)\n\ |
|
1044 \n\ |
|
1045 ARCH : string specifying the data format for the file. Valid |
|
1046 values are\n\ |
1181
|
1047 \n\ |
2318
|
1048 native -- the format of the current machine (default)\n\ |
|
1049 ieee-le -- IEEE big endian\n\ |
|
1050 ieee-be -- IEEE little endian\n\ |
|
1051 vaxd -- VAX D floating format\n\ |
|
1052 vaxg -- VAX G floating format\n\ |
|
1053 cray -- Cray floating format\n |
|
1054 \n\ |
|
1055 however, conversions are currently only supported for ieee-be, and\n\ |
|
1056 ieee-le formats.\n\ |
|
1057 \n\ |
|
1058 \n\ |
|
1059 COUNT : number of elements written") |
1181
|
1060 { |
2116
|
1061 octave_value retval = -1.0; |
|
1062 |
|
1063 int nargin = args.length (); |
|
1064 |
|
1065 if (nargin > 1 && nargin < 6) |
|
1066 { |
|
1067 octave_stream *os = octave_stream_list::lookup (args(0)); |
|
1068 |
|
1069 if (os) |
|
1070 { |
|
1071 octave_value data = args(1); |
2318
|
1072 |
|
1073 octave_value prec = (nargin > 2) |
|
1074 ? args(2) : octave_value ("uchar"); |
|
1075 |
|
1076 octave_value skip = (nargin > 3) |
|
1077 ? args(3) : octave_value (0.0); |
|
1078 |
|
1079 octave_value arch = (nargin > 4) |
|
1080 ? args(4) : octave_value ("unknown"); |
2116
|
1081 |
|
1082 retval = do_fwrite (*os, data, prec, skip, arch); |
|
1083 } |
|
1084 else |
|
1085 gripe_invalid_file_id ("fwrite"); |
|
1086 } |
|
1087 else |
|
1088 print_usage ("fwrite"); |
|
1089 |
1181
|
1090 return retval; |
|
1091 } |
|
1092 |
1957
|
1093 DEFUN (feof, args, , |
2116
|
1094 "ERROR = feof (FILENUM)\n\ |
529
|
1095 \n\ |
|
1096 Returns a non zero value for an end of file condition for the\n\ |
2116
|
1097 file specified by FILENUM from fopen") |
529
|
1098 { |
2095
|
1099 double retval = -1.0; |
529
|
1100 |
|
1101 int nargin = args.length (); |
|
1102 |
2095
|
1103 if (nargin == 1) |
|
1104 { |
|
1105 octave_stream *os = octave_stream_list::lookup (args(0)); |
444
|
1106 |
2095
|
1107 if (os) |
|
1108 retval = os->eof () ? 1.0 : 0.0; |
|
1109 else |
|
1110 gripe_invalid_file_id ("feof"); |
|
1111 } |
529
|
1112 else |
2095
|
1113 print_usage ("feof"); |
444
|
1114 |
|
1115 return retval; |
|
1116 } |
|
1117 |
2095
|
1118 DEFUN (ferror, args, , |
2116
|
1119 "ERROR = ferror (FILENUM, [\"clear\"])\n\ |
2095
|
1120 \n\ |
|
1121 Returns a non zero value for an error condition on the\n\ |
2116
|
1122 file specified by FILENUM from fopen") |
1230
|
1123 { |
2095
|
1124 octave_value_list retval; |
1230
|
1125 |
2095
|
1126 int nargin = args.length (); |
1230
|
1127 |
2095
|
1128 if (nargin == 1 || nargin == 2) |
|
1129 { |
|
1130 octave_stream *os = octave_stream_list::lookup (args(0)); |
1230
|
1131 |
2095
|
1132 if (os) |
|
1133 { |
|
1134 bool clear = false; |
1230
|
1135 |
2095
|
1136 if (nargin == 2) |
|
1137 { |
|
1138 string opt = args(1).string_value (); |
|
1139 |
|
1140 if (! error_state) |
|
1141 clear = (opt == "clear"); |
|
1142 else |
|
1143 return retval; |
|
1144 } |
1755
|
1145 |
2095
|
1146 int error_number = 0; |
|
1147 |
|
1148 string error_message = os->error (clear, error_number); |
1230
|
1149 |
2095
|
1150 retval(1) = (double) error_number; |
|
1151 retval(0) = error_message; |
|
1152 } |
|
1153 else |
|
1154 gripe_invalid_file_id ("ferror"); |
1230
|
1155 } |
2095
|
1156 else |
|
1157 print_usage ("ferror"); |
1230
|
1158 |
|
1159 return retval; |
|
1160 } |
|
1161 |
1957
|
1162 DEFUN (popen, args, , |
1230
|
1163 "FILENUM = popen (FILENAME, MODE)\n\ |
|
1164 \n\ |
|
1165 start a process and create a pipe. Valid values for mode are:\n\ |
|
1166 \n\ |
|
1167 \"r\" : connect stdout of process to pipe\n\ |
|
1168 \"w\" : connect stdin of process to pipe") |
|
1169 { |
2095
|
1170 double retval = -1.0; |
1230
|
1171 |
|
1172 int nargin = args.length (); |
|
1173 |
2095
|
1174 if (nargin == 2) |
|
1175 { |
|
1176 string name = args(0).string_value (); |
1230
|
1177 |
2095
|
1178 if (! error_state) |
|
1179 { |
|
1180 string mode = args(1).string_value (); |
1230
|
1181 |
2095
|
1182 if (! error_state) |
|
1183 { |
|
1184 if (mode == "r") |
|
1185 { |
|
1186 octave_iprocstream *ips = new octave_iprocstream (name); |
1230
|
1187 |
2095
|
1188 retval = octave_stream_list::insert (ips); |
|
1189 } |
|
1190 else if (mode == "w") |
|
1191 { |
|
1192 octave_oprocstream *ops = new octave_oprocstream (name); |
1230
|
1193 |
2095
|
1194 retval = octave_stream_list::insert (ops); |
|
1195 } |
|
1196 else |
|
1197 ::error ("popen: invalid mode specified"); |
|
1198 } |
|
1199 else |
|
1200 ::error ("popen: mode must be a string"); |
|
1201 } |
|
1202 else |
|
1203 ::error ("popen: name must be a string"); |
|
1204 } |
1230
|
1205 else |
2095
|
1206 print_usage ("popen"); |
1230
|
1207 |
|
1208 return retval; |
|
1209 } |
|
1210 |
1957
|
1211 DEFUN (pclose, args, , |
2116
|
1212 "pclose (FILENUM)\n\ |
1230
|
1213 \n\ |
|
1214 Close a pipe and terminate the associated process") |
|
1215 { |
2095
|
1216 double retval = -1.0; |
1230
|
1217 |
|
1218 int nargin = args.length (); |
|
1219 |
2095
|
1220 if (nargin == 1) |
1230
|
1221 { |
2095
|
1222 retval = (double) octave_stream_list::remove (args(0)); |
1230
|
1223 |
2095
|
1224 if (retval < 0) |
|
1225 gripe_invalid_file_id ("pclose"); |
1377
|
1226 } |
|
1227 else |
2095
|
1228 print_usage ("pclose"); |
1379
|
1229 |
|
1230 return retval; |
|
1231 } |
|
1232 |
1957
|
1233 DEFUN (octave_tmp_file_name, args, , |
2237
|
1234 "octave_tmp_file_name ()\n\ |
|
1235 Return unique temporary file name.") |
1802
|
1236 { |
2095
|
1237 octave_value retval; |
1802
|
1238 |
|
1239 if (args.length () == 0) |
|
1240 retval = oct_tempnam (); |
|
1241 else |
|
1242 print_usage ("octave_tmp_file_name"); |
|
1243 |
|
1244 return retval; |
|
1245 } |
|
1246 |
1400
|
1247 static int |
|
1248 convert (int x, int ibase, int obase) |
|
1249 { |
|
1250 int retval = 0; |
|
1251 |
|
1252 int tmp = x % obase; |
|
1253 |
|
1254 if (tmp > ibase - 1) |
2095
|
1255 ::error ("umask: invalid digit"); |
1400
|
1256 else |
|
1257 { |
|
1258 retval = tmp; |
|
1259 int mult = ibase; |
|
1260 while ((x = (x - tmp) / obase)) |
|
1261 { |
|
1262 tmp = x % obase; |
|
1263 if (tmp > ibase - 1) |
|
1264 { |
2095
|
1265 ::error ("umask: invalid digit"); |
1400
|
1266 break; |
|
1267 } |
|
1268 retval += mult * tmp; |
|
1269 mult *= ibase; |
|
1270 } |
|
1271 } |
|
1272 |
|
1273 return retval; |
|
1274 } |
|
1275 |
1957
|
1276 DEFUN (umask, args, , |
1400
|
1277 "umask (MASK)\n\ |
|
1278 \n\ |
|
1279 Change the file permission mask for file creation for the current |
|
1280 process. MASK is an integer, interpreted as an octal number. If |
|
1281 successful, returns the previous value of the mask (as an integer to |
|
1282 be interpreted as an octal number); otherwise an error message is |
|
1283 printed.") |
|
1284 { |
2095
|
1285 octave_value_list retval; |
1400
|
1286 |
|
1287 int status = 0; |
|
1288 |
|
1289 if (args.length () == 1) |
|
1290 { |
|
1291 double dmask = args(0).double_value (); |
|
1292 |
|
1293 if (error_state) |
|
1294 { |
|
1295 status = -1; |
2095
|
1296 ::error ("umask: expecting integer argument"); |
1400
|
1297 } |
|
1298 else |
|
1299 { |
|
1300 int mask = NINT (dmask); |
|
1301 |
|
1302 if ((double) mask != dmask || mask < 0) |
|
1303 { |
|
1304 status = -1; |
2095
|
1305 ::error ("umask: MASK must be a positive integer value"); |
1400
|
1306 } |
|
1307 else |
|
1308 { |
|
1309 int oct_mask = convert (mask, 8, 10); |
|
1310 |
|
1311 if (! error_state) |
1773
|
1312 status = convert (oct_umask (oct_mask), 10, 8); |
1400
|
1313 } |
|
1314 } |
|
1315 } |
|
1316 else |
|
1317 print_usage ("umask"); |
|
1318 |
|
1319 if (status >= 0) |
|
1320 retval(0) = (double) status; |
|
1321 |
|
1322 return retval; |
|
1323 } |
|
1324 |
2189
|
1325 void |
|
1326 symbols_of_file_io (void) |
|
1327 { |
2341
|
1328 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be |
|
1329 // this way for Matlab compatibility. |
|
1330 |
|
1331 DEFCONST (SEEK_SET, -1.0, 0, 0, |
2189
|
1332 "used with fseek to position file relative to the beginning"); |
|
1333 |
2341
|
1334 DEFCONST (SEEK_CUR, 0.0, 0, 0, |
2189
|
1335 "used with fseek to position file relative to the current position"); |
|
1336 |
2341
|
1337 DEFCONST (SEEK_END, 1.0, 0, 0, |
2189
|
1338 "used with fseek to position file relative to the end"); |
|
1339 |
|
1340 DEFCONSTX ("stdin", SBV_stdin, 0.0, 0, 0, |
|
1341 "file number of the standard input stream"); |
|
1342 |
|
1343 DEFCONSTX ("stdout", SBV_stdout, 1.0, 0, 0, |
|
1344 "file number of the standard output stream"); |
|
1345 |
|
1346 DEFCONSTX ("stderr", SBV_stderr, 2.0, 0, 0, |
|
1347 "file number of the standard error stream"); |
|
1348 } |
|
1349 |
444
|
1350 /* |
1
|
1351 ;;; Local Variables: *** |
|
1352 ;;; mode: C++ *** |
|
1353 ;;; End: *** |
|
1354 */ |