Add the bstr history APIs

Trying out an opaque handle style
This commit is contained in:
Aaron Cook 2024-05-13 00:10:01 -05:00
commit 0ecb1bab0c
2 changed files with 108 additions and 0 deletions

View file

@ -4,9 +4,37 @@
#include <stdarg.h>
#include <stdio.h>
typedef struct bstr_history_struct * bstr_history_handle;
/* printf onto the end of base, reallocating and returning that buffer
* can provide NULL for no base */
__attribute__((format(printf, 2, 3)))
char *bstr_print(char *base, const char *fmt, ...);
/* Create a new bstr_history struct. The position of the history will start as
* unset. */
bstr_history_handle bstr_history_create(void);
/* return the string at the current history position (NULL if empty or position
* is not set) */
const char *bstr_history_atpos(bstr_history_handle hist);
/* Put a new entry into the history */
void bstr_history_new_entry(bstr_history_handle hist, const char *str);
/* Move the postition index one entry older. If the history position is unset,
* it is set to the newest entry. */
void bstr_history_older(bstr_history_handle hist);
/* Move the position index one entry newer. If the position is at the newest
* entry, it becomes unset. If the position is unset, it stays unset. */
void bstr_history_newer(bstr_history_handle hist);
/* Unset the history position index */
void bstr_history_unset_pos(bstr_history_handle hist);
/* destroy/free a bstr_history */
void bstr_history_destroy(bstr_history_handle hist);
#endif /* _BSTR_H_ */