annotate src/file-io.cc @ 4028:ef75c970c8f5

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