diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-04-02 22:06:18 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-04-02 22:06:18 +0000 |
commit | f68738e465e4d800ca41fee5600460ce8b80b01d (patch) | |
tree | 57b05ac5d994f7bafb61503553b0dad41b4e9c91 /usr.bin | |
parent | 3b3e2458469c3b7a54a16224bfa57e6e0c0d6b73 (diff) |
Second step towards parser unification:
Replace struct mdoc_node and struct man_node by a unified struct roff_node.
To be able to use the tok member for both mdoc(7) and man(7) without
defining all the macros in roff.h, sacrifice a tiny bit of type safety
and make tok an int rather than an enum.
Almost mechanical, no functional change.
Written on the Eurostar from Bruxelles to London on the way to p2k15.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/libman.h | 26 | ||||
-rw-r--r-- | usr.bin/mandoc/libmdoc.h | 48 | ||||
-rw-r--r-- | usr.bin/mandoc/man.c | 69 | ||||
-rw-r--r-- | usr.bin/mandoc/man.h | 117 | ||||
-rw-r--r-- | usr.bin/mandoc/man_hash.c | 8 | ||||
-rw-r--r-- | usr.bin/mandoc/man_html.c | 18 | ||||
-rw-r--r-- | usr.bin/mandoc/man_macro.c | 35 | ||||
-rw-r--r-- | usr.bin/mandoc/man_term.c | 18 | ||||
-rw-r--r-- | usr.bin/mandoc/man_validate.c | 10 | ||||
-rw-r--r-- | usr.bin/mandoc/mandocdb.c | 58 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 84 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.h | 340 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_argv.c | 8 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_hash.c | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_html.c | 14 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_macro.c | 78 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_man.c | 22 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_term.c | 28 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 112 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.h | 79 | ||||
-rw-r--r-- | usr.bin/mandoc/tree.c | 10 |
21 files changed, 577 insertions, 611 deletions
diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h index 392c8d1e4f0..25eb39d13dc 100644 --- a/usr.bin/mandoc/libman.h +++ b/usr.bin/mandoc/libman.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libman.h,v 1.43 2015/03/20 12:53:43 schwarze Exp $ */ +/* $OpenBSD: libman.h,v 1.44 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -7,9 +7,9 @@ * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF @@ -31,14 +31,14 @@ struct man { #define MAN_LITERAL (1 << 4) /* Literal input. */ #define MAN_NEWLINE (1 << 6) /* first macro/text in a line */ 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 roff_node *last; /* the last parsed node */ + struct roff_node *first; /* the first parsed node */ struct man_meta meta; /* document meta-data */ struct roff *roff; }; #define MACRO_PROT_ARGS struct man *man, \ - enum mant tok, \ + int tok, \ int line, \ int ppos, \ int *pos, \ @@ -59,15 +59,15 @@ __BEGIN_DECLS void man_word_alloc(struct man *, int, int, const char *); void man_word_append(struct man *, const char *); -void man_block_alloc(struct man *, int, int, enum mant); -void man_head_alloc(struct man *, int, int, enum mant); -void man_body_alloc(struct man *, int, int, enum mant); -void man_elem_alloc(struct man *, int, int, enum mant); -void man_node_delete(struct man *, struct man_node *); +void man_block_alloc(struct man *, int, int, int); +void man_head_alloc(struct man *, int, int, int); +void man_body_alloc(struct man *, int, int, int); +void man_elem_alloc(struct man *, int, int, int); +void man_node_delete(struct man *, struct roff_node *); void man_hash_init(void); -enum mant man_hash_find(const char *); +int man_hash_find(const char *); void man_macroend(struct man *); void man_valid_post(struct man *); -void man_unscope(struct man *, const struct man_node *); +void man_unscope(struct man *, const struct roff_node *); __END_DECLS diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h index d7146765759..8a0aeb86ec6 100644 --- a/usr.bin/mandoc/libmdoc.h +++ b/usr.bin/mandoc/libmdoc.h @@ -1,15 +1,15 @@ -/* $OpenBSD: libmdoc.h,v 1.68 2015/02/02 04:26:03 schwarze Exp $ */ +/* $OpenBSD: libmdoc.h,v 1.69 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF @@ -37,17 +37,17 @@ struct mdoc { #define MDOC_SMOFF (1 << 9) /* spacing is off */ #define MDOC_NODELIMC (1 << 10) /* disable closing delimiter handling */ 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_node *last_es; /* the most recent Es node */ + struct roff_node *last; /* the last node parsed */ + struct roff_node *first; /* the first node parsed */ + struct roff_node *last_es; /* the most recent Es node */ struct mdoc_meta meta; /* document meta-data */ - enum mdoc_sec lastnamed; - enum mdoc_sec lastsec; + enum roff_sec lastnamed; + enum roff_sec lastsec; struct roff *roff; }; #define MACRO_PROT_ARGS struct mdoc *mdoc, \ - enum mdoct tok, \ + int tok, \ int line, \ int ppos, \ int *pos, \ @@ -100,28 +100,28 @@ void mdoc_macro(MACRO_PROT_ARGS); void mdoc_word_alloc(struct mdoc *, int, int, const char *); void mdoc_word_append(struct mdoc *, const char *); void mdoc_elem_alloc(struct mdoc *, int, int, - enum mdoct, struct mdoc_arg *); -struct mdoc_node *mdoc_block_alloc(struct mdoc *, int, int, - enum mdoct, struct mdoc_arg *); -struct mdoc_node *mdoc_head_alloc(struct mdoc *, int, int, enum mdoct); -void mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct); -struct mdoc_node *mdoc_body_alloc(struct mdoc *, int, int, enum mdoct); -struct mdoc_node *mdoc_endbody_alloc(struct mdoc *, int, int, enum mdoct, - struct mdoc_node *, enum mdoc_endbody); -void mdoc_node_delete(struct mdoc *, struct mdoc_node *); -void mdoc_node_relink(struct mdoc *, struct mdoc_node *); + int, struct mdoc_arg *); +struct roff_node *mdoc_block_alloc(struct mdoc *, int, int, + int, struct mdoc_arg *); +struct roff_node *mdoc_head_alloc(struct mdoc *, int, int, int); +void mdoc_tail_alloc(struct mdoc *, int, int, int); +struct roff_node *mdoc_body_alloc(struct mdoc *, int, int, int); +struct roff_node *mdoc_endbody_alloc(struct mdoc *, int, int, int, + struct roff_node *, enum mdoc_endbody); +void mdoc_node_delete(struct mdoc *, struct roff_node *); +void mdoc_node_relink(struct mdoc *, struct roff_node *); void mdoc_hash_init(void); -enum mdoct mdoc_hash_find(const char *); +int mdoc_hash_find(const char *); const char *mdoc_a2att(const char *); const char *mdoc_a2st(const char *); const char *mdoc_a2arch(const char *); -void mdoc_valid_pre(struct mdoc *, struct mdoc_node *); +void mdoc_valid_pre(struct mdoc *, struct roff_node *); void mdoc_valid_post(struct mdoc *); -void mdoc_argv(struct mdoc *, int, enum mdoct, +void mdoc_argv(struct mdoc *, int, int, struct mdoc_arg **, int *, char *); void mdoc_argv_free(struct mdoc_arg *); enum margserr mdoc_args(struct mdoc *, int, - int *, char *, enum mdoct, char **); + int *, char *, int, char **); void mdoc_macroend(struct mdoc *); enum mdelim mdoc_isdelim(const char *); diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index bb1b8068991..641422ed66a 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man.c,v 1.98 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: man.c,v 1.99 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -48,20 +48,19 @@ const char *const __man_macronames[MAN_MAX] = { const char * const *man_macronames = __man_macronames; static void man_alloc1(struct man *); -static void man_breakscope(struct man *, enum mant); +static void man_breakscope(struct man *, int); static void man_descope(struct man *, int, int); static void man_free1(struct man *); -static struct man_node *man_node_alloc(struct man *, int, int, - enum roff_type, enum mant); -static void man_node_append(struct man *, struct man_node *); -static void man_node_free(struct man_node *); -static void man_node_unlink(struct man *, - struct man_node *); +static struct roff_node *man_node_alloc(struct man *, int, int, + enum roff_type, int); +static void man_node_append(struct man *, struct roff_node *); +static void man_node_free(struct roff_node *); +static void man_node_unlink(struct man *, struct roff_node *); static int man_ptext(struct man *, int, char *, int); static int man_pmacro(struct man *, int, char *, int); -const struct man_node * +const struct roff_node * man_node(const struct man *man) { @@ -147,7 +146,7 @@ man_alloc1(struct man *man) memset(&man->meta, 0, sizeof(struct man_meta)); man->flags = 0; - man->last = mandoc_calloc(1, sizeof(struct man_node)); + man->last = mandoc_calloc(1, sizeof(*man->last)); man->first = man->last; man->last->type = ROFFT_ROOT; man->last->tok = MAN_MAX; @@ -156,7 +155,7 @@ man_alloc1(struct man *man) static void -man_node_append(struct man *man, struct man_node *p) +man_node_append(struct man *man, struct roff_node *p) { assert(man->last); @@ -211,13 +210,13 @@ man_node_append(struct man *man, struct man_node *p) } } -static struct man_node * +static struct roff_node * man_node_alloc(struct man *man, int line, int pos, - enum roff_type type, enum mant tok) + enum roff_type type, int tok) { - struct man_node *p; + struct roff_node *p; - p = mandoc_calloc(1, sizeof(struct man_node)); + p = mandoc_calloc(1, sizeof(*p)); p->line = line; p->pos = pos; p->type = type; @@ -230,9 +229,9 @@ man_node_alloc(struct man *man, int line, int pos, } void -man_elem_alloc(struct man *man, int line, int pos, enum mant tok) +man_elem_alloc(struct man *man, int line, int pos, int tok) { - struct man_node *p; + struct roff_node *p; p = man_node_alloc(man, line, pos, ROFFT_ELEM, tok); man_node_append(man, p); @@ -240,9 +239,9 @@ man_elem_alloc(struct man *man, int line, int pos, enum mant tok) } void -man_head_alloc(struct man *man, int line, int pos, enum mant tok) +man_head_alloc(struct man *man, int line, int pos, int tok) { - struct man_node *p; + struct roff_node *p; p = man_node_alloc(man, line, pos, ROFFT_HEAD, tok); man_node_append(man, p); @@ -250,9 +249,9 @@ man_head_alloc(struct man *man, int line, int pos, enum mant tok) } void -man_body_alloc(struct man *man, int line, int pos, enum mant tok) +man_body_alloc(struct man *man, int line, int pos, int tok) { - struct man_node *p; + struct roff_node *p; p = man_node_alloc(man, line, pos, ROFFT_BODY, tok); man_node_append(man, p); @@ -260,9 +259,9 @@ man_body_alloc(struct man *man, int line, int pos, enum mant tok) } void -man_block_alloc(struct man *man, int line, int pos, enum mant tok) +man_block_alloc(struct man *man, int line, int pos, int tok) { - struct man_node *p; + struct roff_node *p; p = man_node_alloc(man, line, pos, ROFFT_BLOCK, tok); man_node_append(man, p); @@ -272,7 +271,7 @@ man_block_alloc(struct man *man, int line, int pos, enum mant tok) void man_word_alloc(struct man *man, int line, int pos, const char *word) { - struct man_node *n; + struct roff_node *n; n = man_node_alloc(man, line, pos, ROFFT_TEXT, MAN_MAX); n->string = roff_strdup(man->roff, word); @@ -283,7 +282,7 @@ man_word_alloc(struct man *man, int line, int pos, const char *word) void man_word_append(struct man *man, const char *word) { - struct man_node *n; + struct roff_node *n; char *addstr, *newstr; n = man->last; @@ -300,7 +299,7 @@ man_word_append(struct man *man, const char *word) * node from its context; for that, see man_node_unlink(). */ static void -man_node_free(struct man_node *p) +man_node_free(struct roff_node *p) { free(p->string); @@ -308,7 +307,7 @@ man_node_free(struct man_node *p) } void -man_node_delete(struct man *man, struct man_node *p) +man_node_delete(struct man *man, struct roff_node *p) { while (p->child) @@ -321,7 +320,7 @@ man_node_delete(struct man *man, struct man_node *p) void man_addeqn(struct man *man, const struct eqn *ep) { - struct man_node *n; + struct roff_node *n; n = man_node_alloc(man, ep->ln, ep->pos, ROFFT_EQN, MAN_MAX); n->eqn = ep; @@ -335,7 +334,7 @@ man_addeqn(struct man *man, const struct eqn *ep) void man_addspan(struct man *man, const struct tbl_span *sp) { - struct man_node *n; + struct roff_node *n; man_breakscope(man, MAN_MAX); n = man_node_alloc(man, sp->line, 0, ROFFT_TBL, MAN_MAX); @@ -436,9 +435,9 @@ man_ptext(struct man *man, int line, char *buf, int offs) static int man_pmacro(struct man *man, int ln, char *buf, int offs) { - struct man_node *n; + struct roff_node *n; const char *cp; - enum mant tok; + int tok; int i, ppos; int bline; char mac[5]; @@ -534,9 +533,9 @@ man_pmacro(struct man *man, int ln, char *buf, int offs) } void -man_breakscope(struct man *man, enum mant tok) +man_breakscope(struct man *man, int tok) { - struct man_node *n; + struct roff_node *n; /* * An element next line scope is open, @@ -594,7 +593,7 @@ man_breakscope(struct man *man, enum mant tok) * point will also be adjusted accordingly. */ static void -man_node_unlink(struct man *man, struct man_node *n) +man_node_unlink(struct man *man, struct roff_node *n) { /* Adjust siblings. */ @@ -639,7 +638,7 @@ man_mparse(const struct man *man) } void -man_deroff(char **dest, const struct man_node *n) +man_deroff(char **dest, const struct roff_node *n) { char *cp; size_t sz; diff --git a/usr.bin/mandoc/man.h b/usr.bin/mandoc/man.h index 1b897ca1b5d..af4c3d1b274 100644 --- a/usr.bin/mandoc/man.h +++ b/usr.bin/mandoc/man.h @@ -1,62 +1,60 @@ -/* $OpenBSD: man.h,v 1.50 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: man.h,v 1.51 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -enum mant { - MAN_br = 0, - MAN_TH, - MAN_SH, - MAN_SS, - MAN_TP, - MAN_LP, - MAN_PP, - MAN_P, - MAN_IP, - MAN_HP, - MAN_SM, - MAN_SB, - MAN_BI, - MAN_IB, - MAN_BR, - MAN_RB, - MAN_R, - MAN_B, - MAN_I, - MAN_IR, - MAN_RI, - MAN_sp, - MAN_nf, - MAN_fi, - MAN_RE, - MAN_RS, - MAN_DT, - MAN_UC, - MAN_PD, - MAN_AT, - MAN_in, - MAN_ft, - MAN_OP, - MAN_EX, - MAN_EE, - MAN_UR, - MAN_UE, - MAN_ll, - MAN_MAX -}; +#define MAN_br 0 +#define MAN_TH 1 +#define MAN_SH 2 +#define MAN_SS 3 +#define MAN_TP 4 +#define MAN_LP 5 +#define MAN_PP 6 +#define MAN_P 7 +#define MAN_IP 8 +#define MAN_HP 9 +#define MAN_SM 10 +#define MAN_SB 11 +#define MAN_BI 12 +#define MAN_IB 13 +#define MAN_BR 14 +#define MAN_RB 15 +#define MAN_R 16 +#define MAN_B 17 +#define MAN_I 18 +#define MAN_IR 19 +#define MAN_RI 20 +#define MAN_sp 21 +#define MAN_nf 22 +#define MAN_fi 23 +#define MAN_RE 24 +#define MAN_RS 25 +#define MAN_DT 26 +#define MAN_UC 27 +#define MAN_PD 28 +#define MAN_AT 29 +#define MAN_in 30 +#define MAN_ft 31 +#define MAN_OP 32 +#define MAN_EX 33 +#define MAN_EE 34 +#define MAN_UR 35 +#define MAN_UE 36 +#define MAN_ll 37 +#define MAN_MAX 38 struct man_meta { char *msec; /* `TH' section (1, 3p, etc.) */ @@ -67,39 +65,16 @@ struct man_meta { int hasbody; /* document is not empty */ }; -struct man_node { - struct man_node *parent; /* parent AST node */ - struct man_node *child; /* first child AST node */ - struct man_node *next; /* sibling AST node */ - struct man_node *prev; /* prior sibling AST node */ - int nchild; /* number children */ - int line; - int pos; - enum mant tok; /* tok or MAN__MAX if none */ - int flags; -#define MAN_VALID (1 << 0) /* has been validated */ -#define MAN_EOS (1 << 2) /* at sentence boundary */ -#define MAN_LINE (1 << 3) /* first macro/text on line */ - enum roff_type type; /* AST node type */ - char *string; /* TEXT node argument */ - struct man_node *head; /* BLOCK node HEAD ptr */ - struct man_node *tail; /* BLOCK node TAIL ptr */ - struct man_node *body; /* BLOCK node BODY ptr */ - const struct tbl_span *span; /* TBL */ - const struct eqn *eqn; /* EQN */ - int aux; /* decoded node data, type-dependent */ -}; - -/* Names of macros. Index is enum mant. */ +/* Names of macros. */ extern const char *const *man_macronames; __BEGIN_DECLS struct man; -const struct man_node *man_node(const struct man *); +const struct roff_node *man_node(const struct man *); const struct man_meta *man_meta(const struct man *); const struct mparse *man_mparse(const struct man *); -void man_deroff(char **, const struct man_node *); +void man_deroff(char **, const struct roff_node *); __END_DECLS diff --git a/usr.bin/mandoc/man_hash.c b/usr.bin/mandoc/man_hash.c index 4618424b0d0..d80a9257879 100644 --- a/usr.bin/mandoc/man_hash.c +++ b/usr.bin/mandoc/man_hash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_hash.c,v 1.20 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: man_hash.c,v 1.21 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -75,11 +75,11 @@ man_hash_init(void) } } -enum mant +int man_hash_find(const char *tmp) { int x, y, i; - enum mant tok; + int tok; if ('\0' == (x = tmp[0])) return(MAN_MAX); @@ -92,7 +92,7 @@ man_hash_find(const char *tmp) if (UCHAR_MAX == (y = table[x + i])) return(MAN_MAX); - tok = (enum mant)y; + tok = y; if (0 == strcmp(tmp, man_macronames[tok])) return(tok); } diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c index 712ad37340d..68d61825e03 100644 --- a/usr.bin/mandoc/man_html.c +++ b/usr.bin/mandoc/man_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_html.c,v 1.66 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: man_html.c,v 1.67 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -36,7 +36,7 @@ #define INDENT 5 #define MAN_ARGS const struct man_meta *man, \ - const struct man_node *n, \ + const struct roff_node *n, \ struct mhtml *mh, \ struct html *h @@ -51,12 +51,12 @@ struct htmlman { }; static void print_bvspace(struct html *, - const struct man_node *); + const struct roff_node *); static void print_man(MAN_ARGS); static void print_man_head(MAN_ARGS); static void print_man_nodelist(MAN_ARGS); static void print_man_node(MAN_ARGS); -static int a2width(const struct man_node *, +static int a2width(const struct roff_node *, struct roffsu *); static int man_B_pre(MAN_ARGS); static int man_HP_pre(MAN_ARGS); @@ -128,7 +128,7 @@ static const struct htmlman mans[MAN_MAX] = { * first, print it. */ static void -print_bvspace(struct html *h, const struct man_node *n) +print_bvspace(struct html *h, const struct roff_node *n) { if (n->body && n->body->child) @@ -278,7 +278,7 @@ print_man_node(MAN_ARGS) } static int -a2width(const struct man_node *n, struct roffsu *su) +a2width(const struct roff_node *n, struct roffsu *su) { if (n->type != ROFFT_TEXT) @@ -398,7 +398,7 @@ man_SH_pre(MAN_ARGS) static int man_alt_pre(MAN_ARGS) { - const struct man_node *nn; + const struct roff_node *nn; int i, savelit; enum htmltag fp; struct tag *t; @@ -494,7 +494,7 @@ man_PP_pre(MAN_ARGS) static int man_IP_pre(MAN_ARGS) { - const struct man_node *nn; + const struct roff_node *nn; if (n->type == ROFFT_BODY) { print_otag(h, TAG_DD, 0, NULL); @@ -533,7 +533,7 @@ man_HP_pre(MAN_ARGS) { struct htmlpair tag[2]; struct roffsu su; - const struct man_node *np; + const struct roff_node *np; if (n->type == ROFFT_HEAD) return(0); diff --git a/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c index 1f3ee5aed95..cbaf4e7b171 100644 --- a/usr.bin/mandoc/man_macro.c +++ b/usr.bin/mandoc/man_macro.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_macro.c,v 1.63 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: man_macro.c,v 1.64 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2012, 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -42,12 +42,11 @@ static void in_line_eoln(MACRO_PROT_ARGS); static int man_args(struct man *, int, int *, char *, char **); -static void rew_scope(enum roff_type, - struct man *, enum mant); -static enum rew rew_dohalt(enum mant, enum roff_type, - const struct man_node *); -static enum rew rew_block(enum mant, enum roff_type, - const struct man_node *); +static void rew_scope(enum roff_type, struct man *, int); +static enum rew rew_dohalt(int, enum roff_type, + const struct roff_node *); +static enum rew rew_block(int, enum roff_type, + const struct roff_node *); const struct man_macro __man_macros[MAN_MAX] = { { in_line_eoln, MAN_NSCOPED }, /* br */ @@ -94,9 +93,9 @@ const struct man_macro * const man_macros = __man_macros; void -man_unscope(struct man *man, const struct man_node *to) +man_unscope(struct man *man, const struct roff_node *to) { - struct man_node *n; + struct roff_node *n; to = to->parent; n = man->last; @@ -154,7 +153,7 @@ man_unscope(struct man *man, const struct man_node *to) } static enum rew -rew_block(enum mant ntok, enum roff_type type, const struct man_node *n) +rew_block(int ntok, enum roff_type type, const struct roff_node *n) { if (type == ROFFT_BLOCK && n->parent->tok == ntok && @@ -169,7 +168,7 @@ rew_block(enum mant ntok, enum roff_type type, const struct man_node *n) * sections and subsections). */ static enum rew -rew_dohalt(enum mant tok, enum roff_type type, const struct man_node *n) +rew_dohalt(int tok, enum roff_type type, const struct roff_node *n) { enum rew c; @@ -242,9 +241,9 @@ rew_dohalt(enum mant tok, enum roff_type type, const struct man_node *n) * scopes. When a scope is closed, it must be validated and actioned. */ static void -rew_scope(enum roff_type type, struct man *man, enum mant tok) +rew_scope(enum roff_type type, struct man *man, int tok) { - struct man_node *n; + struct roff_node *n; enum rew c; for (n = man->last; n; n = n->parent) { @@ -275,8 +274,8 @@ rew_scope(enum roff_type type, struct man *man, enum mant tok) void blk_close(MACRO_PROT_ARGS) { - enum mant ntok; - const struct man_node *nn; + int ntok; + const struct roff_node *nn; char *p; int nrew, target; @@ -336,7 +335,7 @@ blk_close(MACRO_PROT_ARGS) void blk_exp(MACRO_PROT_ARGS) { - struct man_node *head; + struct roff_node *head; char *p; int la; @@ -369,7 +368,7 @@ blk_imp(MACRO_PROT_ARGS) { int la; char *p; - struct man_node *n; + struct roff_node *n; rew_scope(ROFFT_BODY, man, tok); rew_scope(ROFFT_BLOCK, man, tok); @@ -409,7 +408,7 @@ in_line_eoln(MACRO_PROT_ARGS) { int la; char *p; - struct man_node *n; + struct roff_node *n; man_elem_alloc(man, line, ppos, tok); n = man->last; diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index deb6ba80b77..448af796bda 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_term.c,v 1.124 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: man_term.c,v 1.125 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -46,7 +46,7 @@ struct mtermp { #define DECL_ARGS struct termp *p, \ struct mtermp *mt, \ - struct man_node *n, \ + struct roff_node *n, \ const struct man_meta *meta struct termact { @@ -61,7 +61,7 @@ static void print_man_node(DECL_ARGS); static void print_man_head(struct termp *, const void *); static void print_man_foot(struct termp *, const void *); static void print_bvspace(struct termp *, - const struct man_node *, int); + const struct roff_node *, int); static int pre_B(DECL_ARGS); static int pre_HP(DECL_ARGS); @@ -138,7 +138,7 @@ terminal_man(void *arg, const struct man *man) { struct termp *p; const struct man_meta *meta; - struct man_node *n; + struct roff_node *n; struct mtermp mt; p = (struct termp *)arg; @@ -189,7 +189,7 @@ terminal_man(void *arg, const struct man *man) * first, print it. */ static void -print_bvspace(struct termp *p, const struct man_node *n, int pardist) +print_bvspace(struct termp *p, const struct roff_node *n, int pardist) { int i; @@ -278,7 +278,7 @@ static int pre_alternate(DECL_ARGS) { enum termfont font[2]; - struct man_node *nn; + struct roff_node *nn; int savelit, i; switch (n->tok) { @@ -486,7 +486,7 @@ static int pre_HP(DECL_ARGS) { struct roffsu su; - const struct man_node *nn; + const struct roff_node *nn; int len; switch (n->type) { @@ -560,7 +560,7 @@ static int pre_IP(DECL_ARGS) { struct roffsu su; - const struct man_node *nn; + const struct roff_node *nn; int len, savelit; switch (n->type) { @@ -641,7 +641,7 @@ static int pre_TP(DECL_ARGS) { struct roffsu su; - struct man_node *nn; + struct roff_node *nn; int len, savelit; switch (n->type) { diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index a0e408cac5c..5dff3c59eb4 100644 --- a/usr.bin/mandoc/man_validate.c +++ b/usr.bin/mandoc/man_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_validate.c,v 1.85 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: man_validate.c,v 1.86 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -33,7 +33,7 @@ #include "libmandoc.h" #include "libman.h" -#define CHKARGS struct man *man, struct man_node *n +#define CHKARGS struct man *man, struct roff_node *n typedef void (*v_check)(CHKARGS); @@ -98,7 +98,7 @@ static v_check man_valids[MAN_MAX] = { void man_valid_post(struct man *man) { - struct man_node *n; + struct roff_node *n; v_check *cp; n = man->last; @@ -298,7 +298,7 @@ post_IP(CHKARGS) static void post_TH(CHKARGS) { - struct man_node *nb; + struct roff_node *nb; const char *p; free(man->meta.title); @@ -458,8 +458,8 @@ post_AT(CHKARGS) "System V Release 2", }; + struct roff_node *nn; const char *p, *s; - struct man_node *nn; n = n->child; diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index 98eaf6240b8..682dc2c4cdf 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandocdb.c,v 1.141 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mandocdb.c,v 1.142 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -121,7 +121,7 @@ enum stmt { }; typedef int (*mdoc_fp)(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); struct mdoc_handler { mdoc_fp fp; /* optional handler */ @@ -147,32 +147,32 @@ static void mpages_merge(struct mparse *); static void names_check(void); static void parse_cat(struct mpage *, int); static void parse_man(struct mpage *, const struct man_meta *, - const struct man_node *); + const struct roff_node *); static void parse_mdoc(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); static int parse_mdoc_body(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); static int parse_mdoc_head(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); static int parse_mdoc_Fd(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); -static void parse_mdoc_fname(struct mpage *, const struct mdoc_node *); + const struct roff_node *); +static void parse_mdoc_fname(struct mpage *, const struct roff_node *); static int parse_mdoc_Fn(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); static int parse_mdoc_Fo(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); static int parse_mdoc_Nd(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); static int parse_mdoc_Nm(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); static int parse_mdoc_Sh(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); static int parse_mdoc_Xr(struct mpage *, const struct mdoc_meta *, - const struct mdoc_node *); + const struct roff_node *); static void putkey(const struct mpage *, char *, uint64_t); static void putkeys(const struct mpage *, char *, size_t, uint64_t); static void putmdockey(const struct mpage *, - const struct mdoc_node *, uint64_t); + const struct roff_node *, uint64_t); static int render_string(char **, size_t *); static void say(const char *, const char *, ...); static int set_basedir(const char *, int); @@ -1413,7 +1413,7 @@ putkey(const struct mpage *mpage, char *value, uint64_t type) */ static void putmdockey(const struct mpage *mpage, - const struct mdoc_node *n, uint64_t m) + const struct roff_node *n, uint64_t m) { for ( ; NULL != n; n = n->next) { @@ -1426,9 +1426,9 @@ putmdockey(const struct mpage *mpage, static void parse_man(struct mpage *mpage, const struct man_meta *meta, - const struct man_node *n) + const struct roff_node *n) { - const struct man_node *head, *body; + const struct roff_node *head, *body; char *start, *title; char byte; size_t sz; @@ -1552,7 +1552,7 @@ parse_man(struct mpage *mpage, const struct man_meta *meta, static void parse_mdoc(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { assert(NULL != n); @@ -1585,7 +1585,7 @@ parse_mdoc(struct mpage *mpage, const struct mdoc_meta *meta, static int parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { char *start, *end; size_t sz; @@ -1628,7 +1628,7 @@ parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_meta *meta, } static void -parse_mdoc_fname(struct mpage *mpage, const struct mdoc_node *n) +parse_mdoc_fname(struct mpage *mpage, const struct roff_node *n) { char *cp; size_t sz; @@ -1650,7 +1650,7 @@ parse_mdoc_fname(struct mpage *mpage, const struct mdoc_node *n) static int parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { if (n->child == NULL) @@ -1667,7 +1667,7 @@ parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_meta *meta, static int parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { if (n->type != ROFFT_HEAD) @@ -1681,7 +1681,7 @@ parse_mdoc_Fo(struct mpage *mpage, const struct mdoc_meta *meta, static int parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { char *cp; @@ -1701,7 +1701,7 @@ parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_meta *meta, static int parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { if (n->type == ROFFT_BODY) @@ -1711,7 +1711,7 @@ parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_meta *meta, static int parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { if (SEC_NAME == n->sec) @@ -1733,7 +1733,7 @@ parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_meta *meta, static int parse_mdoc_Sh(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { return(n->sec == SEC_CUSTOM && n->type == ROFFT_HEAD); @@ -1741,7 +1741,7 @@ parse_mdoc_Sh(struct mpage *mpage, const struct mdoc_meta *meta, static int parse_mdoc_head(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { return(n->type == ROFFT_HEAD); @@ -1749,7 +1749,7 @@ parse_mdoc_head(struct mpage *mpage, const struct mdoc_meta *meta, static int parse_mdoc_body(struct mpage *mpage, const struct mdoc_meta *meta, - const struct mdoc_node *n) + const struct roff_node *n) { return(n->type == ROFFT_BODY); diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index ea26de2c7d3..a48056048ae 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc.c,v 1.128 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mdoc.c,v 1.129 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -81,19 +81,19 @@ const char *const __mdoc_argnames[MDOC_ARG_MAX] = { const char * const *mdoc_macronames = __mdoc_macronames; const char * const *mdoc_argnames = __mdoc_argnames; -static void mdoc_node_free(struct mdoc_node *); +static void mdoc_node_free(struct roff_node *); static void mdoc_node_unlink(struct mdoc *, - struct mdoc_node *); + struct roff_node *); static void mdoc_free1(struct mdoc *); static void mdoc_alloc1(struct mdoc *); -static struct mdoc_node *node_alloc(struct mdoc *, int, int, - enum mdoct, enum roff_type); -static void node_append(struct mdoc *, struct mdoc_node *); +static struct roff_node *node_alloc(struct mdoc *, int, int, + int, enum roff_type); +static void node_append(struct mdoc *, struct roff_node *); static int mdoc_ptext(struct mdoc *, int, char *, int); static int mdoc_pmacro(struct mdoc *, int, char *, int); -const struct mdoc_node * +const struct roff_node * mdoc_node(const struct mdoc *mdoc) { @@ -135,7 +135,7 @@ mdoc_alloc1(struct mdoc *mdoc) memset(&mdoc->meta, 0, sizeof(struct mdoc_meta)); mdoc->flags = 0; mdoc->lastnamed = mdoc->lastsec = SEC_NONE; - mdoc->last = mandoc_calloc(1, sizeof(struct mdoc_node)); + mdoc->last = mandoc_calloc(1, sizeof(*mdoc->last)); mdoc->first = mdoc->last; mdoc->last->type = ROFFT_ROOT; mdoc->last->tok = MDOC_MAX; @@ -199,7 +199,7 @@ mdoc_endparse(struct mdoc *mdoc) void mdoc_addeqn(struct mdoc *mdoc, const struct eqn *ep) { - struct mdoc_node *n; + struct roff_node *n; n = node_alloc(mdoc, ep->ln, ep->pos, MDOC_MAX, ROFFT_EQN); n->eqn = ep; @@ -212,7 +212,7 @@ mdoc_addeqn(struct mdoc *mdoc, const struct eqn *ep) void mdoc_addspan(struct mdoc *mdoc, const struct tbl_span *sp) { - struct mdoc_node *n; + struct roff_node *n; n = node_alloc(mdoc, sp->line, 0, MDOC_MAX, ROFFT_TBL); n->span = sp; @@ -275,7 +275,7 @@ mdoc_macro(MACRO_PROT_ARGS) static void -node_append(struct mdoc *mdoc, struct mdoc_node *p) +node_append(struct mdoc *mdoc, struct roff_node *p) { assert(mdoc->last); @@ -352,13 +352,13 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p) } } -static struct mdoc_node * +static struct roff_node * node_alloc(struct mdoc *mdoc, int line, int pos, - enum mdoct tok, enum roff_type type) + int tok, enum roff_type type) { - struct mdoc_node *p; + struct roff_node *p; - p = mandoc_calloc(1, sizeof(struct mdoc_node)); + p = mandoc_calloc(1, sizeof(*p)); p->sec = mdoc->lastsec; p->line = line; p->pos = pos; @@ -379,19 +379,19 @@ node_alloc(struct mdoc *mdoc, int line, int pos, } void -mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) +mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, int tok) { - struct mdoc_node *p; + struct roff_node *p; p = node_alloc(mdoc, line, pos, tok, ROFFT_TAIL); node_append(mdoc, p); mdoc->next = MDOC_NEXT_CHILD; } -struct mdoc_node * -mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) +struct roff_node * +mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, int tok) { - struct mdoc_node *p; + struct roff_node *p; assert(mdoc->first); assert(mdoc->last); @@ -401,10 +401,10 @@ mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) return(p); } -struct mdoc_node * -mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) +struct roff_node * +mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, int tok) { - struct mdoc_node *p; + struct roff_node *p; p = node_alloc(mdoc, line, pos, tok, ROFFT_BODY); node_append(mdoc, p); @@ -412,11 +412,11 @@ mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) return(p); } -struct mdoc_node * -mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, - struct mdoc_node *body, enum mdoc_endbody end) +struct roff_node * +mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, int tok, + struct roff_node *body, enum mdoc_endbody end) { - struct mdoc_node *p; + struct roff_node *p; body->flags |= MDOC_ENDED; body->parent->flags |= MDOC_ENDED; @@ -429,11 +429,11 @@ mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, return(p); } -struct mdoc_node * +struct roff_node * mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, - enum mdoct tok, struct mdoc_arg *args) + int tok, struct mdoc_arg *args) { - struct mdoc_node *p; + struct roff_node *p; p = node_alloc(mdoc, line, pos, tok, ROFFT_BLOCK); p->args = args; @@ -462,9 +462,9 @@ mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, void mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, - enum mdoct tok, struct mdoc_arg *args) + int tok, struct mdoc_arg *args) { - struct mdoc_node *p; + struct roff_node *p; p = node_alloc(mdoc, line, pos, tok, ROFFT_ELEM); p->args = args; @@ -485,7 +485,7 @@ mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, void mdoc_word_alloc(struct mdoc *mdoc, int line, int pos, const char *p) { - struct mdoc_node *n; + struct roff_node *n; n = node_alloc(mdoc, line, pos, MDOC_MAX, ROFFT_TEXT); n->string = roff_strdup(mdoc->roff, p); @@ -496,7 +496,7 @@ mdoc_word_alloc(struct mdoc *mdoc, int line, int pos, const char *p) void mdoc_word_append(struct mdoc *mdoc, const char *p) { - struct mdoc_node *n; + struct roff_node *n; char *addstr, *newstr; n = mdoc->last; @@ -509,7 +509,7 @@ mdoc_word_append(struct mdoc *mdoc, const char *p) } static void -mdoc_node_free(struct mdoc_node *p) +mdoc_node_free(struct roff_node *p) { if (p->type == ROFFT_BLOCK || p->type == ROFFT_ELEM) @@ -522,7 +522,7 @@ mdoc_node_free(struct mdoc_node *p) } static void -mdoc_node_unlink(struct mdoc *mdoc, struct mdoc_node *n) +mdoc_node_unlink(struct mdoc *mdoc, struct roff_node *n) { /* Adjust siblings. */ @@ -559,7 +559,7 @@ mdoc_node_unlink(struct mdoc *mdoc, struct mdoc_node *n) } void -mdoc_node_delete(struct mdoc *mdoc, struct mdoc_node *p) +mdoc_node_delete(struct mdoc *mdoc, struct roff_node *p) { while (p->child) { @@ -573,7 +573,7 @@ mdoc_node_delete(struct mdoc *mdoc, struct mdoc_node *p) } void -mdoc_node_relink(struct mdoc *mdoc, struct mdoc_node *p) +mdoc_node_relink(struct mdoc *mdoc, struct roff_node *p) { mdoc_node_unlink(mdoc, p); @@ -587,8 +587,8 @@ mdoc_node_relink(struct mdoc *mdoc, struct mdoc_node *p) static int mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int offs) { + struct roff_node *n; char *c, *ws, *end; - struct mdoc_node *n; assert(mdoc->last); n = mdoc->last; @@ -703,9 +703,9 @@ mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int offs) static int mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs) { - struct mdoc_node *n; + struct roff_node *n; const char *cp; - enum mdoct tok; + int tok; int i, sv; char mac[5]; @@ -859,7 +859,7 @@ mdoc_isdelim(const char *p) } void -mdoc_deroff(char **dest, const struct mdoc_node *n) +mdoc_deroff(char **dest, const struct roff_node *n) { char *cp; size_t sz; diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h index 6e68a9d9052..bec7b57ac21 100644 --- a/usr.bin/mandoc/mdoc.h +++ b/usr.bin/mandoc/mdoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc.h,v 1.62 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mdoc.h,v 1.63 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -16,132 +16,130 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -enum mdoct { - MDOC_Ap = 0, - MDOC_Dd, - MDOC_Dt, - MDOC_Os, - MDOC_Sh, - MDOC_Ss, - MDOC_Pp, - MDOC_D1, - MDOC_Dl, - MDOC_Bd, - MDOC_Ed, - MDOC_Bl, - MDOC_El, - MDOC_It, - MDOC_Ad, - MDOC_An, - MDOC_Ar, - MDOC_Cd, - MDOC_Cm, - MDOC_Dv, - MDOC_Er, - MDOC_Ev, - MDOC_Ex, - MDOC_Fa, - MDOC_Fd, - MDOC_Fl, - MDOC_Fn, - MDOC_Ft, - MDOC_Ic, - MDOC_In, - MDOC_Li, - MDOC_Nd, - MDOC_Nm, - MDOC_Op, - MDOC_Ot, - MDOC_Pa, - MDOC_Rv, - MDOC_St, - MDOC_Va, - MDOC_Vt, - MDOC_Xr, - MDOC__A, - MDOC__B, - MDOC__D, - MDOC__I, - MDOC__J, - MDOC__N, - MDOC__O, - MDOC__P, - MDOC__R, - MDOC__T, - MDOC__V, - MDOC_Ac, - MDOC_Ao, - MDOC_Aq, - MDOC_At, - MDOC_Bc, - MDOC_Bf, - MDOC_Bo, - MDOC_Bq, - MDOC_Bsx, - MDOC_Bx, - MDOC_Db, - MDOC_Dc, - MDOC_Do, - MDOC_Dq, - MDOC_Ec, - MDOC_Ef, - MDOC_Em, - MDOC_Eo, - MDOC_Fx, - MDOC_Ms, - MDOC_No, - MDOC_Ns, - MDOC_Nx, - MDOC_Ox, - MDOC_Pc, - MDOC_Pf, - MDOC_Po, - MDOC_Pq, - MDOC_Qc, - MDOC_Ql, - MDOC_Qo, - MDOC_Qq, - MDOC_Re, - MDOC_Rs, - MDOC_Sc, - MDOC_So, - MDOC_Sq, - MDOC_Sm, - MDOC_Sx, - MDOC_Sy, - MDOC_Tn, - MDOC_Ux, - MDOC_Xc, - MDOC_Xo, - MDOC_Fo, - MDOC_Fc, - MDOC_Oo, - MDOC_Oc, - MDOC_Bk, - MDOC_Ek, - MDOC_Bt, - MDOC_Hf, - MDOC_Fr, - MDOC_Ud, - MDOC_Lb, - MDOC_Lp, - MDOC_Lk, - MDOC_Mt, - MDOC_Brq, - MDOC_Bro, - MDOC_Brc, - MDOC__C, - MDOC_Es, - MDOC_En, - MDOC_Dx, - MDOC__Q, - MDOC_br, - MDOC_sp, - MDOC__U, - MDOC_Ta, - MDOC_ll, - MDOC_MAX -}; +#define MDOC_Ap 0 +#define MDOC_Dd 1 +#define MDOC_Dt 2 +#define MDOC_Os 3 +#define MDOC_Sh 4 +#define MDOC_Ss 5 +#define MDOC_Pp 6 +#define MDOC_D1 7 +#define MDOC_Dl 8 +#define MDOC_Bd 9 +#define MDOC_Ed 10 +#define MDOC_Bl 11 +#define MDOC_El 12 +#define MDOC_It 13 +#define MDOC_Ad 14 +#define MDOC_An 15 +#define MDOC_Ar 16 +#define MDOC_Cd 17 +#define MDOC_Cm 18 +#define MDOC_Dv 19 +#define MDOC_Er 20 +#define MDOC_Ev 21 +#define MDOC_Ex 22 +#define MDOC_Fa 23 +#define MDOC_Fd 24 +#define MDOC_Fl 25 +#define MDOC_Fn 26 +#define MDOC_Ft 27 +#define MDOC_Ic 28 +#define MDOC_In 29 +#define MDOC_Li 30 +#define MDOC_Nd 31 +#define MDOC_Nm 32 +#define MDOC_Op 33 +#define MDOC_Ot 34 +#define MDOC_Pa 35 +#define MDOC_Rv 36 +#define MDOC_St 37 +#define MDOC_Va 38 +#define MDOC_Vt 39 +#define MDOC_Xr 40 +#define MDOC__A 41 +#define MDOC__B 42 +#define MDOC__D 43 +#define MDOC__I 44 +#define MDOC__J 45 +#define MDOC__N 46 +#define MDOC__O 47 +#define MDOC__P 48 +#define MDOC__R 49 +#define MDOC__T 50 +#define MDOC__V 51 +#define MDOC_Ac 52 +#define MDOC_Ao 53 +#define MDOC_Aq 54 +#define MDOC_At 55 +#define MDOC_Bc 56 +#define MDOC_Bf 57 +#define MDOC_Bo 58 +#define MDOC_Bq 59 +#define MDOC_Bsx 60 +#define MDOC_Bx 61 +#define MDOC_Db 62 +#define MDOC_Dc 63 +#define MDOC_Do 64 +#define MDOC_Dq 65 +#define MDOC_Ec 66 +#define MDOC_Ef 67 +#define MDOC_Em 68 +#define MDOC_Eo 69 +#define MDOC_Fx 70 +#define MDOC_Ms 71 +#define MDOC_No 72 +#define MDOC_Ns 73 +#define MDOC_Nx 74 +#define MDOC_Ox 75 +#define MDOC_Pc 76 +#define MDOC_Pf 77 +#define MDOC_Po 78 +#define MDOC_Pq 79 +#define MDOC_Qc 80 +#define MDOC_Ql 81 +#define MDOC_Qo 82 +#define MDOC_Qq 83 +#define MDOC_Re 84 +#define MDOC_Rs 85 +#define MDOC_Sc 86 +#define MDOC_So 87 +#define MDOC_Sq 88 +#define MDOC_Sm 89 +#define MDOC_Sx 90 +#define MDOC_Sy 91 +#define MDOC_Tn 92 +#define MDOC_Ux 93 +#define MDOC_Xc 94 +#define MDOC_Xo 95 +#define MDOC_Fo 96 +#define MDOC_Fc 97 +#define MDOC_Oo 98 +#define MDOC_Oc 99 +#define MDOC_Bk 100 +#define MDOC_Ek 101 +#define MDOC_Bt 102 +#define MDOC_Hf 103 +#define MDOC_Fr 104 +#define MDOC_Ud 105 +#define MDOC_Lb 106 +#define MDOC_Lp 107 +#define MDOC_Lk 108 +#define MDOC_Mt 109 +#define MDOC_Brq 110 +#define MDOC_Bro 111 +#define MDOC_Brc 112 +#define MDOC__C 113 +#define MDOC_Es 114 +#define MDOC_En 115 +#define MDOC_Dx 116 +#define MDOC__Q 117 +#define MDOC_br 118 +#define MDOC_sp 119 +#define MDOC__U 120 +#define MDOC_Ta 121 +#define MDOC_ll 122 +#define MDOC_MAX 123 enum mdocargt { MDOC_Split, /* -split */ @@ -174,39 +172,6 @@ enum mdocargt { MDOC_ARG_MAX }; -/* - * Section (named/unnamed) of `Sh'. Note that these appear in the - * conventional order imposed by mdoc.7. In the case of SEC_NONE, no - * section has been invoked (this shouldn't happen). SEC_CUSTOM refers - * to other sections. - */ -enum mdoc_sec { - SEC_NONE = 0, - SEC_NAME, /* NAME */ - SEC_LIBRARY, /* LIBRARY */ - SEC_SYNOPSIS, /* SYNOPSIS */ - SEC_DESCRIPTION, /* DESCRIPTION */ - SEC_CONTEXT, /* CONTEXT */ - SEC_IMPLEMENTATION, /* IMPLEMENTATION NOTES */ - SEC_RETURN_VALUES, /* RETURN VALUES */ - SEC_ENVIRONMENT, /* ENVIRONMENT */ - SEC_FILES, /* FILES */ - SEC_EXIT_STATUS, /* EXIT STATUS */ - SEC_EXAMPLES, /* EXAMPLES */ - SEC_DIAGNOSTICS, /* DIAGNOSTICS */ - SEC_COMPATIBILITY, /* COMPATIBILITY */ - SEC_ERRORS, /* ERRORS */ - SEC_SEE_ALSO, /* SEE ALSO */ - SEC_STANDARDS, /* STANDARDS */ - SEC_HISTORY, /* HISTORY */ - SEC_AUTHORS, /* AUTHORS */ - SEC_CAVEATS, /* CAVEATS */ - SEC_BUGS, /* BUGS */ - SEC_SECURITY, /* SECURITY */ - SEC_CUSTOM, - SEC__MAX -}; - struct mdoc_meta { char *msec; /* `Dt' section (1, 3p, etc.) */ char *vol; /* `Dt' volume (implied) */ @@ -239,16 +204,6 @@ struct mdoc_arg { unsigned int refcnt; }; -/* - * Indicates that a BODY's formatting has ended, but the scope is still - * open. Used for syntax-broken blocks. - */ -enum mdoc_endbody { - ENDBODY_NOT = 0, - ENDBODY_SPACE, /* is broken: append a space */ - ENDBODY_NOSPACE /* is broken: don't append a space */ -}; - enum mdoc_list { LIST__NONE = 0, LIST_bullet, /* -bullet */ @@ -325,48 +280,11 @@ union mdoc_data { struct mdoc_bd Bd; struct mdoc_bf Bf; struct mdoc_bl Bl; - struct mdoc_node *Es; + struct roff_node *Es; struct mdoc_rs Rs; }; -/* - * Single node in tree-linked AST. - */ -struct mdoc_node { - struct mdoc_node *parent; /* parent AST node */ - struct mdoc_node *child; /* first child AST node */ - struct mdoc_node *last; /* last child AST node */ - struct mdoc_node *next; /* sibling AST node */ - struct mdoc_node *prev; /* prior sibling AST node */ - int nchild; /* number children */ - int line; /* parse line */ - int pos; /* parse column */ - enum mdoct tok; /* tok or MDOC__MAX if none */ - int flags; -#define MDOC_VALID (1 << 0) /* has been validated */ -#define MDOC_ENDED (1 << 1) /* gone past body end mark */ -#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 */ -#define MDOC_BROKEN (1 << 5) /* must validate parent when ending */ -#define MDOC_DELIMO (1 << 6) -#define MDOC_DELIMC (1 << 7) - enum roff_type type; /* AST node type */ - enum mdoc_sec sec; /* current named section */ - union mdoc_data *norm; /* normalised args */ - int prev_font; /* before entering this node */ - /* FIXME: these can be union'd to shave a few bytes. */ - struct mdoc_arg *args; /* BLOCK/ELEM */ - struct mdoc_node *head; /* BLOCK */ - struct mdoc_node *body; /* BLOCK/ENDBODY */ - struct mdoc_node *tail; /* BLOCK */ - char *string; /* TEXT */ - const struct tbl_span *span; /* TBL */ - const struct eqn *eqn; /* EQN */ - enum mdoc_endbody end; /* BODY */ -}; - -/* Names of macros. Index is enum mdoct. */ +/* Names of macros. */ extern const char *const *mdoc_macronames; /* Names of macro args. Index is enum mdocargt. */ @@ -376,8 +294,8 @@ __BEGIN_DECLS struct mdoc; -const struct mdoc_node *mdoc_node(const struct mdoc *); +const struct roff_node *mdoc_node(const struct mdoc *); const struct mdoc_meta *mdoc_meta(const struct mdoc *); -void mdoc_deroff(char **, const struct mdoc_node *); +void mdoc_deroff(char **, const struct roff_node *); __END_DECLS diff --git a/usr.bin/mandoc/mdoc_argv.c b/usr.bin/mandoc/mdoc_argv.c index 1742787c8a6..131b448c7bf 100644 --- a/usr.bin/mandoc/mdoc_argv.c +++ b/usr.bin/mandoc/mdoc_argv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_argv.c,v 1.57 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mdoc_argv.c,v 1.58 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2012, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -274,7 +274,7 @@ static const struct mdocarg mdocargs[MDOC_MAX] = { * Some flags take no argument, some one, some multiple. */ void -mdoc_argv(struct mdoc *mdoc, int line, enum mdoct tok, +mdoc_argv(struct mdoc *mdoc, int line, int tok, struct mdoc_arg **reta, int *pos, char *buf) { struct mdoc_argv tmpv; @@ -412,9 +412,9 @@ argn_free(struct mdoc_arg *p, int iarg) enum margserr mdoc_args(struct mdoc *mdoc, int line, int *pos, - char *buf, enum mdoct tok, char **v) + char *buf, int tok, char **v) { - struct mdoc_node *n; + struct roff_node *n; char *v_local; enum argsflag fl; diff --git a/usr.bin/mandoc/mdoc_hash.c b/usr.bin/mandoc/mdoc_hash.c index 169244bb7d4..5df9b4c5eb4 100644 --- a/usr.bin/mandoc/mdoc_hash.c +++ b/usr.bin/mandoc/mdoc_hash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_hash.c,v 1.17 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mdoc_hash.c,v 1.18 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -60,7 +60,7 @@ mdoc_hash_init(void) } } -enum mdoct +int mdoc_hash_find(const char *p) { int major, i, j; @@ -84,7 +84,7 @@ mdoc_hash_find(const char *p) if (UCHAR_MAX == (i = table[major + j])) break; if (0 == strcmp(p, mdoc_macronames[i])) - return((enum mdoct)i); + return(i); } return(MDOC_MAX); diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index 4cbc340d17f..bd2d4ba06ed 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_html.c,v 1.102 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mdoc_html.c,v 1.103 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -34,7 +34,7 @@ #define INDENT 5 #define MDOC_ARGS const struct mdoc_meta *meta, \ - struct mdoc_node *n, \ + struct roff_node *n, \ struct html *h #ifndef MIN @@ -51,7 +51,7 @@ static void print_mdoc_head(MDOC_ARGS); static void print_mdoc_node(MDOC_ARGS); static void print_mdoc_nodelist(MDOC_ARGS); static void synopsis_pre(struct html *, - const struct mdoc_node *); + const struct roff_node *); static void a2width(const char *, struct roffsu *); @@ -291,7 +291,7 @@ a2width(const char *p, struct roffsu *su) * See the same function in mdoc_term.c for documentation. */ static void -synopsis_pre(struct html *h, const struct mdoc_node *n) +synopsis_pre(struct html *h, const struct roff_node *n) { if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags)) @@ -820,7 +820,7 @@ mdoc_it_pre(MDOC_ARGS) struct roffsu su; enum mdoc_list type; struct htmlpair tag[2]; - const struct mdoc_node *bl; + const struct roff_node *bl; bl = n->parent; while (bl && MDOC_Bl != bl->tok) @@ -1124,7 +1124,7 @@ mdoc_bd_pre(MDOC_ARGS) { struct htmlpair tag[2]; int comp, sv; - struct mdoc_node *nn; + struct roff_node *nn; struct roffsu su; if (n->type == ROFFT_HEAD) @@ -1310,7 +1310,7 @@ mdoc_er_pre(MDOC_ARGS) static int mdoc_fa_pre(MDOC_ARGS) { - const struct mdoc_node *nn; + const struct roff_node *nn; struct htmlpair tag; struct tag *t; diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index 74f65409cfa..81cea4bedc6 100644 --- a/usr.bin/mandoc/mdoc_macro.c +++ b/usr.bin/mandoc/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_macro.c,v 1.140 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mdoc_macro.c,v 1.141 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -43,15 +43,13 @@ static void phrase_ta(MACRO_PROT_ARGS); static void dword(struct mdoc *, int, int, const char *, enum mdelim, int); static void append_delims(struct mdoc *, int, int *, char *); -static enum mdoct lookup(struct mdoc *, enum mdoct, - int, int, const char *); +static int lookup(struct mdoc *, int, int, int, const char *); static int macro_or_word(MACRO_PROT_ARGS, int); -static int parse_rest(struct mdoc *, enum mdoct, - int, int *, char *); -static enum mdoct rew_alt(enum mdoct); -static void rew_elem(struct mdoc *, enum mdoct); -static void rew_last(struct mdoc *, const struct mdoc_node *); -static void rew_pending(struct mdoc *, const struct mdoc_node *); +static int parse_rest(struct mdoc *, int, int, int *, char *); +static int rew_alt(int); +static void rew_elem(struct mdoc *, int); +static void rew_last(struct mdoc *, const struct roff_node *); +static void rew_pending(struct mdoc *, const struct roff_node *); const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { in_line_argn, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ap */ @@ -208,7 +206,7 @@ const struct mdoc_macro * const mdoc_macros = __mdoc_macros; void mdoc_macroend(struct mdoc *mdoc) { - struct mdoc_node *n; + struct roff_node *n; /* Scan for open explicit scopes. */ @@ -230,10 +228,10 @@ mdoc_macroend(struct mdoc *mdoc) * Look up the macro at *p called by "from", * or as a line macro if from == MDOC_MAX. */ -static enum mdoct -lookup(struct mdoc *mdoc, enum mdoct from, int line, int ppos, const char *p) +static int +lookup(struct mdoc *mdoc, int from, int line, int ppos, const char *p) { - enum mdoct res; + int res; if (from == MDOC_MAX || mdoc_macros[from].flags & MDOC_PARSED) { res = mdoc_hash_find(p); @@ -252,9 +250,9 @@ lookup(struct mdoc *mdoc, enum mdoct from, int line, int ppos, const char *p) * Rewind up to and including a specific node. */ static void -rew_last(struct mdoc *mdoc, const struct mdoc_node *to) +rew_last(struct mdoc *mdoc, const struct roff_node *to) { - struct mdoc_node *n, *np; + struct roff_node *n, *np; assert(to); mdoc->next = MDOC_NEXT_SIBLING; @@ -279,7 +277,7 @@ rew_last(struct mdoc *mdoc, const struct mdoc_node *to) * Rewind up to a specific block, including all blocks that broke it. */ static void -rew_pending(struct mdoc *mdoc, const struct mdoc_node *n) +rew_pending(struct mdoc *mdoc, const struct roff_node *n) { for (;;) { @@ -317,8 +315,8 @@ rew_pending(struct mdoc *mdoc, const struct mdoc_node *n) * For a block closing macro, return the corresponding opening one. * Otherwise, return the macro itself. */ -static enum mdoct -rew_alt(enum mdoct tok) +static int +rew_alt(int tok) { switch (tok) { case MDOC_Ac: @@ -360,9 +358,9 @@ rew_alt(enum mdoct tok) } static void -rew_elem(struct mdoc *mdoc, enum mdoct tok) +rew_elem(struct mdoc *mdoc, int tok) { - struct mdoc_node *n; + struct roff_node *n; n = mdoc->last; if (n->type != ROFFT_ELEM) @@ -451,7 +449,7 @@ static int macro_or_word(MACRO_PROT_ARGS, int parsed) { char *p; - enum mdoct ntok; + int ntok; p = buf + ppos; ntok = MDOC_MAX; @@ -480,15 +478,15 @@ macro_or_word(MACRO_PROT_ARGS, int parsed) static void blk_exp_close(MACRO_PROT_ARGS) { - struct mdoc_node *body; /* Our own body. */ - struct mdoc_node *endbody; /* Our own end marker. */ - struct mdoc_node *itblk; /* An It block starting later. */ - struct mdoc_node *later; /* A sub-block starting later. */ - struct mdoc_node *n; /* Search back to our block. */ + struct roff_node *body; /* Our own body. */ + struct roff_node *endbody; /* Our own end marker. */ + struct roff_node *itblk; /* An It block starting later. */ + struct roff_node *later; /* A sub-block starting later. */ + struct roff_node *n; /* Search back to our block. */ int j, lastarg, maxargs, nl; enum margserr ac; - enum mdoct atok, ntok; + int atok, ntok; char *p; nl = MDOC_NEWLINE & mdoc->flags; @@ -662,7 +660,7 @@ static void in_line(MACRO_PROT_ARGS) { int la, scope, cnt, firstarg, mayopen, nc, nl; - enum mdoct ntok; + int ntok; enum margserr ac; enum mdelim d; struct mdoc_arg *arg; @@ -846,10 +844,10 @@ blk_full(MACRO_PROT_ARGS) { int la, nl, parsed; struct mdoc_arg *arg; - struct mdoc_node *blk; /* Our own or a broken block. */ - struct mdoc_node *head; /* Our own head. */ - struct mdoc_node *body; /* Our own body. */ - struct mdoc_node *n; + struct roff_node *blk; /* Our own or a broken block. */ + struct roff_node *head; /* Our own head. */ + struct roff_node *body; /* Our own body. */ + struct roff_node *n; enum margserr ac, lac; char *p; @@ -1112,9 +1110,9 @@ blk_part_imp(MACRO_PROT_ARGS) int la, nl; enum margserr ac; char *p; - struct mdoc_node *blk; /* saved block context */ - struct mdoc_node *body; /* saved body context */ - struct mdoc_node *n; + struct roff_node *blk; /* saved block context */ + struct roff_node *body; /* saved body context */ + struct roff_node *n; nl = MDOC_NEWLINE & mdoc->flags; @@ -1205,7 +1203,7 @@ blk_part_exp(MACRO_PROT_ARGS) { int la, nl; enum margserr ac; - struct mdoc_node *head; /* keep track of head */ + struct roff_node *head; /* keep track of head */ char *p; nl = MDOC_NEWLINE & mdoc->flags; @@ -1262,7 +1260,7 @@ in_line_argn(MACRO_PROT_ARGS) struct mdoc_arg *arg; char *p; enum margserr ac; - enum mdoct ntok; + int ntok; int state; /* arg#; -1: not yet open; -2: closed */ int la, maxargs, nl; @@ -1376,7 +1374,7 @@ in_line_argn(MACRO_PROT_ARGS) static void in_line_eoln(MACRO_PROT_ARGS) { - struct mdoc_node *n; + struct roff_node *n; struct mdoc_arg *arg; if ((tok == MDOC_Pp || tok == MDOC_Lp) && @@ -1408,7 +1406,7 @@ in_line_eoln(MACRO_PROT_ARGS) * or until the next macro, call that macro, and return 1. */ static int -parse_rest(struct mdoc *mdoc, enum mdoct tok, int line, int *pos, char *buf) +parse_rest(struct mdoc *mdoc, int tok, int line, int *pos, char *buf) { int la; @@ -1443,7 +1441,7 @@ ctx_synopsis(MACRO_PROT_ARGS) static void phrase_ta(MACRO_PROT_ARGS) { - struct mdoc_node *body, *n; + struct roff_node *body, *n; /* Make sure we are in a column list or ignore this macro. */ diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index dec59817153..303f17a4fca 100644 --- a/usr.bin/mandoc/mdoc_man.c +++ b/usr.bin/mandoc/mdoc_man.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_man.c,v 1.87 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mdoc_man.c,v 1.88 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org> * @@ -28,7 +28,7 @@ #include "out.h" #include "main.h" -#define DECL_ARGS const struct mdoc_meta *meta, struct mdoc_node *n +#define DECL_ARGS const struct mdoc_meta *meta, struct roff_node *n struct manact { int (*cond)(DECL_ARGS); /* DON'T run actions */ @@ -106,7 +106,7 @@ static int pre_sm(DECL_ARGS); static int pre_sp(DECL_ARGS); static int pre_sect(DECL_ARGS); static int pre_sy(DECL_ARGS); -static void pre_syn(const struct mdoc_node *); +static void pre_syn(const struct roff_node *); static int pre_vt(DECL_ARGS); static int pre_ux(DECL_ARGS); static int pre_xr(DECL_ARGS); @@ -115,7 +115,7 @@ static void print_line(const char *, int); static void print_block(const char *, int); static void print_offs(const char *, int); static void print_width(const struct mdoc_bl *, - const struct mdoc_node *); + const struct roff_node *); static void print_count(int *); static void print_node(DECL_ARGS); @@ -466,7 +466,7 @@ print_offs(const char *v, int keywords) * Set up the indentation for a list item; used from pre_it(). */ static void -print_width(const struct mdoc_bl *bl, const struct mdoc_node *child) +print_width(const struct mdoc_bl *bl, const struct roff_node *child) { char buf[24]; struct roffsu su; @@ -546,7 +546,7 @@ void man_mdoc(void *arg, const struct mdoc *mdoc) { const struct mdoc_meta *meta; - struct mdoc_node *n; + struct roff_node *n; meta = mdoc_meta(mdoc); n = mdoc_node(mdoc)->child; @@ -576,7 +576,7 @@ static void print_node(DECL_ARGS) { const struct manact *act; - struct mdoc_node *sub; + struct roff_node *sub; int cond, do_sub; /* @@ -806,7 +806,7 @@ post_sect(DECL_ARGS) /* See mdoc_term.c, synopsis_pre() for comments. */ static void -pre_syn(const struct mdoc_node *n) +pre_syn(const struct roff_node *n) { if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags)) @@ -1364,7 +1364,7 @@ post_in(DECL_ARGS) static int pre_it(DECL_ARGS) { - const struct mdoc_node *bln; + const struct roff_node *bln; switch (n->type) { case ROFFT_HEAD: @@ -1461,7 +1461,7 @@ mid_it(void) static void post_it(DECL_ARGS) { - const struct mdoc_node *bln; + const struct roff_node *bln; bln = n->parent->parent; @@ -1531,7 +1531,7 @@ post_lb(DECL_ARGS) static int pre_lk(DECL_ARGS) { - const struct mdoc_node *link, *descr; + const struct roff_node *link, *descr; if (NULL == (link = n->child)) return(0); diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index adc3eb4e24c..3a1359d39c7 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_term.c,v 1.213 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.214 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -42,7 +42,7 @@ struct termpair { #define DECL_ARGS struct termp *p, \ struct termpair *pair, \ const struct mdoc_meta *meta, \ - struct mdoc_node *n + struct roff_node *n struct termact { int (*pre)(DECL_ARGS); @@ -52,14 +52,14 @@ struct termact { static int a2width(const struct termp *, const char *); static void print_bvspace(struct termp *, - const struct mdoc_node *, - const struct mdoc_node *); + const struct roff_node *, + const struct roff_node *); static void print_mdoc_node(DECL_ARGS); static void print_mdoc_nodelist(DECL_ARGS); static void print_mdoc_head(struct termp *, const void *); static void print_mdoc_foot(struct termp *, const void *); static void synopsis_pre(struct termp *, - const struct mdoc_node *); + const struct roff_node *); static void termp____post(DECL_ARGS); static void termp__t_post(DECL_ARGS); @@ -252,7 +252,7 @@ void terminal_mdoc(void *arg, const struct mdoc *mdoc) { const struct mdoc_meta *meta; - struct mdoc_node *n; + struct roff_node *n; struct termp *p; p = (struct termp *)arg; @@ -547,10 +547,10 @@ a2width(const struct termp *p, const char *v) */ static void print_bvspace(struct termp *p, - const struct mdoc_node *bl, - const struct mdoc_node *n) + const struct roff_node *bl, + const struct roff_node *n) { - const struct mdoc_node *nn; + const struct roff_node *nn; assert(n); @@ -608,7 +608,7 @@ static int termp_it_pre(DECL_ARGS) { char buf[24]; - const struct mdoc_node *bl, *nn; + const struct roff_node *bl, *nn; size_t ncols, dcol; int i, offset, width; enum mdoc_list type; @@ -1265,7 +1265,7 @@ termp_xr_pre(DECL_ARGS) * macro combos). */ static void -synopsis_pre(struct termp *p, const struct mdoc_node *n) +synopsis_pre(struct termp *p, const struct roff_node *n) { /* * Obviously, if we're not in a SYNOPSIS or no prior macros @@ -1513,7 +1513,7 @@ termp_fn_pre(DECL_ARGS) static int termp_fa_pre(DECL_ARGS) { - const struct mdoc_node *nn; + const struct roff_node *nn; if (n->parent->tok != MDOC_Fo) { term_fontpush(p, TERMFONT_UNDER); @@ -1539,7 +1539,7 @@ static int termp_bd_pre(DECL_ARGS) { size_t tabwidth, lm, len, rm, rmax; - struct mdoc_node *nn; + struct roff_node *nn; int offset; if (n->type == ROFFT_BLOCK) { @@ -2168,7 +2168,7 @@ termp_li_pre(DECL_ARGS) static int termp_lk_pre(DECL_ARGS) { - const struct mdoc_node *link, *descr; + const struct roff_node *link, *descr; if (NULL == (link = n->child)) return(0); diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 4408402dcb1..624ee0c6313 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_validate.c,v 1.200 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.201 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -38,7 +38,7 @@ /* FIXME: .Bl -diag can't have non-text children in HEAD. */ -#define PRE_ARGS struct mdoc *mdoc, struct mdoc_node *n +#define PRE_ARGS struct mdoc *mdoc, struct roff_node *n #define POST_ARGS struct mdoc *mdoc enum check_ineq { @@ -57,11 +57,11 @@ struct valids { static void check_text(struct mdoc *, int, int, char *); static void check_argv(struct mdoc *, - struct mdoc_node *, struct mdoc_argv *); -static void check_args(struct mdoc *, struct mdoc_node *); -static int child_an(const struct mdoc_node *); -static enum mdoc_sec a2sec(const char *); -static size_t macro2len(enum mdoct); + struct roff_node *, struct mdoc_argv *); +static void check_args(struct mdoc *, struct roff_node *); +static int child_an(const struct roff_node *); +static enum roff_sec a2sec(const char *); +static size_t macro2len(int); static void rewrite_macro2len(char **); static void post_an(POST_ARGS); @@ -246,7 +246,7 @@ static const struct valids mdoc_valids[MDOC_MAX] = { #define RSORD_MAX 14 /* Number of `Rs' blocks. */ -static const enum mdoct rsord[RSORD_MAX] = { +static const int rsord[RSORD_MAX] = { MDOC__A, MDOC__T, MDOC__B, @@ -291,7 +291,7 @@ static const char * const secnames[SEC__MAX] = { void -mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n) +mdoc_valid_pre(struct mdoc *mdoc, struct roff_node *n) { v_pre p; @@ -319,7 +319,7 @@ mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n) void mdoc_valid_post(struct mdoc *mdoc) { - struct mdoc_node *n; + struct roff_node *n; v_post p; n = mdoc->last; @@ -360,7 +360,7 @@ mdoc_valid_post(struct mdoc *mdoc) } static void -check_args(struct mdoc *mdoc, struct mdoc_node *n) +check_args(struct mdoc *mdoc, struct roff_node *n) { int i; @@ -373,7 +373,7 @@ check_args(struct mdoc *mdoc, struct mdoc_node *n) } static void -check_argv(struct mdoc *mdoc, struct mdoc_node *n, struct mdoc_argv *v) +check_argv(struct mdoc *mdoc, struct roff_node *n, struct mdoc_argv *v) { int i; @@ -397,7 +397,7 @@ check_text(struct mdoc *mdoc, int ln, int pos, char *p) static void pre_display(PRE_ARGS) { - struct mdoc_node *node; + struct roff_node *node; if (n->type != ROFFT_BLOCK) return; @@ -767,7 +767,7 @@ pre_dd(PRE_ARGS) static void post_bf(POST_ARGS) { - struct mdoc_node *np, *nch; + struct roff_node *np, *nch; enum mdocargt arg; /* @@ -829,7 +829,7 @@ post_bf(POST_ARGS) static void post_lb(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; char *libname; n = mdoc->last->child; @@ -842,7 +842,7 @@ post_lb(POST_ARGS) static void post_eoln(POST_ARGS) { - const struct mdoc_node *n; + const struct roff_node *n; n = mdoc->last; if (n->child) @@ -855,7 +855,7 @@ post_eoln(POST_ARGS) static void post_fname(POST_ARGS) { - const struct mdoc_node *n; + const struct roff_node *n; const char *cp; size_t pos; @@ -878,7 +878,7 @@ post_fn(POST_ARGS) static void post_fo(POST_ARGS) { - const struct mdoc_node *n; + const struct roff_node *n; n = mdoc->last; @@ -904,7 +904,7 @@ post_fo(POST_ARGS) static void post_fa(POST_ARGS) { - const struct mdoc_node *n; + const struct roff_node *n; const char *cp; for (n = mdoc->last->child; n != NULL; n = n->next) { @@ -925,7 +925,7 @@ post_fa(POST_ARGS) static void post_vt(POST_ARGS) { - const struct mdoc_node *n; + const struct roff_node *n; /* * The Vt macro comes in both ELEM and BLOCK form, both of which @@ -947,7 +947,7 @@ post_vt(POST_ARGS) static void post_nm(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; n = mdoc->last; @@ -969,7 +969,7 @@ post_nm(POST_ARGS) static void post_nd(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; n = mdoc->last; @@ -986,7 +986,7 @@ post_nd(POST_ARGS) static void post_d1(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; n = mdoc->last; @@ -1003,7 +1003,7 @@ post_d1(POST_ARGS) static void post_literal(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; n = mdoc->last; @@ -1025,7 +1025,7 @@ post_literal(POST_ARGS) static void post_defaults(POST_ARGS) { - struct mdoc_node *nn; + struct roff_node *nn; /* * The `Ar' defaults to "file ..." if no value is provided as an @@ -1059,7 +1059,7 @@ post_defaults(POST_ARGS) static void post_at(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; const char *std_att; char *att; @@ -1093,7 +1093,7 @@ post_at(POST_ARGS) static void post_an(POST_ARGS) { - struct mdoc_node *np, *nch; + struct roff_node *np, *nch; np = mdoc->last; nch = np->child; @@ -1124,9 +1124,9 @@ post_es(POST_ARGS) static void post_it(POST_ARGS) { + struct roff_node *nbl, *nit, *nch; int i, cols; enum mdoc_list lt; - struct mdoc_node *nbl, *nit, *nch; nit = mdoc->last; if (nit->type != ROFFT_BLOCK) @@ -1192,7 +1192,7 @@ post_it(POST_ARGS) static void post_bl_block(POST_ARGS) { - struct mdoc_node *n, *ni, *nc; + struct roff_node *n, *ni, *nc; /* * These are fairly complicated, so we've broken them into two @@ -1253,7 +1253,7 @@ void rewrite_macro2len(char **arg) { size_t width; - enum mdoct tok; + int tok; if (*arg == NULL) return; @@ -1271,7 +1271,7 @@ rewrite_macro2len(char **arg) static void post_bl_block_tag(POST_ARGS) { - struct mdoc_node *n, *nn; + struct roff_node *n, *nn; size_t sz, ssz; int i; char buf[24]; @@ -1336,7 +1336,7 @@ post_bl_block_tag(POST_ARGS) static void post_bl_head(POST_ARGS) { - struct mdoc_node *nbl, *nh, *nch, *nnext; + struct roff_node *nbl, *nh, *nch, *nnext; struct mdoc_argv *argv; int i, j; @@ -1398,9 +1398,9 @@ post_bl_head(POST_ARGS) static void post_bl(POST_ARGS) { - struct mdoc_node *nparent, *nprev; /* of the Bl block */ - struct mdoc_node *nblock, *nbody; /* of the Bl */ - struct mdoc_node *nchild, *nnext; /* of the Bl body */ + struct roff_node *nparent, *nprev; /* of the Bl block */ + struct roff_node *nblock, *nbody; /* of the Bl */ + struct roff_node *nchild, *nnext; /* of the Bl body */ nbody = mdoc->last; switch (nbody->type) { @@ -1481,7 +1481,7 @@ post_bl(POST_ARGS) static void post_bk(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; n = mdoc->last; @@ -1495,7 +1495,7 @@ post_bk(POST_ARGS) static void post_sm(struct mdoc *mdoc) { - struct mdoc_node *nch; + struct roff_node *nch; nch = mdoc->last->child; @@ -1525,7 +1525,7 @@ post_sm(struct mdoc *mdoc) static void post_root(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; /* Add missing prologue data. */ @@ -1565,7 +1565,7 @@ post_root(POST_ARGS) static void post_st(POST_ARGS) { - struct mdoc_node *n, *nch; + struct roff_node *n, *nch; const char *p; n = mdoc->last; @@ -1586,7 +1586,7 @@ post_st(POST_ARGS) static void post_rs(POST_ARGS) { - struct mdoc_node *np, *nch, *next, *prev; + struct roff_node *np, *nch, *next, *prev; int i, j; np = mdoc->last; @@ -1680,7 +1680,7 @@ post_rs(POST_ARGS) static void post_hyph(POST_ARGS) { - struct mdoc_node *nch; + struct roff_node *nch; char *cp; for (nch = mdoc->last->child; nch != NULL; nch = nch->next) { @@ -1739,7 +1739,7 @@ post_sh(POST_ARGS) static void post_sh_name(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; int hasnm, hasnd; hasnm = hasnd = 0; @@ -1777,7 +1777,7 @@ post_sh_name(POST_ARGS) static void post_sh_see_also(POST_ARGS) { - const struct mdoc_node *n; + const struct roff_node *n; const char *name, *sec; const char *lastname, *lastsec, *lastpunct; int cmp; @@ -1837,7 +1837,7 @@ post_sh_see_also(POST_ARGS) } static int -child_an(const struct mdoc_node *n) +child_an(const struct roff_node *n) { for (n = n->child; n != NULL; n = n->next) @@ -1858,10 +1858,10 @@ post_sh_authors(POST_ARGS) static void post_sh_head(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; const char *goodsec; char *secname; - enum mdoc_sec sec; + enum roff_sec sec; /* * Process a new section. Sections are either "named" or @@ -1978,7 +1978,7 @@ post_sh_head(POST_ARGS) static void post_ignpar(POST_ARGS) { - struct mdoc_node *np; + struct roff_node *np; switch (mdoc->last->type) { case ROFFT_HEAD: @@ -2044,7 +2044,7 @@ pre_par(PRE_ARGS) static void post_par(POST_ARGS) { - struct mdoc_node *np; + struct roff_node *np; np = mdoc->last; @@ -2107,7 +2107,7 @@ pre_literal(PRE_ARGS) static void post_dd(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; char *datestr; if (mdoc->meta.date) @@ -2136,7 +2136,7 @@ out: static void post_dt(POST_ARGS) { - struct mdoc_node *nn, *n; + struct roff_node *nn, *n; const char *cp; char *p; @@ -2221,7 +2221,7 @@ out: static void post_bx(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; /* * Make `Bx's second argument always start with an uppercase @@ -2241,7 +2241,7 @@ post_os(POST_ARGS) struct utsname utsname; static char *defbuf; #endif - struct mdoc_node *n; + struct roff_node *n; n = mdoc->last; @@ -2291,7 +2291,7 @@ out: static void post_ex(POST_ARGS) { - struct mdoc_node *n; + struct roff_node *n; n = mdoc->last; @@ -2309,20 +2309,20 @@ post_ex(POST_ARGS) mdoc->last = n; } -static enum mdoc_sec +static enum roff_sec a2sec(const char *p) { int i; for (i = 0; i < (int)SEC__MAX; i++) if (secnames[i] && 0 == strcmp(p, secnames[i])) - return((enum mdoc_sec)i); + return((enum roff_sec)i); return(SEC_CUSTOM); } static size_t -macro2len(enum mdoct macro) +macro2len(int macro) { switch (macro) { diff --git a/usr.bin/mandoc/roff.h b/usr.bin/mandoc/roff.h index 3105289fec8..a1ffea4b862 100644 --- a/usr.bin/mandoc/roff.h +++ b/usr.bin/mandoc/roff.h @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.h,v 1.10 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: roff.h,v 1.11 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -16,6 +16,36 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +struct mdoc_arg; +union mdoc_data; + +enum roff_sec { + SEC_NONE = 0, + SEC_NAME, + SEC_LIBRARY, + SEC_SYNOPSIS, + SEC_DESCRIPTION, + SEC_CONTEXT, + SEC_IMPLEMENTATION, /* IMPLEMENTATION NOTES */ + SEC_RETURN_VALUES, + SEC_ENVIRONMENT, + SEC_FILES, + SEC_EXIT_STATUS, + SEC_EXAMPLES, + SEC_DIAGNOSTICS, + SEC_COMPATIBILITY, + SEC_ERRORS, + SEC_SEE_ALSO, + SEC_STANDARDS, + SEC_HISTORY, + SEC_AUTHORS, + SEC_CAVEATS, + SEC_BUGS, + SEC_SECURITY, + SEC_CUSTOM, + SEC__MAX +}; + enum roff_type { ROFFT_ROOT, ROFFT_BLOCK, @@ -27,3 +57,50 @@ enum roff_type { ROFFT_TBL, ROFFT_EQN }; + +/* + * Indicates that a BODY's formatting has ended, but + * the scope is still open. Used for badly nested blocks. + */ +enum mdoc_endbody { + ENDBODY_NOT = 0, + ENDBODY_SPACE, /* Is broken: append a space. */ + ENDBODY_NOSPACE /* Is broken: don't append a space. */ +}; + +struct roff_node { + struct roff_node *parent; /* Parent AST node. */ + struct roff_node *child; /* First child AST node. */ + struct roff_node *last; /* Last child AST node. */ + struct roff_node *next; /* Sibling AST node. */ + struct roff_node *prev; /* Prior sibling AST node. */ + struct roff_node *head; /* BLOCK */ + struct roff_node *body; /* BLOCK/ENDBODY */ + struct roff_node *tail; /* BLOCK */ + struct mdoc_arg *args; /* BLOCK/ELEM */ + union mdoc_data *norm; /* Normalized arguments. */ + char *string; /* TEXT */ + const struct tbl_span *span; /* TBL */ + const struct eqn *eqn; /* EQN */ + int nchild; /* Number of child nodes. */ + int line; /* Input file line number. */ + int pos; /* Input file column number. */ + int tok; /* Request or macro ID. */ + int flags; +#define MDOC_VALID (1 << 0) /* Has been validated. */ +#define MDOC_ENDED (1 << 1) /* Gone past body end mark. */ +#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. */ +#define MDOC_BROKEN (1 << 5) /* Must validate parent when ending. */ +#define MDOC_DELIMO (1 << 6) +#define MDOC_DELIMC (1 << 7) +#define MAN_VALID MDOC_VALID +#define MAN_EOS MDOC_EOS +#define MAN_LINE MDOC_LINE + int prev_font; /* Before entering this node. */ + int aux; /* Decoded node data, type-dependent. */ + enum roff_type type; /* AST node type. */ + enum roff_sec sec; /* Current named section. */ + enum mdoc_endbody end; /* BODY */ +}; diff --git a/usr.bin/mandoc/tree.c b/usr.bin/mandoc/tree.c index 290b513b6f2..d833fe59f4e 100644 --- a/usr.bin/mandoc/tree.c +++ b/usr.bin/mandoc/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.30 2015/04/02 21:03:18 schwarze Exp $ */ +/* $OpenBSD: tree.c,v 1.31 2015/04/02 22:06:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -30,8 +30,8 @@ #include "main.h" static void print_box(const struct eqn_box *, int); -static void print_man(const struct man_node *, int); -static void print_mdoc(const struct mdoc_node *, int); +static void print_man(const struct roff_node *, int); +static void print_mdoc(const struct roff_node *, int); static void print_span(const struct tbl_span *, int); @@ -50,7 +50,7 @@ tree_man(void *arg, const struct man *man) } static void -print_mdoc(const struct mdoc_node *n, int indent) +print_mdoc(const struct roff_node *n, int indent) { const char *p, *t; int i, j; @@ -174,7 +174,7 @@ print_mdoc(const struct mdoc_node *n, int indent) } static void -print_man(const struct man_node *n, int indent) +print_man(const struct roff_node *n, int indent) { const char *p, *t; int i; |