|
@@ -13,61 +13,55 @@
|
|
|
|
|
|
#include "tinyrl/history.h"
|
|
|
|
|
|
-struct _tinyrl_history
|
|
|
-{
|
|
|
- tinyrl_history_entry_t **entries;
|
|
|
- unsigned length;
|
|
|
- unsigned size;
|
|
|
- unsigned current_index;
|
|
|
- unsigned stifle;
|
|
|
+struct _tinyrl_history {
|
|
|
+ tinyrl_history_entry_t **entries;
|
|
|
+ unsigned length;
|
|
|
+ unsigned size;
|
|
|
+ unsigned current_index;
|
|
|
+ unsigned stifle;
|
|
|
};
|
|
|
|
|
|
|
|
|
-void
|
|
|
-tinyrl_history_init(tinyrl_history_t *this,
|
|
|
- unsigned stifle)
|
|
|
+void tinyrl_history_init(tinyrl_history_t * this, unsigned stifle)
|
|
|
{
|
|
|
- this->entries = NULL;
|
|
|
- this->stifle = stifle;
|
|
|
- this->current_index = 1;
|
|
|
- this->length = 0;
|
|
|
- this->size = 0;
|
|
|
+ this->entries = NULL;
|
|
|
+ this->stifle = stifle;
|
|
|
+ this->current_index = 1;
|
|
|
+ this->length = 0;
|
|
|
+ this->size = 0;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-void
|
|
|
-tinyrl_history_fini(tinyrl_history_t *this)
|
|
|
+void tinyrl_history_fini(tinyrl_history_t * this)
|
|
|
{
|
|
|
- tinyrl_history_entry_t *entry;
|
|
|
- tinyrl_history_iterator_t iter;
|
|
|
-
|
|
|
-
|
|
|
- for(entry = tinyrl_history_getfirst(this,&iter);
|
|
|
- entry;
|
|
|
- entry = tinyrl_history_getnext(&iter))
|
|
|
- {
|
|
|
- tinyrl_history_entry_delete(entry);
|
|
|
- }
|
|
|
-
|
|
|
- free(this->entries);
|
|
|
- this->entries = NULL;
|
|
|
+ tinyrl_history_entry_t *entry;
|
|
|
+ tinyrl_history_iterator_t iter;
|
|
|
+
|
|
|
+
|
|
|
+ for (entry = tinyrl_history_getfirst(this, &iter);
|
|
|
+ entry; entry = tinyrl_history_getnext(&iter)) {
|
|
|
+ tinyrl_history_entry_delete(entry);
|
|
|
+ }
|
|
|
+
|
|
|
+ free(this->entries);
|
|
|
+ this->entries = NULL;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-tinyrl_history_t *
|
|
|
-tinyrl_history_new(unsigned stifle)
|
|
|
+tinyrl_history_t *tinyrl_history_new(unsigned stifle)
|
|
|
{
|
|
|
- tinyrl_history_t *this = malloc(sizeof(tinyrl_history_t));
|
|
|
- if(NULL != this)
|
|
|
- {
|
|
|
- tinyrl_history_init(this,stifle);
|
|
|
- }
|
|
|
- return this;
|
|
|
+ tinyrl_history_t *this = malloc(sizeof(tinyrl_history_t));
|
|
|
+ if (NULL != this) {
|
|
|
+ tinyrl_history_init(this, stifle);
|
|
|
+ }
|
|
|
+ return this;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-void
|
|
|
-tinyrl_history_delete(tinyrl_history_t *this)
|
|
|
+void tinyrl_history_delete(tinyrl_history_t * this)
|
|
|
{
|
|
|
- tinyrl_history_fini(this);
|
|
|
- free(this);
|
|
|
+ tinyrl_history_fini(this);
|
|
|
+ free(this);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -75,18 +69,17 @@ HISTORY LIST MANAGEMENT
|
|
|
*/
|
|
|
|
|
|
|
|
|
-static void
|
|
|
-insert_entry(tinyrl_history_t *this,
|
|
|
- const char *line)
|
|
|
+static void insert_entry(tinyrl_history_t * this, const char *line)
|
|
|
{
|
|
|
- tinyrl_history_entry_t *new_entry = tinyrl_history_entry_new(line,this->current_index++);
|
|
|
- assert(this->length);
|
|
|
- assert(this->entries);
|
|
|
- if(new_entry)
|
|
|
- {
|
|
|
- this->entries[this->length-1] = new_entry;
|
|
|
- }
|
|
|
+ tinyrl_history_entry_t *new_entry =
|
|
|
+ tinyrl_history_entry_new(line, this->current_index++);
|
|
|
+ assert(this->length);
|
|
|
+ assert(this->entries);
|
|
|
+ if (new_entry) {
|
|
|
+ this->entries[this->length - 1] = new_entry;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
* This frees the specified entries from the
|
|
@@ -94,23 +87,19 @@ insert_entry(tinyrl_history_t *this,
|
|
|
* This function is inclusive of start and end
|
|
|
*/
|
|
|
static void
|
|
|
-free_entries(const tinyrl_history_t *this,
|
|
|
- unsigned start,
|
|
|
- unsigned end)
|
|
|
+free_entries(const tinyrl_history_t * this, unsigned start, unsigned end)
|
|
|
{
|
|
|
- unsigned i;
|
|
|
- assert(start <= end);
|
|
|
- assert(end < this->length);
|
|
|
-
|
|
|
- for(i = start;
|
|
|
- i <= end;
|
|
|
- i++)
|
|
|
- {
|
|
|
- tinyrl_history_entry_t *entry = this->entries[i];
|
|
|
- tinyrl_history_entry_delete(entry);
|
|
|
- entry = NULL;
|
|
|
- }
|
|
|
+ unsigned i;
|
|
|
+ assert(start <= end);
|
|
|
+ assert(end < this->length);
|
|
|
+
|
|
|
+ for (i = start; i <= end; i++) {
|
|
|
+ tinyrl_history_entry_t *entry = this->entries[i];
|
|
|
+ tinyrl_history_entry_delete(entry);
|
|
|
+ entry = NULL;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
* This removes the specified entries from the
|
|
@@ -118,344 +107,306 @@ free_entries(const tinyrl_history_t *this,
|
|
|
* This function is inclusive of start and end
|
|
|
*/
|
|
|
static void
|
|
|
-remove_entries(tinyrl_history_t *this,
|
|
|
- unsigned start,
|
|
|
- unsigned end)
|
|
|
+remove_entries(tinyrl_history_t * this, unsigned start, unsigned end)
|
|
|
{
|
|
|
- unsigned delta = (end - start) + 1;
|
|
|
-
|
|
|
- unsigned num_entries = (this->length - end) - 1;
|
|
|
- assert(start <= end);
|
|
|
- assert(end < this->length);
|
|
|
-
|
|
|
- if(num_entries)
|
|
|
- {
|
|
|
-
|
|
|
- memmove(&this->entries[start],
|
|
|
- &this->entries[end+1],
|
|
|
- sizeof(tinyrl_history_entry_t *) * num_entries);
|
|
|
- }
|
|
|
-
|
|
|
- this->length -= delta;
|
|
|
+ unsigned delta = (end - start) + 1;
|
|
|
+
|
|
|
+ unsigned num_entries = (this->length - end) - 1;
|
|
|
+ assert(start <= end);
|
|
|
+ assert(end < this->length);
|
|
|
+
|
|
|
+ if (num_entries) {
|
|
|
+
|
|
|
+ memmove(&this->entries[start],
|
|
|
+ &this->entries[end + 1],
|
|
|
+ sizeof(tinyrl_history_entry_t *) * num_entries);
|
|
|
+ }
|
|
|
+
|
|
|
+ this->length -= delta;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
Search the current history buffer for the specified
|
|
|
line and if found remove it.
|
|
|
*/
|
|
|
-static bool_t
|
|
|
-remove_duplicate(tinyrl_history_t *this,
|
|
|
- const char *line)
|
|
|
+static bool_t remove_duplicate(tinyrl_history_t * this, const char *line)
|
|
|
{
|
|
|
- bool_t result = BOOL_FALSE;
|
|
|
- unsigned i;
|
|
|
-
|
|
|
- for(i = 0;
|
|
|
- i < this->length;
|
|
|
- i++)
|
|
|
- {
|
|
|
- tinyrl_history_entry_t *entry = this->entries[i];
|
|
|
- if(0 == strcmp(line,tinyrl_history_entry__get_line(entry)))
|
|
|
- {
|
|
|
- free_entries(this,i,i);
|
|
|
- remove_entries(this,i,i);
|
|
|
- result = BOOL_TRUE;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
+ bool_t result = BOOL_FALSE;
|
|
|
+ unsigned i;
|
|
|
+
|
|
|
+ for (i = 0; i < this->length; i++) {
|
|
|
+ tinyrl_history_entry_t *entry = this->entries[i];
|
|
|
+ if (0 == strcmp(line, tinyrl_history_entry__get_line(entry))) {
|
|
|
+ free_entries(this, i, i);
|
|
|
+ remove_entries(this, i, i);
|
|
|
+ result = BOOL_TRUE;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
add an entry to the end of the current array
|
|
|
if there is no space returns -1 else 0
|
|
|
*/
|
|
|
-static void
|
|
|
-append_entry(tinyrl_history_t *this,
|
|
|
- const char *line)
|
|
|
+static void append_entry(tinyrl_history_t * this, const char *line)
|
|
|
{
|
|
|
- if(this->length < this->size)
|
|
|
- {
|
|
|
- this->length++;
|
|
|
+ if (this->length < this->size) {
|
|
|
+ this->length++;
|
|
|
|
|
|
- insert_entry(this,line);
|
|
|
- }
|
|
|
+ insert_entry(this, line);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
add a new history entry replacing the oldest one
|
|
|
*/
|
|
|
-static void
|
|
|
-add_n_replace(tinyrl_history_t *this,
|
|
|
- const char *line)
|
|
|
+static void add_n_replace(tinyrl_history_t * this, const char *line)
|
|
|
{
|
|
|
- if(BOOL_FALSE == remove_duplicate(this,line))
|
|
|
- {
|
|
|
-
|
|
|
- free_entries(this,0,0);
|
|
|
-
|
|
|
- remove_entries(this,0,0);
|
|
|
- }
|
|
|
-
|
|
|
- append_entry(this,line);
|
|
|
+ if (BOOL_FALSE == remove_duplicate(this, line)) {
|
|
|
+
|
|
|
+ free_entries(this, 0, 0);
|
|
|
+
|
|
|
+ remove_entries(this, 0, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ append_entry(this, line);
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
-static void
|
|
|
-add_n_grow(tinyrl_history_t *this,
|
|
|
- const char *line)
|
|
|
+static void add_n_grow(tinyrl_history_t * this, const char *line)
|
|
|
{
|
|
|
- if(this->size == this->length)
|
|
|
- {
|
|
|
-
|
|
|
- unsigned new_size = this->size + 10;
|
|
|
- size_t nbytes;
|
|
|
- tinyrl_history_entry_t **new_entries;
|
|
|
-
|
|
|
- nbytes = sizeof(tinyrl_history_entry_t *)*new_size;
|
|
|
- new_entries = realloc(this->entries,nbytes);
|
|
|
- if(NULL != new_entries)
|
|
|
- {
|
|
|
- this->size = new_size;
|
|
|
- this->entries = new_entries;
|
|
|
- }
|
|
|
- }
|
|
|
- (void)remove_duplicate(this,line);
|
|
|
- append_entry(this,line);
|
|
|
+ if (this->size == this->length) {
|
|
|
+
|
|
|
+ unsigned new_size = this->size + 10;
|
|
|
+ size_t nbytes;
|
|
|
+ tinyrl_history_entry_t **new_entries;
|
|
|
+
|
|
|
+ nbytes = sizeof(tinyrl_history_entry_t *) * new_size;
|
|
|
+ new_entries = realloc(this->entries, nbytes);
|
|
|
+ if (NULL != new_entries) {
|
|
|
+ this->size = new_size;
|
|
|
+ this->entries = new_entries;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (void)remove_duplicate(this, line);
|
|
|
+ append_entry(this, line);
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-void
|
|
|
-tinyrl_history_add(tinyrl_history_t *this,
|
|
|
- const char *line)
|
|
|
+void tinyrl_history_add(tinyrl_history_t * this, const char *line)
|
|
|
{
|
|
|
- if(this->length && (this->length == this->stifle))
|
|
|
- {
|
|
|
- add_n_replace(this,line);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- add_n_grow(this,line);
|
|
|
- }
|
|
|
+ if (this->length && (this->length == this->stifle)) {
|
|
|
+ add_n_replace(this, line);
|
|
|
+ } else {
|
|
|
+ add_n_grow(this, line);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-tinyrl_history_entry_t *
|
|
|
-tinyrl_history_remove(tinyrl_history_t *this,
|
|
|
- unsigned offset)
|
|
|
+tinyrl_history_entry_t *tinyrl_history_remove(tinyrl_history_t * this,
|
|
|
+ unsigned offset)
|
|
|
{
|
|
|
- tinyrl_history_entry_t *result = NULL;
|
|
|
-
|
|
|
- if(offset < this->length)
|
|
|
- {
|
|
|
- result = this->entries[offset];
|
|
|
-
|
|
|
- remove_entries(this,offset,offset);
|
|
|
- }
|
|
|
- return result;
|
|
|
+ tinyrl_history_entry_t *result = NULL;
|
|
|
+
|
|
|
+ if (offset < this->length) {
|
|
|
+ result = this->entries[offset];
|
|
|
+
|
|
|
+ remove_entries(this, offset, offset);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-void
|
|
|
-tinyrl_history_clear(tinyrl_history_t *this)
|
|
|
+void tinyrl_history_clear(tinyrl_history_t * this)
|
|
|
{
|
|
|
-
|
|
|
- free_entries(this,0,this->length-1);
|
|
|
-
|
|
|
- remove_entries(this,0,this->length-1);
|
|
|
+
|
|
|
+ free_entries(this, 0, this->length - 1);
|
|
|
+
|
|
|
+ remove_entries(this, 0, this->length - 1);
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-void
|
|
|
-tinyrl_history_stifle(tinyrl_history_t *this,
|
|
|
- unsigned stifle)
|
|
|
+void tinyrl_history_stifle(tinyrl_history_t * this, unsigned stifle)
|
|
|
{
|
|
|
-
|
|
|
- * if we are stifling (i.e. non zero value) then
|
|
|
- * delete the obsolete entries
|
|
|
- */
|
|
|
- if(stifle)
|
|
|
- {
|
|
|
- if(stifle < this->length)
|
|
|
- {
|
|
|
- unsigned num_deletes = this->length - stifle;
|
|
|
-
|
|
|
- free_entries(this,0,num_deletes-1);
|
|
|
-
|
|
|
- remove_entries(this,0,num_deletes-1);
|
|
|
- }
|
|
|
- this->stifle = stifle;
|
|
|
- }
|
|
|
+
|
|
|
+ * if we are stifling (i.e. non zero value) then
|
|
|
+ * delete the obsolete entries
|
|
|
+ */
|
|
|
+ if (stifle) {
|
|
|
+ if (stifle < this->length) {
|
|
|
+ unsigned num_deletes = this->length - stifle;
|
|
|
+
|
|
|
+ free_entries(this, 0, num_deletes - 1);
|
|
|
+
|
|
|
+ remove_entries(this, 0, num_deletes - 1);
|
|
|
+ }
|
|
|
+ this->stifle = stifle;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-unsigned
|
|
|
-tinyrl_history_unstifle(tinyrl_history_t *this)
|
|
|
+unsigned tinyrl_history_unstifle(tinyrl_history_t * this)
|
|
|
{
|
|
|
- unsigned result = this->stifle;
|
|
|
+ unsigned result = this->stifle;
|
|
|
|
|
|
- this->stifle = 0;
|
|
|
+ this->stifle = 0;
|
|
|
|
|
|
- return result;
|
|
|
+ return result;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-bool_t
|
|
|
-tinyrl_history_is_stifled(const tinyrl_history_t *this)
|
|
|
+bool_t tinyrl_history_is_stifled(const tinyrl_history_t * this)
|
|
|
{
|
|
|
- return this->stifle ? BOOL_TRUE : BOOL_FALSE;
|
|
|
+ return this->stifle ? BOOL_TRUE : BOOL_FALSE;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
INFORMATION ABOUT THE HISTORY LIST
|
|
|
-*/
|
|
|
-tinyrl_history_entry_t *
|
|
|
-tinyrl_history_get(const tinyrl_history_t *this,
|
|
|
- unsigned position)
|
|
|
+*/
|
|
|
+tinyrl_history_entry_t *tinyrl_history_get(const tinyrl_history_t * this,
|
|
|
+ unsigned position)
|
|
|
{
|
|
|
- unsigned i;
|
|
|
- tinyrl_history_entry_t *entry = NULL;
|
|
|
- for(i = 0;
|
|
|
- i < this->length;
|
|
|
- i++)
|
|
|
- {
|
|
|
- entry = this->entries[i];
|
|
|
- if(position == tinyrl_history_entry__get_index(entry))
|
|
|
- {
|
|
|
-
|
|
|
- break;
|
|
|
- }
|
|
|
- entry = NULL;
|
|
|
- }
|
|
|
- return entry;
|
|
|
+ unsigned i;
|
|
|
+ tinyrl_history_entry_t *entry = NULL;
|
|
|
+ for (i = 0; i < this->length; i++) {
|
|
|
+ entry = this->entries[i];
|
|
|
+ if (position == tinyrl_history_entry__get_index(entry)) {
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ entry = NULL;
|
|
|
+ }
|
|
|
+ return entry;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
tinyrl_history_expand_t
|
|
|
-tinyrl_history_expand(const tinyrl_history_t *this,
|
|
|
- const char *string,
|
|
|
- char **output)
|
|
|
+tinyrl_history_expand(const tinyrl_history_t * this,
|
|
|
+ const char *string, char **output)
|
|
|
{
|
|
|
- tinyrl_history_expand_t result = tinyrl_history_NO_EXPANSION;
|
|
|
- const char *p,*start;
|
|
|
- char *buffer = NULL;
|
|
|
- unsigned len;
|
|
|
-
|
|
|
- for(p = string,start=string,len=0;
|
|
|
- *p;
|
|
|
- p++,len++)
|
|
|
- {
|
|
|
-
|
|
|
- if(*p == '!')
|
|
|
- {
|
|
|
-
|
|
|
- unsigned offset = this->current_index - 1;
|
|
|
- unsigned skip;
|
|
|
- tinyrl_history_entry_t *entry;
|
|
|
-
|
|
|
-
|
|
|
- if(p[1] != '!')
|
|
|
- {
|
|
|
- int tmp;
|
|
|
- int res;
|
|
|
-
|
|
|
- res = sscanf(p,"!%d",&tmp);
|
|
|
- if((0 == res) || (EOF == res))
|
|
|
- {
|
|
|
-
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if(tmp < 0)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- offset += tmp;
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- offset = (unsigned)tmp;
|
|
|
- }
|
|
|
- }
|
|
|
- if(len > 0)
|
|
|
- {
|
|
|
-
|
|
|
- lub_string_catn(&buffer,start,len);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- p += skip = strspn(p,"!-0123456789");
|
|
|
-
|
|
|
-
|
|
|
- entry = tinyrl_history_get(this,offset);
|
|
|
- if(NULL != entry)
|
|
|
- {
|
|
|
-
|
|
|
- start = p;
|
|
|
- len = 0;
|
|
|
-
|
|
|
- result = tinyrl_history_EXPANDED;
|
|
|
- lub_string_cat(&buffer,tinyrl_history_entry__get_line(entry));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- len += skip;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- lub_string_catn(&buffer,start,len);
|
|
|
- *output = buffer;
|
|
|
-
|
|
|
- return result;
|
|
|
+ tinyrl_history_expand_t result = tinyrl_history_NO_EXPANSION;
|
|
|
+ const char *p, *start;
|
|
|
+ char *buffer = NULL;
|
|
|
+ unsigned len;
|
|
|
+
|
|
|
+ for (p = string, start = string, len = 0; *p; p++, len++) {
|
|
|
+
|
|
|
+ if (*p == '!') {
|
|
|
+
|
|
|
+ unsigned offset = this->current_index - 1;
|
|
|
+ unsigned skip;
|
|
|
+ tinyrl_history_entry_t *entry;
|
|
|
+
|
|
|
+
|
|
|
+ if (p[1] != '!') {
|
|
|
+ int tmp;
|
|
|
+ int res;
|
|
|
+
|
|
|
+ res = sscanf(p, "!%d", &tmp);
|
|
|
+ if ((0 == res) || (EOF == res)) {
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tmp < 0) {
|
|
|
+
|
|
|
+
|
|
|
+ offset += tmp;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ offset = (unsigned)tmp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (len > 0) {
|
|
|
+
|
|
|
+ lub_string_catn(&buffer, start, len);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ p += skip = strspn(p, "!-0123456789");
|
|
|
+
|
|
|
+
|
|
|
+ entry = tinyrl_history_get(this, offset);
|
|
|
+ if (NULL != entry) {
|
|
|
+
|
|
|
+ start = p;
|
|
|
+ len = 0;
|
|
|
+
|
|
|
+ result = tinyrl_history_EXPANDED;
|
|
|
+ lub_string_cat(&buffer,
|
|
|
+ tinyrl_history_entry__get_line
|
|
|
+ (entry));
|
|
|
+ } else {
|
|
|
+
|
|
|
+ len += skip;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lub_string_catn(&buffer, start, len);
|
|
|
+ *output = buffer;
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-tinyrl_history_entry_t *
|
|
|
-tinyrl_history_getfirst(const tinyrl_history_t *this,
|
|
|
- tinyrl_history_iterator_t *iter)
|
|
|
+tinyrl_history_entry_t *tinyrl_history_getfirst(const tinyrl_history_t * this,
|
|
|
+ tinyrl_history_iterator_t *
|
|
|
+ iter)
|
|
|
{
|
|
|
- tinyrl_history_entry_t *result = NULL;
|
|
|
+ tinyrl_history_entry_t *result = NULL;
|
|
|
|
|
|
- iter->history = this;
|
|
|
- iter->offset = 0;
|
|
|
+ iter->history = this;
|
|
|
+ iter->offset = 0;
|
|
|
|
|
|
- if(this->length)
|
|
|
- {
|
|
|
- result = this->entries[iter->offset];
|
|
|
- }
|
|
|
- return result;
|
|
|
+ if (this->length) {
|
|
|
+ result = this->entries[iter->offset];
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-tinyrl_history_entry_t *
|
|
|
-tinyrl_history_getnext(tinyrl_history_iterator_t *iter)
|
|
|
+tinyrl_history_entry_t *tinyrl_history_getnext(tinyrl_history_iterator_t * iter)
|
|
|
{
|
|
|
- tinyrl_history_entry_t *result = NULL;
|
|
|
+ tinyrl_history_entry_t *result = NULL;
|
|
|
|
|
|
- if(iter->offset < iter->history->length - 1)
|
|
|
- {
|
|
|
- iter->offset++;
|
|
|
- result = iter->history->entries[iter->offset];
|
|
|
- }
|
|
|
+ if (iter->offset < iter->history->length - 1) {
|
|
|
+ iter->offset++;
|
|
|
+ result = iter->history->entries[iter->offset];
|
|
|
+ }
|
|
|
|
|
|
- return result;
|
|
|
+ return result;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-tinyrl_history_entry_t *
|
|
|
-tinyrl_history_getlast (const tinyrl_history_t *this,
|
|
|
- tinyrl_history_iterator_t *iter)
|
|
|
+tinyrl_history_entry_t *tinyrl_history_getlast(const tinyrl_history_t * this,
|
|
|
+ tinyrl_history_iterator_t * iter)
|
|
|
{
|
|
|
- iter->history = this;
|
|
|
- iter->offset = this->length;
|
|
|
-
|
|
|
- return tinyrl_history_getprevious(iter);
|
|
|
+ iter->history = this;
|
|
|
+ iter->offset = this->length;
|
|
|
+
|
|
|
+ return tinyrl_history_getprevious(iter);
|
|
|
}
|
|
|
+
|
|
|
|
|
|
-tinyrl_history_entry_t *
|
|
|
-tinyrl_history_getprevious(tinyrl_history_iterator_t *iter)
|
|
|
+tinyrl_history_entry_t *tinyrl_history_getprevious(tinyrl_history_iterator_t *
|
|
|
+ iter)
|
|
|
{
|
|
|
- tinyrl_history_entry_t *result = NULL;
|
|
|
+ tinyrl_history_entry_t *result = NULL;
|
|
|
|
|
|
- if(iter->offset)
|
|
|
- {
|
|
|
- iter->offset--;
|
|
|
- result = iter->history->entries[iter->offset];
|
|
|
- }
|
|
|
+ if (iter->offset) {
|
|
|
+ iter->offset--;
|
|
|
+ result = iter->history->entries[iter->offset];
|
|
|
+ }
|
|
|
|
|
|
- return result;
|
|
|
+ return result;
|
|
|
}
|
|
|
+
|
|
|
|