history.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. \ingroup tinyrl
  3. \defgroup tinyrl_history history
  4. @{
  5. \brief This class handles the maintenance of a historical list of command lines.
  6. */
  7. #ifndef _tinyrl_history_h
  8. #define _tinyrl_history_h
  9. #include "lub/c_decl.h"
  10. #include "lub/types.h"
  11. _BEGIN_C_DECL
  12. /**************************************
  13. * tinyrl_history_entry class interface
  14. ************************************** */
  15. typedef struct _tinyrl_history_entry tinyrl_history_entry_t;
  16. extern const char *tinyrl_history_entry__get_line(const tinyrl_history_entry_t *
  17. instance);
  18. extern unsigned tinyrl_history_entry__get_index(const tinyrl_history_entry_t *
  19. instance);
  20. /**************************************
  21. * tinyrl_history class interface
  22. ************************************** */
  23. typedef struct _tinyrl_history tinyrl_history_t;
  24. /**
  25. * This type is used for the iteration of history entries
  26. */
  27. typedef struct _tinyrl_history_iterator tinyrl_history_iterator_t;
  28. /**
  29. * CLIENTS MUST NOT USE THESE FIELDS DIRECTLY
  30. */
  31. struct _tinyrl_history_iterator {
  32. const tinyrl_history_t *history;
  33. unsigned offset;
  34. };
  35. extern tinyrl_history_t *tinyrl_history_new(unsigned stifle);
  36. extern void tinyrl_history_delete(tinyrl_history_t * instance);
  37. extern void tinyrl_history_add(tinyrl_history_t * instance, const char *line);
  38. extern tinyrl_history_entry_t *tinyrl_history_getfirst(const tinyrl_history_t *
  39. instance,
  40. tinyrl_history_iterator_t
  41. * iter);
  42. extern tinyrl_history_entry_t *tinyrl_history_getlast(const tinyrl_history_t *
  43. instance,
  44. tinyrl_history_iterator_t
  45. * iter);
  46. extern tinyrl_history_entry_t *tinyrl_history_getnext(tinyrl_history_iterator_t
  47. * iter);
  48. extern tinyrl_history_entry_t
  49. *tinyrl_history_getprevious(tinyrl_history_iterator_t * iter);
  50. /*
  51. HISTORY LIST MANAGEMENT
  52. */
  53. extern tinyrl_history_entry_t *tinyrl_history_remove(tinyrl_history_t *
  54. instance, unsigned offset);
  55. extern void tinyrl_history_clear(tinyrl_history_t * instance);
  56. extern void tinyrl_history_stifle(tinyrl_history_t * instance, unsigned stifle);
  57. extern unsigned tinyrl_history_unstifle(tinyrl_history_t * instance);
  58. extern bool_t tinyrl_history_is_stifled(const tinyrl_history_t * instance);
  59. extern int tinyrl_history_save(const tinyrl_history_t *instance, const char *fname);
  60. extern int tinyrl_history_restore(tinyrl_history_t *instance, const char *fname);
  61. /*
  62. INFORMATION ABOUT THE HISTORY LIST
  63. */
  64. extern tinyrl_history_entry_t **tinyrl_history_list(const tinyrl_history_t *
  65. instance);
  66. extern tinyrl_history_entry_t *tinyrl_history_get(const tinyrl_history_t *
  67. instance, unsigned offset);
  68. /*
  69. * HISTORY EXPANSION
  70. */
  71. typedef enum {
  72. tinyrl_history_NO_EXPANSION,
  73. tinyrl_history_EXPANDED
  74. } tinyrl_history_expand_t;
  75. extern tinyrl_history_expand_t
  76. tinyrl_history_expand(const tinyrl_history_t * instance,
  77. const char *string, char **output);
  78. _END_C_DECL
  79. #endif /* _tinyrl_history_h */
  80. /** @} tinyrl_history */