1*6d38604fSBaptiste Daroussin /* $Id: tbl.h,v 1.2 2021/08/10 12:55:04 schwarze Exp $ */ 27295610fSBaptiste Daroussin /* 37295610fSBaptiste Daroussin * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4*6d38604fSBaptiste Daroussin * Copyright (c) 2014,2015,2017,2018,2021 Ingo Schwarze <schwarze@openbsd.org> 57295610fSBaptiste Daroussin * 67295610fSBaptiste Daroussin * Permission to use, copy, modify, and distribute this software for any 77295610fSBaptiste Daroussin * purpose with or without fee is hereby granted, provided that the above 87295610fSBaptiste Daroussin * copyright notice and this permission notice appear in all copies. 97295610fSBaptiste Daroussin * 107295610fSBaptiste Daroussin * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 117295610fSBaptiste Daroussin * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 127295610fSBaptiste Daroussin * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 137295610fSBaptiste Daroussin * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 147295610fSBaptiste Daroussin * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 157295610fSBaptiste Daroussin * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 167295610fSBaptiste Daroussin * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 177295610fSBaptiste Daroussin */ 187295610fSBaptiste Daroussin 197295610fSBaptiste Daroussin struct tbl_opts { 207295610fSBaptiste Daroussin int opts; 217295610fSBaptiste Daroussin #define TBL_OPT_ALLBOX (1 << 0) /* Option "allbox". */ 227295610fSBaptiste Daroussin #define TBL_OPT_BOX (1 << 1) /* Option "box". */ 237295610fSBaptiste Daroussin #define TBL_OPT_CENTRE (1 << 2) /* Option "center". */ 247295610fSBaptiste Daroussin #define TBL_OPT_DBOX (1 << 3) /* Option "doublebox". */ 257295610fSBaptiste Daroussin #define TBL_OPT_EXPAND (1 << 4) /* Option "expand". */ 267295610fSBaptiste Daroussin #define TBL_OPT_NOKEEP (1 << 5) /* Option "nokeep". */ 277295610fSBaptiste Daroussin #define TBL_OPT_NOSPACE (1 << 6) /* Option "nospaces". */ 287295610fSBaptiste Daroussin #define TBL_OPT_NOWARN (1 << 7) /* Option "nowarn". */ 297295610fSBaptiste Daroussin int cols; /* Number of columns. */ 307295610fSBaptiste Daroussin int lvert; /* Width of left vertical line. */ 317295610fSBaptiste Daroussin int rvert; /* Width of right vertical line. */ 327295610fSBaptiste Daroussin char tab; /* Option "tab": cell separator. */ 337295610fSBaptiste Daroussin char decimal; /* Option "decimalpoint". */ 347295610fSBaptiste Daroussin }; 357295610fSBaptiste Daroussin 367295610fSBaptiste Daroussin enum tbl_cellt { 377295610fSBaptiste Daroussin TBL_CELL_CENTRE, /* c, C */ 387295610fSBaptiste Daroussin TBL_CELL_RIGHT, /* r, R */ 397295610fSBaptiste Daroussin TBL_CELL_LEFT, /* l, L */ 407295610fSBaptiste Daroussin TBL_CELL_NUMBER, /* n, N */ 417295610fSBaptiste Daroussin TBL_CELL_SPAN, /* s, S */ 427295610fSBaptiste Daroussin TBL_CELL_LONG, /* a, A */ 437295610fSBaptiste Daroussin TBL_CELL_DOWN, /* ^ */ 447295610fSBaptiste Daroussin TBL_CELL_HORIZ, /* _, - */ 457295610fSBaptiste Daroussin TBL_CELL_DHORIZ, /* = */ 467295610fSBaptiste Daroussin TBL_CELL_MAX 477295610fSBaptiste Daroussin }; 487295610fSBaptiste Daroussin 497295610fSBaptiste Daroussin /* 507295610fSBaptiste Daroussin * A cell in a layout row. 517295610fSBaptiste Daroussin */ 527295610fSBaptiste Daroussin struct tbl_cell { 537295610fSBaptiste Daroussin struct tbl_cell *next; /* Layout cell to the right. */ 547295610fSBaptiste Daroussin char *wstr; /* Min width represented as a string. */ 557295610fSBaptiste Daroussin size_t width; /* Minimum column width. */ 567295610fSBaptiste Daroussin size_t spacing; /* To the right of the column. */ 577295610fSBaptiste Daroussin int vert; /* Width of subsequent vertical line. */ 587295610fSBaptiste Daroussin int col; /* Column number, starting from 0. */ 597295610fSBaptiste Daroussin int flags; 607295610fSBaptiste Daroussin #define TBL_CELL_TALIGN (1 << 2) /* t, T */ 617295610fSBaptiste Daroussin #define TBL_CELL_UP (1 << 3) /* u, U */ 627295610fSBaptiste Daroussin #define TBL_CELL_BALIGN (1 << 4) /* d, D */ 637295610fSBaptiste Daroussin #define TBL_CELL_WIGN (1 << 5) /* z, Z */ 647295610fSBaptiste Daroussin #define TBL_CELL_EQUAL (1 << 6) /* e, E */ 657295610fSBaptiste Daroussin #define TBL_CELL_WMAX (1 << 7) /* x, X */ 66*6d38604fSBaptiste Daroussin enum mandoc_esc font; 677295610fSBaptiste Daroussin enum tbl_cellt pos; 687295610fSBaptiste Daroussin }; 697295610fSBaptiste Daroussin 707295610fSBaptiste Daroussin /* 717295610fSBaptiste Daroussin * A layout row. 727295610fSBaptiste Daroussin */ 737295610fSBaptiste Daroussin struct tbl_row { 747295610fSBaptiste Daroussin struct tbl_row *next; /* Layout row below. */ 757295610fSBaptiste Daroussin struct tbl_cell *first; /* Leftmost layout cell. */ 767295610fSBaptiste Daroussin struct tbl_cell *last; /* Rightmost layout cell. */ 777295610fSBaptiste Daroussin int vert; /* Width of left vertical line. */ 787295610fSBaptiste Daroussin }; 797295610fSBaptiste Daroussin 807295610fSBaptiste Daroussin enum tbl_datt { 817295610fSBaptiste Daroussin TBL_DATA_NONE, /* Uninitialized row. */ 827295610fSBaptiste Daroussin TBL_DATA_DATA, /* Contains data rather than a line. */ 837295610fSBaptiste Daroussin TBL_DATA_HORIZ, /* _: connecting horizontal line. */ 847295610fSBaptiste Daroussin TBL_DATA_DHORIZ, /* =: connecting double horizontal line. */ 857295610fSBaptiste Daroussin TBL_DATA_NHORIZ, /* \_: isolated horizontal line. */ 867295610fSBaptiste Daroussin TBL_DATA_NDHORIZ /* \=: isolated double horizontal line. */ 877295610fSBaptiste Daroussin }; 887295610fSBaptiste Daroussin 897295610fSBaptiste Daroussin /* 907295610fSBaptiste Daroussin * A cell within a row of data. The "string" field contains the 917295610fSBaptiste Daroussin * actual string value that's in the cell. The rest is layout. 927295610fSBaptiste Daroussin */ 937295610fSBaptiste Daroussin struct tbl_dat { 947295610fSBaptiste Daroussin struct tbl_dat *next; /* Data cell to the right. */ 957295610fSBaptiste Daroussin struct tbl_cell *layout; /* Associated layout cell. */ 967295610fSBaptiste Daroussin char *string; /* Data, or NULL if not TBL_DATA_DATA. */ 977295610fSBaptiste Daroussin int hspans; /* How many horizontal spans follow. */ 987295610fSBaptiste Daroussin int vspans; /* How many vertical spans follow. */ 997295610fSBaptiste Daroussin int block; /* T{ text block T} */ 1007295610fSBaptiste Daroussin enum tbl_datt pos; 1017295610fSBaptiste Daroussin }; 1027295610fSBaptiste Daroussin 1037295610fSBaptiste Daroussin enum tbl_spant { 1047295610fSBaptiste Daroussin TBL_SPAN_DATA, /* Contains data rather than a line. */ 1057295610fSBaptiste Daroussin TBL_SPAN_HORIZ, /* _: horizontal line. */ 1067295610fSBaptiste Daroussin TBL_SPAN_DHORIZ /* =: double horizontal line. */ 1077295610fSBaptiste Daroussin }; 1087295610fSBaptiste Daroussin 1097295610fSBaptiste Daroussin /* 1107295610fSBaptiste Daroussin * A row of data in a table. 1117295610fSBaptiste Daroussin */ 1127295610fSBaptiste Daroussin struct tbl_span { 1137295610fSBaptiste Daroussin struct tbl_opts *opts; /* Options for the table as a whole. */ 1147295610fSBaptiste Daroussin struct tbl_span *prev; /* Data row above. */ 1157295610fSBaptiste Daroussin struct tbl_span *next; /* Data row below. */ 1167295610fSBaptiste Daroussin struct tbl_row *layout; /* Associated layout row. */ 1177295610fSBaptiste Daroussin struct tbl_dat *first; /* Leftmost data cell. */ 1187295610fSBaptiste Daroussin struct tbl_dat *last; /* Rightmost data cell. */ 1197295610fSBaptiste Daroussin int line; /* Input file line number. */ 1207295610fSBaptiste Daroussin enum tbl_spant pos; 1217295610fSBaptiste Daroussin }; 122