annotate src/pager.cc @ 3018:5708b8bb4f06

[project @ 1997-06-03 21:48:05 by jwe]
author jwe
date Tue, 03 Jun 1997 21:57:33 +0000
parents 38de16594cb4
children fccab8e7d35f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2795
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
10 later version.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
1315
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1306
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 191
diff changeset
23 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1009
diff changeset
24 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1315
diff changeset
27 #include <csignal>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1315
diff changeset
28
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
29 #include <string>
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
30 #include <fstream.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
31
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
32 #include "cmd-edit.h"
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
33 #include "oct-env.h"
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
34
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
35 #include "procstream.h"
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2476
diff changeset
37 #include <defaults.h>
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1343
diff changeset
38 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1343
diff changeset
39 #include "error.h"
2164
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
40 #include "gripes.h"
2110
dece5cc39e00 [project @ 1996-04-30 12:38:20 by jwe]
jwe
parents: 2103
diff changeset
41 #include "input.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
42 #include "oct-obj.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1343
diff changeset
43 #include "pager.h"
990
d2dd114ba5dd [project @ 1994-12-15 05:58:17 by jwe]
jwe
parents: 988
diff changeset
44 #include "sighandlers.h"
2100
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
45 #include "unwind-prot.h"
2201
e5db2ea7f7c8 [project @ 1996-05-15 05:37:55 by jwe]
jwe
parents: 2200
diff changeset
46 #include "utils.h"
2368
bf6a96fd9b7e [project @ 1996-10-11 23:44:38 by jwe]
jwe
parents: 2210
diff changeset
47 #include "variables.h"
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
48
2209
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
49 static pid_t octave_pager_pid = -1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
50
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
51 // Our actual connection to the external pager.
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
52 static oprocstream *external_pager = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
53
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
54 // TRUE means we write to the diary file.
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
55 static bool write_to_diary_file = false;
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
56
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
57 // The name of the current diary file.
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
58 static string diary_file;
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
59
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
60 // The diary file.
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
61 static ofstream external_diary_file;
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
62
2164
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
63 // The shell command to run as the pager.
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
64 static string Vpager_binary;
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
65
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
66 // TRUE means that if output is going to the pager, it is sent as soon
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
67 // as it is available. Otherwise, it is buffered and only sent to the
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
68 // pager when it is time to print another prompt.
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
69 static bool Vpage_output_immediately;
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
70
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
71 // TRUE means all output intended for the screen should be passed
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
72 // through the pager.
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
73 static bool Vpage_screen_output;
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
74
2705
18395aaeafb7 [project @ 1997-02-20 04:56:43 by jwe]
jwe
parents: 2652
diff changeset
75 // Only one pager can be active at once, so having these at file
18395aaeafb7 [project @ 1997-02-20 04:56:43 by jwe]
jwe
parents: 2652
diff changeset
76 // scope should be ok.
18395aaeafb7 [project @ 1997-02-20 04:56:43 by jwe]
jwe
parents: 2652
diff changeset
77 static octave_interrupt_handler saved_interrupt_handler;
18395aaeafb7 [project @ 1997-02-20 04:56:43 by jwe]
jwe
parents: 2652
diff changeset
78 static bool interrupt_handler_saved = false;
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
79
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
80 static bool really_flush_to_pager = false;
2100
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
81
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
82 static bool flushing_output_to_pager = false;
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
83
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
84 static void
2197
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
85 clear_external_pager (void)
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
86 {
2210
a3e39f8efed2 [project @ 1996-05-15 12:55:55 by jwe]
jwe
parents: 2209
diff changeset
87 octave_child_list::remove (octave_pager_pid);
a3e39f8efed2 [project @ 1996-05-15 12:55:55 by jwe]
jwe
parents: 2209
diff changeset
88
2197
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
89 octave_pager_pid = -1;
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
90
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
91 delete external_pager;
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
92 external_pager = 0;
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
93
2705
18395aaeafb7 [project @ 1997-02-20 04:56:43 by jwe]
jwe
parents: 2652
diff changeset
94 if (interrupt_handler_saved)
2197
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
95 {
2554
f7e3d23f0a8f [project @ 1996-11-21 01:41:57 by jwe]
jwe
parents: 2492
diff changeset
96 octave_set_interrupt_handler (saved_interrupt_handler);
2705
18395aaeafb7 [project @ 1997-02-20 04:56:43 by jwe]
jwe
parents: 2652
diff changeset
97 interrupt_handler_saved = false;
2197
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
98 }
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
99 }
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
100
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
101 static void
2209
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
102 pager_death_handler (pid_t pid, int status)
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
103 {
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
104 if (pid > 0)
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
105 {
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
106 if (WIFEXITED (status) || WIFSIGNALLED (status))
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
107 {
2795
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
108 // Avoid warning() or error(), since that will put us back in
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
109 // the pager, which would be bad news.
2209
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
110
2795
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
111 cerr << "warning: connection to external pager (pid = "
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
112 << pid << ") lost --\n"
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
113 << "warning: attempting to finish pending computations...\n";
2209
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
114 }
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
115 }
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
116 }
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
117
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
118 static void
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
119 do_sync (const char *msg, bool bypass_pager)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
120 {
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
121 if (msg && *msg)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
122 {
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
123 if (bypass_pager)
2646
5adf5280858c [project @ 1997-01-29 18:59:41 by jwe]
jwe
parents: 2554
diff changeset
124 {
5adf5280858c [project @ 1997-01-29 18:59:41 by jwe]
jwe
parents: 2554
diff changeset
125 cout << msg;
2652
69613a17f51a [project @ 1997-01-31 20:30:22 by jwe]
jwe
parents: 2646
diff changeset
126 cout.flush ();
2646
5adf5280858c [project @ 1997-01-29 18:59:41 by jwe]
jwe
parents: 2554
diff changeset
127 }
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
128 else
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
129 {
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
130 if (! external_pager)
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
131 {
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
132 string pgr = Vpager_binary;
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
133
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
134 if (! pgr.empty ())
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
135 {
2554
f7e3d23f0a8f [project @ 1996-11-21 01:41:57 by jwe]
jwe
parents: 2492
diff changeset
136 saved_interrupt_handler = octave_ignore_interrupts ();
2705
18395aaeafb7 [project @ 1997-02-20 04:56:43 by jwe]
jwe
parents: 2652
diff changeset
137 interrupt_handler_saved = true;
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
138
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
139 external_pager = new oprocstream (pgr.c_str ());
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
140
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
141 if (external_pager)
2209
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
142 {
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
143 octave_pager_pid = external_pager->pid ();
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
144
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
145 octave_child_list::insert (octave_pager_pid,
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
146 pager_death_handler);
859030f15706 [project @ 1996-05-15 11:46:43 by jwe]
jwe
parents: 2206
diff changeset
147 }
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
148 }
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
149 }
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
150
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
151 if (external_pager)
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
152 {
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
153 if (octave_pager_pid > 0 && external_pager->good ())
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
154 {
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
155 *external_pager << msg;
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
156
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
157 // These checks are needed if a signal handler
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
158 // invoked since the last set of checks attempts
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
159 // to flush output and then returns
2197
680ce730f0c6 [project @ 1996-05-15 00:03:19 by jwe]
jwe
parents: 2186
diff changeset
160
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
161 if (octave_pager_pid > 0
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
162 && external_pager
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
163 && external_pager->good ())
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
164 external_pager->flush ();
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
165 }
2795
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
166 else
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
167 {
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
168 // We had a pager, but it must have died. Restore
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
169 // the interrupt state so we can escape back to the
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
170 // prompt if there are lots of computations pending.
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
171
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
172 if (interrupt_handler_saved)
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
173 {
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
174 octave_set_interrupt_handler (saved_interrupt_handler);
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
175 interrupt_handler_saved = false;
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
176 }
14d07e4a0265 [project @ 1997-03-07 02:18:49 by jwe]
jwe
parents: 2705
diff changeset
177 }
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
178 }
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
179 else
2646
5adf5280858c [project @ 1997-01-29 18:59:41 by jwe]
jwe
parents: 2554
diff changeset
180 {
5adf5280858c [project @ 1997-01-29 18:59:41 by jwe]
jwe
parents: 2554
diff changeset
181 cout << msg;
2652
69613a17f51a [project @ 1997-01-31 20:30:22 by jwe]
jwe
parents: 2646
diff changeset
182 cout.flush ();
2646
5adf5280858c [project @ 1997-01-29 18:59:41 by jwe]
jwe
parents: 2554
diff changeset
183 }
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
184 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
185 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
186 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
187
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
188 static bool
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
189 more_than_a_screenful (const char *s)
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
190 {
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
191 if (s)
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
192 {
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
193 int available_rows = command_editor::terminal_rows () - 2;
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
194
2103
30e2b1c4ffd9 [project @ 1996-04-28 12:19:45 by jwe]
jwe
parents: 2102
diff changeset
195 int count = 0;
30e2b1c4ffd9 [project @ 1996-04-28 12:19:45 by jwe]
jwe
parents: 2102
diff changeset
196
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
197 char c;
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
198
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
199 while ((c = *s++) != '\0')
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
200 if (c == '\n')
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
201 {
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
202 count++;
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
203
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
204 if (count > available_rows)
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
205 return true;
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
206 }
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
207 }
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
208
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
209 return false;
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
210 }
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
211
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
212 int
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
213 octave_pager_buf::sync (void)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
214 {
2186
0207f7f74be6 [project @ 1996-05-14 02:59:03 by jwe]
jwe
parents: 2185
diff changeset
215 if (! interactive
0207f7f74be6 [project @ 1996-05-14 02:59:03 by jwe]
jwe
parents: 2185
diff changeset
216 || really_flush_to_pager
2164
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
217 || (Vpage_screen_output && Vpage_output_immediately)
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
218 || ! Vpage_screen_output)
2100
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
219 {
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
220 sputc ('\0');
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
221
2100
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
222 char *buf = eback ();
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
223
2110
dece5cc39e00 [project @ 1996-04-30 12:38:20 by jwe]
jwe
parents: 2103
diff changeset
224 bool bypass_pager = (! interactive
2164
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
225 || ! Vpage_screen_output
2110
dece5cc39e00 [project @ 1996-04-30 12:38:20 by jwe]
jwe
parents: 2103
diff changeset
226 || (really_flush_to_pager
2164
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
227 && Vpage_screen_output
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
228 && ! Vpage_output_immediately
2110
dece5cc39e00 [project @ 1996-04-30 12:38:20 by jwe]
jwe
parents: 2103
diff changeset
229 && ! more_than_a_screenful (buf)));
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
230
2475
1d7925d6bede [project @ 1996-11-07 04:36:00 by jwe]
jwe
parents: 2448
diff changeset
231 seekoff (0, ios::beg);
1d7925d6bede [project @ 1996-11-07 04:36:00 by jwe]
jwe
parents: 2448
diff changeset
232
2101
c64b49a4cba3 [project @ 1996-04-28 11:59:25 by jwe]
jwe
parents: 2100
diff changeset
233 do_sync (buf, bypass_pager);
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
234
2100
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
235 octave_diary << buf;
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
236 }
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
237
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
238 return 0;
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
239 }
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
240
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
241 int
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
242 octave_diary_buf::sync (void)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
243 {
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
244 sputc ('\0');
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
245
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
246 if (write_to_diary_file && external_diary_file)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
247 external_diary_file << eback ();
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
248
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
249 seekoff (0, ios::beg);
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
250
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
251 return 0;
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
252 }
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
253
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
254 octave_pager_stream *octave_pager_stream::instance = 0;
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
255
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
256 octave_pager_stream::octave_pager_stream (void) : ostream (), pb (0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
257 {
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
258 pb = new octave_pager_buf;
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
259 rdbuf (pb);
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
260 setf (unitbuf);
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
261 }
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
262
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
263 octave_pager_stream::~octave_pager_stream (void)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
264 {
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
265 flush ();
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
266 delete pb;
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
267 }
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
268
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
269 octave_pager_stream&
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
270 octave_pager_stream::stream (void)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
271 {
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
272 if (! instance)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
273 instance = new octave_pager_stream ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
274
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
275 return *instance;
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
276 }
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
277
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
278 octave_diary_stream *octave_diary_stream::instance = 0;
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
279
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
280 octave_diary_stream::octave_diary_stream (void) : ostream (), db (0)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
281 {
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
282 db = new octave_diary_buf;
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
283 rdbuf (db);
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
284 setf (unitbuf);
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
285 }
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
286
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
287 octave_diary_stream::~octave_diary_stream (void)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
288 {
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
289 flush ();
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
290 delete db;
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
291 }
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
292
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
293 octave_diary_stream&
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
294 octave_diary_stream::stream (void)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
295 {
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
296 if (! instance)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
297 instance = new octave_diary_stream ();
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
298
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
299 return *instance;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
300 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
301
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
302 void
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
303 flush_octave_stdout (void)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
304 {
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
305 if (! flushing_output_to_pager)
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
306 {
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2926
diff changeset
307 unwind_protect::begin_frame ("flush_octave_stdout");
2100
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
308
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
309 unwind_protect_bool (really_flush_to_pager);
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
310 unwind_protect_bool (flushing_output_to_pager);
2100
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
311
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
312 really_flush_to_pager = true;
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
313 flushing_output_to_pager = true;
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
314
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
315 octave_stdout.flush ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
316
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
317 if (external_pager)
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
318 clear_external_pager ();
2100
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
319
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2926
diff changeset
320 unwind_protect::run_frame ("flush_octave_stdout");
2206
9be05ffc288a [project @ 1996-05-15 07:32:58 by jwe]
jwe
parents: 2201
diff changeset
321 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
322 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
323
1965
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
324 static void
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
325 close_diary_file (void)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
326 {
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
327 if (external_diary_file.is_open ())
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
328 {
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
329 octave_diary.flush ();
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
330 external_diary_file.close ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
331 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
332 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
333
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
334 static void
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
335 open_diary_file (void)
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
336 {
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
337 close_diary_file ();
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
338
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
339 external_diary_file.open (diary_file.c_str (), ios::app);
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
340
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
341 if (! external_diary_file)
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
342 error ("diary: can't open diary file `%s'", diary_file.c_str ());
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
343 }
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
344
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
345 DEFUN_TEXT (diary, args, ,
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
346 "diary [on|off]\n\
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
347 diary [file]\n\
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
348 \n\
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
349 redirect all input and screen output to a file.")
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
350 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
351 octave_value_list retval;
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
352
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
353 int argc = args.length () + 1;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
354
1965
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
355 string_vector argv = args.make_argv ("diary");
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
356
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
357 if (error_state)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
358 return retval;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
359
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
360 if (diary_file.empty ())
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
361 diary_file = "diary";
1306
f92615001614 [project @ 1995-05-15 19:54:29 by jwe]
jwe
parents: 1192
diff changeset
362
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
363 switch (argc)
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
364 {
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
365 case 1:
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
366 write_to_diary_file = ! write_to_diary_file;
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
367 open_diary_file ();
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
368 break;
623
7caf80625d0e [project @ 1994-08-17 02:04:04 by jwe]
jwe
parents: 581
diff changeset
369
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
370 case 2:
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
371 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
372 string arg = argv[1];
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
373
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
374 if (arg == "on")
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
375 {
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
376 write_to_diary_file = true;
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
377 open_diary_file ();
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
378 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
379 else if (arg == "off")
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
380 {
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
381 close_diary_file ();
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
382 write_to_diary_file = false;
2093
0b7c868bc4df [project @ 1996-04-28 08:58:41 by jwe]
jwe
parents: 2086
diff changeset
383 }
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
384 else
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
385 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
386 diary_file = arg;
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
387 open_diary_file ();
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
388 }
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
389 }
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
390 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 623
diff changeset
391
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
392 default:
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
393 print_usage ("diary");
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
394 break;
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
395 }
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
396
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
397 return retval;
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
398 }
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 529
diff changeset
399
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
400 DEFUN_TEXT (more, args, ,
1409
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
401 "more on\n\
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
402 more off\n\
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
403 \n\
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
404 Turn output pagination on or off.")
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
405 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
406 octave_value_list retval;
1409
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
407
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
408 int argc = args.length () + 1;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
409
1965
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
410 string_vector argv = args.make_argv ("more");
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
411
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
412 if (error_state)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
413 return retval;
1409
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
414
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
415 if (argc == 2)
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
416 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
417 string arg = argv[1];
1409
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
418
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
419 if (arg == "on")
2448
00998e1442ae [project @ 1996-10-30 22:27:18 by jwe]
jwe
parents: 2368
diff changeset
420 bind_builtin_variable ("page_screen_output", 1.0);
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
421 else if (arg == "off")
2448
00998e1442ae [project @ 1996-10-30 22:27:18 by jwe]
jwe
parents: 2368
diff changeset
422 bind_builtin_variable ("page_screen_output", 0.0);
1409
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
423 else
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
424 error ("more: unrecognized argument `%s'", arg.c_str ());
1409
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
425 }
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
426 else
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
427 print_usage ("more");
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
428
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
429 return retval;
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
430 }
e282214c41a5 [project @ 1995-09-15 06:41:08 by jwe]
jwe
parents: 1358
diff changeset
431
2097
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
432 static string
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
433 default_pager (void)
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
434 {
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
435 string pager_binary = octave_env::getenv ("PAGER");
2097
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
436
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
437 #ifdef DEFAULT_PAGER
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
438 if (pager_binary.empty ())
2097
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
439 {
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
440 pager_binary = string (DEFAULT_PAGER);
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
441
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
442 if (pager_binary == "less")
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
443 {
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
444 pager_binary.append (" -e");
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
445
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
446 string lessflags = octave_env::getenv ("LESS");
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
447 if (lessflags.empty ())
2097
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
448 pager_binary.append
2099
dcf899227c24 [project @ 1996-04-28 10:59:56 by jwe]
jwe
parents: 2098
diff changeset
449 (" -P'-- less ?pB(%pB\\%):--. (f)orward, (b)ack, (q)uit$'");
2097
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
450 }
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
451 }
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
452 #endif
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
453
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
454 return pager_binary;
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
455 }
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
456
2164
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
457 static int
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
458 pager_binary (void)
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
459 {
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
460 int status = 0;
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
461
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
462 string s = builtin_string_variable ("PAGER");
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
463
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
464 if (s.empty ())
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
465 {
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
466 gripe_invalid_value_specified ("PAGER");
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
467 status = -1;
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
468 }
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
469 else
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
470 Vpager_binary = s;
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
471
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
472 return status;
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
473 }
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
474
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
475 static int
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
476 page_output_immediately (void)
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
477 {
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
478 Vpage_output_immediately = check_preference ("page_output_immediately");
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
479
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
480 return 0;
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
481 }
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
482
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
483 static int
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
484 page_screen_output (void)
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
485 {
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
486 Vpage_screen_output = check_preference ("page_screen_output");
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
487
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
488 return 0;
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
489 }
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
490
2097
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
491 void
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
492 symbols_of_pager (void)
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
493 {
2164
269db7306980 [project @ 1996-05-13 13:05:24 by jwe]
jwe
parents: 2146
diff changeset
494 DEFVAR (PAGER, default_pager (), 0, pager_binary,
2097
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
495 "path to pager binary");
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
496
2146
5a417927755a [project @ 1996-05-13 06:03:25 by jwe]
jwe
parents: 2120
diff changeset
497 DEFVAR (page_output_immediately, 0.0, 0, page_output_immediately,
2102
8a40a2a677fa [project @ 1996-04-28 12:03:50 by jwe]
jwe
parents: 2101
diff changeset
498 "if paging output, start sending it as soon as it is available");
2100
49cdc5b183bc [project @ 1996-04-28 11:26:32 by jwe]
jwe
parents: 2099
diff changeset
499
2097
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
500 DEFVAR (page_screen_output, 1.0, 0, page_screen_output,
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
501 "if possible, send output intended for the screen through the pager");
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
502 }
19ba1a7dcfbb [project @ 1996-04-28 10:40:15 by jwe]
jwe
parents: 2093
diff changeset
503
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
504 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
505 ;;; Local Variables: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
506 ;;; mode: C++ ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
507 ;;; End: ***
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
508 */