summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-02-28 17:53:51 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-02-28 17:53:51 +0100
commit4567042b5145b097c962499f26511aa5106f0e60 (patch)
tree57268aa9c2d7b455eeecd5e92b5ec58b7c7a3cc6
parentb251f26261309c933a43c863f81227219a9e8355 (diff)
Add Makefile flag to disable version sorting on C libraries without strverscmp
-rw-r--r--README.md1
-rw-r--r--config.mk10
-rw-r--r--man/Makefile1
-rw-r--r--man/feh.pre3
-rw-r--r--src/feh.h7
-rw-r--r--src/filelist.c29
6 files changed, 35 insertions, 16 deletions
diff --git a/README.md b/README.md
index 328897a..7848158 100644
--- a/README.md
+++ b/README.md
@@ -83,6 +83,7 @@ Available flags are:
| exif | 0 | Builtin EXIF tag display support |
| help | 0 | include help text (refers to the manpage otherwise) |
| stat64 | 0 | Support CIFS shares from 64bit hosts on 32bit machines |
+| verscmp | 1 | Support naturing sorting (`--version-sort`). Requires a GNU-compatible libc exposing `strverscmp` |
| xinerama | 1 | Support Xinerama/XRandR multiscreen setups |
So, by default **libcurl** and **Xinerama** are enabled, the rest is disabled.
diff --git a/config.mk b/config.mk
index 8769b1d..226c612 100644
--- a/config.mk
+++ b/config.mk
@@ -5,9 +5,10 @@ app ?= 0
cam ?= 0
curl ?= 1
debug ?= 0
+exif ?= 0
help ?= 0
+verscmp ?= 1
xinerama ?= 1
-exif ?= 0
# Prefix for all installed files
PREFIX ?= /usr/local
@@ -63,6 +64,13 @@ ifeq (${stat64},1)
CFLAGS += -D_FILE_OFFSET_BITS=64
endif
+ifeq (${verscmp},1)
+ CFLAGS += -DHAVE_VERSCMP
+ MAN_VERSCMP = enabled
+else
+ MAN_VERSCMP = disabled
+endif
+
ifeq (${xinerama},1)
CFLAGS += -DHAVE_LIBXINERAMA
LDLIBS += -lXinerama
diff --git a/man/Makefile b/man/Makefile
index 65f2bc2..9209de1 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -12,6 +12,7 @@ all: ${TARGETS}
-e 's/\$$MAN_CURL\$$/${MAN_CURL}/' \
-e 's/\$$MAN_DEBUG\$$/${MAN_DEBUG}/' \
-e 's/\$$MAN_EXIF\$$/${MAN_EXIF}/' \
+ -e 's/\$$MAN_VERSCMP\$$/${MAN_VERSCMP}/' \
-e 's/\$$MAN_XINERAMA\$$/${MAN_XINERAMA}/' \
< ${@:.1=.pre} > $@
diff --git a/man/feh.pre b/man/feh.pre
index d332774..640ae3f 100644
--- a/man/feh.pre
+++ b/man/feh.pre
@@ -24,7 +24,8 @@ $VERSION$
.
.Pp
.
-Compile-time switches: libcurl support $MAN_CURL$, Xinerama support
+Compile-time switches: libcurl support $MAN_CURL$, natural sorting support
+$MAN_VERSCMP$, Xinerama support
$MAN_XINERAMA$, builtin EXIF support $MAN_EXIF$$MAN_DEBUG$
.
.
diff --git a/src/feh.h b/src/feh.h
index 4e7a3ff..3e0cdda 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -27,7 +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 159491a..453f795 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -397,20 +397,26 @@ void feh_file_dirname(char *dst, feh_file * f, int maxlen)
dst[n] = '\0';
}
-int feh_cmp_filename(void *file1, void *file2)
+#ifdef HAVE_VERSCMP
+inline int strcmp_or_strverscmp(const char *s1, const char *s2)
{
if (!opt.version_sort)
- return(strcmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
+ return(strcmp(s1, s2));
else
- return(strverscmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
+ return(strverscmp(s1, s2));
+}
+#else
+#define strcmp_or_strverscmp strcmp
+#endif
+
+int feh_cmp_filename(void *file1, void *file2)
+{
+ return(strcmp_or_strverscmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
}
int feh_cmp_name(void *file1, void *file2)
{
- 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));
+ return(strcmp_or_strverscmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
}
int feh_cmp_dirname(void *file1, void *file2)
@@ -419,13 +425,8 @@ 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 (!opt.version_sort) {
- if ((cmp = strcmp(dir1, dir2)) != 0)
- return(cmp);
- } else {
- if ((cmp = strverscmp(dir1, dir2)) != 0)
- return(cmp);
- }
+ if ((cmp = strcmp_or_strverscmp(dir1, dir2)) != 0)
+ return(cmp);
return(feh_cmp_name(file1, file2));
}