annotate src/file-io.cc @ 9796:5f24df61667a

update ferror doc string
author John W. Eaton <jwe@octave.org>
date Tue, 10 Nov 2009 17:51:03 -0500
parents 09da0bd91412
children f569f46a1c34
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8792
diff changeset
4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 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
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
11 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 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
16 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
20 <http://www.gnu.org/licenses/>.
1
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 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
23
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
24 // 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
25 //
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
26 // 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
27 // the following functions:
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
28 //
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
29 // popen
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
30 // pclose
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
31 // execute (now popen2.m)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
32 // sync_system (now merged with system)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
33 // async_system (now merged with system)
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
34
9322
66fdc831c580 fix jwe email address
John W. Eaton <jwe@octave.org>
parents: 9236
diff changeset
35 // Extensively revised by John W. Eaton <jwe@octave.org>,
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
36 // April 1996.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 218
diff changeset
38 #ifdef HAVE_CONFIG_H
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
39 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
40 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
41
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4726
diff changeset
42 #include <cerrno>
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
43 #include <climits>
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4726
diff changeset
44 #include <cstdio>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1339
diff changeset
45
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3491
diff changeset
46 #include <iostream>
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7097
diff changeset
47 #include <stack>
4726
14dc2267c343 [project @ 2004-01-23 20:04:35 by jwe]
jwe
parents: 4715
diff changeset
48 #include <vector>
1350
5f63d83dd694 [project @ 1995-09-05 07:37:59 by jwe]
jwe
parents: 1343
diff changeset
49
5f63d83dd694 [project @ 1995-09-05 07:37:59 by jwe]
jwe
parents: 1343
diff changeset
50 #ifdef HAVE_UNISTD_H
2442
f667d7ec08b9 [project @ 1996-10-30 18:46:22 by jwe]
jwe
parents: 2432
diff changeset
51 #ifdef HAVE_SYS_TYPES_H
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
52 #include <sys/types.h>
2442
f667d7ec08b9 [project @ 1996-10-30 18:46:22 by jwe]
jwe
parents: 2432
diff changeset
53 #endif
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
54 #include <unistd.h>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1339
diff changeset
55 #endif
1350
5f63d83dd694 [project @ 1995-09-05 07:37:59 by jwe]
jwe
parents: 1343
diff changeset
56
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
57 #ifdef HAVE_ZLIB_H
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
58 #include <zlib.h>
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
59 #endif
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
60
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
61 #include "error.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2902
diff changeset
62 #include "file-ops.h"
6159
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
63 #include "file-stat.h"
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
64 #include "lo-ieee.h"
6159
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
65 #include "oct-env.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
66 #include "oct-locbuf.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2902
diff changeset
67
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
68 #include "defun.h"
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 6053
diff changeset
69 #include "file-io.h"
6159
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
70 #include "load-path.h"
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
71 #include "oct-fstrm.h"
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
72 #include "oct-iostrm.h"
1377
44f5d41ff757 [project @ 1995-09-12 00:07:58 by jwe]
jwe
parents: 1363
diff changeset
73 #include "oct-map.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
74 #include "oct-obj.h"
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
75 #include "oct-prcstrm.h"
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
76 #include "oct-stream.h"
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
77 #include "oct-strstrm.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
78 #include "pager.h"
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
79 #include "sysdep.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
80 #include "utils.h"
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2341
diff changeset
81 #include "variables.h"
1583
5383d2d4cf9d [project @ 1995-10-27 08:51:20 by jwe]
jwe
parents: 1488
diff changeset
82
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
83 static octave_value stdin_file;
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
84 static octave_value stdout_file;
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
85 static octave_value stderr_file;
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
86
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
87 static octave_stream stdin_stream;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
88 static octave_stream stdout_stream;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
89 static octave_stream stderr_stream;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
90
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
91 void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 66
diff changeset
92 initialize_file_io (void)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
93 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
94 stdin_stream = octave_istream::create (&std::cin, "stdin");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
95
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
96 // 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
97 // standard output stream will pass through the pager.
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
98
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
99 stdout_stream = octave_ostream::create (&octave_stdout, "stdout");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
100
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
101 stderr_stream = octave_ostream::create (&std::cerr, "stderr");
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
102
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
103 stdin_file = octave_stream_list::insert (stdin_stream);
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
104 stdout_file = octave_stream_list::insert (stdout_stream);
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
105 stderr_file = octave_stream_list::insert (stderr_stream);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
106 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
107
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
108 void
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
109 close_files (void)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
110 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
111 octave_stream_list::clear ();
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
112 }
636
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
113
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
114 // List of files to delete when we exit or crash.
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
115 //
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5749
diff changeset
116 // FIXME -- this should really be static, but that causes
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
117 // problems on some systems.
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
118 std::stack <std::string> tmp_files;
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
119
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
120 void
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
121 mark_for_deletion (const std::string& file)
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
122 {
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
123 tmp_files.push (file);
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
124 }
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
125
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
126 void
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
127 cleanup_tmp_files (void)
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
128 {
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
129 while (! tmp_files.empty ())
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
130 {
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
131 std::string filename = tmp_files.top ();
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
132 tmp_files.pop ();
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
133 unlink (filename.c_str ());
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
134 }
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
135 }
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
136
4036
1432e11733d1 [project @ 2002-08-12 18:38:40 by jwe]
jwe
parents: 4028
diff changeset
137 static std::ios::openmode
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
138 fopen_mode_to_ios_mode (const std::string& mode_arg)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
139 {
4036
1432e11733d1 [project @ 2002-08-12 18:38:40 by jwe]
jwe
parents: 4028
diff changeset
140 std::ios::openmode retval = std::ios::in;
896
4a2133b26fa7 [project @ 1994-11-09 16:04:06 by jwe]
jwe
parents: 870
diff changeset
141
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
142 if (! mode_arg.empty ())
368
5c987c27f3d7 [project @ 1994-02-16 08:33:09 by jwe]
jwe
parents: 367
diff changeset
143 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
144 // 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
145
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
146 std::string mode = mode_arg;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
147
7078
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
148 // 'W' and 'R' are accepted as 'w' and 'r', but we warn about
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
149 // them because Matlab says they perform "automatic flushing"
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
150 // but we don't know precisely what action that implies.
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
151
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
152 size_t pos = mode.find ('W');
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
153
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
154 if (pos != std::string::npos)
7078
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
155 {
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
156 warning ("fopen: treating mode \"W\" as equivalent to \"w\"");
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
157 mode[pos] = 'w';
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
158 }
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
159
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
160 pos = mode.find ('R');
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
161
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
162 if (pos != std::string::npos)
7078
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
163 {
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
164 warning ("fopen: treating mode \"R\" as equivalent to \"r\"");
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
165 mode[pos] = 'r';
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
166 }
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
167
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
168 pos = mode.find ('z');
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
169
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
170 if (pos != std::string::npos)
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
171 {
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
172 #if defined (HAVE_ZLIB)
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
173 mode.erase (pos, 1);
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
174 #else
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
175 error ("this version of Octave does not support gzipped files");
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
176 #endif
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
177 }
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
178
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
179 if (! error_state)
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
180 {
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
181 if (mode == "rt")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
182 retval = std::ios::in;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
183 else if (mode == "wt")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
184 retval = std::ios::out | std::ios::trunc;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
185 else if (mode == "at")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
186 retval = std::ios::out | std::ios::app;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
187 else if (mode == "r+t")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
188 retval = std::ios::in | std::ios::out;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
189 else if (mode == "w+t")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
190 retval = std::ios::in | std::ios::out | std::ios::trunc;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
191 else if (mode == "a+t")
7097
e8c94e473c68 [project @ 2007-11-02 17:24:23 by jwe]
jwe
parents: 7096
diff changeset
192 retval = std::ios::in | std::ios::out | std::ios::app;
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
193 else if (mode == "rb" || mode == "r")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
194 retval = std::ios::in | std::ios::binary;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
195 else if (mode == "wb" || mode == "w")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
196 retval = std::ios::out | std::ios::trunc | std::ios::binary;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
197 else if (mode == "ab" || mode == "a")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
198 retval = std::ios::out | std::ios::app | std::ios::binary;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
199 else if (mode == "r+b" || mode == "r+")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
200 retval = std::ios::in | std::ios::out | std::ios::binary;
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
201 else if (mode == "w+b" || mode == "w+")
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
202 retval = (std::ios::in | std::ios::out | std::ios::trunc
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
203 | std::ios::binary);
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
204 else if (mode == "a+b" || mode == "a+")
7097
e8c94e473c68 [project @ 2007-11-02 17:24:23 by jwe]
jwe
parents: 7096
diff changeset
205 retval = (std::ios::in | std::ios::out | std::ios::app
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
206 | std::ios::binary);
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
207 else
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
208 ::error ("invalid mode specified");
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
209 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
210 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
211
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
212 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
213 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
214
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
215 DEFUN (fclose, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
216 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
217 @deftypefn {Built-in Function} {} fclose (@var{fid})\n\
4594
3a284f89aa41 [project @ 2003-11-12 02:27:28 by jwe]
jwe
parents: 4587
diff changeset
218 Closes the specified file. If successful, @code{fclose} returns 0,\n\
3a284f89aa41 [project @ 2003-11-12 02:27:28 by jwe]
jwe
parents: 4587
diff changeset
219 otherwise, it returns -1.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
220 @seealso{fopen, fseek, ftell}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
221 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
222 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
223 octave_value retval = -1;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
224
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
225 int nargin = args.length ();
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
226
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
227 if (nargin == 1)
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
228 retval = octave_stream_list::remove (args(0), "fclose");
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
229 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
230 print_usage ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
231
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
232 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
233 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
234
5144
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
235 DEFUN (fclear, args, ,
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
236 "-*- texinfo -*-\n\
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
237 @deftypefn {Built-in Function} {} fclear (@var{fid})\n\
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
238 Clear the stream state for the specified file.\n\
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
239 @end deftypefn")
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
240 {
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
241 octave_value retval;
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
242
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
243 int nargin = args.length ();
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
244
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
245 if (nargin == 1)
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
246 {
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
247 int fid = octave_stream_list::get_file_number (args (0));
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
248
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
249 octave_stream os = octave_stream_list::lookup (fid, "fclear");
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
250
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
251 if (! error_state)
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
252 os.clearerr ();
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
253 }
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
254 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
255 print_usage ();
5144
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
256
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
257 return retval;
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
258 }
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
259
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
260 DEFUN (fflush, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
261 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
262 @deftypefn {Built-in Function} {} fflush (@var{fid})\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
263 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
264 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
265 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
266 stream before calling @code{input}.\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
267 \n\
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
268 @code{fflush} returns 0 on success and an OS dependent error value\n\
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
269 (@minus{}1 on unix) on error.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
270 @seealso{fopen, fclose}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
271 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
272 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
273 octave_value retval = -1;
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
274
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
275 int nargin = args.length ();
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
276
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
277 if (nargin == 1)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
278 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5749
diff changeset
279 // FIXME -- any way to avoid special case for stdout?
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2599
diff changeset
280
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2599
diff changeset
281 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
282
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2599
diff changeset
283 if (fid == 1)
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2599
diff changeset
284 {
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2599
diff changeset
285 flush_octave_stdout ();
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
286
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
287 retval = 0;
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2599
diff changeset
288 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
289 else
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2599
diff changeset
290 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
291 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
292
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
293 if (! error_state)
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
294 retval = os.flush ();
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2599
diff changeset
295 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
296 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
297 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
298 print_usage ();
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
299
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
300 return retval;
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
301 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
302
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
303 DEFUN (fgetl, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
304 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
305 @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
306 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
307 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
308 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
309 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
310 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
311 character.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
312 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
313 If there are no more characters to read, @code{fgetl} returns @minus{}1.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
314 @seealso{fread, fscanf}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
315 @end deftypefn")
1339
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
316 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
317 static std::string who = "fgetl";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
318
2599
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
319 octave_value_list retval;
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
320
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
321 retval(1) = 0;
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
322 retval(0) = -1;
1339
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
323
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
324 int nargin = args.length ();
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
325
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
326 if (nargin == 1 || nargin == 2)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
327 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
328 octave_stream os = octave_stream_list::lookup (args(0), who);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
329
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
330 if (! error_state)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
331 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6159
diff changeset
332 octave_value len_arg = (nargin == 2) ? args(1) : octave_value ();
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
333
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
334 bool err = false;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
335
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
336 std::string tmp = os.getl (len_arg, err, who);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
337
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
338 if (! (error_state || err))
2599
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
339 {
4254
df5f2e433a11 [project @ 2002-12-31 19:43:07 by jwe]
jwe
parents: 4233
diff changeset
340 retval(1) = tmp.length ();
2599
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
341 retval(0) = tmp;
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
342 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
343 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
344 }
1339
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
345 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
346 print_usage ();
1339
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
347
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
348 return retval;
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
349 }
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
350
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
351 DEFUN (fgets, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
352 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
353 @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
354 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
355 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
356 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
357 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
358 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
359 character.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
360 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
361 If there are no more characters to read, @code{fgets} returns @minus{}1.\n\
7781
02a7fe6907d2 file-io.cc: added documentation
bill@denney.ws
parents: 7768
diff changeset
362 @seealso{fputs, fopen, fread, fscanf}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
363 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
364 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
365 static std::string who = "fgets";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
366
2599
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
367 octave_value_list retval;
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
368
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
369 retval(1) = 0.0;
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
370 retval(0) = -1.0;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
371
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
372 int nargin = args.length ();
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
373
1338
3d235e3c13c0 [project @ 1995-08-25 03:10:55 by jwe]
jwe
parents: 1315
diff changeset
374 if (nargin == 1 || nargin == 2)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
375 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
376 octave_stream os = octave_stream_list::lookup (args(0), who);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
377
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
378 if (! error_state)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
379 {
6345
9e058e5fa8a7 [project @ 2007-02-22 22:22:53 by jwe]
jwe
parents: 6159
diff changeset
380 octave_value len_arg = (nargin == 2) ? args(1) : octave_value ();
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
381
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
382 bool err = false;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
383
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
384 std::string tmp = os.gets (len_arg, err, who);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
385
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
386 if (! (error_state || err))
2599
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
387 {
4254
df5f2e433a11 [project @ 2002-12-31 19:43:07 by jwe]
jwe
parents: 4233
diff changeset
388 retval(1) = tmp.length ();
2599
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
389 retval(0) = tmp;
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
390 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
391 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
392 }
1338
3d235e3c13c0 [project @ 1995-08-25 03:10:55 by jwe]
jwe
parents: 1315
diff changeset
393 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
394 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
395
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
396 return retval;
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
397 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
398
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
399 DEFUN (fskipl, args, ,
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
400 "-*- texinfo -*-\n\
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
401 @deftypefn {Built-in Function} {} fskipl (@var{fid}, @var{count})\n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9701
diff changeset
402 Skips a given number of lines, i.e., discards characters until an end-of-line\n\
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
403 is met exactly @var{count}-times, or end-of-file occurs.\n\
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
404 Returns the number of lines skipped (end-of-line sequences encountered).\n\
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
405 If @var{count} is omitted, it defaults to 1. @var{count} may also be\n\
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
406 @code{Inf}, in which case lines are skipped to the end of file.\n\
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
407 This form is suitable for counting lines in a file.\n\
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
408 @seealso{fgetl, fgets}\n\
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
409 @end deftypefn")
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
410 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
411 static std::string who = "fskipl";
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
412
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
413 octave_value retval;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
414
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
415 int nargin = args.length ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
416
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
417 if (nargin == 1 || nargin == 2)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
418 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
419 octave_stream os = octave_stream_list::lookup (args(0), who);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
420
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
421 if (! error_state)
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
422 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
423 octave_value count_arg = (nargin == 2) ? args(1) : octave_value ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
424
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
425 bool err = false;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
426
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
427 long tmp = os.skipl (count_arg, err, who);
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
428
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
429 if (! (error_state || err))
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
430 retval = tmp;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
431 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
432 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
433 else
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
434 print_usage ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
435
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
436 return retval;
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
437 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
438
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
439
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
440 static octave_stream
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
441 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
442 const std::string& arch, int& fid)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
443 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
444 octave_stream retval;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
445
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
446 fid = -1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
447
4036
1432e11733d1 [project @ 2002-08-12 18:38:40 by jwe]
jwe
parents: 4028
diff changeset
448 std::ios::openmode md = fopen_mode_to_ios_mode (mode);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
449
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
450 if (! error_state)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
451 {
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
452 oct_mach_info::float_format flt_fmt =
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
453 oct_mach_info::string_to_float_format (arch);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
454
4798
da0d1c453971 [project @ 2004-02-24 17:30:05 by jwe]
jwe
parents: 4797
diff changeset
455 if (! error_state)
da0d1c453971 [project @ 2004-02-24 17:30:05 by jwe]
jwe
parents: 4797
diff changeset
456 {
6159
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
457 std::string fname = file_ops::tilde_expand (name);
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
458
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
459 file_stat fs (fname);
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
460
6838
5e3350bdd91d [project @ 2007-08-28 02:59:58 by jwe]
jwe
parents: 6665
diff changeset
461 if (! (md & std::ios::out
5e3350bdd91d [project @ 2007-08-28 02:59:58 by jwe]
jwe
parents: 6665
diff changeset
462 || octave_env::absolute_pathname (fname)
5e3350bdd91d [project @ 2007-08-28 02:59:58 by jwe]
jwe
parents: 6665
diff changeset
463 || octave_env::rooted_relative_pathname (fname)))
6159
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
464 {
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
465 if (! fs.exists ())
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
466 {
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
467 std::string tmp = octave_env::make_absolute
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
468 (load_path::find_file (fname), octave_env::getcwd ());
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
469
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
470 if (! tmp.empty ())
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
471 {
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
472 warning_with_id ("Octave:fopen-file-in-path",
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
473 "fopen: file found in load path");
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
474 fname = tmp;
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
475 }
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
476 }
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
477 }
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
478
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
479 if (! fs.is_dir ())
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
480 {
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
481 std::string tmode = mode;
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6345
diff changeset
482
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
483 // Use binary mode if 't' is not specified, but don't add
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
484 // 'b' if it is already present.
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6345
diff changeset
485
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
486 size_t bpos = tmode.find ('b');
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
487 size_t tpos = tmode.find ('t');
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
488
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
489 if (bpos == std::string::npos && tpos == std::string::npos)
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
490 tmode += 'b';
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents: 6345
diff changeset
491
6905
aee959a21c4b [project @ 2007-09-17 16:00:30 by jwe]
jwe
parents: 6838
diff changeset
492 #if defined (HAVE_ZLIB)
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
493 size_t pos = tmode.find ('z');
4798
da0d1c453971 [project @ 2004-02-24 17:30:05 by jwe]
jwe
parents: 4797
diff changeset
494
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
495 if (pos != std::string::npos)
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
496 {
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
497 tmode.erase (pos, 1);
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
498
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
499 gzFile fptr = ::gzopen (fname.c_str (), tmode.c_str ());
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
500
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
501 if (fptr)
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
502 retval = octave_zstdiostream::create (fname, fptr, md, flt_fmt);
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
503 else
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
504 {
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
505 using namespace std;
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
506 retval.error (::strerror (errno));
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
507 }
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
508 }
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
509 else
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
510 #endif
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
511 {
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
512 FILE *fptr = ::fopen (fname.c_str (), tmode.c_str ());
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
513
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
514 retval = octave_stdiostream::create (fname, fptr, md, flt_fmt);
5370
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
515
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
516 if (! fptr)
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
517 {
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
518 using namespace std;
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
519 retval.error (::strerror (errno));
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
520 }
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
521 }
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
522
4798
da0d1c453971 [project @ 2004-02-24 17:30:05 by jwe]
jwe
parents: 4797
diff changeset
523 }
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4726
diff changeset
524 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
525 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
526
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
527 return retval;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
528 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
529
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
530 static octave_stream
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
531 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
532 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
533 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
534 octave_stream retval;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
535
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
536 fid = -1;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
537
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
538 std::string name = tc_name.string_value ();
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
539
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
540 if (! error_state)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
541 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
542 std::string mode = tc_mode.string_value ();
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
543
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
544 if (! error_state)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
545 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
546 std::string arch = tc_arch.string_value ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
547
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
548 if (! error_state)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
549 retval = do_stream_open (name, mode, arch, fid);
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
550 else
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
551 ::error ("%s: architecture type must be a string", fcn);
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
552 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
553 else
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
554 ::error ("%s: file mode must be a string", fcn);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
555 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
556 else
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
557 ::error ("%s: file name must be a string", fcn);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
558
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
559 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
560 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
561
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
562 DEFUN (fopen, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
563 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
564 @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
565 @deftypefnx {Built-in Function} {@var{fid_list} =} fopen (\"all\")\n\
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5333
diff changeset
566 @deftypefnx {Built-in Function} {[@var{file}, @var{mode}, @var{arch}] =} fopen (@var{fid})\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
567 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
568 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
569 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
570 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
571 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
572 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
573 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
574 reading, writing, or both.\n\
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
575 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
576 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
577 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
578 @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
579 \n\
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5333
diff changeset
580 The third form of the @code{fopen} function returns information about the\n\
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5333
diff changeset
581 open file given its file id.\n\
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
582 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
583 For example,\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
584 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
585 @example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
586 myfile = fopen (\"splat.dat\", \"r\", \"ieee-le\");\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
587 @end example\n\
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
588 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
589 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
590 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
591 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
592 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
593 representation.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
594 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
595 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
596 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
597 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
598 produce unexpected results.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
599 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
600 The possible values @samp{mode} may have are\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
601 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
602 @table @asis\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
603 @item @samp{r}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
604 Open a file for reading.\n\
3263
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
605 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
606 @item @samp{w}\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6905
diff changeset
607 Open a file for writing. The previous contents are discarded.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
608 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
609 @item @samp{a}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
610 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
611 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
612 @item @samp{r+}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
613 Open an existing file for reading and writing.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
614 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
615 @item @samp{w+}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
616 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
617 discarded.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
618 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
619 @item @samp{a+}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
620 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
621 file.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
622 @end table\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
623 \n\
4865
2ac0f95eaa29 [project @ 2004-04-16 16:32:24 by jwe]
jwe
parents: 4799
diff changeset
624 Append a \"t\" to the mode string to open the file in text mode or a\n\
2ac0f95eaa29 [project @ 2004-04-16 16:32:24 by jwe]
jwe
parents: 4799
diff changeset
625 \"b\" to open in binary mode. On Windows and Macintosh systems, text\n\
2ac0f95eaa29 [project @ 2004-04-16 16:32:24 by jwe]
jwe
parents: 4799
diff changeset
626 mode reading and writing automatically converts linefeeds to the\n\
2ac0f95eaa29 [project @ 2004-04-16 16:32:24 by jwe]
jwe
parents: 4799
diff changeset
627 appropriate line end character for the system (carriage-return linefeed\n\
6665
cfb849d6f314 [project @ 2007-05-28 05:45:32 by jwe]
jwe
parents: 6483
diff changeset
628 on Windows, carriage-return on Macintosh). The default if no mode is\n\
4865
2ac0f95eaa29 [project @ 2004-04-16 16:32:24 by jwe]
jwe
parents: 4799
diff changeset
629 specified is binary mode.\n\
2ac0f95eaa29 [project @ 2004-04-16 16:32:24 by jwe]
jwe
parents: 4799
diff changeset
630 \n\
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
631 Additionally, you may append a \"z\" to the mode string to open a\n\
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
632 gzipped file for reading or writing. For this to be successful, you\n\
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
633 must also open the file in binary mode.\n\
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
634 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
635 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
636 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
637 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
638 @table @asis\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
639 @samp{native}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
640 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
641 \n\
4082
b8bae1ba4651 [project @ 2002-10-01 18:10:05 by jwe]
jwe
parents: 4070
diff changeset
642 @samp{ieee-be}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
643 IEEE big endian format.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
644 \n\
4082
b8bae1ba4651 [project @ 2002-10-01 18:10:05 by jwe]
jwe
parents: 4070
diff changeset
645 @samp{ieee-le}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
646 IEEE little endian format.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
647 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
648 @samp{vaxd}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
649 VAX D floating format.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
650 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
651 @samp{vaxg}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
652 VAX G floating format.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
653 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
654 @samp{cray}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
655 Cray floating format.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
656 @end table\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
657 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
658 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
659 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
660 @samp{ieee-be}, and @samp{ieee-le} formats.\n\
7781
02a7fe6907d2 file-io.cc: added documentation
bill@denney.ws
parents: 7768
diff changeset
661 @seealso{fclose, fgets, fputs, fread, fseek, ferror, fprintf, fscanf, ftell, fwrite}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
662 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
663 {
2599
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
664 octave_value_list retval;
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
665
9705ea40f0a2 [project @ 1996-12-19 04:49:09 by jwe]
jwe
parents: 2458
diff changeset
666 retval(0) = -1.0;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
667
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
668 int nargin = args.length ();
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
669
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
670 if (nargin == 1)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
671 {
3263
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
672 if (args(0).is_string ())
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
673 {
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
674 // 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
675 // 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
676 // 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
677 // to supply more than one argument.
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
678
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
679 if (args(0).string_value () == "all")
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
680 return octave_stream_list::open_file_numbers ();
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
681 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
682 else
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
683 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
684 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
685
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
686 if (! error_state)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
687 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
688 retval(2) = tmp(2);
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
689 retval(1) = tmp(1);
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
690 retval(0) = tmp(0);
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
691 }
3263
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
692
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
693 return retval;
2432
874f758eade5 [project @ 1996-10-26 16:37:36 by jwe]
jwe
parents: 2370
diff changeset
694 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
695 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
696
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
697 if (nargin > 0 && nargin < 4)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
698 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
699 octave_value mode = (nargin == 2 || nargin == 3)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
700 ? args(1) : octave_value ("r");
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
701
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
702 octave_value arch = (nargin == 3)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
703 ? args(2) : octave_value ("native");
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
704
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
705 int fid = -1;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
706
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
707 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
708
5370
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
709 if (os && ! error_state)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
710 {
5370
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
711 retval(1) = "";
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
712 retval(0) = octave_stream_list::insert (os);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
713 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
714 else
5370
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
715 {
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
716 int error_number = 0;
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
717
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
718 retval(1) = os.error (false, error_number);
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
719 retval(0) = -1.0;
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
720 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
721 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
722 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
723 print_usage ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
724
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
725 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
726 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
727
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
728 DEFUN (freport, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
729 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
730 @deftypefn {Built-in Function} {} freport ()\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
731 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
732 for reading, writing, or both. For example,\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
733 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
734 @example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
735 @group\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
736 freport ()\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
737 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
738 @print{} number mode name\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
739 @print{} \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
740 @print{} 0 r stdin\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
741 @print{} 1 w stdout\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
742 @print{} 2 w stderr\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
743 @print{} 3 r myfile\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
744 @end group\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
745 @end example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
746 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
747 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
748 octave_value_list retval;
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
749
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
750 int nargin = args.length ();
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
751
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
752 if (nargin > 0)
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
753 warning ("freport: ignoring extra arguments");
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
754
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
755 octave_stdout << octave_stream_list::list_open_files ();
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
756
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
757 return retval;
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
758 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
759
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
760 DEFUN (frewind, args, nargout,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
761 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
762 @deftypefn {Built-in Function} {} frewind (@var{fid})\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
763 Move the file pointer to the beginning of the file @var{fid}, returning\n\
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
764 0 for success, and -1 if an error was encountered. It is equivalent to\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
765 @code{fseek (@var{fid}, 0, SEEK_SET)}.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
766 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
767 {
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
768 octave_value retval;
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
769
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
770 int result = -1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
771
506
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
772 int nargin = args.length ();
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
773
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
774 if (nargin == 1)
1086
75fc98220389 [project @ 1995-01-31 04:17:15 by jwe]
jwe
parents: 1049
diff changeset
775 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
776 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
777
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
778 if (! error_state)
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
779 result = os.rewind ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
780 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
781 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
782 print_usage ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
783
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
784 if (nargout > 0)
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
785 retval = result;
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
786
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
787 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
788 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
789
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
790 DEFUN (fseek, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
791 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
792 @deftypefn {Built-in Function} {} fseek (@var{fid}, @var{offset}, @var{origin})\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
793 Set the file pointer to any location within the file @var{fid}.\n\
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
794 \n\
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
795 The pointer is positioned @var{offset} characters from the @var{origin},\n\
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
796 which may be one of the predefined variables @w{@code{SEEK_CUR}} (current\n\
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
797 position), @w{@code{SEEK_SET}} (beginning), or @w{@code{SEEK_END}} (end of\n\
9039
51dc9691f23f Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
798 file) or strings \"cof\", \"bof\" or \"eof\". If @var{origin} is omitted,\n\
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
799 @w{@code{SEEK_SET}} is assumed. The offset must be zero, or a value returned\n\
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
800 by @code{ftell} (in which case @var{origin} must be @w{@code{SEEK_SET}}).\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
801 \n\
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
802 Return 0 on success and -1 on error.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
803 @seealso{ftell, fopen, fclose}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
804 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
805 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
806 octave_value retval = -1;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
807
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
808 int nargin = args.length ();
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
809
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
810 if (nargin == 2 || nargin == 3)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
811 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
812 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
813
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
814 if (! error_state)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
815 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
816 octave_value origin_arg = (nargin == 3)
2341
6ee55c0f25a9 [project @ 1996-07-24 10:33:09 by jwe]
jwe
parents: 2324
diff changeset
817 ? args(2) : octave_value (-1.0);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
818
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
819 retval = os.seek (args(1), origin_arg);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
820 }
368
5c987c27f3d7 [project @ 1994-02-16 08:33:09 by jwe]
jwe
parents: 367
diff changeset
821 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
822 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
823 print_usage ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
824
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
825 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
826 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
827
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
828 DEFUN (ftell, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
829 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
830 @deftypefn {Built-in Function} {} ftell (@var{fid})\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
831 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
832 from the beginning of the file @var{fid}.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
833 @seealso{fseek, fopen, fclose}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
834 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
835 {
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4726
diff changeset
836 octave_value retval = -1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
837
506
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
838 int nargin = args.length ();
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
839
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
840 if (nargin == 1)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
841 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
842 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
843
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
844 if (! error_state)
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4726
diff changeset
845 retval = os.tell ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
846 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
847 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
848 print_usage ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
849
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
850 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
851 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
852
3737
b736f8b8f0a1 [project @ 2000-11-16 18:01:08 by jwe]
jwe
parents: 3569
diff changeset
853 DEFUN (fprintf, args, nargout,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
854 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
855 @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
856 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
857 written to the stream @var{fid} instead of @code{stdout}.\n\
8606
0611b48a2b61 file-io.cc (Ffprintf): doc fix
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
858 If @var{fid} is omitted, the output is written to @code{stdout}.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
859 @seealso{printf, sprintf, fread, fscanf, fopen, fclose}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
860 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
861 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
862 static std::string who = "fprintf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
863
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
864 octave_value retval;
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
865
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
866 int result = -1;
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
867
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
868 int nargin = args.length ();
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
869
2875
2e45e7a3d45e [project @ 1997-04-24 08:56:20 by jwe]
jwe
parents: 2873
diff changeset
870 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
871 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
872 octave_stream os;
2873
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
873 int fmt_n = 0;
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
874
3737
b736f8b8f0a1 [project @ 2000-11-16 18:01:08 by jwe]
jwe
parents: 3569
diff changeset
875 if (args(0).is_string ())
b736f8b8f0a1 [project @ 2000-11-16 18:01:08 by jwe]
jwe
parents: 3569
diff changeset
876 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
877 os = octave_stream_list::lookup (1, who);
3737
b736f8b8f0a1 [project @ 2000-11-16 18:01:08 by jwe]
jwe
parents: 3569
diff changeset
878 }
2873
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
879 else
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
880 {
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
881 fmt_n = 1;
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
882 os = octave_stream_list::lookup (args(0), who);
2873
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
883 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
884
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
885 if (! error_state)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
886 {
2873
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
887 if (args(fmt_n).is_string ())
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
888 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
889 octave_value_list tmp_args;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
890
2873
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
891 if (nargin > 1 + fmt_n)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
892 {
2873
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
893 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
894
2873
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
895 for (int i = fmt_n + 1; i < nargin; i++)
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
896 tmp_args(i-fmt_n-1) = args(i);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
897 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
898
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
899 result = os.printf (args(fmt_n), tmp_args, who);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
900 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
901 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
902 ::error ("%s: format must be a string", who.c_str ());
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
903 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
904 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
905 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
906 print_usage ();
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
907
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
908 if (nargout > 0)
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
909 retval = result;
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
910
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
911 return retval;
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
912 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
913
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
914 DEFUN (printf, args, nargout,
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
915 "-*- texinfo -*-\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
916 @deftypefn {Built-in Function} {} printf (@var{template}, @dots{})\n\
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
917 Print optional arguments under the control of the template string\n\
5653
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
918 @var{template} to the stream @code{stdout} and return the number of\n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
919 characters printed.\n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
920 @ifclear OCTAVE_MANUAL\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
921 \n\
5653
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
922 See the Formatted Output section of the GNU Octave manual for a\n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
923 complete description of the syntax of the template string.\n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
924 @end ifclear\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
925 @seealso{fprintf, sprintf, scanf}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
926 @end deftypefn")
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
927 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
928 static std::string who = "printf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
929
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
930 octave_value retval;
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
931
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
932 int result = -1;
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
933
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
934 int nargin = args.length ();
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
935
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
936 if (nargin > 0)
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
937 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
938 if (args(0).is_string ())
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
939 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
940 octave_value_list tmp_args;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
941
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
942 if (nargin > 1)
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
943 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
944 tmp_args.resize (nargin-1, octave_value ());
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
945
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
946 for (int i = 1; i < nargin; i++)
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
947 tmp_args(i-1) = args(i);
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
948 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
949
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
950 result = stdout_stream.printf (args(0), tmp_args, who);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
951 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
952 else
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
953 ::error ("%s: format must be a string", who.c_str ());
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
954 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
955 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
956 print_usage ();
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
957
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
958 if (nargout > 0)
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
959 retval = result;
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
960
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
961 return retval;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
962 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
963
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
964 DEFUN (fputs, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
965 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
966 @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
967 Write a string to a file with no formatting.\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
968 \n\
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
969 Return a non-negative number on success and EOF on error.\n\
7781
02a7fe6907d2 file-io.cc: added documentation
bill@denney.ws
parents: 7768
diff changeset
970 @seealso{scanf, sscanf, fread, fprintf, fgets, fscanf}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
971 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
972 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
973 static std::string who = "fputs";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
974
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
975 octave_value retval = -1;
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
976
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
977 int nargin = args.length ();
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
978
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
979 if (nargin == 2)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
980 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
981 octave_stream os = octave_stream_list::lookup (args(0), who);
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
982
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
983 if (! error_state)
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
984 retval = os.puts (args(1), who);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
985 }
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
986 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
987 print_usage ();
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
988
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
989 return retval;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
990 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
991
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
992 DEFUN (puts, args, ,
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
993 "-*- texinfo -*-\n\
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
994 @deftypefn {Built-in Function} {} puts (@var{string})\n\
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
995 Write a string to the standard output with no formatting.\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
996 \n\
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
997 Return a non-negative number on success and EOF on error.\n\
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
998 @end deftypefn")
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
999 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1000 static std::string who = "puts";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1001
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1002 octave_value retval = -1;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1003
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1004 if (args.length () == 1)
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1005 retval = stdout_stream.puts (args(0), who);
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1006 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1007 print_usage ();
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1008
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1009 return retval;
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1010 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1011
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1012 DEFUN (sprintf, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1013 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1014 @deftypefn {Built-in Function} {} sprintf (@var{template}, @dots{})\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1015 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
1016 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
1017 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
1018 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
1019 converted.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1020 @seealso{printf, fprintf, sscanf}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1021 @end deftypefn")
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1022 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1023 static std::string who = "sprintf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1024
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1025 octave_value_list retval;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1026
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1027 int nargin = args.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1028
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1029 if (nargin > 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1030 {
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1031 retval(2) = -1.0;
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1032 retval(1) = "unknown error";
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1033 retval(0) = "";
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1034
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1035 octave_ostrstream *ostr = new octave_ostrstream ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1036
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1037 octave_stream os (ostr);
628
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
1038
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1039 if (os.is_valid ())
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1040 {
6007
52b520087c50 [project @ 2006-09-27 15:05:53 by jwe]
jwe
parents: 5906
diff changeset
1041 octave_value fmt_arg = args(0);
52b520087c50 [project @ 2006-09-27 15:05:53 by jwe]
jwe
parents: 5906
diff changeset
1042
52b520087c50 [project @ 2006-09-27 15:05:53 by jwe]
jwe
parents: 5906
diff changeset
1043 if (fmt_arg.is_string ())
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1044 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1045 octave_value_list tmp_args;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1046
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1047 if (nargin > 1)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1048 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1049 tmp_args.resize (nargin-1, octave_value ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1050
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1051 for (int i = 1; i < nargin; i++)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1052 tmp_args(i-1) = args(i);
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1053 }
628
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
1054
6007
52b520087c50 [project @ 2006-09-27 15:05:53 by jwe]
jwe
parents: 5906
diff changeset
1055 retval(2) = os.printf (fmt_arg, tmp_args, who);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1056 retval(1) = os.error ();
6007
52b520087c50 [project @ 2006-09-27 15:05:53 by jwe]
jwe
parents: 5906
diff changeset
1057 retval(0) = octave_value (ostr->str (),
52b520087c50 [project @ 2006-09-27 15:05:53 by jwe]
jwe
parents: 5906
diff changeset
1058 fmt_arg.is_sq_string () ? '\'' : '"');
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1059 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1060 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1061 ::error ("%s: format must be a string", who.c_str ());
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1062 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1063 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1064 ::error ("%s: unable to create output buffer", who.c_str ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1065 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1066 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1067 print_usage ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1068
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1069 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1070 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1071
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1072 DEFUN (fscanf, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1073 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1074 @deftypefn {Built-in Function} {[@var{val}, @var{count}] =} fscanf (@var{fid}, @var{template}, @var{size})\n\
7650
eb7bdde776f2 Texinfo fixes
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
1075 @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
1076 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
1077 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
1078 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1079 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
1080 and may be one of\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1081 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1082 @table @code\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1083 @item Inf\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1084 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
1085 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1086 @item @var{nr}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1087 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
1088 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1089 @item [@var{nr}, Inf]\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1090 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
1091 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
1092 column is padded with zeros.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1093 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1094 @item [@var{nr}, @var{nc}]\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1095 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
1096 @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
1097 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
1098 @end table\n\
2122
91d802f77456 [project @ 1996-05-12 07:08:38 by jwe]
jwe
parents: 2116
diff changeset
1099 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1100 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1101 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
1102 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1103 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
1104 conversions.\n\
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1105 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1106 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
1107 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1108 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
1109 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
1110 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
1111 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
1112 conversions is returned in @var{count}\n\
5653
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
1113 @ifclear OCTAVE_MANUAL\n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
1114 \n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
1115 See the Formatted Input section of the GNU Octave manual for a\n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
1116 complete description of the syntax of the template string.\n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
1117 @end ifclear\n\
7781
02a7fe6907d2 file-io.cc: added documentation
bill@denney.ws
parents: 7768
diff changeset
1118 @seealso{scanf, sscanf, fread, fprintf, fgets, fputs}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1119 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1120 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1121 static std::string who = "fscanf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1122
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1123 octave_value_list retval;
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1124
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1125 int nargin = args.length ();
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1126
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1127 if (nargin == 3 && args(2).is_string ())
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1128 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1129 octave_stream os = octave_stream_list::lookup (args(0), who);
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1130
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
1131 if (! error_state)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1132 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1133 if (args(1).is_string ())
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
1134 retval = os.oscanf (args(1), who);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1135 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1136 ::error ("%s: format must be a string", who.c_str ());
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1137 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1138 }
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1139 else
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1140 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1141 retval (1) = 0.0;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1142 retval (0) = Matrix ();
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1143
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1144 if (nargin == 2 || nargin == 3)
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1145 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1146 octave_stream os = octave_stream_list::lookup (args(0), who);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1147
3342
d8d3700fb4ab [project @ 1999-11-05 16:55:17 by jwe]
jwe
parents: 3341
diff changeset
1148 if (! error_state)
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1149 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1150 if (args(1).is_string ())
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1151 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5144
diff changeset
1152 octave_idx_type count = 0;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1153
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3775
diff changeset
1154 Array<double> size = (nargin == 3)
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4101
diff changeset
1155 ? args(2).vector_value ()
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4101
diff changeset
1156 : Array<double> (1, lo_ieee_inf_value ());
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1157
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1158 if (! error_state)
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1159 {
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
1160 octave_value tmp = os.scanf (args(1), size, count, who);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1161
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1162 if (! error_state)
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1163 {
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1164 retval(1) = count;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1165 retval(0) = tmp;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1166 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1167 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1168 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1169 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1170 ::error ("%s: format must be a string", who.c_str ());
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1171 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1172 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1173 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1174 print_usage ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1175 }
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1176
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1177 return retval;
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1178 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1179
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1180 DEFUN (sscanf, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1181 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1182 @deftypefn {Built-in Function} {[@var{val}, @var{count}] =} sscanf (@var{string}, @var{template}, @var{size})\n\
7650
eb7bdde776f2 Texinfo fixes
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
1183 @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
1184 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
1185 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
1186 string is treated as an end-of-file condition.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1187 @seealso{fscanf, scanf, sprintf}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1188 @end deftypefn")
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1189 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1190 static std::string who = "sscanf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1191
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1192 octave_value_list retval;
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1193
506
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
1194 int nargin = args.length ();
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
1195
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1196 if (nargin == 3 && args(2).is_string ())
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1197 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1198 if (args(0).is_string ())
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1199 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1200 std::string data = args(0).string_value ();
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1201
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1202 octave_stream os = octave_istrstream::create (data);
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
1203
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1204 if (os.is_valid ())
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1205 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1206 if (args(1).is_string ())
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
1207 retval = os.oscanf (args(1), who);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1208 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1209 ::error ("%s: format must be a string", who.c_str ());
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1210 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1211 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1212 ::error ("%s: unable to create temporary input buffer",
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1213 who.c_str ());
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1214 }
636
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
1215 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1216 ::error ("%s: first argument must be a string", who.c_str ());
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1217 }
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1218 else
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1219 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1220 if (nargin == 2 || nargin == 3)
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1221 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1222 retval(3) = -1.0;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1223 retval(2) = "unknown error";
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1224 retval(1) = 0.0;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1225 retval(0) = Matrix ();
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1226
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1227 if (args(0).is_string ())
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1228 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1229 std::string data = args(0).string_value ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1230
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1231 octave_stream os = octave_istrstream::create (data);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1232
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1233 if (os.is_valid ())
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1234 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1235 if (args(1).is_string ())
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1236 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5144
diff changeset
1237 octave_idx_type count = 0;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1238
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3775
diff changeset
1239 Array<double> size = (nargin == 3)
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3775
diff changeset
1240 ? args(2).vector_value ()
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4101
diff changeset
1241 : Array<double> (1, lo_ieee_inf_value ());
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1242
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
1243 octave_value tmp = os.scanf (args(1), size, count, who);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1244
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1245 if (! error_state)
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1246 {
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1247 // FIXME -- is this the right thing to do?
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1248 // Extract error message first, because getting
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1249 // position will clear it.
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1250 std::string errmsg = os.error ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1251
8773
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1252 retval(3) = os.tell () + 1;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1253 retval(2) = errmsg;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1254 retval(1) = count;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1255 retval(0) = tmp;
9e3111d203c0 disallow reading from stdin while running interactively
John W. Eaton <jwe@octave.org>
parents: 8606
diff changeset
1256 }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1257 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1258 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1259 ::error ("%s: format must be a string", who.c_str ());
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1260 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1261 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1262 ::error ("%s: unable to create temporary input buffer",
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1263 who.c_str ());
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1264 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1265 else
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1266 ::error ("%s: first argument must be a string", who.c_str ());
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1267 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1268 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1269 print_usage ();
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1270 }
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1271
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1272 return retval;
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1273 }
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1274
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1275 DEFUN (scanf, args, nargout,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1276 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1277 @deftypefn {Built-in Function} {[@var{val}, @var{count}] =} scanf (@var{template}, @var{size})\n\
7650
eb7bdde776f2 Texinfo fixes
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
1278 @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
1279 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
1280 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1281 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
1282 programs.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1283 @seealso{fscanf, sscanf, printf}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1284 @end deftypefn")
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1285 {
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1286 int nargin = args.length ();
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1287
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1288 octave_value_list tmp_args (nargin+1, octave_value ());
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1289
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1290 tmp_args (0) = 0.0;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1291 for (int i = 0; i < nargin; i++)
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1292 tmp_args (i+1) = args (i);
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1293
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1294 return Ffscanf (tmp_args, nargout);
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1295 }
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1296
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1297 static octave_value
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1298 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
1299 const octave_value& prec_arg, const octave_value& skip_arg,
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5144
diff changeset
1300 const octave_value& arch_arg, octave_idx_type& count)
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1301 {
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1302 octave_value retval;
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1303
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1304 count = -1;
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1305
3810
f19f00339363 [project @ 2001-03-29 21:03:01 by jwe]
jwe
parents: 3775
diff changeset
1306 Array<double> size = size_arg.vector_value ();
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1307
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1308 if (! error_state)
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1309 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1310 std::string prec = prec_arg.string_value ();
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1311
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1312 if (! error_state)
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1313 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1314 int block_size = 1;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1315 oct_data_conv::data_type input_type;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1316 oct_data_conv::data_type output_type;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1317
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1318 oct_data_conv::string_to_data_type (prec, block_size,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1319 input_type, output_type);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1320
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1321 if (! error_state)
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1322 {
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1323 int skip = skip_arg.int_value (true);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1324
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1325 if (! error_state)
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1326 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1327 std::string arch = arch_arg.string_value ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1328
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1329 if (! error_state)
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1330 {
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1331 oct_mach_info::float_format flt_fmt
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1332 = oct_mach_info::string_to_float_format (arch);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1333
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1334 if (! error_state)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1335 retval = os.read (size, block_size, input_type,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1336 output_type, skip, flt_fmt, count);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1337 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1338 else
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1339 ::error ("fread: architecture type must be a string");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1340 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1341 else
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1342 ::error ("fread: skip must be an integer");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1343 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1344 else
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1345 ::error ("fread: invalid data type specified");
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1346 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1347 else
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1348 ::error ("fread: precision must be a string");
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1349 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1350 else
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1351 ::error ("fread: invalid size specified");
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1352
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1353 return retval;
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1354 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1355
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1356 DEFUN (fread, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1357 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1358 @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
1359 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
1360 @var{fid}.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1361 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1362 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
1363 and may be one of\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1364 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1365 @table @code\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1366 @item Inf\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1367 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
1368 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1369 @item @var{nr}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1370 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
1371 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1372 @item [@var{nr}, Inf]\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1373 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
1374 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
1375 column is padded with zeros.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1376 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1377 @item [@var{nr}, @var{nc}]\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1378 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
1379 @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
1380 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
1381 @end table\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1382 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1383 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1384 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
1385 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1386 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
1387 data to read and may be one of\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1388 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1389 @table @code\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1390 @item \"schar\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1391 @itemx \"signed char\"\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1392 Signed character.\n\
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1393 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1394 @item \"uchar\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1395 @itemx \"unsigned char\"\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1396 Unsigned character.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1397 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1398 @item \"int8\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1399 @itemx \"integer*1\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1400 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1401 8-bit signed integer.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1402 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1403 @item \"int16\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1404 @itemx \"integer*2\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1405 16-bit signed integer.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1406 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1407 @item \"int32\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1408 @itemx \"integer*4\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1409 32-bit signed integer.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1410 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1411 @item \"int64\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1412 @itemx \"integer*8\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1413 64-bit signed integer.\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1414 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1415 @item \"uint8\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1416 8-bit unsigned integer.\n\
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1417 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1418 @item \"uint16\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1419 16-bit unsigned integer.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1420 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1421 @item \"uint32\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1422 32-bit unsigned integer.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1423 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1424 @item \"uint64\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1425 64-bit unsigned integer.\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1426 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1427 @item \"single\"\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1428 @itemx \"float32\"\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1429 @itemx \"real*4\"\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1430 32-bit floating point number.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1431 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1432 @item \"double\"\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1433 @itemx \"float64\"\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1434 @itemx \"real*8\"\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1435 64-bit floating point number.\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1436 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1437 @item \"char\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1438 @itemx \"char*1\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1439 Single character.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1440 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1441 @item \"short\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1442 Short integer (size is platform dependent).\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1443 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1444 @item \"int\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1445 Integer (size is platform dependent).\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1446 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1447 @item \"long\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1448 Long integer (size is platform dependent).\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1449 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1450 @item \"ushort\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1451 @itemx \"unsigned short\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1452 Unsigned short integer (size is platform dependent).\n\
4610
02d2fcf835fc [project @ 2003-11-14 17:08:59 by jwe]
jwe
parents: 4594
diff changeset
1453 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1454 @item \"uint\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1455 @itemx \"unsigned int\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1456 Unsigned integer (size is platform dependent).\n\
4610
02d2fcf835fc [project @ 2003-11-14 17:08:59 by jwe]
jwe
parents: 4594
diff changeset
1457 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1458 @item \"ulong\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1459 @itemx \"unsigned long\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1460 Unsigned long integer (size is platform dependent).\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1461 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1462 @item \"float\"\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1463 Single precision floating point number (size is platform dependent).\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1464 @end table\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1465 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1466 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1467 The default precision is @code{\"uchar\"}.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1468 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1469 The @var{precision} argument may also specify an optional repeat\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1470 count. For example, @samp{32*single} causes @code{fread} to read\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1471 a block of 32 single precision floating point numbers. Reading in\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1472 blocks is useful in combination with the @var{skip} argument.\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1473 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1474 The @var{precision} argument may also specify a type conversion.\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1475 For example, @samp{int16=>int32} causes @code{fread} to read 16-bit\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1476 integer values and return an array of 32-bit integer values. By\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1477 default, @code{fread} returns a double precision array. The special\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1478 form @samp{*TYPE} is shorthand for @samp{TYPE=>TYPE}.\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1479 \n\
7096
81bed50b9feb [project @ 2007-11-02 16:13:43 by jwe]
jwe
parents: 7078
diff changeset
1480 The conversion and repeat counts may be combined. For example, the\n\
81bed50b9feb [project @ 2007-11-02 16:13:43 by jwe]
jwe
parents: 7078
diff changeset
1481 specification @samp{32*single=>single} causes @code{fread} to read\n\
81bed50b9feb [project @ 2007-11-02 16:13:43 by jwe]
jwe
parents: 7078
diff changeset
1482 blocks of single precision floating point values and return an array\n\
81bed50b9feb [project @ 2007-11-02 16:13:43 by jwe]
jwe
parents: 7078
diff changeset
1483 of single precision values instead of the default array of double\n\
81bed50b9feb [project @ 2007-11-02 16:13:43 by jwe]
jwe
parents: 7078
diff changeset
1484 precision values.\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1485 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1486 The optional argument @var{skip} specifies the number of bytes to skip\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1487 after each element (or block of elements) is read. If it is not\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1488 specified, a value of 0 is assumed. If the final block read is not\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1489 complete, the final skip is omitted. For example,\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1490 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1491 @example\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1492 fread (f, 10, \"3*single=>single\", 8)\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1493 @end example\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1494 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1495 @noindent\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1496 will omit the final 8-byte skip because the last read will not be\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1497 a complete block of 3 values.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1498 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1499 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
1500 for the file. Valid values are\n\
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1501 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1502 @table @code\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1503 @item \"native\"\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1504 The format of the current machine.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1505 \n\
4546
a4796ccde726 [project @ 2003-10-24 18:58:22 by jwe]
jwe
parents: 4537
diff changeset
1506 @item \"ieee-be\"\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1507 IEEE big endian.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1508 \n\
4546
a4796ccde726 [project @ 2003-10-24 18:58:22 by jwe]
jwe
parents: 4537
diff changeset
1509 @item \"ieee-le\"\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1510 IEEE little endian.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1511 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1512 @item \"vaxd\"\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1513 VAX D floating format.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1514 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1515 @item \"vaxg\"\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1516 VAX G floating format.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1517 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1518 @item \"cray\"\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1519 Cray floating format.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1520 @end table\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1521 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1522 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1523 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
1524 @code{\"ieee-le\"} formats.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1525 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1526 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
1527 values read is returned in @code{count}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1528 @seealso{fwrite, fopen, fclose}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1529 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1530 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1531 octave_value_list retval;
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1532
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1533 int nargin = args.length ();
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1534
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1535 if (nargin > 0 && nargin < 6)
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1536 {
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1537 retval(1) = -1.0;
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1538 retval(0) = Matrix ();
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1539
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
1540 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
1541
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
1542 if (! error_state)
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1543 {
4257
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1544 octave_value size = lo_ieee_inf_value ();
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1545 octave_value prec = "uchar";
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1546 octave_value skip = 0;
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1547 octave_value arch = "unknown";
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1548
4257
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1549 int idx = 1;
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1550
7708
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1551 if (nargin > idx && ! args(idx).is_string ())
4257
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1552 size = args(idx++);
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1553
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1554 if (nargin > idx)
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1555 prec = args(idx++);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1556
4257
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1557 if (nargin > idx)
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1558 skip = args(idx++);
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1559
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1560 if (nargin > idx)
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1561 arch = args(idx++);
7708
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1562 else if (skip.is_string ())
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1563 {
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1564 arch = skip;
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1565 skip = 0;
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1566 }
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1567
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5144
diff changeset
1568 octave_idx_type count = -1;
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1569
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1570 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
1571
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
1572 retval(1) = count;
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1573 retval(0) = tmp;
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1574 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1575 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1576 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1577 print_usage ();
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1578
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1579 return retval;
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1580 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1581
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1582 static int
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1583 do_fwrite (octave_stream& os, const octave_value& data,
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1584 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
1585 const octave_value& arch_arg)
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1586 {
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1587 int retval = -1;
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1588
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1589 std::string prec = prec_arg.string_value ();
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1590
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1591 if (! error_state)
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1592 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1593 int block_size = 1;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1594 oct_data_conv::data_type output_type;
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1595
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1596 oct_data_conv::string_to_data_type (prec, block_size, output_type);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1597
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1598 if (! error_state)
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1599 {
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1600 int skip = skip_arg.int_value (true);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1601
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1602 if (! error_state)
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1603 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1604 std::string arch = arch_arg.string_value ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1605
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1606 if (! error_state)
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1607 {
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1608 oct_mach_info::float_format flt_fmt
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1609 = oct_mach_info::string_to_float_format (arch);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1610
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1611 if (! error_state)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1612 retval = os.write (data, block_size, output_type,
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1613 skip, flt_fmt);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1614 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1615 else
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1616 ::error ("fwrite: architecture type must be a string");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1617 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1618 else
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1619 ::error ("fwrite: skip must be an integer");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1620 }
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1621 else
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1622 ::error ("fwrite: invalid precision specified");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1623 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1624 else
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1625 ::error ("fwrite: precision must be a string");
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1626
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1627 return retval;
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1628 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1629
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1630 DEFUN (fwrite, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1631 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1632 @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
1633 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
1634 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
1635 file.\n\
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1636 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1637 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
1638 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
1639 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1640 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
1641 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
1642 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1643 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
1644 are too large to fit in the specified precision.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1645 @seealso{fread, fopen, fclose}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1646 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1647 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
1648 octave_value retval = -1;
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1649
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1650 int nargin = args.length ();
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1651
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1652 if (nargin > 1 && nargin < 6)
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1653 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
1654 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
1655
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
1656 if (! error_state)
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1657 {
7708
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1658 octave_value prec = "uchar";
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1659 octave_value skip = 0;
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1660 octave_value arch = "unknown";
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1661
7708
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1662 int idx = 1;
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1663
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1664 octave_value data = args(idx++);
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1665
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1666 if (nargin > idx)
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1667 prec = args(idx++);
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1668
7708
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1669 if (nargin > idx)
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1670 skip = args(idx++);
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1671
7708
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1672 if (nargin > idx)
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1673 arch = args(idx++);
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1674 else if (skip.is_string ())
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1675 {
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1676 arch = skip;
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1677 skip = 0;
b42abee70a98 fread, fwrite: allow SKIP arg to be omitted
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
1678 }
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1679
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1680 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
1681
60ae49e1284f [project @ 1997-03-25 23:17:36 by jwe]
jwe
parents: 2802
diff changeset
1682 retval = status;
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1683 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1684 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1685 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1686 print_usage ();
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1687
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1688 return retval;
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1689 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1690
5906
bdf16e1564e1 [project @ 2006-07-27 03:07:14 by jwe]
jwe
parents: 5823
diff changeset
1691 DEFUNX ("feof", Ffeof, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1692 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1693 @deftypefn {Built-in Function} {} feof (@var{fid})\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1694 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
1695 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
1696 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
1697 result in an end-of-file condition.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1698 @seealso{fread, fopen, fclose}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1699 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1700 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
1701 octave_value retval = -1;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1702
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1703 int nargin = args.length ();
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1704
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1705 if (nargin == 1)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1706 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
1707 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
1708
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
1709 if (! error_state)
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1710 retval = os.eof () ? 1.0 : 0.0;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1711 }
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1712 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1713 print_usage ();
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1714
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1715 return retval;
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1716 }
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1717
5906
bdf16e1564e1 [project @ 2006-07-27 03:07:14 by jwe]
jwe
parents: 5823
diff changeset
1718 DEFUNX ("ferror", Fferror, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1719 "-*- texinfo -*-\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1720 @deftypefn {Built-in Function} {} ferror (@var{fid})\n\
9796
5f24df61667a update ferror doc string
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1721 @deftypefnx {Built-in Function} {} ferror (@var{fid}, \"clear\")\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1722 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
1723 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
1724 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
1725 error condition.\n\
9796
5f24df61667a update ferror doc string
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1726 \n\
5f24df61667a update ferror doc string
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1727 If the optional argument @code{\"clear\"} is supplied, the error\n\
5f24df61667a update ferror doc string
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
1728 condition is cleared.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1729 @end deftypefn")
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1730 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1731 octave_value_list retval;
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1732
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1733 int nargin = args.length ();
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1734
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1735 if (nargin == 1 || nargin == 2)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1736 {
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
1737 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
1738
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
1739 if (! error_state)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1740 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1741 bool clear = false;
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1742
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1743 if (nargin == 2)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1744 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1745 std::string opt = args(1).string_value ();
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1746
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1747 if (! error_state)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1748 clear = (opt == "clear");
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1749 else
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1750 return retval;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1751 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
1752
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1753 int error_number = 0;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1754
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1755 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
1756
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
1757 retval(1) = error_number;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1758 retval(0) = error_message;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1759 }
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1760 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1761 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1762 print_usage ();
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1763
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1764 return retval;
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1765 }
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1766
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
1767 DEFUN (popen, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1768 "-*- texinfo -*-\n\
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1769 @deftypefn {Built-in Function} {@var{fid} =} popen (@var{command}, @var{mode})\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1770 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
1771 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
1772 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
1773 @var{mode} may be\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1774 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1775 @table @code\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1776 @item \"r\"\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1777 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
1778 open for reading.\n\
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1779 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1780 @item \"w\"\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1781 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
1782 open for writing.\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1783 @end table\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1784 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1785 For example,\n\
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1786 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1787 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1788 @group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1789 fid = popen (\"ls -ltr / | tail -3\", \"r\");\n\
7768
a2d9f325b65a Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents: 7730
diff changeset
1790 while (ischar (s = fgets (fid)))\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1791 fputs (stdout, s);\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1792 endwhile\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1793 @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
1794 @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
1795 @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
1796 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1797 @end example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1798 @end deftypefn")
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1799 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
1800 octave_value retval = -1;
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1801
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1802 int nargin = args.length ();
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1803
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1804 if (nargin == 2)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1805 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1806 std::string name = args(0).string_value ();
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1807
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1808 if (! error_state)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1809 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1810 std::string mode = args(1).string_value ();
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1811
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1812 if (! error_state)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1813 {
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1814 if (mode == "r")
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1815 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1816 octave_stream ips = octave_iprocstream::create (name);
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1817
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1818 retval = octave_stream_list::insert (ips);
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1819 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1820 else if (mode == "w")
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1821 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
1822 octave_stream ops = octave_oprocstream::create (name);
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1823
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1824 retval = octave_stream_list::insert (ops);
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1825 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1826 else
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1827 ::error ("popen: invalid mode specified");
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1828 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1829 else
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1830 ::error ("popen: mode must be a string");
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1831 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1832 else
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1833 ::error ("popen: name must be a string");
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1834 }
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1835 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1836 print_usage ();
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1837
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1838 return retval;
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1839 }
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1840
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
1841 DEFUN (pclose, args, ,
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3372
diff changeset
1842 "-*- texinfo -*-\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1843 @deftypefn {Built-in Function} {} pclose (@var{fid})\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1844 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
1845 use @code{fclose} for the same purpose.\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1846 @end deftypefn")
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1847 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
1848 octave_value retval = -1;
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1849
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1850 int nargin = args.length ();
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1851
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1852 if (nargin == 1)
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
1853 retval = octave_stream_list::remove (args(0), "pclose");
1377
44f5d41ff757 [project @ 1995-09-12 00:07:58 by jwe]
jwe
parents: 1363
diff changeset
1854 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1855 print_usage ();
1379
e29697484908 [project @ 1995-09-12 00:41:58 by jwe]
jwe
parents: 1377
diff changeset
1856
e29697484908 [project @ 1995-09-12 00:41:58 by jwe]
jwe
parents: 1377
diff changeset
1857 return retval;
e29697484908 [project @ 1995-09-12 00:41:58 by jwe]
jwe
parents: 1377
diff changeset
1858 }
e29697484908 [project @ 1995-09-12 00:41:58 by jwe]
jwe
parents: 1377
diff changeset
1859
2458
d07a5d0b57e2 [project @ 1996-11-03 03:25:18 by jwe]
jwe
parents: 2442
diff changeset
1860 DEFUN (tmpnam, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1861 "-*- texinfo -*-\n\
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1862 @deftypefn {Built-in Function} {} tmpnam (@var{dir}, @var{prefix})\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1863 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
1864 \n\
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1865 If @var{prefix} is omitted, a value of @code{\"oct-\"} is used.\n\
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1866 If @var{dir} is also omitted, the default directory for temporary files\n\
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1867 is used. If @var{dir} is provided, it must exist, otherwise the default\n\
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1868 directory for temporary files is used. Since the named file is not\n\
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1869 opened, by @code{tmpnam}, it is possible (though relatively unlikely)\n\
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1870 that it will not be available by the time your program attempts to open it.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1871 @seealso{tmpfile, mkstemp, P_tmpdir}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1872 @end deftypefn")
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1873 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1874 octave_value retval;
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1875
2936
87cb7614257d [project @ 1997-05-06 05:46:00 by jwe]
jwe
parents: 2926
diff changeset
1876 int len = args.length ();
87cb7614257d [project @ 1997-05-06 05:46:00 by jwe]
jwe
parents: 2926
diff changeset
1877
87cb7614257d [project @ 1997-05-06 05:46:00 by jwe]
jwe
parents: 2926
diff changeset
1878 if (len < 3)
87cb7614257d [project @ 1997-05-06 05:46:00 by jwe]
jwe
parents: 2926
diff changeset
1879 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1880 std::string dir = len > 0 ? args(0).string_value () : std::string ();
2936
87cb7614257d [project @ 1997-05-06 05:46:00 by jwe]
jwe
parents: 2926
diff changeset
1881
87cb7614257d [project @ 1997-05-06 05:46:00 by jwe]
jwe
parents: 2926
diff changeset
1882 if (! error_state)
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1883 {
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1884 std::string pfx
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1885 = len > 1 ? args(1).string_value () : std::string ("oct-");
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1886
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1887 if (! error_state)
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1888 retval = file_ops::tempnam (dir, pfx);
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1889 else
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1890 ::error ("expecting second argument to be a string");
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1891 }
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1892 else
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1893 ::error ("expecting first argument to be a string");
2936
87cb7614257d [project @ 1997-05-06 05:46:00 by jwe]
jwe
parents: 2926
diff changeset
1894 }
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1895 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1896 print_usage ();
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1897
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1898 return retval;
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1899 }
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1900
2458
d07a5d0b57e2 [project @ 1996-11-03 03:25:18 by jwe]
jwe
parents: 2442
diff changeset
1901 DEFALIAS (octave_tmp_file_name, tmpnam);
d07a5d0b57e2 [project @ 1996-11-03 03:25:18 by jwe]
jwe
parents: 2442
diff changeset
1902
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1903 DEFUN (tmpfile, args, ,
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1904 "-*- texinfo -*-\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1905 @deftypefn {Built-in Function} {[@var{fid}, @var{msg}] =} tmpfile ()\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1906 Return the file ID corresponding to a new temporary file with a unique\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1907 name. The file is opened in binary read/write (@code{\"w+b\"}) mode.\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1908 The file will be deleted automatically when it is closed or when Octave\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1909 exits.\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1910 \n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1911 If successful, @var{fid} is a valid file ID and @var{msg} is an empty\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1912 string. Otherwise, @var{fid} is -1 and @var{msg} contains a\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1913 system-dependent error message.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1914 @seealso{tmpnam, mkstemp, P_tmpdir}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1915 @end deftypefn")
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1916 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1917 octave_value_list retval;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1918
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1919 retval(1) = std::string ();
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1920 retval(0) = -1;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1921
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1922 int nargin = args.length ();
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1923
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1924 if (nargin == 0)
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1925 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1926 FILE *fid = tmpfile ();
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1927
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1928 if (fid)
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1929 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1930 std::string nm;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1931
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1932 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b");
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1933
4327
c29c382a5b4b [project @ 2003-02-16 03:24:26 by jwe]
jwe
parents: 4326
diff changeset
1934 octave_stream s = octave_stdiostream::create (nm, fid, md);
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1935
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1936 if (s)
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1937 retval(0) = octave_stream_list::insert (s);
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1938 else
4327
c29c382a5b4b [project @ 2003-02-16 03:24:26 by jwe]
jwe
parents: 4326
diff changeset
1939 error ("tmpfile: failed to create octave_stdiostream object");
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1940
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1941 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1942 else
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1943 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1944 using namespace std;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1945 retval(1) = ::strerror (errno);
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1946 retval(0) = -1;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1947 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1948 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1949 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1950 print_usage ();
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1951
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1952 return retval;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1953 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1954
8792
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
1955 #if defined (HAVE_MKSTEMPS)
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
1956 // Prototype for mkstemps in libiberty
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
1957 extern "C" int mkstemps (char *pattern, int suffix_len);
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
1958 #endif
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
1959
9236
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1960 #if ! defined (HAVE_MKSTEMP) && ! defined (HAVE_MKSTEMPS) && defined (_MSC_VER)
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1961 # if defined (HAVE_FCNTL_H)
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1962 # include <fcntl.h>
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1963 # endif
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1964 # if defined (HAVE_SYS_STAT_H)
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1965 # include <sys/stat.h>
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1966 # endif
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1967 int mkstemp (char *tmpl)
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1968 {
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1969 int ret=-1;
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1970 mktemp (tmpl);
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1971 ret = open (tmpl, O_RDWR | O_BINARY | O_CREAT | O_EXCL | _O_SHORT_LIVED,
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1972 _S_IREAD | _S_IWRITE);
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1973 return ret;
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1974 }
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1975 #define HAVE_MKSTEMP 1
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1976 #endif
c02224afead6 Add mkstemp implementation based on mktemp, for platforms missing it
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9209
diff changeset
1977
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1978 DEFUN (mkstemp, args, ,
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1979 "-*- texinfo -*-\n\
5109
1e36493572a0 [project @ 2005-01-18 20:17:53 by jwe]
jwe
parents: 5102
diff changeset
1980 @deftypefn {Built-in Function} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (@var{template}, @var{delete})\n\
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1981 Return the file ID corresponding to a new temporary file with a unique\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1982 name created from @var{template}. The last six characters of @var{template}\n\
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4944
diff changeset
1983 must be @code{XXXXXX} and these are replaced with a string that makes the\n\
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1984 filename unique. The file is then created with mode read/write and\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1985 permissions that are system dependent (on GNU/Linux systems, the permissions\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1986 will be 0600 for versions of glibc 2.0.7 and later). The file is opened\n\
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
1987 with the @w{@code{O_EXCL}} flag.\n\
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1988 \n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1989 If the optional argument @var{delete} is supplied and is true,\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1990 the file will be deleted automatically when Octave exits, or when\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1991 the function @code{purge_tmp_files} is called.\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1992 \n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1993 If successful, @var{fid} is a valid file ID, @var{name} is the name of\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6905
diff changeset
1994 the file, and @var{msg} is an empty string. Otherwise, @var{fid}\n\
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1995 is -1, @var{name} is empty, and @var{msg} contains a system-dependent\n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1996 error message.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1997 @seealso{tmpfile, tmpnam, P_tmpdir}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1998 @end deftypefn")
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1999 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2000 octave_value_list retval;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2001
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2002 retval(2) = std::string ();
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2003 retval(1) = std::string ();
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2004 retval(0) = -1;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2005
8792
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
2006 #if defined (HAVE_MKSTEMP) || defined (HAVE_MKSTEMPS)
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2007
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2008 int nargin = args.length ();
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2009
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2010 if (nargin == 1 || nargin == 2)
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2011 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2012 std::string tmpl8 = args(0).string_value ();
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2013
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2014 if (! error_state)
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2015 {
4354
dfd47756dda7 [project @ 2003-02-21 21:42:02 by jwe]
jwe
parents: 4341
diff changeset
2016 OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1);
dfd47756dda7 [project @ 2003-02-21 21:42:02 by jwe]
jwe
parents: 4341
diff changeset
2017 strcpy (tmp, tmpl8.c_str ());
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2018
8792
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
2019 #if defined (HAVE_MKSTEMP)
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2020 int fd = mkstemp (tmp);
8792
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
2021 #else
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
2022 int fd = mkstemps (tmp, 0);
bbb3fa6778f3 use mkstemps as replacement for mkstemp on mingw32
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8773
diff changeset
2023 #endif
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2024
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2025 if (fd < 0)
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2026 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2027 using namespace std;
5109
1e36493572a0 [project @ 2005-01-18 20:17:53 by jwe]
jwe
parents: 5102
diff changeset
2028 retval(2) = ::strerror (errno);
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2029 retval(0) = fd;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2030 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2031 else
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2032 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2033 const char *fopen_mode = "w+";
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2034
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2035 FILE *fid = fdopen (fd, fopen_mode);
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2036
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2037 if (fid)
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2038 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2039 std::string nm = tmp;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2040
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2041 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode);
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2042
4327
c29c382a5b4b [project @ 2003-02-16 03:24:26 by jwe]
jwe
parents: 4326
diff changeset
2043 octave_stream s = octave_stdiostream::create (nm, fid, md);
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2044
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2045 if (s)
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2046 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2047 retval(1) = nm;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2048 retval(0) = octave_stream_list::insert (s);
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2049
5401
f654f94c46af [project @ 2005-07-05 16:29:22 by jwe]
jwe
parents: 5370
diff changeset
2050 if (nargin == 2 && args(1).is_true ())
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2051 mark_for_deletion (nm);
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2052 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2053 else
4327
c29c382a5b4b [project @ 2003-02-16 03:24:26 by jwe]
jwe
parents: 4326
diff changeset
2054 error ("mkstemp: failed to create octave_stdiostream object");
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2055 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2056 else
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2057 {
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2058 using namespace std;
5109
1e36493572a0 [project @ 2005-01-18 20:17:53 by jwe]
jwe
parents: 5102
diff changeset
2059 retval(2) = ::strerror (errno);
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2060 retval(0) = -1;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2061 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2062 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2063 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2064 else
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2065 error ("mkstemp: expecting string as first argument");
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2066 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2067 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
2068 print_usage ();
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2069
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2070 #else
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2071 retval(2) = "mkstemp: not supported on this sytem";
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2072 #endif
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2073
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2074 return retval;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2075 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
2076
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2077 static int
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2078 convert (int x, int ibase, int obase)
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2079 {
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2080 int retval = 0;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2081
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2082 int tmp = x % obase;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2083
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2084 if (tmp > ibase - 1)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
2085 ::error ("umask: invalid digit");
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2086 else
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2087 {
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2088 retval = tmp;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2089 int mult = ibase;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2090 while ((x = (x - tmp) / obase))
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2091 {
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2092 tmp = x % obase;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2093 if (tmp > ibase - 1)
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2094 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
2095 ::error ("umask: invalid digit");
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2096 break;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2097 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2098 retval += mult * tmp;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2099 mult *= ibase;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2100 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2101 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2102
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2103 return retval;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2104 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2105
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
2106 DEFUN (umask, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
2107 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
2108 @deftypefn {Built-in Function} {} umask (@var{mask})\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
2109 Set the permission mask for file creation. The parameter @var{mask}\n\
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
2110 is an integer, interpreted as an octal number. If successful,\n\
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
2111 returns the previous value of the mask (as an integer to be\n\
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
2112 interpreted as an octal number); otherwise an error message is printed.\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
2113 @end deftypefn")
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2114 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
2115 octave_value_list retval;
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2116
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2117 int status = 0;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2118
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2119 if (args.length () == 1)
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2120 {
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
2121 int mask = args(0).int_value (true);
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2122
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
2123 if (! error_state)
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2124 {
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
2125 if (mask < 0)
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2126 {
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2127 status = -1;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
2128 ::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
2129 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2130 else
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2131 {
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2132 int oct_mask = convert (mask, 8, 10);
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2133
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2134 if (! error_state)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2902
diff changeset
2135 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
2136 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2137 }
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
2138 else
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
2139 {
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
2140 status = -1;
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
2141 ::error ("umask: expecting integer argument");
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
2142 }
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2143 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2144 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
2145 print_usage ();
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2146
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2147 if (status >= 0)
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4102
diff changeset
2148 retval(0) = status;
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2149
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2150 return retval;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2151 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
2152
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2153 static octave_value
6483
d00da2148c53 [project @ 2007-04-04 02:58:48 by jwe]
jwe
parents: 6456
diff changeset
2154 const_value (const char *, const octave_value_list& args, int val)
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2155 {
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2156 octave_value retval;
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2157
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2158 int nargin = args.length ();
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2159
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2160 if (nargin == 0)
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2161 retval = val;
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2162 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
2163 print_usage ();
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2164
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2165 return retval;
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2166 }
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2167
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
2168 #if ! defined (P_tmpdir)
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
2169 #define P_tmpdir "/tmp"
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
2170 #endif
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
2171
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2172 DEFUNX ("P_tmpdir", FP_tmpdir, args, ,
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2173 "-*- texinfo -*-\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2174 @deftypefn {Built-in Function} {} P_tmpdir ()\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2175 Return the default name of the directory for temporary files on\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2176 this system. The name of this directory is system dependent.\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2177 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2178 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2179 octave_value retval;
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2180
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2181 int nargin = args.length ();
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
2182
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2183 if (nargin == 0)
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2184 retval = P_tmpdir;
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2185 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
2186 print_usage ();
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2187
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2188 return retval;
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2189 }
2341
6ee55c0f25a9 [project @ 1996-07-24 10:33:09 by jwe]
jwe
parents: 2324
diff changeset
2190
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2191 // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2192 // this way for Matlab compatibility.
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2193
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2194 DEFUNX ("SEEK_SET", FSEEK_SET, args, ,
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2195 "-*- texinfo -*-\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2196 @deftypefn {Built-in Function} {} SEEK_SET ()\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2197 @deftypefnx {Built-in Function} {} SEEK_CUR ()\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2198 @deftypefnx {Built-in Function} {} SEEK_END ()\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2199 Return the value required to request that @code{fseek} perform\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2200 one of the following actions:\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
2201 @table @code\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
2202 @item SEEK_SET\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
2203 Position file relative to the beginning.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
2204 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
2205 @item SEEK_CUR\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
2206 Position file relative to the current position.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
2207 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
2208 @item SEEK_END\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2209 Position file relative to the end.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
2210 @end table\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2211 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2212 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2213 return const_value ("SEEK_SET", args, -1);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2214 }
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2215
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2216 DEFUNX ("SEEK_CUR", FSEEK_CUR, args, ,
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2217 "-*- texinfo -*-\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2218 @deftypefn {Built-in Function} {} SEEK_CUR ()\n\
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3448
diff changeset
2219 See SEEK_SET.\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2220 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2221 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2222 return const_value ("SEEK_CUR", args, 0);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2223 }
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2224
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2225 DEFUNX ("SEEK_END", FSEEK_END, args, ,
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2226 "-*- texinfo -*-\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2227 @deftypefn {Built-in Function} {} SEEK_END ()\n\
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3448
diff changeset
2228 See SEEK_SET.\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2229 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2230 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2231 return const_value ("SEEK_END", args, 1);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2232 }
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2233
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2234 static octave_value
6483
d00da2148c53 [project @ 2007-04-04 02:58:48 by jwe]
jwe
parents: 6456
diff changeset
2235 const_value (const char *, const octave_value_list& args,
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2236 const octave_value& val)
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2237 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2238 octave_value retval;
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2239
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2240 int nargin = args.length ();
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2241
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2242 if (nargin == 0)
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2243 retval = val;
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2244 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
2245 print_usage ();
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2246
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2247 return retval;
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2248 }
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2249
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2250 DEFUNX ("stdin", Fstdin, args, ,
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2251 "-*- texinfo -*-\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2252 @deftypefn {Built-in Function} {} stdin ()\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2253 Return the numeric value corresponding to the standard input stream.\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2254 When Octave is used interactively, this is filtered through the command\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2255 line editing functions.\n\
5333
ac8d64b9e76a [project @ 2005-05-02 18:15:20 by jwe]
jwe
parents: 5325
diff changeset
2256 @seealso{stdout, stderr}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2257 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2258 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2259 return const_value ("stdin", args, stdin_file);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2260 }
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2261
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2262 DEFUNX ("stdout", Fstdout, args, ,
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2263 "-*- texinfo -*-\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2264 @deftypefn {Built-in Function} {} stdout ()\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2265 Return the numeric value corresponding to the standard output stream.\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2266 Data written to the standard output is normally filtered through the pager.\n\
5333
ac8d64b9e76a [project @ 2005-05-02 18:15:20 by jwe]
jwe
parents: 5325
diff changeset
2267 @seealso{stdin, stderr}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2268 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2269 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2270 return const_value ("stdout", args, stdout_file);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2271 }
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2272
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2273 DEFUNX ("stderr", Fstderr, args, ,
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2274 "-*- texinfo -*-\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2275 @deftypefn {Built-in Function} {} stderr ()\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2276 Return the numeric value corresponding to the standard error stream.\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2277 Even if paging is turned on, the standard error is not sent to the\n\
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2278 pager. It is useful for error messages and prompts.\n\
5333
ac8d64b9e76a [project @ 2005-05-02 18:15:20 by jwe]
jwe
parents: 5325
diff changeset
2279 @seealso{stdin, stdout}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2280 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2281 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2282 return const_value ("stderr", args, stderr_file);
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2283 }
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2284
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
2285 /*
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2286 ;;; Local Variables: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2287 ;;; mode: C++ ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2288 ;;; End: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2289 */