template.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_var_setn(struct tmpl_var *, const char *, size_t);
  45. void tmpl_data_free(struct tmpl_data *);
  46. struct tmpl_data *tmpl_data_new(void);
  47. struct tmpl_var *tmpl_data_get_variable(struct tmpl_data *,
  48. const char *);
  49. void tmpl_data_set_variable(struct tmpl_data *,
  50. const char *, const char *);
  51. void tmpl_data_set_variablen(struct tmpl_data *,
  52. const char *, const char *, size_t);
  53. void tmpl_data_move_variable(struct tmpl_data *,
  54. const char *, char *);
  55. struct tmpl_loop *tmpl_data_get_loop(struct tmpl_data *, const char *);
  56. struct tmpl_loop *tmpl_data_add_loop(struct tmpl_data *, const char *);
  57. void tmpl_data_set_loop(struct tmpl_data *, const char *,
  58. struct tmpl_loop *);
  59. void tmpl_loop_free(struct tmpl_loop *);
  60. struct tmpl_loop *tmpl_loop_new(const char *);
  61. bool tmpl_loop_isempty(struct tmpl_loop *);
  62. void tmpl_loop_add_data(struct tmpl_loop *,
  63. struct tmpl_data *);
  64. struct buffer_list *tmpl_parse(const char *, size_t _len,
  65. struct tmpl_data *);
  66. struct buffer_list *tmpl_parse_file(const char *, struct tmpl_data *);
  67. #endif // __TEMPLATE_H__