xref: /dragonfly/contrib/mdocml/tbl.h (revision ed183f8c)
1 /*	$Id: tbl.h,v 1.1 2018/12/12 21:54:35 schwarze Exp $ */
2 /*
3  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4  * Copyright (c) 2014, 2015, 2017, 2018 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_BOLD	 (1 << 0)   /* b, B, fB */
61 #define	TBL_CELL_ITALIC	 (1 << 1)   /* i, I, fI */
62 #define	TBL_CELL_TALIGN	 (1 << 2)   /* t, T */
63 #define	TBL_CELL_UP	 (1 << 3)   /* u, U */
64 #define	TBL_CELL_BALIGN	 (1 << 4)   /* d, D */
65 #define	TBL_CELL_WIGN	 (1 << 5)   /* z, Z */
66 #define	TBL_CELL_EQUAL	 (1 << 6)   /* e, E */
67 #define	TBL_CELL_WMAX	 (1 << 7)   /* x, X */
68 	enum tbl_cellt	  pos;
69 };
70 
71 /*
72  * A layout row.
73  */
74 struct	tbl_row {
75 	struct tbl_row	 *next;   /* Layout row below. */
76 	struct tbl_cell	 *first;  /* Leftmost layout cell. */
77 	struct tbl_cell	 *last;   /* Rightmost layout cell. */
78 	int		  vert;   /* Width of left vertical line. */
79 };
80 
81 enum	tbl_datt {
82 	TBL_DATA_NONE,    /* Uninitialized row. */
83 	TBL_DATA_DATA,    /* Contains data rather than a line. */
84 	TBL_DATA_HORIZ,   /* _: connecting horizontal line. */
85 	TBL_DATA_DHORIZ,  /* =: connecting double horizontal line. */
86 	TBL_DATA_NHORIZ,  /* \_: isolated horizontal line. */
87 	TBL_DATA_NDHORIZ  /* \=: isolated double horizontal line. */
88 };
89 
90 /*
91  * A cell within a row of data.  The "string" field contains the
92  * actual string value that's in the cell.  The rest is layout.
93  */
94 struct	tbl_dat {
95 	struct tbl_dat	 *next;    /* Data cell to the right. */
96 	struct tbl_cell	 *layout;  /* Associated layout cell. */
97 	char		 *string;  /* Data, or NULL if not TBL_DATA_DATA. */
98 	int		  hspans;  /* How many horizontal spans follow. */
99 	int		  vspans;  /* How many vertical spans follow. */
100 	int		  block;   /* T{ text block T} */
101 	enum tbl_datt	  pos;
102 };
103 
104 enum	tbl_spant {
105 	TBL_SPAN_DATA,   /* Contains data rather than a line. */
106 	TBL_SPAN_HORIZ,  /* _: horizontal line. */
107 	TBL_SPAN_DHORIZ  /* =: double horizontal line. */
108 };
109 
110 /*
111  * A row of data in a table.
112  */
113 struct	tbl_span {
114 	struct tbl_opts	 *opts;    /* Options for the table as a whole. */
115 	struct tbl_span	 *prev;    /* Data row above. */
116 	struct tbl_span	 *next;    /* Data row below. */
117 	struct tbl_row	 *layout;  /* Associated layout row. */
118 	struct tbl_dat	 *first;   /* Leftmost data cell. */
119 	struct tbl_dat	 *last;    /* Rightmost data cell. */
120 	int		  line;    /* Input file line number. */
121 	enum tbl_spant	  pos;
122 };
123