summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-02-28 17:56:13 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-02-28 17:56:13 +0100
commite6a535093596d3732628b8114386eb9b72929a02 (patch)
tree09279aaf64051767df0880faaaf22636856770eb /src
parent8eaa39234a54fcdd3c9050a01790b152598af80d (diff)
parent5a2db8f2ffc4371d2e88a65567d85663e6d16b36 (diff)
Merge branch 'ulteq-natural-sort'
Diffstat (limited to 'src')
-rw-r--r--src/feh.h8
-rw-r--r--src/filelist.c18
-rw-r--r--src/help.raw1
-rw-r--r--src/options.c4
-rw-r--r--src/options.h1
5 files changed, 29 insertions, 3 deletions
diff --git a/src/feh.h b/src/feh.h
index 63771b6..3e0cdda 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -27,6 +27,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef FEH_H
#define FEH_H
+/*
+ * strverscmp(3) is a GNU extension. In most supporting C libraries it
+ * requires _GNU_SOURCE to be defined.
+ */
+#ifdef HAVE_VERSCMP
+#define _GNU_SOURCE
+#endif
+
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
diff --git a/src/filelist.c b/src/filelist.c
index 9a4af27..453f795 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -397,14 +397,26 @@ void feh_file_dirname(char *dst, feh_file * f, int maxlen)
dst[n] = '\0';
}
+#ifdef HAVE_VERSCMP
+inline int strcmp_or_strverscmp(const char *s1, const char *s2)
+{
+ if (!opt.version_sort)
+ return(strcmp(s1, s2));
+ else
+ return(strverscmp(s1, s2));
+}
+#else
+#define strcmp_or_strverscmp strcmp
+#endif
+
int feh_cmp_filename(void *file1, void *file2)
{
- return(strcmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
+ return(strcmp_or_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));
+ return(strcmp_or_strverscmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
}
int feh_cmp_dirname(void *file1, void *file2)
@@ -413,7 +425,7 @@ 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)
+ if ((cmp = strcmp_or_strverscmp(dir1, dir2)) != 0)
return(cmp);
return(feh_cmp_name(file1, file2));
}
diff --git a/src/help.raw b/src/help.raw
index 8b244c1..86bb617 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 0ad7c74..3d11482 100644
--- a/src/options.c
+++ b/src/options.c
@@ -415,6 +415,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;
@@ -780,6 +781,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 33b2bd3..c6b4e0e 100644
--- a/src/options.h
+++ b/src/options.h
@@ -104,6 +104,7 @@ struct __fehoptions {
unsigned int thumb_redraw;
double reload;
int sort;
+ int version_sort;
int debug;
int geom_flags;
int geom_x;