source: libcaca/trunk/src/cacaplay.c @ 865

Last change on this file since 865 was 859, checked in by Sam Hocevar, 14 years ago
  • Removed duplicate uint*_t defines from *_internal.h and included common.h in all .c files that needed it.
  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1/*
2 *  cacaplay      caca file player
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: cacaplay.c 859 2006-04-24 20:35:59Z sam $
7 *
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.
12 */
13
14#include "config.h"
15#include "common.h"
16
17#include <stdio.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <fcntl.h>
21#include <unistd.h>
22#include <stdlib.h>
23
24#include "cucul.h"
25#include "caca.h"
26
27int main(int argc, char **argv)
28{
29    struct stat statbuf;
30    caca_event_t ev;
31    cucul_canvas_t *cv;
32    caca_display_t *dp;
33    void *buffer;
34    int fd;
35
36    if(argc < 2)
37    {
38        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
39        return 1;
40    }
41
42    fd = open(argv[1], O_RDONLY);
43    if(!fd)
44    {
45        fprintf(stderr, "%s: could not open %s.\n", argv[0], argv[1]);
46        return 1;
47    }
48
49    if(fstat(fd, &statbuf))
50    {
51        fprintf(stderr, "%s: could not stat %s.\n", argv[0], argv[1]);
52        return 1;
53    }
54
55    buffer = malloc(statbuf.st_size);
56    read(fd, buffer, statbuf.st_size);
57    cv = cucul_import_canvas(buffer, statbuf.st_size, "caca");
58    free(buffer);
59
60    if(!cv)
61    {
62        fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]);
63        return 1;
64    }
65
66    dp = caca_create_display(cv);
67
68    caca_refresh_display(dp);
69
70    while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1))
71    {
72        if(ev.data.key.ch == CACA_KEY_ESCAPE)
73            break;
74    }
75
76    /* Clean up */
77    caca_free_display(dp);
78    cucul_free_canvas(cv);
79
80    return 0;
81}
82
Note: See TracBrowser for help on using the repository browser.