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