tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Cc: jmc@openbsd.org
Subject: overhaul apropos(1) interface
Date: Wed, 9 Nov 2011 02:30:44 +0100	[thread overview]
Message-ID: <20111109013044.GA25679@iris.usta.de> (raw)

Hi,

the interface of the apropos utility in the mandoc package
is very different from traditional apropos, and the -t option
hinders logical extensions, as discussed previously.
So, here is a first step to fix this, doing various things:

INTERFACE CHANGES:
 * drop the -s (sort) option, it clashes with -s (section)
 * introduce -N (numerical sort) instead
 * drop the -c (cat) option, it clashes with -c (copy to stdout)
 * rename it to the usual -s (section)
 * drop the -a (arch) option, it clashes with -a (all)
 * rename it to the usual -S (subsection)
 * drop the -t (search type), it clashes with -t (use troff)
 * use a macro= syntax instead, as discussed
 * drop -e (exact) and -r (regex), it belongs to each query phrase
 * use a macro== and macro=~ syntax instead

The new syntax is:

  apropos [-IN] [-s section] [-S arch] query_phrase [...]

  query_phrase ::= [[macro[,...]](=|==|=~)]query_value

Multiple query phrases are not yet implemented, but they are to
be or'ed in the future.

The operators are:

 =  substring match
 == exact match
 =~ regex match

If no operator is given, = is assumed.
Multiple macros can be given, joined with commas, they are or'ed.
If no macro is given, "Nm,Nd" is assumed.

STRUCTURAL CLEANUP:
 * collect the common defines for mandocdb and apropos in mandocdb.h
 * name the TYPE_ bitfield constants according to the new interface
 * drop types and match from the global struct opts
   because these are local to each query phrase
 * drop the enum sort; for an alternative, a bool is sufficient
 * drop the local dbf and idxf strings, use those in the global struct

This is lightly tested, but given that we are not yet in production
and lots of heavy changes are needed in after this, i consider
light testing sufficient.

OK?

Of course, when committing, i'm going to change the manual, too.

And by the way, this patch is +144 -175 :-).

Yours,
  Ingo


ischwarze@isnote $ apropos An=Gray    
AN(4) - Aironet Communications 4500/4800 IEEE 802.11FH/b wireless network device
APS(4) - ThinkPad Active Protection System accelerometer
BWI(4) - Broadcom AirForce IEEE 802.11b/g wireless network device
ET(4) - Agere/LSI ET1310 10/100/Gigabit Ethernet device
ETPHY(4) - Agere/LSI ET1011 TruePHY Gigabit Ethernet PHY
JME(4) - JMicron JMC250/JMC260 10/100/Gigabit Ethernet device
JMPHY(4) - JMicron JMP202/JMP211 10/100/Gigabit Ethernet PHY
MOSCOM(4) - MosChip Semiconductor MCS7703 based USB serial adapter
NFE(4) - NVIDIA nForce MCP 10/100/Gigabit Ethernet device
RTW(4) - Realtek RTL8180L IEEE 802.11b wireless network device
SPDMEM(4) - Serial Presence Detect memory
UARK(4) - Arkmicro Technologies ARK3116 based USB serial adapter
UCHCOM(4) - WinChipHead CH341/340 based USB serial adapter
UDAV(4) - Davicom DM9601 10/100 USB Ethernet device
UMSM(4) - Qualcomm MSM modem device
USLCOM(4) - Silicon Laboratories CP2101/CP2102 based USB serial adapter
ZYD(4) - ZyDAS ZD1211/ZD1211B USB IEEE 802.11b/g wireless network device
ischwarze@isnote $ apropos Xr==et.4 
PCI(4) - introduction to PCI bus support
ischwarze@isnote $ apropos Nm=~^b.e$
BCE(4) - Broadcom BCM4401 10/100 Ethernet device
BGE(4) - Broadcom BCM57xx/BCM590x 10/100/Gigabit Ethernet device


--- apropos.c.orig
+++ apropos.c
@@ -1,6 +1,7 @@
 /*	$Id: apropos.c,v 1.2 2011/10/09 17:59:56 schwarze Exp $ */
 /*
-* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -31,44 +32,21 @@
 #include <db.h>
 
 #include "mandoc.h"
+#include "mandocdb.h"
 
 #define	MAXRESULTS	 256
 
-/* Bit-fields.  See mandocdb.8. */
-
-#define TYPE_NAME	  0x01
-#define TYPE_FUNCTION	  0x02
-#define TYPE_UTILITY	  0x04
-#define TYPE_INCLUDES	  0x08
-#define TYPE_VARIABLE	  0x10
-#define TYPE_STANDARD	  0x20
-#define TYPE_AUTHOR	  0x40
-#define TYPE_CONFIG	  0x80
-#define TYPE_DESC	  0x100
-#define TYPE_XREF	  0x200
-#define TYPE_PATH	  0x400
-#define TYPE_ENV	  0x800
-#define TYPE_ERR	  0x1000
-
 enum	match {
 	MATCH_SUBSTR = 0,
 	MATCH_REGEX,
 	MATCH_EXACT
 };
 
-enum	sort {
-	SORT_TITLE = 0,
-	SORT_CAT,
-	SORT__MAX
-};
-
 struct	opts {
-	enum sort	 sort; /* output sorting */
+	const char	*sec; /* restrict to manual section */
 	const char	*arch; /* restrict to architecture */
-	const char	*cat; /* restrict to category */
-	int		 types; /* only types in bitmask */
 	int		 insens; /* case-insensitive match */
-	enum match	 match; /* match type */
+	int		 numerical; /* sort output by section */
 };
 
 struct	type {
@@ -78,7 +56,7 @@ struct	type {
 
 struct	rec {
 	char		*file; /* file in file-system */
-	char		*cat; /* category (3p, 3, etc.) */
+	char		*sec; /* section (3p, 3, etc.) */
 	char		*title; /* title (FOO, etc.) */
 	char		*arch; /* arch (or empty string) */
 	char		*desc; /* description (from Nd) */
@@ -86,12 +64,12 @@ struct	rec {
 };
 
 struct	res {
+	char		*sec; /* manual section */
+	char		*title; /* manual title */
 	char		*arch; /* architecture */
 	char		*desc; /* free-form description */
 	char		*keyword; /* matched keyword */
 	int	 	 types; /* bitmask of field selectors */
-	char		*cat; /* manual section */
-	char		*title; /* manual section */
 	char		*uri; /* formatted uri of file */
 	recno_t		 rec; /* unique id of underlying manual */
 	/*
@@ -111,26 +89,22 @@ struct	state {
 	const char	 *idxf; /* index name */
 };
 
-static	const char * const sorts[SORT__MAX] = {
-	"cat", /* SORT_CAT */
-	"title", /* SORT_TITLE */
-};
-
-static	const struct type types[] = {
-	{ TYPE_NAME, "name" },
-	{ TYPE_FUNCTION, "func" },
-	{ TYPE_UTILITY, "utility" },
-	{ TYPE_INCLUDES, "incl" },
-	{ TYPE_VARIABLE, "var" },
-	{ TYPE_STANDARD, "stand" },
-	{ TYPE_AUTHOR, "auth" },
-	{ TYPE_CONFIG, "conf" },
-	{ TYPE_DESC, "desc" },
-	{ TYPE_XREF, "xref" },
-	{ TYPE_PATH, "path" },
-	{ TYPE_ENV, "env" },
-	{ TYPE_ERR, "err" },
-	{ INT_MAX, "all" },
+static	const struct type typemap[] = {
+	{ TYPE_An, "An" },
+	{ TYPE_Cd, "Cd" },
+	{ TYPE_Er, "Er" },
+	{ TYPE_Ev, "Ev" },
+	{ TYPE_Fn, "Fn" },
+	{ TYPE_Fn, "Fo" },
+	{ TYPE_In, "In" },
+	{ TYPE_Nd, "Nd" },
+	{ TYPE_Nm, "Nm" },
+	{ TYPE_Pa, "Pa" },
+	{ TYPE_St, "St" },
+	{ TYPE_Va, "Va" },
+	{ TYPE_Va, "Vt" },
+	{ TYPE_Xr, "Xr" },
+	{ INT_MAX, "any" },
 	{ 0, NULL }
 };
 
@@ -138,7 +112,7 @@ static	void	 buf_alloc(char **, size_t *, size_t);
 static	void	 buf_dup(struct mchars *, char **, const char *);
 static	void	 buf_redup(struct mchars *, char **, 
 			size_t *, const char *);
-static	int	 sort_cat(const void *, const void *);
+static	int	 sort_sec(const void *, const void *);
 static	int	 sort_title(const void *, const void *);
 static	int	 state_getrecord(struct state *, 
 			recno_t, struct rec *);
@@ -153,10 +127,9 @@ int
 apropos(int argc, char *argv[])
 {
 	BTREEINFO	 info;
-	int		 ch, i, rc;
-	const char	*dbf, *idxf;
+	int		 ch, rc;
 	struct state	 state;
-	char		*q, *v;
+	char		*q;
 	struct opts	 opts;
 	extern int	 optind;
 	extern char	*optarg;
@@ -164,8 +137,8 @@ apropos(int argc, char *argv[])
 	memset(&opts, 0, sizeof(struct opts));
 	memset(&state, 0, sizeof(struct state));
 
-	dbf = "mandoc.db";
-	idxf = "mandoc.index";
+	state.dbf = MANDOC_DB;
+	state.idxf = MANDOC_IDX;
 	q = NULL;
 	rc = EXIT_FAILURE;
 
@@ -175,56 +148,20 @@ apropos(int argc, char *argv[])
 	else
 		++progname;
 
-	opts.match = MATCH_SUBSTR;
-
-	while (-1 != (ch = getopt(argc, argv, "a:c:eIrs:t:"))) 
+	while (-1 != (ch = getopt(argc, argv, "INS:s:"))) 
 		switch (ch) {
-		case ('a'):
-			opts.arch = optarg;
-			break;
-		case ('c'):
-			opts.cat = optarg;
-			break;
-		case ('e'):
-			opts.match = MATCH_EXACT;
-			break;
 		case ('I'):
 			opts.insens = 1;
 			break;
-		case ('r'):
-			opts.match = MATCH_REGEX;
+		case ('N'):
+			opts.numerical = 1;
+			break;
+		case ('S'):
+			opts.arch = optarg;
 			break;
 		case ('s'):
-			for (i = 0; i < SORT__MAX; i++) {
-				if (strcmp(optarg, sorts[i])) 
-					continue;
-				opts.sort = (enum sort)i;
-				break;
-			}
-
-			if (i < SORT__MAX)
-				break;
-
-			fprintf(stderr, "%s: Bad sort\n", optarg);
-			return(EXIT_FAILURE);
-		case ('t'):
-			while (NULL != (v = strsep(&optarg, ","))) {
-				if ('\0' == *v)
-					continue;
-				for (i = 0; types[i].mask; i++) {
-					if (strcmp(types[i].name, v))
-						continue;
-					break;
-				}
-				if (0 == types[i].mask)
-					break;
-				opts.types |= types[i].mask;
-			}
-			if (NULL == v)
-				break;
-			
-			fprintf(stderr, "%s: Bad type\n", v);
-			return(EXIT_FAILURE);
+			opts.sec = optarg;
+			break;
 		default:
 			usage();
 			return(EXIT_FAILURE);
@@ -239,9 +176,6 @@ apropos(int argc, char *argv[])
 	} else
 		q = *argv;
 
-	if (0 == opts.types)
-		opts.types = TYPE_NAME | TYPE_DESC;
-
 	/*
 	 * Configure databases.
 	 * The keyword database is a btree that allows for duplicate
@@ -252,15 +186,15 @@ apropos(int argc, char *argv[])
 	memset(&info, 0, sizeof(BTREEINFO));
 	info.flags = R_DUP;
 
-	state.db = dbopen(dbf, O_RDONLY, 0, DB_BTREE, &info);
+	state.db = dbopen(state.dbf, O_RDONLY, 0, DB_BTREE, &info);
 	if (NULL == state.db) {
-		perror(dbf);
+		perror(state.dbf);
 		goto out;
 	}
 
-	state.idx = dbopen(idxf, O_RDONLY, 0, DB_RECNO, NULL);
+	state.idx = dbopen(state.idxf, O_RDONLY, 0, DB_RECNO, NULL);
 	if (NULL == state.idx) {
-		perror(idxf);
+		perror(state.idxf);
 		goto out;
 	}
 
@@ -280,9 +214,9 @@ out:
 static int
 state_search(struct state *p, const struct opts *opts, char *q)
 {
-	int		 leaf, root, len, ch, dflag, rc;
+	int		 i, leaf, root, len, ch, dflag, rc, types;
 	struct mchars	*mc;
-	char		*buf;
+	char		*buf, *qkey, *qval;
 	size_t		 bufsz;
 	recno_t		 rec;
 	uint32_t	 fl;
@@ -292,6 +226,7 @@ state_search(struct state *p, const struct opts *opts, char *q)
 	regex_t		*regp;
 	char		 filebuf[10];
 	struct rec	 record;
+	enum match	 match_method;
 
 	rc = 0;
 	root = leaf = -1;
@@ -302,29 +237,50 @@ state_search(struct state *p, const struct opts *opts, char *q)
 	regp = NULL;
 
 	/*
+	 * Determine the search types.
+	 */
+
+	types = 0;
+	if (NULL == (qval = strchr(q, '=')))
+		qval = q;
+	else {
+		*qval++ = '\0';
+		while (NULL != (qkey = strsep(&q, ","))) {
+			i = 0;
+			while (typemap[i].mask &&
+			    strcmp(typemap[i].name, qkey))
+				i++;
+			types |= typemap[i].mask;
+		}
+	}
+	if (0 == types)
+		types = TYPE_Nm | TYPE_Nd;
+
+	/*
 	 * Configure how we scan through results to see if we match:
 	 * whether by regexp or exact matches.
 	 */
 
-	switch (opts->match) {
-	case (MATCH_REGEX):
+	switch (*qval) {
+	case ('~'):
+		match_method = MATCH_REGEX;
 		ch = REG_EXTENDED | REG_NOSUB | 
 			(opts->insens ? REG_ICASE : 0);
-
-		if (0 != regcomp(&reg, q, ch)) {
-			fprintf(stderr, "%s: Bad pattern\n", q);
+		if (0 != regcomp(&reg, ++qval, ch)) {
+			fprintf(stderr, "%s: Bad pattern\n", qval);
 			return(0);
 		}
-
 		regp = &reg;
 		dflag = R_FIRST;
 		break;
-	case (MATCH_EXACT):
-		key.data = q;
-		key.size = strlen(q) + 1;
+	case ('='):
+		match_method = MATCH_EXACT;
+		key.data = ++qval;
+		key.size = strlen(qval) + 1;
 		dflag = R_CURSOR;
 		break;
 	default:
+		match_method = MATCH_SUBSTR;
 		dflag = R_FIRST;
 		break;
 	}
@@ -357,24 +313,24 @@ state_search(struct state *p, const struct opts *opts, char *q)
 
 		fl = *(uint32_t *)val.data;
 
-		if ( ! (fl & opts->types))
+		if ( ! (fl & types))
 			continue;
 
-		switch (opts->match) {
+		switch (match_method) {
 		case (MATCH_REGEX):
 			if (regexec(regp, buf, 0, NULL, 0))
 				continue;
 			break;
 		case (MATCH_EXACT):
-			if (opts->insens && strcasecmp(buf, q))
+			if (opts->insens && strcasecmp(buf, qval))
 				goto send;
-			if ( ! opts->insens && strcmp(buf, q))
+			if ( ! opts->insens && strcmp(buf, qval))
 				goto send;
 			break;
 		default:
-			if (opts->insens && NULL == strcasestr(buf, q))
+			if (opts->insens && NULL == strcasestr(buf, qval))
 				continue;
-			if ( ! opts->insens && NULL == strstr(buf, q))
+			if ( ! opts->insens && NULL == strstr(buf, qval))
 				continue;
 			break;
 		}
@@ -391,7 +347,7 @@ state_search(struct state *p, const struct opts *opts, char *q)
 
 		/* If we're in a different section, skip... */
 
-		if (opts->cat && strcasecmp(opts->cat, record.cat))
+		if (opts->sec && strcasecmp(opts->sec, record.sec))
 			continue;
 		if (opts->arch && strcasecmp(opts->arch, record.arch))
 			continue;
@@ -431,7 +387,7 @@ state_search(struct state *p, const struct opts *opts, char *q)
 
 		buf_dup(mc, &res[len].keyword, buf);
 		buf_dup(mc, &res[len].uri, filebuf);
-		buf_dup(mc, &res[len].cat, record.cat);
+		buf_dup(mc, &res[len].sec, record.sec);
 		buf_dup(mc, &res[len].arch, record.arch);
 		buf_dup(mc, &res[len].title, record.title);
 		buf_dup(mc, &res[len].desc, record.desc);
@@ -454,8 +410,8 @@ state_search(struct state *p, const struct opts *opts, char *q)
 send:
 	/* Sort our results. */
 
-	if (SORT_CAT == opts->sort)
-		qsort(res, len, sizeof(struct res), sort_cat);
+	if (opts->numerical)
+		qsort(res, len, sizeof(struct res), sort_sec);
 	else
 		qsort(res, len, sizeof(struct res), sort_title);
 
@@ -465,7 +421,7 @@ out:
 	for (len-- ; len >= 0; len--) {
 		free(res[len].keyword);
 		free(res[len].title);
-		free(res[len].cat);
+		free(res[len].sec);
 		free(res[len].arch);
 		free(res[len].desc);
 		free(res[len].uri);
@@ -589,7 +545,7 @@ state_output(const struct res *res, int sz)
 
 	for (i = 0; i < sz; i++)
 		printf("%s(%s%s%s) - %s\n", res[i].title, 
-				res[i].cat, 
+				res[i].sec, 
 				*res[i].arch ? "/" : "",
 				*res[i].arch ? res[i].arch : "",
 				res[i].desc);
@@ -600,11 +556,9 @@ usage(void)
 {
 
 	fprintf(stderr, "usage: %s "
-			"[-eIr] "
-			"[-a arch] "
-			"[-c cat] "
-			"[-s sort] "
-			"[-t type[,...]] "
+			"[-IN] "
+			"[-S subsection] "
+			"[-s section] "
 			"key\n", progname);
 }
 
@@ -629,8 +583,8 @@ state_getrecord(struct state *p, recno_t rec, struct rec *rp)
 	if ((sz = strlen(rp->file) + 1) >= val.size)
 		goto err;
 
-	rp->cat = (char *)val.data + (int)sz;
-	if ((sz += strlen(rp->cat) + 1) >= val.size)
+	rp->sec = (char *)val.data + (int)sz;
+	if ((sz += strlen(rp->sec) + 1) >= val.size)
 		goto err;
 
 	rp->title = (char *)val.data + (int)sz;
@@ -658,12 +612,12 @@ sort_title(const void *p1, const void *p2)
 }
 
 static int
-sort_cat(const void *p1, const void *p2)
+sort_sec(const void *p1, const void *p2)
 {
 	int		 rc;
 
-	rc = strcmp(((const struct res *)p1)->cat,
-			((const struct res *)p2)->cat);
+	rc = strcmp(((const struct res *)p1)->sec,
+			((const struct res *)p2)->sec);
 
 	return(0 == rc ? sort_title(p1, p2) : rc);
 }
--- mandocdb.c.orig
+++ mandocdb.c
@@ -29,28 +29,11 @@
 #include "man.h"
 #include "mdoc.h"
 #include "mandoc.h"
+#include "mandocdb.h"
 
-#define	MANDOC_DB	 "mandoc.db"
-#define	MANDOC_IDX	 "mandoc.index"
 #define	MANDOC_BUFSZ	  BUFSIZ
 #define	MANDOC_SLOP	  1024
 
-/* Bit-fields.  See mandocdb.8. */
-
-#define TYPE_NAME	  0x01
-#define TYPE_FUNCTION	  0x02
-#define TYPE_UTILITY	  0x04
-#define TYPE_INCLUDES	  0x08
-#define TYPE_VARIABLE	  0x10
-#define TYPE_STANDARD	  0x20
-#define TYPE_AUTHOR	  0x40
-#define TYPE_CONFIG	  0x80
-#define TYPE_DESC	  0x100
-#define TYPE_XREF	  0x200
-#define TYPE_PATH	  0x400
-#define TYPE_ENV	  0x800
-#define TYPE_ERR	  0x1000
-
 /* Tiny list for files.  No need to bring in QUEUE. */
 
 struct	of {
@@ -719,7 +702,7 @@ pmdoc_An(MDOC_ARGS)
 		return;
 
 	buf_appendmdoc(buf, n->child, 0);
-	hash_put(hash, buf, TYPE_AUTHOR);
+	hash_put(hash, buf, TYPE_An);
 }
 
 static void
@@ -780,7 +763,7 @@ pmdoc_Fd(MDOC_ARGS)
 	buf_appendb(buf, start, (size_t)(end - start + 1));
 	buf_appendb(buf, "", 1);
 
-	hash_put(hash, buf, TYPE_INCLUDES);
+	hash_put(hash, buf, TYPE_In);
 }
 
 /* ARGSUSED */
@@ -792,7 +775,7 @@ pmdoc_Cd(MDOC_ARGS)
 		return;
 
 	buf_appendmdoc(buf, n->child, 0);
-	hash_put(hash, buf, TYPE_CONFIG);
+	hash_put(hash, buf, TYPE_Cd);
 }
 
 /* ARGSUSED */
@@ -806,7 +789,7 @@ pmdoc_In(MDOC_ARGS)
 		return;
 
 	buf_append(buf, n->child->string);
-	hash_put(hash, buf, TYPE_INCLUDES);
+	hash_put(hash, buf, TYPE_In);
 }
 
 /* ARGSUSED */
@@ -832,7 +815,7 @@ pmdoc_Fn(MDOC_ARGS)
 		cp++;
 
 	buf_append(buf, cp);
-	hash_put(hash, buf, TYPE_FUNCTION);
+	hash_put(hash, buf, TYPE_Fn);
 }
 
 /* ARGSUSED */
@@ -846,7 +829,7 @@ pmdoc_St(MDOC_ARGS)
 		return;
 
 	buf_append(buf, n->child->string);
-	hash_put(hash, buf, TYPE_STANDARD);
+	hash_put(hash, buf, TYPE_St);
 }
 
 /* ARGSUSED */
@@ -865,7 +848,7 @@ pmdoc_Xr(MDOC_ARGS)
 	} else
 		buf_appendb(buf, ".", 2);
 
-	hash_put(hash, buf, TYPE_XREF);
+	hash_put(hash, buf, TYPE_Xr);
 }
 
 /* ARGSUSED */
@@ -902,7 +885,7 @@ pmdoc_Vt(MDOC_ARGS)
 
 	buf_appendb(buf, start, sz);
 	buf_appendb(buf, "", 1);
-	hash_put(hash, buf, TYPE_VARIABLE);
+	hash_put(hash, buf, TYPE_Va);
 }
 
 /* ARGSUSED */
@@ -916,7 +899,7 @@ pmdoc_Fo(MDOC_ARGS)
 		return;
 
 	buf_append(buf, n->child->string);
-	hash_put(hash, buf, TYPE_FUNCTION);
+	hash_put(hash, buf, TYPE_Fn);
 }
 
 
@@ -931,7 +914,7 @@ pmdoc_Nd(MDOC_ARGS)
 	buf_appendmdoc(dbuf, n->child, 1);
 	buf_appendmdoc(buf, n->child, 0);
 
-	hash_put(hash, buf, TYPE_DESC);
+	hash_put(hash, buf, TYPE_Nd);
 }
 
 /* ARGSUSED */
@@ -943,7 +926,7 @@ pmdoc_Er(MDOC_ARGS)
 		return;
 	
 	buf_appendmdoc(buf, n->child, 0);
-	hash_put(hash, buf, TYPE_ERR);
+	hash_put(hash, buf, TYPE_Er);
 }
 
 /* ARGSUSED */
@@ -955,7 +938,7 @@ pmdoc_Ev(MDOC_ARGS)
 		return;
 	
 	buf_appendmdoc(buf, n->child, 0);
-	hash_put(hash, buf, TYPE_ENV);
+	hash_put(hash, buf, TYPE_Ev);
 }
 
 /* ARGSUSED */
@@ -967,7 +950,7 @@ pmdoc_Pa(MDOC_ARGS)
 		return;
 	
 	buf_appendmdoc(buf, n->child, 0);
-	hash_put(hash, buf, TYPE_PATH);
+	hash_put(hash, buf, TYPE_Pa);
 }
 
 /* ARGSUSED */
@@ -977,7 +960,7 @@ pmdoc_Nm(MDOC_ARGS)
 	
 	if (SEC_NAME == n->sec) {
 		buf_appendmdoc(buf, n->child, 0);
-		hash_put(hash, buf, TYPE_NAME);
+		hash_put(hash, buf, TYPE_Nm);
 		return;
 	} else if (SEC_SYNOPSIS != n->sec || MDOC_HEAD != n->type)
 		return;
@@ -986,7 +969,7 @@ pmdoc_Nm(MDOC_ARGS)
 		buf_append(buf, m->name);
 
 	buf_appendmdoc(buf, n->child, 0);
-	hash_put(hash, buf, TYPE_UTILITY);
+	hash_put(hash, buf, TYPE_Nm);
 }
 
 static void
@@ -1116,7 +1099,7 @@ pman_node(MAN_ARGS)
 				buf_appendb(buf, start, sz);
 				buf_appendb(buf, "", 1);
 
-				hash_put(hash, buf, TYPE_NAME);
+				hash_put(hash, buf, TYPE_Nm);
 
 				if (' ' == start[(int)sz]) {
 					start += (int)sz + 1;
@@ -1155,7 +1138,7 @@ pman_node(MAN_ARGS)
 			buf_appendb(dbuf, start, sz);
 			buf_appendb(buf, start, sz);
 
-			hash_put(hash, buf, TYPE_DESC);
+			hash_put(hash, buf, TYPE_Nd);
 		}
 	}
 
--- /dev/null
+++ mandocdb.h
@@ -0,0 +1,32 @@
+/*      $Id$ */
+/*
+ * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ *
+ * 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.
+ */
+
+#define	MANDOC_DB	"mandoc.db"
+#define	MANDOC_IDX	"mandoc.index"
+
+#define	TYPE_An		0x01
+#define	TYPE_Cd		0x02
+#define	TYPE_Er		0x04
+#define	TYPE_Ev		0x08
+#define	TYPE_Fn		0x10
+#define	TYPE_In		0x20
+#define	TYPE_Nd		0x40
+#define	TYPE_Nm		0x100
+#define	TYPE_Pa		0x200
+#define	TYPE_St		0x400
+#define	TYPE_Va		0x1000
+#define	TYPE_Xr		0x2000
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

             reply	other threads:[~2011-11-09  1:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-09  1:30 Ingo Schwarze [this message]
2011-11-09 10:19 ` Kristaps Dzonsons
2011-11-12 23:54 ` Ingo Schwarze
2011-11-13  0:07   ` Kristaps Dzonsons
2011-11-13  0:39     ` Ingo Schwarze
2011-11-13  9:23       ` 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=20111109013044.GA25679@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=jmc@openbsd.org \
    --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).