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

Last change on this file since 1353 was 1353, checked in by Sam Hocevar, 14 years ago
  • Flush stdout after writing the data in the raw driver.
  • 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 1353 2006-11-12 10:02:51Z 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    fflush(stdout);
77    free(buffer);
78}
79
80static void raw_handle_resize(caca_display_t *dp)
81{
82    ;
83}
84
85static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
86{
87    ev->type = CACA_EVENT_NONE;
88    return 0;
89}
90
91/*
92 * Driver initialisation
93 */
94
95int raw_install(caca_display_t *dp)
96{
97    dp->drv.driver = CACA_DRIVER_RAW;
98
99    dp->drv.init_graphics = raw_init_graphics;
100    dp->drv.end_graphics = raw_end_graphics;
101    dp->drv.set_display_title = raw_set_display_title;
102    dp->drv.get_display_width = raw_get_display_width;
103    dp->drv.get_display_height = raw_get_display_height;
104    dp->drv.display = raw_display;
105    dp->drv.handle_resize = raw_handle_resize;
106    dp->drv.get_event = raw_get_event;
107    dp->drv.set_mouse = NULL;
108
109    return 0;
110}
111
112#endif /* !__KERNEL__ */
Note: See TracBrowser for help on using the repository browser.