File: [cvsweb.bsd.lv] / mandoc / tbl.h (download)
Revision 1.3, Sun Jan 5 18:14:39 2025 UTC (5 months, 1 week ago) by schwarze
Branch: MAIN
CVS Tags: HEAD Changes since 1.2: +1 -2 lines
In the tbl(7) layout parser, use the roff(7) numerical expression parser
to support arithmetic operations in column width modifiers.
Documentation authors ought to focus on semantic markup and avoid trying
to manipulate presentational details. Consequently, using tbl(7) is
discouraged in the first place, using column width modifiers even more
so, and complicating them by performing arithmetics yet more so.
However, the madhouse called DocBook relies on this feature.
For example, DocBook XSL version 1.79.2 generates man(7)+tbl(7) code
that abuses arithmetics in column width modifiers to format things
as simple and mundane as numbered lists, resulting in atrocious layout
that is very hard to read. Last year, tb@ reported git-reset(1)
as an example of an affected manual page.
Properly parsing the width in the tbl(7) parser allows removal of some
incomplete ad-hoc parsing from the tbl(7) formatter, where it didn't
really belong.
|
/* $Id: tbl.h,v 1.3 2025/01/05 18:14:39 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014,2015,2017,2018,2021 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. */
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 << 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 mandoc_esc font;
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;
};