diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | libman.h | 1 | ||||
-rw-r--r-- | libmandoc.h | 38 | ||||
-rw-r--r-- | libmdoc.h | 1 | ||||
-rw-r--r-- | man.c | 4 | ||||
-rw-r--r-- | mdoc.c | 8 | ||||
-rw-r--r-- | mdoc_validate.c | 2 | ||||
-rw-r--r-- | read.c | 13 | ||||
-rw-r--r-- | roff.c | 45 |
9 files changed, 61 insertions, 57 deletions
@@ -33,6 +33,9 @@ INSTALL_LIB = $(INSTALL) -m 0644 INSTALL_SOURCE = $(INSTALL) -m 0644 INSTALL_MAN = $(INSTALL_DATA) +# Linux needs -ldb to compile mandocdb. +#DBLIB = -ldb + all: mandoc preconv SRCS = Makefile \ @@ -353,9 +356,8 @@ mandoc: $(MANDOC_OBJS) libmandoc.a llib-lmandoc.ln: $(MANDOC_LNS) $(LINT) $(LINTFLAGS) -Cmandoc $(MANDOC_LNS) -# You'll need -ldb for Linux. mandocdb: $(MANDOCDB_OBJS) libmandoc.a - $(CC) -o $@ $(MANDOCDB_OBJS) libmandoc.a -ldb + $(CC) -o $@ $(MANDOCDB_OBJS) libmandoc.a $(DBLIB) llib-lmandocdb.ln: $(MANDOCDB_LNS) $(LINT) $(LINTFLAGS) -Cmandocdb $(MANDOCDB_LNS) @@ -37,6 +37,7 @@ struct man { struct man_node *first; /* the first parsed node */ struct man_meta meta; /* document meta-data */ struct regset *regs; /* registers */ + struct roff *roff; }; #define MACRO_PROT_ARGS struct man *m, \ diff --git a/libmandoc.h b/libmandoc.h index ad16bc65..0e79ca99 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -34,35 +34,6 @@ enum regs { REG__MAX }; -/* - * A register (struct reg) can consist of many types: this consists of - * normalised types from the original string form. For the time being, - * there's only an unsigned integer type. - */ -union regval { - unsigned u; /* unsigned integer */ -}; - -/* - * A single register entity. If "set" is zero, the value of the - * register should be the default one, which is per-register. It's - * assumed that callers know which type in "v" corresponds to which - * register value. - */ -struct reg { - int set; /* whether set or not */ - union regval v; /* parsed data */ -}; - -/* - * The primary interface to setting register values is in libroff, - * although libmdoc and libman from time to time will manipulate - * registers (such as `.Sh SYNOPSIS' enabling REG_nS). - */ -struct regset { - struct reg regs[REG__MAX]; -}; - __BEGIN_DECLS struct roff; @@ -81,7 +52,7 @@ int mandoc_getcontrol(const char *, int *); int mandoc_strntou(const char *, size_t, int); void mdoc_free(struct mdoc *); -struct mdoc *mdoc_alloc(struct regset *, struct mparse *); +struct mdoc *mdoc_alloc(struct roff *, struct mparse *); void mdoc_reset(struct mdoc *); int mdoc_parseln(struct mdoc *, int, char *, int); int mdoc_endparse(struct mdoc *); @@ -89,7 +60,7 @@ int mdoc_addspan(struct mdoc *, const struct tbl_span *); int mdoc_addeqn(struct mdoc *, const struct eqn *); void man_free(struct man *); -struct man *man_alloc(struct regset *, struct mparse *); +struct man *man_alloc(struct roff *, struct mparse *); void man_reset(struct man *); int man_parseln(struct man *, int, char *, int); int man_endparse(struct man *); @@ -97,11 +68,14 @@ int man_addspan(struct man *, const struct tbl_span *); int man_addeqn(struct man *, const struct eqn *); void roff_free(struct roff *); -struct roff *roff_alloc(struct regset *, struct mparse *); +struct roff *roff_alloc(struct mparse *); void roff_reset(struct roff *); enum rofferr roff_parseln(struct roff *, int, char **, size_t *, int, int *); void roff_endparse(struct roff *); +int roff_regisset(const struct roff *, enum regs); +unsigned int roff_regget(const struct roff *, enum regs); +void roff_regunset(struct roff *, enum regs); const struct tbl_span *roff_span(const struct roff *); const struct eqn *roff_eqn(const struct roff *); @@ -40,6 +40,7 @@ struct mdoc { enum mdoc_sec lastnamed; enum mdoc_sec lastsec; struct regset *regs; /* registers */ + struct roff *roff; }; #define MACRO_PROT_ARGS struct mdoc *m, \ @@ -96,7 +96,7 @@ man_free(struct man *man) struct man * -man_alloc(struct regset *regs, struct mparse *parse) +man_alloc(struct roff *roff, struct mparse *parse) { struct man *p; @@ -104,7 +104,7 @@ man_alloc(struct regset *regs, struct mparse *parse) man_hash_init(); p->parse = parse; - p->regs = regs; + p->roff = roff; man_alloc1(p); return(p); @@ -193,14 +193,14 @@ mdoc_free(struct mdoc *mdoc) * Allocate volatile and non-volatile parse resources. */ struct mdoc * -mdoc_alloc(struct regset *regs, struct mparse *parse) +mdoc_alloc(struct roff *roff, struct mparse *parse) { struct mdoc *p; p = mandoc_calloc(1, sizeof(struct mdoc)); p->parse = parse; - p->regs = regs; + p->roff = roff; mdoc_hash_init(); mdoc_alloc1(p); @@ -290,8 +290,8 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs) * whether this mode is on or off. * Note that this mode is also switched by the Sh macro. */ - if (m->regs->regs[(int)REG_nS].set) { - if (m->regs->regs[(int)REG_nS].v.u) + if (roff_regisset(m->roff, REG_nS)) { + if (roff_regget(m->roff, REG_nS)) m->flags |= MDOC_SYNOPSIS; else m->flags &= ~MDOC_SYNOPSIS; diff --git a/mdoc_validate.c b/mdoc_validate.c index 3c8d4aab..c3198c0d 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -899,7 +899,7 @@ pre_sh(PRE_ARGS) if (MDOC_BLOCK != n->type) return(1); - mdoc->regs->regs[(int)REG_nS].set = 0; + roff_regunset(mdoc->roff, REG_nS); return(check_parent(mdoc, n, MDOC_MAX, MDOC_ROOT)); } @@ -59,7 +59,6 @@ struct mparse { struct man *man; /* man parser */ struct mdoc *mdoc; /* mdoc parser */ struct roff *roff; /* roff parser (!NULL) */ - struct regset regs; /* roff registers */ int reparse_count; /* finite interp. stack */ mandocmsg mmsg; /* warning/error message handler */ void *arg; /* argument to mmsg */ @@ -243,13 +242,13 @@ pset(const char *buf, int pos, struct mparse *curp) switch (curp->inttype) { case (MPARSE_MDOC): if (NULL == curp->pmdoc) - curp->pmdoc = mdoc_alloc(&curp->regs, curp); + curp->pmdoc = mdoc_alloc(curp->roff, curp); assert(curp->pmdoc); curp->mdoc = curp->pmdoc; return; case (MPARSE_MAN): if (NULL == curp->pman) - curp->pman = man_alloc(&curp->regs, curp); + curp->pman = man_alloc(curp->roff, curp); assert(curp->pman); curp->man = curp->pman; return; @@ -259,14 +258,14 @@ pset(const char *buf, int pos, struct mparse *curp) if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) { if (NULL == curp->pmdoc) - curp->pmdoc = mdoc_alloc(&curp->regs, curp); + curp->pmdoc = mdoc_alloc(curp->roff, curp); assert(curp->pmdoc); curp->mdoc = curp->pmdoc; return; } if (NULL == curp->pman) - curp->pman = man_alloc(&curp->regs, curp); + curp->pman = man_alloc(curp->roff, curp); assert(curp->pman); curp->man = curp->pman; } @@ -687,7 +686,7 @@ mparse_alloc(enum mparset inttype, enum mandoclevel wlevel, mandocmsg mmsg, void curp->arg = arg; curp->inttype = inttype; - curp->roff = roff_alloc(&curp->regs, curp); + curp->roff = roff_alloc(curp); return(curp); } @@ -695,8 +694,6 @@ void mparse_reset(struct mparse *curp) { - memset(&curp->regs, 0, sizeof(struct regset)); - roff_reset(curp->roff); if (curp->mdoc) @@ -71,6 +71,16 @@ enum roffrule { ROFFRULE_DENY }; +/* + * A single register entity. If "set" is zero, the value of the + * register should be the default one, which is per-register. + * Registers are assumed to be unsigned ints for now. + */ +struct reg { + int set; /* whether set or not */ + unsigned int u; /* unsigned integer */ +}; + struct roffstr { char *name; /* key of symbol */ char *string; /* current value */ @@ -82,7 +92,7 @@ struct roff { struct roffnode *last; /* leaf of stack */ enum roffrule rstack[RSTACK_MAX]; /* stack of !`ie' rules */ int rstackpos; /* position in rstack */ - struct regset *regs; /* read/writable registers */ + struct reg regs[REG__MAX]; struct roffstr *first_string; /* user-defined strings & macros */ const char *current_string; /* value of last called user macro */ struct tbl_node *first_tbl; /* first table parsed */ @@ -351,6 +361,8 @@ roff_reset(struct roff *r) roff_free1(r); + memset(&r->regs, 0, sizeof(struct reg) * REG__MAX); + for (i = 0; i < PREDEFS_MAX; i++) roff_setstr(r, predefs[i].name, predefs[i].str, 0); } @@ -366,13 +378,12 @@ roff_free(struct roff *r) struct roff * -roff_alloc(struct regset *regs, struct mparse *parse) +roff_alloc(struct mparse *parse) { struct roff *r; int i; r = mandoc_calloc(1, sizeof(struct roff)); - r->regs = regs; r->parse = parse; r->rstackpos = -1; @@ -1104,6 +1115,26 @@ roff_ds(ROFF_ARGS) return(ROFF_IGN); } +int +roff_regisset(const struct roff *r, enum regs reg) +{ + + return(r->regs[(int)reg].set); +} + +unsigned int +roff_regget(const struct roff *r, enum regs reg) +{ + + return(r->regs[(int)reg].u); +} + +void +roff_regunset(struct roff *r, enum regs reg) +{ + + r->regs[(int)reg].set = 0; +} /* ARGSUSED */ static enum rofferr @@ -1112,18 +1143,16 @@ roff_nr(ROFF_ARGS) const char *key; char *val; int iv; - struct reg *rg; val = *bufp + pos; key = roff_getname(r, &val, ln, pos); - rg = r->regs->regs; if (0 == strcmp(key, "nS")) { - rg[(int)REG_nS].set = 1; + r->regs[(int)REG_nS].set = 1; if ((iv = mandoc_strntou(val, strlen(val), 10)) >= 0) - rg[REG_nS].v.u = (unsigned)iv; + r->regs[(int)REG_nS].u = (unsigned)iv; else - rg[(int)REG_nS].v.u = 0u; + r->regs[(int)REG_nS].u = 0u; } return(ROFF_IGN); |