1 /* Header for saving and retrieving history strings */ 2 #ifndef HIST_INFO_H 3 #define HIST_INFO_H 4 5 struct History_info; 6 7 /* Options for history logging */ 8 struct History_info_opt { 9 size_t n_byte_struct; /* sizeof(struct History_info_opt) 10 * Used for possible versioning */ 11 unsigned int n_str_init; /* initial number of allocated string locators 12 * Value must be at least 2 */ 13 unsigned int n_str_max; /* max number of string locators 14 * Value must be at least n_str_init when 15 * initializing but not when changing options. 16 * Then it must be at least 2 */ 17 size_t n_byte_str_buf_init; /* initial size of the string buffer. 18 * Value must be at least 2 */ 19 20 /* If the amount of the buffer for storing strings that is in use 21 * multiplied by oversize_factor is less than the allocated amount, 22 * the buffer for storing strings is reduced by a factor of 2. 23 * Value must be at least 4. 24 * 25 * The first check for an oversized buffer is made after 26 * n_insert_first_oversize_check calls to history_add(). 27 * A value of 0 suppresses checks. 28 * 29 * Subsequent checks are made after n_insert_per_oversize_check calls 30 * to history_add(). 31 * A value of 0 suppresses checks after the first one. 32 */ 33 unsigned int oversize_factor; 34 unsigned int n_insert_first_oversize_check; 35 unsigned int n_insert_per_oversize_check; 36 }; 37 38 39 struct History_info *history_init(struct History_info_opt *p_hi_opt); 40 int history_add(struct History_info **pp_hi, 41 unsigned int n_char_str, const char *str); 42 void history_free(struct History_info *p_hi);\ 43 const char *history_get_newest(struct History_info *p_hi, 44 unsigned int *p_n_char_str); 45 const char *history_get_next(struct History_info *p_hi, 46 unsigned int *p_n_char_str); 47 const char *history_get_prev(struct History_info *p_hi, 48 unsigned int *p_n_char_str); 49 void history_reset_pos(struct History_info *p_hi); 50 int history_getopt(const struct History_info *p_hi, 51 struct History_info_opt *p_hi_opt); 52 int history_setopt(struct History_info **pp_hi, 53 struct History_info_opt *p_hi_opt); 54 55 #endif /* HIST_INFO_H include guard */ 56