annotate libinterp/corefcn/file-io.cc @ 21457:05ffef4ebf62

tempname: Fix failing BIST test when P_tmpdir has trailing slash * file-io.cc: Fix failing tempname BIST test on UNIX systems that define the P_tmpdir directory with a trailing slash.
author Mike Miller <mtmiller@octave.org>
date Wed, 16 Mar 2016 16:09:03 -0700
parents 40de9f8f23a6
children 7a19c5678f91
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
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19597
diff changeset
3 Copyright (C) 1993-2015 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
9 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
10 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
18 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
19 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
23 // Originally written by John C. Campbell <jcc@bevo.che.wisc.edu>
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
24 //
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
25 // Thomas Baier <baier@ci.tuwien.ac.at> added the original versions of
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
26 // the following functions:
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
27 //
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
28 // popen
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
29 // pclose
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
30 // execute (now popen2.m)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
31 // sync_system (now merged with system)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
32 // async_system (now merged with system)
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
33
9322
66fdc831c580 fix jwe email address
John W. Eaton <jwe@octave.org>
parents: 9236
diff changeset
34 // 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
35 // April 1996.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 218
diff changeset
37 #ifdef HAVE_CONFIG_H
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
38 # include "config.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
39 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
40
4797
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4726
diff changeset
41 #include <cerrno>
19b8225bdaa2 [project @ 2004-02-23 22:10:31 by jwe]
jwe
parents: 4726
diff changeset
42 #include <cstdio>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1339
diff changeset
43
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3491
diff changeset
44 #include <iostream>
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
45 #include <limits>
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7097
diff changeset
46 #include <stack>
4726
14dc2267c343 [project @ 2004-01-23 20:04:35 by jwe]
jwe
parents: 4715
diff changeset
47 #include <vector>
1350
5f63d83dd694 [project @ 1995-09-05 07:37:59 by jwe]
jwe
parents: 1343
diff changeset
48
13958
cb15c5185b6a mkstemp: open file in binary mode (bug #33669)
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
49 #include <fcntl.h>
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
50 #include <sys/types.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
51 #include <unistd.h>
1350
5f63d83dd694 [project @ 1995-09-05 07:37:59 by jwe]
jwe
parents: 1343
diff changeset
52
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
53 #ifdef HAVE_ZLIB_H
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21127
diff changeset
54 # include <zlib.h>
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
55 #endif
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
56
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
57 #include "error.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2902
diff changeset
58 #include "file-ops.h"
6159
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
59 #include "file-stat.h"
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
60 #include "lo-ieee.h"
6159
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
61 #include "oct-env.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
62 #include "oct-locbuf.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2902
diff changeset
63
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
64 #include "defun.h"
21126
ba0a4b4f021d include errwarn.h in files that use err_disabled_feature conditionally
John W. Eaton <jwe@octave.org>
parents: 21109
diff changeset
65 #include "errwarn.h"
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 6053
diff changeset
66 #include "file-io.h"
6159
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
67 #include "load-path.h"
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
68 #include "oct-fstrm.h"
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
69 #include "oct-iostrm.h"
1377
44f5d41ff757 [project @ 1995-09-12 00:07:58 by jwe]
jwe
parents: 1363
diff changeset
70 #include "oct-map.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20918
diff changeset
71 #include "ovl.h"
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
72 #include "oct-prcstrm.h"
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
73 #include "oct-stream.h"
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
74 #include "oct-strstrm.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
75 #include "pager.h"
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
76 #include "sysdep.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
77 #include "utils.h"
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2341
diff changeset
78 #include "variables.h"
1583
5383d2d4cf9d [project @ 1995-10-27 08:51:20 by jwe]
jwe
parents: 1488
diff changeset
79
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
80 static octave_value stdin_file;
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
81 static octave_value stdout_file;
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
82 static octave_value stderr_file;
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
83
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
84 static octave_stream stdin_stream;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
85 static octave_stream stdout_stream;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
86 static octave_stream stderr_stream;
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
87
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
88 void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 66
diff changeset
89 initialize_file_io (void)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
90 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
91 stdin_stream = octave_istream::create (&std::cin, "stdin");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
92
3531
97cf542676e1 [project @ 2000-02-02 11:30:40 by jwe]
jwe
parents: 3523
diff changeset
93 // 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
94 // standard output stream will pass through the pager.
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
95
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
96 stdout_stream = octave_ostream::create (&octave_stdout, "stdout");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
97
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
98 stderr_stream = octave_ostream::create (&std::cerr, "stderr");
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
99
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
100 stdin_file = octave_stream_list::insert (stdin_stream);
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
101 stdout_file = octave_stream_list::insert (stdout_stream);
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2875
diff changeset
102 stderr_file = octave_stream_list::insert (stderr_stream);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
103 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
104
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
105 void
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
106 close_files (void)
1
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 octave_stream_list::clear ();
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
109 }
636
fae2bd91c027 [project @ 1994-08-23 18:39:50 by jwe]
jwe
parents: 628
diff changeset
110
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
111 // 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
112 //
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
113 // FIXME: this should really be static,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
114 // but that causes problems on some systems.
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
115 std::stack <std::string> tmp_files;
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
116
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
117 void
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
118 mark_for_deletion (const std::string& file)
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 tmp_files.push (file);
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
121 }
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 void
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
124 cleanup_tmp_files (void)
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 while (! tmp_files.empty ())
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
127 {
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
128 std::string filename = tmp_files.top ();
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
129 tmp_files.pop ();
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
130 gnulib::unlink (filename.c_str ());
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
131 }
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
132 }
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5095
diff changeset
133
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
134 static void
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
135 normalize_fopen_mode (std::string& mode, bool& use_zlib)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
136 {
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
137 use_zlib = false;
896
4a2133b26fa7 [project @ 1994-11-09 16:04:06 by jwe]
jwe
parents: 870
diff changeset
138
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
139 if (! mode.empty ())
368
5c987c27f3d7 [project @ 1994-02-16 08:33:09 by jwe]
jwe
parents: 367
diff changeset
140 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
141 // 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
142
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
143 // Accept 'W', 'R', and 'A' as 'w', 'r', and 'a' but we warn about
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
144 // them because Matlab says they don't perform "automatic
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
145 // flushing" but we don't know precisely what action that implies.
7078
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
146
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
147 size_t pos = mode.find ('W');
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
148
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
149 if (pos != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
150 {
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
151 warning_with_id ("Octave:fopen-mode",
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
152 "fopen: treating mode \"W\" as equivalent to \"w\"");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
153 mode[pos] = 'w';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
154 }
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 pos = mode.find ('R');
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
157
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
158 if (pos != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
159 {
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
160 warning_with_id ("Octave:fopen-mode",
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
161 "fopen: treating mode \"R\" as equivalent to \"r\"");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
162 mode[pos] = 'r';
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
163 }
7078
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
164
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
165 pos = mode.find ('A');
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
166
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
167 if (pos != std::string::npos)
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
168 {
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
169 warning_with_id ("Octave:fopen-mode",
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
170 "fopen: treating mode \"A\" as equivalent to \"a\"");
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
171 mode[pos] = 'a';
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
172 }
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
173
7078
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7017
diff changeset
174 pos = mode.find ('z');
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
175
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
176 if (pos != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
177 {
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
178 #if defined (HAVE_ZLIB)
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
179 use_zlib = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
180 mode.erase (pos, 1);
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
181 #else
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21078
diff changeset
182 err_disabled_feature ("", "gzipped files (zlib)");
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
183 #endif
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
184 }
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
185
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
186 // Use binary mode if 't' is not specified, but don't add
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
187 // 'b' if it is already present.
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
188
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
189 size_t bpos = mode.find ('b');
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
190 size_t tpos = mode.find ('t');
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
191
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
192 if (bpos == std::string::npos && tpos == std::string::npos)
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
193 mode += 'b';
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
194 }
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
195 }
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
196
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
197 static std::ios::openmode
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
198 fopen_mode_to_ios_mode (const std::string& mode)
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
199 {
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
200 std::ios::openmode retval = std::ios::in;
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
201
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
202 if (mode == "rt")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
203 retval = std::ios::in;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
204 else if (mode == "wt")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
205 retval = std::ios::out | std::ios::trunc;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
206 else if (mode == "at")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
207 retval = std::ios::out | std::ios::app;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
208 else if (mode == "r+t" || mode == "rt+")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
209 retval = std::ios::in | std::ios::out;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
210 else if (mode == "w+t" || mode == "wt+")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
211 retval = std::ios::in | std::ios::out | std::ios::trunc;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
212 else if (mode == "a+t" || mode == "at+")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
213 retval = std::ios::in | std::ios::out | std::ios::app;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
214 else if (mode == "rb" || mode == "r")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
215 retval = std::ios::in | std::ios::binary;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
216 else if (mode == "wb" || mode == "w")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
217 retval = std::ios::out | std::ios::trunc | std::ios::binary;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
218 else if (mode == "ab" || mode == "a")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
219 retval = std::ios::out | std::ios::app | std::ios::binary;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
220 else if (mode == "r+b" || mode == "rb+" || mode == "r+")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
221 retval = std::ios::in | std::ios::out | std::ios::binary;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
222 else if (mode == "w+b" || mode == "wb+" || mode == "w+")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
223 retval = (std::ios::in | std::ios::out | std::ios::trunc
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
224 | std::ios::binary);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
225 else if (mode == "a+b" || mode == "ab+" || mode == "a+")
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
226 retval = (std::ios::in | std::ios::out | std::ios::app
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
227 | std::ios::binary);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
228 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
229 error ("invalid mode specified");
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
230
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
231 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
232 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
233
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
234 DEFUN (fclose, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
235 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
236 @deftypefn {} {} fclose (@var{fid})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
237 @deftypefnx {} {} fclose (\"all\")\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
238 @deftypefnx {} {@var{status} =} fclose (\"all\")\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
239 Close the file specified by the file descriptor @var{fid}.\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
240 \n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
241 If successful, @code{fclose} returns 0, otherwise, it returns -1. The\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
242 second form of the @code{fclose} call closes all open files except\n\
20764
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
243 @code{stdin}, @code{stdout}, @code{stderr}, and any FIDs associated\n\
0ad449bc8848 Stop 'fclose ("all")' from closing down gnuplot pipes (bug #39504).
Rik <rik@octave.org>
parents: 20756
diff changeset
244 with gnuplot.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
245 @seealso{fopen, fflush, freport}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
246 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
247 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
248 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
249 print_usage ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
250
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
251 return ovl (octave_stream_list::remove (args(0), "fclose"));
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
252 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
253
5144
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
254 DEFUN (fclear, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
255 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
256 @deftypefn {} {} fclear (@var{fid})\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
257 Clear the stream state for the file specified by the file descriptor\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
258 @var{fid}.\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
259 @seealso{ferror, fopen}\n\
5144
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
260 @end deftypefn")
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
261 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
262 if (args.length () != 1)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
263 print_usage ();
5144
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
264
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
265 int fid = octave_stream_list::get_file_number (args(0));
5144
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
266
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
267 octave_stream os = octave_stream_list::lookup (fid, "fclear");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
268
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
269 os.clearerr ();
5144
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
270
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
271 return ovl ();
5144
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
272 }
25b090e1be9f [project @ 2005-02-15 12:06:05 by jwe]
jwe
parents: 5109
diff changeset
273
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
274 DEFUN (fflush, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
275 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
276 @deftypefn {} {} fflush (@var{fid})\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
277 Flush output to file descriptor @var{fid}.\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
278 \n\
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
279 @code{fflush} returns 0 on success and an OS dependent error value\n\
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10411
diff changeset
280 (@minus{}1 on Unix) on error.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
281 \n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
282 Programming Note: Flushing is useful for ensuring that all pending output\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
283 makes it to the screen before some other event occurs. For example, it is\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
284 always a good idea to flush the standard output stream before calling\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
285 @code{input}.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
286 @seealso{fopen, fclose}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
287 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
288 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
289 if (args.length () != 1)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
290 print_usage ();
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
291
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
292 octave_value retval = -1;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
293
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
294 // FIXME: any way to avoid special case for stdout?
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
295 int fid = octave_stream_list::get_file_number (args(0));
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
296
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
297 if (fid == 1)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
298 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
299 flush_octave_stdout ();
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2599
diff changeset
300
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
301 retval = 0;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
302 }
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
303 else
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
304 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
305 octave_stream os = octave_stream_list::lookup (fid, "fflush");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
306
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
307 retval = os.flush ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
308 }
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
309
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
310 return retval;
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
311 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
312
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
313 DEFUN (fgetl, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
314 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
315 @deftypefn {} {@var{str} =} fgetl (@var{fid})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
316 @deftypefnx {} {@var{str} =} fgetl (@var{fid}, @var{len})\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
317 Read characters from a file, stopping after a newline, or EOF,\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
318 or @var{len} characters have been read.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
319 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
320 The characters read, excluding the possible trailing newline, are returned\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
321 as a string.\n\
1339
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
322 \n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
323 If @var{len} is omitted, @code{fgetl} reads until the next newline character.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
324 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
325 If there are no more characters to read, @code{fgetl} returns @minus{}1.\n\
14435
f312918f16d2 doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
326 \n\
f312918f16d2 doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
327 To read a line and return the terminating newline see @code{fgets}.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
328 @seealso{fgets, fscanf, fread, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
329 @end deftypefn")
1339
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
330 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
331 static std::string who = "fgetl";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
332
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
333 int nargin = args.length ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
334
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
335 if (nargin < 1 || nargin > 2)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
336 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
337
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
338 octave_stream os = octave_stream_list::lookup (args(0), who);
1339
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
339
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
340 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
341
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
342 bool err = false;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
343
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
344 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
345
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
346 if (! err)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
347 return ovl (tmp, tmp.length ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
348 else
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
349 return ovl (-1, 0);
1339
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
350 }
e1dbc5585afd [project @ 1995-08-25 03:58:02 by jwe]
jwe
parents: 1338
diff changeset
351
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
352 DEFUN (fgets, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
353 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
354 @deftypefn {} {@var{str} =} fgets (@var{fid})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
355 @deftypefnx {} {@var{str} =} fgets (@var{fid}, @var{len})\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
356 Read characters from a file, stopping after a newline, or EOF,\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
357 or @var{len} characters have been read.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
358 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
359 The characters read, including the possible trailing newline, are returned\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
360 as a string.\n\
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
361 \n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
362 If @var{len} is omitted, @code{fgets} reads until the next newline character.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
363 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
364 If there are no more characters to read, @code{fgets} returns @minus{}1.\n\
14435
f312918f16d2 doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
365 \n\
f312918f16d2 doc: Add cross-references between fgets and fgetl in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
366 To read a line and discard the terminating newline see @code{fgetl}.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
367 @seealso{fputs, fgetl, fscanf, fread, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
368 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
369 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
370 static std::string who = "fgets";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
371
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
372 int nargin = args.length ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
373
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
374 if (nargin < 1 || nargin > 2)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
375 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
376
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
377 octave_stream os = octave_stream_list::lookup (args(0), who);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
378
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
379 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
380
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
381 bool err = false;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
382
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
383 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
384
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
385 if (! err)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
386 return ovl (tmp, tmp.length ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
387 else
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
388 return ovl (-1.0, 0.0);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
389 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
390
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
391 DEFUN (fskipl, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
392 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
393 @deftypefn {} {@var{nlines} =} fskipl (@var{fid})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
394 @deftypefnx {} {@var{nlines} =} fskipl (@var{fid}, @var{count})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
395 @deftypefnx {} {@var{nlines} =} fskipl (@var{fid}, Inf)\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
396 Read and skip @var{count} lines from the file specified by the file\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
397 descriptor @var{fid}.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
398 \n\
14436
12097d20a23e doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents: 14435
diff changeset
399 @code{fskipl} discards characters until an end-of-line is encountered exactly\n\
12097d20a23e doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents: 14435
diff changeset
400 @var{count}-times, or until the end-of-file marker is found.\n\
12097d20a23e doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents: 14435
diff changeset
401 \n\
12097d20a23e doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents: 14435
diff changeset
402 If @var{count} is omitted, it defaults to 1. @var{count} may also be\n\
12097d20a23e doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents: 14435
diff changeset
403 @code{Inf}, in which case lines are skipped until the end of the file.\n\
12097d20a23e doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents: 14435
diff changeset
404 This form is suitable for counting the number of lines in a file.\n\
12097d20a23e doc: Improve docstring for fskipl.
Rik <octave@nomad.inbox5.com>
parents: 14435
diff changeset
405 \n\
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
406 Returns the number of lines skipped (end-of-line sequences encountered).\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
407 @seealso{fgetl, fgets, fscanf, fopen}\n\
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
408 @end deftypefn")
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
409 {
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
410 static std::string who = "fskipl";
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
411
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
412 int nargin = args.length ();
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
413
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
414 if (nargin < 1 || nargin > 2)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
415 print_usage ();
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
416
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
417 octave_stream os = octave_stream_list::lookup (args(0), who);
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
418
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
419 octave_value count_arg = (nargin == 2) ? args(1) : octave_value ();
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
420
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
421 bool err = false;
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
422
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
423 off_t tmp = os.skipl (count_arg, err, who);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
424
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
425 if (! err)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
426 return ovl (tmp);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
427 else
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
428 return ovl ();
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
429 }
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
430
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 9322
diff changeset
431
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
432 static octave_stream
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
433 do_stream_open (const std::string& name, const std::string& mode_arg,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
434 const std::string& arch, int& fid)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
435 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
436 octave_stream retval;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
437
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
438 fid = -1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
439
16590
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
440 std::string mode = mode_arg;
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
441 bool use_zlib = false;
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
442 normalize_fopen_mode (mode, use_zlib);
2d968b7830d6 handle A, R, and W fopen modes correctly (bug #38851)
John W. Eaton <jwe@octave.org>
parents: 16308
diff changeset
443
4036
1432e11733d1 [project @ 2002-08-12 18:38:40 by jwe]
jwe
parents: 4028
diff changeset
444 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
445
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
446 oct_mach_info::float_format flt_fmt =
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
447 oct_mach_info::string_to_float_format (arch);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
448
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
449 std::string fname = file_ops::tilde_expand (name);
6159
645605133a6f [project @ 2006-11-14 02:55:05 by jwe]
jwe
parents: 6108
diff changeset
450
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
451 file_stat fs (fname);
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
452
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
453 if (! (md & std::ios::out))
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
454 fname = find_data_file_in_load_path ("fopen", fname);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
455
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
456 if (! fs.is_dir ())
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
457 {
6905
aee959a21c4b [project @ 2007-09-17 16:00:30 by jwe]
jwe
parents: 6838
diff changeset
458 #if defined (HAVE_ZLIB)
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
459 if (use_zlib)
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
460 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
461 FILE *fptr = gnulib::fopen (fname.c_str (), mode.c_str ());
11004
594adb99a25e cache file id in octave_tstdiostream class
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
462
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
463 int fd = fileno (fptr);
11004
594adb99a25e cache file id in octave_tstdiostream class
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
464
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
465 gzFile gzf = ::gzdopen (fd, mode.c_str ());
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
466
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
467 if (fptr)
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
468 retval = octave_zstdiostream::create (fname, gzf, fd,
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
469 md, flt_fmt);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
470 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
471 retval.error (gnulib::strerror (errno));
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
472 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
473 else
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
474 #endif
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
475 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
476 FILE *fptr = gnulib::fopen (fname.c_str (), mode.c_str ());
5370
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
477
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
478 retval = octave_stdiostream::create (fname, fptr, md,
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
479 flt_fmt);
7730
b68e44c90afe file-io.cc (do_stream_open): return -1 for directories
John W. Eaton <jwe@octave.org>
parents: 7708
diff changeset
480
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
481 if (! fptr)
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
482 retval.error (gnulib::strerror (errno));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
483 }
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
484
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
485 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
486
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
487 return retval;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
488 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
489
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
490 static octave_stream
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
491 do_stream_open (const octave_value& tc_name, const octave_value& tc_mode,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
492 const octave_value& tc_arch, const char *fcn, int& fid)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
493 {
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3321
diff changeset
494 octave_stream retval;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
495
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
496 fid = -1;
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
497
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 20704
diff changeset
498 std::string name = tc_name.xstring_value ("%s: filename must be a string", fcn);
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
499 std::string mode = tc_mode.xstring_value ("%s: file mode must be a string", fcn);
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
500 std::string arch = tc_arch.xstring_value ("%s: architecture type must be a string", fcn);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
501
20581
fd0efcdb3718 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
502 retval = do_stream_open (name, mode, arch, fid);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
503
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
504 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
505 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
506
11146
69b2f237060e file-io.cc (Ffopen): argument parsing tweak
John W. Eaton <jwe@octave.org>
parents: 11081
diff changeset
507 DEFUN (fopen, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
508 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
509 @deftypefn {} {@var{fid} =} fopen (@var{name})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
510 @deftypefnx {} {@var{fid} =} fopen (@var{name}, @var{mode})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
511 @deftypefnx {} {@var{fid} =} fopen (@var{name}, @var{mode}, @var{arch})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
512 @deftypefnx {} {[@var{fid}, @var{msg}] =} fopen (@dots{})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
513 @deftypefnx {} {@var{fid_list} =} fopen (\"all\")\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
514 @deftypefnx {} {[@var{file}, @var{mode}, @var{arch}] =} fopen (@var{fid})\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
515 Open a file for low-level I/O or query open files and file descriptors.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
516 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
517 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
518 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
519 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
520 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
521 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
522 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
523 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
524 reading, writing, or both.\n\
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
525 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
526 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
527 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
528 @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
529 \n\
5353
df230b7df93c [project @ 2005-05-18 02:18:24 by jwe]
jwe
parents: 5333
diff changeset
530 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
531 open file given its file id.\n\
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
532 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
533 For example,\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
534 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
535 @example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
536 myfile = fopen (\"splat.dat\", \"r\", \"ieee-le\");\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
537 @end example\n\
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
538 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
539 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
540 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
541 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
542 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
543 representation.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
544 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
545 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
546 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
547 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
548 produce unexpected results.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
549 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
550 The possible values @samp{mode} may have are\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
551 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
552 @table @asis\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
553 @item @samp{r} (default)\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
554 Open a file for reading.\n\
3263
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
555 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
556 @item @samp{w}\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6905
diff changeset
557 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
558 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
559 @item @samp{a}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
560 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
561 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
562 @item @samp{r+}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
563 Open an existing file for reading and writing.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
564 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
565 @item @samp{w+}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
566 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
567 discarded.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
568 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
569 @item @samp{a+}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
570 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
571 file.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
572 @end table\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
573 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
574 Append a @qcode{\"t\"} to the mode string to open the file in text mode or a\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
575 @qcode{\"b\"} to open in binary mode. On Windows and Macintosh systems, text\n\
4865
2ac0f95eaa29 [project @ 2004-04-16 16:32:24 by jwe]
jwe
parents: 4799
diff changeset
576 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
577 appropriate line end character for the system (carriage-return linefeed\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
578 on Windows, carriage-return on Macintosh). The default when no mode is\n\
4865
2ac0f95eaa29 [project @ 2004-04-16 16:32:24 by jwe]
jwe
parents: 4799
diff changeset
579 specified is binary mode.\n\
2ac0f95eaa29 [project @ 2004-04-16 16:32:24 by jwe]
jwe
parents: 4799
diff changeset
580 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
581 Additionally, you may append a @qcode{\"z\"} to the mode string to open a\n\
5325
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
582 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
583 must also open the file in binary mode.\n\
ecbe4aa87e51 [project @ 2005-04-29 20:48:35 by jwe]
jwe
parents: 5320
diff changeset
584 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
585 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
586 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
587 \n\
20431
f02c22f71cdb doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents: 20198
diff changeset
588 @table @asis\n\
f02c22f71cdb doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents: 20198
diff changeset
589 @item @qcode{\"native\"} or @qcode{\"n\"} (default)\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
590 The format of the current machine.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
591 \n\
20431
f02c22f71cdb doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents: 20198
diff changeset
592 @item @qcode{\"ieee-be\"} or @qcode{\"b\"}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
593 IEEE big endian format.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
594 \n\
20431
f02c22f71cdb doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents: 20198
diff changeset
595 @item @qcode{\"ieee-le\"} or @qcode{\"l\"}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
596 IEEE little endian format.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
597 @end table\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
598 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
599 @noindent\n\
20431
f02c22f71cdb doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents: 20198
diff changeset
600 However, conversions are currently only supported for @samp{native},\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
601 @samp{ieee-be}, and @samp{ieee-le} formats.\n\
20198
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
602 \n\
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
603 When opening a new file that does not yet exist, permissions will be set to\n\
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
604 @code{0666 - @var{umask}}.\n\
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
605 @seealso{fclose, fgets, fgetl, fscanf, fread, fputs, fdisp, fprintf, fwrite, fskipl, fseek, frewind, ftell, feof, ferror, fclear, fflush, freport, umask}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
606 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
607 {
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
608 int nargin = args.length ();
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
609
20861
6774cc464ea0 * file-io.cc (Ffopen): Fix nargin range check, fixes cset f2cd811f0f9e
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
610 if (nargin < 1 || nargin > 3)
20846
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
611 print_usage ();
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
612
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
613 octave_value_list retval = ovl (-1.0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
614
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
615 if (nargin == 1)
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
616 {
12896
a19b50f6697f Correctly allow single string input form of fopen() (Bug #33535).
Rik <octave@nomad.inbox5.com>
parents: 12775
diff changeset
617 if (args(0).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
618 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
619 // If there is only one argument and it is a string but it
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
620 // is not the string "all", we assume it is a file to open
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
621 // with MODE = "r". To open a file called "all", you have
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
622 // to supply more than one argument.
12896
a19b50f6697f Correctly allow single string input form of fopen() (Bug #33535).
Rik <octave@nomad.inbox5.com>
parents: 12775
diff changeset
623 if (nargout < 2 && args(0).string_value () == "all")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
624 return octave_stream_list::open_file_numbers ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
625 }
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
626 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
627 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
628 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
629
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
630 retval = ovl (tmp(0), tmp(1), tmp(2));
3263
7d80b56e0dc8 [project @ 1999-08-20 19:10:09 by jwe]
jwe
parents: 3246
diff changeset
631
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
632 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
633 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
634 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
635
20846
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
636 octave_value mode = (nargin == 2 || nargin == 3)
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
637 ? args(1) : octave_value ("r");
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
638
20846
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
639 octave_value arch = (nargin == 3)
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
640 ? args(2) : octave_value ("native");
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
641
20846
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
642 int fid = -1;
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
643
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
644 octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid);
5370
f07a9653b844 [project @ 2005-05-24 02:25:57 by jwe]
jwe
parents: 5353
diff changeset
645
20846
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
646 if (os)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
647 retval = ovl (octave_stream_list::insert (os), "");
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
648 else
20846
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
649 {
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
650 int error_number = 0;
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
651
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
652 retval = ovl (-1.0, os.error (false, error_number));
20846
f2cd811f0f9e maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20819
diff changeset
653 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
654
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
655 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
656 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
657
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
658 DEFUN (freport, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
659 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
660 @deftypefn {} {} freport ()\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
661 Print a list of which files have been opened, and whether they are open\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
662 for reading, writing, or both.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
663 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
664 For example:\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
665 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
666 @example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
667 @group\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
668 freport ()\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
669 \n\
19123
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 19109
diff changeset
670 @print{} number mode arch name\n\
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 19109
diff changeset
671 @print{} ------ ---- ---- ----\n\
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 19109
diff changeset
672 @print{} 0 r ieee-le stdin\n\
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 19109
diff changeset
673 @print{} 1 w ieee-le stdout\n\
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 19109
diff changeset
674 @print{} 2 w ieee-le stderr\n\
c8f03ccdc9ee Align columns for freport() output.
Rik <rik@octave.org>
parents: 19109
diff changeset
675 @print{} 3 r ieee-le myfile\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
676 @end group\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
677 @end example\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
678 @seealso{fopen, fclose, is_valid_file_id}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
679 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
680 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20812
diff changeset
681 if (args.length () > 0)
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
682 warning ("freport: ignoring extra arguments");
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
683
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
684 octave_stdout << octave_stream_list::list_open_files ();
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
685
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21055
diff changeset
686 return ovl ();
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
687 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
688
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
689 DEFUN (frewind, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
690 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
691 @deftypefn {} {} frewind (@var{fid})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
692 @deftypefnx {} {@var{status} =} frewind (@var{fid})\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
693 Move the file pointer to the beginning of the file specified by file\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
694 descriptor @var{fid}.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
695 \n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
696 @code{frewind} returns 0 for success, and -1 if an error is encountered. It\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
697 is equivalent to @code{fseek (@var{fid}, 0, SEEK_SET)}.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
698 @seealso{fseek, ftell, fopen}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
699 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
700 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
701 if (args.length () != 1)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
702 print_usage ();
506
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
703
20812
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20805
diff changeset
704 int result = -1;
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20805
diff changeset
705
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
706 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
707
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
708 result = os.rewind ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
709
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
710 if (nargout > 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
711 return ovl (result);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
712 else
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
713 return ovl ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
714 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
715
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
716 DEFUN (fseek, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
717 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
718 @deftypefn {} {} fseek (@var{fid}, @var{offset})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
719 @deftypefnx {} {} fseek (@var{fid}, @var{offset}, @var{origin})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
720 @deftypefnx {} {@var{status} =} fseek (@dots{})\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
721 Set the file pointer to the location @var{offset} within the file @var{fid}.\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
722 \n\
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
723 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
724 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
725 position), @w{@code{SEEK_SET}} (beginning), or @w{@code{SEEK_END}} (end of\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
726 file) or strings @qcode{\"cof\"}, @qcode{\"bof\"} or @qcode{\"eof\"}. If\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
727 @var{origin} is omitted, @w{@code{SEEK_SET}} is assumed. @var{offset} may\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
728 be positive, negative, or zero but not all combinations of @var{origin} and\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
729 @var{offset} can be realized.\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
730 \n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
731 @code{fseek} returns 0 on success and -1 on error.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
732 @seealso{fskipl, frewind, ftell, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
733 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
734 {
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
735 int nargin = args.length ();
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
736
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
737 if (nargin < 2 || nargin > 3)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
738 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
739
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
740 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
741
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
742 octave_value origin_arg = (nargin == 3) ? args(2) : octave_value (-1.0);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
743
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
744 return ovl (os.seek (args(1), origin_arg));
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
745 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
746
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
747 DEFUN (ftell, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
748 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
749 @deftypefn {} {@var{pos} =} ftell (@var{fid})\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
750 Return the position of the file pointer as the number of characters from the\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
751 beginning of the file specified by file descriptor @var{fid}.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
752 @seealso{fseek, frewind, feof, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
753 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
754 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
755 if (args.length () != 1)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
756 print_usage ();
506
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
757
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
758 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
759
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
760 return ovl (os.tell ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
761 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
762
3737
b736f8b8f0a1 [project @ 2000-11-16 18:01:08 by jwe]
jwe
parents: 3569
diff changeset
763 DEFUN (fprintf, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
764 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
765 @deftypefn {} {} fprintf (@var{fid}, @var{template}, @dots{})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
766 @deftypefnx {} {} fprintf (@var{template}, @dots{})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
767 @deftypefnx {} {@var{numbytes} =} fprintf (@dots{})\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
768 This function is equivalent to @code{printf}, except that the output is\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
769 written to the file descriptor @var{fid} instead of @code{stdout}.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
770 \n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
771 If @var{fid} is omitted, the output is written to @code{stdout} making the\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
772 function exactly equivalent to @code{printf}.\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
773 \n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
774 The optional output returns the number of bytes written to the file.\n\
20041
dbf2418a46dd Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents: 19861
diff changeset
775 \n\
20097
1f9ed81bd173 maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents: 20041
diff changeset
776 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\
20101
e51473fdb622 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 20097
diff changeset
777 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\
e51473fdb622 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 20097
diff changeset
778 expanded even when the template string is defined with single quotes.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
779 @seealso{fputs, fdisp, fwrite, fscanf, printf, sprintf, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
780 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
781 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
782 static std::string who = "fprintf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
783
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
784 int nargin = args.length ();
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
785
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
786 if (! (nargin > 1 || (nargin > 0 && args(0).is_string ())))
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
787 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
788
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
789 int result;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
790
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
791 octave_stream os;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
792 int fmt_n = 0;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
793
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
794 if (args(0).is_string ())
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
795 os = octave_stream_list::lookup (1, who);
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
796 else
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
797 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
798 fmt_n = 1;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
799 os = octave_stream_list::lookup (args(0), who);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
800 }
2873
c3f7ed3874af [project @ 1997-04-23 04:01:02 by jwe]
jwe
parents: 2847
diff changeset
801
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
802 if (! args(fmt_n).is_string ())
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
803 error ("%s: format TEMPLATE must be a string", who.c_str ());
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
804
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
805 octave_value_list tmp_args;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
806
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
807 if (nargin > 1 + fmt_n)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
808 {
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
809 tmp_args.resize (nargin-fmt_n-1, octave_value ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
810
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
811 for (int i = fmt_n + 1; i < nargin; i++)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
812 tmp_args(i-fmt_n-1) = args(i);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
813 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
814
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
815 result = os.printf (args(fmt_n), tmp_args, who);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
816
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
817 if (nargout > 0)
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
818 return ovl (result);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
819 else
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
820 return ovl ();
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
821 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
822
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
823 DEFUN (printf, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
824 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
825 @deftypefn {} {} printf (@var{template}, @dots{})\n\
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
826 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
827 @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
828 characters printed.\n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
829 @ifclear OCTAVE_MANUAL\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
830 \n\
5653
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
831 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
832 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
833 @end ifclear\n\
20041
dbf2418a46dd Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents: 19861
diff changeset
834 \n\
20097
1f9ed81bd173 maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents: 20041
diff changeset
835 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\
20101
e51473fdb622 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 20097
diff changeset
836 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\
e51473fdb622 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 20097
diff changeset
837 expanded even when the template string is defined with single quotes.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
838 @seealso{fprintf, sprintf, scanf}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
839 @end deftypefn")
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
840 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
841 static std::string who = "printf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
842
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
843 int nargin = args.length ();
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
844
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
845 if (nargin == 0)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
846 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
847
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
848 int result;
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
849
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
850 if (! args(0).is_string ())
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
851 error ("%s: format TEMPLATE must be a string", who.c_str ());
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
852
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
853 octave_value_list tmp_args;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
854
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
855 if (nargin > 1)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
856 {
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
857 tmp_args.resize (nargin-1, octave_value ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
858
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
859 for (int i = 1; i < nargin; i++)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
860 tmp_args(i-1) = args(i);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
861 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
862
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
863 result = stdout_stream.printf (args(0), tmp_args, who);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
864
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
865 if (nargout > 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
866 return ovl (result);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
867 else
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
868 return ovl ();
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
869 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
870
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
871 DEFUN (fputs, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
872 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
873 @deftypefn {} {} fputs (@var{fid}, @var{string})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
874 @deftypefnx {} {@var{status} =} fputs (@var{fid}, @var{string})\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
875 Write the string @var{string} to the file with file descriptor @var{fid}.\n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
876 \n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
877 The string is written to the file with no additional formatting. Use\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
878 @code{fdisp} instead to automatically append a newline character appropriate\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
879 for the local machine.\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
880 \n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
881 Return a non-negative number on success or EOF on error.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
882 @seealso{fdisp, fprintf, fwrite, fopen}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
883 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
884 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
885 static std::string who = "fputs";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
886
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
887 if (args.length () != 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
888 print_usage ();
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
889
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
890 octave_stream os = octave_stream_list::lookup (args(0), who);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
891
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
892 return ovl (os.puts (args(1), who));
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
893 }
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
894
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
895 DEFUN (puts, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
896 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
897 @deftypefn {} {} puts (@var{string})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
898 @deftypefnx {} {@var{status} =} puts (@var{string})\n\
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
899 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
900 \n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
901 The string is written verbatim to the standard output. Use @code{disp} to\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
902 automatically append a newline character appropriate for the local machine.\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
903 \n\
5095
c9a44ec47b20 [project @ 2004-12-03 14:18:51 by jwe]
jwe
parents: 5041
diff changeset
904 Return a non-negative number on success and EOF on error.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
905 @seealso{fputs, disp}\n\
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
906 @end deftypefn")
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
907 {
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
908 static std::string who = "puts";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
909
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
910 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
911 print_usage ();
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
912
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
913 return ovl (stdout_stream.puts (args(0), who));
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
914 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
915
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
916 DEFUN (sprintf, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
917 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
918 @deftypefn {} {} sprintf (@var{template}, @dots{})\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
919 This is like @code{printf}, except that the output is returned as a\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
920 string.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
921 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
922 Unlike the C library function, which requires you to provide a suitably\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
923 sized string as an argument, Octave's @code{sprintf} function returns the\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
924 string, automatically sized to hold all of the items converted.\n\
20041
dbf2418a46dd Document expansion of escape sequences in single quotes (bug #44745).
Rik <rik@octave.org>
parents: 19861
diff changeset
925 \n\
20097
1f9ed81bd173 maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents: 20041
diff changeset
926 Implementation Note: For compatibility with @sc{matlab}, escape sequences in\n\
20101
e51473fdb622 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 20097
diff changeset
927 the template string (e.g., @qcode{\"@xbackslashchar{}n\"} => newline) are\n\
e51473fdb622 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 20097
diff changeset
928 expanded even when the template string is defined with single quotes.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
929 @seealso{printf, fprintf, sscanf}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
930 @end deftypefn")
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
931 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
932 static std::string who = "sprintf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
933
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
934 int nargin = args.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
935
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
936 if (nargin == 0)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
937 print_usage ();
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
938
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
939 octave_ostrstream *ostr = new octave_ostrstream ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
940
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
941 octave_stream os (ostr);
628
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
942
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
943 if (! os.is_valid ())
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
944 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
945
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
946 octave_value fmt_arg = args(0);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
947
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
948 if (! fmt_arg.is_string ())
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
949 error ("%s: format TEMPLATE must be a string", who.c_str ());
628
aecbe369233b [project @ 1994-08-19 13:27:51 by jwe]
jwe
parents: 610
diff changeset
950
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
951 octave_value_list retval (3);
19727
3c3b9fce7d2b improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
952
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
953 octave_value_list tmp_args;
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
954 if (nargin > 1)
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
955 {
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
956 tmp_args.resize (nargin-1, octave_value ());
19727
3c3b9fce7d2b improve compatibility of sprintf function.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
957
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
958 for (int i = 1; i < nargin; i++)
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
959 tmp_args(i-1) = args(i);
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
960 }
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
961
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
962 // NOTE: Call to os.error must precede next call to ostr which might reset it.
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
963 retval(2) = os.printf (fmt_arg, tmp_args, who);
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
964 retval(1) = os.error ();
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
965
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
966 std::string result = ostr->str ();
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
967 char type = fmt_arg.is_sq_string () ? '\'' : '"';
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
968
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
969 retval(0) = (result.empty () ? octave_value (charMatrix (1, 0), type)
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20884
diff changeset
970 : octave_value (result, type));
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
971
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
972 return retval;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
973 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
974
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
975 DEFUN (fscanf, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
976 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
977 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, @var{size})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
978 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} fscanf (@var{fid}, @var{template}, \"C\")\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
979 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
980 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
981 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
982 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
983 and may be one of\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
984 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
985 @table @code\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
986 @item Inf\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
987 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
988 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
989 @item @var{nr}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
990 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
991 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
992 @item [@var{nr}, Inf]\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
993 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
994 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
995 column is padded with zeros.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
996 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
997 @item [@var{nr}, @var{nc}]\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
998 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
999 @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
1000 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
1001 @end table\n\
2122
91d802f77456 [project @ 1996-05-12 07:08:38 by jwe]
jwe
parents: 2116
diff changeset
1002 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1003 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1004 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
1005 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1006 A string is returned if @var{template} specifies only character conversions.\n\
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1007 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1008 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
1009 \n\
13271
fba2cc36b762 return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents: 13194
diff changeset
1010 If an error occurs, @var{errmsg} contains a system-dependent error message.\n\
fba2cc36b762 return stream error message in scanf functions and document behavior
John W. Eaton <jwe@octave.org>
parents: 13194
diff changeset
1011 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1012 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
1013 with each conversion specifier in @var{template} corresponding to a\n\
16766
7268845c0a1e avoid backquote in error messages, some uses in doc strings
John W. Eaton <jwe@octave.org>
parents: 16590
diff changeset
1014 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
1015 compatible with previous versions of Octave. The number of successful\n\
16099
4b6c44096862 Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents: 16094
diff changeset
1016 conversions is returned in @var{count}\n\
5653
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
1017 @ifclear OCTAVE_MANUAL\n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
1018 \n\
ab9a339fcec8 [project @ 2006-03-09 17:28:13 by jwe]
jwe
parents: 5642
diff changeset
1019 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
1020 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
1021 @end ifclear\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
1022 @seealso{fgets, fgetl, fread, scanf, sscanf, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1023 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1024 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1025 static std::string who = "fscanf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1026
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1027 int nargin = args.length ();
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1028
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1029 if (nargin < 2 || nargin > 3)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1030 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1031
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1032 octave_value_list retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1033
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1034 if (nargin == 3 && args(2).is_string ())
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1035 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1036 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
1037
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1038 if (! args(1).is_string ())
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
1039 error ("%s: format TEMPLATE must be a string", who.c_str ());
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1040
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1041 retval = ovl (os.oscanf (args(1), who));
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1042 }
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1043 else
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1044 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1045 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
1046
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1047 if (! args(1).is_string ())
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1048 error ("%s: format must be a string", who.c_str ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1049
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1050 octave_idx_type count = 0;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1051
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1052 Array<double> size = (nargin == 3)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1053 ? args(2).vector_value ()
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1054 : Array<double> (dim_vector (1, 1),
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1055 lo_ieee_inf_value ());
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1056
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1057 octave_value tmp = os.scanf (args(1), size, count, who);
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1058
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1059 retval = ovl (tmp, count, os.error ());
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1060 }
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1061
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1062 return retval;
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1063 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1064
13194
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1065 static std::string
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1066 get_sscanf_data (const octave_value& val)
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1067 {
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1068 std::string retval;
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1069
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
1070 if (! val.is_string ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
1071 error ("sscanf: argument STRING must be a string");
13194
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1072
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
1073 octave_value tmp = val.reshape (dim_vector (1, val.numel ()));
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
1074
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20956
diff changeset
1075 retval = tmp.string_value ();
13194
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1076
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1077 return retval;
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1078 }
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1079
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1080 DEFUN (sscanf, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1081 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1082 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}, @var{pos}] =} sscanf (@var{string}, @var{template}, @var{size})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1083 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}] =} sscanf (@var{string}, @var{template}, \"C\")\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1084 This is like @code{fscanf}, except that the characters are taken from the\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1085 string @var{string} instead of from a stream.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1086 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1087 Reaching the end of the string is treated as an end-of-file condition. In\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1088 addition to the values returned by @code{fscanf}, the index of the next\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1089 character to be read is returned in @var{pos}.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1090 @seealso{fscanf, scanf, sprintf}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1091 @end deftypefn")
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1092 {
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1093 static std::string who = "sscanf";
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4388
diff changeset
1094
506
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
1095 int nargin = args.length ();
0f388340e607 [project @ 1994-07-09 06:10:34 by jwe]
jwe
parents: 497
diff changeset
1096
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1097 if (nargin < 2 || nargin > 3)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1098 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1099
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1100 octave_value_list retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1101
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1102 if (nargin == 3 && args(2).is_string ())
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1103 {
13194
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1104 std::string data = get_sscanf_data (args(0));
3e1871badab9 allow sscanf to accept character arrays with more than one row
John W. Eaton <jwe@octave.org>
parents: 12998
diff changeset
1105
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20581
diff changeset
1106 octave_stream os = octave_istrstream::create (data);
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
1107
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1108 if (! os.is_valid ())
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20581
diff changeset
1109 error ("%s: unable to create temporary input buffer", who.c_str ());
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1110
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1111 if (! args(1).is_string ())
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1112 error ("%s: format TEMPLATE must be a string", who.c_str ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1113
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1114 retval = ovl (os.oscanf (args(1), who));
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1115 }
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1116 else
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1117 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1118 std::string data = get_sscanf_data (args(0));
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1119
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1120 octave_stream os = octave_istrstream::create (data);
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
1121
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1122 if (! os.is_valid ())
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1123 error ("%s: unable to create temporary input buffer", who.c_str ());
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1124
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1125 if (! args(1).is_string ())
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1126 error ("%s: format TEMPLATE must be a string", who.c_str ());
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
1127
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1128 octave_idx_type count = 0;
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1129
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1130 Array<double> size = (nargin == 3) ? args(2).vector_value ()
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1131 : Array<double> (dim_vector (1, 1),
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1132 lo_ieee_inf_value ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1133
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1134 octave_value tmp = os.scanf (args(1), size, count, who);
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
1135
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1136 // FIXME: is this the right thing to do?
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1137 // Extract error message first, because getting
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1138 // position will clear it.
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1139 std::string errmsg = os.error ();
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1140
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1141 retval = ovl (tmp, count, errmsg,
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1142 (os.eof () ? data.length () : os.tell ()) + 1);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1143 }
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1144
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1145 return retval;
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1146 }
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1147
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1148 DEFUN (scanf, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1149 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1150 @deftypefn {} {[@var{val}, @var{count}, @var{errmsg}] =} scanf (@var{template}, @var{size})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1151 @deftypefnx {} {[@var{v1}, @var{v2}, @dots{}, @var{count}, @var{errmsg}]] =} scanf (@var{template}, \"C\")\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1152 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
1153 \n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1154 It is currently not useful to call @code{scanf} in interactive programs.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1155 @seealso{fscanf, sscanf, printf}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1156 @end deftypefn")
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 int nargin = args.length ();
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1159
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1160 octave_value_list tmp_args (nargin+1, octave_value ());
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1161
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1162 tmp_args (0) = 0.0;
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1163 for (int i = 0; i < nargin; i++)
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18078
diff changeset
1164 tmp_args(i+1) = args(i);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1165
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2189
diff changeset
1166 return Ffscanf (tmp_args, nargout);
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
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1169 static octave_value
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1170 do_fread (octave_stream& os, const octave_value& size_arg,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
1171 const octave_value& prec_arg, const octave_value& skip_arg,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
1172 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
1173 {
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1174 count = -1;
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1175
20703
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1176 Array<double> size = size_arg.xvector_value ("fread: invalid SIZE specified");
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1177
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1178 std::string prec = prec_arg.xstring_value ("fread: PRECISION must be a string");
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1179
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1180 int block_size = 1;
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1181 oct_data_conv::data_type input_type;
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1182 oct_data_conv::data_type output_type;
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1183
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1184 try
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1185 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1186 oct_data_conv::string_to_data_type (prec, block_size,
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1187 input_type, output_type);
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1188 }
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20764
diff changeset
1189 catch (octave_execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1190 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
1191 error (e, "fread: invalid PRECISION specified");
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1192 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1193
20747
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
1194 int skip = 0;
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1195
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1196 try
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1197 {
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1198 skip = skip_arg.int_value (true);
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1199 }
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20764
diff changeset
1200 catch (octave_execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1201 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
1202 error (e, "fread: SKIP must be an integer");
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1203 }
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1204
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1205 std::string arch = arch_arg.xstring_value ("fread: ARCH architecture type must be a string");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1206
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1207 oct_mach_info::float_format flt_fmt
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1208 = oct_mach_info::string_to_float_format (arch);
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1209
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1210 return os.read (size, block_size, input_type, output_type, skip,
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1211 flt_fmt, count);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1212 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1213
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1214 DEFUN (fread, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1215 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1216 @deftypefn {} {@var{val} =} fread (@var{fid})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1217 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1218 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1219 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1220 @deftypefnx {} {@var{val} =} fread (@var{fid}, @var{size}, @var{precision}, @var{skip}, @var{arch})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1221 @deftypefnx {} {[@var{val}, @var{count}] =} fread (@dots{})\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1222 Read binary data from the file specified by the file descriptor @var{fid}.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1223 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1224 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
1225 and may be one of\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1226 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1227 @table @code\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1228 @item Inf\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1229 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
1230 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1231 @item @var{nr}\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1232 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
1233 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1234 @item [@var{nr}, Inf]\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1235 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
1236 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
1237 column is padded with zeros.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1238 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1239 @item [@var{nr}, @var{nc}]\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1240 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
1241 @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
1242 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
1243 @end table\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1244 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1245 @noindent\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1246 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
1247 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1248 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
1249 data to read and may be one of\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1250 \n\
11595
5ec6aa05638d Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
1251 @table @asis\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1252 @item @qcode{\"schar\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1253 @itemx @qcode{\"signed char\"}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1254 Signed character.\n\
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1255 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1256 @item @qcode{\"uchar\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1257 @itemx @qcode{\"unsigned char\"}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1258 Unsigned character.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1259 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1260 @item @qcode{\"int8\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1261 @itemx @qcode{\"integer*1\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1262 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1263 8-bit signed integer.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1264 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1265 @item @qcode{\"int16\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1266 @itemx @qcode{\"integer*2\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1267 16-bit signed integer.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1268 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1269 @item @qcode{\"int32\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1270 @itemx @qcode{\"integer*4\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1271 32-bit signed integer.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1272 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1273 @item @qcode{\"int64\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1274 @itemx @qcode{\"integer*8\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1275 64-bit signed integer.\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1276 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1277 @item @qcode{\"uint8\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1278 8-bit unsigned integer.\n\
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1279 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1280 @item @qcode{\"uint16\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1281 16-bit unsigned integer.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1282 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1283 @item @qcode{\"uint32\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1284 32-bit unsigned integer.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1285 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1286 @item @qcode{\"uint64\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1287 64-bit unsigned integer.\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1288 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1289 @item @qcode{\"single\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1290 @itemx @qcode{\"float32\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1291 @itemx @qcode{\"real*4\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1292 32-bit floating point number.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1293 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1294 @item @qcode{\"double\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1295 @itemx @qcode{\"float64\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1296 @itemx @qcode{\"real*8\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1297 64-bit floating point number.\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1298 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1299 @item @qcode{\"char\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1300 @itemx @qcode{\"char*1\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1301 Single character.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1302 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1303 @item @qcode{\"short\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1304 Short integer (size is platform dependent).\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1305 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1306 @item @qcode{\"int\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1307 Integer (size is platform dependent).\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1308 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1309 @item @qcode{\"long\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1310 Long integer (size is platform dependent).\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1311 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1312 @item @qcode{\"ushort\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1313 @itemx @qcode{\"unsigned short\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1314 Unsigned short integer (size is platform dependent).\n\
4610
02d2fcf835fc [project @ 2003-11-14 17:08:59 by jwe]
jwe
parents: 4594
diff changeset
1315 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1316 @item @qcode{\"uint\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1317 @itemx @qcode{\"unsigned int\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1318 Unsigned integer (size is platform dependent).\n\
4610
02d2fcf835fc [project @ 2003-11-14 17:08:59 by jwe]
jwe
parents: 4594
diff changeset
1319 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1320 @item @qcode{\"ulong\"}\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1321 @itemx @qcode{\"unsigned long\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1322 Unsigned long integer (size is platform dependent).\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1323 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1324 @item @qcode{\"float\"}\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1325 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
1326 @end table\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1327 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1328 @noindent\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1329 The default precision is @qcode{\"uchar\"}.\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1330 \n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1331 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
1332 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
1333 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
1334 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
1335 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1336 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
1337 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
1338 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
1339 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
1340 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
1341 \n\
7096
81bed50b9feb [project @ 2007-11-02 16:13:43 by jwe]
jwe
parents: 7078
diff changeset
1342 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
1343 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
1344 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
1345 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
1346 precision values.\n\
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1347 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1348 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
1349 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
1350 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
1351 complete, the final skip is omitted. For example,\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1352 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1353 @example\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1354 fread (f, 10, \"3*single=>single\", 8)\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1355 @end example\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1356 \n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1357 @noindent\n\
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4933
diff changeset
1358 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
1359 a complete block of 3 values.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1360 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1361 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
1362 for the file. Valid values are\n\
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1363 \n\
18078
b06a9768b643 doc: Don't use @table @qcode to avoid problems with Texinfo 5.2.
Rik <rik@octave.org>
parents: 18040
diff changeset
1364 @table @asis\n\
20431
f02c22f71cdb doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents: 20198
diff changeset
1365 @item @qcode{\"native\"} or @qcode{\"n\"}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1366 The format of the current machine.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1367 \n\
20431
f02c22f71cdb doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents: 20198
diff changeset
1368 @item @qcode{\"ieee-be\"} or @qcode{\"b\"}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1369 IEEE big endian.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1370 \n\
20431
f02c22f71cdb doc: Add info about single letter codes for fread, fopen IEEE format.
Rik <rik@octave.org>
parents: 20198
diff changeset
1371 @item @qcode{\"ieee-le\"} or @qcode{\"l\"}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1372 IEEE little endian.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1373 @end table\n\
2318
31e7eb125d89 [project @ 1996-07-14 22:44:50 by jwe]
jwe
parents: 2237
diff changeset
1374 \n\
20439
97edbce9b975 doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents: 20431
diff changeset
1375 If no @var{arch} is given the value used in the call to @code{fopen} which\n\
97edbce9b975 doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents: 20431
diff changeset
1376 created the file descriptor is used. Otherwise, the value specified with\n\
97edbce9b975 doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents: 20431
diff changeset
1377 @code{fread} overrides that of @code{fopen} and determines the data format.\n\
97edbce9b975 doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents: 20431
diff changeset
1378 \n\
18208
bea06b5d4423 doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents: 18112
diff changeset
1379 The output argument @var{val} contains the data read from the file.\n\
20439
97edbce9b975 doc: Clarify that ARCH argument to fread overrides ARCH arg to fopen.
Rik <rik@octave.org>
parents: 20431
diff changeset
1380 \n\
18208
bea06b5d4423 doc: Improve documentation for fread function.
Rik <rik@octave.org>
parents: 18112
diff changeset
1381 The optional return value @var{count} contains the number of elements read.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
1382 @seealso{fwrite, fgets, fgetl, fscanf, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1383 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1384 {
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1385 int nargin = args.length ();
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1386
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1387 if (nargin < 1 || nargin > 5)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1388 print_usage ();
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1389
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1390 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
1391
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1392 octave_value size = lo_ieee_inf_value ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1393 octave_value prec = "uchar";
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1394 octave_value skip = 0;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1395 octave_value arch = "unknown";
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1396
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1397 int idx = 1;
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1398
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1399 if (nargin > idx && ! args(idx).is_string ())
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1400 size = args(idx++);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1401
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1402 if (nargin > idx)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1403 prec = args(idx++);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1404
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1405 if (nargin > idx)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1406 skip = args(idx++);
4257
e556870ce8f0 [project @ 2003-01-02 03:14:41 by jwe]
jwe
parents: 4254
diff changeset
1407
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1408 if (nargin > idx)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1409 arch = args(idx++);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1410 else if (skip.is_string ())
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1411 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1412 arch = skip;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1413 skip = 0;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1414 }
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1415
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1416 octave_idx_type count = -1;
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
1417
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1418 octave_value tmp = do_fread (os, size, prec, skip, arch, count);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1419
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1420 return ovl (tmp, count);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1421 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1422
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1423 static int
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1424 do_fwrite (octave_stream& os, const octave_value& data,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
1425 const octave_value& prec_arg, const octave_value& skip_arg,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
1426 const octave_value& arch_arg)
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1427 {
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
1428 std::string prec = prec_arg.xstring_value ("fwrite: PRECISION must be a string");
20581
fd0efcdb3718 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
1429
fd0efcdb3718 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
1430 int block_size = 1;
fd0efcdb3718 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
1431 oct_data_conv::data_type output_type;
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1432
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1433 try
20581
fd0efcdb3718 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
1434 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1435 oct_data_conv::string_to_data_type (prec, block_size, output_type);
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1436 }
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20764
diff changeset
1437 catch (octave_execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1438 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
1439 error (e, "fwrite: invalid PRECISION specified");
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1440 }
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1441
20747
ee2743bd07a8 eliminate various compiler warnings
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
1442 int skip = 0;
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
1443
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1444 try
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1445 {
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1446 skip = skip_arg.int_value (true);
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1447 }
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20764
diff changeset
1448 catch (octave_execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1449 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
1450 error (e, "fwrite: SKIP must be an integer");
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1451 }
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1452
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1453 std::string arch = arch_arg.xstring_value ("fwrite: ARCH architecture type must be a string");
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1454
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1455 oct_mach_info::float_format flt_fmt
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1456 = oct_mach_info::string_to_float_format (arch);
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1457
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
1458 return os.write (data, block_size, output_type, skip, flt_fmt);
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1459 }
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1460
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1461 DEFUN (fwrite, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1462 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1463 @deftypefn {} {} fwrite (@var{fid}, @var{data})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1464 @deftypefnx {} {} fwrite (@var{fid}, @var{data}, @var{precision})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1465 @deftypefnx {} {} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1466 @deftypefnx {} {} fwrite (@var{fid}, @var{data}, @var{precision}, @var{skip}, @var{arch})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1467 @deftypefnx {} {@var{count} =} fwrite (@dots{})\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1468 Write data in binary form to the file specified by the file descriptor\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1469 @var{fid}, returning the number of values @var{count} successfully written\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1470 to the file.\n\
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1471 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1472 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
1473 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
1474 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1475 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
1476 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
1477 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1478 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
1479 are too large to fit in the specified precision.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
1480 @seealso{fread, fputs, fprintf, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1481 @end deftypefn")
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1482 {
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1483 int nargin = args.length ();
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1484
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1485 if (nargin < 2 || nargin > 5)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1486 print_usage ();
2116
99658f9b74c8 [project @ 1996-05-10 07:20:15 by jwe]
jwe
parents: 2095
diff changeset
1487
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1488 octave_stream os = octave_stream_list::lookup (args(0), "fwrite");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1489
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1490 octave_value prec = "uchar";
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1491 octave_value skip = 0;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1492 octave_value arch = "unknown";
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1493
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1494 int idx = 1;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1495
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1496 octave_value data = args(idx++);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1497
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1498 if (nargin > idx)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1499 prec = args(idx++);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1500
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1501 if (nargin > idx)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1502 skip = args(idx++);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1503
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1504 if (nargin > idx)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1505 arch = args(idx++);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1506 else if (skip.is_string ())
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1507 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1508 arch = skip;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1509 skip = 0;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1510 }
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1511
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
1512 return ovl (do_fwrite (os, data, prec, skip, arch));
1181
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1513 }
b2b7c5264ac2 [project @ 1995-03-28 23:51:50 by jwe]
jwe
parents: 1086
diff changeset
1514
5906
bdf16e1564e1 [project @ 2006-07-27 03:07:14 by jwe]
jwe
parents: 5823
diff changeset
1515 DEFUNX ("feof", Ffeof, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1516 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1517 @deftypefn {} {@var{status} =} feof (@var{fid})\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1518 Return 1 if an end-of-file condition has been encountered for the file\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1519 specified by file descriptor @var{fid} and 0 otherwise.\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1520 \n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1521 Note that @code{feof} will only return 1 if the end of the file has already\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1522 been encountered, not if the next read operation will result in an\n\
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1523 end-of-file condition.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1524 @seealso{fread, frewind, fseek, fclear, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1525 @end deftypefn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 506
diff changeset
1526 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1527 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1528 print_usage ();
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1529
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1530 octave_stream os = octave_stream_list::lookup (args(0), "feof");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1531
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
1532 return ovl (os.eof () ? 1.0 : 0.0);
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1533 }
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 372
diff changeset
1534
5906
bdf16e1564e1 [project @ 2006-07-27 03:07:14 by jwe]
jwe
parents: 5823
diff changeset
1535 DEFUNX ("ferror", Fferror, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1536 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1537 @deftypefn {} {@var{msg} =} ferror (@var{fid})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1538 @deftypefnx {} {[@var{msg}, @var{err}] =} ferror (@var{fid})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1539 @deftypefnx {} {[@var{dots}] =} ferror (@var{fid}, \"clear\")\n\
19150
adb102face2d doc: Redo docstring for ferror().
Rik <rik@octave.org>
parents: 19127
diff changeset
1540 Query the error status of the stream specified by file descriptor @var{fid}\n\
adb102face2d doc: Redo docstring for ferror().
Rik <rik@octave.org>
parents: 19127
diff changeset
1541 \n\
adb102face2d doc: Redo docstring for ferror().
Rik <rik@octave.org>
parents: 19127
diff changeset
1542 If an error condition exists then return a string @var{msg} describing the\n\
adb102face2d doc: Redo docstring for ferror().
Rik <rik@octave.org>
parents: 19127
diff changeset
1543 error. Otherwise, return an empty string @qcode{\"\"}.\n\
9797
f569f46a1c34 update ferror doc string, take 2
John W. Eaton <jwe@octave.org>
parents: 9796
diff changeset
1544 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1545 The second input @qcode{\"clear\"} is optional. If supplied, the error\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1546 state on the stream will be cleared.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1547 \n\
19150
adb102face2d doc: Redo docstring for ferror().
Rik <rik@octave.org>
parents: 19127
diff changeset
1548 The optional second output is a numeric indication of the error status.\n\
adb102face2d doc: Redo docstring for ferror().
Rik <rik@octave.org>
parents: 19127
diff changeset
1549 @var{err} is 1 if an error condition has been encountered and 0 otherwise.\n\
19127
df5e4024ec18 doc: Rephrase docstrings for low level C I/O functions.
Rik <rik@octave.org>
parents: 19123
diff changeset
1550 \n\
19150
adb102face2d doc: Redo docstring for ferror().
Rik <rik@octave.org>
parents: 19127
diff changeset
1551 Note that @code{ferror} indicates if an error has already occurred, not\n\
adb102face2d doc: Redo docstring for ferror().
Rik <rik@octave.org>
parents: 19127
diff changeset
1552 whether the next operation will result in an error condition.\n\
14438
6a8c3cd326fd doc: Improve seealso links between low-level file I/O functions.
Rik <octave@nomad.inbox5.com>
parents: 14436
diff changeset
1553 @seealso{fclear, fopen}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1554 @end deftypefn")
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1555 {
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1556 int nargin = args.length ();
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1557
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1558 if (nargin < 1 || nargin > 2)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1559 print_usage ();
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1560
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1561 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
1562
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1563 bool clear = false;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1564
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1565 if (nargin == 2)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1566 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1567 std::string opt = args(1).string_value ();
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20457
diff changeset
1568
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1569 clear = (opt == "clear");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1570 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
1571
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1572 int error_number = 0;
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1573
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1574 std::string error_message = os.error (clear, error_number);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1575
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1576 return ovl (error_message, error_number);
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1577 }
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1578
18477
aa7ca90ce746 avoid problems if popen is a macro
John W. Eaton <jwe@octave.org>
parents: 18040
diff changeset
1579 DEFUNX ("popen", Fpopen, args, ,
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19727
diff changeset
1580 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1581 @deftypefn {} {@var{fid} =} popen (@var{command}, @var{mode})\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1582 Start a process and create a pipe.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1583 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1584 The name of the command to run is given by @var{command}. The argument\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1585 @var{mode} may be\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1586 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1587 @table @code\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1588 @item @qcode{\"r\"}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1589 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
1590 open for reading.\n\
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1591 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1592 @item @qcode{\"w\"}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1593 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
1594 open for writing.\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1595 @end table\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1596 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1597 The file identifier corresponding to the input or output stream of the\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1598 process is returned in @var{fid}.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1599 \n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
1600 For example:\n\
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1601 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1602 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1603 @group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1604 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
1605 while (ischar (s = fgets (fid)))\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1606 fputs (stdout, s);\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1607 endwhile\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14210
diff changeset
1608 \n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14210
diff changeset
1609 @print{} drwxr-xr-x 33 root root 3072 Feb 15 13:28 etc\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14210
diff changeset
1610 @print{} drwxr-xr-x 3 root root 1024 Feb 15 13:28 lib\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14210
diff changeset
1611 @print{} drwxrwxrwt 15 root root 2048 Feb 17 14:53 tmp\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1612 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1613 @end example\n\
18950
ed3cb9f81145 file-io.cc (popen): Add seealso popen2
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18487
diff changeset
1614 @seealso{popen2}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1615 @end deftypefn")
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1616 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1617 if (args.length () != 2)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1618 print_usage ();
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1619
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1620 std::string name = args(0).xstring_value ("popen: COMMAND must be a string");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1621 std::string mode = args(1).xstring_value ("popen: MODE must be a string");
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1622
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1623 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1624
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1625 if (mode == "r")
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1626 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1627 octave_stream ips = octave_iprocstream::create (name);
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1628
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1629 retval = octave_stream_list::insert (ips);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1630 }
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1631 else if (mode == "w")
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1632 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1633 octave_stream ops = octave_oprocstream::create (name);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1634
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1635 retval = octave_stream_list::insert (ops);
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 1996
diff changeset
1636 }
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1637 else
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1638 error ("popen: invalid MODE specified");
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1639
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1640 return retval;
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1641 }
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1642
16308
122c1a7a3004 avoid trouble if pclose is a macro
John W. Eaton <jwe@octave.org>
parents: 16099
diff changeset
1643 DEFUNX ("pclose", Fpclose, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1644 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1645 @deftypefn {} {} pclose (@var{fid})\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1646 Close a file identifier that was opened by @code{popen}.\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1647 \n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1648 The function @code{fclose} may also be used for the same purpose.\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1649 @seealso{fclose, popen}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1650 @end deftypefn")
1230
92609e161b29 [project @ 1995-04-10 01:08:57 by jwe]
jwe
parents: 1181
diff changeset
1651 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1652 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1653 print_usage ();
1379
e29697484908 [project @ 1995-09-12 00:41:58 by jwe]
jwe
parents: 1377
diff changeset
1654
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
1655 return ovl (octave_stream_list::remove (args(0), "pclose"));
1379
e29697484908 [project @ 1995-09-12 00:41:58 by jwe]
jwe
parents: 1377
diff changeset
1656 }
e29697484908 [project @ 1995-09-12 00:41:58 by jwe]
jwe
parents: 1377
diff changeset
1657
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 19268
diff changeset
1658 DEFUN (tempname, args, ,
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 19268
diff changeset
1659 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1660 @deftypefn {} {@var{fname} =} tempname ()\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1661 @deftypefnx {} {@var{fname} =} tempname (@var{dir})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1662 @deftypefnx {} {@var{fname} =} tempname (@var{dir}, @var{prefix})\n\
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 20704
diff changeset
1663 Return a unique temporary filename as a string.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1664 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17170
diff changeset
1665 If @var{prefix} is omitted, a value of @qcode{\"oct-\"} is used.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1666 \n\
4267
7cd865a8c815 [project @ 2003-01-03 15:27:05 by jwe]
jwe
parents: 4257
diff changeset
1667 If @var{dir} is also omitted, the default directory for temporary files\n\
19385
3b4d6780d6b8 doc: Add missing closing parenthesis in tempname docstring.
Rik <rik@octave.org>
parents: 19278
diff changeset
1668 (@code{P_tmpdir}) is used. If @var{dir} is provided, it must exist,\n\
19210
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1669 otherwise the default directory for temporary files is used.\n\
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1670 \n\
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 19268
diff changeset
1671 Programming Note: Because the named file is not opened by @code{tempname},\n\
19210
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1672 it is possible, though relatively unlikely, that it will not be available\n\
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1673 by the time your program attempts to open it. If this is a concern,\n\
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 19268
diff changeset
1674 see @code{tmpfile}.\n\
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 19268
diff changeset
1675 @seealso{mkstemp, tempdir, P_tmpdir, tmpfile}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1676 @end deftypefn")
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1677 {
20812
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20805
diff changeset
1678 int nargin = args.length ();
2936
87cb7614257d [project @ 1997-05-06 05:46:00 by jwe]
jwe
parents: 2926
diff changeset
1679
20812
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20805
diff changeset
1680 if (nargin > 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1681 print_usage ();
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1682
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1683 std::string dir;
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1684
20812
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20805
diff changeset
1685 if (nargin > 0)
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1686 dir = args(0).xstring_value ("tempname: DIR must be a string");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1687
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1688 std::string pfx ("oct-");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1689
20812
d9ca869ca124 maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents: 20805
diff changeset
1690 if (nargin > 1)
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1691 pfx = args(1).xstring_value ("tempname: PREFIX must be a string");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1692
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
1693 return ovl (octave_tempnam (dir, pfx));
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1694 }
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
1695
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1696 /*
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1697 %!test
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1698 %! if (ispc ())
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1699 %! envname = "TMP";
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1700 %! else
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1701 %! envname = "TMPDIR";
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1702 %! endif
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1703 %! envdir = getenv (envname);
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1704 %! unsetenv (envname);
21457
05ffef4ebf62 tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents: 21301
diff changeset
1705 %! ## Strip trailing file separators from P_tmpdir
05ffef4ebf62 tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents: 21301
diff changeset
1706 %! def_tmpdir = P_tmpdir;
05ffef4ebf62 tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents: 21301
diff changeset
1707 %! while (length (def_tmpdir) > 2 && strfind (filesep ("all"), def_tmpdir(end)))
05ffef4ebf62 tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents: 21301
diff changeset
1708 %! def_tmpdir(end) = [];
05ffef4ebf62 tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents: 21301
diff changeset
1709 %! endwhile
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1710 %! unwind_protect
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1711 %! ## Test 0-argument form
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1712 %! fname = tempname ();
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19420
diff changeset
1713 %! [tmpdir, tmpfname] = fileparts (fname);
21457
05ffef4ebf62 tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents: 21301
diff changeset
1714 %! assert (tmpdir, def_tmpdir);
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1715 %! assert (tmpfname (1:4), "oct-");
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19420
diff changeset
1716 %! ## Test 1-argument form
21457
05ffef4ebf62 tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents: 21301
diff changeset
1717 %! tmp_tmpdir = [def_tmpdir filesep() substr(tmpfname, -5)];
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1718 %! mkdir (tmp_tmpdir) || error ("Unable to create tmp dir");
21457
05ffef4ebf62 tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents: 21301
diff changeset
1719 %! setenv (envname, def_tmpdir);
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1720 %! fname = tempname (tmp_tmpdir);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19420
diff changeset
1721 %! [tmpdir, tmpfname] = fileparts (fname);
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1722 %! assert (tmpdir, tmp_tmpdir);
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1723 %! assert (tmpfname (1:4), "oct-");
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1724 %! ## Test 1-argument form w/null tmpdir
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1725 %! fname = tempname ("");
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19420
diff changeset
1726 %! [tmpdir, tmpfname] = fileparts (fname);
21457
05ffef4ebf62 tempname: Fix failing BIST test when P_tmpdir has trailing slash
Mike Miller <mtmiller@octave.org>
parents: 21301
diff changeset
1727 %! assert (tmpdir, def_tmpdir);
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1728 %! assert (tmpfname (1:4), "oct-");
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19420
diff changeset
1729 %! ## Test 2-argument form
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1730 %! fname = tempname (tmp_tmpdir, "pfx-");
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19420
diff changeset
1731 %! [tmpdir, tmpfname] = fileparts (fname);
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1732 %! assert (tmpdir, tmp_tmpdir);
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1733 %! assert (tmpfname (1:4), "pfx-");
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1734 %! ## Test 2-argument form w/null prefix
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1735 %! fname = tempname (tmp_tmpdir, "");
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19420
diff changeset
1736 %! [tmpdir, tmpfname] = fileparts (fname);
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1737 %! assert (tmpdir, tmp_tmpdir);
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1738 %! assert (tmpfname (1:4), "file");
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1739 %! unwind_protect_cleanup
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1740 %! rmdir (tmp_tmpdir);
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1741 %! if (isempty (envdir))
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1742 %! unsetenv (envname);
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1743 %! else
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1744 %! setenv (envname, envdir);
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1745 %! endif
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1746 %! end_unwind_protect
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1747 */
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 19403
diff changeset
1748
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1749 DEFUN (tmpfile, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1750 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1751 @deftypefn {} {[@var{fid}, @var{msg}] =} tmpfile ()\n\
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1752 Return the file ID corresponding to a new temporary file with a unique\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1753 name.\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1754 \n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1755 The file is opened in binary read/write (@qcode{\"w+b\"}) mode and will be\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1756 deleted automatically when it is closed or when Octave exits.\n\
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1757 \n\
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1758 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
1759 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
1760 system-dependent error message.\n\
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 19268
diff changeset
1761 @seealso{tempname, mkstemp, tempdir, P_tmpdir}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1762 @end deftypefn")
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1763 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1764 if (args.length () != 0)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1765 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1766
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1767 octave_value_list retval;
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1768
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1769 FILE *fid = gnulib::tmpfile ();
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1770
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1771 if (fid)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1772 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1773 std::string nm;
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1774
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1775 std::ios::openmode md = fopen_mode_to_ios_mode ("w+b");
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1776
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1777 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
1778
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1779 if (! s)
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1780 error ("tmpfile: failed to create octave_stdiostream object");
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1781
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1782 retval = ovl (octave_stream_list::insert (s), "");
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1783 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1784 else
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1785 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1786 retval = ovl (-1, gnulib::strerror (errno));
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1787 }
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1788
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1789 return retval;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1790 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1791
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1792 DEFUN (mkstemp, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1793 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1794 @deftypefn {} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (\"@var{template}\")\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1795 @deftypefnx {} {[@var{fid}, @var{name}, @var{msg}] =} mkstemp (\"@var{template}\", @var{delete})\n\
19210
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1796 Return the file descriptor @var{fid} corresponding to a new temporary file\n\
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1797 with a unique name created from @var{template}.\n\
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1798 \n\
19210
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1799 The last six characters of @var{template} must be @qcode{\"XXXXXX\"} and\n\
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1800 these are replaced with a string that makes the filename unique. The file\n\
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1801 is then created with mode read/write and permissions that are system\n\
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1802 dependent (on GNU/Linux systems, the permissions will be 0600 for versions of\n\
19230
cfa9996afcbf doc: fix stray escape sequence in mkstemp's docstring
Mike Miller <mtmiller@ieee.org>
parents: 19210
diff changeset
1803 glibc 2.0.7 and later). The file is opened in binary mode and with the\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1804 @w{@code{O_EXCL}} flag.\n\
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1805 \n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1806 If the optional argument @var{delete} is supplied and is true, the file will\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1807 be deleted automatically when Octave exits.\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1808 \n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1809 If successful, @var{fid} is a valid file ID, @var{name} is the name of the\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1810 file, and @var{msg} is an empty string. Otherwise, @var{fid} is -1,\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1811 @var{name} is empty, and @var{msg} contains a system-dependent error message.\n\
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 19268
diff changeset
1812 @seealso{tempname, tempdir, P_tmpdir, tmpfile, fopen}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5421
diff changeset
1813 @end deftypefn")
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1814 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1815 int nargin = args.length ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1816
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1817 if (nargin < 1 || nargin > 2)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1818 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1819
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1820 std::string tmpl8 = args(0).xstring_value ("mkstemp: TEMPLATE argument must be a string");
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1821
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1822 octave_value_list retval = ovl (-1, "", "");
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1823
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1824 OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1825 strcpy (tmp, tmpl8.c_str ());
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1826
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1827 int fd = gnulib::mkostemp (tmp, O_BINARY);
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1828
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1829 if (fd < 0)
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1830 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1831 retval(0) = fd;
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1832 retval(2) = gnulib::strerror (errno);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1833 }
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1834 else
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1835 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1836 const char *fopen_mode = "w+b";
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1837
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1838 FILE *fid = fdopen (fd, fopen_mode);
20581
fd0efcdb3718 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
1839
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1840 if (! fid)
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1841 {
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1842 retval(0) = -1;
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1843 retval(2) = gnulib::strerror (errno);
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1844 }
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1845 else
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1846 {
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1847 std::string nm = tmp;
20581
fd0efcdb3718 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
1848
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1849 std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode);
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1850
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1851 octave_stream s = octave_stdiostream::create (nm, fid, md);
20581
fd0efcdb3718 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
1852
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1853 if (! s)
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1854 error ("mkstemp: failed to create octave_stdiostream object");
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1855
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1856 retval(0) = octave_stream_list::insert (s);
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1857 retval(1) = nm;
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1858
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1859 if (nargin == 2 && args(1).is_true ())
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20861
diff changeset
1860 mark_for_deletion (nm);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
1861 }
4326
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1862 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1863
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1864 return retval;
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1865 }
1cae4472c624 [project @ 2003-02-15 23:14:47 by jwe]
jwe
parents: 4267
diff changeset
1866
20200
d9f35ceff9e1 Change mkfifo to use an octal argument for MODE (bug #45054).
Rik <rik@octave.org>
parents: 20198
diff changeset
1867 // FIXME: This routine also exists verbatim in syscalls.cc.
d9f35ceff9e1 Change mkfifo to use an octal argument for MODE (bug #45054).
Rik <rik@octave.org>
parents: 20198
diff changeset
1868 // Maybe change to be a general utility routine.
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1869 static int
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1870 convert (int x, int ibase, int obase)
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1871 {
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1872 int retval = 0;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1873
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1874 int tmp = x % obase;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1875
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1876 if (tmp > ibase - 1)
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20200
diff changeset
1877 error ("umask: invalid digit");
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1878
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1879 retval = tmp;
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1880 int mult = ibase;
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1881 while ((x = (x - tmp) / obase))
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1882 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1883 tmp = x % obase;
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1884
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1885 if (tmp > ibase - 1)
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1886 error ("umask: invalid digit");
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1887
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1888 retval += mult * tmp;
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20962
diff changeset
1889 mult *= ibase;
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1890 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1891
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1892 return retval;
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1893 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1894
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
1895 DEFUNX ("umask", Fumask, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1896 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1897 @deftypefn {} {} umask (@var{mask})\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1898 Set the permission mask for file creation.\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1899 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1900 The parameter @var{mask} is an integer, interpreted as an octal number.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1901 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20101
diff changeset
1902 If successful, returns the previous value of the mask (as an integer to be\n\
4715
7bed0ef1a6ad [project @ 2004-01-22 22:10:28 by jwe]
jwe
parents: 4649
diff changeset
1903 interpreted as an octal number); otherwise an error message is printed.\n\
20198
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
1904 \n\
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
1905 The permission mask is a UNIX concept used when creating new objects on a\n\
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
1906 file system such as files, directories, or named FIFOs. The object to be\n\
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
1907 created has base permissions in an octal number @var{mode} which are\n\
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
1908 modified according to the octal value of @var{mask}. The final permissions\n\
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
1909 for the new object are @code{@var{mode} - @var{mask}}.\n\
b597bd161a5f doc: Document that mkfifo's mode argument is in decimal (bug #45054).
Rik <rik@octave.org>
parents: 20172
diff changeset
1910 @seealso{fopen, mkdir, mkfifo}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3263
diff changeset
1911 @end deftypefn")
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1912 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1913 if (args.length () != 1)
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1914 print_usage ();
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1915
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1916 int mask = args(0).xint_value ("umask: MASK must be an integer");
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1917
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1918 if (mask < 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1919 error ("umask: MASK must be a positive integer value");
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1920
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1921 int oct_mask = convert (mask, 8, 10);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1922
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1923 int status = convert (octave_umask (oct_mask), 10, 8);
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1924
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1925 if (status >= 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1926 return ovl (status);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1927 else
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
1928 return ovl ();
1400
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1929 }
209ec8f4db00 [project @ 1995-09-15 04:08:08 by jwe]
jwe
parents: 1381
diff changeset
1930
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1931 static octave_value
6483
d00da2148c53 [project @ 2007-04-04 02:58:48 by jwe]
jwe
parents: 6456
diff changeset
1932 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
1933 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1934 if (args.length () != 0)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1935 print_usage ();
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1936
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1937 return octave_value (val);
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1938 }
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1939
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1940 DEFUNX ("P_tmpdir", FP_tmpdir, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1941 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1942 @deftypefn {} {} P_tmpdir ()\n\
19210
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1943 Return the name of the host system's @strong{default} directory for\n\
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1944 temporary files.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1945 \n\
19210
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1946 Programming Note: The value returned by @code{P_tmpdir} is always the\n\
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1947 default location. This value may not agree with that returned from\n\
20097
1f9ed81bd173 maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents: 20041
diff changeset
1948 @code{tempdir} if the user has overridden the default with the @env{TMPDIR}\n\
19210
841d8f606bcd doc: Improve docstrings for tempname, tempdir family of functions.
Rik <rik@octave.org>
parents: 19150
diff changeset
1949 environment variable.\n\
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 19268
diff changeset
1950 @seealso{tempdir, tempname, mkstemp, tmpfile}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1951 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1952 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1953 if (args.length () != 0)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1954 print_usage ();
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1955
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21126
diff changeset
1956 return ovl (get_P_tmpdir ());
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1957 }
2341
6ee55c0f25a9 [project @ 1996-07-24 10:33:09 by jwe]
jwe
parents: 2324
diff changeset
1958
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1959 // 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
1960 // this way for Matlab compatibility.
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1961
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1962 DEFUNX ("SEEK_SET", FSEEK_SET, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1963 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1964 @deftypefn {} {} SEEK_SET ()\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1965 @deftypefnx {} {} SEEK_CUR ()\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1966 @deftypefnx {} {} SEEK_END ()\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1967 Return the numerical value to pass to @code{fseek} to perform one of the\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
1968 following actions:\n\
14366
b76f0740940e doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14365
diff changeset
1969 \n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1970 @table @code\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1971 @item SEEK_SET\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1972 Position file relative to the beginning.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1973 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1974 @item SEEK_CUR\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1975 Position file relative to the current position.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1976 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1977 @item SEEK_END\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1978 Position file relative to the end.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3342
diff changeset
1979 @end table\n\
14171
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1980 @seealso{fseek}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1981 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1982 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1983 return const_value ("SEEK_SET", args, -1);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1984 }
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
1985
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1986 DEFUNX ("SEEK_CUR", FSEEK_CUR, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1987 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1988 @deftypefn {} {} SEEK_CUR ()\n\
14171
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1989 Return the numerical value to pass to @code{fseek} to\n\
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1990 position the file pointer relative to the current position.\n\
18040
62f94ef938b4 don't use period after end of @seealso{...}
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1991 @seealso{SEEK_SET, SEEK_END}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1992 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1993 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1994 return const_value ("SEEK_CUR", args, 0);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1995 }
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
1996
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
1997 DEFUNX ("SEEK_END", FSEEK_END, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1998 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
1999 @deftypefn {} {} SEEK_END ()\n\
14171
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2000 Return the numerical value to pass to @code{fseek} to\n\
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2001 position the file pointer relative to the end of the file.\n\
18040
62f94ef938b4 don't use period after end of @seealso{...}
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2002 @seealso{SEEK_SET, SEEK_CUR}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2003 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2004 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2005 return const_value ("SEEK_END", args, 1);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2006 }
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2007
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2008 static octave_value
6483
d00da2148c53 [project @ 2007-04-04 02:58:48 by jwe]
jwe
parents: 6456
diff changeset
2009 const_value (const char *, const octave_value_list& args,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10259
diff changeset
2010 const octave_value& val)
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2011 {
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2012 if (args.length () != 0)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
2013 print_usage ();
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2014
20805
2d6ddb2b157c eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2015 return octave_value (val);
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2016 }
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2017
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2018 DEFUNX ("stdin", Fstdin, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2019 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
2020 @deftypefn {} {} stdin ()\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2021 Return the numeric value corresponding to the standard input stream.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
2022 \n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
2023 When Octave is used interactively, stdin is filtered through the command\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2024 line editing functions.\n\
5333
ac8d64b9e76a [project @ 2005-05-02 18:15:20 by jwe]
jwe
parents: 5325
diff changeset
2025 @seealso{stdout, stderr}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2026 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2027 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2028 return const_value ("stdin", args, stdin_file);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2029 }
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2030
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2031 DEFUNX ("stdout", Fstdout, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2032 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
2033 @deftypefn {} {} stdout ()\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2034 Return the numeric value corresponding to the standard output stream.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
2035 \n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2036 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
2037 @seealso{stdin, stderr}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2038 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2039 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2040 return const_value ("stdout", args, stdout_file);
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2041 }
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2042
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2043 DEFUNX ("stderr", Fstderr, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2044 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20846
diff changeset
2045 @deftypefn {} {} stderr ()\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2046 Return the numeric value corresponding to the standard error stream.\n\
19109
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
2047 \n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
2048 Even if paging is turned on, the standard error is not sent to the pager.\n\
e90bfaadb489 doc: Increase seealso links between low level C IO functions.
Rik <rik@octave.org>
parents: 19030
diff changeset
2049 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
2050 @seealso{stdin, stdout}\n\
5749
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2051 @end deftypefn")
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2052 {
26beffa9f66f [project @ 2006-04-07 20:35:07 by jwe]
jwe
parents: 5653
diff changeset
2053 return const_value ("stderr", args, stderr_file);
2189
d01936305d99 [project @ 1996-05-14 03:31:57 by jwe]
jwe
parents: 2148
diff changeset
2054 }