logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

tbl_alloc, tbl_read, tbl_restart, tbl_span, tbl_end, tbl_free — roff table parser library for mandoc

Authors

       The  tbl library was written by Kristaps Dzonsons <kristaps@bsd.lv> with contributions from Ingo Schwarze
       <schwarze@openbsd.org>.

Debian                                          December 14, 2018                                         TBL(3)

Description

       This  library is tightly integrated into the mandoc(1) utility and not designed for stand-alone use.  The
       present manual is intended as a reference for developers working on mandoc(1).

   Datastructures
       Unless otherwise noted, all of the following data structures are declared in <tbl.h> and are  deleted  in
       tbl_free().

       structtbl_node
               This  structure  describes  a  complete  table.   It  is  declared  in  <tbl_int.h>,  created  in
               tbl_alloc(), and stored in the members first_tbl, last_tbl, and tbl of structroff [roff.c].

               The first_span, current_span, last_span, and  next  members  may  be  NULL.   The  first_row  and
               last_row  members  may be NULL, but if there is a span, the function tbl_layout() guarantees that
               these pointers are not NULL.

       structtbl_opts
               This structure describes the options of one table.  It  is  used  as  a  substructure  of  structtbl_node and thus created and deleted together with it.  It is filled in tbl_options().

       structtbl_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 row() [tbl_layout.c] and  referenced  from  the  layout
               member of structtbl_node.

               The  next  member  may  be  NULL.   The  function tbl_layout() guarantees that the first and last
               members are not NULL.

       structtbl_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 cell_alloc() [tbl_layout.c] and
               referenced from the first and last members of structtbl_row.

               The next member may be NULL.

       structtbl_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  newspan()
               [tbl_data.c]  which  is  called from tbl_data() and referenced from the first_span, current_span,
               and last_span members of structtbl_node, and from the span members of structman_node and structmdoc_node from <man.h> and <mdoc.h>.

               The first, last, prev, and next  members  may  be  NULL.   The  function  newspan()  [tbl_data.c]
               guarantees that the opts and layout members are not NULL.

       structtbl_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 tbl_data() and referenced from the first and last members of structtbl_span.

               The  string  and  next  members  may  be NULL.  The function getdata() guarantees that the layout
               member is not NULL.

   Interfacefunctions
       The following functions are implemented in tbl.c, and all callers are in roff.c.

       tbl_alloc()
               Allocates, initializes, and returns a new structtbl_node.  Called from roff_TS().

       tbl_read()
               Dispatches to tbl_option(), tbl_layout(), tbl_cdata(), and tbl_data(), see  below.   Called  from
               roff_parseln().

       tbl_restart()
               Resets the part member of structtbl_node to TBL_PART_LAYOUT.  Called from roff_T_().

       tbl_span()
               On  the  first  call,  return  the first structtbl_span; for later calls, return the next one or
               NULL.  Called from roff_span().

       tbl_end()
               Flags the last span as TBL_SPAN_LAST and clears the pointer passed as an  argment.   Called  from
               roff_TE() and roff_endparse().

       tbl_free()
               Frees  the  specified  structtbl_node  and  all  the  tbl_row,  tbl_cell, tbl_span, and tbl_dat
               structures referenced from it.  Called from roff_free() and roff_reset().

   Privatefunctions
       The following functions are declared in <tbl_int.h>.

       inttbl_options(structtbl_node*tbl, intln, constchar*p)
               Parses the options line into structtbl_opts.  Implemented in tbl_opts.c, called from tbl_read().

       inttbl_layout(structtbl_node*tbl, intln, constchar*p)
               Allocates and fills one structtbl_row for each layout line and  one  structtbl_cell  for  each
               layout cell.  Implemented in tbl_layout.c, called from tbl_read().

       inttbl_data(structtbl_node*tbl, intln, constchar*p)
               Allocates  one  structtbl_span  for  each  data  line  and  calls getdata() for each data cell.
               Implemented in tbl_data.c, called from tbl_read().

       inttbl_cdata(structtbl_node*tbl, intln, constchar*p)
               Continues parsing a data line: When finding ‘T}’, switches back to TBL_PART_DATA mode  and  calls
               getdata()  if  there are more data cells on the line.  Otherwise, appends the data to the current
               data cell.  Implemented in tbl_data.c, called from tbl_read().

       intgetdata(structtbl_node*tbl, structtbl_span*dp, intln, constchar*p, int*pos)
               Parses one data cell into one structtbl_dat.  Implemented in tbl_data.c, called from  tbl_data()
               and tbl_cdata().

Name

       tbl_alloc, tbl_read, tbl_restart, tbl_span, tbl_end, tbl_free — roff table parser library for mandoc

See Also

mandoc(1), mandoc(3), tbl(7)

Synopsis

#include<sys/types.h>#include<tbl.h>#include<tbl_parse.h>structtbl_node*tbl_alloc(intpos, intline);

       voidtbl_read(structtbl_node*tbl, intln, constchar*p, intoffs);

       voidtbl_restart(intline, intpos, structtbl_node*tbl);

       conststructtbl_span*tbl_span(structtbl_node*tbl);

       voidtbl_end(structtbl_node**tblp);

       voidtbl_free(structtbl_node*tbl);

See Also