Mercurial > hg > octave-nkf
annotate src/pager.cc @ 15077:f0b04a20d7cf
initialize randn state in splinefit test
* splinefit.m: Initialize randn state to make test reproducible.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 01 Aug 2012 12:10:26 -0400 |
parents | bf219932bf3e |
children |
rev | line source |
---|---|
1 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14045
diff
changeset
|
3 Copyright (C) 1993-2012 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
240 | 23 #ifdef HAVE_CONFIG_H |
1192 | 24 #include <config.h> |
1 | 25 #endif |
26 | |
3503 | 27 #include <fstream> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
28 #include <iostream> |
1755 | 29 #include <string> |
1 | 30 |
2926 | 31 #include "cmd-edit.h" |
32 #include "oct-env.h" | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
33 #include "singleton-cleanup.h" |
2101 | 34 |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
35 #include "defaults.h" |
1352 | 36 #include "defun.h" |
37 #include "error.h" | |
2164 | 38 #include "gripes.h" |
2110 | 39 #include "input.h" |
1755 | 40 #include "oct-obj.h" |
1352 | 41 #include "pager.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
42 #include "procstream.h" |
990 | 43 #include "sighandlers.h" |
2100 | 44 #include "unwind-prot.h" |
2201 | 45 #include "utils.h" |
2368 | 46 #include "variables.h" |
2093 | 47 |
48 // Our actual connection to the external pager. | |
49 static oprocstream *external_pager = 0; | |
1 | 50 |
3018 | 51 // TRUE means we write to the diary file. |
52 static bool write_to_diary_file = false; | |
581 | 53 |
54 // The name of the current diary file. | |
3523 | 55 static std::string diary_file; |
581 | 56 |
57 // The diary file. | |
3523 | 58 static std::ofstream external_diary_file; |
581 | 59 |
5794 | 60 static std::string |
61 default_pager (void) | |
62 { | |
63 std::string pager_binary = octave_env::getenv ("PAGER"); | |
64 | |
65 #ifdef OCTAVE_DEFAULT_PAGER | |
66 if (pager_binary.empty ()) | |
6144 | 67 pager_binary = OCTAVE_DEFAULT_PAGER; |
5794 | 68 #endif |
69 | |
70 return pager_binary; | |
71 } | |
72 | |
2164 | 73 // The shell command to run as the pager. |
5794 | 74 static std::string VPAGER = default_pager (); |
2164 | 75 |
6144 | 76 // The options to pass to the pager. |
77 static std::string VPAGER_FLAGS; | |
78 | |
2164 | 79 // TRUE means that if output is going to the pager, it is sent as soon |
80 // as it is available. Otherwise, it is buffered and only sent to the | |
81 // pager when it is time to print another prompt. | |
5794 | 82 static bool Vpage_output_immediately = false; |
2164 | 83 |
84 // TRUE means all output intended for the screen should be passed | |
85 // through the pager. | |
5794 | 86 static bool Vpage_screen_output = true; |
2164 | 87 |
3018 | 88 static bool really_flush_to_pager = false; |
2100 | 89 |
3018 | 90 static bool flushing_output_to_pager = false; |
2206 | 91 |
2093 | 92 static void |
2197 | 93 clear_external_pager (void) |
94 { | |
5142 | 95 if (external_pager) |
96 { | |
97 octave_child_list::remove (external_pager->pid ()); | |
2197 | 98 |
5142 | 99 delete external_pager; |
100 external_pager = 0; | |
2197 | 101 } |
102 } | |
103 | |
5142 | 104 static bool |
105 pager_event_handler (pid_t pid, int status) | |
2209 | 106 { |
5142 | 107 bool retval = false; |
108 | |
2209 | 109 if (pid > 0) |
110 { | |
111 if (WIFEXITED (status) || WIFSIGNALLED (status)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
112 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
113 // Avoid warning() since that will put us back in the pager, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 // which would be bad news. |
2209 | 115 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
116 std::cerr << "warning: connection to external pager lost (pid = " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
117 << pid << ")" << std::endl; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
118 std::cerr << "warning: flushing pending output (please wait)" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 << std::endl; |
5142 | 120 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
121 // Request removal of this PID from the list of child |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 // processes. |
5142 | 123 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
124 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
125 } |
2209 | 126 } |
5142 | 127 |
128 return retval; | |
2209 | 129 } |
130 | |
6144 | 131 static std::string |
132 pager_command (void) | |
133 { | |
134 std::string cmd = VPAGER; | |
135 | |
136 if (! (cmd.empty () || VPAGER_FLAGS.empty ())) | |
137 cmd += " " + VPAGER_FLAGS; | |
138 | |
139 return cmd; | |
140 } | |
141 | |
2209 | 142 static void |
3233 | 143 do_sync (const char *msg, int len, bool bypass_pager) |
1 | 144 { |
3233 | 145 if (msg && len > 0) |
1 | 146 { |
2206 | 147 if (bypass_pager) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
148 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 std::cout.write (msg, len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
150 std::cout.flush (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 } |
2206 | 152 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
153 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
154 if (! external_pager) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
155 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
156 std::string pgr = pager_command (); |
2093 | 157 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
158 if (! pgr.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
159 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
160 external_pager = new oprocstream (pgr.c_str ()); |
2093 | 161 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
162 if (external_pager) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
163 octave_child_list::insert (external_pager->pid (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
164 pager_event_handler); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
165 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
166 } |
2101 | 167 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
168 if (external_pager) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
169 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 if (external_pager->good ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
171 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
172 external_pager->write (msg, len); |
2101 | 173 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 external_pager->flush (); |
2197 | 175 |
5142 | 176 #if defined (EPIPE) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
177 if (errno == EPIPE) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
178 external_pager->setstate (std::ios::failbit); |
5142 | 179 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
182 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
183 // FIXME -- omething is not right with the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
184 // pager. If it died then we should receive a |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
185 // signal for that. If there is some other problem, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
186 // then what? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
187 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
188 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
189 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
190 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
191 std::cout.write (msg, len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
192 std::cout.flush (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
193 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
194 } |
1 | 195 } |
196 } | |
197 | |
3233 | 198 // Assume our terminal wraps long lines. |
199 | |
2101 | 200 static bool |
3233 | 201 more_than_a_screenful (const char *s, int len) |
2101 | 202 { |
203 if (s) | |
204 { | |
2926 | 205 int available_rows = command_editor::terminal_rows () - 2; |
2101 | 206 |
3233 | 207 int cols = command_editor::terminal_cols (); |
208 | |
2103 | 209 int count = 0; |
210 | |
3233 | 211 int chars_this_line = 0; |
2101 | 212 |
3233 | 213 for (int i = 0; i < len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
214 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
215 if (*s++ == '\n') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
216 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
217 count += chars_this_line / cols + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
218 chars_this_line = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
219 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
220 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
221 chars_this_line++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
222 } |
2101 | 223 |
3233 | 224 if (count > available_rows) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
225 return true; |
2101 | 226 } |
227 | |
228 return false; | |
229 } | |
230 | |
2093 | 231 int |
232 octave_pager_buf::sync (void) | |
233 { | |
2186 | 234 if (! interactive |
235 || really_flush_to_pager | |
2164 | 236 || (Vpage_screen_output && Vpage_output_immediately) |
237 || ! Vpage_screen_output) | |
2100 | 238 { |
3233 | 239 char *buf = eback (); |
2093 | 240 |
3233 | 241 int len = pptr () - buf; |
2100 | 242 |
2110 | 243 bool bypass_pager = (! interactive |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 || ! Vpage_screen_output |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
245 || (really_flush_to_pager |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
246 && Vpage_screen_output |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 && ! Vpage_output_immediately |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
248 && ! more_than_a_screenful (buf, len))); |
2475 | 249 |
3233 | 250 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
251 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
252 do_sync (buf, len, bypass_pager); |
2093 | 253 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
254 flush_current_contents_to_diary (); |
3233 | 255 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
256 seekoff (0, std::ios::beg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
257 } |
2100 | 258 } |
2093 | 259 |
260 return 0; | |
261 } | |
262 | |
3477 | 263 void |
264 octave_pager_buf::flush_current_contents_to_diary (void) | |
265 { | |
3756 | 266 char *buf = eback () + diary_skip; |
3477 | 267 |
3756 | 268 size_t len = pptr () - buf; |
3477 | 269 |
270 octave_diary.write (buf, len); | |
3756 | 271 |
3870 | 272 diary_skip = 0; |
3756 | 273 } |
274 | |
275 void | |
276 octave_pager_buf::set_diary_skip (void) | |
277 { | |
278 diary_skip = pptr () - eback (); | |
3477 | 279 } |
280 | |
2093 | 281 int |
282 octave_diary_buf::sync (void) | |
283 { | |
3233 | 284 if (write_to_diary_file && external_diary_file) |
285 { | |
3870 | 286 char *buf = eback (); |
287 | |
288 int len = pptr () - buf; | |
2093 | 289 |
3233 | 290 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
291 external_diary_file.write (buf, len); |
3233 | 292 } |
2093 | 293 |
3544 | 294 seekoff (0, std::ios::beg); |
2093 | 295 |
296 return 0; | |
297 } | |
298 | |
299 octave_pager_stream *octave_pager_stream::instance = 0; | |
300 | |
3775 | 301 octave_pager_stream::octave_pager_stream (void) : std::ostream (0), pb (0) |
1 | 302 { |
4051 | 303 pb = new octave_pager_buf (); |
2093 | 304 rdbuf (pb); |
305 setf (unitbuf); | |
306 } | |
307 | |
308 octave_pager_stream::~octave_pager_stream (void) | |
309 { | |
310 flush (); | |
311 delete pb; | |
312 } | |
313 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
314 std::ostream& |
2093 | 315 octave_pager_stream::stream (void) |
316 { | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
317 return instance_ok () ? *instance : std::cout; |
2093 | 318 } |
319 | |
3477 | 320 void |
321 octave_pager_stream::flush_current_contents_to_diary (void) | |
322 { | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
323 if (instance_ok ()) |
14044
c15ddadffbfb
Fix segfault in diary class (Bug #35065)
Rik <octave@nomad.inbox5.com>
parents:
13983
diff
changeset
|
324 instance->do_flush_current_contents_to_diary (); |
3477 | 325 } |
326 | |
3756 | 327 void |
328 octave_pager_stream::set_diary_skip (void) | |
329 { | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
330 if (instance_ok ()) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
331 instance->do_set_diary_skip (); |
3756 | 332 } |
333 | |
13266
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
334 // Reinitialize the pager buffer to avoid hanging on to large internal |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
335 // buffers when they might not be needed. This function should only be |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
336 // called when the pager is not in use. For example, just before |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
337 // getting command-line input. |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
338 |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
339 void |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
340 octave_pager_stream::reset (void) |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
341 { |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
342 if (instance_ok ()) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
343 instance->do_reset (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
344 } |
13266
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
345 |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
346 void |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
347 octave_pager_stream::do_flush_current_contents_to_diary (void) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
348 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
349 if (pb) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
350 pb->flush_current_contents_to_diary (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
351 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
352 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
353 void |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
354 octave_pager_stream::do_set_diary_skip (void) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
355 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
356 if (pb) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
357 pb->set_diary_skip (); |
13266
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
358 } |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
359 |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
360 void |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
361 octave_pager_stream::do_reset (void) |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
362 { |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
363 delete pb; |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
364 pb = new octave_pager_buf (); |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
365 rdbuf (pb); |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
366 setf (unitbuf); |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
367 } |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
368 |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
369 bool |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
370 octave_pager_stream::instance_ok (void) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
371 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
372 bool retval = true; |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
373 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
374 if (! instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
375 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
376 instance = new octave_pager_stream (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
377 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
378 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
379 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
380 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
381 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
382 if (! instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
383 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
384 ::error ("unable to create pager_stream object!"); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
385 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
386 retval = false; |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
387 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
388 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
389 return retval; |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
390 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
391 |
2093 | 392 octave_diary_stream *octave_diary_stream::instance = 0; |
393 | |
3775 | 394 octave_diary_stream::octave_diary_stream (void) : std::ostream (0), db (0) |
2093 | 395 { |
4051 | 396 db = new octave_diary_buf (); |
2093 | 397 rdbuf (db); |
398 setf (unitbuf); | |
399 } | |
400 | |
401 octave_diary_stream::~octave_diary_stream (void) | |
402 { | |
403 flush (); | |
404 delete db; | |
405 } | |
406 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
407 std::ostream& |
2093 | 408 octave_diary_stream::stream (void) |
409 { | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
410 return instance_ok () ? *instance : std::cout; |
1 | 411 } |
412 | |
13266
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
413 // Reinitialize the diary buffer to avoid hanging on to large internal |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
414 // buffers when they might not be needed. This function should only be |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
415 // called when the pager is not in use. For example, just before |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
416 // getting command-line input. |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
417 |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
418 void |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
419 octave_diary_stream::reset (void) |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
420 { |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
421 if (instance_ok ()) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
422 instance->do_reset (); |
13266
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
423 } |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
424 |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
425 void |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
426 octave_diary_stream::do_reset (void) |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
427 { |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
428 delete db; |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
429 db = new octave_diary_buf (); |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
430 rdbuf (db); |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
431 setf (unitbuf); |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
432 } |
c053740eb2aa
improve memory use for the pager and diary streams (bug #34431)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
433 |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
434 bool |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
435 octave_diary_stream::instance_ok (void) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
436 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
437 bool retval = true; |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
438 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
439 if (! instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
440 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
441 instance = new octave_diary_stream (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
442 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
443 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
444 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
445 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
446 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
447 if (! instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
448 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
449 ::error ("unable to create diary_stream object!"); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
450 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
451 retval = false; |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
452 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
453 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
454 return retval; |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
455 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
456 |
1 | 457 void |
2093 | 458 flush_octave_stdout (void) |
1 | 459 { |
2206 | 460 if (! flushing_output_to_pager) |
461 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
462 unwind_protect frame; |
2100 | 463 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
464 frame.protect_var (really_flush_to_pager); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
465 frame.protect_var (flushing_output_to_pager); |
2100 | 466 |
3018 | 467 really_flush_to_pager = true; |
468 flushing_output_to_pager = true; | |
2206 | 469 |
470 octave_stdout.flush (); | |
1 | 471 |
5142 | 472 clear_external_pager (); |
2206 | 473 } |
1 | 474 } |
475 | |
1965 | 476 static void |
2093 | 477 close_diary_file (void) |
1 | 478 { |
3477 | 479 // Try to flush the current buffer to the diary now, so that things |
480 // like | |
481 // | |
482 // function foo () | |
483 // diary on; | |
484 // ... | |
485 // diary off; | |
486 // endfunction | |
487 // | |
488 // will do the right thing. | |
489 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
490 octave_pager_stream::flush_current_contents_to_diary (); |
3477 | 491 |
2093 | 492 if (external_diary_file.is_open ()) |
1 | 493 { |
2093 | 494 octave_diary.flush (); |
495 external_diary_file.close (); | |
1 | 496 } |
497 } | |
498 | |
581 | 499 static void |
500 open_diary_file (void) | |
501 { | |
2093 | 502 close_diary_file (); |
581 | 503 |
3756 | 504 // If there is pending output in the pager buf, it should not go |
505 // into the diary file. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
506 |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
507 octave_pager_stream::set_diary_skip (); |
3756 | 508 |
3544 | 509 external_diary_file.open (diary_file.c_str (), std::ios::app); |
581 | 510 |
2093 | 511 if (! external_diary_file) |
512 error ("diary: can't open diary file `%s'", diary_file.c_str ()); | |
581 | 513 } |
514 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
7432
diff
changeset
|
515 DEFUN (diary, args, , |
3332 | 516 "-*- texinfo -*-\n\ |
11547 | 517 @deftypefn {Command} {} diary options\n\ |
9134
a3739e27b017
Update section 2.4 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
8950
diff
changeset
|
518 Record a list of all commands @emph{and} the output they produce, mixed\n\ |
3332 | 519 together just as you see them on your terminal. Valid options are:\n\ |
520 \n\ | |
521 @table @code\n\ | |
522 @item on\n\ | |
523 Start recording your session in a file called @file{diary} in your\n\ | |
524 current working directory.\n\ | |
581 | 525 \n\ |
3332 | 526 @item off\n\ |
527 Stop recording your session in the diary file.\n\ | |
528 \n\ | |
529 @item @var{file}\n\ | |
530 Record your session in the file named @var{file}.\n\ | |
531 @end table\n\ | |
532 \n\ | |
9134
a3739e27b017
Update section 2.4 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
8950
diff
changeset
|
533 With no arguments, @code{diary} toggles the current diary state.\n\ |
11547 | 534 @end deftypefn") |
581 | 535 { |
2086 | 536 octave_value_list retval; |
581 | 537 |
1755 | 538 int argc = args.length () + 1; |
539 | |
1965 | 540 string_vector argv = args.make_argv ("diary"); |
581 | 541 |
1755 | 542 if (error_state) |
543 return retval; | |
544 | |
545 if (diary_file.empty ()) | |
546 diary_file = "diary"; | |
1306 | 547 |
581 | 548 switch (argc) |
549 { | |
550 case 1: | |
551 write_to_diary_file = ! write_to_diary_file; | |
552 open_diary_file (); | |
553 break; | |
623 | 554 |
581 | 555 case 2: |
556 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
557 std::string arg = argv[1]; |
1755 | 558 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
559 if (arg == "on") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
560 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
561 write_to_diary_file = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
562 open_diary_file (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
563 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
564 else if (arg == "off") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
565 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
566 close_diary_file (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
567 write_to_diary_file = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
568 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
569 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
570 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
571 diary_file = arg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
572 write_to_diary_file = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
573 open_diary_file (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
574 } |
581 | 575 } |
576 break; | |
777 | 577 |
581 | 578 default: |
5823 | 579 print_usage (); |
581 | 580 break; |
581 } | |
582 | |
583 return retval; | |
584 } | |
585 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
7432
diff
changeset
|
586 DEFUN (more, args, , |
3372 | 587 "-*- texinfo -*-\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
588 @deftypefn {Command} {} more\n\ |
11547 | 589 @deftypefnx {Command} {} more on\n\ |
590 @deftypefnx {Command} {} more off\n\ | |
3372 | 591 Turn output pagination on or off. Without an argument, @code{more}\n\ |
592 toggles the current state.\n\ | |
7432 | 593 The current state can be determined via @code{page_screen_output}.\n\ |
14542
bf219932bf3e
doc: Increase seealso references between paging functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
594 @seealso{page_screen_output, page_output_immediately, PAGER, PAGER_FLAGS}\n\ |
11547 | 595 @end deftypefn") |
1409 | 596 { |
2086 | 597 octave_value_list retval; |
1409 | 598 |
1755 | 599 int argc = args.length () + 1; |
600 | |
1965 | 601 string_vector argv = args.make_argv ("more"); |
1755 | 602 |
603 if (error_state) | |
604 return retval; | |
1409 | 605 |
606 if (argc == 2) | |
607 { | |
3523 | 608 std::string arg = argv[1]; |
1409 | 609 |
1755 | 610 if (arg == "on") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
611 Vpage_screen_output = true; |
1755 | 612 else if (arg == "off") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
613 Vpage_screen_output = false; |
1409 | 614 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
615 error ("more: unrecognized argument `%s'", arg.c_str ()); |
1409 | 616 } |
4324 | 617 else if (argc == 1) |
5794 | 618 Vpage_screen_output = ! Vpage_screen_output; |
1409 | 619 else |
5823 | 620 print_usage (); |
1409 | 621 |
622 return retval; | |
623 } | |
624 | |
5673 | 625 DEFUN (terminal_size, , , |
626 "-*- texinfo -*-\n\ | |
627 @deftypefn {Built-in Function} {} terminal_size ()\n\ | |
628 Return a two-element row vector containing the current size of the\n\ | |
629 terminal window in characters (rows and columns).\n\ | |
5778 | 630 @seealso{list_in_columns}\n\ |
5673 | 631 @end deftypefn") |
632 { | |
633 RowVector size (2, 0.0); | |
634 | |
635 size(0) = command_editor::terminal_rows (); | |
636 size(1) = command_editor::terminal_cols (); | |
637 | |
638 return octave_value (size); | |
639 } | |
640 | |
5794 | 641 DEFUN (page_output_immediately, args, nargout, |
642 "-*- texinfo -*-\n\ | |
10840 | 643 @deftypefn {Built-in Function} {@var{val} =} page_output_immediately ()\n\ |
14045
db264e617a98
Make page_output_immediately documentation consistent with other internal variables.
Rik <octave@nomad.inbox5.com>
parents:
14044
diff
changeset
|
644 @deftypefnx {Built-in Function} {@var{old_val} =} page_output_immediately (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
645 @deftypefnx {Built-in Function} {} page_output_immediately (@var{new_val}, \"local\")\n\ |
5794 | 646 Query or set the internal variable that controls whether Octave sends\n\ |
647 output to the pager as soon as it is available. Otherwise, Octave\n\ | |
648 buffers its output and waits until just before the prompt is printed to\n\ | |
649 flush it to the pager.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
650 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
651 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
652 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
653 variable value is restored when exiting the function.\n\ |
14542
bf219932bf3e
doc: Increase seealso references between paging functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
654 @seealso{page_screen_output, more, PAGER, PAGER_FLAGS}\n\ |
5794 | 655 @end deftypefn") |
2097 | 656 { |
5794 | 657 return SET_INTERNAL_VARIABLE (page_output_immediately); |
2164 | 658 } |
659 | |
5794 | 660 DEFUN (page_screen_output, args, nargout, |
661 "-*- texinfo -*-\n\ | |
10840 | 662 @deftypefn {Built-in Function} {@var{val} =} page_screen_output ()\n\ |
5794 | 663 @deftypefnx {Built-in Function} {@var{old_val} =} page_screen_output (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
664 @deftypefnx {Built-in Function} {} page_screen_output (@var{new_val}, \"local\")\n\ |
5794 | 665 Query or set the internal variable that controls whether output intended\n\ |
666 for the terminal window that is longer than one page is sent through a\n\ | |
667 pager. This allows you to view one screenful at a time. Some pagers\n\ | |
668 (such as @code{less}---see @ref{Installation}) are also capable of moving\n\ | |
669 backward on the output.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
670 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
671 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
672 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
673 variable value is restored when exiting the function.\n\ |
14542
bf219932bf3e
doc: Increase seealso references between paging functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
674 @seealso{more, page_output_immediately, PAGER, PAGER_FLAGS}\n\ |
5794 | 675 @end deftypefn") |
2164 | 676 { |
5794 | 677 return SET_INTERNAL_VARIABLE (page_screen_output); |
2164 | 678 } |
679 | |
5794 | 680 DEFUN (PAGER, args, nargout, |
681 "-*- texinfo -*-\n\ | |
10840 | 682 @deftypefn {Built-in Function} {@var{val} =} PAGER ()\n\ |
5794 | 683 @deftypefnx {Built-in Function} {@var{old_val} =} PAGER (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
684 @deftypefnx {Built-in Function} {} PAGER (@var{new_val}, \"local\")\n\ |
5794 | 685 Query or set the internal variable that specifies the program to use\n\ |
686 to display terminal output on your system. The default value is\n\ | |
687 normally @code{\"less\"}, @code{\"more\"}, or\n\ | |
3372 | 688 @code{\"pg\"}, depending on what programs are installed on your system.\n\ |
689 @xref{Installation}.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
690 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
691 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
692 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
693 variable value is restored when exiting the function.\n\ |
14542
bf219932bf3e
doc: Increase seealso references between paging functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
694 @seealso{PAGER_FLAGS, page_output_immediately, more, page_screen_output}\n\ |
5794 | 695 @end deftypefn") |
696 { | |
697 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (PAGER); | |
2097 | 698 } |
699 | |
6144 | 700 DEFUN (PAGER_FLAGS, args, nargout, |
701 "-*- texinfo -*-\n\ | |
10840 | 702 @deftypefn {Built-in Function} {@var{val} =} PAGER_FLAGS ()\n\ |
6144 | 703 @deftypefnx {Built-in Function} {@var{old_val} =} PAGER_FLAGS (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
704 @deftypefnx {Built-in Function} {} PAGER_FLAGS (@var{new_val}, \"local\")\n\ |
6144 | 705 Query or set the internal variable that specifies the options to pass\n\ |
706 to the pager.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
707 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
708 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
709 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13266
diff
changeset
|
710 variable value is restored when exiting the function.\n\ |
14542
bf219932bf3e
doc: Increase seealso references between paging functions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
711 @seealso{PAGER, more, page_screen_output, page_output_immediately}\n\ |
6144 | 712 @end deftypefn") |
713 { | |
714 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (PAGER_FLAGS); | |
715 } |