diff options
-rw-r--r-- | libman.h | 2 | ||||
-rw-r--r-- | libmdoc.h | 2 | ||||
-rw-r--r-- | man.3 | 6 | ||||
-rw-r--r-- | man.c | 4 | ||||
-rw-r--r-- | man.h | 2 | ||||
-rw-r--r-- | man_html.c | 1 | ||||
-rw-r--r-- | mdoc.3 | 6 | ||||
-rw-r--r-- | mdoc.c | 13 | ||||
-rw-r--r-- | mdoc.h | 3 | ||||
-rw-r--r-- | mdoc_html.c | 10 | ||||
-rw-r--r-- | mdoc_term.c | 12 |
11 files changed, 38 insertions, 23 deletions
@@ -40,7 +40,7 @@ struct man { 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 */ + struct regset *regs; /* registers */ }; #define MACRO_PROT_ARGS struct man *m, \ @@ -43,7 +43,7 @@ struct mdoc { struct mdoc_meta meta; /* document meta-data */ enum mdoc_sec lastnamed; enum mdoc_sec lastsec; - const struct regset *regs; /* readonly registers */ + struct regset *regs; /* registers */ }; #define MACRO_PROT_ARGS struct mdoc *m, \ @@ -34,7 +34,7 @@ .Vt extern const char * const * man_macronames; .Ft "struct man *" .Fo man_alloc -.Fa "const struct regset *regs" +.Fa "struct regset *regs" .Fa "void *data" .Fa "int pflags" .Fa "mandocmsg msgs" @@ -291,14 +291,16 @@ on the finished parse tree with .Fn parsed . This example does not error-check nor free memory upon failure. .Bd -literal -offset indent +struct regset regs; struct man *man; struct man_node *node; char *buf; size_t len; int line; +bzero(®s, sizeof(struct regset)); line = 1; -man = man_alloc(NULL, 0, NULL); +man = man_alloc(®s, NULL, 0, NULL); buf = NULL; alloc_len = 0; @@ -95,8 +95,8 @@ man_free(struct man *man) struct man * -man_alloc(const struct regset *regs, - void *data, int pflags, mandocmsg msg) +man_alloc(struct regset *regs, void *data, + int pflags, mandocmsg msg) { struct man *p; @@ -106,7 +106,7 @@ __BEGIN_DECLS struct man; void man_free(struct man *); -struct man *man_alloc(const struct regset *, void *, int, mandocmsg); +struct man *man_alloc(struct regset *, void *, int, mandocmsg); void man_reset(struct man *); int man_parseln(struct man *, int, char *, int); int man_endparse(struct man *); @@ -252,6 +252,7 @@ a2width(const struct man_node *n, struct roffsu *su) } +/* ARGSUSED */ static int man_root_pre(MAN_ARGS) { @@ -35,7 +35,7 @@ .Vt extern const char * const * mdoc_argnames; .Ft "struct mdoc *" .Fo mdoc_alloc -.Fa "const struct regset *regs" +.Fa "struct regset *regs" .Fa "void *data" .Fa "int pflags" .Fa "mandocmsg msgs" @@ -259,14 +259,16 @@ on the finished parse tree with .Fn parsed . This example does not error-check nor free memory upon failure. .Bd -literal -offset indent +struct regset regs; struct mdoc *mdoc; const struct mdoc_node *node; char *buf; size_t len; int line; +bzero(®s, sizeof(struct regset)); line = 1; -mdoc = mdoc_alloc(NULL, 0, NULL); +mdoc = mdoc_alloc(®s, NULL, 0, NULL); buf = NULL; alloc_len = 0; @@ -192,8 +192,8 @@ mdoc_free(struct mdoc *mdoc) * Allocate volatile and non-volatile parse resources. */ struct mdoc * -mdoc_alloc(const struct regset *regs, - void *data, int pflags, mandocmsg msg) +mdoc_alloc(struct regset *regs, void *data, + int pflags, mandocmsg msg) { struct mdoc *p; @@ -368,9 +368,18 @@ node_alloc(struct mdoc *m, int line, int pos, p->pos = pos; p->tok = tok; p->type = type; + + /* Flag analysis. */ + if (MDOC_NEWLINE & m->flags) p->flags |= MDOC_LINE; m->flags &= ~MDOC_NEWLINE; + + /* Section analysis. */ + + if (SEC_SYNOPSIS == p->sec) + p->flags |= MDOC_SYNPRETTY; + return(p); } @@ -301,6 +301,7 @@ struct mdoc_node { #define MDOC_ACTED (1 << 1) /* has been acted upon */ #define MDOC_EOS (1 << 2) /* at sentence boundary */ #define MDOC_LINE (1 << 3) /* first macro/text on line */ +#define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */ 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. */ @@ -333,7 +334,7 @@ struct mdoc; /* See mdoc.3 for documentation. */ void mdoc_free(struct mdoc *); -struct mdoc *mdoc_alloc(const struct regset *, void *, int, mandocmsg); +struct mdoc *mdoc_alloc(struct regset *, void *, int, mandocmsg); void mdoc_reset(struct mdoc *); int mdoc_parseln(struct mdoc *, int, char *, int); const struct mdoc_node *mdoc_node(const struct mdoc *); diff --git a/mdoc_html.c b/mdoc_html.c index f3bc78e2..cafc664c 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -304,7 +304,7 @@ synopsis_pre(struct html *h, const struct mdoc_node *n) struct roffsu su; struct htmlpair tag; - if (NULL == n->prev || SEC_SYNOPSIS != n->sec) + if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags)) return; SCALE_VS_INIT(&su, 1); @@ -1614,7 +1614,7 @@ mdoc_fn_pre(MDOC_ARGS) */ #if 0 - if (SEC_SYNOPSIS == n->sec) { + if (MDOC_SYNPRETTY & n->flags) { nbuf[0] = '\0'; html_idcat(nbuf, sp, BUFSIZ); PAIR_ID_INIT(&tag[1], nbuf); @@ -1644,7 +1644,7 @@ mdoc_fn_pre(MDOC_ARGS) for (nn = n->child->next; nn; nn = nn->next) { i = 1; - if (SEC_SYNOPSIS == n->sec) + if (MDOC_SYNPRETTY & n->flags) i = 2; t = print_otag(h, TAG_SPAN, i, tag); print_text(h, nn->string); @@ -1654,7 +1654,7 @@ mdoc_fn_pre(MDOC_ARGS) } print_text(h, ")"); - if (SEC_SYNOPSIS == n->sec) + if (MDOC_SYNPRETTY & n->flags) print_text(h, ";"); return(0); @@ -1824,7 +1824,7 @@ mdoc_in_pre(MDOC_ARGS) PAIR_CLASS_INIT(&tag[0], "includes"); print_otag(h, TAG_SPAN, 1, tag); - if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) + if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) print_text(h, "#include"); print_text(h, "<"); diff --git a/mdoc_term.c b/mdoc_term.c index 7cc7388c..3352bf77 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1278,7 +1278,7 @@ synopsis_pre(struct termp *p, const struct mdoc_node *n) * Obviously, if we're not in a SYNOPSIS or no prior macros * exist, do nothing. */ - if (NULL == n->prev || SEC_SYNOPSIS != n->sec) + if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags)) return; /* @@ -1543,7 +1543,7 @@ termp_fn_pre(DECL_ARGS) term_word(p, ")"); - if (SEC_SYNOPSIS == n->sec) + if (MDOC_SYNPRETTY & n->flags) term_word(p, ";"); return(0); @@ -1820,7 +1820,7 @@ termp_in_pre(DECL_ARGS) synopsis_pre(p, n); - if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) { + if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) { term_fontpush(p, TERMFONT_BOLD); term_word(p, "#include"); term_word(p, "<"); @@ -1839,13 +1839,13 @@ static void termp_in_post(DECL_ARGS) { - if (SEC_SYNOPSIS == n->sec) + if (MDOC_SYNPRETTY & n->flags) term_fontpush(p, TERMFONT_BOLD); p->flags |= TERMP_NOSPACE; term_word(p, ">"); - if (SEC_SYNOPSIS == n->sec) + if (MDOC_SYNPRETTY & n->flags) term_fontpop(p); } @@ -1987,7 +1987,7 @@ termp_fo_post(DECL_ARGS) p->flags |= TERMP_NOSPACE; term_word(p, ")"); - if (SEC_SYNOPSIS == n->sec) { + if (MDOC_SYNPRETTY & n->flags) { p->flags |= TERMP_NOSPACE; term_word(p, ";"); } |