2
* swallow swallow another libcaca application
3
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
6
* $Id: swallow.c 1060 2006-11-13 13:34:06Z sam $
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the Do What The Fuck You Want To
10
* Public License, Version 2, as published by Sam Hocevar. See
11
* http://sam.zoy.org/wtfpl/COPYING for more details.
16
#if !defined(__KERNEL__)
25
int main(int argc, char **argv)
28
static cucul_canvas_t *cv, *app;
29
static caca_display_t *dp;
30
unsigned char *buf[4];
31
long int bytes[4], total[4];
37
fprintf(stderr, "usage: %s <cmd1> <cmd2> <cmd3> <cmd4>\n", argv[0]);
41
cv = cucul_create_canvas(0, 0);
42
app = cucul_create_canvas(0, 0);
43
dp = caca_create_display(cv);
47
w = (cucul_get_canvas_width(cv) - 4) / 2;
48
h = (cucul_get_canvas_height(cv) - 6) / 2;
53
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
54
cucul_draw_line(cv, 0, 0, cucul_get_canvas_width(cv) - 1, 0, ' ');
55
cucul_printf(cv, cucul_get_canvas_width(cv) / 2 - 10, 0,
56
"libcaca multiplexer");
58
for(i = 0; i < 4; i++)
61
total[i] = bytes[i] = 0;
62
sprintf(cmd, "CACA_DRIVER=raw CACA_GEOMETRY=%ix%i %s",
64
f[i] = popen(cmd, "r");
67
cucul_printf(cv, (w + 2) * (i / 2) + 1,
68
(h + 2) * ((i % 2) + 1), "%s", argv[i + 1]);
74
int ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, 0);
76
if(ret && ev.type & CACA_EVENT_KEY_PRESS)
79
for(i = 0; i < 4; i++)
81
bytes[i] = cucul_import_memory(app, buf[i], total[i], "caca");
86
memmove(buf[i], buf[i] + bytes[i], total[i]);
88
cucul_blit(cv, (w + 2) * (i / 2) + 1,
89
(h + 2) * (i % 2) + 2, app, NULL);
90
caca_refresh_display(dp);
92
else if(bytes[i] == 0)
94
buf[i] = realloc(buf[i], total[i] + 128);
95
fread(buf[i] + total[i], 128, 1, f[i]);
100
fprintf(stderr, "%s: corrupted input %i\n", argv[0], i);
107
caca_free_display(dp);
108
cucul_free_canvas(cv);
109
cucul_free_canvas(app);