/* Header file for history array * * by Bryce Schroeder. */ #ifndef _HISTORY_ARRAY_H_ #define _HISTORY_ARRAY_H_ #include #define HISTORY_WIDTH 120 #include #include #include /* Example of the circular array after filling with eight elements a-h * 0: a Suppose we add a new element j. * 1: b We want to replace the oldest element * 2: c This is a. But since it is the second from last we want to * 3: d list it as the second, not the last. So we move 'tail' from * 4: e 0 to 1. Now the logical order is still b-j but the physical * 5: f order is j,b-h. * 6: g * 7: h */ /* This structure describes a history array instance. * * * * current: the number of insertions. * * size: the maxiumum size of the cirular array */ typedef struct { //size_t tail; size_t size; size_t current; char **content; } history_array_t; /* Create a new history array (allocates new memory) * * size: how many items will the circular array hold? */ history_array_t *history_new (size_t size); /* Dispose of a history array. (frees memory allocated by the constructor) * * history: the array to be deallocated. */ void history_free (history_array_t *history); /* Add a new item to the history array. A local copy will be made. * * history: the array to add the item to. * * item: the string which is to be copied into the array. */ void history_append(history_array_t *history, const char *item); /* Get an item from the history. The pointer is read-only. * * history: the array to get the item from. * * index: the logical index of the item (in the order inserted, from 0.) */ const char *history_get (history_array_t *history, size_t index); /* Get the size of a history array. * * history: the array to get the size of. */ size_t history_size (history_array_t *history); /* Get the current number of items of a history array. * * history: the array to get the size of. */ size_t history_len (history_array_t *history); /* Check to see if the string is present in a history array. * * history: the history array to be checked * * item: the string to be searched for. */ int history_check (history_array_t *history, const char *item); /* Show the items in a history array by logical index. * * history: the array to show. */ void history_show (history_array_t *history); #endif /* _HISTORY_ARRAY_H_ */