p≡p engine FORK
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.

216 lines
4.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. /**
  2. * @file stringlist.h
  3. * @brief stringlist struct builders, accessorsm manipulators
  4. * @license GNU General Public License 3.0 - see LICENSE.txt
  5. */
  6. #ifndef STRINGLIST_H
  7. #define STRINGLIST_H
  8. #include "dynamic_api.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /**
  13. * @struct stringlist_t
  14. *
  15. * @brief TODO
  16. *
  17. */
  18. typedef struct _stringlist_t {
  19. char *value;
  20. struct _stringlist_t *next;
  21. } stringlist_t;
  22. /**
  23. * <!-- new_stringlist() -->
  24. *
  25. * @brief Allocate a new stringlist
  26. *
  27. * @param[in] value initial value as C string or NULL for empty list
  28. *
  29. * @retval pointer to stringlist_t object or NULL if out of memory
  30. *
  31. * @warning the value is being copied before being added to the list
  32. * the original string is still being owned by the caller
  33. * the "next" pointer of the returned object is NULL
  34. *
  35. */
  36. DYNAMIC_API stringlist_t *new_stringlist(const char *value);
  37. /**
  38. * <!-- stringlist_dup() -->
  39. *
  40. * @brief Duplicate a stringlist
  41. *
  42. * @param[in] src stringlist to copy
  43. *
  44. * @retval pointer to stringlist_t object or NULL if out of memory
  45. *
  46. *
  47. */
  48. DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src);
  49. /**
  50. * <!-- stringlist_add() -->
  51. *
  52. * @brief Add key to stringlist
  53. *
  54. * @param[in] stringlist stringlist struct or NULL to create a new one
  55. * @param[in] value value as C string
  56. *
  57. * @retval pointer to last element in stringlist or NULL if out of memory
  58. *
  59. * @warning the value is being copied before being added to the list
  60. * the original string is still being owned by the caller
  61. *
  62. */
  63. DYNAMIC_API stringlist_t *stringlist_add(
  64. stringlist_t *stringlist,
  65. const char *value
  66. );
  67. /**
  68. * <!-- stringlist_add_unique() -->
  69. *
  70. * @brief Add string to stringlist, if not already there
  71. *
  72. * @param[in] stringlist stringlist struct or NULL to create a new one
  73. * @param[in] value value as C string
  74. *
  75. * @retval pointer to last element in stringlist or NULL if out of memory
  76. *
  77. * @warning the value is being copied before being added to the list
  78. * the original string is still being owned by the caller
  79. *
  80. */
  81. DYNAMIC_API stringlist_t *stringlist_add_unique(
  82. stringlist_t *stringlist,
  83. const char *value
  84. );
  85. /**
  86. * <!-- stringlist_append() -->
  87. *
  88. * @brief Append stringlist to stringlist
  89. *
  90. * @param[in] stringlist stringlist struct to append to
  91. * @param[in] second stringlist struct to append
  92. *
  93. * @retval pointer to last element in stringlist or NULL if out of memory
  94. * @retval or stringpair_list is NULL
  95. *
  96. * @warning all values are being copied before being added to the list
  97. * the original values are still being owned by the caller
  98. *
  99. */
  100. DYNAMIC_API stringlist_t *stringlist_append(
  101. stringlist_t *stringlist,
  102. stringlist_t *second
  103. );
  104. /**
  105. * <!-- stringlist_length() -->
  106. *
  107. * @brief Get length of stringlist
  108. *
  109. * @param[in] stringlist stringlist struct to determine length of
  110. *
  111. * @retval length of stringlist in number of elements
  112. *
  113. *
  114. */
  115. DYNAMIC_API int stringlist_length(const stringlist_t *stringlist);
  116. /**
  117. * <!-- stringlist_delete() -->
  118. *
  119. * @brief Delete entry from stringlist
  120. *
  121. * @param[in] stringlist stringlist struct to delete from
  122. * @param[in] value data to delete
  123. *
  124. * @retval modified stringlist
  125. *
  126. *
  127. */
  128. DYNAMIC_API stringlist_t *stringlist_delete(
  129. stringlist_t *stringlist,
  130. const char *value
  131. );
  132. /**
  133. * <!-- free_stringlist() -->
  134. *
  135. * @brief Free memory occupied by stringlist
  136. *
  137. * @param[in] stringlist stringlist to free
  138. *
  139. *
  140. */
  141. DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
  142. /**
  143. * <!-- stringlist_search() -->
  144. *
  145. * @brief TODO
  146. *
  147. * @param[in] head stringlist_t*
  148. * @param[in] value const char*
  149. *
  150. */
  151. stringlist_t* stringlist_search(stringlist_t* head, const char* value);
  152. // create comma-separated string
  153. /**
  154. * <!-- stringlist_to_string() -->
  155. *
  156. * @brief TODO
  157. *
  158. * @param[in] list stringlist_t*
  159. *
  160. */
  161. char* stringlist_to_string(stringlist_t* list);
  162. /**
  163. * <!-- string_to_stringlist() -->
  164. *
  165. * @brief TODO
  166. *
  167. * @param[in] str const char*
  168. *
  169. */
  170. stringlist_t* string_to_stringlist(const char* str);
  171. /**
  172. * <!-- dedup_stringlist() -->
  173. *
  174. * @brief TODO
  175. *
  176. * @param[in] stringlist stringlist_t*
  177. *
  178. */
  179. void dedup_stringlist(stringlist_t* stringlist);
  180. #ifdef __cplusplus
  181. }
  182. #endif
  183. #endif