summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/tbl_extern.h
blob: 1c73041c92ba5b26649eeb03c37bc71959fc1d15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*	$Id: tbl_extern.h,v 1.3 2010/10/15 22:07:12 schwarze Exp $ */
/*
 * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
 *
 * 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
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
 */
#ifndef TBL_EXTERN_H
#define TBL_EXTERN_H

enum	tbl_err {
	ERR_SYNTAX,
	ERR_OPTION,
	ERR_MAX
};

enum	tbl_tok {
	TBL_TOK_WORD,
	TBL_TOK_OPENPAREN,
	TBL_TOK_CLOSEPAREN,
	TBL_TOK_COMMA,
	TBL_TOK_SEMICOLON,
	TBL_TOK_PERIOD,
	TBL_TOK_SPACE,
	TBL_TOK_TAB,
	TBL_TOK_NIL
};

enum	tbl_part {
	TBL_PART_OPTS,
	TBL_PART_LAYOUT,
	TBL_PART_CLAYOUT,
	TBL_PART_DATA,
	TBL_PART_ERROR
};

struct	tbl;
struct	tbl_head;
struct	tbl_row;
struct	tbl_cell;
struct	tbl_span;
struct	tbl_data;

TAILQ_HEAD(tbl_rowh, tbl_row);
TAILQ_HEAD(tbl_cellh, tbl_cell);
TAILQ_HEAD(tbl_headh, tbl_head);
TAILQ_HEAD(tbl_spanh, tbl_span);
TAILQ_HEAD(tbl_datah, tbl_data);

struct	tbl {
	enum tbl_part	 	 part;
	int		 	 opts;
#define	TBL_OPT_CENTRE		(1 << 0)
#define	TBL_OPT_EXPAND		(1 << 1)
#define	TBL_OPT_BOX		(1 << 2)
#define	TBL_OPT_DBOX		(1 << 3)
#define	TBL_OPT_ALLBOX		(1 << 4)
#define	TBL_OPT_NOKEEP		(1 << 5)
#define	TBL_OPT_NOSPACE		(1 << 6)
	char		 	 tab;
	char		 	 decimal;
	int		 	 linesize;
	char		 	 delims[2];
	struct tbl_spanh	 span;
	struct tbl_headh	 head;
	struct tbl_rowh		 row;
};

enum	tbl_headt {
	TBL_HEAD_DATA,
	TBL_HEAD_VERT,
	TBL_HEAD_DVERT,
	TBL_HEAD_MAX
};

struct	tbl_head {
	struct tbl		*tbl;
	enum tbl_headt	 	 pos;
	int			 width;
	int			 decimal;
	TAILQ_ENTRY(tbl_head)	 entries;
};

struct	tbl_row {
	struct tbl		*tbl;
	struct tbl_cellh	 cell;
	TAILQ_ENTRY(tbl_row)	 entries;
};

enum	tbl_cellt {
	TBL_CELL_CENTRE,	/* c, C */
	TBL_CELL_RIGHT,		/* r, R */
	TBL_CELL_LEFT,		/* l, L */
	TBL_CELL_NUMBER,	/* n, N */
	TBL_CELL_SPAN,		/* s, S */
	TBL_CELL_LONG,		/* a, A */
	TBL_CELL_DOWN,		/* ^ */
	TBL_CELL_HORIZ,		/* _, - */
	TBL_CELL_DHORIZ,	/* = */
	TBL_CELL_VERT,		/* | */
	TBL_CELL_DVERT,		/* || */
	TBL_CELL_MAX
};

struct	tbl_cell {
	struct tbl_row		*row;
	struct tbl_head		*head;
	enum tbl_cellt	 	 pos;
	int		  	 spacing;
	int		 	 flags;
#define	TBL_CELL_TALIGN		(1 << 0)	/* t, T */
#define	TBL_CELL_BALIGN		(1 << 1)	/* d, D */
#define	TBL_CELL_BOLD		(1 << 2)	/* fB, B, b */
#define	TBL_CELL_ITALIC		(1 << 3)	/* fI, I, i */
#define	TBL_CELL_EQUAL		(1 << 4)	/* e, E */
#define	TBL_CELL_UP		(1 << 5)	/* u, U */
#define	TBL_CELL_WIGN		(1 << 6)	/* z, Z */
	TAILQ_ENTRY(tbl_cell)	 entries;
};

struct	tbl_data {
	struct tbl_span		*span;
	struct tbl_cell		*cell;
	int		 	 flags;
#define	TBL_DATA_HORIZ		(1 << 0)
#define	TBL_DATA_DHORIZ		(1 << 1)
#define	TBL_DATA_NHORIZ		(1 << 2)
#define	TBL_DATA_NDHORIZ 	(1 << 3)
	char			*string;
	TAILQ_ENTRY(tbl_data)	 entries;
};

struct	tbl_span {
	struct tbl_row		*row;
	struct tbl		*tbl;
	int		 	 flags;
#define	TBL_SPAN_HORIZ		(1 << 0)
#define	TBL_SPAN_DHORIZ		(1 << 1)
	struct tbl_datah	 data;
	TAILQ_ENTRY(tbl_span)	 entries;
};

__BEGIN_DECLS

int	 	 tbl_option(struct tbl *, 
			const char *, int, const char *);
int	 	 tbl_layout(struct tbl *, 
			const char *, int, const char *);
int	 	 tbl_data(struct tbl *, 
			const char *, int, const char *);
int		 tbl_data_close(struct tbl *,  const char *, int);

enum tbl_tok	 tbl_next(const char *, int *);
const char	*tbl_last(void);
int		 tbl_last_uint(void);
int		 tbl_errx(struct tbl *, enum tbl_err, 
			const char *, int, int);
int		 tbl_warnx(struct tbl *, enum tbl_err, 
			const char *, int, int);
int		 tbl_err(struct tbl *);

struct tbl_row	*tbl_row_alloc(struct tbl *);
struct tbl_cell	*tbl_cell_alloc(struct tbl_row *, enum tbl_cellt);
struct tbl_span	*tbl_span_alloc(struct tbl *);
struct tbl_data	*tbl_data_alloc(struct tbl_span *);

int		 tbl_write_term(struct termp *, const struct tbl *);
int		 tbl_calc_term(struct termp *, struct tbl *);
int		 tbl_write_tree(const struct tbl *);
int		 tbl_calc_tree(struct tbl *);

__END_DECLS

#endif /*TBL_EXTERN_H*/