From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-1.sys.kth.se (smtp-1.sys.kth.se [130.237.32.175]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id pARCGnm8011079 for ; Sun, 27 Nov 2011 07:16:49 -0500 (EST) Received: from mailscan-1.sys.kth.se (mailscan-1.sys.kth.se [130.237.32.91]) by smtp-1.sys.kth.se (Postfix) with ESMTP id CCCCD154220 for ; Sun, 27 Nov 2011 13:16:43 +0100 (CET) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-1.sys.kth.se ([130.237.32.175]) by mailscan-1.sys.kth.se (mailscan-1.sys.kth.se [130.237.32.91]) (amavisd-new, port 10024) with LMTP id 26Ycm86htnVZ for ; Sun, 27 Nov 2011 13:16:41 +0100 (CET) X-KTH-Auth: kristaps [83.250.6.251] X-KTH-mail-from: kristaps@bsd.lv X-KTH-rcpt-to: tech@mdocml.bsd.lv Received: from macky.local (c83-250-6-251.bredband.comhem.se [83.250.6.251]) by smtp-1.sys.kth.se (Postfix) with ESMTP id C324B15588C for ; Sun, 27 Nov 2011 13:16:40 +0100 (CET) Message-ID: <4ED22A28.6040401@bsd.lv> Date: Sun, 27 Nov 2011 13:16:40 +0100 From: Kristaps Dzonsons User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0 X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 To: tech@mdocml.bsd.lv Subject: whatis(1) Content-Type: multipart/mixed; boundary="------------000607050900040100020206" This is a multi-part message in MIME format. --------------000607050900040100020206 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, Enclosed is a simple implementation of whatis(1). It's a mode of apropos(1) where arguments are re-written as foo => Nm~^foo$ This follows OpenBSD's method; other systems, like my Mac, search for both `Nm' and `Nd', but I'm avoiding this for now because I can't figure out the proper regex for word boundaries in multi-word `Nd' strings. Thoughts? Kristaps --------------000607050900040100020206 Content-Type: text/plain; name="patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.txt" Index: apropos.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos.c,v retrieving revision 1.19 diff -u -r1.19 apropos.c --- apropos.c 26 Nov 2011 22:38:11 -0000 1.19 +++ apropos.c 27 Nov 2011 12:15:23 -0000 @@ -38,12 +38,13 @@ int main(int argc, char *argv[]) { - int ch, rc; + int ch, rc, whatis, i; struct manpaths paths; - size_t terms; + size_t terms, sz; struct opts opts; struct expr *e; char *defpaths, *auxpaths; + char *buf; extern int optind; extern char *optarg; @@ -53,12 +54,13 @@ else ++progname; + whatis = 0 == strcmp(progname, "whatis"); + memset(&paths, 0, sizeof(struct manpaths)); memset(&opts, 0, sizeof(struct opts)); auxpaths = defpaths = NULL; e = NULL; - rc = 0; while (-1 != (ch = getopt(argc, argv, "M:m:S:s:"))) switch (ch) { @@ -76,19 +78,34 @@ break; default: usage(); - goto out; + return(EXIT_FAILURE); } argc -= optind; argv += optind; - if (0 == argc) { - rc = 1; - goto out; - } + if (0 == argc) + return(EXIT_SUCCESS); + + rc = 0; manpath_parse(&paths, defpaths, auxpaths); + /* + * whatis(1) has a much simpler syntax than apropos(1): it + * accepts standalone words and composes them into full-string + * matches within the name. + */ + if (whatis) + for (i = 0; i < argc; i++) { + sz = strlen(argv[i]) + 6; + buf = mandoc_malloc(sz); + strlcpy(buf, "Nm~^", sz); + strlcat(buf, argv[i], sz); + strlcat(buf, "$", sz); + argv[i] = buf; + } + if (NULL == (e = exprcomp(argc, argv, &terms))) { fprintf(stderr, "%s: Bad expression\n", progname); goto out; @@ -105,6 +122,10 @@ out: manpath_free(&paths); exprfree(e); + + if (whatis) + for (i = 0; i < argc; i++) + free(argv[i]); return(rc ? EXIT_SUCCESS : EXIT_FAILURE); } Index: whatis.1 =================================================================== RCS file: whatis.1 diff -N whatis.1 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ whatis.1 27 Nov 2011 12:15:23 -0000 @@ -0,0 +1,111 @@ +.\" $Id: apropos.1,v 1.9 2011/11/26 22:38:11 schwarze Exp $ +.\" +.\" Copyright (c) 2011 Kristaps Dzonsons +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: November 26 2011 $ +.Dt WHATIS 1 +.Os +.Sh NAME +.Nm whatis +.Nd search manual page databases +.Sh SYNOPSIS +.Nm +.Op Fl M Ar manpath +.Op Fl m Ar manpath +.Op Fl S Ar arch +.Op Fl s Ar section +.Ar term... +.Sh DESCRIPTION +The +.Nm +utility searches for manuals named +.Ar term +in manual page databases generated by +.Xr mandocdb 8 . +Its arguments are as follows: +.Bl -tag -width Ds +.It Fl M Ar manpath +Use the colon-separated path instead of the default list of paths +searched for +.Xr mandocdb 8 +databases. +Invalid paths, or paths without manual databases, are ignored. +.It Fl m Ar manpath +Prepend the colon-separated paths to the list of paths searched +for +.Xr mandocdb 8 +databases. +Invalid paths, or paths without manual databases, are ignored. +.It Fl S Ar arch +Search only for a particular architecture. +.It Fl s Ar cat +Search only for a manual section. +See +.Xr man 1 +for a listing of manual sections. +.El +.Pp +By default, +.Nm +searches for +.Xr mandocdb 8 +databases in the default paths stipulated by +.Xr man 1 . +Results are sorted by manual title, with output formatted as +.Pp +.D1 title(sec) \- description +.Pp +Where +.Qq title +is the manual's title (note multiple manual names may exist for one +title), +.Qq sec +is the manual section, and +.Qq description +is the manual's short description. +If an architecture is specified for the manual, it is displayed as +.Pp +.D1 title(cat/arch) \- description +.Pp +Resulting manuals may be accessed as +.Pp +.Dl $ man \-s sec title +.Pp +If an architecture is specified in the output, use +.Pp +.Dl $ man \-s sec \-S arch title +.Sh ENVIRONMENT +.Bl -tag -width Ds +.It Ev MANPATH +Colon-separated paths overriding the default list of paths searched for +manual databases. +Invalid paths, or paths without manual databases, are ignored. +Overridden by +.Fl M . +.El +.\" .Sh FILES +.Sh EXIT STATUS +.Ex -std +.Sh SEE ALSO +.Xr apropos 1 , +.Xr man 1 , +.Xr mandoc 1 , +.Xr mandocdb 8 +.Sh AUTHORS +The +.Nm +utility was written by +.An Kristaps Dzonsons , +.Mt kristaps@bsd.lv . --------------000607050900040100020206-- -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv