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.

107 lines
1.9 KiB

3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. // p≡p API header generator
  2. // Copyleft (c) 2019-2020, p≡p foundation
  3. // this file is under GNU General Public License 3.0
  4. // see LICENSE.txt
  5. // written by Volker Birk
  6. include yslt.yml2
  7. include ./config.yml2
  8. tstylesheet {
  9. include ./to_c.ysl2
  10. include standardlib.ysl2
  11. const "version" **version;
  12. const "copyleft" **copyleft;
  13. template "/package"
  14. apply "package", 0;
  15. template "package" document "{@name}_{@type}.h", "text" {
  16. ||
  17. // «../@name» «$version»
  18. // «@name»_«@type».h
  19. // «$copyleft»
  20. #pragma once
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #include <pEp/basic_types.h>
  25. ||
  26. apply "doc|type|enum|struct", 0;
  27. ||
  28. #ifdef __cplusplus
  29. } // extern "C"
  30. #endif
  31. ||
  32. }
  33. template "type" {
  34. apply "@doc", 0;
  35. | typedef «func:basetype(@name)» «@name»;
  36. |
  37. }
  38. template "struct" {
  39. ||
  40. typedef struct _«func:name()» {
  41. ||
  42. apply "field|internal|doc";
  43. apply "field[@function='free']", mode=free;
  44. ||
  45. } «func:name()»;
  46. ||
  47. }
  48. template "field|internal" {
  49. apply "@doc", 0;
  50. | «func:c-type(@type)» «@name»;
  51. }
  52. template "field", mode=free
  53. ||
  54. // free function for «@name»
  55. void (*release_«@name»)(«func:c-type(@type)» «@name»);
  56. ||
  57. template "enum" {
  58. ||
  59. typedef enum _«func:name()» {
  60. ||
  61. apply "item|doc";
  62. ||
  63. } «func:name()»;
  64. ||
  65. }
  66. template "doc|@doc" {
  67. > \n
  68. for "str:split(., '\n')"
  69. | // «.»
  70. }
  71. template "item" {
  72. apply "@doc", 0;
  73. choose {
  74. when "@output='hex'"
  75. | «func:name()»`if "text()" { " = 0x" value "yml:dec2hex(., 2)" }``if "position()!=last()" > ,`
  76. otherwise
  77. | «func:name()»`if "text()" { " = " value "." }``if "position()!=last()" > ,`
  78. }
  79. }
  80. }