n-t-roff / heirloom-doctools

The Heirloom Documentation Tools: troff, nroff, and related utilities
http://n-t-roff.github.io/heirloom/doctools.html
Other
127 stars 23 forks source link

refer fails on FreeBSD/amd64 - bug in refer/hunt3.c #118

Open mghis opened 1 year ago

mghis commented 1 year ago

Refer fails on FreeBSD/amd64 at the second reference in the document, as described in the following minimal example:

% echo "First reference:
dquote> .[
dquote> sethi
dquote> .]
dquote> Second reference:
dquote> .[
dquote> sethi
dquote> .]
dquote> " | /usr/local/heirloom/bin/refer
First reference:\*([.1\*(.]
.ds [F 1
.]-
.ds [A R. Sethi
.as [A " and J. D. Ullman
.ds [T The Generation of Optimal Code for Arithmetic Expressions
.ds [J J. Assoc. Comp. Mach.
.ds [K acm jacm
.ds [V 17
.ds [N 4
.ds [D October 1970
.ds [P 715-728
.nr [P 1
.ds [O Reprinted as pp. 229-247 in \fICompiler Techniques\fR, ed. B. W. Pollack, Auerbach, Princeton NJ (1972).
.nr [T 0
.nr [A 0
.nr [O 1
.][ 1 journal-article
bad fgrep call
% echo $?
2
%

PS: I used two references to the same paper in the example, but this is irrelevant: the issue also happens in the same fashion if I refer to two different papers.

PPS: I think i found the bug, which is fixed with the following patch,

diff --git a/refer/hunt3.c b/refer/hunt3.c
index 1ce5a99..3483e73 100644
--- a/refer/hunt3.c
+++ b/refer/hunt3.c
@@ -60,7 +60,7 @@ getq(char **v)
        if (p > buff + BSIZ)
                fprintf(stderr, "query long than %d characters\n", BSIZ);
        assert(p < buff + BSIZ);
-       if (use_sinput || c<=0) eof=1;
+       if (!use_sinput && c<=0) eof=1;
 # if D1
        fprintf(stderr, "no. keys %d\n",n);
        for(c=0; c<n; c++)