1*95c635efSGarrett D'Amore /* $Id: term.h,v 1.90 2011/12/04 23:10:52 schwarze Exp $ */ 2*95c635efSGarrett D'Amore /* 3*95c635efSGarrett D'Amore * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4*95c635efSGarrett D'Amore * 5*95c635efSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any 6*95c635efSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above 7*95c635efSGarrett D'Amore * copyright notice and this permission notice appear in all copies. 8*95c635efSGarrett D'Amore * 9*95c635efSGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10*95c635efSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*95c635efSGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12*95c635efSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*95c635efSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*95c635efSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15*95c635efSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16*95c635efSGarrett D'Amore */ 17*95c635efSGarrett D'Amore #ifndef TERM_H 18*95c635efSGarrett D'Amore #define TERM_H 19*95c635efSGarrett D'Amore 20*95c635efSGarrett D'Amore __BEGIN_DECLS 21*95c635efSGarrett D'Amore 22*95c635efSGarrett D'Amore struct termp; 23*95c635efSGarrett D'Amore 24*95c635efSGarrett D'Amore enum termenc { 25*95c635efSGarrett D'Amore TERMENC_ASCII, 26*95c635efSGarrett D'Amore TERMENC_LOCALE, 27*95c635efSGarrett D'Amore TERMENC_UTF8 28*95c635efSGarrett D'Amore }; 29*95c635efSGarrett D'Amore 30*95c635efSGarrett D'Amore enum termtype { 31*95c635efSGarrett D'Amore TERMTYPE_CHAR, 32*95c635efSGarrett D'Amore TERMTYPE_PS, 33*95c635efSGarrett D'Amore TERMTYPE_PDF 34*95c635efSGarrett D'Amore }; 35*95c635efSGarrett D'Amore 36*95c635efSGarrett D'Amore enum termfont { 37*95c635efSGarrett D'Amore TERMFONT_NONE = 0, 38*95c635efSGarrett D'Amore TERMFONT_BOLD, 39*95c635efSGarrett D'Amore TERMFONT_UNDER, 40*95c635efSGarrett D'Amore TERMFONT__MAX 41*95c635efSGarrett D'Amore }; 42*95c635efSGarrett D'Amore 43*95c635efSGarrett D'Amore #define TERM_MAXMARGIN 100000 /* FIXME */ 44*95c635efSGarrett D'Amore 45*95c635efSGarrett D'Amore typedef void (*term_margin)(struct termp *, const void *); 46*95c635efSGarrett D'Amore 47*95c635efSGarrett D'Amore struct termp_tbl { 48*95c635efSGarrett D'Amore int width; /* width in fixed chars */ 49*95c635efSGarrett D'Amore int decimal; /* decimal point position */ 50*95c635efSGarrett D'Amore }; 51*95c635efSGarrett D'Amore 52*95c635efSGarrett D'Amore struct termp { 53*95c635efSGarrett D'Amore enum termtype type; 54*95c635efSGarrett D'Amore struct rofftbl tbl; /* table configuration */ 55*95c635efSGarrett D'Amore int mdocstyle; /* imitate mdoc(7) output */ 56*95c635efSGarrett D'Amore size_t defindent; /* Default indent for text. */ 57*95c635efSGarrett D'Amore size_t defrmargin; /* Right margin of the device. */ 58*95c635efSGarrett D'Amore size_t rmargin; /* Current right margin. */ 59*95c635efSGarrett D'Amore size_t maxrmargin; /* Max right margin. */ 60*95c635efSGarrett D'Amore int maxcols; /* Max size of buf. */ 61*95c635efSGarrett D'Amore size_t offset; /* Margin offest. */ 62*95c635efSGarrett D'Amore size_t tabwidth; /* Distance of tab positions. */ 63*95c635efSGarrett D'Amore int col; /* Bytes in buf. */ 64*95c635efSGarrett D'Amore size_t viscol; /* Chars on current line. */ 65*95c635efSGarrett D'Amore int overstep; /* See termp_flushln(). */ 66*95c635efSGarrett D'Amore int flags; 67*95c635efSGarrett D'Amore #define TERMP_SENTENCE (1 << 1) /* Space before a sentence. */ 68*95c635efSGarrett D'Amore #define TERMP_NOSPACE (1 << 2) /* No space before words. */ 69*95c635efSGarrett D'Amore #define TERMP_NOBREAK (1 << 4) /* See term_flushln(). */ 70*95c635efSGarrett D'Amore #define TERMP_IGNDELIM (1 << 6) /* Delims like regulars. */ 71*95c635efSGarrett D'Amore #define TERMP_NONOSPACE (1 << 7) /* No space (no autounset). */ 72*95c635efSGarrett D'Amore #define TERMP_DANGLE (1 << 8) /* See term_flushln(). */ 73*95c635efSGarrett D'Amore #define TERMP_HANG (1 << 9) /* See term_flushln(). */ 74*95c635efSGarrett D'Amore #define TERMP_TWOSPACE (1 << 10) /* See term_flushln(). */ 75*95c635efSGarrett D'Amore #define TERMP_NOSPLIT (1 << 11) /* See termp_an_pre/post(). */ 76*95c635efSGarrett D'Amore #define TERMP_SPLIT (1 << 12) /* See termp_an_pre/post(). */ 77*95c635efSGarrett D'Amore #define TERMP_ANPREC (1 << 13) /* See termp_an_pre(). */ 78*95c635efSGarrett D'Amore #define TERMP_KEEP (1 << 14) /* Keep words together. */ 79*95c635efSGarrett D'Amore #define TERMP_PREKEEP (1 << 15) /* ...starting with the next one. */ 80*95c635efSGarrett D'Amore int *buf; /* Output buffer. */ 81*95c635efSGarrett D'Amore enum termenc enc; /* Type of encoding. */ 82*95c635efSGarrett D'Amore struct mchars *symtab; /* Encoded-symbol table. */ 83*95c635efSGarrett D'Amore enum termfont fontl; /* Last font set. */ 84*95c635efSGarrett D'Amore enum termfont fontq[10]; /* Symmetric fonts. */ 85*95c635efSGarrett D'Amore int fonti; /* Index of font stack. */ 86*95c635efSGarrett D'Amore term_margin headf; /* invoked to print head */ 87*95c635efSGarrett D'Amore term_margin footf; /* invoked to print foot */ 88*95c635efSGarrett D'Amore void (*letter)(struct termp *, int); 89*95c635efSGarrett D'Amore void (*begin)(struct termp *); 90*95c635efSGarrett D'Amore void (*end)(struct termp *); 91*95c635efSGarrett D'Amore void (*endline)(struct termp *); 92*95c635efSGarrett D'Amore void (*advance)(struct termp *, size_t); 93*95c635efSGarrett D'Amore size_t (*width)(const struct termp *, int); 94*95c635efSGarrett D'Amore double (*hspan)(const struct termp *, 95*95c635efSGarrett D'Amore const struct roffsu *); 96*95c635efSGarrett D'Amore const void *argf; /* arg for headf/footf */ 97*95c635efSGarrett D'Amore struct termp_ps *ps; 98*95c635efSGarrett D'Amore }; 99*95c635efSGarrett D'Amore 100*95c635efSGarrett D'Amore void term_eqn(struct termp *, const struct eqn *); 101*95c635efSGarrett D'Amore void term_tbl(struct termp *, const struct tbl_span *); 102*95c635efSGarrett D'Amore void term_free(struct termp *); 103*95c635efSGarrett D'Amore void term_newln(struct termp *); 104*95c635efSGarrett D'Amore void term_vspace(struct termp *); 105*95c635efSGarrett D'Amore void term_word(struct termp *, const char *); 106*95c635efSGarrett D'Amore void term_flushln(struct termp *); 107*95c635efSGarrett D'Amore void term_begin(struct termp *, term_margin, 108*95c635efSGarrett D'Amore term_margin, const void *); 109*95c635efSGarrett D'Amore void term_end(struct termp *); 110*95c635efSGarrett D'Amore 111*95c635efSGarrett D'Amore size_t term_hspan(const struct termp *, 112*95c635efSGarrett D'Amore const struct roffsu *); 113*95c635efSGarrett D'Amore size_t term_vspan(const struct termp *, 114*95c635efSGarrett D'Amore const struct roffsu *); 115*95c635efSGarrett D'Amore size_t term_strlen(const struct termp *, const char *); 116*95c635efSGarrett D'Amore size_t term_len(const struct termp *, size_t); 117*95c635efSGarrett D'Amore 118*95c635efSGarrett D'Amore enum termfont term_fonttop(struct termp *); 119*95c635efSGarrett D'Amore const void *term_fontq(struct termp *); 120*95c635efSGarrett D'Amore void term_fontpush(struct termp *, enum termfont); 121*95c635efSGarrett D'Amore void term_fontpop(struct termp *); 122*95c635efSGarrett D'Amore void term_fontpopq(struct termp *, const void *); 123*95c635efSGarrett D'Amore void term_fontrepl(struct termp *, enum termfont); 124*95c635efSGarrett D'Amore void term_fontlast(struct termp *); 125*95c635efSGarrett D'Amore 126*95c635efSGarrett D'Amore __END_DECLS 127*95c635efSGarrett D'Amore 128*95c635efSGarrett D'Amore #endif /*!TERM_H*/ 129