1*cec8643bSMichal Nowak /* $Id: term.h,v 1.131 2019/01/04 03:21:02 schwarze Exp $ */ 295c635efSGarrett D'Amore /* 395c635efSGarrett D'Amore * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4*cec8643bSMichal Nowak * Copyright (c) 2011-2015, 2017, 2019 Ingo Schwarze <schwarze@openbsd.org> 595c635efSGarrett D'Amore * 695c635efSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any 795c635efSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above 895c635efSGarrett D'Amore * copyright notice and this permission notice appear in all copies. 995c635efSGarrett D'Amore * 10371584c2SYuri Pankov * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 1195c635efSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12371584c2SYuri Pankov * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 1395c635efSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1495c635efSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1595c635efSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1695c635efSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1795c635efSGarrett D'Amore */ 1895c635efSGarrett D'Amore 1995c635efSGarrett D'Amore enum termenc { 2095c635efSGarrett D'Amore TERMENC_ASCII, 2195c635efSGarrett D'Amore TERMENC_LOCALE, 2295c635efSGarrett D'Amore TERMENC_UTF8 2395c635efSGarrett D'Amore }; 2495c635efSGarrett D'Amore 2595c635efSGarrett D'Amore enum termtype { 2695c635efSGarrett D'Amore TERMTYPE_CHAR, 2795c635efSGarrett D'Amore TERMTYPE_PS, 2895c635efSGarrett D'Amore TERMTYPE_PDF 2995c635efSGarrett D'Amore }; 3095c635efSGarrett D'Amore 3195c635efSGarrett D'Amore enum termfont { 3295c635efSGarrett D'Amore TERMFONT_NONE = 0, 3395c635efSGarrett D'Amore TERMFONT_BOLD, 3495c635efSGarrett D'Amore TERMFONT_UNDER, 35698f87a4SGarrett D'Amore TERMFONT_BI, 3695c635efSGarrett D'Amore TERMFONT__MAX 3795c635efSGarrett D'Amore }; 3895c635efSGarrett D'Amore 39c66b8046SYuri Pankov struct eqn_box; 40371584c2SYuri Pankov struct roff_meta; 41c66b8046SYuri Pankov struct roff_node; 42c66b8046SYuri Pankov struct tbl_span; 43260e9a87SYuri Pankov struct termp; 44260e9a87SYuri Pankov 45371584c2SYuri Pankov typedef void (*term_margin)(struct termp *, const struct roff_meta *); 4695c635efSGarrett D'Amore 4795c635efSGarrett D'Amore struct termp_tbl { 4895c635efSGarrett D'Amore int width; /* width in fixed chars */ 4995c635efSGarrett D'Amore int decimal; /* decimal point position */ 5095c635efSGarrett D'Amore }; 5195c635efSGarrett D'Amore 52c66b8046SYuri Pankov struct termp_col { 53c66b8046SYuri Pankov int *buf; /* Output buffer. */ 54c66b8046SYuri Pankov size_t maxcols; /* Allocated bytes in buf. */ 55c66b8046SYuri Pankov size_t lastcol; /* Last byte in buf. */ 56c66b8046SYuri Pankov size_t col; /* Byte in buf to be written. */ 57c66b8046SYuri Pankov size_t rmargin; /* Current right margin. */ 58c66b8046SYuri Pankov size_t offset; /* Current left margin. */ 59c66b8046SYuri Pankov }; 60c66b8046SYuri Pankov 6195c635efSGarrett D'Amore struct termp { 62c66b8046SYuri Pankov struct rofftbl tbl; /* Table configuration. */ 63c66b8046SYuri Pankov struct termp_col *tcols; /* Array of table columns. */ 64c66b8046SYuri Pankov struct termp_col *tcol; /* Current table column. */ 65c66b8046SYuri Pankov size_t maxtcol; /* Allocated table columns. */ 66c66b8046SYuri Pankov size_t lasttcol; /* Last column currently used. */ 67371584c2SYuri Pankov size_t line; /* Current output line number. */ 6895c635efSGarrett D'Amore size_t defindent; /* Default indent for text. */ 6995c635efSGarrett D'Amore size_t defrmargin; /* Right margin of the device. */ 70260e9a87SYuri Pankov size_t lastrmargin; /* Right margin before the last ll. */ 7195c635efSGarrett D'Amore size_t maxrmargin; /* Max right margin. */ 72c66b8046SYuri Pankov size_t col; /* Byte position in buf. */ 7395c635efSGarrett D'Amore size_t viscol; /* Chars on current line. */ 74c66b8046SYuri Pankov size_t trailspace; /* See term_flushln(). */ 75c66b8046SYuri Pankov size_t minbl; /* Minimum blanks before next field. */ 76c66b8046SYuri Pankov int synopsisonly; /* Print the synopsis only. */ 77c66b8046SYuri Pankov int mdocstyle; /* Imitate mdoc(7) output. */ 78c66b8046SYuri Pankov int ti; /* Temporary indent for one line. */ 79698f87a4SGarrett D'Amore int skipvsp; /* Vertical space to skip. */ 8095c635efSGarrett D'Amore int flags; 81371584c2SYuri Pankov #define TERMP_SENTENCE (1 << 0) /* Space before a sentence. */ 82371584c2SYuri Pankov #define TERMP_NOSPACE (1 << 1) /* No space before words. */ 83371584c2SYuri Pankov #define TERMP_NONOSPACE (1 << 2) /* No space (no autounset). */ 84371584c2SYuri Pankov #define TERMP_NBRWORD (1 << 3) /* Make next word nonbreaking. */ 85371584c2SYuri Pankov #define TERMP_KEEP (1 << 4) /* Keep words together. */ 86371584c2SYuri Pankov #define TERMP_PREKEEP (1 << 5) /* ...starting with the next one. */ 87371584c2SYuri Pankov #define TERMP_BACKAFTER (1 << 6) /* Back up after next character. */ 88371584c2SYuri Pankov #define TERMP_BACKBEFORE (1 << 7) /* Back up before next character. */ 89698f87a4SGarrett D'Amore #define TERMP_NOBREAK (1 << 8) /* See term_flushln(). */ 90371584c2SYuri Pankov #define TERMP_BRTRSP (1 << 9) /* See term_flushln(). */ 91371584c2SYuri Pankov #define TERMP_BRIND (1 << 10) /* See term_flushln(). */ 92c66b8046SYuri Pankov #define TERMP_HANG (1 << 11) /* See term_flushln(). */ 93c66b8046SYuri Pankov #define TERMP_NOPAD (1 << 12) /* See term_flushln(). */ 94371584c2SYuri Pankov #define TERMP_NOSPLIT (1 << 13) /* Do not break line before .An. */ 95371584c2SYuri Pankov #define TERMP_SPLIT (1 << 14) /* Break line before .An. */ 96371584c2SYuri Pankov #define TERMP_NONEWLINE (1 << 15) /* No line break in nofill mode. */ 97c66b8046SYuri Pankov #define TERMP_BRNEVER (1 << 16) /* Don't even break at maxrmargin. */ 98c66b8046SYuri Pankov #define TERMP_NOBUF (1 << 17) /* Bypass output buffer. */ 99c66b8046SYuri Pankov #define TERMP_NEWMC (1 << 18) /* No .mc printed yet. */ 100c66b8046SYuri Pankov #define TERMP_ENDMC (1 << 19) /* Next break ends .mc mode. */ 101c66b8046SYuri Pankov #define TERMP_MULTICOL (1 << 20) /* Multiple column mode. */ 102*cec8643bSMichal Nowak #define TERMP_CENTER (1 << 21) /* Center output lines. */ 103*cec8643bSMichal Nowak #define TERMP_RIGHT (1 << 22) /* Adjust to the right margin. */ 104c66b8046SYuri Pankov enum termtype type; /* Terminal, PS, or PDF. */ 10595c635efSGarrett D'Amore enum termenc enc; /* Type of encoding. */ 10695c635efSGarrett D'Amore enum termfont fontl; /* Last font set. */ 107260e9a87SYuri Pankov enum termfont *fontq; /* Symmetric fonts. */ 108260e9a87SYuri Pankov int fontsz; /* Allocated size of font stack */ 10995c635efSGarrett D'Amore int fonti; /* Index of font stack. */ 11095c635efSGarrett D'Amore term_margin headf; /* invoked to print head */ 11195c635efSGarrett D'Amore term_margin footf; /* invoked to print foot */ 11295c635efSGarrett D'Amore void (*letter)(struct termp *, int); 11395c635efSGarrett D'Amore void (*begin)(struct termp *); 11495c635efSGarrett D'Amore void (*end)(struct termp *); 11595c635efSGarrett D'Amore void (*endline)(struct termp *); 11695c635efSGarrett D'Amore void (*advance)(struct termp *, size_t); 117371584c2SYuri Pankov void (*setwidth)(struct termp *, int, int); 11895c635efSGarrett D'Amore size_t (*width)(const struct termp *, int); 119371584c2SYuri Pankov int (*hspan)(const struct termp *, 12095c635efSGarrett D'Amore const struct roffsu *); 12195c635efSGarrett D'Amore const void *argf; /* arg for headf/footf */ 122c66b8046SYuri Pankov const char *mc; /* Margin character. */ 12395c635efSGarrett D'Amore struct termp_ps *ps; 12495c635efSGarrett D'Amore }; 12595c635efSGarrett D'Amore 126260e9a87SYuri Pankov 127260e9a87SYuri Pankov const char *ascii_uc2str(int); 128260e9a87SYuri Pankov 129c66b8046SYuri Pankov void roff_term_pre(struct termp *, const struct roff_node *); 130c66b8046SYuri Pankov 131c66b8046SYuri Pankov void term_eqn(struct termp *, const struct eqn_box *); 13295c635efSGarrett D'Amore void term_tbl(struct termp *, const struct tbl_span *); 13395c635efSGarrett D'Amore void term_free(struct termp *); 134c66b8046SYuri Pankov void term_setcol(struct termp *, size_t); 13595c635efSGarrett D'Amore void term_newln(struct termp *); 13695c635efSGarrett D'Amore void term_vspace(struct termp *); 13795c635efSGarrett D'Amore void term_word(struct termp *, const char *); 13895c635efSGarrett D'Amore void term_flushln(struct termp *); 13995c635efSGarrett D'Amore void term_begin(struct termp *, term_margin, 140371584c2SYuri Pankov term_margin, const struct roff_meta *); 14195c635efSGarrett D'Amore void term_end(struct termp *); 14295c635efSGarrett D'Amore 143260e9a87SYuri Pankov void term_setwidth(struct termp *, const char *); 144260e9a87SYuri Pankov int term_hspan(const struct termp *, const struct roffsu *); 145c66b8046SYuri Pankov int term_hen(const struct termp *, const struct roffsu *); 146260e9a87SYuri Pankov int term_vspan(const struct termp *, const struct roffsu *); 14795c635efSGarrett D'Amore size_t term_strlen(const struct termp *, const char *); 14895c635efSGarrett D'Amore size_t term_len(const struct termp *, size_t); 14995c635efSGarrett D'Amore 150c66b8046SYuri Pankov void term_tab_set(const struct termp *, const char *); 151c66b8046SYuri Pankov void term_tab_iset(size_t); 152c66b8046SYuri Pankov size_t term_tab_next(size_t); 153c66b8046SYuri Pankov 15495c635efSGarrett D'Amore void term_fontpush(struct termp *, enum termfont); 15595c635efSGarrett D'Amore void term_fontpop(struct termp *); 156260e9a87SYuri Pankov void term_fontpopq(struct termp *, int); 15795c635efSGarrett D'Amore void term_fontrepl(struct termp *, enum termfont); 15895c635efSGarrett D'Amore void term_fontlast(struct termp *); 159