Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

driver_raw.c 2.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  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. * This file contains the libcaca raw input and output driver
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #if !defined(__KERNEL__)
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include "caca.h"
  23. #include "caca_internals.h"
  24. #include "cucul.h"
  25. #include "cucul_internals.h"
  26. static int raw_init_graphics(caca_display_t *dp)
  27. {
  28. unsigned int width = dp->cv->width, height = dp->cv->height;
  29. char const *geometry;
  30. #if defined(HAVE_GETENV)
  31. geometry = getenv("CACA_GEOMETRY");
  32. if(geometry && *geometry)
  33. sscanf(geometry, "%ux%u", &width, &height);
  34. #endif
  35. _cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
  36. return 0;
  37. }
  38. static int raw_end_graphics(caca_display_t *dp)
  39. {
  40. return 0;
  41. }
  42. static int raw_set_display_title(caca_display_t *dp, char const *title)
  43. {
  44. return -1;
  45. }
  46. static unsigned int raw_get_display_width(caca_display_t *dp)
  47. {
  48. return 0;
  49. }
  50. static unsigned int raw_get_display_height(caca_display_t *dp)
  51. {
  52. return 0;
  53. }
  54. static void raw_display(caca_display_t *dp)
  55. {
  56. void *buffer;
  57. unsigned long int len;
  58. buffer = cucul_export_memory(dp->cv, "caca", &len);
  59. if(!buffer)
  60. return;
  61. fwrite(buffer, len, 1, stdout);
  62. fflush(stdout);
  63. free(buffer);
  64. }
  65. static void raw_handle_resize(caca_display_t *dp)
  66. {
  67. ;
  68. }
  69. static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
  70. {
  71. ev->type = CACA_EVENT_NONE;
  72. return 0;
  73. }
  74. /*
  75. * Driver initialisation
  76. */
  77. int raw_install(caca_display_t *dp)
  78. {
  79. dp->drv.driver = CACA_DRIVER_RAW;
  80. dp->drv.init_graphics = raw_init_graphics;
  81. dp->drv.end_graphics = raw_end_graphics;
  82. dp->drv.set_display_title = raw_set_display_title;
  83. dp->drv.get_display_width = raw_get_display_width;
  84. dp->drv.get_display_height = raw_get_display_height;
  85. dp->drv.display = raw_display;
  86. dp->drv.handle_resize = raw_handle_resize;
  87. dp->drv.get_event = raw_get_event;
  88. dp->drv.set_mouse = NULL;
  89. dp->drv.set_cursor = NULL;
  90. return 0;
  91. }
  92. #endif /* !__KERNEL__ */