From dc649a73f967c1a61e60d2495f16d56db82eac57 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sun, 27 Jun 2010 15:52:41 +0000 Subject: Downstream maintainers: this removes UGLY! I don't want diverging functionality and UGLY works quite well thanks to schwarze@'s careful attention. This also backs out function-prototype changes for struct regset, instead stuffing a pointer to the regset directly into struct mdoc/man/roff. --- Makefile | 4 ---- libman.h | 16 ++++++++-------- libmdoc.h | 16 ++++++++-------- main.c | 19 ++++++++++--------- man.3 | 12 ++++++++---- man.c | 20 +++++++++----------- man.h | 8 +++----- man_html.c | 3 +-- mdoc.3 | 12 ++++++++---- mdoc.c | 44 ++++++++++++++++++-------------------------- mdoc.h | 11 ++++------- mdoc_action.c | 7 ++++++- mdoc_macro.c | 41 ++++++++++++++++------------------------- roff.3 | 10 +++++++--- roff.c | 37 +++++++++++++++++++------------------ roff.h | 8 ++++---- 16 files changed, 129 insertions(+), 139 deletions(-) diff --git a/Makefile b/Makefile index 9a85b103..b74e1581 100644 --- a/Makefile +++ b/Makefile @@ -23,10 +23,6 @@ CFLAGS += -g $(WFLAGS) $(VFLAGS) -DHAVE_CONFIG_H # in the lower-left hand corner of -mdoc manuals. # CFLAGS += -DOSNAME="\"OpenBSD 4.5\"" -# Unset this if you don't want Xo/Xc allowing split `It' lines, which -# breaks symmetry. -CFLAGS += -DUGLY - LINTFLAGS += $(VFLAGS) MANDOCFLAGS = -Wall -fstrict diff --git a/libman.h b/libman.h index 2bc50027..4cc0befc 100644 --- a/libman.h +++ b/libman.h @@ -1,4 +1,4 @@ -/* $Id: libman.h,v 1.38 2010/06/26 16:07:08 kristaps Exp $ */ +/* $Id: libman.h,v 1.39 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -26,8 +26,8 @@ enum man_next { }; struct man { - void *data; - mandocmsg msg; + void *data; /* private application data */ + mandocmsg msg; /* output message handler */ int pflags; /* parse flags (see man.h) */ int flags; /* parse flags */ #define MAN_HALT (1 << 0) /* badness happened: die */ @@ -36,14 +36,14 @@ struct man { #define MAN_ILINE (1 << 3) /* Ignored in next-line scope. */ #define MAN_LITERAL (1 << 4) /* Literal input. */ #define MAN_BPLINE (1 << 5) - enum man_next next; - struct man_node *last; - struct man_node *first; - struct man_meta meta; + enum man_next next; /* where to put the next node */ + struct man_node *last; /* the last parsed node */ + struct man_node *first; /* the first parsed node */ + struct man_meta meta; /* document meta-data */ + const struct regset *regs; /* readonly registers */ }; #define MACRO_PROT_ARGS struct man *m, \ - const struct regset *regs, \ enum mant tok, \ int line, \ int ppos, \ diff --git a/libmdoc.h b/libmdoc.h index 83a300e1..16d577ce 100644 --- a/libmdoc.h +++ b/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.55 2010/06/26 16:07:08 kristaps Exp $ */ +/* $Id: libmdoc.h,v 1.56 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -26,8 +26,8 @@ enum mdoc_next { }; struct mdoc { - void *data; - mandocmsg msg; + void *data; /* private application data */ + mandocmsg msg; /* message callback */ int flags; #define MDOC_HALT (1 << 0) /* error in parse: halt */ #define MDOC_LITERAL (1 << 1) /* in a literal scope */ @@ -37,16 +37,16 @@ struct mdoc { #define MDOC_PPHRASE (1 << 5) /* within a partial phrase */ #define MDOC_FREECOL (1 << 6) /* `It' invocation should close */ int pflags; - enum mdoc_next next; - struct mdoc_node *last; - struct mdoc_node *first; - struct mdoc_meta meta; + enum mdoc_next next; /* where to put the next node */ + struct mdoc_node *last; /* the last node parsed */ + struct mdoc_node *first; /* the first node parsed */ + struct mdoc_meta meta; /* document meta-data */ enum mdoc_sec lastnamed; enum mdoc_sec lastsec; + const struct regset *regs; /* readonly registers */ }; #define MACRO_PROT_ARGS struct mdoc *m, \ - const struct regset *regs, \ enum mdoct tok, \ int line, \ int ppos, \ diff --git a/main.c b/main.c index 11b7a900..469dc2ef 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.91 2010/06/26 15:36:37 kristaps Exp $ */ +/* $Id: main.c,v 1.92 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -88,6 +88,7 @@ struct curparse { struct man *man; /* man parser */ struct mdoc *mdoc; /* mdoc parser */ struct roff *roff; /* roff parser (!NULL) */ + struct regset regs; /* roff registers */ enum outt outtype; /* which output to use */ out_mdoc outmdoc; /* mdoc output ptr */ out_man outman; /* man output ptr */ @@ -298,7 +299,7 @@ man_init(struct curparse *curp) if (curp->fflags & FL_NIGN_ESCAPE) pflags &= ~MAN_IGN_ESCAPE; - return(man_alloc(curp, pflags, mmsg)); + return(man_alloc(&curp->regs, curp, pflags, mmsg)); } @@ -306,7 +307,7 @@ static struct roff * roff_init(struct curparse *curp) { - return(roff_alloc(mmsg, curp)); + return(roff_alloc(&curp->regs, mmsg, curp)); } @@ -326,7 +327,7 @@ mdoc_init(struct curparse *curp) if (curp->fflags & FL_NIGN_MACRO) pflags &= ~MDOC_IGN_MACRO; - return(mdoc_alloc(curp, pflags, mmsg)); + return(mdoc_alloc(&curp->regs, curp, pflags, mmsg)); } @@ -451,13 +452,12 @@ fdesc(struct curparse *curp) struct man *man; struct mdoc *mdoc; struct roff *roff; - struct regset regs; man = NULL; mdoc = NULL; roff = NULL; + memset(&ln, 0, sizeof(struct buf)); - memset(®s, 0, sizeof(struct regset)); /* * Two buffers: ln and buf. buf is the input file and may be @@ -540,7 +540,7 @@ fdesc(struct curparse *curp) of = 0; do { - re = roff_parseln(roff, ®s, lnn_start, + re = roff_parseln(roff, lnn_start, &ln.buf, &ln.sz, of, &of); } while (ROFF_RERUN == re); @@ -562,9 +562,9 @@ fdesc(struct curparse *curp) /* Lastly, push down into the parsers themselves. */ - if (man && ! man_parseln(man, ®s, lnn_start, ln.buf, of)) + if (man && ! man_parseln(man, lnn_start, ln.buf, of)) goto bailout; - if (mdoc && ! mdoc_parseln(mdoc, ®s, lnn_start, ln.buf, of)) + if (mdoc && ! mdoc_parseln(mdoc, lnn_start, ln.buf, of)) goto bailout; } @@ -637,6 +637,7 @@ fdesc(struct curparse *curp) (*curp->outmdoc)(curp->outdata, mdoc); cleanup: + memset(&curp->regs, 0, sizeof(struct regset)); if (mdoc) mdoc_reset(mdoc); if (man) diff --git a/man.3 b/man.3 index 3191a11e..4f461290 100644 --- a/man.3 +++ b/man.3 @@ -1,4 +1,4 @@ -.\" $Id: man.3,v 1.19 2010/06/26 15:36:37 kristaps Exp $ +.\" $Id: man.3,v 1.20 2010/06/27 15:52:41 kristaps Exp $ .\" .\" Copyright (c) 2009-2010 Kristaps Dzonsons .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 26 2010 $ +.Dd $Mdocdate: June 27 2010 $ .Dt MAN 3 .Os .Sh NAME @@ -33,7 +33,12 @@ .In man.h .Vt extern const char * const * man_macronames; .Ft "struct man *" -.Fn man_alloc "void *data" "int pflags" "mandocmsg msgs" +.Fo man_alloc +.Fa "const struct regset *regs" +.Fa "void *data" +.Fa "int pflags" +.Fa "mandocmsg msgs" +.Fc .Ft int .Fn man_endparse "struct man *man" .Ft void @@ -45,7 +50,6 @@ .Ft int .Fo man_parseln .Fa "struct man *man" -.Fa "const struct regset *regs" .Fa "int line" .Fa "char *buf" .Fc diff --git a/man.c b/man.c index 3c1dbdad..0bdff790 100644 --- a/man.c +++ b/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.78 2010/06/26 16:07:08 kristaps Exp $ */ +/* $Id: man.c,v 1.79 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -54,9 +54,7 @@ static void man_node_free(struct man_node *); static void man_node_unlink(struct man *, struct man_node *); static int man_ptext(struct man *, int, char *, int); -static int man_pmacro(struct man *, - const struct regset *regs, - int, char *, int); +static int man_pmacro(struct man *, int, char *, int); static void man_free1(struct man *); static void man_alloc1(struct man *); static int macrowarn(struct man *, int, const char *, int); @@ -97,7 +95,8 @@ man_free(struct man *man) struct man * -man_alloc(void *data, int pflags, mandocmsg msg) +man_alloc(const struct regset *regs, + void *data, int pflags, mandocmsg msg) { struct man *p; @@ -107,6 +106,7 @@ man_alloc(void *data, int pflags, mandocmsg msg) p->data = data; p->pflags = pflags; p->msg = msg; + p->regs = regs; man_alloc1(p); return(p); @@ -127,15 +127,14 @@ man_endparse(struct man *m) int -man_parseln(struct man *m, const struct regset *regs, - int ln, char *buf, int offs) +man_parseln(struct man *m, int ln, char *buf, int offs) { if (MAN_HALT & m->flags) return(0); return(('.' == buf[offs] || '\'' == buf[offs]) ? - man_pmacro(m, regs, ln, buf, offs) : + man_pmacro(m, ln, buf, offs) : man_ptext(m, ln, buf, offs)); } @@ -451,8 +450,7 @@ macrowarn(struct man *m, int ln, const char *buf, int offs) int -man_pmacro(struct man *m, const struct regset *regs, - int ln, char *buf, int offs) +man_pmacro(struct man *m, int ln, char *buf, int offs) { int i, j, ppos; enum mant tok; @@ -577,7 +575,7 @@ man_pmacro(struct man *m, const struct regset *regs, /* Call to handler... */ assert(man_macros[tok].fp); - if ( ! (*man_macros[tok].fp)(m, regs, tok, ln, ppos, &i, buf)) + if ( ! (*man_macros[tok].fp)(m, tok, ln, ppos, &i, buf)) goto err; out: diff --git a/man.h b/man.h index ddeb0184..f8c8d786 100644 --- a/man.h +++ b/man.h @@ -1,4 +1,4 @@ -/* $Id: man.h,v 1.38 2010/06/26 15:36:37 kristaps Exp $ */ +/* $Id: man.h,v 1.39 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -106,11 +106,9 @@ __BEGIN_DECLS struct man; void man_free(struct man *); -struct man *man_alloc(void *, int, mandocmsg); +struct man *man_alloc(const struct regset *, void *, int, mandocmsg); void man_reset(struct man *); -int man_parseln(struct man *, - const struct regset *, - int, char *, int); +int man_parseln(struct man *, int, char *, int); int man_endparse(struct man *); const struct man_node *man_node(const struct man *); diff --git a/man_html.c b/man_html.c index ed6e6c7f..1534e12c 100644 --- a/man_html.c +++ b/man_html.c @@ -1,4 +1,4 @@ -/* $Id: man_html.c,v 1.38 2010/06/26 15:36:37 kristaps Exp $ */ +/* $Id: man_html.c,v 1.39 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -252,7 +252,6 @@ a2width(const struct man_node *n, struct roffsu *su) } -/* ARGSUSED */ static int man_root_pre(MAN_ARGS) { diff --git a/mdoc.3 b/mdoc.3 index 49acb46e..17d41fef 100644 --- a/mdoc.3 +++ b/mdoc.3 @@ -1,4 +1,4 @@ -.\" $Id: mdoc.3,v 1.42 2010/06/26 15:36:37 kristaps Exp $ +.\" $Id: mdoc.3,v 1.43 2010/06/27 15:52:41 kristaps Exp $ .\" .\" Copyright (c) 2009-2010 Kristaps Dzonsons .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 26 2010 $ +.Dd $Mdocdate: June 27 2010 $ .Dt MDOC 3 .Os .Sh NAME @@ -34,7 +34,12 @@ .Vt extern const char * const * mdoc_macronames; .Vt extern const char * const * mdoc_argnames; .Ft "struct mdoc *" -.Fn mdoc_alloc "void *data" "int pflags" "mandocmsg msgs" +.Fo mdoc_alloc +.Fa "const struct regset *regs" +.Fa "void *data" +.Fa "int pflags" +.Fa "mandocmsg msgs" +.Fc .Ft int .Fn mdoc_endparse "struct mdoc *mdoc" .Ft void @@ -46,7 +51,6 @@ .Ft int .Fo mdoc_parseln .Fa "struct mdoc *mdoc" -.Fa "const struct regset *regs" .Fa "int line" .Fa "char *buf" .Fc diff --git a/mdoc.c b/mdoc.c index 3afa42c0..4848b045 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.148 2010/06/26 16:07:08 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.149 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -97,12 +97,8 @@ static struct mdoc_node *node_alloc(struct mdoc *, int, int, enum mdoct, enum mdoc_type); static int node_append(struct mdoc *, struct mdoc_node *); -static int mdoc_ptext(struct mdoc *, - const struct regset *, - int, char *, int); -static int mdoc_pmacro(struct mdoc *, - const struct regset *, - int, char *, int); +static int mdoc_ptext(struct mdoc *, int, char *, int); +static int mdoc_pmacro(struct mdoc *, int, char *, int); static int macrowarn(struct mdoc *, int, const char *, int); @@ -196,7 +192,8 @@ mdoc_free(struct mdoc *mdoc) * Allocate volatile and non-volatile parse resources. */ struct mdoc * -mdoc_alloc(void *data, int pflags, mandocmsg msg) +mdoc_alloc(const struct regset *regs, + void *data, int pflags, mandocmsg msg) { struct mdoc *p; @@ -205,6 +202,7 @@ mdoc_alloc(void *data, int pflags, mandocmsg msg) p->msg = msg; p->data = data; p->pflags = pflags; + p->regs = regs; mdoc_hash_init(); mdoc_alloc1(p); @@ -234,8 +232,7 @@ mdoc_endparse(struct mdoc *m) * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()). */ int -mdoc_parseln(struct mdoc *m, const struct regset *regs, - int ln, char *buf, int offs) +mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs) { if (MDOC_HALT & m->flags) @@ -243,8 +240,8 @@ mdoc_parseln(struct mdoc *m, const struct regset *regs, m->flags |= MDOC_NEWLINE; return(('.' == buf[offs] || '\'' == buf[offs]) ? - mdoc_pmacro(m, regs, ln, buf, offs) : - mdoc_ptext(m, regs, ln, buf, offs)); + mdoc_pmacro(m, ln, buf, offs) : + mdoc_ptext(m, ln, buf, offs)); } @@ -291,8 +288,7 @@ mdoc_macro(MACRO_PROT_ARGS) m->flags |= MDOC_PBODY; } - return((*mdoc_macros[tok].fp) - (m, regs, tok, line, ppos, pos, buf)); + return((*mdoc_macros[tok].fp)(m, tok, line, ppos, pos, buf)); } @@ -546,8 +542,7 @@ mdoc_node_delete(struct mdoc *m, struct mdoc_node *p) * control character. */ static int -mdoc_ptext(struct mdoc *m, const struct regset *regs, - int line, char *buf, int offs) +mdoc_ptext(struct mdoc *m, int line, char *buf, int offs) { char *c, *ws, *end; struct mdoc_node *n; @@ -578,8 +573,7 @@ mdoc_ptext(struct mdoc *m, const struct regset *regs, LIST_column == n->data.Bl.type) { /* `Bl' is open without any children. */ m->flags |= MDOC_FREECOL; - return(mdoc_macro(m, regs, MDOC_It, - line, offs, &offs, buf)); + return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf)); } if (MDOC_It == n->tok && MDOC_BLOCK == n->type && @@ -588,8 +582,7 @@ mdoc_ptext(struct mdoc *m, const struct regset *regs, LIST_column == n->parent->data.Bl.type) { /* `Bl' has block-level `It' children. */ m->flags |= MDOC_FREECOL; - return(mdoc_macro(m, regs, MDOC_It, - line, offs, &offs, buf)); + return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf)); } /* @@ -699,8 +692,7 @@ macrowarn(struct mdoc *m, int ln, const char *buf, int offs) * character. */ int -mdoc_pmacro(struct mdoc *m, const struct regset *regs, - int ln, char *buf, int offs) +mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs) { enum mdoct tok; int i, j, sv; @@ -779,7 +771,7 @@ mdoc_pmacro(struct mdoc *m, const struct regset *regs, */ if (NULL == m->last || MDOC_It == tok || MDOC_El == tok) { - if ( ! mdoc_macro(m, regs, tok, ln, sv, &i, buf)) + if ( ! mdoc_macro(m, tok, ln, sv, &i, buf)) goto err; return(1); } @@ -795,7 +787,7 @@ mdoc_pmacro(struct mdoc *m, const struct regset *regs, if (MDOC_Bl == n->tok && MDOC_BODY == n->type && LIST_column == n->data.Bl.type) { m->flags |= MDOC_FREECOL; - if ( ! mdoc_macro(m, regs, MDOC_It, ln, sv, &sv, buf)) + if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf)) goto err; return(1); } @@ -811,14 +803,14 @@ mdoc_pmacro(struct mdoc *m, const struct regset *regs, MDOC_Bl == n->parent->tok && LIST_column == n->parent->data.Bl.type) { m->flags |= MDOC_FREECOL; - if ( ! mdoc_macro(m, regs, MDOC_It, ln, sv, &sv, buf)) + if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf)) goto err; return(1); } /* Normal processing of a macro. */ - if ( ! mdoc_macro(m, regs, tok, ln, sv, &i, buf)) + if ( ! mdoc_macro(m, tok, ln, sv, &i, buf)) goto err; return(1); diff --git a/mdoc.h b/mdoc.h index dc4be587..19e52e23 100644 --- a/mdoc.h +++ b/mdoc.h @@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.92 2010/06/26 15:36:37 kristaps Exp $ */ +/* $Id: mdoc.h,v 1.93 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -303,10 +303,9 @@ struct mdoc_node { #define MDOC_LINE (1 << 3) /* first macro/text on line */ enum mdoc_type type; /* AST node type */ enum mdoc_sec sec; /* current named section */ + /* FIXME: these can be union'd to shave a few bytes. */ struct mdoc_arg *args; /* BLOCK/ELEM */ -#ifdef UGLY struct mdoc_node *pending; /* BLOCK */ -#endif struct mdoc_node *head; /* BLOCK */ struct mdoc_node *body; /* BLOCK */ struct mdoc_node *tail; /* BLOCK */ @@ -334,11 +333,9 @@ struct mdoc; /* See mdoc.3 for documentation. */ void mdoc_free(struct mdoc *); -struct mdoc *mdoc_alloc(void *, int, mandocmsg); +struct mdoc *mdoc_alloc(const struct regset *, void *, int, mandocmsg); void mdoc_reset(struct mdoc *); -int mdoc_parseln(struct mdoc *, - const struct regset *, - int, char *, int); +int mdoc_parseln(struct mdoc *, int, char *, int); const struct mdoc_node *mdoc_node(const struct mdoc *); const struct mdoc_meta *mdoc_meta(const struct mdoc *); int mdoc_endparse(struct mdoc *); diff --git a/mdoc_action.c b/mdoc_action.c index 3cc87e41..d01d665b 100644 --- a/mdoc_action.c +++ b/mdoc_action.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_action.c,v 1.71 2010/06/19 20:46:28 kristaps Exp $ */ +/* $Id: mdoc_action.c,v 1.72 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -32,6 +32,11 @@ #include "libmdoc.h" #include "libmandoc.h" +/* + * FIXME: this file is deprecated. All future "actions" should be + * pushed into mdoc_validate.c. + */ + #define POST_ARGS struct mdoc *m, struct mdoc_node *n #define PRE_ARGS struct mdoc *m, struct mdoc_node *n diff --git a/mdoc_macro.c b/mdoc_macro.c index e274dfc7..51c852a0 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.81 2010/06/26 16:07:08 kristaps Exp $ */ +/* $Id: mdoc_macro.c,v 1.82 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -50,9 +50,7 @@ static int append_delims(struct mdoc *, int, int *, char *); static enum mdoct lookup(enum mdoct, const char *); static enum mdoct lookup_raw(const char *); -static int phrase(struct mdoc *, - const struct regset *, - int, int, char *); +static int phrase(struct mdoc *, int, int, char *); static enum mdoct rew_alt(enum mdoct); static int rew_dobreak(enum mdoct, const struct mdoc_node *); @@ -609,7 +607,6 @@ rew_sub(enum mdoc_type t, struct mdoc *m, if ( ! rew_last(m, n)) return(0); -#ifdef UGLY /* * The current block extends an enclosing block beyond a line * break. Now that the current block ends, close the enclosing @@ -622,7 +619,6 @@ rew_sub(enum mdoc_type t, struct mdoc *m, if ( ! mdoc_body_alloc(m, n->line, n->pos, n->tok)) return(0); } -#endif return(1); } @@ -741,7 +737,7 @@ blk_exp_close(MACRO_PROT_ARGS) return(0); flushed = 1; } - if ( ! mdoc_macro(m, regs, ntok, line, lastarg, pos, buf)) + if ( ! mdoc_macro(m, ntok, line, lastarg, pos, buf)) return(0); break; } @@ -842,7 +838,7 @@ in_line(MACRO_PROT_ARGS) if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_MACROEMPTY)) return(0); } - if ( ! mdoc_macro(m, regs, ntok, line, la, pos, buf)) + if ( ! mdoc_macro(m, ntok, line, la, pos, buf)) return(0); if ( ! nl) return(1); @@ -938,9 +934,7 @@ blk_full(MACRO_PROT_ARGS) struct mdoc_arg *arg; struct mdoc_node *head; /* save of head macro */ struct mdoc_node *body; /* save of body macro */ -#ifdef UGLY struct mdoc_node *n; -#endif enum mdoc_type mtt; enum mdoct ntok; enum margserr ac, lac; @@ -1088,7 +1082,7 @@ blk_full(MACRO_PROT_ARGS) if (ARGS_PEND == ac && ARGS_PPHRASE == lac) m->flags |= MDOC_PPHRASE; - if ( ! phrase(m, regs, line, la, buf)) + if ( ! phrase(m, line, la, buf)) return(0); m->flags &= ~MDOC_PPHRASE; @@ -1103,7 +1097,7 @@ blk_full(MACRO_PROT_ARGS) continue; } - if ( ! mdoc_macro(m, regs, ntok, line, la, pos, buf)) + if ( ! mdoc_macro(m, ntok, line, la, pos, buf)) return(0); break; } @@ -1122,7 +1116,6 @@ blk_full(MACRO_PROT_ARGS) if (NULL != body) goto out; -#ifdef UGLY /* * If there is an open (i.e., unvalidated) sub-block requiring * explicit close-out, postpone switching the current block from @@ -1138,7 +1131,6 @@ blk_full(MACRO_PROT_ARGS) return(1); } } -#endif /* Close out scopes to remain in a consistent state. */ @@ -1231,7 +1223,7 @@ blk_part_imp(MACRO_PROT_ARGS) continue; } - if ( ! mdoc_macro(m, regs, ntok, line, la, pos, buf)) + if ( ! mdoc_macro(m, ntok, line, la, pos, buf)) return(0); break; } @@ -1376,7 +1368,7 @@ blk_part_exp(MACRO_PROT_ARGS) continue; } - if ( ! mdoc_macro(m, regs, ntok, line, la, pos, buf)) + if ( ! mdoc_macro(m, ntok, line, la, pos, buf)) return(0); break; } @@ -1495,7 +1487,7 @@ in_line_argn(MACRO_PROT_ARGS) if ( ! flushed && ! rew_elem(m, tok)) return(0); flushed = 1; - if ( ! mdoc_macro(m, regs, ntok, line, la, pos, buf)) + if ( ! mdoc_macro(m, ntok, line, la, pos, buf)) return(0); j++; break; @@ -1601,7 +1593,7 @@ in_line_eoln(MACRO_PROT_ARGS) if ( ! rew_elem(m, tok)) return(0); - return(mdoc_macro(m, regs, ntok, line, la, pos, buf)); + return(mdoc_macro(m, ntok, line, la, pos, buf)); } /* Close out (no delimiters). */ @@ -1620,11 +1612,11 @@ ctx_synopsis(MACRO_PROT_ARGS) /* If we're not in the SYNOPSIS, go straight to in-line. */ if (SEC_SYNOPSIS != m->lastsec) - return(in_line(m, regs, tok, line, ppos, pos, buf)); + return(in_line(m, tok, line, ppos, pos, buf)); /* If we're a nested call, same place. */ if ( ! nl) - return(in_line(m, regs, tok, line, ppos, pos, buf)); + return(in_line(m, tok, line, ppos, pos, buf)); /* * XXX: this will open a block scope; however, if later we end @@ -1632,7 +1624,7 @@ ctx_synopsis(MACRO_PROT_ARGS) * the formatting. Be careful. */ - return(blk_part_imp(m, regs, tok, line, ppos, pos, buf)); + return(blk_part_imp(m, tok, line, ppos, pos, buf)); } @@ -1651,8 +1643,7 @@ obsolete(MACRO_PROT_ARGS) * macro is encountered. */ static int -phrase(struct mdoc *m, const struct regset *regs, - int line, int ppos, char *buf) +phrase(struct mdoc *m, int line, int ppos, char *buf) { int la, pos; enum margserr ac; @@ -1677,7 +1668,7 @@ phrase(struct mdoc *m, const struct regset *regs, continue; } - if ( ! mdoc_macro(m, regs, ntok, line, la, &pos, buf)) + if ( ! mdoc_macro(m, ntok, line, la, &pos, buf)) return(0); return(append_delims(m, line, &pos, buf)); } @@ -1722,7 +1713,7 @@ phrase_ta(MACRO_PROT_ARGS) continue; } - if ( ! mdoc_macro(m, regs, ntok, line, la, pos, buf)) + if ( ! mdoc_macro(m, ntok, line, la, pos, buf)) return(0); return(append_delims(m, line, pos, buf)); } diff --git a/roff.3 b/roff.3 index 961daff5..1aff639a 100644 --- a/roff.3 +++ b/roff.3 @@ -1,4 +1,4 @@ -.\" $Id: roff.3,v 1.2 2010/06/26 15:22:19 kristaps Exp $ +.\" $Id: roff.3,v 1.3 2010/06/27 15:52:41 kristaps Exp $ .\" .\" Copyright (c) 2010 Kristaps Dzonsons .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 26 2010 $ +.Dd $Mdocdate: June 27 2010 $ .Dt ROFF 3 .Os .Sh NAME @@ -30,7 +30,11 @@ .In regs.h .In roff.h .Ft "struct roff *" -.Fn roff_alloc "mandocmsg msgs" "void *data" +.Fo roff_alloc +.Fa "struct regset *regs" +.Fa "mandocmsg msgs" +.Fa "void *data" +.Fc .Ft int .Fn roff_endparse "struct roff *roff" .Ft void diff --git a/roff.c b/roff.c index 513de8e0..4bb34f68 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.89 2010/06/26 15:22:19 kristaps Exp $ */ +/* $Id: roff.c,v 1.90 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons * @@ -74,6 +74,7 @@ struct roff { void *data; /* privdata for messages */ enum roffrule rstack[RSTACK_MAX]; /* stack of !`ie' rules */ int rstackpos; /* position in rstack */ + struct regset *regs; /* read/writable registers */ }; struct roffnode { @@ -87,7 +88,6 @@ struct roffnode { }; #define ROFF_ARGS struct roff *r, /* parse ctx */ \ - struct regset *regs, /* registers */ \ enum rofft tok, /* tok of macro */ \ char **bufp, /* input buffer */ \ size_t *szp, /* size of input buffer */ \ @@ -289,7 +289,7 @@ roff_free(struct roff *r) struct roff * -roff_alloc(const mandocmsg msg, void *data) +roff_alloc(struct regset *regs, const mandocmsg msg, void *data) { struct roff *r; @@ -298,6 +298,7 @@ roff_alloc(const mandocmsg msg, void *data) return(0); } + r->regs = regs; r->msg = msg; r->data = data; r->rstackpos = -1; @@ -308,8 +309,8 @@ roff_alloc(const mandocmsg msg, void *data) enum rofferr -roff_parseln(struct roff *r, struct regset *regs, int ln, - char **bufp, size_t *szp, int pos, int *offs) +roff_parseln(struct roff *r, int ln, char **bufp, + size_t *szp, int pos, int *offs) { enum rofft t; int ppos; @@ -326,8 +327,8 @@ roff_parseln(struct roff *r, struct regset *regs, int ln, ROFF_DEBUG("roff: intercept scoped text: %s, [%s]\n", roffs[t].name, &(*bufp)[pos]); return((*roffs[t].text) - (r, regs, t, bufp, - szp, ln, pos, pos, offs)); + (r, t, bufp, szp, + ln, pos, pos, offs)); } else if ( ! ROFF_CTL((*bufp)[pos])) { ROFF_DEBUG("roff: pass non-scoped text: [%s]\n", &(*bufp)[pos]); @@ -345,8 +346,8 @@ roff_parseln(struct roff *r, struct regset *regs, int ln, ROFF_DEBUG("roff: intercept scoped context: %s\n", roffs[t].name); return((*roffs[t].sub) - (r, regs, t, bufp, - szp, ln, pos, pos, offs)); + (r, t, bufp, szp, + ln, pos, pos, offs)); } /* @@ -366,8 +367,8 @@ roff_parseln(struct roff *r, struct regset *regs, int ln, roffs[t].name, &(*bufp)[pos]); assert(roffs[t].proc); return((*roffs[t].proc) - (r, regs, t, bufp, - szp, ln, ppos, pos, offs)); + (r, t, bufp, szp, + ln, ppos, pos, offs)); } @@ -653,8 +654,8 @@ roff_block_sub(ROFF_ARGS) return(ROFF_IGN); assert(roffs[t].proc); - return((*roffs[t].proc)(r, regs, t, bufp, - szp, ln, ppos, pos, offs)); + return((*roffs[t].proc)(r, t, bufp, szp, + ln, ppos, pos, offs)); } @@ -703,8 +704,8 @@ roff_cond_sub(ROFF_ARGS) return(ROFF_IGN); assert(roffs[t].proc); - return((*roffs[t].proc) - (r, regs, t, bufp, szp, ln, ppos, pos, offs)); + return((*roffs[t].proc)(r, t, bufp, szp, + ln, ppos, pos, offs)); } @@ -904,11 +905,11 @@ roff_nr(ROFF_ARGS) /* Process register token. */ if (0 == strcmp(key, "nS")) { - if ( ! roff_parse_nat(val, ®s->regs[(int)REG_nS].i)) - regs->regs[(int)REG_nS].i = 0; + if ( ! roff_parse_nat(val, &r->regs->regs[(int)REG_nS].i)) + r->regs->regs[(int)REG_nS].i = 0; ROFF_DEBUG("roff: register nS: %d\n", - regs->regs[(int)REG_nS].i); + r->regs->regs[(int)REG_nS].i); } else ROFF_DEBUG("roff: ignoring register: %s\n", key); diff --git a/roff.h b/roff.h index c8c4babc..e181570c 100644 --- a/roff.h +++ b/roff.h @@ -1,4 +1,4 @@ -/* $Id: roff.h,v 1.16 2010/06/26 15:22:19 kristaps Exp $ */ +/* $Id: roff.h,v 1.17 2010/06/27 15:52:41 kristaps Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons * @@ -29,10 +29,10 @@ __BEGIN_DECLS struct roff; void roff_free(struct roff *); -struct roff *roff_alloc(mandocmsg, void *); +struct roff *roff_alloc(struct regset *, mandocmsg, void *); void roff_reset(struct roff *); -enum rofferr roff_parseln(struct roff *, struct regset *, - int, char **, size_t *, int, int *); +enum rofferr roff_parseln(struct roff *, int, + char **, size_t *, int, int *); int roff_endparse(struct roff *); __END_DECLS -- cgit v1.2.3-56-ge451