您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

driver_raw.c 2.3 KiB

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