1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
$NetBSD: patch-ad,v 1.3 2011/02/09 22:51:38 rumko Exp $
$OpenBSD: patch-engine_c,v 1.1 2008/06/13 00:38:12 canacar Exp $
* DragonFly compatibility
* Patches to support PF > 4.1 taken from OpenBSD's ports.
--- engine.c.orig 2007-11-07 07:35:44 +0100
+++ engine.c 2009-11-17 00:31:46 +0100
@@ -18,11 +18,18 @@
#include <sys/types.h>
+#ifdef __DragonFly__
+#include "queue.h"
+#else
#include <sys/queue.h>
+#endif
#include <ctype.h>
#include <curses.h>
+#include <errno.h>
+#include <poll.h>
#include <signal.h>
+#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -33,6 +40,10 @@
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
+#ifndef CIRCLEQ_END
+#define CIRCLEQ_END(head) ((void *)(head))
+#endif
+
/* circular linked list of views */
CIRCLEQ_HEAD(view_list, view_ent) view_head =
CIRCLEQ_HEAD_INITIALIZER(view_head);
@@ -55,9 +66,6 @@
volatile sig_atomic_t gotsig_close = 0;
volatile sig_atomic_t gotsig_resize = 0;
-volatile sig_atomic_t gotsig_alarm = 0;
-int need_update = 0;
-int need_sort = 0;
SCREEN *screen;
@@ -105,7 +113,6 @@
int
tbprintf(char *format, ...)
- GCC_PRINTFLIKE(1,2) /* defined in curses.h */
{
int len;
va_list arg;
@@ -482,7 +489,6 @@
v = ve->view;
if ((curr_view != NULL) && (curr_mgr != v->mgr)) {
- gotsig_alarm = 1;
if (v->mgr != NULL && v->mgr->select_fn != NULL)
v->mgr->select_fn();
}
@@ -491,7 +497,6 @@
curr_view = v;
curr_mgr = v->mgr;
field_setup();
- need_update = 1;
}
void
@@ -809,6 +814,9 @@
{
order_type *o, *oc;
+ if (curr_view->mgr->order_list == NULL)
+ return;
+
oc = curr_view->mgr->order_curr;
for (o = curr_view->mgr->order_list; o->name != NULL; o++) {
@@ -905,12 +913,6 @@
}
void
-sig_alarm(int signal)
-{
- gotsig_alarm = 1;
-}
-
-void
setup_term(int dmax)
{
max_disp = dmax;
@@ -941,8 +943,9 @@
keypad(stdscr, TRUE);
intrflush(stdscr, FALSE);
- halfdelay(10);
+ cbreak();
noecho();
+ timeout(0);
}
if (dmax == 0)
@@ -970,7 +973,6 @@
}
curr_message = NULL;
curr_cmd = cmd;
- need_update = 1;
return prev;
}
@@ -987,7 +989,6 @@
int
msgprintf(char *format, ...)
- GCC_PRINTFLIKE(1,2) /* defined in curses.h */
{
static char buf[1024];
int len;
@@ -1085,28 +1086,21 @@
if (curr_message != NULL) {
if (ch > 0) {
curr_message = NULL;
- need_update = 1;
}
}
switch (ch) {
- case ' ':
- gotsig_alarm = 1;
- break;
case 'o':
next_order();
- need_sort = 1;
break;
case 'p':
paused = !paused;
- gotsig_alarm = 1;
break;
case 'q':
gotsig_close = 1;
break;
case 'r':
sortdir *= -1;
- need_sort = 1;
break;
case 'v':
/* FALLTHROUGH */
@@ -1124,49 +1118,40 @@
/* FALLTHROUGH */
case CTRL_N:
dispstart++;
- need_update = 1;
break;
case KEY_UP:
/* FALLTHROUGH */
case CTRL_P:
dispstart--;
- need_update = 1;
break;
case KEY_NPAGE:
/* FALLTHROUGH */
case CTRL_V:
dispstart += maxprint;
- need_update = 1;
break;
case KEY_PPAGE:
/* FALLTHROUGH */
case META_V:
dispstart -= maxprint;
- need_update = 1;
break;
case KEY_HOME:
/* FALLTHROUGH */
case CTRL_A:
dispstart = 0;
- need_update = 1;
break;
case KEY_END:
/* FALLTHROUGH */
case CTRL_E:
dispstart = num_disp;
- need_update = 1;
break;
case CTRL_L:
clear();
- need_update = 1;
break;
default:
break;
}
- if (set_order_hotkey(ch))
- need_sort = 1;
- else
+ if (!set_order_hotkey(ch))
set_view_hotkey(ch);
}
@@ -1177,43 +1162,15 @@
signal(SIGINT, sig_close);
signal(SIGQUIT, sig_close);
signal(SIGWINCH, sig_resize);
- signal(SIGALRM, sig_alarm);
}
void
engine_loop(int countmax)
{
+ struct pollfd set[1];
int count = 0;
for (;;) {
- if (gotsig_alarm) {
- read_view();
- need_sort = 1;
- gotsig_alarm = 0;
- alarm(delay);
- }
-
- if (need_sort) {
- sort_view();
- need_sort = 0;
- need_update = 1;
-
- /* XXX if sort took too long */
- if (gotsig_alarm) {
- gotsig_alarm = 0;
- alarm(delay);
- }
- }
-
- if (need_update) {
- erase();
- disp_update();
- end_page();
- need_update = 0;
- if (countmax && ++count >= countmax)
- break;
- }
-
if (gotsig_close)
break;
if (gotsig_resize) {
@@ -1221,13 +1178,31 @@
endwin();
setup_term(max_disp);
gotsig_resize = 0;
- need_update = 1;
}
- if (interactive && need_update == 0)
- keyboard();
- else if (interactive == 0)
+ read_view();
+ sort_view();
+
+ if (rawmode == 0)
+ erase();
+ disp_update();
+ end_page();
+ if (countmax && ++count >= countmax)
+ break;
+
+ if (interactive) {
+ set[0].fd = STDIN_FILENO;
+ set[0].events = POLLIN;
+ if (poll(set, 1, delay * 1000) == -1) {
+ if (errno == EINTR)
+ continue;
+ break;
+ }
+ if ((set[0].revents & POLLIN) != 0)
+ keyboard();
+ } else {
sleep(delay);
+ }
}
if (rawmode == 0)
|