diff options
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | eqn.c | 1 | ||||
-rw-r--r-- | mandoc.h | 107 | ||||
-rw-r--r-- | mandoc_headers.3 | 48 | ||||
-rw-r--r-- | out.c | 1 | ||||
-rw-r--r-- | roff.c | 3 | ||||
-rw-r--r-- | tbl.3 | 1 | ||||
-rw-r--r-- | tbl.c | 3 | ||||
-rw-r--r-- | tbl.h | 122 | ||||
-rw-r--r-- | tbl_data.c | 3 | ||||
-rw-r--r-- | tbl_html.c | 2 | ||||
-rw-r--r-- | tbl_layout.c | 3 | ||||
-rw-r--r-- | tbl_opts.c | 1 | ||||
-rw-r--r-- | tbl_term.c | 1 | ||||
-rw-r--r-- | tree.c | 1 |
15 files changed, 179 insertions, 125 deletions
@@ -202,6 +202,7 @@ DISTFILES = INSTALL \ tag.h \ tbl.3 \ tbl.7 \ + tbl.h \ term.h \ $(SRCS) \ $(TESTSRCS) @@ -351,7 +352,8 @@ WWW_INCS = man.h.html \ mandoc_aux.h.html \ mansearch.h.html \ mdoc.h.html \ - roff.h.html + roff.h.html \ + tbl.h.html # === USER CONFIGURATION =============================================== @@ -422,7 +424,7 @@ lib-install: libmandoc.a mkdir -p $(DESTDIR)$(INCLUDEDIR) mkdir -p $(DESTDIR)$(MANDIR)/man3 $(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR) - $(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h roff.h \ + $(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h roff.h tbl.h \ $(DESTDIR)$(INCLUDEDIR) $(INSTALL_MAN) mandoc.3 mandoc_escape.3 mandoc_malloc.3 \ mansearch.3 mchars_alloc.3 tbl.3 $(DESTDIR)$(MANDIR)/man3 @@ -482,6 +484,7 @@ uninstall: rm -f $(DESTDIR)$(INCLUDEDIR)/mandoc_aux.h rm -f $(DESTDIR)$(INCLUDEDIR)/mdoc.h rm -f $(DESTDIR)$(INCLUDEDIR)/roff.h + rm -f $(DESTDIR)$(INCLUDEDIR)/tbl.h [ ! -e $(DESTDIR)$(INCLUDEDIR) ] || rmdir $(DESTDIR)$(INCLUDEDIR) regress: all @@ -30,6 +30,7 @@ #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" +#include "tbl.h" #include "libmandoc.h" #include "libroff.h" @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010, 2012-2018 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 @@ -241,111 +241,6 @@ enum mandocerr { MANDOCERR_MAX }; -struct tbl_opts { - char tab; /* cell-separator */ - char decimal; /* decimal point */ - int opts; -#define TBL_OPT_CENTRE (1 << 0) -#define TBL_OPT_EXPAND (1 << 1) -#define TBL_OPT_BOX (1 << 2) -#define TBL_OPT_DBOX (1 << 3) -#define TBL_OPT_ALLBOX (1 << 4) -#define TBL_OPT_NOKEEP (1 << 5) -#define TBL_OPT_NOSPACE (1 << 6) -#define TBL_OPT_NOWARN (1 << 7) - int cols; /* number of columns */ - int lvert; /* width of left vertical line */ - int rvert; /* width of right vertical line */ -}; - -enum tbl_cellt { - TBL_CELL_CENTRE, /* c, C */ - TBL_CELL_RIGHT, /* r, R */ - TBL_CELL_LEFT, /* l, L */ - TBL_CELL_NUMBER, /* n, N */ - TBL_CELL_SPAN, /* s, S */ - TBL_CELL_LONG, /* a, A */ - TBL_CELL_DOWN, /* ^ */ - TBL_CELL_HORIZ, /* _, - */ - TBL_CELL_DHORIZ, /* = */ - TBL_CELL_MAX -}; - -/* - * A cell in a layout row. - */ -struct tbl_cell { - struct tbl_cell *next; - char *wstr; /* min width represented as a string */ - size_t width; /* minimum column width */ - size_t spacing; /* to the right of the column */ - int vert; /* width of subsequent vertical line */ - int col; /* column number, starting from 0 */ - int flags; -#define TBL_CELL_TALIGN (1 << 0) /* t, T */ -#define TBL_CELL_BALIGN (1 << 1) /* d, D */ -#define TBL_CELL_BOLD (1 << 2) /* fB, B, b */ -#define TBL_CELL_ITALIC (1 << 3) /* fI, I, i */ -#define TBL_CELL_EQUAL (1 << 4) /* e, E */ -#define TBL_CELL_UP (1 << 5) /* u, U */ -#define TBL_CELL_WIGN (1 << 6) /* z, Z */ -#define TBL_CELL_WMAX (1 << 7) /* x, X */ - enum tbl_cellt pos; -}; - -/* - * A layout row. - */ -struct tbl_row { - struct tbl_row *next; - struct tbl_cell *first; - struct tbl_cell *last; - int vert; /* width of left vertical line */ -}; - -enum tbl_datt { - TBL_DATA_NONE, /* has no data */ - TBL_DATA_DATA, /* consists of data/string */ - TBL_DATA_HORIZ, /* horizontal line */ - TBL_DATA_DHORIZ, /* double-horizontal line */ - TBL_DATA_NHORIZ, /* squeezed horizontal line */ - TBL_DATA_NDHORIZ /* squeezed double-horizontal line */ -}; - -/* - * A cell within a row of data. The "string" field contains the actual - * string value that's in the cell. The rest is layout. - */ -struct tbl_dat { - struct tbl_cell *layout; /* layout cell */ - struct tbl_dat *next; - char *string; /* data (NULL if not TBL_DATA_DATA) */ - int hspans; /* how many horizontal spans follow */ - int vspans; /* how many vertical spans follow */ - int block; /* T{ text block T} */ - enum tbl_datt pos; -}; - -enum tbl_spant { - TBL_SPAN_DATA, /* span consists of data */ - TBL_SPAN_HORIZ, /* span is horizontal line */ - TBL_SPAN_DHORIZ /* span is double horizontal line */ -}; - -/* - * A row of data in a table. - */ -struct tbl_span { - struct tbl_opts *opts; - struct tbl_row *layout; /* layout row */ - struct tbl_dat *first; - struct tbl_dat *last; - struct tbl_span *prev; - struct tbl_span *next; - int line; /* parse line */ - enum tbl_spant pos; -}; - enum eqn_boxt { EQN_TEXT, /* text (number, variable, whatever) */ EQN_SUBEXPR, /* nested `eqn' subexpression */ diff --git a/mandoc_headers.3 b/mandoc_headers.3 index a6e1004c..def4b990 100644 --- a/mandoc_headers.3 +++ b/mandoc_headers.3 @@ -25,13 +25,13 @@ separate from each other: .Pp .Bl -dash -offset indent -compact .It -.Xr mdoc 7 +.Xr roff 7 parser .It -.Xr man 7 +.Xr mdoc 7 parser .It -.Xr roff 7 +.Xr man 7 parser .It .Xr tbl 7 @@ -45,6 +45,8 @@ terminal formatters HTML formatters .It search tools +.It +main programs .El .Pp Note that mere usage of an opaque struct type does @@ -56,14 +58,18 @@ any other mandoc header. These headers should be included before any other mandoc headers. .Bl -tag -width Ds .It Qq Pa mandoc_aux.h +Memory allocation utility functions; can be used everywhere. +.Pp Requires .In sys/types.h for .Vt size_t . .Pp -Provides the utility functions documented in +Provides the functions documented in .Xr mandoc_malloc 3 . .It Qq Pa mandoc_ohash.h +Hashing utility functions; can be used everywhere. +.Pp Requires .In stddef.h for @@ -78,6 +84,9 @@ Includes and provides .Fn mandoc_ohash_init . .It Qq Pa mandoc.h +Error handling utilities and top level parser interface; +can be used everywhere. +.Pp Requires .In sys/types.h for @@ -88,18 +97,10 @@ Provides .Vt enum mandocerr , .Vt enum mandoclevel , .Vt enum mandoc_os , -.Vt enum tbl_cellt , -.Vt enum tbl_datt , -.Vt enum tbl_spant , .Vt enum eqn_boxt , .Vt enum eqn_fontt , .Vt enum eqn_pilet , .Vt enum eqn_post , -.Vt struct tbl_opts , -.Vt struct tbl_cell , -.Vt struct tbl_row , -.Vt struct tbl_dat , -.Vt struct tbl_span , .Vt struct eqn_box , the function prototype typedef .Fn mandocmsg , @@ -122,7 +123,30 @@ Uses the type from .Pa roff.h as an opaque type for function prototypes. +.It Qq Pa tbl.h +Data structures for the +.Xr tbl 7 +parse tree; can be used everywhere. +.Pp +Requires +.In sys/types.h +for +.Vt size_t . +.Pp +Provides +.Vt enum tbl_cellt , +.Vt enum tbl_datt , +.Vt enum tbl_spant , +.Vt struct tbl_opts , +.Vt struct tbl_cell , +.Vt struct tbl_row , +.Vt struct tbl_dat , +and +.Vt struct tbl_span . .It Qq Pa mandoc_xr.h +Cross reference validation; intended for use in the main program +and in parsers, but not in formatters. +.Pp Provides .Vt struct mandoc_xr and the functions @@ -28,6 +28,7 @@ #include "mandoc_aux.h" #include "mandoc.h" +#include "tbl.h" #include "out.h" struct tbl_colgroup { @@ -28,10 +28,11 @@ #include <stdlib.h> #include <string.h> -#include "mandoc.h" #include "mandoc_aux.h" #include "mandoc_ohash.h" +#include "mandoc.h" #include "roff.h" +#include "tbl.h" #include "libmandoc.h" #include "roff_int.h" #include "libroff.h" @@ -27,6 +27,7 @@ .Nd roff table parser library for mandoc .Sh SYNOPSIS .In mandoc.h +.In tbl.h .In libmandoc.h .In libroff.h .Ft struct tbl_node * @@ -25,8 +25,9 @@ #include <string.h> #include <time.h> -#include "mandoc.h" #include "mandoc_aux.h" +#include "mandoc.h" +#include "tbl.h" #include "libmandoc.h" #include "libroff.h" @@ -0,0 +1,122 @@ +/* $Id$ */ +/* + * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2014, 2015, 2017, 2018 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 AUTHORS DISCLAIM ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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. + */ + +struct tbl_opts { + int opts; +#define TBL_OPT_ALLBOX (1 << 0) /* Option "allbox". */ +#define TBL_OPT_BOX (1 << 1) /* Option "box". */ +#define TBL_OPT_CENTRE (1 << 2) /* Option "center". */ +#define TBL_OPT_DBOX (1 << 3) /* Option "doublebox". */ +#define TBL_OPT_EXPAND (1 << 4) /* Option "expand". */ +#define TBL_OPT_NOKEEP (1 << 5) /* Option "nokeep". */ +#define TBL_OPT_NOSPACE (1 << 6) /* Option "nospaces". */ +#define TBL_OPT_NOWARN (1 << 7) /* Option "nowarn". */ + int cols; /* Number of columns. */ + int lvert; /* Width of left vertical line. */ + int rvert; /* Width of right vertical line. */ + char tab; /* Option "tab": cell separator. */ + char decimal; /* Option "decimalpoint". */ +}; + +enum tbl_cellt { + TBL_CELL_CENTRE, /* c, C */ + TBL_CELL_RIGHT, /* r, R */ + TBL_CELL_LEFT, /* l, L */ + TBL_CELL_NUMBER, /* n, N */ + TBL_CELL_SPAN, /* s, S */ + TBL_CELL_LONG, /* a, A */ + TBL_CELL_DOWN, /* ^ */ + TBL_CELL_HORIZ, /* _, - */ + TBL_CELL_DHORIZ, /* = */ + TBL_CELL_MAX +}; + +/* + * A cell in a layout row. + */ +struct tbl_cell { + struct tbl_cell *next; /* Layout cell to the right. */ + char *wstr; /* Min width represented as a string. */ + size_t width; /* Minimum column width. */ + size_t spacing; /* To the right of the column. */ + int vert; /* Width of subsequent vertical line. */ + int col; /* Column number, starting from 0. */ + int flags; +#define TBL_CELL_BOLD (1 << 0) /* b, B, fB */ +#define TBL_CELL_ITALIC (1 << 1) /* i, I, fI */ +#define TBL_CELL_TALIGN (1 << 2) /* t, T */ +#define TBL_CELL_UP (1 << 3) /* u, U */ +#define TBL_CELL_BALIGN (1 << 4) /* d, D */ +#define TBL_CELL_WIGN (1 << 5) /* z, Z */ +#define TBL_CELL_EQUAL (1 << 6) /* e, E */ +#define TBL_CELL_WMAX (1 << 7) /* x, X */ + enum tbl_cellt pos; +}; + +/* + * A layout row. + */ +struct tbl_row { + struct tbl_row *next; /* Layout row below. */ + struct tbl_cell *first; /* Leftmost layout cell. */ + struct tbl_cell *last; /* Rightmost layout cell. */ + int vert; /* Width of left vertical line. */ +}; + +enum tbl_datt { + TBL_DATA_NONE, /* Uninitialized row. */ + TBL_DATA_DATA, /* Contains data rather than a line. */ + TBL_DATA_HORIZ, /* _: connecting horizontal line. */ + TBL_DATA_DHORIZ, /* =: connecting double horizontal line. */ + TBL_DATA_NHORIZ, /* \_: isolated horizontal line. */ + TBL_DATA_NDHORIZ /* \=: isolated double horizontal line. */ +}; + +/* + * A cell within a row of data. The "string" field contains the + * actual string value that's in the cell. The rest is layout. + */ +struct tbl_dat { + struct tbl_dat *next; /* Data cell to the right. */ + struct tbl_cell *layout; /* Associated layout cell. */ + char *string; /* Data, or NULL if not TBL_DATA_DATA. */ + int hspans; /* How many horizontal spans follow. */ + int vspans; /* How many vertical spans follow. */ + int block; /* T{ text block T} */ + enum tbl_datt pos; +}; + +enum tbl_spant { + TBL_SPAN_DATA, /* Contains data rather than a line. */ + TBL_SPAN_HORIZ, /* _: horizontal line. */ + TBL_SPAN_DHORIZ /* =: double horizontal line. */ +}; + +/* + * A row of data in a table. + */ +struct tbl_span { + struct tbl_opts *opts; /* Options for the table as a whole. */ + struct tbl_span *prev; /* Data row above. */ + struct tbl_span *next; /* Data row below. */ + struct tbl_row *layout; /* Associated layout row. */ + struct tbl_dat *first; /* Leftmost data cell. */ + struct tbl_dat *last; /* Rightmost data cell. */ + int line; /* Input file line number. */ + enum tbl_spant pos; +}; @@ -25,8 +25,9 @@ #include <string.h> #include <time.h> -#include "mandoc.h" #include "mandoc_aux.h" +#include "mandoc.h" +#include "tbl.h" #include "libmandoc.h" #include "libroff.h" @@ -24,7 +24,7 @@ #include <stdlib.h> #include <string.h> -#include "mandoc.h" +#include "tbl.h" #include "out.h" #include "html.h" diff --git a/tbl_layout.c b/tbl_layout.c index 51a3ba37..580667b8 100644 --- a/tbl_layout.c +++ b/tbl_layout.c @@ -25,8 +25,9 @@ #include <string.h> #include <time.h> -#include "mandoc.h" #include "mandoc_aux.h" +#include "mandoc.h" +#include "tbl.h" #include "libmandoc.h" #include "libroff.h" @@ -25,6 +25,7 @@ #include <string.h> #include "mandoc.h" +#include "tbl.h" #include "libmandoc.h" #include "libroff.h" @@ -26,6 +26,7 @@ #include <string.h> #include "mandoc.h" +#include "tbl.h" #include "out.h" #include "term.h" @@ -29,6 +29,7 @@ #include "roff.h" #include "mdoc.h" #include "man.h" +#include "tbl.h" #include "main.h" static void print_box(const struct eqn_box *, int); |