summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorulteq <ulteq@web.de>2018-01-18 11:07:45 +0100
committerulteq <ulteq@web.de>2018-01-23 19:29:40 +0100
commit7acf83ea6d6f36e418f43a3408632944fbb7bcde (patch)
tree2a129172891e5515dbf4b6f518ed47a417d8b487
parent886bea1e034c6878f4466a7e427302351281043e (diff)
Add natural sort of (version) numbers
-rw-r--r--src/feh.h1
-rw-r--r--src/filelist.c19
-rw-r--r--src/help.raw1
-rw-r--r--src/options.c4
-rw-r--r--src/options.h1
5 files changed, 22 insertions, 4 deletions
diff --git a/src/feh.h b/src/feh.h
index a4a0a7b..da08aba 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef FEH_H
#define FEH_H
+#define _GNU_SOURCE
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
diff --git a/src/filelist.c b/src/filelist.c
index b569b8a..3157e32 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -399,12 +399,18 @@ void feh_file_dirname(char *dst, feh_file * f, int maxlen)
int feh_cmp_filename(void *file1, void *file2)
{
- return(strcmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
+ if (!opt.version_sort)
+ return(strcmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
+ else
+ return(strverscmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
}
int feh_cmp_name(void *file1, void *file2)
{
- return(strcmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
+ if (!opt.version_sort)
+ return(strcmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
+ else
+ return(strverscmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
}
int feh_cmp_dirname(void *file1, void *file2)
@@ -413,8 +419,13 @@ int feh_cmp_dirname(void *file1, void *file2)
int cmp;
feh_file_dirname(dir1, FEH_FILE(file1), PATH_MAX);
feh_file_dirname(dir2, FEH_FILE(file2), PATH_MAX);
- if ((cmp = strcmp(dir1, dir2)) != 0)
- return(cmp);
+ if (!opt.version_sort) {
+ if ((cmp = strcmp(dir1, dir2)) != 0)
+ return(cmp);
+ } else {
+ if ((cmp = strverscmp(dir1, dir2)) != 0)
+ return(cmp);
+ }
return(feh_cmp_name(file1, file2));
}
diff --git a/src/help.raw b/src/help.raw
index 37e0e71..8c83b5b 100644
--- a/src/help.raw
+++ b/src/help.raw
@@ -52,6 +52,7 @@ OPTIONS
name, filename, mtime, width, height, pixels, size,
or format
-n, --reverse Reverse sort order
+ --version-sort Natural sort of (version) numbers within text
-A, --action [;]ACTION Specify action to perform when pressing <return>.
Executed by /bin/sh, may contain FORMAT SPECIFIERS
reloads image with \";\", switches to next otherwise
diff --git a/src/options.c b/src/options.c
index c874832..3fcbdef 100644
--- a/src/options.c
+++ b/src/options.c
@@ -412,6 +412,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
{"insecure" , 0, 0, 240},
{"no-recursive" , 0, 0, 241},
{"cache-size" , 1, 0, 243},
+ {"version-sort" , 0, 0, 246},
{0, 0, 0, 0}
};
int optch = 0, cmdx = 0;
@@ -782,6 +783,9 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
if (opt.cache_size > 2048)
opt.cache_size = 2048;
break;
+ case 246:
+ opt.version_sort = 1;
+ break;
default:
break;
}
diff --git a/src/options.h b/src/options.h
index c6959c8..277cede 100644
--- a/src/options.h
+++ b/src/options.h
@@ -103,6 +103,7 @@ struct __fehoptions {
unsigned int thumb_redraw;
double reload;
int sort;
+ int version_sort;
int debug;
int geom_flags;
int geom_x;