source: libcaca/trunk/test/import.c @ 873

Last change on this file since 873 was 873, checked in by Sam Hocevar, 15 years ago
  • Jylam is too modest.
  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1/*
2 *  import        libcaca importers test program
3 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
6 *  $Id: import.c 873 2006-04-25 11:05:03Z 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#if defined(HAVE_INTTYPES_H)
18#   include <inttypes.h>
19#endif
20
21#include <stdio.h>
22#include <stdlib.h>
23
24#include "cucul.h"
25#include "caca.h"
26
27int main(int argc, char *argv[])
28{
29    cucul_canvas_t *cv;
30    caca_display_t *dp;
31    FILE *fp;
32    unsigned char *buffer;
33    int size=0;
34
35    if(argc < 2)
36    {
37        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
38        return 1;
39    }
40
41    fp = fopen(argv[1], "rb");
42
43    if(!fp)
44    {
45        fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
46        return 1;
47    }
48    fseek(fp, 0, SEEK_END);
49    size = ftell(fp);
50    fseek(fp, 0, SEEK_SET);
51    buffer = malloc(sizeof(unsigned char) * size);
52    if(!buffer)
53    {
54        fprintf(stderr, "%s: Can't allocate memory (%d bytes)\n", argv[0], size);
55        return 1;
56    }
57
58    if(!fread(buffer, size, 1, fp))
59    {
60        fprintf(stderr, "%s: Can't read %s\n", argv[0], argv[1]);
61        return 1;
62    }
63
64    cv = cucul_import_canvas(buffer, size, "");
65
66    if(cv == NULL)
67    {
68        fprintf(stderr, "%s: Can't load %s, unknow reason.\n", argv[0], argv[1]);
69        return 1;
70    }
71
72    dp = caca_create_display(cv);
73
74    caca_refresh_display(dp);
75
76    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
77
78    caca_free_display(dp);
79    cucul_free_canvas(cv);
80
81    return 0;
82}
83
Note: See TracBrowser for help on using the repository browser.