From b348e3f390cd129f76eb4a0e65e08f7255a0c1bf Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 11 Mar 2013 03:31:19 +0100 Subject: [PATCH] Rename ptr member to more sensible name 'size' and kill rgui_list_size --- frontend/menu/rgui.c | 22 +++++++++++----------- frontend/menu/utils/file_list.c | 33 ++++++++++++++------------------- frontend/menu/utils/file_list.h | 1 - 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/frontend/menu/rgui.c b/frontend/menu/rgui.c index a67bf72d41..59c5bbb169 100644 --- a/frontend/menu/rgui.c +++ b/frontend/menu/rgui.c @@ -389,8 +389,8 @@ static void render_text(rgui_handle_t *rgui) size_t begin = rgui->directory_ptr >= TERM_HEIGHT / 2 ? rgui->directory_ptr - TERM_HEIGHT / 2 : 0; - size_t end = rgui->directory_ptr + TERM_HEIGHT <= rgui_list_size(rgui->folder_buf) ? - rgui->directory_ptr + TERM_HEIGHT : rgui_list_size(rgui->folder_buf); + size_t end = rgui->directory_ptr + TERM_HEIGHT <= rgui->folder_buf->size ? + rgui->directory_ptr + TERM_HEIGHT : rgui->folder_buf->size; if (end - begin > TERM_HEIGHT) end = begin + TERM_HEIGHT; @@ -1187,11 +1187,11 @@ static int rgui_settings_iterate(rgui_handle_t *rgui, rgui_action_t action) if (rgui->directory_ptr > 0) rgui->directory_ptr--; else - rgui->directory_ptr = rgui_list_size(rgui->folder_buf) - 1; + rgui->directory_ptr = rgui->folder_buf->size - 1; break; case RGUI_ACTION_DOWN: - if (rgui->directory_ptr + 1 < rgui_list_size(rgui->folder_buf)) + if (rgui->directory_ptr + 1 < rgui->folder_buf->size) rgui->directory_ptr++; else rgui->directory_ptr = 0; @@ -1199,7 +1199,7 @@ static int rgui_settings_iterate(rgui_handle_t *rgui, rgui_action_t action) case RGUI_ACTION_CANCEL: case RGUI_ACTION_SETTINGS: - if (rgui_list_size(rgui->path_stack) > 1) + if (rgui->path_stack->size > 1) { rgui_list_pop(rgui->path_stack); rgui->directory_ptr = directory_ptr; @@ -1298,11 +1298,11 @@ int rgui_iterate(rgui_handle_t *rgui, rgui_action_t action) if (rgui->directory_ptr > 0) rgui->directory_ptr--; else - rgui->directory_ptr = rgui_list_size(rgui->folder_buf) - 1; + rgui->directory_ptr = rgui->folder_buf->size - 1; break; case RGUI_ACTION_DOWN: - if (rgui->directory_ptr + 1 < rgui_list_size(rgui->folder_buf)) + if (rgui->directory_ptr + 1 < rgui->folder_buf->size) rgui->directory_ptr++; else rgui->directory_ptr = 0; @@ -1316,14 +1316,14 @@ int rgui_iterate(rgui_handle_t *rgui, rgui_action_t action) break; case RGUI_ACTION_RIGHT: - if (rgui->directory_ptr + 8 < rgui_list_size(rgui->folder_buf)) + if (rgui->directory_ptr + 8 < rgui->folder_buf->size) rgui->directory_ptr += 8; else - rgui->directory_ptr = rgui_list_size(rgui->folder_buf) - 1; + rgui->directory_ptr = rgui->folder_buf->size - 1; break; case RGUI_ACTION_CANCEL: - if (rgui_list_size(rgui->path_stack) > 1) + if (rgui->path_stack->size > 1) { rgui->need_refresh = true; rgui->directory_ptr = directory_ptr; @@ -1333,7 +1333,7 @@ int rgui_iterate(rgui_handle_t *rgui, rgui_action_t action) case RGUI_ACTION_OK: { - if (rgui_list_size(rgui->folder_buf) == 0) + if (rgui->folder_buf->size == 0) return 0; const char *path = 0; diff --git a/frontend/menu/utils/file_list.c b/frontend/menu/utils/file_list.c index 1d93b30193..c650e2115e 100644 --- a/frontend/menu/utils/file_list.c +++ b/frontend/menu/utils/file_list.c @@ -32,7 +32,7 @@ struct rgui_list struct rgui_file *list; size_t capacity; - size_t ptr; + size_t size; }; rgui_list_t *rgui_list_new(void) @@ -42,34 +42,34 @@ rgui_list_t *rgui_list_new(void) bool rgui_list_empty(const rgui_list_t *list) { - return list->ptr == 0; + return list->size == 0; } void rgui_list_push(rgui_list_t *list, const char *path, unsigned type, size_t directory_ptr) { - if (list->ptr >= list->capacity) + if (list->size >= list->capacity) { list->capacity++; list->capacity *= 2; list->list = (struct rgui_file*)realloc(list->list, list->capacity * sizeof(struct rgui_file)); } - list->list[list->ptr].path = strdup(path); - list->list[list->ptr].type = type; - list->list[list->ptr].directory_ptr = directory_ptr; - list->ptr++; + list->list[list->size].path = strdup(path); + list->list[list->size].type = type; + list->list[list->size].directory_ptr = directory_ptr; + list->size++; } void rgui_list_pop(rgui_list_t *list) { if (!rgui_list_empty(list)) - free(list->list[--list->ptr].path); + free(list->list[--list->size].path); } void rgui_list_free(rgui_list_t *list) { - for (size_t i = 0; i < list->ptr; i++) + for (size_t i = 0; i < list->size; i++) free(list->list[i].path); free(list->list); free(list); @@ -77,9 +77,9 @@ void rgui_list_free(rgui_list_t *list) void rgui_list_clear(rgui_list_t *list) { - for (size_t i = 0; i < list->ptr; i++) + for (size_t i = 0; i < list->size; i++) free(list->list[i].path); - list->ptr = 0; + list->size = 0; } void rgui_list_get_at_offset(const rgui_list_t *list, size_t index, @@ -96,13 +96,8 @@ void rgui_list_get_at_offset(const rgui_list_t *list, size_t index, void rgui_list_get_last(const rgui_list_t *list, const char **path, unsigned *file_type, size_t *directory_ptr) { - if (rgui_list_size(list) > 0) - rgui_list_get_at_offset(list, rgui_list_size(list) - 1, path, file_type, directory_ptr); -} - -size_t rgui_list_size(const rgui_list_t *list) -{ - return list->ptr; + if (list->size > 0) + rgui_list_get_at_offset(list, list->size - 1, path, file_type, directory_ptr); } static int list_comp(const void *a_, const void *b_) @@ -118,5 +113,5 @@ static int list_comp(const void *a_, const void *b_) void rgui_list_sort(rgui_list_t *list) { - qsort(list->list, list->ptr, sizeof(struct rgui_file), list_comp); + qsort(list->list, list->size, sizeof(struct rgui_file), list_comp); } diff --git a/frontend/menu/utils/file_list.h b/frontend/menu/utils/file_list.h index 7b0c4635cd..f09817c497 100644 --- a/frontend/menu/utils/file_list.h +++ b/frontend/menu/utils/file_list.h @@ -34,7 +34,6 @@ bool rgui_list_empty(const rgui_list_t *list); void rgui_list_get_last(const rgui_list_t *list, const char **path, unsigned *type, size_t *directory_ptr); -size_t rgui_list_size(const rgui_list_t *list); void rgui_list_get_at_offset(const rgui_list_t *list, size_t index, const char **path, unsigned *type, size_t *directory_ptr);