summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-04-02 06:51:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-04-02 06:51:44 +0000
commitf8fe5d9a147b378ab9cd53f2287730070ded22c2 (patch)
treeac8804842dcd211cf3ee64177bff113640075a2c
parent4cd2606cca8b6f78a9d90bec6f4fa0c45c2dcd0f (diff)
downloadmandoc-f8fe5d9a147b378ab9cd53f2287730070ded22c2.tar.gz
mandoc-f8fe5d9a147b378ab9cd53f2287730070ded22c2.tar.zst
mandoc-f8fe5d9a147b378ab9cd53f2287730070ded22c2.zip
mdoc_tokhash -> hash
Initial man hashtab (BROKEN).
-rw-r--r--libmdoc.h8
-rw-r--r--man.c4
-rw-r--r--man.h5
-rw-r--r--man_action.c3
-rw-r--r--man_hash.c55
-rw-r--r--man_macro.c3
-rw-r--r--man_term.c3
-rw-r--r--man_validate.c3
-rw-r--r--mdoc.c18
-rw-r--r--mdoc_action.c4
-rw-r--r--mdoc_hash.c11
-rw-r--r--mdoc_macro.c6
12 files changed, 83 insertions, 40 deletions
diff --git a/libmdoc.h b/libmdoc.h
index f7054711..591c3198 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmdoc.h,v 1.3 2009/03/31 13:50:19 kristaps Exp $ */
+/* $Id: libmdoc.h,v 1.4 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -111,9 +111,9 @@ int mdoc_tail_alloc(struct mdoc *, int, int, int);
int mdoc_body_alloc(struct mdoc *, int, int, int);
void mdoc_node_free(struct mdoc_node *);
void mdoc_node_freelist(struct mdoc_node *);
-void *mdoc_tokhash_alloc(void);
-int mdoc_tokhash_find(const void *, const char *);
-void mdoc_tokhash_free(void *);
+void *mdoc_hash_alloc(void);
+int mdoc_hash_find(const void *, const char *);
+void mdoc_hash_free(void *);
int mdoc_iscdelim(char);
int mdoc_isdelim(const char *);
size_t mdoc_isescape(const char *);
diff --git a/man.c b/man.c
index 56822f40..99af2012 100644
--- a/man.c
+++ b/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.13 2009/03/27 14:56:15 kristaps Exp $ */
+/* $Id: man.c,v 1.14 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -32,7 +32,7 @@ const char *const __man_macronames[MAN_MAX] = {
"IP", "HP", "SM", "SB",
"BI", "IB", "BR", "RB",
"R", "B", "I", "IR",
- "RI", "br"
+ "RI", "br", "na"
};
const char * const *man_macronames = __man_macronames;
diff --git a/man.h b/man.h
index 699d4223..27571017 100644
--- a/man.h
+++ b/man.h
@@ -1,4 +1,4 @@
-/* $Id: man.h,v 1.7 2009/03/27 14:56:15 kristaps Exp $ */
+/* $Id: man.h,v 1.8 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -43,7 +43,8 @@
#define MAN_IR 19
#define MAN_RI 20
#define MAN_br 21
-#define MAN_MAX 22
+#define MAN_na 22
+#define MAN_MAX 23
enum man_type {
MAN_TEXT,
diff --git a/man_action.c b/man_action.c
index ca4139c2..09885ee8 100644
--- a/man_action.c
+++ b/man_action.c
@@ -1,4 +1,4 @@
-/* $Id: man_action.c,v 1.7 2009/03/31 13:50:19 kristaps Exp $ */
+/* $Id: man_action.c,v 1.8 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -60,6 +60,7 @@ const struct actions man_actions[MAN_MAX] = {
{ NULL }, /* IR */
{ NULL }, /* RI */
{ NULL }, /* br */
+ { NULL }, /* na */
};
diff --git a/man_hash.c b/man_hash.c
index 039ead53..9aaafb20 100644
--- a/man_hash.c
+++ b/man_hash.c
@@ -1,4 +1,4 @@
-/* $Id: man_hash.c,v 1.4 2009/03/31 13:50:19 kristaps Exp $ */
+/* $Id: man_hash.c,v 1.5 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -16,17 +16,19 @@
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "libman.h"
+
/* ARGUSED */
void
man_hash_free(void *htab)
{
- /* Do nothing. */
+ free(htab);
}
@@ -34,22 +36,57 @@ man_hash_free(void *htab)
void *
man_hash_alloc(void)
{
+ int *htab;
+ int i, j, x;
+
+ htab = calloc(26 * 4, sizeof(int));
+ if (NULL == htab)
+ return(NULL);
+
+ for (i = 1; i < MAN_MAX; i++) {
+ x = man_macronames[i][0];
+
+ assert((x >= 65 && x <= 90) ||
+ (x >= 97 && x <= 122));
+
+ x -= (x <= 90) ? 65 : 97;
+ x *= 4;
- /* Do nothing. */
- return(NULL);
+ for (j = 0; j < 4; j++)
+ if (0 == htab[x + j]) {
+ htab[x + j] = i;
+ break;
+ }
+
+ assert(j < 4);
+ }
+
+ return((void *)htab);
}
int
man_hash_find(const void *arg, const char *tmp)
{
- int i;
+ int x, i, tok;
+ const int *htab;
+
+ htab = (const int *)arg;
+
+ if (0 == (x = tmp[0]))
+ return(MAN_MAX);
+ if ( ! ((x >= 65 && x <= 90) || (x >= 97 && x <= 122)))
+ return(MAN_MAX);
- /* TODO */
+ x -= (x <= 90) ? 65 : 97;
+ x *= 4;
- for (i = 0; i < MAN_MAX; i++)
- if (0 == strcmp(tmp, man_macronames[i]))
- return(i);
+ for (i = 0; i < 4; i++) {
+ if (0 == (tok = htab[x + i]))
+ return(MAN_MAX);
+ if (0 == strcmp(tmp, man_macronames[tok]))
+ return(tok);
+ }
return(MAN_MAX);
}
diff --git a/man_macro.c b/man_macro.c
index 72578fb6..91490bf0 100644
--- a/man_macro.c
+++ b/man_macro.c
@@ -1,4 +1,4 @@
-/* $Id: man_macro.c,v 1.11 2009/03/31 13:50:19 kristaps Exp $ */
+/* $Id: man_macro.c,v 1.12 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -52,6 +52,7 @@ static int man_flags[MAN_MAX] = {
FL_NLINE, /* IR */
FL_NLINE, /* RI */
0, /* br */
+ 0, /* na */
};
int
diff --git a/man_term.c b/man_term.c
index bb8df7ba..f5fa109e 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.5 2009/03/27 14:56:15 kristaps Exp $ */
+/* $Id: man_term.c,v 1.6 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -81,6 +81,7 @@ static const struct termact termacts[MAN_MAX] = {
{ pre_IR, NULL }, /* IR */
{ pre_RI, NULL }, /* RI */
{ pre_PP, NULL }, /* br */
+ { NULL, NULL }, /* na */
};
static void print_head(struct termp *,
diff --git a/man_validate.c b/man_validate.c
index f2c5b90c..54cb0448 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -1,4 +1,4 @@
-/* $Id: man_validate.c,v 1.5 2009/03/27 14:56:15 kristaps Exp $ */
+/* $Id: man_validate.c,v 1.6 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -72,6 +72,7 @@ static const struct man_valid man_valids[MAN_MAX] = {
{ NULL }, /* IR */
{ NULL }, /* RI */
{ posts_eq0 }, /* br */
+ { posts_eq0 }, /* na */
};
diff --git a/mdoc.c b/mdoc.c
index 2c9aa845..717c1a11 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.73 2009/03/31 13:50:19 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.74 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -180,7 +180,7 @@ mdoc_free(struct mdoc *mdoc)
mdoc_free1(mdoc);
if (mdoc->htab)
- mdoc_tokhash_free(mdoc->htab);
+ mdoc_hash_free(mdoc->htab);
free(mdoc);
}
@@ -192,16 +192,18 @@ mdoc_alloc(void *data, int pflags, const struct mdoc_cb *cb)
if (NULL == (p = calloc(1, sizeof(struct mdoc))))
return(NULL);
+ if (cb)
+ (void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb));
p->data = data;
- p->htab = mdoc_tokhash_alloc();
p->pflags = pflags;
- if (cb)
- (void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb));
-
- if (mdoc_alloc1(p))
+ if (NULL == (p->htab = mdoc_hash_alloc())) {
+ free(p);
+ return(NULL);
+ } else if (mdoc_alloc1(p))
return(p);
+
free(p);
return(NULL);
}
@@ -624,7 +626,7 @@ parsemacro(struct mdoc *m, int ln, char *buf)
return(1);
}
- if (MDOC_MAX == (c = mdoc_tokhash_find(m->htab, mac))) {
+ if (MDOC_MAX == (c = mdoc_hash_find(m->htab, mac))) {
if ( ! macrowarn(m, ln, mac))
goto err;
return(1);
diff --git a/mdoc_action.c b/mdoc_action.c
index 72f7bc4f..cd423964 100644
--- a/mdoc_action.c
+++ b/mdoc_action.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_action.c,v 1.2 2009/03/31 13:50:19 kristaps Exp $ */
+/* $Id: mdoc_action.c,v 1.3 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -609,7 +609,7 @@ post_bl_width(struct mdoc *m)
if (0 == strcmp(p, "Ds"))
width = 8;
- else if (MDOC_MAX == (tok = mdoc_tokhash_find(m->htab, p)))
+ else if (MDOC_MAX == (tok = mdoc_hash_find(m->htab, p)))
return(1);
else if (0 == (width = mdoc_macro2len(tok)))
return(vwarn(m, WNOWIDTH));
diff --git a/mdoc_hash.c b/mdoc_hash.c
index 5127095c..cf8c2056 100644
--- a/mdoc_hash.c
+++ b/mdoc_hash.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_hash.c,v 1.1 2009/03/23 14:22:11 kristaps Exp $ */
+/* $Id: mdoc_hash.c,v 1.2 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -18,7 +18,6 @@
*/
#include <assert.h>
#include <ctype.h>
-#include <err.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -32,7 +31,7 @@
*/
void
-mdoc_tokhash_free(void *htab)
+mdoc_hash_free(void *htab)
{
free(htab);
@@ -40,14 +39,14 @@ mdoc_tokhash_free(void *htab)
void *
-mdoc_tokhash_alloc(void)
+mdoc_hash_alloc(void)
{
int i, major, minor, ind;
const void **htab;
htab = calloc(27 * 26 * 3, sizeof(struct mdoc_macro *));
if (NULL == htab)
- err(1, "calloc");
+ return(NULL);
for (i = 1; i < MDOC_MAX; i++) {
major = mdoc_macronames[i][0];
@@ -95,7 +94,7 @@ mdoc_tokhash_alloc(void)
int
-mdoc_tokhash_find(const void *arg, const char *tmp)
+mdoc_hash_find(const void *arg, const char *tmp)
{
int major, minor, ind, slot;
const void **htab;
diff --git a/mdoc_macro.c b/mdoc_macro.c
index 75431fc4..3f11ed1e 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.5 2009/03/31 13:50:19 kristaps Exp $ */
+/* $Id: mdoc_macro.c,v 1.6 2009/04/02 06:51:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -328,7 +328,7 @@ lookup(struct mdoc *mdoc, int line, int pos, int from, const char *p)
{
int res;
- res = mdoc_tokhash_find(mdoc->htab, p);
+ res = mdoc_hash_find(mdoc->htab, p);
if (MDOC_PARSED & mdoc_macros[from].flags)
return(res);
if (MDOC_MAX == res)
@@ -1473,7 +1473,7 @@ phrase(struct mdoc *mdoc, int line, int ppos, char *buf)
*/
c = quoted ? MDOC_MAX :
- mdoc_tokhash_find(mdoc->htab, &buf[la]);
+ mdoc_hash_find(mdoc->htab, &buf[la]);
if (MDOC_MAX != c) {
if ( ! mdoc_macro(mdoc, c, line, la, &i, buf))