config.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * config.c
  3. *
  4. * This file provides the implementation of a config definition
  5. */
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <assert.h>
  9. #include <string.h>
  10. #include "lub/types.h"
  11. #include "lub/string.h"
  12. #include "private.h"
  13. /*--------------------------------------------------------- */
  14. static void clish_config_init(clish_config_t *this)
  15. {
  16. this->op = CLISH_CONFIG_NONE;
  17. this->priority = 0;
  18. this->pattern = NULL;
  19. this->file = NULL;
  20. this->splitter = BOOL_TRUE;
  21. this->seq = NULL;
  22. this->unique = BOOL_TRUE;
  23. this->depth = NULL;
  24. }
  25. /*--------------------------------------------------------- */
  26. static void clish_config_fini(clish_config_t *this)
  27. {
  28. lub_string_free(this->pattern);
  29. lub_string_free(this->file);
  30. lub_string_free(this->seq);
  31. lub_string_free(this->depth);
  32. }
  33. /*--------------------------------------------------------- */
  34. clish_config_t *clish_config_new(void)
  35. {
  36. clish_config_t *this = malloc(sizeof(clish_config_t));
  37. if (this)
  38. clish_config_init(this);
  39. return this;
  40. }
  41. /*--------------------------------------------------------- */
  42. void clish_config_delete(clish_config_t *this)
  43. {
  44. clish_config_fini(this);
  45. free(this);
  46. }
  47. CLISH_SET(config, clish_config_op_e, op);
  48. CLISH_GET(config, clish_config_op_e, op);
  49. CLISH_SET(config, unsigned short, priority);
  50. CLISH_GET(config, unsigned short, priority);
  51. CLISH_SET(config, bool_t, splitter);
  52. CLISH_GET(config, bool_t, splitter);
  53. CLISH_SET(config, bool_t, unique);
  54. CLISH_GET(config, bool_t, unique);
  55. CLISH_SET_STR_ONCE(config, pattern);
  56. CLISH_GET_STR(config, pattern);
  57. CLISH_SET_STR_ONCE(config, file);
  58. CLISH_GET_STR(config, file);
  59. CLISH_SET_STR_ONCE(config, seq);
  60. CLISH_GET_STR(config, seq);
  61. CLISH_SET_STR_ONCE(config, depth);
  62. CLISH_GET_STR(config, depth);