xref: /freebsd/contrib/mandoc/tbl.h (revision 6d38604fc532a3fc060788e3ce40464b46047eaf)
1 /*	$Id: tbl.h,v 1.2 2021/08/10 12:55:04 schwarze Exp $ */
2 /*
3  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4  * Copyright (c) 2014,2015,2017,2018,2021 Ingo Schwarze <schwarze@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 struct	tbl_opts {
20 	int		  opts;
21 #define	TBL_OPT_ALLBOX	 (1 << 0)  /* Option "allbox". */
22 #define	TBL_OPT_BOX	 (1 << 1)  /* Option "box". */
23 #define	TBL_OPT_CENTRE	 (1 << 2)  /* Option "center". */
24 #define	TBL_OPT_DBOX	 (1 << 3)  /* Option "doublebox". */
25 #define	TBL_OPT_EXPAND	 (1 << 4)  /* Option "expand". */
26 #define	TBL_OPT_NOKEEP	 (1 << 5)  /* Option "nokeep". */
27 #define	TBL_OPT_NOSPACE	 (1 << 6)  /* Option "nospaces". */
28 #define	TBL_OPT_NOWARN	 (1 << 7)  /* Option "nowarn". */
29 	int		  cols;    /* Number of columns. */
30 	int		  lvert;   /* Width of left vertical line. */
31 	int		  rvert;   /* Width of right vertical line. */
32 	char		  tab;     /* Option "tab": cell separator. */
33 	char		  decimal; /* Option "decimalpoint". */
34 };
35 
36 enum	tbl_cellt {
37 	TBL_CELL_CENTRE,  /* c, C */
38 	TBL_CELL_RIGHT,   /* r, R */
39 	TBL_CELL_LEFT,    /* l, L */
40 	TBL_CELL_NUMBER,  /* n, N */
41 	TBL_CELL_SPAN,    /* s, S */
42 	TBL_CELL_LONG,    /* a, A */
43 	TBL_CELL_DOWN,    /* ^    */
44 	TBL_CELL_HORIZ,   /* _, - */
45 	TBL_CELL_DHORIZ,  /* =    */
46 	TBL_CELL_MAX
47 };
48 
49 /*
50  * A cell in a layout row.
51  */
52 struct	tbl_cell {
53 	struct tbl_cell	 *next;     /* Layout cell to the right. */
54 	char		 *wstr;     /* Min width represented as a string. */
55 	size_t		  width;    /* Minimum column width. */
56 	size_t		  spacing;  /* To the right of the column. */
57 	int		  vert;     /* Width of subsequent vertical line. */
58 	int		  col;      /* Column number, starting from 0. */
59 	int		  flags;
60 #define	TBL_CELL_TALIGN	 (1 << 2)   /* t, T */
61 #define	TBL_CELL_UP	 (1 << 3)   /* u, U */
62 #define	TBL_CELL_BALIGN	 (1 << 4)   /* d, D */
63 #define	TBL_CELL_WIGN	 (1 << 5)   /* z, Z */
64 #define	TBL_CELL_EQUAL	 (1 << 6)   /* e, E */
65 #define	TBL_CELL_WMAX	 (1 << 7)   /* x, X */
66 	enum mandoc_esc	  font;
67 	enum tbl_cellt	  pos;
68 };
69 
70 /*
71  * A layout row.
72  */
73 struct	tbl_row {
74 	struct tbl_row	 *next;   /* Layout row below. */
75 	struct tbl_cell	 *first;  /* Leftmost layout cell. */
76 	struct tbl_cell	 *last;   /* Rightmost layout cell. */
77 	int		  vert;   /* Width of left vertical line. */
78 };
79 
80 enum	tbl_datt {
81 	TBL_DATA_NONE,    /* Uninitialized row. */
82 	TBL_DATA_DATA,    /* Contains data rather than a line. */
83 	TBL_DATA_HORIZ,   /* _: connecting horizontal line. */
84 	TBL_DATA_DHORIZ,  /* =: connecting double horizontal line. */
85 	TBL_DATA_NHORIZ,  /* \_: isolated horizontal line. */
86 	TBL_DATA_NDHORIZ  /* \=: isolated double horizontal line. */
87 };
88 
89 /*
90  * A cell within a row of data.  The "string" field contains the
91  * actual string value that's in the cell.  The rest is layout.
92  */
93 struct	tbl_dat {
94 	struct tbl_dat	 *next;    /* Data cell to the right. */
95 	struct tbl_cell	 *layout;  /* Associated layout cell. */
96 	char		 *string;  /* Data, or NULL if not TBL_DATA_DATA. */
97 	int		  hspans;  /* How many horizontal spans follow. */
98 	int		  vspans;  /* How many vertical spans follow. */
99 	int		  block;   /* T{ text block T} */
100 	enum tbl_datt	  pos;
101 };
102 
103 enum	tbl_spant {
104 	TBL_SPAN_DATA,   /* Contains data rather than a line. */
105 	TBL_SPAN_HORIZ,  /* _: horizontal line. */
106 	TBL_SPAN_DHORIZ  /* =: double horizontal line. */
107 };
108 
109 /*
110  * A row of data in a table.
111  */
112 struct	tbl_span {
113 	struct tbl_opts	 *opts;    /* Options for the table as a whole. */
114 	struct tbl_span	 *prev;    /* Data row above. */
115 	struct tbl_span	 *next;    /* Data row below. */
116 	struct tbl_row	 *layout;  /* Associated layout row. */
117 	struct tbl_dat	 *first;   /* Leftmost data cell. */
118 	struct tbl_dat	 *last;    /* Rightmost data cell. */
119 	int		  line;    /* Input file line number. */
120 	enum tbl_spant	  pos;
121 };
122