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