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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/epoll.h>
#include <sys/timerfd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include "async.h"
#include "config.h"
#include "sixel.h"
#include "user-notification.h"
#include "vt.h"
extern bool fdm_ptmx(struct fdm *fdm, int fd, int events, void *data);
static void
usage(const char *prog_name)
{
printf(
"Usage: %s stimuli-file1 stimuli-file2 ... stimuli-fileN\n",
prog_name);
}
enum async_write_status
async_write(int fd, const void *data, size_t len, size_t *idx)
{
return ASYNC_WRITE_DONE;
}
bool
fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data)
{
return true;
}
bool
fdm_del(struct fdm *fdm, int fd)
{
return true;
}
bool
fdm_event_add(struct fdm *fdm, int fd, int events)
{
return true;
}
bool
fdm_event_del(struct fdm *fdm, int fd, int events)
{
return true;
}
bool
render_resize_force(struct terminal *term, int width, int height)
{
return true;
}
void render_refresh(struct terminal *term) {}
void render_refresh_csd(struct terminal *term) {}
void render_refresh_title(struct terminal *term) {}
bool
render_xcursor_set(struct seat *seat, struct terminal *term, const char *xcursor)
{
return true;
}
struct wl_window *
wayl_win_init(struct terminal *term)
{
return NULL;
}
void wayl_win_destroy(struct wl_window *win) {}
bool
spawn(struct reaper *reaper, const char *cwd, char *const argv[],
int stdin_fd, int stdout_fd, int stderr_fd)
{
return true;
}
pid_t
slave_spawn(
int ptmx, int argc, const char *cwd, char *const *argv, const char *term_env,
const char *conf_shell, bool login_shell,
const user_notifications_t *notifications)
{
return 0;
}
int
render_worker_thread(void *_ctx)
{
return 0;
}
struct extraction_context *
extract_begin(enum selection_kind kind)
{
return NULL;
}
bool
extract_one(
const struct terminal *term, const struct row *row, const struct cell *cell,
int col, void *context)
{
return true;
}
bool
extract_finish(struct extraction_context *context, char **text, size_t *len)
{
return true;
}
void cmd_scrollback_up(struct terminal *term, int rows) {}
void cmd_scrollback_down(struct terminal *term, int rows) {}
void ime_enable(struct seat *seat) {}
void ime_disable(struct seat *seat) {}
void
notify_notify(const struct terminal *term, const char *title, const char *body)
{
}
int
main(int argc, const char *const *argv)
{
if (argc < 2) {
usage(argv[0]);
return EXIT_FAILURE;
}
const int row_count = 67;
const int col_count = 135;
const int grid_row_count = 16384;
int lower_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
if (lower_fd < 0)
return EXIT_FAILURE;
int upper_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
if (upper_fd < 0) {
close(lower_fd);
return EXIT_FAILURE;
}
struct row **rows = calloc(grid_row_count, sizeof(rows[0]));
for (int i = 0; i < grid_row_count; i++) {
rows[i] = calloc(1, sizeof(*rows[i]));
rows[i]->cells = calloc(col_count, sizeof(rows[i]->cells[0]));
}
struct config conf = {
.tweak = {
.delayed_render_lower_ns = 500000, /* 0.5ms */
.delayed_render_upper_ns = 16666666 / 2, /* half a frame period (60Hz) */
},
};
struct wayland wayl = {
.seats = tll_init(),
.monitors = tll_init(),
.terms = tll_init(),
};
struct terminal term = {
.conf = &conf,
.wl = &wayl,
.grid = &term.normal,
.normal = {
.num_rows = grid_row_count,
.num_cols = col_count,
.rows = rows,
.cur_row = rows[0],
},
.alt = {
.num_rows = grid_row_count,
.num_cols = col_count,
.rows = rows,
.cur_row = rows[0],
},
.scale = 1,
.width = col_count * 8,
.height = row_count * 15,
.cols = col_count,
.rows = row_count,
.cell_width = 8,
.cell_height = 15,
.scroll_region = {
.start = 0,
.end = row_count,
},
.selection = {
.start = {-1, -1},
.end = {-1, -1},
},
.delayed_render_timer = {
.lower_fd = lower_fd,
.upper_fd = upper_fd
},
.sixel = {
.palette_size = SIXEL_MAX_COLORS,
.max_width = SIXEL_MAX_WIDTH,
.max_height = SIXEL_MAX_HEIGHT,
},
};
tll_push_back(wayl.terms, &term);
int ret = EXIT_FAILURE;
for (int i = 1; i < argc; i++) {
struct stat st;
if (stat(argv[i], &st) < 0) {
fprintf(stderr, "error: %s: failed to stat: %s\n",
argv[i], strerror(errno));
goto out;
}
uint8_t *data = malloc(st.st_size);
if (data == NULL) {
fprintf(stderr, "error: %s: failed to allocate buffer: %s\n",
argv[i], strerror(errno));
goto out;
}
int fd = open(argv[1], O_RDONLY);
if (fd < 0) {
fprintf(stderr, "error: %s: failed to open: %s\n",
argv[i], strerror(errno));
goto out;
}
ssize_t amount = read(fd, data, st.st_size);
if (amount != st.st_size) {
fprintf(stderr, "error: %s: failed to read: %s\n",
argv[i], strerror(errno));
goto out;
}
close(fd);
int mem_fd = memfd_create("foot-pgo-ptmx", MFD_CLOEXEC);
if (mem_fd < 0) {
fprintf(stderr, "error: failed to create memory FD\n");
goto out;
}
if (write(mem_fd, data, st.st_size) < 0) {
fprintf(stderr, "error: failed to write memory FD\n");
close(mem_fd);
goto out;
}
free(data);
term.ptmx = mem_fd;
lseek(mem_fd, 0, SEEK_SET);
printf("Feeding VT parser with %s (%lld bytes)\n",
argv[i], (long long)st.st_size);
while (lseek(mem_fd, 0, SEEK_CUR) < st.st_size) {
if (!fdm_ptmx(NULL, -1, EPOLLIN, &term)) {
fprintf(stderr, "error: fdm_ptmx() failed\n");
close(mem_fd);
goto out;
}
}
close(mem_fd);
}
ret = EXIT_SUCCESS;
out:
tll_free(wayl.terms);
for (int i = 0; i < grid_row_count; i++) {
free(rows[i]->cells);
free(rows[i]);
}
free(rows);
close(lower_fd);
close(upper_fd);
return ret;
}
|