1*544c191cSchristos.\" Id: tbl.3,v 1.6 2018/12/14 06:33:14 schwarze Exp 270f041f9Sjoerg.\" 3*544c191cSchristos.\" Copyright (c) 2013, 2015, 2018 Ingo Schwarze <schwarze@openbsd.org> 470f041f9Sjoerg.\" 570f041f9Sjoerg.\" Permission to use, copy, modify, and distribute this software for any 670f041f9Sjoerg.\" purpose with or without fee is hereby granted, provided that the above 770f041f9Sjoerg.\" copyright notice and this permission notice appear in all copies. 870f041f9Sjoerg.\" 970f041f9Sjoerg.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1070f041f9Sjoerg.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1170f041f9Sjoerg.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1270f041f9Sjoerg.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1370f041f9Sjoerg.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1470f041f9Sjoerg.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1570f041f9Sjoerg.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1670f041f9Sjoerg.\" 17*544c191cSchristos.Dd December 14, 2018 1870f041f9Sjoerg.Dt TBL 3 1970f041f9Sjoerg.Os 2070f041f9Sjoerg.Sh NAME 2170f041f9Sjoerg.Nm tbl_alloc , 2270f041f9Sjoerg.Nm tbl_read , 2370f041f9Sjoerg.Nm tbl_restart , 2470f041f9Sjoerg.Nm tbl_span , 2570f041f9Sjoerg.Nm tbl_end , 2670f041f9Sjoerg.Nm tbl_free 2770f041f9Sjoerg.Nd roff table parser library for mandoc 2870f041f9Sjoerg.Sh SYNOPSIS 29*544c191cSchristos.In sys/types.h 30*544c191cSchristos.In tbl.h 31*544c191cSchristos.In tbl_parse.h 3270f041f9Sjoerg.Ft struct tbl_node * 3370f041f9Sjoerg.Fo tbl_alloc 3470f041f9Sjoerg.Fa "int pos" 3570f041f9Sjoerg.Fa "int line" 3670f041f9Sjoerg.Fc 37*544c191cSchristos.Ft void 3870f041f9Sjoerg.Fo tbl_read 3970f041f9Sjoerg.Fa "struct tbl_node *tbl" 4070f041f9Sjoerg.Fa "int ln" 4170f041f9Sjoerg.Fa "const char *p" 4270f041f9Sjoerg.Fa "int offs" 4370f041f9Sjoerg.Fc 4470f041f9Sjoerg.Ft void 4570f041f9Sjoerg.Fo tbl_restart 4670f041f9Sjoerg.Fa "int line" 4770f041f9Sjoerg.Fa "int pos" 4870f041f9Sjoerg.Fa "struct tbl_node *tbl" 4970f041f9Sjoerg.Fc 5070f041f9Sjoerg.Ft const struct tbl_span * 5170f041f9Sjoerg.Fo tbl_span 5270f041f9Sjoerg.Fa "struct tbl_node *tbl" 5370f041f9Sjoerg.Fc 5470f041f9Sjoerg.Ft void 5570f041f9Sjoerg.Fo tbl_end 5670f041f9Sjoerg.Fa "struct tbl_node **tblp" 5770f041f9Sjoerg.Fc 5870f041f9Sjoerg.Ft void 5970f041f9Sjoerg.Fo tbl_free 6070f041f9Sjoerg.Fa "struct tbl_node *tbl" 6170f041f9Sjoerg.Fc 6270f041f9Sjoerg.Sh DESCRIPTION 6370f041f9SjoergThis library is tightly integrated into the 6470f041f9Sjoerg.Xr mandoc 1 6570f041f9Sjoergutility and not designed for stand-alone use. 6670f041f9SjoergThe present manual is intended as a reference for developers working on 6770f041f9Sjoerg.Xr mandoc 1 . 6870f041f9Sjoerg.Ss Data structures 69*544c191cSchristosUnless otherwise noted, all of the following data structures are declared in 70*544c191cSchristos.In tbl.h 7170f041f9Sjoergand are deleted in 7270f041f9Sjoerg.Fn tbl_free . 7370f041f9Sjoerg.Bl -tag -width Ds 7470f041f9Sjoerg.It Vt struct tbl_node 7570f041f9SjoergThis structure describes a complete table. 76*544c191cSchristosIt is declared in 77*544c191cSchristos.In tbl_int.h , 7870f041f9Sjoergcreated in 7970f041f9Sjoerg.Fn tbl_alloc , 8070f041f9Sjoergand stored in the members 81fec65c98Schristos.Fa first_tbl , 82fec65c98Schristos.Fa last_tbl , 8370f041f9Sjoergand 84fec65c98Schristos.Fa tbl 8570f041f9Sjoergof 8670f041f9Sjoerg.Vt struct roff Bq Pa roff.c . 87fec65c98Schristos.Pp 88fec65c98SchristosThe 89fec65c98Schristos.Fa first_span , 90fec65c98Schristos.Fa current_span , 91fec65c98Schristos.Fa last_span , 92fec65c98Schristosand 93fec65c98Schristos.Fa next 94fec65c98Schristosmembers may be 95fec65c98Schristos.Dv NULL . 96fec65c98SchristosThe 97fec65c98Schristos.Fa first_row 98fec65c98Schristosand 99fec65c98Schristos.Fa last_row 100fec65c98Schristosmembers may be 101fec65c98Schristos.Dv NULL , 102fec65c98Schristosbut if there is a span, the function 103fec65c98Schristos.Fn tbl_layout 104fec65c98Schristosguarantees that these pointers are not 105fec65c98Schristos.Dv NULL . 10670f041f9Sjoerg.It Vt struct tbl_opts 10770f041f9SjoergThis structure describes the options of one table. 10870f041f9SjoergIt is used as a substructure of 10970f041f9Sjoerg.Vt struct tbl_node 11070f041f9Sjoergand thus created and deleted together with it. 11170f041f9SjoergIt is filled in 11270f041f9Sjoerg.Fn tbl_options . 11370f041f9Sjoerg.It Vt struct tbl_row 11470f041f9SjoergThis structure describes one layout line in a table 11570f041f9Sjoergby maintaining a list of all the cells in that line. 11670f041f9SjoergIt is allocated and filled in 11770f041f9Sjoerg.Fn row Bq Pa tbl_layout.c 11870f041f9Sjoergand referenced from the 119fec65c98Schristos.Fa layout 12070f041f9Sjoergmember of 12170f041f9Sjoerg.Vt struct tbl_node . 122fec65c98Schristos.Pp 123fec65c98SchristosThe 124fec65c98Schristos.Fa next 125fec65c98Schristosmember may be 126fec65c98Schristos.Dv NULL . 127fec65c98SchristosThe function 128fec65c98Schristos.Fn tbl_layout 129fec65c98Schristosguarantees that the 130fec65c98Schristos.Fa first 131fec65c98Schristosand 132fec65c98Schristos.Fa last 133fec65c98Schristosmembers are not NULL. 13470f041f9Sjoerg.It Vt struct tbl_cell 13570f041f9SjoergThis structure describes one layout cell in a table, 13670f041f9Sjoergin particular its alignment, membership in spans, and 13770f041f9Sjoergusage for lines. 13870f041f9SjoergIt is allocated and filled in 13970f041f9Sjoerg.Fn cell_alloc Bq Pa tbl_layout.c 14070f041f9Sjoergand referenced from the 141fec65c98Schristos.Fa first 14270f041f9Sjoergand 143fec65c98Schristos.Fa last 14470f041f9Sjoergmembers of 14570f041f9Sjoerg.Vt struct tbl_row . 146fec65c98Schristos.Pp 147fec65c98SchristosThe 148fec65c98Schristos.Fa next 149fec65c98Schristosmember may be 150fec65c98Schristos.Dv NULL . 15170f041f9Sjoerg.It Vt struct tbl_span 15270f041f9SjoergThis structure describes one data line in a table 15370f041f9Sjoergby maintaining a list of all data cells in that line 15470f041f9Sjoergor by specifying that it is a horizontal line. 15570f041f9SjoergIt is allocated and filled in 15670f041f9Sjoerg.Fn newspan Bq Pa tbl_data.c 15770f041f9Sjoergwhich is called from 15870f041f9Sjoerg.Fn tbl_data 15970f041f9Sjoergand referenced from the 160fec65c98Schristos.Fa first_span , 161fec65c98Schristos.Fa current_span , 16270f041f9Sjoergand 163fec65c98Schristos.Fa last_span 16470f041f9Sjoergmembers of 16570f041f9Sjoerg.Vt struct tbl_node , 16670f041f9Sjoergand from the 167fec65c98Schristos.Fa span 16870f041f9Sjoergmembers of 16970f041f9Sjoerg.Vt struct man_node 17070f041f9Sjoergand 17170f041f9Sjoerg.Vt struct mdoc_node 17270f041f9Sjoergfrom 17370f041f9Sjoerg.In man.h 17470f041f9Sjoergand 17570f041f9Sjoerg.In mdoc.h . 176fec65c98Schristos.Pp 177fec65c98SchristosThe 178fec65c98Schristos.Fa first , 179fec65c98Schristos.Fa last , 180fec65c98Schristos.Fa prev , 181fec65c98Schristosand 182fec65c98Schristos.Fa next 183fec65c98Schristosmembers may be 184fec65c98Schristos.Dv NULL . 185fec65c98SchristosThe function 186fec65c98Schristos.Fn newspan Bq Pa tbl_data.c 187fec65c98Schristosguarantees that the 188fec65c98Schristos.Fa opts 189fec65c98Schristosand 190fec65c98Schristos.Fa layout 191fec65c98Schristosmembers are not 192fec65c98Schristos.Dv NULL . 19370f041f9Sjoerg.It Vt struct tbl_dat 19470f041f9SjoergThis structure describes one data cell in a table by specifying 19570f041f9Sjoergwhether it contains a line or data, whether it spans additional 19670f041f9Sjoerglayout cells, and by storing the data. 19770f041f9SjoergIt is allocated and filled in 198fec65c98Schristos.Fn tbl_data 19970f041f9Sjoergand referenced from the 200fec65c98Schristos.Fa first 20170f041f9Sjoergand 202fec65c98Schristos.Fa last 20370f041f9Sjoergmembers of 20470f041f9Sjoerg.Vt struct tbl_span . 205fec65c98Schristos.Pp 206fec65c98SchristosThe 207fec65c98Schristos.Fa string 208fec65c98Schristosand 209fec65c98Schristos.Fa next 210fec65c98Schristosmembers may be 211fec65c98Schristos.Dv NULL . 212fec65c98SchristosThe function 213fec65c98Schristos.Fn getdata 214fec65c98Schristosguarantees that the 215fec65c98Schristos.Fa layout 216fec65c98Schristosmember is not 217fec65c98Schristos.Dv NULL . 21870f041f9Sjoerg.El 21970f041f9Sjoerg.Ss Interface functions 22070f041f9SjoergThe following functions are implemented in 22170f041f9Sjoerg.Pa tbl.c , 222*544c191cSchristosand all callers are in 22370f041f9Sjoerg.Pa roff.c . 22470f041f9Sjoerg.Bl -tag -width Ds 22570f041f9Sjoerg.It Fn tbl_alloc 22670f041f9SjoergAllocates, initializes, and returns a new 22770f041f9Sjoerg.Vt struct tbl_node . 22870f041f9SjoergCalled from 22970f041f9Sjoerg.Fn roff_TS . 23070f041f9Sjoerg.It Fn tbl_read 23170f041f9SjoergDispatches to 23270f041f9Sjoerg.Fn tbl_option , 23370f041f9Sjoerg.Fn tbl_layout , 23470f041f9Sjoerg.Fn tbl_cdata , 23570f041f9Sjoergand 23670f041f9Sjoerg.Fn tbl_data , 23770f041f9Sjoergsee below. 23870f041f9SjoergCalled from 23970f041f9Sjoerg.Fn roff_parseln . 24070f041f9Sjoerg.It Fn tbl_restart 24170f041f9SjoergResets the 242fec65c98Schristos.Fa part 24370f041f9Sjoergmember of 24470f041f9Sjoerg.Vt struct tbl_node 24570f041f9Sjoergto 24670f041f9Sjoerg.Dv TBL_PART_LAYOUT . 24770f041f9SjoergCalled from 24870f041f9Sjoerg.Fn roff_T_ . 24970f041f9Sjoerg.It Fn tbl_span 25070f041f9SjoergOn the first call, return the first 25170f041f9Sjoerg.Vt struct tbl_span ; 25270f041f9Sjoergfor later calls, return the next one or 25370f041f9Sjoerg.Dv NULL . 25470f041f9SjoergCalled from 25570f041f9Sjoerg.Fn roff_span . 25670f041f9Sjoerg.It Fn tbl_end 25770f041f9SjoergFlags the last span as 25870f041f9Sjoerg.Dv TBL_SPAN_LAST 25970f041f9Sjoergand clears the pointer passed as an argment. 26070f041f9SjoergCalled from 26170f041f9Sjoerg.Fn roff_TE 26270f041f9Sjoergand 26370f041f9Sjoerg.Fn roff_endparse . 26470f041f9Sjoerg.It Fn tbl_free 26570f041f9SjoergFrees the specified 26670f041f9Sjoerg.Vt struct tbl_node 267fec65c98Schristosand all the tbl_row, tbl_cell, tbl_span, and tbl_dat structures 26870f041f9Sjoergreferenced from it. 26970f041f9SjoergCalled from 27070f041f9Sjoerg.Fn roff_free 27170f041f9Sjoergand 27270f041f9Sjoerg.Fn roff_reset . 27370f041f9Sjoerg.El 27470f041f9Sjoerg.Ss Private functions 275*544c191cSchristosThe following functions are declared in 276*544c191cSchristos.In tbl_int.h . 27770f041f9Sjoerg.Bl -tag -width Ds 27870f041f9Sjoerg.It Ft int Fn tbl_options "struct tbl_node *tbl" "int ln" "const char *p" 27970f041f9SjoergParses the options line into 28070f041f9Sjoerg.Vt struct tbl_opts . 28170f041f9SjoergImplemented in 28270f041f9Sjoerg.Pa tbl_opts.c , 28370f041f9Sjoergcalled from 28470f041f9Sjoerg.Fn tbl_read . 28570f041f9Sjoerg.It Ft int Fn tbl_layout "struct tbl_node *tbl" "int ln" "const char *p" 28670f041f9SjoergAllocates and fills one 28770f041f9Sjoerg.Vt struct tbl_row 288fec65c98Schristosfor each layout line and one 28970f041f9Sjoerg.Vt struct tbl_cell 29070f041f9Sjoergfor each layout cell. 29170f041f9SjoergImplemented in 29270f041f9Sjoerg.Pa tbl_layout.c , 29370f041f9Sjoergcalled from 29470f041f9Sjoerg.Fn tbl_read . 29570f041f9Sjoerg.It Ft int Fn tbl_data "struct tbl_node *tbl" "int ln" "const char *p" 29670f041f9SjoergAllocates one 29770f041f9Sjoerg.Vt struct tbl_span 29870f041f9Sjoergfor each data line and calls 299fec65c98Schristos.Fn getdata 300fec65c98Schristosfor each data cell. 30170f041f9SjoergImplemented in 30270f041f9Sjoerg.Pa tbl_data.c , 30370f041f9Sjoergcalled from 30470f041f9Sjoerg.Fn tbl_read . 30570f041f9Sjoerg.It Ft int Fn tbl_cdata "struct tbl_node *tbl" "int ln" "const char *p" 30670f041f9SjoergContinues parsing a data line: 30770f041f9SjoergWhen finding 30870f041f9Sjoerg.Sq T} , 30970f041f9Sjoergswitches back to 31070f041f9Sjoerg.Dv TBL_PART_DATA 31170f041f9Sjoergmode and calls 312fec65c98Schristos.Fn getdata 31370f041f9Sjoergif there are more data cells on the line. 31470f041f9SjoergOtherwise, appends the data to the current data cell. 31570f041f9SjoergImplemented in 31670f041f9Sjoerg.Pa tbl_data.c , 31770f041f9Sjoergcalled from 31870f041f9Sjoerg.Fn tbl_read . 31970f041f9Sjoerg.It Xo 32070f041f9Sjoerg.Ft int 321fec65c98Schristos.Fo getdata 32270f041f9Sjoerg.Fa "struct tbl_node *tbl" 32370f041f9Sjoerg.Fa "struct tbl_span *dp" 32470f041f9Sjoerg.Fa "int ln" 32570f041f9Sjoerg.Fa "const char *p" 32670f041f9Sjoerg.Fa "int *pos" 32770f041f9Sjoerg.Fc 32870f041f9Sjoerg.Xc 32970f041f9SjoergParses one data cell into one 33070f041f9Sjoerg.Vt struct tbl_dat . 33170f041f9SjoergImplemented in 33270f041f9Sjoerg.Pa tbl_data.c , 33370f041f9Sjoergcalled from 33470f041f9Sjoerg.Fn tbl_data 33570f041f9Sjoergand 33670f041f9Sjoerg.Fn tbl_cdata . 33770f041f9Sjoerg.El 33870f041f9Sjoerg.Sh SEE ALSO 33970f041f9Sjoerg.Xr mandoc 1 , 34070f041f9Sjoerg.Xr mandoc 3 , 34170f041f9Sjoerg.Xr tbl 7 34270f041f9Sjoerg.Sh AUTHORS 34370f041f9Sjoerg.An -nosplit 34470f041f9SjoergThe 34570f041f9Sjoerg.Nm tbl 34670f041f9Sjoerglibrary was written by 34770f041f9Sjoerg.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv 34870f041f9Sjoergwith contributions from 34970f041f9Sjoerg.An Ingo Schwarze Aq Mt schwarze@openbsd.org . 350