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

Last change on this file since 1306 was 1306, checked in by Sam Hocevar, 14 years ago
  • Renamed cucul_export() to cucul_export_memory(), paves the way for a cucul_export_file() but I'm not sure yet this is a good idea.
  • Use the new import/export API in libcaca.
  • Property svn:keywords set to Id
File size: 2.3 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 1306 2006-11-08 16:43:59Z sam $
7 *
8 *  This library 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/*
15 *  This file contains the libcaca raw input and output driver
16 */
17
18#include "config.h"
19#include "common.h"
20
21#if !defined(__KERNEL__)
22
23#include <stdio.h>
24#include <stdlib.h>
25
26#include "caca.h"
27#include "caca_internals.h"
28#include "cucul.h"
29#include "cucul_internals.h"
30
31static int raw_init_graphics(caca_display_t *dp)
32{
33    unsigned int width = dp->cv->width, height = dp->cv->height;
34    char const *geometry;
35
36#if defined(HAVE_GETENV)
37    geometry = getenv("CACA_GEOMETRY");
38    if(geometry && *geometry)
39        sscanf(geometry, "%ux%u", &width, &height);
40#endif
41
42    _cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
43
44    return 0;
45}
46
47static int raw_end_graphics(caca_display_t *dp)
48{
49    return 0;
50}
51
52static int raw_set_display_title(caca_display_t *dp, char const *title)
53{
54    return -1;
55}
56
57static unsigned int raw_get_display_width(caca_display_t *dp)
58{
59    return 0;
60}
61
62static unsigned int raw_get_display_height(caca_display_t *dp)
63{
64    return 0;
65}
66
67static void raw_display(caca_display_t *dp)
68{
69    void *buffer;
70    unsigned long int len;
71
72    buffer = cucul_export_memory(dp->cv, "caca", &len);
73    if(!buffer)
74        return;
75    fwrite(buffer, len, 1, stdout);
76    free(buffer);
77}
78
79static void raw_handle_resize(caca_display_t *dp)
80{
81    ;
82}
83
84static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
85{
86    ev->type = CACA_EVENT_NONE;
87    return 0;
88}
89
90/*
91 * Driver initialisation
92 */
93
94int raw_install(caca_display_t *dp)
95{
96    dp->drv.driver = CACA_DRIVER_RAW;
97
98    dp->drv.init_graphics = raw_init_graphics;
99    dp->drv.end_graphics = raw_end_graphics;
100    dp->drv.set_display_title = raw_set_display_title;
101    dp->drv.get_display_width = raw_get_display_width;
102    dp->drv.get_display_height = raw_get_display_height;
103    dp->drv.display = raw_display;
104    dp->drv.handle_resize = raw_handle_resize;
105    dp->drv.get_event = raw_get_event;
106    dp->drv.set_mouse = NULL;
107
108    return 0;
109}
110
111#endif /* !__KERNEL__ */
Note: See TracBrowser for help on using the repository browser.