]> git.tuebingen.mpg.de Git - tfortune.git/blobdiff - tfortune.c
Fall back to system-wide epigram directory.
[tfortune.git] / tfortune.c
index ec4c323f7c29040b0bbb7d1e883f303c6559951c..e3eef042fcd2b81bd4bb24a96243d28c5f66ed94 100644 (file)
@@ -302,9 +302,16 @@ static char *get_basedir(void)
 static char *get_epidir(void)
 {
        char *basedir, *epidir;
+       struct stat s;
+
        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;
 }
 
@@ -863,23 +870,20 @@ static int com_stats(void)
        struct linhash_item *itemp;
        unsigned num_epi_files, num_epis, num_unique_tags, num_x = 0;
        long unsigned num_tags = 0;
-       char *xdir, *lh_stats;
+       char *xdir;
        struct regfile_iter *riter;
-       bool verbose = OPT_GIVEN(STATS, VERBOSE);
 
        tagtab = hash_tags(&num_epi_files, &num_epis);
        for (
                liter = linhash_iterator_new(tagtab, NULL, false);
                (itemp = linhash_iterator_item(liter));
                linhash_iterator_next(liter)
-       )
+       ) {
+               free((char *)itemp->key);
                num_tags += (long unsigned)itemp->object;
+       }
        num_unique_tags = linhash_num_items(tagtab);
        linhash_iterator_free(liter);
-       if (verbose)
-               lh_stats = linhash_statistics(tagtab);
-       linhash_free(tagtab);
-
        xdir = get_xdir();
        for (
                regfile_iter_new(xdir, &riter);
@@ -900,10 +904,12 @@ static int com_stats(void)
                (float)num_tags / num_epis : 0);
        printf("average number of tag recurrence... %8.02f\n", num_unique_tags > 0?
                (float)num_tags / num_unique_tags : 0);
-       if (verbose) {
+       if (OPT_GIVEN(STATS, VERBOSE)) {
+               char *lh_stats = linhash_statistics(tagtab);
                printf("\nlinear hashing statistics:\n%s\n", lh_stats);
                free(lh_stats);
        }
+       linhash_free(tagtab);
        return 1;
 }
 EXPORT_CMD_HANDLER(stats);