GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pager.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_pager_h)
27#define octave_pager_h 1
28
29#include "octave-config.h"
30
31#include <fstream>
32#include <iosfwd>
33#include <sstream>
34#include <string>
35
36class octave_value;
38
39OCTAVE_NAMESPACE_BEGIN
40
41 class interpreter;
42 class oprocstream;
43
44 class
45 OCTINTERP_API
46 pager_buf : public std::stringbuf
47 {
48 public:
49
50 pager_buf (void) : std::stringbuf (), m_diary_skip (0) { }
51
52 void flush_current_contents_to_diary (void);
53
54 void set_diary_skip (void);
55
56 protected:
57
58 int sync (void);
59
60 private:
61
62 std::size_t m_diary_skip;
63 };
64
65 class
66 OCTINTERP_API
67 pager_stream : public std::ostream
68 {
69 public:
70
71 pager_stream (void);
72
73 // No copying!
74
75 pager_stream (const pager_stream&) = delete;
76
78
79 ~pager_stream (void);
80
81 void flush_current_contents_to_diary (void);
82
83 void set_diary_skip (void);
84
85 std::ostream& stream (void);
86
87 void reset (void);
88
89 private:
90
92 };
93
94 class
95 OCTINTERP_API
96 diary_buf : public std::stringbuf
97 {
98 public:
99
100 diary_buf (void) : std::stringbuf () { }
101
102 protected:
103
104 int sync (void);
105 };
106
107 class
108 OCTINTERP_API
109 diary_stream : public std::ostream
110 {
111 public:
112
113 diary_stream (void);
114
115 // No copying!
116
117 diary_stream (const diary_stream&) = delete;
118
120
121 ~diary_stream (void);
122
123 std::ostream& stream (void);
124
125 void reset (void);
126
127 private:
128
130 };
131
132 extern OCTINTERP_API void flush_stdout (void);
133
135 {
136 public:
137
138 output_system (interpreter& interp);
139
140 output_system (const output_system&) = delete;
141
143
144 ~output_system (void) = default;
145
147
149
150 std::string diary_file_name (void) const { return m_diary_file_name; }
151
152 std::string diary_file_name (const std::string& nm)
153 {
154 std::string val = m_diary_file_name;
155 m_diary_file_name = nm.empty () ? "diary" : nm;
156 return val;
157 }
158
159 octave_value PAGER (const octave_value_list& args, int nargout);
160
161 std::string PAGER (void) const { return m_PAGER; }
162
163 std::string PAGER (const std::string& s)
164 {
165 std::string val = m_PAGER;
166 m_PAGER = s;
167 return val;
168 }
169
170 octave_value PAGER_FLAGS (const octave_value_list& args, int nargout);
171
172 std::string PAGER_FLAGS (void) const { return m_PAGER_FLAGS; }
173
174 std::string PAGER_FLAGS (const std::string& s)
175 {
176 std::string val = m_PAGER_FLAGS;
177 m_PAGER_FLAGS = s;
178 return val;
179 }
180
182 int nargout);
183
184 bool page_output_immediately (void) const
185 {
187 }
188
189 bool page_output_immediately (bool flag)
190 {
191 bool val = m_page_output_immediately;
193 return val;
194 }
195
197 int nargout);
198
199 bool page_screen_output (void) const { return m_page_screen_output; }
200
201 bool page_screen_output (bool flag)
202 {
203 bool val = m_page_screen_output;
205 return val;
206 }
207
208 bool write_to_diary_file (void) const
209 {
211 }
212
213 bool write_to_diary_file (bool flag)
214 {
215 bool val = m_write_to_diary_file;
217 return val;
218 }
219
220 bool really_flush_to_pager (void) const
221 {
223 }
224
225 bool really_flush_to_pager (bool flag)
226 {
227 bool val = m_really_flush_to_pager;
229 return val;
230 }
231
232 bool flushing_output_to_pager (void) const
233 {
235 }
236
238 {
241 return val;
242 }
243
244 std::string pager_command (void) const;
245
247
248 void reset (void);
249
250 void flush_stdout (void);
251
252 bool sync (const char *msg, int len);
253
254 void clear_external_pager (void);
255
256 void open_diary (void);
257
258 void close_diary (void);
259
260 std::ostream& __stdout__ (void) { return m_pager_stream.stream (); }
261
262 std::ostream& __diary__ (void) { return m_diary_stream.stream (); }
263
264 private:
265
267
269
271
272 // Our actual connection to the external pager.
274
275 // The diary file.
277
278 // The name of the current diary file.
279 std::string m_diary_file_name;
280
281 // The shell command to run as the pager.
282 std::string m_PAGER;
283
284 // The options to pass to the pager.
285 std::string m_PAGER_FLAGS;
286
287 // TRUE means that if output is going to the pager, it is sent as soon
288 // as it is available. Otherwise, it is buffered and only sent to the
289 // pager when it is time to print another prompt.
291
292 // TRUE means all output intended for the screen should be passed
293 // through the pager.
295
296 // TRUE means we write to the diary file.
298
300
302
303 void start_external_pager (void);
304
305 void do_sync (const char *msg, int len, bool bypass_pager);
306 };
307
308 extern OCTINTERP_API std::ostream& __stdout__ (void);
309
310 extern OCTINTERP_API std::ostream& __diary__ (void);
311
312OCTAVE_NAMESPACE_END
313
314#define octave_stdout (octave::__stdout__ ())
315
316#define octave_diary (octave::__diary__ ())
317
318#endif
diary_buf(void)
Definition: pager.h:100
std::ostream & stream(void)
Definition: pager.cc:242
diary_buf * m_db
Definition: pager.h:129
diary_stream(const diary_stream &)=delete
oprocstream & operator=(const oprocstream &)
bool m_write_to_diary_file
Definition: pager.h:297
std::ofstream & external_diary_file(void)
Definition: pager.h:246
pager_stream m_pager_stream
Definition: pager.h:268
bool page_output_immediately(bool flag)
Definition: pager.h:189
std::string PAGER_FLAGS(void) const
Definition: pager.h:172
output_system & operator=(const output_system &)=delete
std::ostream & __diary__(void)
Definition: pager.h:262
std::string PAGER(void) const
Definition: pager.h:161
diary_stream m_diary_stream
Definition: pager.h:270
void close_diary(void)
Definition: pager.cc:341
bool flushing_output_to_pager(bool flag)
Definition: pager.h:237
bool really_flush_to_pager(void) const
Definition: pager.h:220
std::string m_PAGER
Definition: pager.h:282
bool page_screen_output(void) const
Definition: pager.h:199
output_system(const output_system &)=delete
void reset(void)
Definition: pager.cc:315
interpreter & m_interpreter
Definition: pager.h:266
std::string diary_file_name(void) const
Definition: pager.h:150
std::ostream & __stdout__(void)
Definition: pager.h:260
void open_diary(void)
Definition: pager.cc:363
bool write_to_diary_file(bool flag)
Definition: pager.h:213
bool m_flushing_output_to_pager
Definition: pager.h:301
~output_system(void)=default
oprocstream * m_external_pager
Definition: pager.h:273
std::string PAGER(const std::string &s)
Definition: pager.h:163
bool really_flush_to_pager(bool flag)
Definition: pager.h:225
bool sync(const char *msg, int len)
Definition: pager.cc:378
bool write_to_diary_file(void) const
Definition: pager.h:208
void start_external_pager(void)
Definition: pager.cc:422
void clear_external_pager(void)
Definition: pager.cc:409
std::string pager_command(void) const
Definition: pager.cc:305
bool flushing_output_to_pager(void) const
Definition: pager.h:232
bool m_page_screen_output
Definition: pager.h:294
diary_stream & diary(void)
Definition: pager.h:148
void flush_stdout(void)
Definition: pager.cc:323
output_system(interpreter &interp)
Definition: pager.cc:267
std::string m_PAGER_FLAGS
Definition: pager.h:285
bool page_output_immediately(void) const
Definition: pager.h:184
std::string diary_file_name(const std::string &nm)
Definition: pager.h:152
bool m_really_flush_to_pager
Definition: pager.h:299
std::string m_diary_file_name
Definition: pager.h:279
pager_stream & pager(void)
Definition: pager.h:146
bool m_page_output_immediately
Definition: pager.h:290
std::string PAGER_FLAGS(const std::string &s)
Definition: pager.h:174
void do_sync(const char *msg, int len, bool bypass_pager)
Definition: pager.cc:440
std::ofstream m_external_diary_file
Definition: pager.h:276
bool page_screen_output(bool flag)
Definition: pager.h:201
std::size_t m_diary_skip
Definition: pager.h:62
pager_buf(void)
Definition: pager.h:50
pager_stream(const pager_stream &)=delete
std::ostream & stream(void)
Definition: pager.cc:199
pager_buf * m_pb
Definition: pager.h:91
std::ofstream ofstream(const std::string &filename, const std::ios::openmode mode)
Definition: lo-sysdep.cc:414
STL namespace.
OCTINTERP_API std::ostream & __stdout__(void)
Definition: pager.cc:492
OCTINTERP_API std::ostream & __diary__(void)
Definition: pager.cc:499
OCTINTERP_API void flush_stdout(void)
Definition: pager.cc:260
F77_RET_T len
Definition: xerbla.cc:61