history_entry.c 1.4 KB

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