template.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2018 Markus Hennecke <markus-hennecke@markus-hennecke.de>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef _TEMPLATE_H_
  17. #define _TEMPLATE_H_
  18. #include <sys/queue.h>
  19. #include <stdbool.h>
  20. #include "buffer.h"
  21. struct tmpl_name {
  22. char *name;
  23. };
  24. struct tmpl_var {
  25. TAILQ_ENTRY(tmpl_var) entry;
  26. struct tmpl_name name;
  27. char *value;
  28. };
  29. struct tmpl_data;
  30. struct tmpl_loop {
  31. TAILQ_ENTRY(tmpl_loop) entry;
  32. struct tmpl_name name;
  33. TAILQ_HEAD(tmpl_data_array, tmpl_data) data;
  34. };
  35. struct tmpl_data {
  36. TAILQ_HEAD(tmpl_vars, tmpl_var) variables;
  37. TAILQ_HEAD(tmpl_loops, tmpl_loop) loops;
  38. TAILQ_ENTRY(tmpl_data) entry;
  39. };
  40. void tmpl_name_free(struct tmpl_name *);
  41. void tmpl_var_free(struct tmpl_var *);
  42. struct tmpl_var *tmpl_var_new(const char *);
  43. void tmpl_var_set(struct tmpl_var *, const char *);
  44. void tmpl_data_free(struct tmpl_data *);
  45. struct tmpl_data *tmpl_data_new(void);
  46. struct tmpl_var *tmpl_data_get_variable(struct tmpl_data *,
  47. const char *);
  48. void tmpl_data_set_variable(struct tmpl_data *,
  49. const char *, const char *);
  50. struct tmpl_loop *tmpl_data_get_loop(struct tmpl_data *, const char *);
  51. struct tmpl_loop *tmpl_data_add_loop(struct tmpl_data *, const char *);
  52. void tmpl_loop_free(struct tmpl_loop *);
  53. struct tmpl_loop *tmpl_loop_new(const char *);
  54. bool tmpl_loop_isempty(struct tmpl_loop *);
  55. void tmpl_loop_add_data(struct tmpl_loop *,
  56. struct tmpl_data *);
  57. struct buffer_list *tmpl_parse(const char *, size_t _len,
  58. struct tmpl_data *);
  59. struct buffer_list *tmpl_parse_file(const char *, struct tmpl_data *);
  60. #endif // _TEMPLATE_H_