diff --git a/caca/driver_raw.c b/caca/driver_raw.c index 394f4e2..e8ffc4f 100644 --- a/caca/driver_raw.c +++ b/caca/driver_raw.c @@ -57,18 +57,26 @@ static void raw_display(caca_t *kk) { uint8_t *attr = kk->qq->attr; uint32_t *chars = kk->qq->chars; - int n; + uint32_t w, h; + unsigned int n; + + w = kk->qq->width; + h = kk->qq->height; + + fprintf(stdout, "CACA%c%c%c%c%c%c%c%c", + (w >> 24), (w >> 16) & 0xff, (w >> 8) & 0xff, w & 0xff, + (h >> 24), (h >> 16) & 0xff, (h >> 8) & 0xff, h & 0xff); - fprintf(stdout, "CACA %i %i\n", kk->qq->width, kk->qq->height); for(n = kk->qq->height * kk->qq->width; n--; ) { uint32_t c = *chars++; uint8_t a = *attr++; - fprintf(stdout, "%c%c%c%c %c", (c >> 24), (c >> 16) & 0xff, - (c >> 8) & 0xff, c & 0xff, a); + fprintf(stdout, "%c%c%c%c%c", (c >> 24), (c >> 16) & 0xff, + (c >> 8) & 0xff, c & 0xff, a); } - fprintf(stdout, "ACAC\n"); + + fprintf(stdout, "ACAC"); fflush(stdout); } diff --git a/src/Makefile.am b/src/Makefile.am index 9807655..caf7ec7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,7 +5,7 @@ pkgdata_DATA = caca.txt EXTRA_DIST = caca.txt AM_CPPFLAGS = -I$(top_srcdir)/cucul -I$(top_srcdir)/caca -DLIBCACA=1 -DX_DISPLAY_MISSING=1 -bin_PROGRAMS = cacafire cacaball cacaplas cacaview cacamoir +bin_PROGRAMS = cacafire cacaball cacaplas cacaview cacamoir cacaplay cacafire_SOURCES = aafire.c cacafire_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ @@ -29,3 +29,6 @@ cacaview_CFLAGS = cacaview_LDFLAGS = endif +cacaplay_SOURCES = cacaplay.c +cacaplay_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ + diff --git a/src/cacaplay.c b/src/cacaplay.c new file mode 100644 index 0000000..7613e45 --- /dev/null +++ b/src/cacaplay.c @@ -0,0 +1,81 @@ +/* + * cacaplay caca file player + * Copyright (c) 2006 Sam Hocevar + * All Rights Reserved + * + * $Id$ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the Do What The Fuck You Want To + * Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/wtfpl/COPYING for more details. + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include + +#include "cucul.h" +#include "caca.h" + +int main(int argc, char **argv) +{ + struct stat statbuf; + struct caca_event ev; + cucul_t *qq; + caca_t *kk; + void *buffer; + int fd; + + if(argc < 2) + { + fprintf(stderr, "%s: missing argument (filename).\n", argv[0]); + return 1; + } + + fd = open(argv[1], O_RDONLY); + if(!fd) + { + fprintf(stderr, "%s: could not open %s.\n", argv[0], argv[1]); + return 1; + } + + if(fstat(fd, &statbuf)) + { + fprintf(stderr, "%s: could not stat %s.\n", argv[0], argv[1]); + return 1; + } + + buffer = malloc(statbuf.st_size); + read(fd, buffer, statbuf.st_size); + qq = cucul_load(buffer, statbuf.st_size); + free(buffer); + + if(!qq) + { + fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]); + return 1; + } + + kk = caca_attach(qq); + + caca_display(kk); + + while(caca_wait_event(kk, CACA_EVENT_KEY_PRESS, &ev)) + { + if(ev.data.key.c == CACA_KEY_ESCAPE) + break; + } + + /* Clean up */ + caca_detach(kk); + cucul_free(qq); + + return 0; +} +