File: tbl.3

package info (click to toggle)
mdocml 1.14.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,096 kB
  • sloc: ansic: 34,421; makefile: 994; sh: 461; perl: 374
file content (354 lines) | stat: -rw-r--r-- 7,107 bytes parent folder | download | duplicates (3)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
.\"	$Id: tbl.3,v 1.2 2015/01/30 04:11:50 schwarze Exp $
.\"
.\" Copyright (c) 2013 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
.\" 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.
.\"
.Dd $Mdocdate: January 30 2015 $
.Dt TBL 3
.Os
.Sh NAME
.Nm tbl_alloc ,
.Nm tbl_read ,
.Nm tbl_restart ,
.Nm tbl_span ,
.Nm tbl_end ,
.Nm tbl_free
.Nd roff table parser library for mandoc
.Sh SYNOPSIS
.In mandoc.h
.In libmandoc.h
.In libroff.h
.Ft struct tbl_node *
.Fo tbl_alloc
.Fa "int pos"
.Fa "int line"
.Fa "struct mparse *parse"
.Fc
.Ft enum rofferr
.Fo tbl_read
.Fa "struct tbl_node *tbl"
.Fa "int ln"
.Fa "const char *p"
.Fa "int offs"
.Fc
.Ft void
.Fo tbl_restart
.Fa "int line"
.Fa "int pos"
.Fa "struct tbl_node *tbl"
.Fc
.Ft const struct tbl_span *
.Fo tbl_span
.Fa "struct tbl_node *tbl"
.Fc
.Ft void
.Fo tbl_end
.Fa "struct tbl_node **tblp"
.Fc
.Ft void
.Fo tbl_free
.Fa "struct tbl_node *tbl"
.Fc
.Sh DESCRIPTION
This library is tightly integrated into the
.Xr mandoc 1
utility and not designed for stand-alone use.
The present manual is intended as a reference for developers working on
.Xr mandoc 1 .
.Ss Data structures
Unless otherwise noted, all of the following data structures are defined in
.In mandoc.h
and are deleted in
.Fn tbl_free .
.Bl -tag -width Ds
.It Vt struct tbl_node
This structure describes a complete table.
It is defined in
.In libroff.h ,
created in
.Fn tbl_alloc ,
and stored in the members
.Fa first_tbl ,
.Fa last_tbl ,
and
.Fa tbl
of
.Vt struct roff Bq Pa roff.c .
.Pp
The
.Fa first_span ,
.Fa current_span ,
.Fa last_span ,
and
.Fa next
members may be
.Dv NULL .
The
.Fa first_row
and
.Fa last_row
members may be
.Dv NULL ,
but if there is a span, the function
.Fn tbl_layout
guarantees that these pointers are not
.Dv NULL .
The function
.Fn tbl_alloc
guarantees that the
.Fa parse
member is not
.Dv NULL .
.It Vt struct tbl_opts
This structure describes the options of one table.
It is used as a substructure of
.Vt struct tbl_node
and thus created and deleted together with it.
It is filled in
.Fn tbl_options .
.It Vt struct tbl_row
This structure describes one layout line in a table
by maintaining a list of all the cells in that line.
It is allocated and filled in
.Fn row Bq Pa tbl_layout.c
and referenced from the
.Fa layout
member of
.Vt struct tbl_node .
.Pp
The
.Fa next
member may be
.Dv NULL .
The function
.Fn tbl_layout
guarantees that the
.Fa first
and
.Fa last
members are not NULL.
.It Vt struct tbl_cell
This structure describes one layout cell in a table,
in particular its alignment, membership in spans, and
usage for lines.
It is allocated and filled in
.Fn cell_alloc Bq Pa tbl_layout.c
and referenced from the
.Fa first
and
.Fa last
members of
.Vt struct tbl_row .
.Pp
The
.Fa next
member may be
.Dv NULL .
.It Vt struct tbl_span
This structure describes one data line in a table
by maintaining a list of all data cells in that line
or by specifying that it is a horizontal line.
It is allocated and filled in
.Fn newspan Bq Pa tbl_data.c
which is called from
.Fn tbl_data
and referenced from the
.Fa first_span ,
.Fa current_span ,
and
.Fa last_span
members of
.Vt struct tbl_node ,
and from the
.Fa span
members of
.Vt struct man_node
and
.Vt struct mdoc_node
from
.In man.h
and
.In mdoc.h .
.Pp
The
.Fa first ,
.Fa last ,
.Fa prev ,
and
.Fa next
members may be
.Dv NULL .
The function
.Fn newspan Bq Pa tbl_data.c
guarantees that the
.Fa opts
and
.Fa layout
members are not
.Dv NULL .
.It Vt struct tbl_dat
This structure describes one data cell in a table by specifying
whether it contains a line or data, whether it spans additional
layout cells, and by storing the data.
It is allocated and filled in
.Fn tbl_data
and referenced from the
.Fa first
and
.Fa last
members of
.Vt struct tbl_span .
.Pp
The
.Fa string
and
.Fa next
members may be
.Dv NULL .
The function
.Fn getdata
guarantees that the
.Fa layout
member is not
.Dv NULL .
.El
.Ss Interface functions
The following functions are implemented in
.Pa tbl.c ,
and all callers in
.Pa roff.c .
.Bl -tag -width Ds
.It Fn tbl_alloc
Allocates, initializes, and returns a new
.Vt struct tbl_node .
Called from
.Fn roff_TS .
.It Fn tbl_read
Dispatches to
.Fn tbl_option ,
.Fn tbl_layout ,
.Fn tbl_cdata ,
and
.Fn tbl_data ,
see below.
Called from
.Fn roff_parseln .
.It Fn tbl_restart
Resets the
.Fa part
member of
.Vt struct tbl_node
to
.Dv TBL_PART_LAYOUT .
Called from
.Fn roff_T_ .
.It Fn tbl_span
On the first call, return the first
.Vt struct tbl_span ;
for later calls, return the next one or
.Dv NULL .
Called from
.Fn roff_span .
.It Fn tbl_end
Flags the last span as
.Dv TBL_SPAN_LAST
and clears the pointer passed as an argment.
Called from
.Fn roff_TE
and
.Fn roff_endparse .
.It Fn tbl_free
Frees the specified
.Vt struct tbl_node
and all the tbl_row, tbl_cell, tbl_span, and tbl_dat structures
referenced from it.
Called from
.Fn roff_free
and
.Fn roff_reset .
.El
.Ss Private functions
.Bl -tag -width Ds
.It Ft int Fn tbl_options "struct tbl_node *tbl" "int ln" "const char *p"
Parses the options line into
.Vt struct tbl_opts .
Implemented in
.Pa tbl_opts.c ,
called from
.Fn tbl_read .
.It Ft int Fn tbl_layout "struct tbl_node *tbl" "int ln" "const char *p"
Allocates and fills one
.Vt struct tbl_row
for each layout line and one
.Vt struct tbl_cell
for each layout cell.
Implemented in
.Pa tbl_layout.c ,
called from
.Fn tbl_read .
.It Ft int Fn tbl_data "struct tbl_node *tbl" "int ln" "const char *p"
Allocates one
.Vt struct tbl_span
for each data line and calls
.Fn getdata
for each data cell.
Implemented in
.Pa tbl_data.c ,
called from
.Fn tbl_read .
.It Ft int Fn tbl_cdata "struct tbl_node *tbl" "int ln" "const char *p"
Continues parsing a data line:
When finding
.Sq T} ,
switches back to
.Dv TBL_PART_DATA
mode and calls
.Fn getdata
if there are more data cells on the line.
Otherwise, appends the data to the current data cell.
Implemented in
.Pa tbl_data.c ,
called from
.Fn tbl_read .
.It Xo
.Ft int
.Fo getdata
.Fa "struct tbl_node *tbl"
.Fa "struct tbl_span *dp"
.Fa "int ln"
.Fa "const char *p"
.Fa "int *pos"
.Fc
.Xc
Parses one data cell into one
.Vt struct tbl_dat .
Implemented in
.Pa tbl_data.c ,
called from
.Fn tbl_data
and
.Fn tbl_cdata .
.El
.Sh SEE ALSO
.Xr mandoc 1 ,
.Xr mandoc 3 ,
.Xr tbl 7
.Sh AUTHORS
.An -nosplit
The
.Nm tbl
library was written by
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
with contributions from
.An Ingo Schwarze Aq Mt schwarze@openbsd.org .