]> git.tuebingen.mpg.de Git - tfortune.git/commitdiff
Fall back to system-wide epigram directory.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 16 Jun 2019 11:46:45 +0000 (13:46 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 19 Jun 2019 09:33:08 +0000 (11:33 +0200)
If the per-user directory can not be opened, we currently print an
error message and exit. As pointed out by Adam Borowski, this is not
especially user-friendly.

This commit teaches tfortune to look in a second, system-wide location
in this case.  This location can be controlled with the --datadir
option of configure. The man page is updated accordingly.

Makefile
config.mak.in
tfortune.c
tfortune.suite.m4

index 5ad483bbf5787879d44f45562ca3a9f9efdd7fb6..d9f31971cec099d2cb16721a490cd927b728ec8d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -99,6 +99,7 @@ version.c:
 index.html tfortune.suite: %: %.m4
        $(call SAY, M4 $<)
        $(M4) -D "AUTHOR=$(AUTHOR)" -D "COPYRIGHT_YEAR=$(COPYRIGHT_YEAR)" \
 index.html tfortune.suite: %: %.m4
        $(call SAY, M4 $<)
        $(M4) -D "AUTHOR=$(AUTHOR)" -D "COPYRIGHT_YEAR=$(COPYRIGHT_YEAR)" \
+               -D "DATADIR=$(datadir)" \
                -D "PACKAGE=$(PACKAGE)" \
                -D "SLOGAN=$(SLOGAN)" \
                -D "EMAIL=$(EMAIL)" \
                -D "PACKAGE=$(PACKAGE)" \
                -D "SLOGAN=$(SLOGAN)" \
                -D "EMAIL=$(EMAIL)" \
@@ -150,6 +151,7 @@ TF_CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
 TF_CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
 TF_CPPFLAGS += -DLICENSE='"$(LICENSE)"'
 TF_CPPFLAGS += -DLICENSE_URL='"$(LICENSE_URL)"'
 TF_CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
 TF_CPPFLAGS += -DLICENSE='"$(LICENSE)"'
 TF_CPPFLAGS += -DLICENSE_URL='"$(LICENSE_URL)"'
+TF_CPPFLAGS += -DDATADIR='"$(datadir)"'
 TF_CPPFLAGS += -I/usr/local/include
 
 TF_CFLAGS += -g
 TF_CPPFLAGS += -I/usr/local/include
 
 TF_CFLAGS += -g
index 829f4203e48463dbef25a1c4bebf4f128f51c96a..b6468b434900f3751b294a2d9bd6b66c9fcaca75 100644 (file)
@@ -3,9 +3,9 @@
 prefix := @prefix@
 exec_prefix := @exec_prefix@
 
 prefix := @prefix@
 exec_prefix := @exec_prefix@
 
-# These two use prefix and exec_prefix
 bindir := @bindir@
 datarootdir := @datarootdir@
 bindir := @bindir@
 datarootdir := @datarootdir@
+datadir := @datadir@
 
 FLEX := @FLEX@
 BISON := @BISON@
 
 FLEX := @FLEX@
 BISON := @BISON@
index 02e54ea40e864032e75886c454bb742b8b3c37c8..e3eef042fcd2b81bd4bb24a96243d28c5f66ed94 100644 (file)
@@ -302,9 +302,16 @@ static char *get_basedir(void)
 static char *get_epidir(void)
 {
        char *basedir, *epidir;
 static char *get_epidir(void)
 {
        char *basedir, *epidir;
+       struct stat s;
+
        basedir = get_basedir();
        xasprintf(&epidir, "%s/epigrams", basedir);
        free(basedir);
        basedir = get_basedir();
        xasprintf(&epidir, "%s/epigrams", basedir);
        free(basedir);
+       if (!OPT_GIVEN(TFORTUNE, BASEDIR) && stat(epidir, &s) < 0) {
+               free(epidir);
+               epidir = xstrdup(DATADIR "/tfortunes/epigrams");
+               INFO_LOG("falling back to system-wide epidir %s\n", epidir);
+       }
        return epidir;
 }
 
        return epidir;
 }
 
index ce0324a5297340df53db8de6581bee444d4c53d6..dc8bae9cd22eb5e52ee9e1f62851c6fb24f8cbfe 100644 (file)
@@ -65,6 +65,10 @@ caption = Subcommands
                        Epigrams are expected in the "epigrams" subdirectory of the base
                        directory while tag expressions are expected to be stored below
                        "expressions".
                        Epigrams are expected in the "epigrams" subdirectory of the base
                        directory while tag expressions are expected to be stored below
                        "expressions".
+
+                       If the option is not given, and the per-user epigram directory does
+                       not exist, the system-wide default DATADIR() is tried. There is no
+                       such fallback for tag expressions, though.
                [/help]
 
 [subcommand compgen]
                [/help]
 
 [subcommand compgen]