source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Get rid of the local keys table, use the new mansearch_const.c.
@ 2014-01-19  1:18 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-01-19  1:18 UTC (permalink / raw)
  To: source

Log Message:
-----------
Get rid of the local keys table, use the new mansearch_const.c.
No functional change.

Modified Files:
--------------
    mdocml:
        Makefile
        mansearch.c

Revision Data
-------------
Index: mansearch.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mansearch.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -Lmansearch.c -Lmansearch.c -u -p -r1.19 -r1.20
--- mansearch.c
+++ mansearch.c
@@ -42,6 +42,9 @@
 #include "manpath.h"
 #include "mansearch.h"
 
+extern int mansearch_keymax;
+extern const char *const mansearch_keynames[];
+
 #define	SQL_BIND_TEXT(_db, _s, _i, _v) \
 	do { if (SQLITE_OK != sqlite3_bind_text \
 		((_s), (_i)++, (_v), -1, SQLITE_STATIC)) \
@@ -73,57 +76,6 @@ struct	match {
 	int		 form; /* 0 == catpage */
 };
 
-struct	type {
-	uint64_t	 bits;
-	const char	*name;
-};
-
-static	const struct type types[] = {
-	{ TYPE_An,  "An" },
-	{ TYPE_Ar,  "Ar" },
-	{ TYPE_At,  "At" },
-	{ TYPE_Bsx, "Bsx" },
-	{ TYPE_Bx,  "Bx" },
-	{ TYPE_Cd,  "Cd" },
-	{ TYPE_Cm,  "Cm" },
-	{ TYPE_Dv,  "Dv" },
-	{ TYPE_Dx,  "Dx" },
-	{ TYPE_Em,  "Em" },
-	{ TYPE_Er,  "Er" },
-	{ TYPE_Ev,  "Ev" },
-	{ TYPE_Fa,  "Fa" },
-	{ TYPE_Fl,  "Fl" },
-	{ TYPE_Fn,  "Fn" },
-	{ TYPE_Fn,  "Fo" },
-	{ TYPE_Ft,  "Ft" },
-	{ TYPE_Fx,  "Fx" },
-	{ TYPE_Ic,  "Ic" },
-	{ TYPE_In,  "In" },
-	{ TYPE_Lb,  "Lb" },
-	{ TYPE_Li,  "Li" },
-	{ TYPE_Lk,  "Lk" },
-	{ TYPE_Ms,  "Ms" },
-	{ TYPE_Mt,  "Mt" },
-	{ TYPE_Nd,  "Nd" },
-	{ TYPE_Nm,  "Nm" },
-	{ TYPE_Nx,  "Nx" },
-	{ TYPE_Ox,  "Ox" },
-	{ TYPE_Pa,  "Pa" },
-	{ TYPE_Rs,  "Rs" },
-	{ TYPE_Sh,  "Sh" },
-	{ TYPE_Ss,  "Ss" },
-	{ TYPE_St,  "St" },
-	{ TYPE_Sy,  "Sy" },
-	{ TYPE_Tn,  "Tn" },
-	{ TYPE_Va,  "Va" },
-	{ TYPE_Va,  "Vt" },
-	{ TYPE_Xr,  "Xr" },
-	{ TYPE_sec, "sec" },
-	{ TYPE_arch,"arch" },
-	{ ~0ULL,    "any" },
-	{ 0ULL, NULL }
-};
-
 static	void		 buildnames(struct manpage *, sqlite3 *,
 				sqlite3_stmt *, uint64_t,
 				const char *, int form);
@@ -153,9 +105,9 @@ mansearch(const struct mansearch *search
 		const char *outkey,
 		struct manpage **res, size_t *sz)
 {
-	int		 fd, rc, c, ibit;
+	int		 fd, rc, c, indexbit;
 	int64_t		 id;
-	uint64_t	 outbit;
+	uint64_t	 outbit, iterbit;
 	char		 buf[PATH_MAX];
 	char		*sql;
 	struct manpage	*mpage;
@@ -189,9 +141,12 @@ mansearch(const struct mansearch *search
 
 	outbit = 0;
 	if (NULL != outkey) {
-		for (ibit = 0; types[ibit].bits; ibit++) {
-			if (0 == strcasecmp(types[ibit].name, outkey)) {
-				outbit = types[ibit].bits;
+		for (indexbit = 0, iterbit = 1;
+		     indexbit < mansearch_keymax;
+		     indexbit++, iterbit <<= 1) {
+			if (0 == strcasecmp(outkey,
+			    mansearch_keynames[indexbit])) {
+				outbit = iterbit;
 				break;
 			}
 		}
@@ -623,8 +578,8 @@ exprterm(const struct mansearch *search,
 	char		 errbuf[BUFSIZ];
 	struct expr	*e;
 	char		*key, *v;
-	size_t		 i;
-	int		 irc;
+	uint64_t	 iterbit;
+	int		 i, irc;
 
 	if ('\0' == *buf)
 		return(NULL);
@@ -672,15 +627,22 @@ exprterm(const struct mansearch *search,
 	while (NULL != (key = strsep(&buf, ","))) {
 		if ('\0' == *key)
 			continue;
-		i = 0;
-		while (types[i].bits && 
-			strcasecmp(types[i].name, key))
-			i++;
-		if (0 == types[i].bits) {
-			free(e);
-			return(NULL);
+		for (i = 0, iterbit = 1;
+		     i < mansearch_keymax;
+		     i++, iterbit <<= 1) {
+			if (0 == strcasecmp(key,
+			    mansearch_keynames[i])) {
+				e->bits |= iterbit;
+				break;
+			}
+		}
+		if (i == mansearch_keymax) {
+			if (strcasecmp(key, "any")) {
+				free(e);
+				return(NULL);
+			}
+			e->bits |= ~0ULL;
 		}
-		e->bits |= types[i].bits;
 	}
 
 	return(e);
Index: Makefile
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v
retrieving revision 1.411
retrieving revision 1.412
diff -LMakefile -LMakefile -u -p -r1.411 -r1.412
--- Makefile
+++ Makefile
@@ -256,10 +256,10 @@ $(MANDOCDB_OBJS): mansearch.h mandoc.h m
 PRECONV_OBJS	 = preconv.o
 $(PRECONV_OBJS): config.h
 
-APROPOS_OBJS	 = apropos.o mansearch.o manpath.o
+APROPOS_OBJS	 = apropos.o mansearch.o mansearch_const.o manpath.o
 $(APROPOS_OBJS): config.h manpath.h mansearch.h
 
-MANPAGE_OBJS	 = manpage.o mansearch.o manpath.o
+MANPAGE_OBJS	 = manpage.o mansearch.o mansearch_const.o manpath.o
 $(MANPAGE_OBJS): config.h manpath.h mansearch.h
 
 DEMANDOC_OBJS	 = demandoc.o
--
 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:[~2014-01-19  1:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-19  1:18 mdocml: Get rid of the local keys table, use the new mansearch_const.c 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).