Select Git revision
To find the state of this project's repository at the time of any of these versions, check out the tags.
dirlist.c 9.83 KiB
/* ncdu - NCurses Disk Usage
Copyright (c) 2007-2018 Yoran Heling
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "global.h"
#include <string.h>
#include <stdlib.h>
/* public variables */
struct dir *dirlist_parent = NULL,
*dirlist_par = NULL;
int64_t dirlist_maxs = 0,
dirlist_maxa = 0;
int dirlist_sort_desc = 1,
dirlist_sort_col = DL_COL_SIZE,
dirlist_sort_df = 0,
dirlist_hidden = 0;
/* private state vars */
static struct dir *parent_alloc, *head, *head_real, *selected, *top = NULL;
#define ISHIDDEN(d) (dirlist_hidden && (d) != dirlist_parent && (\
(d)->flags & FF_EXL || (d)->name[0] == '.' || (d)->name[strlen((d)->name)-1] == '~'\
))
static inline int cmp_mtime(struct dir *x, struct dir*y) {
int64_t x_mtime = 0, y_mtime = 0;
if (x->flags & FF_EXT)
x_mtime = dir_ext_ptr(x)->mtime;
if (y->flags & FF_EXT)
y_mtime = dir_ext_ptr(y)->mtime;
return (x_mtime > y_mtime ? 1 : (x_mtime == y_mtime ? 0 : -1));
}
static int dirlist_cmp(struct dir *x, struct dir *y) {
int r;
/* dirs are always before files when that option is set */
if(dirlist_sort_df) {
if(y->flags & FF_DIR && !(x->flags & FF_DIR))
return 1;
else if(!(y->flags & FF_DIR) && x->flags & FF_DIR)
return -1;