xref: /freebsd/contrib/mandoc/tbl.3 (revision 7648bc9fee8dec6cb3c4941e0165a930fbe8dcb0)
1.\"	$Id: tbl.3,v 1.6 2018/12/14 06:33:14 schwarze Exp $
2.\"
3.\" Copyright (c) 2013, 2015, 2018 Ingo Schwarze <schwarze@openbsd.org>
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.Dd $Mdocdate: December 14 2018 $
18.Dt TBL 3
19.Os
20.Sh NAME
21.Nm tbl_alloc ,
22.Nm tbl_read ,
23.Nm tbl_restart ,
24.Nm tbl_span ,
25.Nm tbl_end ,
26.Nm tbl_free
27.Nd roff table parser library for mandoc
28.Sh SYNOPSIS
29.In sys/types.h
30.In tbl.h
31.In tbl_parse.h
32.Ft struct tbl_node *
33.Fo tbl_alloc
34.Fa "int pos"
35.Fa "int line"
36.Fc
37.Ft void
38.Fo tbl_read
39.Fa "struct tbl_node *tbl"
40.Fa "int ln"
41.Fa "const char *p"
42.Fa "int offs"
43.Fc
44.Ft void
45.Fo tbl_restart
46.Fa "int line"
47.Fa "int pos"
48.Fa "struct tbl_node *tbl"
49.Fc
50.Ft const struct tbl_span *
51.Fo tbl_span
52.Fa "struct tbl_node *tbl"
53.Fc
54.Ft void
55.Fo tbl_end
56.Fa "struct tbl_node **tblp"
57.Fc
58.Ft void
59.Fo tbl_free
60.Fa "struct tbl_node *tbl"
61.Fc
62.Sh DESCRIPTION
63This library is tightly integrated into the
64.Xr mandoc 1
65utility and not designed for stand-alone use.
66The present manual is intended as a reference for developers working on
67.Xr mandoc 1 .
68.Ss Data structures
69Unless otherwise noted, all of the following data structures are declared in
70.In tbl.h
71and are deleted in
72.Fn tbl_free .
73.Bl -tag -width Ds
74.It Vt struct tbl_node
75This structure describes a complete table.
76It is declared in
77.In tbl_int.h ,
78created in
79.Fn tbl_alloc ,
80and stored in the members
81.Fa first_tbl ,
82.Fa last_tbl ,
83and
84.Fa tbl
85of
86.Vt struct roff Bq Pa roff.c .
87.Pp
88The
89.Fa first_span ,
90.Fa current_span ,
91.Fa last_span ,
92and
93.Fa next
94members may be
95.Dv NULL .
96The
97.Fa first_row
98and
99.Fa last_row
100members may be
101.Dv NULL ,
102but if there is a span, the function
103.Fn tbl_layout
104guarantees that these pointers are not
105.Dv NULL .
106.It Vt struct tbl_opts
107This structure describes the options of one table.
108It is used as a substructure of
109.Vt struct tbl_node
110and thus created and deleted together with it.
111It is filled in
112.Fn tbl_options .
113.It Vt struct tbl_row
114This structure describes one layout line in a table
115by maintaining a list of all the cells in that line.
116It is allocated and filled in
117.Fn row Bq Pa tbl_layout.c
118and referenced from the
119.Fa layout
120member of
121.Vt struct tbl_node .
122.Pp
123The
124.Fa next
125member may be
126.Dv NULL .
127The function
128.Fn tbl_layout
129guarantees that the
130.Fa first
131and
132.Fa last
133members are not NULL.
134.It Vt struct tbl_cell
135This structure describes one layout cell in a table,
136in particular its alignment, membership in spans, and
137usage for lines.
138It is allocated and filled in
139.Fn cell_alloc Bq Pa tbl_layout.c
140and referenced from the
141.Fa first
142and
143.Fa last
144members of
145.Vt struct tbl_row .
146.Pp
147The
148.Fa next
149member may be
150.Dv NULL .
151.It Vt struct tbl_span
152This structure describes one data line in a table
153by maintaining a list of all data cells in that line
154or by specifying that it is a horizontal line.
155It is allocated and filled in
156.Fn newspan Bq Pa tbl_data.c
157which is called from
158.Fn tbl_data
159and referenced from the
160.Fa first_span ,
161.Fa current_span ,
162and
163.Fa last_span
164members of
165.Vt struct tbl_node ,
166and from the
167.Fa span
168members of
169.Vt struct man_node
170and
171.Vt struct mdoc_node
172from
173.In man.h
174and
175.In mdoc.h .
176.Pp
177The
178.Fa first ,
179.Fa last ,
180.Fa prev ,
181and
182.Fa next
183members may be
184.Dv NULL .
185The function
186.Fn newspan Bq Pa tbl_data.c
187guarantees that the
188.Fa opts
189and
190.Fa layout
191members are not
192.Dv NULL .
193.It Vt struct tbl_dat
194This structure describes one data cell in a table by specifying
195whether it contains a line or data, whether it spans additional
196layout cells, and by storing the data.
197It is allocated and filled in
198.Fn tbl_data
199and referenced from the
200.Fa first
201and
202.Fa last
203members of
204.Vt struct tbl_span .
205.Pp
206The
207.Fa string
208and
209.Fa next
210members may be
211.Dv NULL .
212The function
213.Fn getdata
214guarantees that the
215.Fa layout
216member is not
217.Dv NULL .
218.El
219.Ss Interface functions
220The following functions are implemented in
221.Pa tbl.c ,
222and all callers are in
223.Pa roff.c .
224.Bl -tag -width Ds
225.It Fn tbl_alloc
226Allocates, initializes, and returns a new
227.Vt struct tbl_node .
228Called from
229.Fn roff_TS .
230.It Fn tbl_read
231Dispatches to
232.Fn tbl_option ,
233.Fn tbl_layout ,
234.Fn tbl_cdata ,
235and
236.Fn tbl_data ,
237see below.
238Called from
239.Fn roff_parseln .
240.It Fn tbl_restart
241Resets the
242.Fa part
243member of
244.Vt struct tbl_node
245to
246.Dv TBL_PART_LAYOUT .
247Called from
248.Fn roff_T_ .
249.It Fn tbl_span
250On the first call, return the first
251.Vt struct tbl_span ;
252for later calls, return the next one or
253.Dv NULL .
254Called from
255.Fn roff_span .
256.It Fn tbl_end
257Flags the last span as
258.Dv TBL_SPAN_LAST
259and clears the pointer passed as an argment.
260Called from
261.Fn roff_TE
262and
263.Fn roff_endparse .
264.It Fn tbl_free
265Frees the specified
266.Vt struct tbl_node
267and all the tbl_row, tbl_cell, tbl_span, and tbl_dat structures
268referenced from it.
269Called from
270.Fn roff_free
271and
272.Fn roff_reset .
273.El
274.Ss Private functions
275The following functions are declared in
276.In tbl_int.h .
277.Bl -tag -width Ds
278.It Ft int Fn tbl_options "struct tbl_node *tbl" "int ln" "const char *p"
279Parses the options line into
280.Vt struct tbl_opts .
281Implemented in
282.Pa tbl_opts.c ,
283called from
284.Fn tbl_read .
285.It Ft int Fn tbl_layout "struct tbl_node *tbl" "int ln" "const char *p"
286Allocates and fills one
287.Vt struct tbl_row
288for each layout line and one
289.Vt struct tbl_cell
290for each layout cell.
291Implemented in
292.Pa tbl_layout.c ,
293called from
294.Fn tbl_read .
295.It Ft int Fn tbl_data "struct tbl_node *tbl" "int ln" "const char *p"
296Allocates one
297.Vt struct tbl_span
298for each data line and calls
299.Fn getdata
300for each data cell.
301Implemented in
302.Pa tbl_data.c ,
303called from
304.Fn tbl_read .
305.It Ft int Fn tbl_cdata "struct tbl_node *tbl" "int ln" "const char *p"
306Continues parsing a data line:
307When finding
308.Sq T} ,
309switches back to
310.Dv TBL_PART_DATA
311mode and calls
312.Fn getdata
313if there are more data cells on the line.
314Otherwise, appends the data to the current data cell.
315Implemented in
316.Pa tbl_data.c ,
317called from
318.Fn tbl_read .
319.It Xo
320.Ft int
321.Fo getdata
322.Fa "struct tbl_node *tbl"
323.Fa "struct tbl_span *dp"
324.Fa "int ln"
325.Fa "const char *p"
326.Fa "int *pos"
327.Fc
328.Xc
329Parses one data cell into one
330.Vt struct tbl_dat .
331Implemented in
332.Pa tbl_data.c ,
333called from
334.Fn tbl_data
335and
336.Fn tbl_cdata .
337.El
338.Sh SEE ALSO
339.Xr mandoc 1 ,
340.Xr mandoc 3 ,
341.Xr tbl 7
342.Sh AUTHORS
343.An -nosplit
344The
345.Nm tbl
346library was written by
347.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
348with contributions from
349.An Ingo Schwarze Aq Mt schwarze@openbsd.org .
350