Annotation of src/usr.bin/mandoc/tbl_extern.h, Revision 1.3
1.3 ! schwarze 1: /* $Id: tbl_extern.h,v 1.2 2010/10/15 21:33:47 schwarze Exp $ */
1.1 schwarze 2: /*
3: * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
17: #ifndef TBL_EXTERN_H
18: #define TBL_EXTERN_H
19:
20: enum tbl_err {
21: ERR_SYNTAX,
22: ERR_OPTION,
23: ERR_MAX
24: };
25:
26: enum tbl_tok {
27: TBL_TOK_WORD,
28: TBL_TOK_OPENPAREN,
29: TBL_TOK_CLOSEPAREN,
30: TBL_TOK_COMMA,
31: TBL_TOK_SEMICOLON,
32: TBL_TOK_PERIOD,
33: TBL_TOK_SPACE,
34: TBL_TOK_TAB,
35: TBL_TOK_NIL
36: };
37:
38: enum tbl_part {
39: TBL_PART_OPTS,
40: TBL_PART_LAYOUT,
41: TBL_PART_CLAYOUT,
42: TBL_PART_DATA,
43: TBL_PART_ERROR
44: };
45:
46: struct tbl;
47: struct tbl_head;
48: struct tbl_row;
49: struct tbl_cell;
50: struct tbl_span;
51: struct tbl_data;
52:
53: TAILQ_HEAD(tbl_rowh, tbl_row);
54: TAILQ_HEAD(tbl_cellh, tbl_cell);
55: TAILQ_HEAD(tbl_headh, tbl_head);
56: TAILQ_HEAD(tbl_spanh, tbl_span);
57: TAILQ_HEAD(tbl_datah, tbl_data);
58:
59: struct tbl {
60: enum tbl_part part;
61: int opts;
62: #define TBL_OPT_CENTRE (1 << 0)
63: #define TBL_OPT_EXPAND (1 << 1)
64: #define TBL_OPT_BOX (1 << 2)
65: #define TBL_OPT_DBOX (1 << 3)
66: #define TBL_OPT_ALLBOX (1 << 4)
67: #define TBL_OPT_NOKEEP (1 << 5)
68: #define TBL_OPT_NOSPACE (1 << 6)
69: char tab;
70: char decimal;
71: int linesize;
72: char delims[2];
73: struct tbl_spanh span;
74: struct tbl_headh head;
75: struct tbl_rowh row;
76: };
77:
78: enum tbl_headt {
79: TBL_HEAD_DATA,
80: TBL_HEAD_VERT,
81: TBL_HEAD_DVERT,
82: TBL_HEAD_MAX
83: };
84:
85: struct tbl_head {
86: struct tbl *tbl;
87: enum tbl_headt pos;
88: int width;
89: int decimal;
90: TAILQ_ENTRY(tbl_head) entries;
91: };
92:
93: struct tbl_row {
94: struct tbl *tbl;
95: struct tbl_cellh cell;
96: TAILQ_ENTRY(tbl_row) entries;
97: };
98:
99: enum tbl_cellt {
100: TBL_CELL_CENTRE, /* c, C */
101: TBL_CELL_RIGHT, /* r, R */
102: TBL_CELL_LEFT, /* l, L */
103: TBL_CELL_NUMBER, /* n, N */
104: TBL_CELL_SPAN, /* s, S */
105: TBL_CELL_LONG, /* a, A */
106: TBL_CELL_DOWN, /* ^ */
107: TBL_CELL_HORIZ, /* _, - */
108: TBL_CELL_DHORIZ, /* = */
109: TBL_CELL_VERT, /* | */
110: TBL_CELL_DVERT, /* || */
111: TBL_CELL_MAX
112: };
113:
114: struct tbl_cell {
115: struct tbl_row *row;
116: struct tbl_head *head;
117: enum tbl_cellt pos;
118: int spacing;
119: int flags;
120: #define TBL_CELL_TALIGN (1 << 0) /* t, T */
121: #define TBL_CELL_BALIGN (1 << 1) /* d, D */
122: #define TBL_CELL_BOLD (1 << 2) /* fB, B, b */
123: #define TBL_CELL_ITALIC (1 << 3) /* fI, I, i */
124: #define TBL_CELL_EQUAL (1 << 4) /* e, E */
125: #define TBL_CELL_UP (1 << 5) /* u, U */
126: #define TBL_CELL_WIGN (1 << 6) /* z, Z */
127: TAILQ_ENTRY(tbl_cell) entries;
128: };
129:
130: struct tbl_data {
131: struct tbl_span *span;
132: struct tbl_cell *cell;
133: int flags;
134: #define TBL_DATA_HORIZ (1 << 0)
135: #define TBL_DATA_DHORIZ (1 << 1)
136: #define TBL_DATA_NHORIZ (1 << 2)
137: #define TBL_DATA_NDHORIZ (1 << 3)
138: char *string;
139: TAILQ_ENTRY(tbl_data) entries;
140: };
141:
142: struct tbl_span {
143: struct tbl_row *row;
144: struct tbl *tbl;
145: int flags;
146: #define TBL_SPAN_HORIZ (1 << 0)
147: #define TBL_SPAN_DHORIZ (1 << 1)
148: struct tbl_datah data;
149: TAILQ_ENTRY(tbl_span) entries;
150: };
151:
152: __BEGIN_DECLS
153:
154: int tbl_option(struct tbl *,
155: const char *, int, const char *);
156: int tbl_layout(struct tbl *,
157: const char *, int, const char *);
158: int tbl_data(struct tbl *,
159: const char *, int, const char *);
160: int tbl_data_close(struct tbl *, const char *, int);
161:
162: enum tbl_tok tbl_next(const char *, int *);
163: const char *tbl_last(void);
164: int tbl_last_uint(void);
165: int tbl_errx(struct tbl *, enum tbl_err,
166: const char *, int, int);
167: int tbl_warnx(struct tbl *, enum tbl_err,
168: const char *, int, int);
169: int tbl_err(struct tbl *);
170:
171: struct tbl_row *tbl_row_alloc(struct tbl *);
172: struct tbl_cell *tbl_cell_alloc(struct tbl_row *, enum tbl_cellt);
173: struct tbl_span *tbl_span_alloc(struct tbl *);
174: struct tbl_data *tbl_data_alloc(struct tbl_span *);
175:
1.2 schwarze 176: int tbl_write_term(struct termp *, const struct tbl *);
1.3 ! schwarze 177: int tbl_calc_term(struct termp *, struct tbl *);
1.1 schwarze 178: int tbl_write_tree(const struct tbl *);
179: int tbl_calc_tree(struct tbl *);
180:
181: __END_DECLS
182:
183: #endif /*TBL_EXTERN_H*/