From 6b22ab776c4daa764caf4d15b18da9e097cbfc03 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 24 Jul 2009 06:48:49 +0000 Subject: [PATCH] Add a null driver that does absolutely nothing. --- caca/Makefile.am | 1 + caca/caca.c | 6 +++ caca/caca_internals.h | 5 ++- caca/driver/null.c | 90 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 caca/driver/null.c diff --git a/caca/Makefile.am b/caca/Makefile.am index 9e02618..30e372b 100644 --- a/caca/Makefile.am +++ b/caca/Makefile.am @@ -62,6 +62,7 @@ codec_source = \ driver_source = \ driver/conio.c \ driver/ncurses.c \ + driver/null.c \ driver/raw.c \ driver/slang.c \ driver/vga.c \ diff --git a/caca/caca.c b/caca/caca.c index ee972f1..ae2a7d3 100644 --- a/caca/caca.c +++ b/caca/caca.c @@ -178,6 +178,7 @@ char const * const * caca_get_display_driver_list(void) #endif #if !defined(__KERNEL__) "raw", "raw libcaca output", + "null", "null driver", #endif NULL, NULL }; @@ -388,6 +389,9 @@ static int caca_select_driver(caca_display_t *dp, char const *driver) #endif #if defined(USE_VGA) if(!strcasecmp(var, "vga")) return vga_install(dp); +#endif +#if !defined(__KERNEL__) + if(!strcasecmp(var, "null")) return null_install(dp); #endif return -1; } @@ -419,6 +423,8 @@ static int caca_select_driver(caca_display_t *dp, char const *driver) #if defined(USE_SLANG) if(slang_install(dp) == 0) return 0; #endif + /* Of course we don't try "raw" or "null" if the user did not + * specifically ask for them. */ return -1; } diff --git a/caca/caca_internals.h b/caca/caca_internals.h index 267c08f..c5d3c96 100644 --- a/caca/caca_internals.h +++ b/caca/caca_internals.h @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * $Id$ @@ -80,7 +80,7 @@ struct caca_canvas /* Graphics driver */ enum caca_driver { - CACA_DRIVER_NONE = 0, + CACA_DRIVER_NULL = 0, CACA_DRIVER_RAW = 1, #if defined(USE_COCOA) CACA_DRIVER_COCOA = 2, @@ -121,6 +121,7 @@ int gl_install(caca_display_t *); #if defined(USE_NCURSES) int ncurses_install(caca_display_t *); #endif +int null_install(caca_display_t *); int raw_install(caca_display_t *); #if defined(USE_SLANG) int slang_install(caca_display_t *); diff --git a/caca/driver/null.c b/caca/driver/null.c new file mode 100644 index 0000000..046a779 --- /dev/null +++ b/caca/driver/null.c @@ -0,0 +1,90 @@ +/* + * libcaca Colour ASCII-Art library + * Copyright (c) 2002-2009 Sam Hocevar + * All Rights Reserved + * + * $Id$ + * + * This library is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/wtfpl/COPYING for more details. + */ + +/* + * This file contains a null libcaca input and output driver + */ + +#include "config.h" + +#if !defined(__KERNEL__) + +#include "caca.h" +#include "caca_internals.h" + +static int null_init_graphics(caca_display_t *dp) +{ + return 0; +} + +static int null_end_graphics(caca_display_t *dp) +{ + return 0; +} + +static int null_set_display_title(caca_display_t *dp, char const *title) +{ + return -1; +} + +static int null_get_display_width(caca_display_t const *dp) +{ + return 0; +} + +static int null_get_display_height(caca_display_t const *dp) +{ + return 0; +} + +static void null_display(caca_display_t *dp) +{ + ; +} + +static void null_handle_resize(caca_display_t *dp) +{ + ; +} + +static int null_get_event(caca_display_t *dp, caca_privevent_t *ev) +{ + ev->type = CACA_EVENT_NONE; + return 0; +} + +/* + * Driver initialisation + */ + +int null_install(caca_display_t *dp) +{ + dp->drv.id = CACA_DRIVER_NULL; + dp->drv.driver = "null"; + + dp->drv.init_graphics = null_init_graphics; + dp->drv.end_graphics = null_end_graphics; + dp->drv.set_display_title = null_set_display_title; + dp->drv.get_display_width = null_get_display_width; + dp->drv.get_display_height = null_get_display_height; + dp->drv.display = null_display; + dp->drv.handle_resize = null_handle_resize; + dp->drv.get_event = null_get_event; + dp->drv.set_mouse = NULL; + dp->drv.set_cursor = NULL; + + return 0; +} + +#endif /* !__KERNEL__ */