summaryrefslogtreecommitdiffstats
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
commit8a03dc6dd4f8c96b6231d1f60da2bd65f437a8b4 (patch)
tree121b76378b915aba7ec64f61d34338b21358fd46
parente487e44b52bbc7bfdb77346cc9a44d1a7c825d2c (diff)
downloadmandoc-8a03dc6dd4f8c96b6231d1f60da2bd65f437a8b4.tar.gz
mdoc_tokhash -> hash
Initial man hashtab (BROKEN).
-rw-r--r--libmdoc.h6
-rw-r--r--man.c2
-rw-r--r--man.h3
-rw-r--r--man_action.c1
-rw-r--r--man_hash.c53
-rw-r--r--man_macro.c1
-rw-r--r--man_term.c1
-rw-r--r--man_validate.c1
-rw-r--r--mdoc.c16
-rw-r--r--mdoc_action.c2
-rw-r--r--mdoc_hash.c9
-rw-r--r--mdoc_macro.c4
12 files changed, 71 insertions, 28 deletions
diff --git a/libmdoc.h b/libmdoc.h
index e4708b6e..0cc956bb 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -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 49db57fa..3dabf3cc 100644
--- a/man.c
+++ b/man.c
@@ -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 881e6bb4..bd50d869 100644
--- a/man.h
+++ b/man.h
@@ -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 b14afa41..c6eef21a 100644
--- a/man_action.c
+++ b/man_action.c
@@ -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 9806eff5..246f370c 100644
--- a/man_hash.c
+++ b/man_hash.c
@@ -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 6447b3bb..8c49983f 100644
--- a/man_macro.c
+++ b/man_macro.c
@@ -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 7d949470..e227ec23 100644
--- a/man_term.c
+++ b/man_term.c
@@ -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 b7fd95b8..ceded34e 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -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 82408d8a..273c8ed5 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -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 cbba4a43..a13412ee 100644
--- a/mdoc_action.c
+++ b/mdoc_action.c
@@ -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 f0496d2e..90bfab38 100644
--- a/mdoc_hash.c
+++ b/mdoc_hash.c
@@ -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 e2aacaab..4e4a799d 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -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))