X-Git-Url: http://git.tuebingen.mpg.de/?p=tfortune.git;a=blobdiff_plain;f=tfortune.c;h=e3eef042fcd2b81bd4bb24a96243d28c5f66ed94;hp=e11c6da7556e7f2b613b1be7829bc3914b8d62a6;hb=873ecbb82d5038bb517d4531710276727343051b;hpb=6275dd846813572558b81d96fe04da9a26a73306 diff --git a/tfortune.c b/tfortune.c index e11c6da..e3eef04 100644 --- a/tfortune.c +++ b/tfortune.c @@ -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); @@ -895,15 +899,17 @@ static int com_stats(void) printf("number of tags..................... %5lu\n", num_tags); printf("number of unique tags.............. %5u\n", num_unique_tags); printf("average number of epigrams per file %8.02f\n", - (float)num_epis / num_epi_files); - printf("average number of tags per epigram. %8.02f\n", - (float)num_tags / num_epis); - printf("average number of tag recurrence... %8.02f\n", - (float)num_tags / num_unique_tags); - if (verbose) { + num_epi_files > 0? (float)num_epis / num_epi_files : 0); + printf("average number of tags per epigram. %8.02f\n", num_epis > 0? + (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 (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); @@ -969,6 +975,7 @@ static int com_help(void) } EXPORT_CMD_HANDLER(help); +const char *GET_VERSION(void); static void handle_help_and_version(void) { int i; @@ -976,14 +983,19 @@ static void handle_help_and_version(void) const struct lls_command *cmd; if (OPT_GIVEN(TFORTUNE, VERSION)) { - printf("tfortune %s\n" + printf(PACKAGE " %s\n" "Copyright (C) " COPYRIGHT_YEAR " " AUTHOR ".\n" - "License " LICENSE ": <" LICENSE_URL ">.\n" + "License: " LICENSE ": <" LICENSE_URL ">.\n" "This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n" - "Report bugs to " AUTHOR " <" PACKAGE_BUGREPORT ">.\n" + "\n" + "Web page: " PACKAGE_HOMEPAGE "\n" + "Clone URL: " CLONE_URL "\n" + "Gitweb: " GITWEB_URL "\n" + "Author's Home Page: " HOME_URL "\n" + "Send feedback to: " AUTHOR " <" EMAIL ">\n" , - tf_version() + GET_VERSION() ); exit(EXIT_SUCCESS); }