mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-18 09:19:24 +03:00
(dir_list_append): add new dir_list API and use it.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
6aa9503f2f
commit
6b31f67f31
@ -287,6 +287,41 @@ dir_list_grow (dir_list * list, int delta)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Append file info to the directory list.
|
||||||
|
*
|
||||||
|
* @param list directory list
|
||||||
|
* @param fname file name
|
||||||
|
* @param st file stat info
|
||||||
|
* @param link_to_dir is file link to directory
|
||||||
|
* @param stale_link is file stale elink
|
||||||
|
*
|
||||||
|
* @return FALSE on failure, TRUE on success
|
||||||
|
*/
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
dir_list_append (dir_list * list, const char *fname, const struct stat *st,
|
||||||
|
gboolean link_to_dir, gboolean stale_link)
|
||||||
|
{
|
||||||
|
/* Need to grow the *list? */
|
||||||
|
if (list->len == list->size && !dir_list_grow (list, RESIZE_STEPS))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
list->list[list->len].fnamelen = strlen (fname);
|
||||||
|
list->list[list->len].fname = g_strndup (fname, list->list[list->len].fnamelen);
|
||||||
|
list->list[list->len].f.marked = 0;
|
||||||
|
list->list[list->len].f.link_to_dir = link_to_dir ? 1 : 0;
|
||||||
|
list->list[list->len].f.stale_link = stale_link ? 1 : 0;
|
||||||
|
list->list[list->len].f.dir_size_computed = 0;
|
||||||
|
list->list[list->len].st = *st;
|
||||||
|
list->list[list->len].sort_key = NULL;
|
||||||
|
list->list[list->len].second_sort_key = NULL;
|
||||||
|
list->len++;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -606,20 +641,9 @@ do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort,
|
|||||||
{
|
{
|
||||||
if (!handle_dirent (dp, fltr, &st, &link_to_dir, &stale_link))
|
if (!handle_dirent (dp, fltr, &st, &link_to_dir, &stale_link))
|
||||||
continue;
|
continue;
|
||||||
/* Need to grow the *list? */
|
|
||||||
if (list->len == list->size && !dir_list_grow (list, RESIZE_STEPS))
|
|
||||||
goto ret;
|
|
||||||
|
|
||||||
list->list[list->len].fnamelen = strlen (dp->d_name);
|
if (!dir_list_append (list, dp->d_name, &st, link_to_dir != 0, stale_link != 0))
|
||||||
list->list[list->len].fname = g_strndup (dp->d_name, list->list[list->len].fnamelen);
|
goto ret;
|
||||||
list->list[list->len].f.marked = 0;
|
|
||||||
list->list[list->len].f.link_to_dir = link_to_dir;
|
|
||||||
list->list[list->len].f.stale_link = stale_link;
|
|
||||||
list->list[list->len].f.dir_size_computed = 0;
|
|
||||||
list->list[list->len].st = st;
|
|
||||||
list->list[list->len].sort_key = NULL;
|
|
||||||
list->list[list->len].second_sort_key = NULL;
|
|
||||||
list->len++;
|
|
||||||
|
|
||||||
if ((list->len & 31) == 0)
|
if ((list->len & 31) == 0)
|
||||||
rotate_dash (TRUE);
|
rotate_dash (TRUE);
|
||||||
@ -711,8 +735,8 @@ do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort,
|
|||||||
{
|
{
|
||||||
if (!handle_dirent (dp, fltr, &st, &link_to_dir, &stale_link))
|
if (!handle_dirent (dp, fltr, &st, &link_to_dir, &stale_link))
|
||||||
continue;
|
continue;
|
||||||
/* Need to grow the *list? */
|
|
||||||
if (list->len == list->size && !dir_list_grow (list, RESIZE_STEPS))
|
if (!dir_list_append (list, dp->d_name, &st, link_to_dir != 0, stale_link != 0))
|
||||||
{
|
{
|
||||||
mc_closedir (dirp);
|
mc_closedir (dirp);
|
||||||
/* Norbert (Feb 12, 1997):
|
/* Norbert (Feb 12, 1997):
|
||||||
@ -730,7 +754,7 @@ do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
list->list[list->len].f.marked = 0;
|
list->list[list->len - 1].f.marked = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we have marked files in the copy, scan through the copy
|
* If we have marked files in the copy, scan through the copy
|
||||||
@ -739,19 +763,10 @@ do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort,
|
|||||||
*/
|
*/
|
||||||
if (marked_cnt > 0 && g_hash_table_lookup (marked_files, dp->d_name) != NULL)
|
if (marked_cnt > 0 && g_hash_table_lookup (marked_files, dp->d_name) != NULL)
|
||||||
{
|
{
|
||||||
list->list[list->len].f.marked = 1;
|
list->list[list->len - 1].f.marked = 1;
|
||||||
marked_cnt--;
|
marked_cnt--;
|
||||||
}
|
}
|
||||||
|
|
||||||
list->list[list->len].fnamelen = strlen (dp->d_name);
|
|
||||||
list->list[list->len].fname = g_strndup (dp->d_name, list->list[list->len].fnamelen);
|
|
||||||
list->list[list->len].f.link_to_dir = link_to_dir;
|
|
||||||
list->list[list->len].f.stale_link = stale_link;
|
|
||||||
list->list[list->len].f.dir_size_computed = 0;
|
|
||||||
list->list[list->len].st = st;
|
|
||||||
list->list[list->len].sort_key = NULL;
|
|
||||||
list->list[list->len].second_sort_key = NULL;
|
|
||||||
list->len++;
|
|
||||||
if ((list->len & 15) == 0)
|
if ((list->len & 15) == 0)
|
||||||
rotate_dash (TRUE);
|
rotate_dash (TRUE);
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,8 @@ typedef struct dir_sort_options_struct
|
|||||||
/*** declarations of public functions ************************************************************/
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
gboolean dir_list_grow (dir_list * list, int delta);
|
gboolean dir_list_grow (dir_list * list, int delta);
|
||||||
|
gboolean dir_list_append (dir_list * list, const char *fname, const struct stat *st,
|
||||||
|
gboolean link_to_dir, gboolean stale_link);
|
||||||
|
|
||||||
void do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort,
|
void 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);
|
||||||
|
@ -353,20 +353,12 @@ do_external_panelize (char *command)
|
|||||||
|
|
||||||
if (!handle_path (name, &st, &link_to_dir, &stale_link))
|
if (!handle_path (name, &st, &link_to_dir, &stale_link))
|
||||||
continue;
|
continue;
|
||||||
/* Need to grow the *list? */
|
|
||||||
if (list->len == list->size && !dir_list_grow (list, RESIZE_STEPS))
|
if (!dir_list_append (list, name, &st, link_to_dir != 0, stale_link != 0))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
list->list[list->len].fnamelen = strlen (name);
|
file_mark (current_panel, list->len - 1, 0);
|
||||||
list->list[list->len].fname = g_strndup (name, list->list[list->len].fnamelen);
|
|
||||||
list->list[list->len].f.link_to_dir = link_to_dir;
|
|
||||||
list->list[list->len].f.stale_link = stale_link;
|
|
||||||
list->list[list->len].f.dir_size_computed = 0;
|
|
||||||
list->list[list->len].st = st;
|
|
||||||
list->list[list->len].sort_key = NULL;
|
|
||||||
list->list[list->len].second_sort_key = NULL;
|
|
||||||
file_mark (current_panel, list->len, 0);
|
|
||||||
list->len++;
|
|
||||||
if ((list->len & 31) == 0)
|
if ((list->len & 31) == 0)
|
||||||
rotate_dash (TRUE);
|
rotate_dash (TRUE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user