GNU Octave  6.2.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-2021 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 
36 class octave_value;
37 class octave_value_list;
38 class oprocstream;
39 
40 namespace octave
41 {
42  class interpreter;
43 
44  class
45  OCTINTERP_API
46  pager_buf : public std::stringbuf
47  {
48  public:
49 
50  pager_buf (void) : std::stringbuf (), 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  size_t 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 
77  pager_stream& operator = (const pager_stream&) = delete;
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 
119  diary_stream& operator = (const diary_stream&) = delete;
120 
121  ~diary_stream (void);
122 
123  std::ostream& stream (void);
124 
125  void reset (void);
126 
127  private:
128 
130  };
131 
132  extern OCTAVE_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 
146  pager_stream& pager (void) { return m_pager_stream; }
147 
148  diary_stream& diary (void) { return m_diary_stream; }
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;
204  m_page_screen_output = flag;
205  return val;
206  }
207 
208  bool write_to_diary_file (void) const
209  {
210  return m_write_to_diary_file;
211  }
212 
213  bool write_to_diary_file (bool flag)
214  {
215  bool val = m_write_to_diary_file;
216  m_write_to_diary_file = flag;
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 
237  bool flushing_output_to_pager (bool flag)
238  {
239  bool val = m_flushing_output_to_pager;
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 std::ostream& __stdout__ (void);
309 
310  extern std::ostream& __diary__ (void);
311 }
312 
313 #define octave_stdout (octave::__stdout__ ())
314 
315 #define octave_diary (octave::__diary__ ())
316 
317 #endif
diary_buf(void)
Definition: pager.h:100
std::ostream & stream(void)
Definition: pager.cc:242
diary_stream(const diary_stream &)=delete
diary_buf * db
Definition: pager.h:129
bool page_output_immediately(void) const
Definition: pager.h:184
bool page_screen_output(void) const
Definition: pager.h:199
std::string PAGER_FLAGS(void) const
Definition: pager.h:172
bool m_flushing_output_to_pager
Definition: pager.h:301
bool sync(const char *msg, int len)
Definition: pager.cc:380
bool write_to_diary_file(void) const
Definition: pager.h:208
diary_stream m_diary_stream
Definition: pager.h:270
pager_stream & pager(void)
Definition: pager.h:146
output_system(interpreter &interp)
Definition: pager.cc:267
output_system & operator=(const output_system &)=delete
void flush_stdout(void)
Definition: pager.cc:323
diary_stream & diary(void)
Definition: pager.h:148
std::string pager_command(void) const
Definition: pager.cc:305
bool m_page_output_immediately
Definition: pager.h:290
void reset(void)
Definition: pager.cc:315
oprocstream * m_external_pager
Definition: pager.h:273
void clear_external_pager(void)
Definition: pager.cc:407
std::string diary_file_name(const std::string &nm)
Definition: pager.h:152
~output_system(void)=default
std::string m_PAGER_FLAGS
Definition: pager.h:285
interpreter & m_interpreter
Definition: pager.h:266
pager_stream m_pager_stream
Definition: pager.h:268
bool really_flush_to_pager(bool flag)
Definition: pager.h:225
void close_diary(void)
Definition: pager.cc:343
std::ostream & __stdout__(void)
Definition: pager.h:260
std::string m_diary_file_name
Definition: pager.h:279
bool page_output_immediately(bool flag)
Definition: pager.h:189
std::string diary_file_name(void) const
Definition: pager.h:150
bool page_screen_output(bool flag)
Definition: pager.h:201
bool flushing_output_to_pager(bool flag)
Definition: pager.h:237
void open_diary(void)
Definition: pager.cc:365
output_system(const output_system &)=delete
bool m_write_to_diary_file
Definition: pager.h:297
bool flushing_output_to_pager(void) const
Definition: pager.h:232
bool really_flush_to_pager(void) const
Definition: pager.h:220
void start_external_pager(void)
Definition: pager.cc:420
std::ofstream & external_diary_file(void)
Definition: pager.h:246
bool m_really_flush_to_pager
Definition: pager.h:299
std::string m_PAGER
Definition: pager.h:282
std::string PAGER(const std::string &s)
Definition: pager.h:163
bool write_to_diary_file(bool flag)
Definition: pager.h:213
std::string PAGER_FLAGS(const std::string &s)
Definition: pager.h:174
std::ostream & __diary__(void)
Definition: pager.h:262
void do_sync(const char *msg, int len, bool bypass_pager)
Definition: pager.cc:438
bool m_page_screen_output
Definition: pager.h:294
std::ofstream m_external_diary_file
Definition: pager.h:276
std::string PAGER(void) const
Definition: pager.h:161
size_t diary_skip
Definition: pager.h:62
pager_buf(void)
Definition: pager.h:50
std::ostream & stream(void)
Definition: pager.cc:199
pager_stream(const pager_stream &)=delete
pager_buf * pb
Definition: pager.h:91
std::ofstream ofstream(const std::string &filename, const std::ios::openmode mode)
Definition: lo-sysdep.cc:395
std::ostream & __stdout__(void)
Definition: pager.cc:481
void flush_stdout(void)
Definition: pager.cc:260
std::ostream & __diary__(void)
Definition: pager.cc:488
F77_RET_T len
Definition: xerbla.cc:61