source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Inventing new keywords for mostly the same thing when a
@ 2011-11-13 10:49 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2011-11-13 10:49 UTC (permalink / raw)
  To: source

Log Message:
-----------
Inventing new keywords for mostly the same thing when a well-established
set of keywords already exists is a bad idea, so reuse the mdoc(7)
macro names as apropos(1) search types.  This is a gain in brevity
as well.  Some time ago, kristaps@ agreed in principle.

The search type bit field constants are used by both mandocdb(8) and
apropos(1) and should better stay in sync, so give them their own
header file.

Modified Files:
--------------
    mdocml:
        Makefile
        apropos_db.c
        apropos_db.h
        cgi.c
        mandocdb.c

Added Files:
-----------
    mdocml:
        mandocdb.h

Revision Data
-------------
Index: apropos_db.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lapropos_db.c -Lapropos_db.c -u -p -r1.1 -r1.2
--- apropos_db.c
+++ apropos_db.c
@@ -27,6 +27,7 @@
 # include <db.h>
 #endif
 
+#include "mandocdb.h"
 #include "apropos_db.h"
 #include "mandoc.h"
 
@@ -50,20 +51,21 @@ struct	type {
 };
 
 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" },
+	{ 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 }
 };
 
@@ -89,7 +91,7 @@ btree_open(void)
 	memset(&info, 0, sizeof(BTREEINFO));
 	info.flags = R_DUP;
 
-	db = dbopen("mandoc.db", O_RDONLY, 0, DB_BTREE, &info);
+	db = dbopen(MANDOC_DB, O_RDONLY, 0, DB_BTREE, &info);
 	if (NULL != db) 
 		return(db);
 
@@ -274,7 +276,7 @@ index_open(void)
 {
 	DB		*db;
 
-	db = dbopen("mandoc.index", O_RDONLY, 0, DB_RECNO, NULL);
+	db = dbopen(MANDOC_IDX, O_RDONLY, 0, DB_RECNO, NULL);
 	if (NULL != db)
 		return(db);
 
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.7 -r1.8
--- mandocdb.c
+++ mandocdb.c
@@ -38,28 +38,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 {
@@ -728,7 +711,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
@@ -789,7 +772,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 */
@@ -801,7 +784,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 */
@@ -815,7 +798,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 */
@@ -841,7 +824,7 @@ pmdoc_Fn(MDOC_ARGS)
 		cp++;
 
 	buf_append(buf, cp);
-	hash_put(hash, buf, TYPE_FUNCTION);
+	hash_put(hash, buf, TYPE_Fn);
 }
 
 /* ARGSUSED */
@@ -855,7 +838,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 */
@@ -874,7 +857,7 @@ pmdoc_Xr(MDOC_ARGS)
 	} else
 		buf_appendb(buf, ".", 2);
 
-	hash_put(hash, buf, TYPE_XREF);
+	hash_put(hash, buf, TYPE_Xr);
 }
 
 /* ARGSUSED */
@@ -911,7 +894,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 */
@@ -925,7 +908,7 @@ pmdoc_Fo(MDOC_ARGS)
 		return;
 
 	buf_append(buf, n->child->string);
-	hash_put(hash, buf, TYPE_FUNCTION);
+	hash_put(hash, buf, TYPE_Fn);
 }
 
 
@@ -940,7 +923,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 */
@@ -952,7 +935,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 */
@@ -964,7 +947,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 */
@@ -976,7 +959,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 */
@@ -986,7 +969,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;
@@ -995,7 +978,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
@@ -1125,7 +1108,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;
@@ -1164,7 +1147,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: mandocdb.h,v 1.1 2011/11/13 10:49:57 schwarze Exp $ */
+/*
+ * 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
Index: apropos_db.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos_db.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lapropos_db.h -Lapropos_db.h -u -p -r1.1 -r1.2
--- apropos_db.h
+++ apropos_db.h
@@ -17,20 +17,6 @@
 #ifndef APROPOS_H
 #define APROPOS_H
 
-#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
-
 struct	rec {
 	char		*file; /* file in file-system */
 	char		*cat; /* category (3p, 3, etc.) */
Index: cgi.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/cgi.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lcgi.c -Lcgi.c -u -p -r1.3 -r1.4
--- cgi.c
+++ cgi.c
@@ -7,8 +7,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "apropos_db.h"
 #include "mandoc.h"
+#include "mandocdb.h"
+#include "apropos_db.h"
 
 /*
  * The page a request is trying to make.
Index: Makefile
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v
retrieving revision 1.377
retrieving revision 1.378
diff -LMakefile -LMakefile -u -p -r1.377 -r1.378
--- Makefile
+++ Makefile
@@ -97,6 +97,7 @@ SRCS		 = Makefile \
 		   mandoc.h \
 		   mandocdb.8 \
 		   mandocdb.c \
+		   mandocdb.h \
 		   mandoc_char.7 \
 		   mdoc.h \
 		   mdoc.7 \
@@ -271,7 +272,7 @@ $(MANDOC_OBJS) $(MANDOC_LNS): main.h man
 MANDOCDB_OBJS	 = mandocdb.o
 MANDOCDB_LNS	 = mandocdb.ln
 
-$(MANDOCDB_OBJS) $(MANDOCDB_LNS): mandoc.h mdoc.h man.h config.h
+$(MANDOCDB_OBJS) $(MANDOCDB_LNS): mandocdb.h mandoc.h mdoc.h man.h config.h
 
 PRECONV_OBJS	 = preconv.o
 PRECONV_LNS	 = preconv.ln
@@ -281,12 +282,12 @@ $(PRECONV_OBJS) $(PRECONV_LNS): config.h
 APROPOS_OBJS	 = apropos.o apropos_db.o
 APROPOS_LNS	 = apropos.ln apropos_db.ln
 
-$(APROPOS_OBJS) $(APROPOS_LNS): config.h mandoc.h apropos_db.h
+$(APROPOS_OBJS) $(APROPOS_LNS): config.h mandoc.h mandocdb.h apropos_db.h
 
 CGI_OBJS	 = cgi.o apropos_db.o
 CGI_LNS	 	 = cgi.ln apropos_db.ln
 
-$(CGI_OBJS) $(CGI_LNS): config.h mandoc.h apropos_db.h
+$(CGI_OBJS) $(CGI_LNS): config.h mandoc.h mandocdb.h apropos_db.h
 
 DEMANDOC_OBJS	 = demandoc.o
 DEMANDOC_LNS	 = demandoc.ln
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-11-13 10:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-13 10:49 mdocml: Inventing new keywords for mostly the same thing when a 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).