summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--chars.c48
-rw-r--r--html.c14
-rw-r--r--html.h2
-rw-r--r--man_term.c2
-rw-r--r--mandoc.h15
-rw-r--r--mdoc_term.c2
-rw-r--r--out.h13
-rw-r--r--term.c12
-rw-r--r--term.h2
10 files changed, 56 insertions, 63 deletions
diff --git a/Makefile b/Makefile
index 760f463c..577548d9 100644
--- a/Makefile
+++ b/Makefile
@@ -154,16 +154,19 @@ LIBROFF_LNS = eqn.ln \
LIBMANDOC_OBJS = $(LIBMAN_OBJS) \
$(LIBMDOC_OBJS) \
$(LIBROFF_OBJS) \
+ chars.o \
mandoc.o \
read.o
LIBMANDOC_LNS = $(LIBMAN_LNS) \
$(LIBMDOC_LNS) \
$(LIBROFF_LNS) \
+ chars.ln \
mandoc.ln \
read.ln
arch.o arch.ln: arch.in
att.o att.ln: att.in
+chars.o chars.ln: chars.in
lib.o lib.ln: lib.in
msec.o msec.ln: msec.in
st.o st.ln: st.in
@@ -198,19 +201,15 @@ MANDOC_TERM_LNS = man_term.ln \
MANDOC_OBJS = $(MANDOC_HTML_OBJS) \
$(MANDOC_TERM_OBJS) \
- chars.o \
main.o \
out.o \
tree.o
MANDOC_LNS = $(MANDOC_HTML_LNS) \
$(MANDOC_TERM_LNS) \
- chars.ln \
main.ln \
out.ln \
tree.ln
-chars.o chars.ln: chars.in
-
$(MANDOC_HTML_OBJS) $(MANDOC_HTML_LNS): html.h
$(MANDOC_TERM_OBJS) $(MANDOC_TERM_LNS): term.h
$(MANDOC_OBJS) $(MANDOC_LNS): main.h mandoc.h mdoc.h man.h config.h out.h
@@ -322,7 +321,7 @@ mandoc: $(MANDOC_OBJS) libmandoc.a
# You'll need -ldb for Linux.
mandoc-db: $(MANDOCDB_OBJS) libmandoc.a
- $(CC) -o $@ $(MANDOCDB_OBJS) libmandoc.a
+ $(CC) -o $@ $(MANDOCDB_OBJS) libmandoc.a -ldb
llib-lmandoc.ln: $(MANDOC_LNS)
$(LINT) $(LINTFLAGS) -Cmandoc $(MANDOC_LNS)
diff --git a/chars.c b/chars.c
index 61569f88..be1077ce 100644
--- a/chars.c
+++ b/chars.c
@@ -25,7 +25,6 @@
#include <string.h>
#include "mandoc.h"
-#include "out.h"
#define PRINT_HI 126
#define PRINT_LO 32
@@ -55,32 +54,27 @@ struct ln {
#include "chars.in"
-struct ctab {
- enum chars type;
+struct mchars {
+ enum mcharst type;
struct ln **htab;
};
static inline int match(const struct ln *,
const char *, size_t, int);
-static const struct ln *find(struct ctab *, const char *, size_t, int);
-
+static const struct ln *find(struct mchars *, const char *, size_t, int);
void
-chars_free(void *arg)
+mchars_free(struct mchars *arg)
{
- struct ctab *tab;
-
- tab = (struct ctab *)arg;
- free(tab->htab);
- free(tab);
+ free(arg->htab);
+ free(arg);
}
-
-void *
-chars_init(enum chars type)
+struct mchars *
+mchars_init(enum mcharst type)
{
- struct ctab *tab;
+ struct mchars *tab;
struct ln **htab;
struct ln *pp;
int i, hash;
@@ -92,7 +86,7 @@ chars_init(enum chars type)
* (they're in-line re-ordered during lookup).
*/
- tab = mandoc_malloc(sizeof(struct ctab));
+ tab = mandoc_malloc(sizeof(struct mchars));
htab = mandoc_calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **));
for (i = 0; i < LINES_MAX; i++) {
@@ -118,11 +112,11 @@ chars_init(enum chars type)
* Special character to Unicode codepoint.
*/
int
-chars_spec2cp(void *arg, const char *p, size_t sz)
+mchars_spec2cp(struct mchars *arg, const char *p, size_t sz)
{
const struct ln *ln;
- ln = find((struct ctab *)arg, p, sz, CHARS_CHAR);
+ ln = find(arg, p, sz, CHARS_CHAR);
if (NULL == ln)
return(-1);
return(ln->unicode);
@@ -133,11 +127,11 @@ chars_spec2cp(void *arg, const char *p, size_t sz)
* Reserved word to Unicode codepoint.
*/
int
-chars_res2cp(void *arg, const char *p, size_t sz)
+mchars_res2cp(struct mchars *arg, const char *p, size_t sz)
{
const struct ln *ln;
- ln = find((struct ctab *)arg, p, sz, CHARS_STRING);
+ ln = find(arg, p, sz, CHARS_STRING);
if (NULL == ln)
return(-1);
return(ln->unicode);
@@ -149,7 +143,7 @@ chars_res2cp(void *arg, const char *p, size_t sz)
* represented as a null-terminated string for additional safety.
*/
const char *
-chars_num2char(const char *p, size_t sz)
+mchars_num2char(const char *p, size_t sz)
{
int i;
static char c[2];
@@ -169,11 +163,11 @@ chars_num2char(const char *p, size_t sz)
* Special character to string array.
*/
const char *
-chars_spec2str(void *arg, const char *p, size_t sz, size_t *rsz)
+mchars_spec2str(struct mchars *arg, const char *p, size_t sz, size_t *rsz)
{
const struct ln *ln;
- ln = find((struct ctab *)arg, p, sz, CHARS_CHAR);
+ ln = find(arg, p, sz, CHARS_CHAR);
if (NULL == ln)
return(NULL);
@@ -186,11 +180,11 @@ chars_spec2str(void *arg, const char *p, size_t sz, size_t *rsz)
* Reserved word to string array.
*/
const char *
-chars_res2str(void *arg, const char *p, size_t sz, size_t *rsz)
+mchars_res2str(struct mchars *arg, const char *p, size_t sz, size_t *rsz)
{
const struct ln *ln;
- ln = find((struct ctab *)arg, p, sz, CHARS_STRING);
+ ln = find(arg, p, sz, CHARS_STRING);
if (NULL == ln)
return(NULL);
@@ -198,9 +192,8 @@ chars_res2str(void *arg, const char *p, size_t sz, size_t *rsz)
return(ln->ascii);
}
-
static const struct ln *
-find(struct ctab *tab, const char *p, size_t sz, int type)
+find(struct mchars *tab, const char *p, size_t sz, int type)
{
struct ln *pp, *prev;
struct ln **htab;
@@ -243,7 +236,6 @@ find(struct ctab *tab, const char *p, size_t sz, int type)
return(NULL);
}
-
static inline int
match(const struct ln *ln, const char *p, size_t sz, int type)
{
diff --git a/html.c b/html.c
index bc5049c7..d5eee733 100644
--- a/html.c
+++ b/html.c
@@ -122,7 +122,7 @@ ml_alloc(char *outopts, enum htmltype type)
h->type = type;
h->tags.head = NULL;
- h->symtab = chars_init(CHARS_HTML);
+ h->symtab = mchars_init(MCHARS_HTML);
while (outopts && *outopts)
switch (getsubopt(&outopts, UNCONST(toks), &v)) {
@@ -172,7 +172,7 @@ html_free(void *p)
}
if (h->symtab)
- chars_free(h->symtab);
+ mchars_free(h->symtab);
free(h);
}
@@ -214,7 +214,7 @@ print_num(struct html *h, const char *p, size_t len)
{
const char *rhs;
- rhs = chars_num2char(p, len);
+ rhs = mchars_num2char(p, len);
if (rhs)
putchar((int)*rhs);
}
@@ -226,7 +226,7 @@ print_spec(struct html *h, const char *p, size_t len)
const char *rhs;
size_t sz;
- if ((cp = chars_spec2cp(h->symtab, p, len)) > 0) {
+ if ((cp = mchars_spec2cp(h->symtab, p, len)) > 0) {
printf("&#%d;", cp);
return;
} else if (-1 == cp && 1 == len) {
@@ -235,7 +235,7 @@ print_spec(struct html *h, const char *p, size_t len)
} else if (-1 == cp)
return;
- if (NULL != (rhs = chars_spec2str(h->symtab, p, len, &sz)))
+ if (NULL != (rhs = mchars_spec2str(h->symtab, p, len, &sz)))
fwrite(rhs, 1, sz, stdout);
}
@@ -247,13 +247,13 @@ print_res(struct html *h, const char *p, size_t len)
const char *rhs;
size_t sz;
- if ((cp = chars_res2cp(h->symtab, p, len)) > 0) {
+ if ((cp = mchars_res2cp(h->symtab, p, len)) > 0) {
printf("&#%d;", cp);
return;
} else if (-1 == cp)
return;
- if (NULL != (rhs = chars_res2str(h->symtab, p, len, &sz)))
+ if (NULL != (rhs = mchars_res2str(h->symtab, p, len, &sz)))
fwrite(rhs, 1, sz, stdout);
}
diff --git a/html.h b/html.h
index 8cb83954..4cea5ca5 100644
--- a/html.h
+++ b/html.h
@@ -120,7 +120,7 @@ struct html {
struct tagq tags; /* stack of open tags */
struct rofftbl tbl; /* current table */
struct tag *tblt; /* current open table scope */
- void *symtab; /* character-escapes */
+ struct mchars *symtab; /* character-escapes */
char *base_man; /* base for manpage href */
char *base_includes; /* base for include href */
char *style; /* style-sheet URI */
diff --git a/man_term.c b/man_term.c
index 8d84eedf..7b1b99db 100644
--- a/man_term.c
+++ b/man_term.c
@@ -158,7 +158,7 @@ terminal_man(void *arg, const struct man *man)
if (NULL == p->symtab)
switch (p->enc) {
case (TERMENC_ASCII):
- p->symtab = chars_init(CHARS_ASCII);
+ p->symtab = mchars_init(MCHARS_ASCII);
break;
default:
abort();
diff --git a/mandoc.h b/mandoc.h
index a838c325..477f8809 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -302,10 +302,16 @@ enum mandoc_esc {
ESCAPE_NOSPACE /* suppress space if the last on a line */
};
+enum mcharst {
+ MCHARS_ASCII, /* 7-bit ascii representation */
+ MCHARS_HTML /* unicode values */
+};
+
typedef void (*mandocmsg)(enum mandocerr, enum mandoclevel,
const char *, int, int, const char *);
struct mparse;
+struct mchars;
struct mdoc;
struct man;
@@ -326,6 +332,15 @@ void *mandoc_realloc(void *, size_t);
enum mandoc_esc mandoc_escape(const char **, const char **, int *);
+struct mchars *mchars_init(enum mcharst);
+const char *mchars_num2char(const char *, size_t);
+const char *mchars_spec2str(struct mchars *, const char *, size_t, size_t *);
+int mchars_spec2cp(struct mchars *, const char *, size_t);
+const char *mchars_res2str(struct mchars *, const char *, size_t, size_t *);
+int mchars_res2cp(struct mchars *, const char *, size_t);
+void mchars_free(struct mchars *);
+
+
__END_DECLS
#endif /*!MANDOC_H*/
diff --git a/mdoc_term.c b/mdoc_term.c
index d08c3b29..2aed2fed 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -266,7 +266,7 @@ terminal_mdoc(void *arg, const struct mdoc *mdoc)
if (NULL == p->symtab)
switch (p->enc) {
case (TERMENC_ASCII):
- p->symtab = chars_init(CHARS_ASCII);
+ p->symtab = mchars_init(MCHARS_ASCII);
break;
default:
abort();
diff --git a/out.h b/out.h
index 77414d71..3e70c4bf 100644
--- a/out.h
+++ b/out.h
@@ -31,11 +31,6 @@ enum roffscale {
SCALE_MAX
};
-enum chars {
- CHARS_ASCII, /* 7-bit ascii representation */
- CHARS_HTML /* unicode values */
-};
-
struct roffcol {
size_t width; /* width of cell */
size_t decimal; /* decimal position in cell */
@@ -72,14 +67,6 @@ int a2roffsu(const char *, struct roffsu *, enum roffscale);
void time2a(time_t, char *, size_t);
void tblcalc(struct rofftbl *tbl, const struct tbl_span *);
-void *chars_init(enum chars);
-const char *chars_num2char(const char *, size_t);
-const char *chars_spec2str(void *, const char *, size_t, size_t *);
-int chars_spec2cp(void *, const char *, size_t);
-const char *chars_res2str(void *, const char *, size_t, size_t *);
-int chars_res2cp(void *, const char *, size_t);
-void chars_free(void *);
-
__END_DECLS
#endif /*!OUT_H*/
diff --git a/term.c b/term.c
index 742b9877..b78f9ad1 100644
--- a/term.c
+++ b/term.c
@@ -47,7 +47,7 @@ term_free(struct termp *p)
if (p->buf)
free(p->buf);
if (p->symtab)
- chars_free(p->symtab);
+ mchars_free(p->symtab);
free(p);
}
@@ -350,7 +350,7 @@ numbered(struct termp *p, const char *word, size_t len)
{
const char *rhs;
- rhs = chars_num2char(word, len);
+ rhs = mchars_num2char(word, len);
if (rhs)
encode(p, rhs, 1);
}
@@ -362,7 +362,7 @@ spec(struct termp *p, const char *word, size_t len)
const char *rhs;
size_t sz;
- rhs = chars_spec2str(p->symtab, word, len, &sz);
+ rhs = mchars_spec2str(p->symtab, word, len, &sz);
if (rhs)
encode(p, rhs, sz);
else if (1 == len)
@@ -376,7 +376,7 @@ res(struct termp *p, const char *word, size_t len)
const char *rhs;
size_t sz;
- rhs = chars_res2str(p->symtab, word, len, &sz);
+ rhs = mchars_res2str(p->symtab, word, len, &sz);
if (rhs)
encode(p, rhs, sz);
}
@@ -623,11 +623,11 @@ term_strlen(const struct termp *p, const char *cp)
switch (esc) {
case (ESCAPE_PREDEF):
- rhs = chars_res2str
+ rhs = mchars_res2str
(p->symtab, seq, ssz, &rsz);
break;
case (ESCAPE_SPECIAL):
- rhs = chars_spec2str
+ rhs = mchars_spec2str
(p->symtab, seq, ssz, &rsz);
if (ssz != 1 || rhs)
diff --git a/term.h b/term.h
index 0ada6094..45392359 100644
--- a/term.h
+++ b/term.h
@@ -105,7 +105,7 @@ struct termp {
#define TERMP_PREKEEP (1 << 15) /* ...starting with the next one. */
char *buf; /* Output buffer. */
enum termenc enc; /* Type of encoding. */
- void *symtab; /* Encoded-symbol table. */
+ struct mchars *symtab; /* Encoded-symbol table. */
enum termfont fontl; /* Last font set. */
enum termfont fontq[10]; /* Symmetric fonts. */
int fonti; /* Index of font stack. */