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