source: libcaca/trunk/caca/driver_raw.c @ 2040

Last change on this file since 2040 was 2040, checked in by Sam Hocevar, 13 years ago
  • Rename _cucul_set_canvas_size into cucul_set_canvas_size to prevent collisions due to symbol mangling.
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: driver_raw.c 2040 2007-11-23 22:34:35Z sam $
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 *  This file contains the libcaca raw input and output driver
17 */
18
19#include "config.h"
20#include "common.h"
21
22#if !defined(__KERNEL__)
23
24#include <stdio.h>
25#include <stdlib.h>
26
27#include "caca.h"
28#include "caca_internals.h"
29#include "cucul.h"
30#include "cucul_internals.h"
31
32static int raw_init_graphics(caca_display_t *dp)
33{
34    unsigned int width = dp->cv->width, height = dp->cv->height;
35    char const *geometry;
36
37#if defined(HAVE_GETENV)
38    geometry = getenv("CACA_GEOMETRY");
39    if(geometry && *geometry)
40        sscanf(geometry, "%ux%u", &width, &height);
41#endif
42
43    __cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
44
45    return 0;
46}
47
48static int raw_end_graphics(caca_display_t *dp)
49{
50    return 0;
51}
52
53static int raw_set_display_title(caca_display_t *dp, char const *title)
54{
55    return -1;
56}
57
58static unsigned int raw_get_display_width(caca_display_t *dp)
59{
60    return 0;
61}
62
63static unsigned int raw_get_display_height(caca_display_t *dp)
64{
65    return 0;
66}
67
68static void raw_display(caca_display_t *dp)
69{
70    void *buffer;
71    unsigned long int len;
72
73    buffer = cucul_export_memory(dp->cv, "caca", &len);
74    if(!buffer)
75        return;
76    fwrite(buffer, len, 1, stdout);
77    fflush(stdout);
78    free(buffer);
79}
80
81static void raw_handle_resize(caca_display_t *dp)
82{
83    ;
84}
85
86static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
87{
88    ev->type = CACA_EVENT_NONE;
89    return 0;
90}
91
92/*
93 * Driver initialisation
94 */
95
96int raw_install(caca_display_t *dp)
97{
98    dp->drv.driver = CACA_DRIVER_RAW;
99
100    dp->drv.init_graphics = raw_init_graphics;
101    dp->drv.end_graphics = raw_end_graphics;
102    dp->drv.set_display_title = raw_set_display_title;
103    dp->drv.get_display_width = raw_get_display_width;
104    dp->drv.get_display_height = raw_get_display_height;
105    dp->drv.display = raw_display;
106    dp->drv.handle_resize = raw_handle_resize;
107    dp->drv.get_event = raw_get_event;
108    dp->drv.set_mouse = NULL;
109    dp->drv.set_cursor = NULL;
110
111    return 0;
112}
113
114#endif /* !__KERNEL__ */
Note: See TracBrowser for help on using the repository browser.