1
0

history_entry.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* tinyrl_history_entry.c */
  2. #include "private.h"
  3. #include "lub/string.h"
  4. #include <stdlib.h>
  5. struct _tinyrl_history_entry {
  6. char *line;
  7. unsigned index;
  8. };
  9. /*------------------------------------- */
  10. static void
  11. entry_init(tinyrl_history_entry_t * this, const char *line, unsigned index)
  12. {
  13. this->line = lub_string_dup(line);
  14. this->index = index;
  15. }
  16. /*------------------------------------- */
  17. static void entry_fini(tinyrl_history_entry_t * this)
  18. {
  19. lub_string_free(this->line);
  20. this->line = NULL;
  21. }
  22. /*------------------------------------- */
  23. tinyrl_history_entry_t *tinyrl_history_entry_new(const char *line,
  24. unsigned index)
  25. {
  26. tinyrl_history_entry_t *this = malloc(sizeof(tinyrl_history_entry_t));
  27. if (NULL != this) {
  28. entry_init(this, line, index);
  29. }
  30. return this;
  31. }
  32. /*------------------------------------- */
  33. void tinyrl_history_entry_delete(tinyrl_history_entry_t * this)
  34. {
  35. entry_fini(this);
  36. free(this);
  37. }
  38. /*------------------------------------- */
  39. const char *tinyrl_history_entry__get_line(const tinyrl_history_entry_t * this)
  40. {
  41. return this->line;
  42. }
  43. /*------------------------------------- */
  44. unsigned tinyrl_history_entry__get_index(const tinyrl_history_entry_t * this)
  45. {
  46. return this->index;
  47. }
  48. /*------------------------------------- */