diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-12-13 05:13:16 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-12-13 05:13:16 +0000 |
commit | 1789e8ed4cf7e787cf02a57f980465dad6edf2b9 (patch) | |
tree | d12df24dd8f8bfa7daaceae15e1b73b72e27b2d9 | |
parent | 644676265aa660ec7fc96c007fa1ae698b0a78e0 (diff) |
Cleanup, no functional change:
No need to expose the eqn(7) syntax tree data structures everywhere.
Move them to their own include file, "eqn.h".
While here, delete the unused enum eqn_pilet.
-rw-r--r-- | usr.bin/mandoc/eqn.c | 18 | ||||
-rw-r--r-- | usr.bin/mandoc/eqn.h | 72 | ||||
-rw-r--r-- | usr.bin/mandoc/eqn_html.c | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/eqn_parse.h | 5 | ||||
-rw-r--r-- | usr.bin/mandoc/eqn_term.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.h | 70 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.c | 5 | ||||
-rw-r--r-- | usr.bin/mandoc/tree.c | 3 |
8 files changed, 98 insertions, 82 deletions
diff --git a/usr.bin/mandoc/eqn.c b/usr.bin/mandoc/eqn.c index cf7b3b8121b..3bb0c680e6c 100644 --- a/usr.bin/mandoc/eqn.c +++ b/usr.bin/mandoc/eqn.c @@ -1,7 +1,7 @@ -/* $OpenBSD: eqn.c,v 1.43 2018/12/13 03:40:09 schwarze Exp $ */ +/* $OpenBSD: eqn.c,v 1.44 2018/12/13 05:13:15 schwarze Exp $ */ /* * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2014, 2015, 2017, 2018 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 @@ -28,6 +28,7 @@ #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" +#include "eqn.h" #include "libmandoc.h" #include "eqn_parse.h" @@ -489,6 +490,16 @@ eqn_box_free(struct eqn_box *bp) free(bp); } +struct eqn_box * +eqn_box_new(void) +{ + struct eqn_box *bp; + + bp = mandoc_calloc(1, sizeof(*bp)); + bp->expectargs = UINT_MAX; + return bp; +} + /* * Allocate a box as the last child of the parent node. */ @@ -497,10 +508,9 @@ eqn_box_alloc(struct eqn_node *ep, struct eqn_box *parent) { struct eqn_box *bp; - bp = mandoc_calloc(1, sizeof(struct eqn_box)); + bp = eqn_box_new(); bp->parent = parent; bp->parent->args++; - bp->expectargs = UINT_MAX; bp->font = bp->parent->font; bp->size = ep->gsize; diff --git a/usr.bin/mandoc/eqn.h b/usr.bin/mandoc/eqn.h new file mode 100644 index 00000000000..0eff4a4fb11 --- /dev/null +++ b/usr.bin/mandoc/eqn.h @@ -0,0 +1,72 @@ +/* $OpenBSD: eqn.h,v 1.1 2018/12/13 05:13:15 schwarze Exp $ */ +/* + * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> + * + * 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 AUTHORS DISCLAIM ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * 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. + * + * Public data types for eqn(7) syntax trees. + */ + +enum eqn_boxt { + EQN_TEXT, /* Text, e.g. number, variable, operator, ... */ + EQN_SUBEXPR, /* Nested eqn(7) subexpression. */ + EQN_LIST, /* List, for example in braces. */ + EQN_PILE, /* Vertical pile. */ + EQN_MATRIX /* List of columns. */ +}; + +enum eqn_fontt { + EQNFONT_NONE = 0, + EQNFONT_ROMAN, + EQNFONT_BOLD, + EQNFONT_FAT, + EQNFONT_ITALIC, + EQNFONT__MAX +}; + +enum eqn_post { + EQNPOS_NONE = 0, + EQNPOS_SUP, + EQNPOS_SUBSUP, + EQNPOS_SUB, + EQNPOS_TO, + EQNPOS_FROM, + EQNPOS_FROMTO, + EQNPOS_OVER, + EQNPOS_SQRT, + EQNPOS__MAX +}; + + /* + * A "box" is a parsed mathematical expression as defined by the eqn.7 + * grammar. + */ +struct eqn_box { + struct eqn_box *parent; + struct eqn_box *prev; + struct eqn_box *next; + struct eqn_box *first; /* First child node. */ + struct eqn_box *last; /* Last child node. */ + char *text; /* Text (or NULL). */ + char *left; /* Left-hand fence. */ + char *right; /* Right-hand fence. */ + char *top; /* Symbol above. */ + char *bottom; /* Symbol below. */ + size_t expectargs; /* Maximal number of arguments. */ + size_t args; /* Actual number of arguments. */ + int size; /* Font size. */ +#define EQN_DEFSIZE INT_MIN + enum eqn_boxt type; /* Type of node. */ + enum eqn_fontt font; /* Font in this box. */ + enum eqn_post pos; /* Position of the next box. */ +}; diff --git a/usr.bin/mandoc/eqn_html.c b/usr.bin/mandoc/eqn_html.c index a0d3ecb0296..60a894c44e4 100644 --- a/usr.bin/mandoc/eqn_html.c +++ b/usr.bin/mandoc/eqn_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eqn_html.c,v 1.13 2017/07/14 13:32:27 schwarze Exp $ */ +/* $OpenBSD: eqn_html.c,v 1.14 2018/12/13 05:13:15 schwarze Exp $ */ /* * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -24,6 +24,7 @@ #include <string.h> #include "mandoc.h" +#include "eqn.h" #include "out.h" #include "html.h" diff --git a/usr.bin/mandoc/eqn_parse.h b/usr.bin/mandoc/eqn_parse.h index b829ca25be9..b935bc53645 100644 --- a/usr.bin/mandoc/eqn_parse.h +++ b/usr.bin/mandoc/eqn_parse.h @@ -1,7 +1,7 @@ -/* $OpenBSD: eqn_parse.h,v 1.1 2018/12/13 03:40:09 schwarze Exp $ */ +/* $OpenBSD: eqn_parse.h,v 1.2 2018/12/13 05:13:15 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2014, 2017 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2014, 2017, 2018 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 @@ -42,6 +42,7 @@ struct eqn_node { struct eqn_node *eqn_alloc(struct mparse *); +struct eqn_box *eqn_box_new(void); void eqn_box_free(struct eqn_box *); void eqn_free(struct eqn_node *); void eqn_parse(struct eqn_node *); diff --git a/usr.bin/mandoc/eqn_term.c b/usr.bin/mandoc/eqn_term.c index 9cbd2a5f159..7bb1aae4435 100644 --- a/usr.bin/mandoc/eqn_term.c +++ b/usr.bin/mandoc/eqn_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eqn_term.c,v 1.14 2018/10/02 12:14:44 schwarze Exp $ */ +/* $OpenBSD: eqn_term.c,v 1.15 2018/12/13 05:13:15 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -23,7 +23,7 @@ #include <stdlib.h> #include <string.h> -#include "mandoc.h" +#include "eqn.h" #include "out.h" #include "term.h" diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 056f53765ca..24e4c0336f7 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.198 2018/12/12 21:54:30 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.199 2018/12/13 05:13:15 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org> @@ -241,74 +241,6 @@ enum mandocerr { MANDOCERR_MAX }; -enum eqn_boxt { - EQN_TEXT, /* text (number, variable, whatever) */ - EQN_SUBEXPR, /* nested `eqn' subexpression */ - EQN_LIST, /* list (braces, etc.) */ - EQN_PILE, /* vertical pile */ - EQN_MATRIX /* pile of piles */ -}; - -enum eqn_fontt { - EQNFONT_NONE = 0, - EQNFONT_ROMAN, - EQNFONT_BOLD, - EQNFONT_FAT, - EQNFONT_ITALIC, - EQNFONT__MAX -}; - -enum eqn_post { - EQNPOS_NONE = 0, - EQNPOS_SUP, - EQNPOS_SUBSUP, - EQNPOS_SUB, - EQNPOS_TO, - EQNPOS_FROM, - EQNPOS_FROMTO, - EQNPOS_OVER, - EQNPOS_SQRT, - EQNPOS__MAX -}; - -enum eqn_pilet { - EQNPILE_NONE = 0, - EQNPILE_PILE, - EQNPILE_CPILE, - EQNPILE_RPILE, - EQNPILE_LPILE, - EQNPILE_COL, - EQNPILE_CCOL, - EQNPILE_RCOL, - EQNPILE_LCOL, - EQNPILE__MAX -}; - - /* - * A "box" is a parsed mathematical expression as defined by the eqn.7 - * grammar. - */ -struct eqn_box { - int size; /* font size of expression */ -#define EQN_DEFSIZE INT_MIN - enum eqn_boxt type; /* type of node */ - struct eqn_box *first; /* first child node */ - struct eqn_box *last; /* last child node */ - struct eqn_box *next; /* node sibling */ - struct eqn_box *prev; /* node sibling */ - struct eqn_box *parent; /* node sibling */ - char *text; /* text (or NULL) */ - char *left; /* fence left-hand */ - char *right; /* fence right-hand */ - char *top; /* expression over-symbol */ - char *bottom; /* expression under-symbol */ - size_t args; /* arguments in parent */ - size_t expectargs; /* max arguments in parent */ - enum eqn_post pos; /* position of next box */ - enum eqn_fontt font; /* font of box */ - enum eqn_pilet pile; /* equation piling */ -}; - /* * Parse options. */ diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index a1767789ecc..037cf99192b 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.219 2018/12/13 03:40:09 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.220 2018/12/13 05:13:15 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> @@ -3151,8 +3151,7 @@ roff_EQ(ROFF_ARGS) n = roff_node_alloc(r->man, ln, ppos, ROFFT_EQN, TOKEN_NONE); if (ln > r->man->last->line) n->flags |= NODE_LINE; - n->eqn = mandoc_calloc(1, sizeof(*n->eqn)); - n->eqn->expectargs = UINT_MAX; + n->eqn = eqn_box_new(); roff_node_append(r->man, n); r->man->next = ROFF_NEXT_SIBLING; diff --git a/usr.bin/mandoc/tree.c b/usr.bin/mandoc/tree.c index 2a15b94c58b..bab922bf5a7 100644 --- a/usr.bin/mandoc/tree.c +++ b/usr.bin/mandoc/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.48 2018/12/12 21:54:30 schwarze Exp $ */ +/* $OpenBSD: tree.c,v 1.49 2018/12/13 05:13:15 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org> @@ -28,6 +28,7 @@ #include "mdoc.h" #include "man.h" #include "tbl.h" +#include "eqn.h" #include "main.h" static void print_box(const struct eqn_box *, int); |