1
0

config.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. * PRIVATE METHODS
  15. *--------------------------------------------------------- */
  16. static void clish_config_init(clish_config_t *this)
  17. {
  18. this->op = CLISH_CONFIG_NONE;
  19. this->priority = 0;
  20. this->pattern = NULL;
  21. this->file = NULL;
  22. this->splitter = BOOL_TRUE;
  23. this->seq = NULL;
  24. this->unique = BOOL_TRUE;
  25. this->depth = NULL;
  26. }
  27. /*--------------------------------------------------------- */
  28. static void clish_config_fini(clish_config_t *this)
  29. {
  30. lub_string_free(this->pattern);
  31. lub_string_free(this->file);
  32. lub_string_free(this->seq);
  33. lub_string_free(this->depth);
  34. }
  35. /*---------------------------------------------------------
  36. * PUBLIC META FUNCTIONS
  37. *--------------------------------------------------------- */
  38. clish_config_t *clish_config_new(void)
  39. {
  40. clish_config_t *this = malloc(sizeof(clish_config_t));
  41. if (this)
  42. clish_config_init(this);
  43. return this;
  44. }
  45. /*---------------------------------------------------------
  46. * PUBLIC METHODS
  47. *--------------------------------------------------------- */
  48. void clish_config_delete(clish_config_t *this)
  49. {
  50. clish_config_fini(this);
  51. free(this);
  52. }
  53. /*---------------------------------------------------------
  54. * PUBLIC ATTRIBUTES
  55. *--------------------------------------------------------- */
  56. void clish_config__set_op(clish_config_t *this, clish_config_op_e op)
  57. {
  58. this->op = op;
  59. }
  60. /*--------------------------------------------------------- */
  61. clish_config_op_e clish_config__get_op(const clish_config_t *this)
  62. {
  63. return this->op;
  64. }
  65. /*--------------------------------------------------------- */
  66. void clish_config__set_priority(clish_config_t *this, unsigned short priority)
  67. {
  68. this->priority = priority;
  69. }
  70. /*--------------------------------------------------------- */
  71. unsigned short clish_config__get_priority(const clish_config_t *this)
  72. {
  73. return this->priority;
  74. }
  75. /*--------------------------------------------------------- */
  76. void clish_config__set_pattern(clish_config_t *this, const char *pattern)
  77. {
  78. assert(!this->pattern);
  79. this->pattern = lub_string_dup(pattern);
  80. }
  81. /*--------------------------------------------------------- */
  82. char *clish_config__get_pattern(const clish_config_t *this)
  83. {
  84. return this->pattern;
  85. }
  86. /*--------------------------------------------------------- */
  87. void clish_config__set_file(clish_config_t *this, const char *file)
  88. {
  89. assert(!this->file);
  90. this->file = lub_string_dup(file);
  91. }
  92. /*--------------------------------------------------------- */
  93. char *clish_config__get_file(const clish_config_t *this)
  94. {
  95. return this->file;
  96. }
  97. /*--------------------------------------------------------- */
  98. bool_t clish_config__get_splitter(const clish_config_t *this)
  99. {
  100. return this->splitter;
  101. }
  102. /*--------------------------------------------------------- */
  103. void clish_config__set_splitter(clish_config_t *this, bool_t splitter)
  104. {
  105. this->splitter = splitter;
  106. }
  107. /*--------------------------------------------------------- */
  108. void clish_config__set_seq(clish_config_t *this, const char *seq)
  109. {
  110. assert(!this->seq);
  111. this->seq = lub_string_dup(seq);
  112. }
  113. /*--------------------------------------------------------- */
  114. const char *clish_config__get_seq(const clish_config_t *this)
  115. {
  116. return this->seq;
  117. }
  118. /*--------------------------------------------------------- */
  119. bool_t clish_config__get_unique(const clish_config_t *this)
  120. {
  121. return this->unique;
  122. }
  123. /*--------------------------------------------------------- */
  124. void clish_config__set_unique(clish_config_t *this, bool_t unique)
  125. {
  126. this->unique = unique;
  127. }
  128. /*--------------------------------------------------------- */
  129. void clish_config__set_depth(clish_config_t *this, const char *depth)
  130. {
  131. assert(!this->depth);
  132. this->depth = lub_string_dup(depth);
  133. }
  134. /*--------------------------------------------------------- */
  135. const char *clish_config__get_depth(const clish_config_t *this)
  136. {
  137. return this->depth;
  138. }