tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* Showing all possible apropls keys.
@ 2011-11-21 17:13 Kristaps Dzonsons
  2011-11-21 22:37 ` Ingo Schwarze
  0 siblings, 1 reply; 8+ messages in thread
From: Kristaps Dzonsons @ 2011-11-21 17:13 UTC (permalink / raw)
  To: tech

[-- 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 *);
 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-11-29  1:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-21 17:13 Showing all possible apropls keys Kristaps Dzonsons
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

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).