1*6d38604fSBaptiste Daroussin /* $Id: out.h,v 1.34 2020/04/03 11:35:01 schwarze Exp $ */ 261d06d6bSBaptiste Daroussin /* 361d06d6bSBaptiste Daroussin * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 47295610fSBaptiste Daroussin * Copyright (c) 2014, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> 561d06d6bSBaptiste Daroussin * 661d06d6bSBaptiste Daroussin * Permission to use, copy, modify, and distribute this software for any 761d06d6bSBaptiste Daroussin * purpose with or without fee is hereby granted, provided that the above 861d06d6bSBaptiste Daroussin * copyright notice and this permission notice appear in all copies. 961d06d6bSBaptiste Daroussin * 1061d06d6bSBaptiste Daroussin * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1161d06d6bSBaptiste Daroussin * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1261d06d6bSBaptiste Daroussin * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1361d06d6bSBaptiste Daroussin * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1461d06d6bSBaptiste Daroussin * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1561d06d6bSBaptiste Daroussin * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1661d06d6bSBaptiste Daroussin * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17*6d38604fSBaptiste Daroussin * 18*6d38604fSBaptiste Daroussin * Utilities for use by multiple mandoc(1) formatters. 1961d06d6bSBaptiste Daroussin */ 2061d06d6bSBaptiste Daroussin 2161d06d6bSBaptiste Daroussin enum roffscale { 2261d06d6bSBaptiste Daroussin SCALE_CM, /* centimeters (c) */ 2361d06d6bSBaptiste Daroussin SCALE_IN, /* inches (i) */ 2461d06d6bSBaptiste Daroussin SCALE_PC, /* pica (P) */ 2561d06d6bSBaptiste Daroussin SCALE_PT, /* points (p) */ 2661d06d6bSBaptiste Daroussin SCALE_EM, /* ems (m) */ 2761d06d6bSBaptiste Daroussin SCALE_MM, /* mini-ems (M) */ 2861d06d6bSBaptiste Daroussin SCALE_EN, /* ens (n) */ 2961d06d6bSBaptiste Daroussin SCALE_BU, /* default horizontal (u) */ 3061d06d6bSBaptiste Daroussin SCALE_VS, /* default vertical (v) */ 3161d06d6bSBaptiste Daroussin SCALE_FS, /* syn. for u (f) */ 3261d06d6bSBaptiste Daroussin SCALE_MAX 3361d06d6bSBaptiste Daroussin }; 3461d06d6bSBaptiste Daroussin 3561d06d6bSBaptiste Daroussin struct roffcol { 3661d06d6bSBaptiste Daroussin size_t width; /* width of cell */ 377295610fSBaptiste Daroussin size_t nwidth; /* max. width of number in cell */ 3861d06d6bSBaptiste Daroussin size_t decimal; /* decimal position in cell */ 3961d06d6bSBaptiste Daroussin size_t spacing; /* spacing after the column */ 4061d06d6bSBaptiste Daroussin int flags; /* layout flags, see tbl_cell */ 4161d06d6bSBaptiste Daroussin }; 4261d06d6bSBaptiste Daroussin 4361d06d6bSBaptiste Daroussin struct roffsu { 4461d06d6bSBaptiste Daroussin enum roffscale unit; 4561d06d6bSBaptiste Daroussin double scale; 4661d06d6bSBaptiste Daroussin }; 4761d06d6bSBaptiste Daroussin 4861d06d6bSBaptiste Daroussin typedef size_t (*tbl_sulen)(const struct roffsu *, void *); 4961d06d6bSBaptiste Daroussin typedef size_t (*tbl_strlen)(const char *, void *); 5061d06d6bSBaptiste Daroussin typedef size_t (*tbl_len)(size_t, void *); 5161d06d6bSBaptiste Daroussin 5261d06d6bSBaptiste Daroussin struct rofftbl { 5361d06d6bSBaptiste Daroussin tbl_sulen sulen; /* calculate scaling unit length */ 5461d06d6bSBaptiste Daroussin tbl_strlen slen; /* calculate string length */ 5561d06d6bSBaptiste Daroussin tbl_len len; /* produce width of empty space */ 5661d06d6bSBaptiste Daroussin struct roffcol *cols; /* master column specifiers */ 5761d06d6bSBaptiste Daroussin void *arg; /* passed to sulen, slen, and len */ 5861d06d6bSBaptiste Daroussin }; 5961d06d6bSBaptiste Daroussin 6061d06d6bSBaptiste Daroussin #define SCALE_HS_INIT(p, v) \ 6161d06d6bSBaptiste Daroussin do { (p)->unit = SCALE_EN; \ 6261d06d6bSBaptiste Daroussin (p)->scale = (v); } \ 6361d06d6bSBaptiste Daroussin while (/* CONSTCOND */ 0) 6461d06d6bSBaptiste Daroussin 6561d06d6bSBaptiste Daroussin 6661d06d6bSBaptiste Daroussin struct tbl_span; 6761d06d6bSBaptiste Daroussin 6861d06d6bSBaptiste Daroussin const char *a2roffsu(const char *, struct roffsu *, enum roffscale); 69*6d38604fSBaptiste Daroussin void tblcalc(struct rofftbl *, 7061d06d6bSBaptiste Daroussin const struct tbl_span *, size_t, size_t); 71