1 | /* |
---|
2 | * cacaplay caca file player |
---|
3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: cacaplay.c 826 2006-04-21 18:44:04Z 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 | |
---|
26 | int main(int argc, char **argv) |
---|
27 | { |
---|
28 | struct stat statbuf; |
---|
29 | caca_event_t ev; |
---|
30 | cucul_canvas_t *cv; |
---|
31 | caca_display_t *dp; |
---|
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 | cv = cucul_import_canvas(buffer, statbuf.st_size, "caca"); |
---|
57 | free(buffer); |
---|
58 | |
---|
59 | if(!cv) |
---|
60 | { |
---|
61 | fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]); |
---|
62 | return 1; |
---|
63 | } |
---|
64 | |
---|
65 | dp = caca_create_display(cv); |
---|
66 | |
---|
67 | caca_refresh_display(dp); |
---|
68 | |
---|
69 | while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1)) |
---|
70 | { |
---|
71 | if(ev.data.key.ch == CACA_KEY_ESCAPE) |
---|
72 | break; |
---|
73 | } |
---|
74 | |
---|
75 | /* Clean up */ |
---|
76 | caca_free_display(dp); |
---|
77 | cucul_free_canvas(cv); |
---|
78 | |
---|
79 | return 0; |
---|
80 | } |
---|
81 | |
---|