From: Kristaps Dzonsons <kristaps@bsd.lv>
To: tech@mdocml.bsd.lv
Subject: Showing all possible apropls keys.
Date: Mon, 21 Nov 2011 18:13:44 +0100 [thread overview]
Message-ID: <4ECA86C8.1030100@bsd.lv> (raw)
[-- Attachment #1: Type: text/plain, Size: 137 bytes --]
Hi,
Enclosed is a patch to show all possible apropos keys with apropos -k.
I chose "-k" more or less arbitrarily.
Thoughts?
Kristaps
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3263 bytes --]
Index: apropos.1
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos.1,v
retrieving revision 1.7
diff -u -r1.7 apropos.1
--- apropos.1 20 Nov 2011 21:36:00 -0000 1.7
+++ apropos.1 21 Nov 2011 17:00:59 -0000
@@ -22,6 +22,7 @@
.Nd search manual page databases
.Sh SYNOPSIS
.Nm
+.Op Fl k
.Op Fl M Ar manpath
.Op Fl m Ar manpath
.Op Fl S Ar arch
@@ -56,6 +57,11 @@
See
.Xr man 1
for a listing of manual sections.
+.It Fl k
+List all
+.Xr mdoc 7
+keywords accepted by
+.Nm .
.El
.Pp
An
Index: apropos.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos.c,v
retrieving revision 1.17
diff -u -r1.17 apropos.c
--- apropos.c 20 Nov 2011 21:36:00 -0000 1.17
+++ apropos.c 21 Nov 2011 17:00:59 -0000
@@ -50,6 +50,7 @@
static void manpath_add(struct manpaths *, const char *);
static void manpath_parse(struct manpaths *, char *);
static void manpath_parseconf(struct manpaths *);
+static void showkey(const char * const *, size_t, void *);
static void usage(void);
static char *progname;
@@ -79,8 +80,11 @@
e = NULL;
rc = 0;
- while (-1 != (ch = getopt(argc, argv, "M:m:S:s:")))
+ while (-1 != (ch = getopt(argc, argv, "kM:m:S:s:")))
switch (ch) {
+ case ('k'):
+ apropos_keys(NULL, showkey);
+ return(EXIT_SUCCESS);
case ('M'):
defpaths = optarg;
break;
@@ -95,7 +99,7 @@
break;
default:
usage();
- goto out;
+ return(EXIT_FAILURE);
}
argc -= optind;
@@ -168,6 +172,7 @@
{
fprintf(stderr, "usage: %s "
+ "[-k] "
"[-M dirs] "
"[-m dirs] "
"[-S arch] "
@@ -273,4 +278,13 @@
fclose(stream);
#endif
+}
+
+static void
+showkey(const char * const *res, size_t sz, void *arg)
+{
+ int i;
+
+ for (i = 0; i < (int)sz; i++)
+ puts(res[i]);
}
Index: apropos_db.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.c,v
retrieving revision 1.10
diff -u -r1.10 apropos_db.c
--- apropos_db.c 20 Nov 2011 16:29:50 -0000 1.10
+++ apropos_db.c 21 Nov 2011 17:00:59 -0000
@@ -373,6 +373,25 @@
return(1);
}
+void
+apropos_keys(void *arg,
+ void (*res)(const char * const *, size_t, void *))
+{
+ int i, len;
+ const char **buf;
+
+ for (len = 0; types[len].mask; len++)
+ /* Count records. */ ;
+
+ buf = mandoc_malloc(len * sizeof(char *));
+
+ for (i = 0; i < len; i++)
+ buf[i] = types[i].name;
+
+ (*res)(buf, len, arg);
+ free(buf);
+}
+
/*
* Search mandocdb databases in paths for expression "expr".
* Filter out by "opts".
Index: apropos_db.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.h,v
retrieving revision 1.6
diff -u -r1.6 apropos_db.h
--- apropos_db.h 20 Nov 2011 15:43:14 -0000 1.6
+++ apropos_db.h 21 Nov 2011 17:00:59 -0000
@@ -38,6 +38,8 @@
int apropos_search(int, char **, const struct opts *,
const struct expr *, size_t, void *,
void (*)(struct res *, size_t, void *));
+void apropos_keys(void *, void (*)(const char * const *,
+ size_t, void *));
struct expr *exprcomp(int, char *[], size_t *);
void exprfree(struct expr *);
next reply other threads:[~2011-11-21 17:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-21 17:13 Kristaps Dzonsons [this message]
2011-11-21 22:37 ` Ingo Schwarze
2011-11-22 8:58 ` Kristaps Dzonsons
2011-11-26 12:21 ` Ingo Schwarze
2011-11-28 20:37 ` Kristaps Dzonsons
2011-11-28 23:59 ` Ingo Schwarze
2011-11-29 0:34 ` Kristaps Dzonsons
2011-11-29 1:01 ` Ingo Schwarze
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=4ECA86C8.1030100@bsd.lv \
--to=kristaps@bsd.lv \
--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).