1*60395358Sschwarze /* $OpenBSD: tbl.h,v 1.7 2025/01/05 18:03:51 schwarze Exp $ */ 2fae2491eSschwarze /* 3fae2491eSschwarze * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 47d063611Sschwarze * Copyright (c) 2014,2015,2017,2018,2021 Ingo Schwarze <schwarze@openbsd.org> 5fae2491eSschwarze * 6fae2491eSschwarze * Permission to use, copy, modify, and distribute this software for any 7fae2491eSschwarze * purpose with or without fee is hereby granted, provided that the above 8fae2491eSschwarze * copyright notice and this permission notice appear in all copies. 9fae2491eSschwarze * 10fae2491eSschwarze * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 11fae2491eSschwarze * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12fae2491eSschwarze * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 13fae2491eSschwarze * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14fae2491eSschwarze * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15fae2491eSschwarze * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16fae2491eSschwarze * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17fae2491eSschwarze */ 18fae2491eSschwarze 19fae2491eSschwarze struct tbl_opts { 20fae2491eSschwarze int opts; 21fae2491eSschwarze #define TBL_OPT_ALLBOX (1 << 0) /* Option "allbox". */ 22fae2491eSschwarze #define TBL_OPT_BOX (1 << 1) /* Option "box". */ 23fae2491eSschwarze #define TBL_OPT_CENTRE (1 << 2) /* Option "center". */ 24fae2491eSschwarze #define TBL_OPT_DBOX (1 << 3) /* Option "doublebox". */ 25fae2491eSschwarze #define TBL_OPT_EXPAND (1 << 4) /* Option "expand". */ 26fae2491eSschwarze #define TBL_OPT_NOKEEP (1 << 5) /* Option "nokeep". */ 27fae2491eSschwarze #define TBL_OPT_NOSPACE (1 << 6) /* Option "nospaces". */ 28fae2491eSschwarze #define TBL_OPT_NOWARN (1 << 7) /* Option "nowarn". */ 29fae2491eSschwarze int cols; /* Number of columns. */ 30fae2491eSschwarze int lvert; /* Width of left vertical line. */ 31fae2491eSschwarze int rvert; /* Width of right vertical line. */ 32fae2491eSschwarze char tab; /* Option "tab": cell separator. */ 33fae2491eSschwarze char decimal; /* Option "decimalpoint". */ 34fae2491eSschwarze }; 35fae2491eSschwarze 36fae2491eSschwarze enum tbl_cellt { 37fae2491eSschwarze TBL_CELL_CENTRE, /* c, C */ 38fae2491eSschwarze TBL_CELL_RIGHT, /* r, R */ 39fae2491eSschwarze TBL_CELL_LEFT, /* l, L */ 40fae2491eSschwarze TBL_CELL_NUMBER, /* n, N */ 41fae2491eSschwarze TBL_CELL_SPAN, /* s, S */ 42fae2491eSschwarze TBL_CELL_LONG, /* a, A */ 43fae2491eSschwarze TBL_CELL_DOWN, /* ^ */ 44fae2491eSschwarze TBL_CELL_HORIZ, /* _, - */ 45fae2491eSschwarze TBL_CELL_DHORIZ, /* = */ 46fae2491eSschwarze TBL_CELL_MAX 47fae2491eSschwarze }; 48fae2491eSschwarze 49fae2491eSschwarze /* 50fae2491eSschwarze * A cell in a layout row. 51fae2491eSschwarze */ 52fae2491eSschwarze struct tbl_cell { 53fae2491eSschwarze struct tbl_cell *next; /* Layout cell to the right. */ 54fae2491eSschwarze size_t width; /* Minimum column width. */ 55fae2491eSschwarze size_t spacing; /* To the right of the column. */ 56fae2491eSschwarze int vert; /* Width of subsequent vertical line. */ 57fae2491eSschwarze int col; /* Column number, starting from 0. */ 58fae2491eSschwarze int flags; 59fae2491eSschwarze #define TBL_CELL_TALIGN (1 << 2) /* t, T */ 60fae2491eSschwarze #define TBL_CELL_UP (1 << 3) /* u, U */ 61fae2491eSschwarze #define TBL_CELL_BALIGN (1 << 4) /* d, D */ 62fae2491eSschwarze #define TBL_CELL_WIGN (1 << 5) /* z, Z */ 63fae2491eSschwarze #define TBL_CELL_EQUAL (1 << 6) /* e, E */ 64fae2491eSschwarze #define TBL_CELL_WMAX (1 << 7) /* x, X */ 657d063611Sschwarze enum mandoc_esc font; 66fae2491eSschwarze enum tbl_cellt pos; 67fae2491eSschwarze }; 68fae2491eSschwarze 69fae2491eSschwarze /* 70fae2491eSschwarze * A layout row. 71fae2491eSschwarze */ 72fae2491eSschwarze struct tbl_row { 73fae2491eSschwarze struct tbl_row *next; /* Layout row below. */ 74fae2491eSschwarze struct tbl_cell *first; /* Leftmost layout cell. */ 75fae2491eSschwarze struct tbl_cell *last; /* Rightmost layout cell. */ 76fae2491eSschwarze int vert; /* Width of left vertical line. */ 77fae2491eSschwarze }; 78fae2491eSschwarze 79fae2491eSschwarze enum tbl_datt { 80fae2491eSschwarze TBL_DATA_NONE, /* Uninitialized row. */ 81fae2491eSschwarze TBL_DATA_DATA, /* Contains data rather than a line. */ 82fae2491eSschwarze TBL_DATA_HORIZ, /* _: connecting horizontal line. */ 83fae2491eSschwarze TBL_DATA_DHORIZ, /* =: connecting double horizontal line. */ 84fae2491eSschwarze TBL_DATA_NHORIZ, /* \_: isolated horizontal line. */ 85fae2491eSschwarze TBL_DATA_NDHORIZ /* \=: isolated double horizontal line. */ 86fae2491eSschwarze }; 87fae2491eSschwarze 88fae2491eSschwarze /* 89fae2491eSschwarze * A cell within a row of data. The "string" field contains the 90fae2491eSschwarze * actual string value that's in the cell. The rest is layout. 91fae2491eSschwarze */ 92fae2491eSschwarze struct tbl_dat { 93fae2491eSschwarze struct tbl_dat *next; /* Data cell to the right. */ 94fae2491eSschwarze struct tbl_cell *layout; /* Associated layout cell. */ 95fae2491eSschwarze char *string; /* Data, or NULL if not TBL_DATA_DATA. */ 96fae2491eSschwarze int hspans; /* How many horizontal spans follow. */ 97fae2491eSschwarze int vspans; /* How many vertical spans follow. */ 98fae2491eSschwarze int block; /* T{ text block T} */ 99fae2491eSschwarze enum tbl_datt pos; 100fae2491eSschwarze }; 101fae2491eSschwarze 102fae2491eSschwarze enum tbl_spant { 103fae2491eSschwarze TBL_SPAN_DATA, /* Contains data rather than a line. */ 104fae2491eSschwarze TBL_SPAN_HORIZ, /* _: horizontal line. */ 105fae2491eSschwarze TBL_SPAN_DHORIZ /* =: double horizontal line. */ 106fae2491eSschwarze }; 107fae2491eSschwarze 108fae2491eSschwarze /* 109fae2491eSschwarze * A row of data in a table. 110fae2491eSschwarze */ 111fae2491eSschwarze struct tbl_span { 112fae2491eSschwarze struct tbl_opts *opts; /* Options for the table as a whole. */ 113fae2491eSschwarze struct tbl_span *prev; /* Data row above. */ 114fae2491eSschwarze struct tbl_span *next; /* Data row below. */ 115fae2491eSschwarze struct tbl_row *layout; /* Associated layout row. */ 116fae2491eSschwarze struct tbl_dat *first; /* Leftmost data cell. */ 117fae2491eSschwarze struct tbl_dat *last; /* Rightmost data cell. */ 118fae2491eSschwarze int line; /* Input file line number. */ 119fae2491eSschwarze enum tbl_spant pos; 120fae2491eSschwarze }; 121