From 58b2b9f4741e56383779973cc412ca087987b114 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sun, 13 Nov 2011 10:49:57 +0000 Subject: 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. --- Makefile | 7 ++++--- apropos_db.c | 36 +++++++++++++++++++----------------- apropos_db.h | 16 +--------------- cgi.c | 5 +++-- mandocdb.c | 55 +++++++++++++++++++------------------------------------ mandocdb.h | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 73 deletions(-) create mode 100644 mandocdb.h diff --git a/Makefile b/Makefile index af8e7097..5b30f07a 100644 --- a/Makefile +++ b/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 mandoc.h mdoc.h man.h config.h out.h 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 diff --git a/apropos_db.c b/apropos_db.c index 8ec6130e..98ae214f 100644 --- a/apropos_db.c +++ b/apropos_db.c @@ -1,4 +1,4 @@ -/* $Id: apropos_db.c,v 1.1 2011/11/13 10:12:05 schwarze Exp $ */ +/* $Id: apropos_db.c,v 1.2 2011/11/13 10:49:57 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -27,6 +27,7 @@ # include #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); diff --git a/apropos_db.h b/apropos_db.h index fd37931c..7801b126 100644 --- a/apropos_db.h +++ b/apropos_db.h @@ -1,4 +1,4 @@ -/* $Id: apropos_db.h,v 1.1 2011/11/13 10:12:05 schwarze Exp $ */ +/* $Id: apropos_db.h,v 1.2 2011/11/13 10:49:57 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -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.) */ diff --git a/cgi.c b/cgi.c index 67ad47bb..b6ded9ff 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.3 2011/11/13 10:12:05 schwarze Exp $ */ +/* $Id: cgi.c,v 1.4 2011/11/13 10:49:57 schwarze Exp $ */ #include #include #include @@ -7,8 +7,9 @@ #include #include -#include "apropos_db.h" #include "mandoc.h" +#include "mandocdb.h" +#include "apropos_db.h" /* * The page a request is trying to make. diff --git a/mandocdb.c b/mandocdb.c index 7e2b4a54..9bb66c70 100644 --- a/mandocdb.c +++ b/mandocdb.c @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.7 2011/11/13 00:53:13 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.8 2011/11/13 10:49:57 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -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); } } diff --git a/mandocdb.h b/mandocdb.h new file mode 100644 index 00000000..2871ec8e --- /dev/null +++ b/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 + * + * 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 -- cgit v1.2.3-56-ge451