diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-06-02 13:45:00 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-06-02 13:45:00 +0200 |
commit | 09c59148f8cdc1cb1cb83cb63f6edacec617a446 (patch) | |
tree | 36e759b0bd5d94fa4ef8817a746f43b6e6e9d5c4 /src/filelist.c | |
parent | 315bac4637537654b4711867911458c3a6974c7e (diff) | |
parent | 36b09fa038a8b7996a12e45419c28821c5596308 (diff) |
Merge branch 'guns-dirnav'
Diffstat (limited to 'src/filelist.c')
-rw-r--r-- | src/filelist.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/filelist.c b/src/filelist.c index 7e9dcbe..8956238 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -383,6 +383,20 @@ int feh_file_info_load(feh_file * file, Imlib_Image im) return(0); } +void feh_file_dirname(char *dst, feh_file * f, int maxlen) +{ + int n = strlen(f->filename) - strlen(f->name); + + /* Give up on long dirnames */ + if (n <= 0 || n >= maxlen) { + dst[0] = '\0'; + return; + } + + strncpy(dst, f->filename, n); + dst[n] = '\0'; +} + int feh_cmp_filename(void *file1, void *file2) { return(strcmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename)); @@ -393,6 +407,17 @@ int feh_cmp_name(void *file1, void *file2) return(strcmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name)); } +int feh_cmp_dirname(void *file1, void *file2) +{ + char dir1[FEH_MAX_DIRNAME_LEN], dir2[FEH_MAX_DIRNAME_LEN]; + int cmp; + feh_file_dirname(dir1, FEH_FILE(file1), FEH_MAX_DIRNAME_LEN); + feh_file_dirname(dir2, FEH_FILE(file2), FEH_MAX_DIRNAME_LEN); + if ((cmp = strcmp(dir1, dir2)) != 0) + return(cmp); + return(feh_cmp_name(file1, file2)); +} + /* Return -1 if file1 is _newer_ than file2 */ int feh_cmp_mtime(void *file1, void *file2) { @@ -465,6 +490,9 @@ void feh_prepare_filelist(void) case SORT_FILENAME: filelist = gib_list_sort(filelist, feh_cmp_filename); break; + case SORT_DIRNAME: + filelist = gib_list_sort(filelist, feh_cmp_dirname); + break; case SORT_MTIME: filelist = gib_list_sort(filelist, feh_cmp_mtime); break; |