summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--apropos_db.c34
-rw-r--r--apropos_db.h14
-rw-r--r--cgi.c3
-rw-r--r--mandocdb.c53
-rw-r--r--mandocdb.h32
6 files changed, 74 insertions, 69 deletions
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 30b9217e..75a5df2d 100644
--- a/apropos_db.c
+++ b/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);
diff --git a/apropos_db.h b/apropos_db.h
index a2c90239..135f6793 100644
--- a/apropos_db.h
+++ b/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.) */
diff --git a/cgi.c b/cgi.c
index 72b7c971..be2eed1f 100644
--- a/cgi.c
+++ b/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.
diff --git a/mandocdb.c b/mandocdb.c
index a8057716..d1eb31c9 100644
--- a/mandocdb.c
+++ b/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);
}
}
diff --git a/mandocdb.h b/mandocdb.h
new file mode 100644
index 00000000..a57623cf
--- /dev/null
+++ b/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