Mercurial > hg > octave-nkf
annotate src/pager.cc @ 11572:7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 19 Jan 2011 17:51:22 -0800 |
parents | e1851653d59c |
children | 12df7854fa7c |
rev | line source |
---|---|
1 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1993-2011 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" | |
2101 | 33 |
1 | 34 #include "procstream.h" |
35 | |
2492 | 36 #include <defaults.h> |
1352 | 37 #include "defun.h" |
38 #include "error.h" | |
2164 | 39 #include "gripes.h" |
2110 | 40 #include "input.h" |
1755 | 41 #include "oct-obj.h" |
1352 | 42 #include "pager.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 | |
314 octave_pager_stream& | |
315 octave_pager_stream::stream (void) | |
316 { | |
317 if (! instance) | |
318 instance = new octave_pager_stream (); | |
2926 | 319 |
2093 | 320 return *instance; |
321 } | |
322 | |
3477 | 323 void |
324 octave_pager_stream::flush_current_contents_to_diary (void) | |
325 { | |
326 if (pb) | |
327 pb->flush_current_contents_to_diary (); | |
328 } | |
329 | |
3756 | 330 void |
331 octave_pager_stream::set_diary_skip (void) | |
332 { | |
333 if (pb) | |
334 pb->set_diary_skip (); | |
335 } | |
336 | |
2093 | 337 octave_diary_stream *octave_diary_stream::instance = 0; |
338 | |
3775 | 339 octave_diary_stream::octave_diary_stream (void) : std::ostream (0), db (0) |
2093 | 340 { |
4051 | 341 db = new octave_diary_buf (); |
2093 | 342 rdbuf (db); |
343 setf (unitbuf); | |
344 } | |
345 | |
346 octave_diary_stream::~octave_diary_stream (void) | |
347 { | |
348 flush (); | |
349 delete db; | |
350 } | |
351 | |
352 octave_diary_stream& | |
353 octave_diary_stream::stream (void) | |
354 { | |
355 if (! instance) | |
356 instance = new octave_diary_stream (); | |
357 | |
358 return *instance; | |
1 | 359 } |
360 | |
361 void | |
2093 | 362 flush_octave_stdout (void) |
1 | 363 { |
2206 | 364 if (! flushing_output_to_pager) |
365 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
366 unwind_protect frame; |
2100 | 367 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
368 frame.protect_var (really_flush_to_pager); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
369 frame.protect_var (flushing_output_to_pager); |
2100 | 370 |
3018 | 371 really_flush_to_pager = true; |
372 flushing_output_to_pager = true; | |
2206 | 373 |
374 octave_stdout.flush (); | |
1 | 375 |
5142 | 376 clear_external_pager (); |
2206 | 377 } |
1 | 378 } |
379 | |
1965 | 380 static void |
2093 | 381 close_diary_file (void) |
1 | 382 { |
3477 | 383 // Try to flush the current buffer to the diary now, so that things |
384 // like | |
385 // | |
386 // function foo () | |
387 // diary on; | |
388 // ... | |
389 // diary off; | |
390 // endfunction | |
391 // | |
392 // will do the right thing. | |
393 | |
394 octave_stdout.flush_current_contents_to_diary (); | |
395 | |
2093 | 396 if (external_diary_file.is_open ()) |
1 | 397 { |
2093 | 398 octave_diary.flush (); |
399 external_diary_file.close (); | |
1 | 400 } |
401 } | |
402 | |
581 | 403 static void |
404 open_diary_file (void) | |
405 { | |
2093 | 406 close_diary_file (); |
581 | 407 |
3756 | 408 // If there is pending output in the pager buf, it should not go |
409 // into the diary file. | |
410 | |
411 octave_stdout.set_diary_skip (); | |
412 | |
3544 | 413 external_diary_file.open (diary_file.c_str (), std::ios::app); |
581 | 414 |
2093 | 415 if (! external_diary_file) |
416 error ("diary: can't open diary file `%s'", diary_file.c_str ()); | |
581 | 417 } |
418 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
7432
diff
changeset
|
419 DEFUN (diary, args, , |
3332 | 420 "-*- texinfo -*-\n\ |
11547 | 421 @deftypefn {Command} {} diary options\n\ |
9134
a3739e27b017
Update section 2.4 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
8950
diff
changeset
|
422 Record a list of all commands @emph{and} the output they produce, mixed\n\ |
3332 | 423 together just as you see them on your terminal. Valid options are:\n\ |
424 \n\ | |
425 @table @code\n\ | |
426 @item on\n\ | |
427 Start recording your session in a file called @file{diary} in your\n\ | |
428 current working directory.\n\ | |
581 | 429 \n\ |
3332 | 430 @item off\n\ |
431 Stop recording your session in the diary file.\n\ | |
432 \n\ | |
433 @item @var{file}\n\ | |
434 Record your session in the file named @var{file}.\n\ | |
435 @end table\n\ | |
436 \n\ | |
9134
a3739e27b017
Update section 2.4 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
8950
diff
changeset
|
437 With no arguments, @code{diary} toggles the current diary state.\n\ |
11547 | 438 @end deftypefn") |
581 | 439 { |
2086 | 440 octave_value_list retval; |
581 | 441 |
1755 | 442 int argc = args.length () + 1; |
443 | |
1965 | 444 string_vector argv = args.make_argv ("diary"); |
581 | 445 |
1755 | 446 if (error_state) |
447 return retval; | |
448 | |
449 if (diary_file.empty ()) | |
450 diary_file = "diary"; | |
1306 | 451 |
581 | 452 switch (argc) |
453 { | |
454 case 1: | |
455 write_to_diary_file = ! write_to_diary_file; | |
456 open_diary_file (); | |
457 break; | |
623 | 458 |
581 | 459 case 2: |
460 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
461 std::string arg = argv[1]; |
1755 | 462 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
463 if (arg == "on") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
464 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
465 write_to_diary_file = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
466 open_diary_file (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
467 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
468 else if (arg == "off") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
469 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
470 close_diary_file (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
471 write_to_diary_file = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
472 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
473 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
474 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
475 diary_file = arg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
476 write_to_diary_file = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
477 open_diary_file (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
478 } |
581 | 479 } |
480 break; | |
777 | 481 |
581 | 482 default: |
5823 | 483 print_usage (); |
581 | 484 break; |
485 } | |
486 | |
487 return retval; | |
488 } | |
489 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
7432
diff
changeset
|
490 DEFUN (more, args, , |
3372 | 491 "-*- texinfo -*-\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
492 @deftypefn {Command} {} more\n\ |
11547 | 493 @deftypefnx {Command} {} more on\n\ |
494 @deftypefnx {Command} {} more off\n\ | |
3372 | 495 Turn output pagination on or off. Without an argument, @code{more}\n\ |
496 toggles the current state.\n\ | |
7432 | 497 The current state can be determined via @code{page_screen_output}.\n\ |
11547 | 498 @end deftypefn") |
1409 | 499 { |
2086 | 500 octave_value_list retval; |
1409 | 501 |
1755 | 502 int argc = args.length () + 1; |
503 | |
1965 | 504 string_vector argv = args.make_argv ("more"); |
1755 | 505 |
506 if (error_state) | |
507 return retval; | |
1409 | 508 |
509 if (argc == 2) | |
510 { | |
3523 | 511 std::string arg = argv[1]; |
1409 | 512 |
1755 | 513 if (arg == "on") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
514 Vpage_screen_output = true; |
1755 | 515 else if (arg == "off") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
516 Vpage_screen_output = false; |
1409 | 517 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 error ("more: unrecognized argument `%s'", arg.c_str ()); |
1409 | 519 } |
4324 | 520 else if (argc == 1) |
5794 | 521 Vpage_screen_output = ! Vpage_screen_output; |
1409 | 522 else |
5823 | 523 print_usage (); |
1409 | 524 |
525 return retval; | |
526 } | |
527 | |
5673 | 528 DEFUN (terminal_size, , , |
529 "-*- texinfo -*-\n\ | |
530 @deftypefn {Built-in Function} {} terminal_size ()\n\ | |
531 Return a two-element row vector containing the current size of the\n\ | |
532 terminal window in characters (rows and columns).\n\ | |
5778 | 533 @seealso{list_in_columns}\n\ |
5673 | 534 @end deftypefn") |
535 { | |
536 RowVector size (2, 0.0); | |
537 | |
538 size(0) = command_editor::terminal_rows (); | |
539 size(1) = command_editor::terminal_cols (); | |
540 | |
541 return octave_value (size); | |
542 } | |
543 | |
5794 | 544 DEFUN (page_output_immediately, args, nargout, |
545 "-*- texinfo -*-\n\ | |
10840 | 546 @deftypefn {Built-in Function} {@var{val} =} page_output_immediately ()\n\ |
5794 | 547 @deftypefnx {Built-in Function} {@var{val} =} page_output_immediately (@var{new_val})\n\ |
548 Query or set the internal variable that controls whether Octave sends\n\ | |
549 output to the pager as soon as it is available. Otherwise, Octave\n\ | |
550 buffers its output and waits until just before the prompt is printed to\n\ | |
551 flush it to the pager.\n\ | |
552 @end deftypefn") | |
2097 | 553 { |
5794 | 554 return SET_INTERNAL_VARIABLE (page_output_immediately); |
2164 | 555 } |
556 | |
5794 | 557 DEFUN (page_screen_output, args, nargout, |
558 "-*- texinfo -*-\n\ | |
10840 | 559 @deftypefn {Built-in Function} {@var{val} =} page_screen_output ()\n\ |
5794 | 560 @deftypefnx {Built-in Function} {@var{old_val} =} page_screen_output (@var{new_val})\n\ |
561 Query or set the internal variable that controls whether output intended\n\ | |
562 for the terminal window that is longer than one page is sent through a\n\ | |
563 pager. This allows you to view one screenful at a time. Some pagers\n\ | |
564 (such as @code{less}---see @ref{Installation}) are also capable of moving\n\ | |
565 backward on the output.\n\ | |
566 @end deftypefn") | |
2164 | 567 { |
5794 | 568 return SET_INTERNAL_VARIABLE (page_screen_output); |
2164 | 569 } |
570 | |
5794 | 571 DEFUN (PAGER, args, nargout, |
572 "-*- texinfo -*-\n\ | |
10840 | 573 @deftypefn {Built-in Function} {@var{val} =} PAGER ()\n\ |
5794 | 574 @deftypefnx {Built-in Function} {@var{old_val} =} PAGER (@var{new_val})\n\ |
575 Query or set the internal variable that specifies the program to use\n\ | |
576 to display terminal output on your system. The default value is\n\ | |
577 normally @code{\"less\"}, @code{\"more\"}, or\n\ | |
3372 | 578 @code{\"pg\"}, depending on what programs are installed on your system.\n\ |
579 @xref{Installation}.\n\ | |
6144 | 580 @seealso{more, page_screen_output, page_output_immediately, PAGER_FLAGS}\n\ |
5794 | 581 @end deftypefn") |
582 { | |
583 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (PAGER); | |
2097 | 584 } |
585 | |
6144 | 586 DEFUN (PAGER_FLAGS, args, nargout, |
587 "-*- texinfo -*-\n\ | |
10840 | 588 @deftypefn {Built-in Function} {@var{val} =} PAGER_FLAGS ()\n\ |
6144 | 589 @deftypefnx {Built-in Function} {@var{old_val} =} PAGER_FLAGS (@var{new_val})\n\ |
590 Query or set the internal variable that specifies the options to pass\n\ | |
591 to the pager.\n\ | |
592 @seealso{PAGER}\n\ | |
593 @end deftypefn") | |
594 { | |
595 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (PAGER_FLAGS); | |
596 } |