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
RevLine 
[699]1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
[769]6 *  $Id: driver_raw.c 1353 2006-11-12 10:02:51Z sam $
7 *
[699]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
[769]14/*
[699]15 *  This file contains the libcaca raw input and output driver
16 */
17
18#include "config.h"
[859]19#include "common.h"
[699]20
21#if !defined(__KERNEL__)
22
[1054]23#include <stdio.h>
[1233]24#include <stdlib.h>
[1054]25
[699]26#include "caca.h"
27#include "caca_internals.h"
28#include "cucul.h"
29#include "cucul_internals.h"
30
[811]31static int raw_init_graphics(caca_display_t *dp)
[699]32{
[1233]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
[699]44    return 0;
45}
46
[811]47static int raw_end_graphics(caca_display_t *dp)
[699]48{
49    return 0;
50}
51
[819]52static int raw_set_display_title(caca_display_t *dp, char const *title)
[699]53{
[1006]54    return -1;
[699]55}
56
[819]57static unsigned int raw_get_display_width(caca_display_t *dp)
[699]58{
59    return 0;
60}
61
[819]62static unsigned int raw_get_display_height(caca_display_t *dp)
[699]63{
64    return 0;
65}
66
[811]67static void raw_display(caca_display_t *dp)
[699]68{
[1306]69    void *buffer;
70    unsigned long int len;
[699]71
[1306]72    buffer = cucul_export_memory(dp->cv, "caca", &len);
73    if(!buffer)
74        return;
75    fwrite(buffer, len, 1, stdout);
[1353]76    fflush(stdout);
[1306]77    free(buffer);
[699]78}
79
[811]80static void raw_handle_resize(caca_display_t *dp)
[699]81{
82    ;
83}
84
[811]85static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
[699]86{
87    ev->type = CACA_EVENT_NONE;
88    return 0;
89}
90
91/*
92 * Driver initialisation
93 */
94
[811]95int raw_install(caca_display_t *dp)
[699]96{
[811]97    dp->drv.driver = CACA_DRIVER_RAW;
[699]98
[811]99    dp->drv.init_graphics = raw_init_graphics;
100    dp->drv.end_graphics = raw_end_graphics;
[819]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;
[811]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;
[699]108
109    return 0;
110}
111
[1054]112#endif /* !__KERNEL__ */
Note: See TracBrowser for help on using the repository browser.