diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-11-13 10:40:53 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-11-13 10:40:53 +0000 |
commit | a8cf81082537b1b37a4ee51b5147db17b6f794e9 (patch) | |
tree | b1c7e2141418da6c727fb0f1cc34ee3217e8529f /usr.bin | |
parent | c1a0cbbbec9055ccd98836dda5d211c0c0ddb81f (diff) |
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.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/apropos_db.c | 36 | ||||
-rw-r--r-- | usr.bin/mandoc/apropos_db.h | 16 | ||||
-rw-r--r-- | usr.bin/mandoc/mandocdb.c | 55 | ||||
-rw-r--r-- | usr.bin/mandoc/mandocdb.h | 32 |
4 files changed, 71 insertions, 68 deletions
diff --git a/usr.bin/mandoc/apropos_db.c b/usr.bin/mandoc/apropos_db.c index 0166ccef4da..90176366be3 100644 --- a/usr.bin/mandoc/apropos_db.c +++ b/usr.bin/mandoc/apropos_db.c @@ -1,4 +1,4 @@ -/* $Id: apropos_db.c,v 1.1 2011/11/13 10:28:38 schwarze Exp $ */ +/* $Id: apropos_db.c,v 1.2 2011/11/13 10:40:52 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -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/usr.bin/mandoc/apropos_db.h b/usr.bin/mandoc/apropos_db.h index 2008ff73b05..c64136318b1 100644 --- a/usr.bin/mandoc/apropos_db.h +++ b/usr.bin/mandoc/apropos_db.h @@ -1,4 +1,4 @@ -/* $Id: apropos_db.h,v 1.1 2011/11/13 10:28:38 schwarze Exp $ */ +/* $Id: apropos_db.h,v 1.2 2011/11/13 10:40:52 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -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/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index 80b9468f677..49ac04ccce5 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.4 2011/11/13 00:53:07 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.5 2011/11/13 10:40:52 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -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); } } diff --git a/usr.bin/mandoc/mandocdb.h b/usr.bin/mandoc/mandocdb.h new file mode 100644 index 00000000000..4e67239eed2 --- /dev/null +++ b/usr.bin/mandoc/mandocdb.h @@ -0,0 +1,32 @@ +/* $Id: mandocdb.h,v 1.1 2011/11/13 10:40:52 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 |