Team Fortress 2 Source Code as on 22/4/2020
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.

82 lines
2.1 KiB

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * cdata.i
  6. *
  7. * SWIG library file containing macros for manipulating raw C data as strings.
  8. * ----------------------------------------------------------------------------- */
  9. %{
  10. typedef struct SWIGCDATA {
  11. char *data;
  12. int len;
  13. } SWIGCDATA;
  14. %}
  15. /* -----------------------------------------------------------------------------
  16. * Typemaps for returning binary data
  17. * ----------------------------------------------------------------------------- */
  18. #if SWIGGUILE
  19. %typemap(out) SWIGCDATA {
  20. $result = gh_str2scm($1.data,$1.len);
  21. }
  22. %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
  23. #elif SWIGCHICKEN
  24. %typemap(out) SWIGCDATA {
  25. C_word *string_space = C_alloc(C_SIZEOF_STRING($1.len));
  26. $result = C_string(&string_space, $1.len, $1.data);
  27. }
  28. %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
  29. #else
  30. %echo "cdata.i module not supported."
  31. #endif
  32. /* -----------------------------------------------------------------------------
  33. * %cdata(TYPE [, NAME])
  34. *
  35. * Convert raw C data to a binary string.
  36. * ----------------------------------------------------------------------------- */
  37. %define %cdata(TYPE,NAME...)
  38. %insert("header") {
  39. #if #NAME == ""
  40. static SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements) {
  41. #else
  42. static SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements) {
  43. #endif
  44. SWIGCDATA d;
  45. d.data = (char *) ptr;
  46. #if #TYPE != "void"
  47. d.len = nelements*sizeof(TYPE);
  48. #else
  49. d.len = nelements;
  50. #endif
  51. return d;
  52. }
  53. }
  54. %typemap(default) int nelements "$1 = 1;"
  55. #if #NAME == ""
  56. SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements);
  57. #else
  58. SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
  59. #endif
  60. %enddef
  61. %typemap(default) int nelements;
  62. %rename(cdata) ::cdata_void(void *ptr, int nelements);
  63. %cdata(void);
  64. /* Memory move function */
  65. void memmove(void *data, const void *indata, int inlen);