mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
(dir_list_grow): new public API of dir_list.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
e6bb69a0d9
commit
6a3943fcf0
@ -137,30 +137,6 @@ clean_sort_keys (dir_list * list, int start, int count)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
/**
|
|
||||||
* Increase directory list by RESIZE_STEPS
|
|
||||||
*
|
|
||||||
* @param list directory list
|
|
||||||
* @return FALSE on failure, TRUE on success
|
|
||||||
*/
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
grow_list (dir_list * list)
|
|
||||||
{
|
|
||||||
if (list == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
|
|
||||||
|
|
||||||
if (list->list == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
list->size += RESIZE_STEPS;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/**
|
/**
|
||||||
* If you change handle_dirent then check also handle_path.
|
* If you change handle_dirent then check also handle_path.
|
||||||
@ -211,7 +187,7 @@ handle_dirent (dir_list * list, const char *fltr, struct dirent *dp,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Need to grow the *list? */
|
/* Need to grow the *list? */
|
||||||
if (next_free == list->size && !grow_list (list))
|
if (next_free == list->size && !dir_list_grow (list, RESIZE_STEPS))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -267,6 +243,46 @@ alloc_dir_copy (int size)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*** public functions ****************************************************************************/
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Increase or decrease directory list size.
|
||||||
|
*
|
||||||
|
* @param list directory list
|
||||||
|
* @param delta value by increase (if positive) or decrease (if negative) list size
|
||||||
|
*
|
||||||
|
* @return FALSE on failure, TRUE on success
|
||||||
|
*/
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
dir_list_grow (dir_list * list, int delta)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
|
||||||
|
if (list == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (delta == 0)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
size = list->size + delta;
|
||||||
|
if (size <= 0)
|
||||||
|
size = MIN_FILES;
|
||||||
|
|
||||||
|
if (size != list->size)
|
||||||
|
{
|
||||||
|
file_entry *fe;
|
||||||
|
|
||||||
|
fe = g_try_renew (file_entry, list->list, size);
|
||||||
|
if (fe == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
list->list = fe;
|
||||||
|
list->size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -479,7 +495,7 @@ gboolean
|
|||||||
set_zero_dir (dir_list * list)
|
set_zero_dir (dir_list * list)
|
||||||
{
|
{
|
||||||
/* Need to grow the *list? */
|
/* Need to grow the *list? */
|
||||||
if (list->size == 0 && !grow_list (list))
|
if (list->size == 0 && !dir_list_grow (list, RESIZE_STEPS))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
memset (&(list->list)[0], 0, sizeof (file_entry));
|
memset (&(list->list)[0], 0, sizeof (file_entry));
|
||||||
@ -536,7 +552,7 @@ handle_path (dir_list * list, const char *path,
|
|||||||
vfs_path_free (vpath);
|
vfs_path_free (vpath);
|
||||||
|
|
||||||
/* Need to grow the *list? */
|
/* Need to grow the *list? */
|
||||||
if (next_free == list->size && !grow_list (list))
|
if (next_free == list->size && !dir_list_grow (list, RESIZE_STEPS))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -40,6 +40,8 @@ typedef struct dir_sort_options_struct
|
|||||||
|
|
||||||
/*** declarations of public functions ************************************************************/
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
gboolean dir_list_grow (dir_list * list, int delta);
|
||||||
|
|
||||||
int do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort,
|
int do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort,
|
||||||
const dir_sort_options_t * sort_op, const char *fltr);
|
const dir_sort_options_t * sort_op, const char *fltr);
|
||||||
void do_sort (dir_list * list, GCompareFunc sort, int top, const dir_sort_options_t * sort_op);
|
void do_sort (dir_list * list, GCompareFunc sort, int top, const dir_sort_options_t * sort_op);
|
||||||
|
Loading…
Reference in New Issue
Block a user