tfortune.git
4 years agoMake errors from regfile_iter_new() non-fatal.
Andre Noll [Sun, 16 Jun 2019 12:04:44 +0000 (14:04 +0200)]
Make errors from regfile_iter_new() non-fatal.

The callers of the regfile iter API already handle the case of no
epigrams or tag expressions just fine. In particular, the stats
command can still print meaningful output if the tag expression
directory does not exist, which is a perfectly valid setup.

This patch modifies regfile_iter_new() to no longer abort but merely
print a log message and return NULL if opendir() fails. The various
accessors of the regfile iter API have to be adjusted to deal with
NULL pointers but no changes to tfortune.c are required.

4 years agocom_stats(): Fix memory leak.
Andre Noll [Tue, 18 Jun 2019 17:45:30 +0000 (19:45 +0200)]
com_stats(): Fix memory leak.

We currently leak one allocation per tag. Not a big deal since
"stats" is a short-running subcommand. But at least valgrind no
longer complains.

4 years agocom_stats(): Work around bogus gcc warning.
Andre Noll [Tue, 18 Jun 2019 17:07:24 +0000 (19:07 +0200)]
com_stats(): Work around bogus gcc warning.

For some versions of gcc (7.4.0, 8.3.0, and 8.3.0-7 as shipped with
Debian-11, but not gcc-7.4.0-1ubuntu1~18.04.1), the previous patch
introduced the following warning:

tfortune.c:912:3: warning: 'lh_stats' may be used uninitialized in this function [-Wmaybe-uninitialized]
   free(lh_stats);
   ^~~~~~~~~~~~~~

We only assign to lh_stats when --verbose is given, and only free the
memory if --verbose is given.  Apparently gcc has started to believe
that the value of the "verbose" boolean variable might change, which is
impossible. Therefore, the warning is believed to be a false positive.

However, gcc has a point: There is no need to check for --verbose
twice, as a single branch is sufficient. This not only gets rid of
the warning but also makes the boolean variable pointless and removes
more lines than it adds.

4 years agocom_stats(): Avoid division by zero.
Andre Noll [Mon, 17 Jun 2019 11:27:36 +0000 (13:27 +0200)]
com_stats(): Avoid division by zero.

If no epigrams are defined yet, the arguments to printf() contain
a division by zero which results in output like:

average number of epigrams per file     -nan
average number of tags per epigram.     -nan
average number of tag recurrence...     -nan

This is not a wrong per se, but it seems to be safer to special case
this and print zero.

4 years agoAdd infrastructure to build debian packages.
Andre Noll [Mon, 20 May 2019 14:58:20 +0000 (16:58 +0200)]
Add infrastructure to build debian packages.

This commit adds the usual files below debian/ so that debian source
and binary packages can be made with a command like

    dpkg-buildpackage

The debian/rules file relies on dh but overrides the dh_auto_configure
and the dh_autoreconf targets. The default recipe for dh_auto_configure
results in warnings because tfortune's configure does not implement
some of the options which dh appends to the configure command. The
override for autoreconf is needed because the default recipe would
remove our configure wrapper and replace it with the generated script.

This has been tested on debian-9, debian-10 and debian-11. On all
systems, lintian(1) reports no warnings and no errors.

v3 -> v4
~~~~~~~~
* Fix Bug ID in debian/changelog (pointed out by Adam Borowski)

v2 -> v3
~~~~~~~~
* Switch to a simple debian/rules file as suggested by Alexis Murzeau
  and Adam Borowski.

v1 -> v2
~~~~~~~~
Incorporate feedback from Adam Borowski:
 * Use dh_installchangelogs instead of open-coding it
 * Use gzip -n to avoid rendering the build non-reproducible
 * Fix the installation path of debian/copyright by running dh_install,
 * Create md5sums file

4 years agoMakefile: Avoid warning when config.mak is not present.
Andre Noll [Tue, 4 Jun 2019 14:22:05 +0000 (16:22 +0200)]
Makefile: Avoid warning when config.mak is not present.

Without the leading dash, make(1) complains if, for example,

make config.mak

is run on a pristine tree. The dash instructs make(1) to not emit
a warning if the file to include does not exist or cannot be remade.

4 years agoRun gzip with -n.
Andre Noll [Fri, 31 May 2019 18:23:02 +0000 (20:23 +0200)]
Run gzip with -n.

It is generally a good idea to not save the local file name and
timestamp in the compressed file, as this thwarts reproducible builds.

Suggested-by: Adam Borowski <kilobyte@angband.pl>
4 years agoNew make targets: exe, build-arch, man and build-indep.
Andre Noll [Wed, 22 May 2019 13:56:31 +0000 (15:56 +0200)]
New make targets: exe, build-arch, man and build-indep.

It's good practice to provide separate make targets for generating
arch-dependent files (e.g., executables) and for arch-independent files
(e.g., manual pages). Currently there is only one file of either type
which gets installed by the make target, but this might change.

4 years agomake distclean: Remove also configure.sh.
Andre Noll [Mon, 20 May 2019 22:09:51 +0000 (00:09 +0200)]
make distclean: Remove also configure.sh.

All derived files should be removed by the distclean target.

4 years agoInstall man pages in compressed form.
Andre Noll [Tue, 21 May 2019 09:54:25 +0000 (11:54 +0200)]
Install man pages in compressed form.

This is generally a good idea since all versions of man(1) support
at least gzip-compressed manual pages.

4 years agoInstall man page in section 6.
Andre Noll [Mon, 20 May 2019 17:09:30 +0000 (19:09 +0200)]
Install man page in section 6.

The manual page of the standard fortune program is part of section 6
(Games Manuals), so the tfortune man page should be installed there
as well rather than in section 1.

5 years agoAvoid duplication in version, README, man page.
Andre Noll [Sun, 17 Feb 2019 11:39:40 +0000 (12:39 +0100)]
Avoid duplication in version, README, man page.

URLs and the email address are currently spread out over multiple
files.  This commit cleans up the mess by defining everything in
Makefile and adjusting other places to use the information from there.
We use the opportunity to add a link to the author's home page.

version-gen.sh is made generic, i.e., it does not refer to tfortune
any more.

5 years agoFix --basedir completion.
Andre Noll [Sun, 20 Jan 2019 21:01:35 +0000 (22:01 +0100)]
Fix --basedir completion.

Silly braino.

5 years agoUpdate copyright year.
Andre Noll [Sat, 19 Jan 2019 23:17:36 +0000 (00:17 +0100)]
Update copyright year.

5 years agocom_help(): Fix comma placement.
Andre Noll [Sun, 13 May 2018 17:23:33 +0000 (19:23 +0200)]
com_help(): Fix comma placement.

We never want to print a comma at the beginning of the line.

5 years agoepi_iter_new(): Use xrealloc().
Andre Noll [Sun, 13 May 2018 15:27:07 +0000 (17:27 +0200)]
epi_iter_new(): Use xrealloc().

This way we get proper error checking.

5 years agotxt2ast(): Mark iovec structure as const.
Andre Noll [Sun, 13 May 2018 10:51:00 +0000 (12:51 +0200)]
txt2ast(): Mark iovec structure as const.

The function does not modify the fields of "tx".

6 years agoInitial commit. v1.0.0
Andre Noll [Mon, 19 Mar 2018 17:37:28 +0000 (18:37 +0100)]
Initial commit.

Tfortune was maintained in a non-public git repository between 2016-04
and 2018-01. By then it was moved to a dedicated repository, rewritten
to support the tag expression grammar and made scalable by introducing
linear hashing. At the same time command line parsing was switched
to the lopsub library, the command line options were redesigned and
properly documented, and the nifty logo was added.

In 2018-03 tfortune reached version 1.0 and was finally made public. All
commits that led to version 1.0 have been discarded, so this repository
contains only the final result as a single commit.

Many thanks to Effie Symeonidi who gave valuable feedback regarding the
installation instructions.