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

Last change on this file since 717 was 710, checked in by Sam Hocevar, 14 years ago
  • Merged caca_wait_event() into caca_get_event() and added a timeout parameter to do what both functions did before, and even more.
  • Property svn:keywords set to Id
File size: 1.6 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 710 2006-04-01 14:44:09Z 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
16#include <stdio.h>
17#include <sys/types.h>
18#include <sys/stat.h>
19#include <fcntl.h>
20#include <unistd.h>
21#include <stdlib.h>
22
23#include "cucul.h"
24#include "caca.h"
25
26int main(int argc, char **argv)
27{
28    struct stat statbuf;
29    struct caca_event ev;
30    cucul_t *qq;
31    caca_t *kk;
32    void *buffer;
33    int fd;
34
35    if(argc < 2)
36    {
37        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
38        return 1;
39    }
40
41    fd = open(argv[1], O_RDONLY);
42    if(!fd)
43    {
44        fprintf(stderr, "%s: could not open %s.\n", argv[0], argv[1]);
45        return 1;
46    }
47
48    if(fstat(fd, &statbuf))
49    {
50        fprintf(stderr, "%s: could not stat %s.\n", argv[0], argv[1]);
51        return 1;
52    }
53
54    buffer = malloc(statbuf.st_size);
55    read(fd, buffer, statbuf.st_size);
56    qq = cucul_load(buffer, statbuf.st_size);
57    free(buffer);
58
59    if(!qq)
60    {
61        fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]);
62        return 1;
63    }
64
65    kk = caca_attach(qq);
66
67    caca_display(kk);
68
69    while(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1))
70    {
71        if(ev.data.key.c == CACA_KEY_ESCAPE)
72            break;
73    }
74
75    /* Clean up */
76    caca_detach(kk);
77    cucul_free(qq);
78
79    return 0;
80}
81
Note: See TracBrowser for help on using the repository browser.