You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.h 2.4 KiB

17 jaren geleden
17 jaren geleden
17 jaren geleden
17 jaren geleden
17 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * libcaca Ruby bindings
  3. * Copyright (c) 2007-2010 Pascal Terjan <pterjan@linuxfr.org>
  4. * 2012 Sam Hocevar <sam@hocevar.net>
  5. *
  6. * This library is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What the Fuck You Want
  9. * to Public License, Version 2, as published by Sam Hocevar. See
  10. * http://www.wtfpl.net/ for more details.
  11. */
  12. #ifndef __COMMON_H__
  13. #define __COMMON_H__
  14. #define _SELF (DATA_PTR(self))
  15. #define get_singleton_double_list(x) \
  16. static VALUE x##_list(void) \
  17. { \
  18. VALUE ary, ary2; \
  19. char const* const* list; \
  20. \
  21. list = caca_get_##x##_list(); \
  22. ary = rb_ary_new(); \
  23. while (*list != NULL) \
  24. { \
  25. ary2 = rb_ary_new(); \
  26. rb_ary_push(ary2, rb_str_new2(*list)); \
  27. list++; \
  28. rb_ary_push(ary2, rb_str_new2(*list)); \
  29. list++; \
  30. rb_ary_push(ary, ary2); \
  31. } \
  32. \
  33. return ary; \
  34. }
  35. #define get_double_list(x) \
  36. static VALUE x##_list(VALUE self) \
  37. { \
  38. VALUE ary, ary2; \
  39. char const* const* list; \
  40. \
  41. list = caca_get_##x##_list(_SELF); \
  42. ary = rb_ary_new(); \
  43. while (*list != NULL) \
  44. { \
  45. ary2 = rb_ary_new(); \
  46. rb_ary_push(ary2, rb_str_new2(*list)); \
  47. list++; \
  48. rb_ary_push(ary2, rb_str_new2(*list)); \
  49. list++; \
  50. rb_ary_push(ary, ary2); \
  51. } \
  52. \
  53. return ary; \
  54. }
  55. #endif