tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: whatis(1)
Date: Mon, 28 Nov 2011 01:35:21 +0100	[thread overview]
Message-ID: <20111128003521.GB15140@iris.usta.de> (raw)
In-Reply-To: <4ED287DE.3030001@bsd.lv>

Hi Kristaps,

Kristaps Dzonsons wrote on Sun, Nov 27, 2011 at 07:56:30PM +0100:

> To get the ball rolling, I just checked in whatis.1 and the code
> modified to use your regexp.  I simplified the call into
> apropos_db.h with termcomp() instead of exprcomp(), as this mode
> might be useful for man.cgi too.  The search expression is now case
> insensitive and ~[[:<:]]term[[:>:]].  (Thanks!)

I have merged this to OpenBSD, with a few tweaks, see below:

 - One real bug: termcomp() returned the wrong end of the singly
   linked list it built, such that only the last word given on
   the command line was used.

 - Whatever MacOS may be doing, i tweaked the the regex
   from "Nm,Nd~" to "Nm~", which is current OpenBSD behaviour.
   When we replace tools, we should not change behaviour at the
   same time, but propose changes separately - if we want them.
   In this case, i'm not even convinced the change makes sense.
   If you ask "whatis mandoc", you clearly want "mandoc(1)" as
   an answer; but why should you get "eqn(7), roff(7), tbl(7)"
   as well?  That's, i think, what plain apropos(1) is for.
   Maybe that's even a bug in MacOS?

 - I suggest to check only the beginning of the command name,
   such that you can e.g. install as "whatis.m" for testing
   purposes.

OK to commit these three tweaks to bsd.lv, too?

> NOTE: this fixed a subtle bug in apropos_db.h in compiling case
> insensitive regular expression.

Indeed, thanks!
  Ingo

 ----- 8< ----- schnipp ----- >8 ----- 8< ----- schnapp ----- >8 -----

CVSROOT:	/cvs
Module name:	src
Changes by:	schwarze@cvs.openbsd.org	2011/11/27 17:16:38

Modified files:
	usr.bin/mandoc : apropos.c apropos_db.c apropos_db.h main.c 

Log message:
Implement whatis(1) as a special apropos(1) mode as a part of
the mandoc(1) binary; not yet enabled for the general public.
Intended to replace src/usr.bin/whatis at a later time.
Coded by kristaps@, with a few tweaks by me.

To test this:
$ mandocdb  # unless you have already done so earlier
$ sudo ln -s /usr/bin/mandoc /usr/bin/whatis.m
$ whatis.m mandoc apropos whatis
$ whatis.m man

 ----- 8< ----- schnipp ----- >8 ----- 8< ----- schnapp ----- >8 -----

--- /co/mdocml/apropos.c	Sun Nov 27 23:51:01 2011
+++ ./apropos.c	Mon Nov 28 01:16:38 2011
@@ -53,7 +49,7 @@ main(int argc, char *argv[])
 	else
 		++progname;
 
-	whatis = 0 == strcmp(progname, "whatis");
+	whatis = 0 == strncmp(progname, "whatis", 6);
 
 	memset(&paths, 0, sizeof(struct manpaths));
 	memset(&opts, 0, sizeof(struct opts));
--- /co/mdocml/apropos_db.c	Mon Nov 28 00:11:37 2011
+++ ./apropos_db.c	Mon Nov 28 01:16:38 2011
@@ -599,10 +599,10 @@ termcomp(int argc, char *argv[], size_t *tt)
 	e = NULL;
 	*tt = 0;
 
-	for (pos = 0; pos < argc; pos++) {
-		sz = strlen(argv[pos]) + 16;
+	for (pos = argc - 1; pos >= 0; pos--) {
+		sz = strlen(argv[pos]) + 18;
 		buf = mandoc_realloc(buf, sz);
-		strlcpy(buf, "~[[:<:]]", sz);
+		strlcpy(buf, "Nm~[[:<:]]", sz);
 		strlcat(buf, argv[pos], sz);
 		strlcat(buf, "[[:>:]]", sz);
 		if (NULL == (next = exprterm(buf, 0))) {
@@ -610,8 +610,7 @@ termcomp(int argc, char *argv[], size_t *tt)
 			exprfree(e);
 			return(NULL);
 		}
-		if (NULL != e)
-			e->next = next;
+		next->next = e;
 		e = next;
 		(*tt)++;
 	}
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

  reply	other threads:[~2011-11-28  0:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-27 12:16 whatis(1) Kristaps Dzonsons
2011-11-27 18:13 ` whatis(1) Ingo Schwarze
2011-11-27 18:56   ` whatis(1) Kristaps Dzonsons
2011-11-28  0:35     ` Ingo Schwarze [this message]
2011-11-28  8:42       ` whatis(1) Kristaps Dzonsons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111128003521.GB15140@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).