term.h revision 260e9a87725c090ba5835b1f9f0b62fa2f96036f
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle/* $Id: term.h,v 1.111 2015/01/31 00:12:41 schwarze Exp $ */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle/*
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
2312a9d8e5342846988edcd629e1ac56a8b5d4a9Brendan Mmiller * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle *
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * Permission to use, copy, modify, and distribute this software for any
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * purpose with or without fee is hereby granted, provided that the above
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * copyright notice and this permission notice appear in all copies.
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle *
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienleenum termenc {
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle TERMENC_ASCII,
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle TERMENC_LOCALE,
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle TERMENC_UTF8
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle};
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienleenum termtype {
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle TERMTYPE_CHAR,
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle TERMTYPE_PS,
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle TERMTYPE_PDF
33c021457bc11072601be0484041e2f46c2616a5Brendan Miller};
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienleenum termfont {
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle TERMFONT_NONE = 0,
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle TERMFONT_BOLD,
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle TERMFONT_UNDER,
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle TERMFONT_BI,
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle TERMFONT__MAX
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle};
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle#define TERM_MAXMARGIN 100000 /* FIXME */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienlestruct termp;
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienletypedef void (*term_margin)(struct termp *, const void *);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienlestruct termp_tbl {
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle int width; /* width in fixed chars */
ad0b283113c3f11ac1877df97d5d0fae899b56caBrendan Mmiller int decimal; /* decimal point position */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle};
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle
331c327f500d45223e8ad933fd4472740a75aeeachad.kienlestruct termp {
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle enum termtype type;
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle struct rofftbl tbl; /* table configuration */
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle int synopsisonly; /* print the synopsis only */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle int mdocstyle; /* imitate mdoc(7) output */
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle size_t defindent; /* Default indent for text. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t defrmargin; /* Right margin of the device. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t lastrmargin; /* Right margin before the last ll. */
ad0b283113c3f11ac1877df97d5d0fae899b56caBrendan Mmiller size_t rmargin; /* Current right margin. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t maxrmargin; /* Max right margin. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t maxcols; /* Max size of buf. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t offset; /* Margin offest. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t tabwidth; /* Distance of tab positions. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t col; /* Bytes in buf. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t viscol; /* Chars on current line. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t trailspace; /* See termp_flushln(). */
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle int overstep; /* See termp_flushln(). */
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle int skipvsp; /* Vertical space to skip. */
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle int flags;
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle#define TERMP_SENTENCE (1 << 1) /* Space before a sentence. */
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle#define TERMP_NOSPACE (1 << 2) /* No space before words. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle#define TERMP_NONOSPACE (1 << 3) /* No space (no autounset). */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle#define TERMP_NBRWORD (1 << 4) /* Make next word nonbreaking. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle#define TERMP_KEEP (1 << 5) /* Keep words together. */
b1c33bb0456be2f3b9e866871ff404ae012978b9Chad Kienle#define TERMP_PREKEEP (1 << 6) /* ...starting with the next one. */
331c327f500d45223e8ad933fd4472740a75aeeachad.kienle#define TERMP_SKIPCHAR (1 << 7) /* Skip the next character. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle#define TERMP_NOBREAK (1 << 8) /* See term_flushln(). */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle#define TERMP_BRIND (1 << 9) /* See term_flushln(). */
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle#define TERMP_DANGLE (1 << 10) /* See term_flushln(). */
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle#define TERMP_HANG (1 << 11) /* See term_flushln(). */
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle#define TERMP_NOSPLIT (1 << 12) /* Do not break line before .An. */
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle#define TERMP_SPLIT (1 << 13) /* Break line before .An. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle#define TERMP_NONEWLINE (1 << 14) /* No line break in nofill mode. */
2312a9d8e5342846988edcd629e1ac56a8b5d4a9Brendan Mmiller int *buf; /* Output buffer. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle enum termenc enc; /* Type of encoding. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle const struct mchars *symtab; /* Character table. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle enum termfont fontl; /* Last font set. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle enum termfont *fontq; /* Symmetric fonts. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle int fontsz; /* Allocated size of font stack */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle int fonti; /* Index of font stack. */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle term_margin headf; /* invoked to print head */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle term_margin footf; /* invoked to print foot */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle void (*letter)(struct termp *, int);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle void (*begin)(struct termp *);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle void (*end)(struct termp *);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle void (*endline)(struct termp *);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle void (*advance)(struct termp *, size_t);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle void (*setwidth)(struct termp *, int, size_t);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle size_t (*width)(const struct termp *, int);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle double (*hspan)(const struct termp *,
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle const struct roffsu *);
2312a9d8e5342846988edcd629e1ac56a8b5d4a9Brendan Mmiller const void *argf; /* arg for headf/footf */
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle struct termp_ps *ps;
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle};
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle__BEGIN_DECLS
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienlestruct tbl_span;
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienlestruct eqn;
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienleconst char *ascii_uc2str(int);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienlevoid term_eqn(struct termp *, const struct eqn *);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienlevoid term_tbl(struct termp *, const struct tbl_span *);
b1c33bb0456be2f3b9e866871ff404ae012978b9Chad Kienlevoid term_free(struct termp *);
331c327f500d45223e8ad933fd4472740a75aeeachad.kienlevoid term_newln(struct termp *);
b1c33bb0456be2f3b9e866871ff404ae012978b9Chad Kienlevoid term_vspace(struct termp *);
b1c33bb0456be2f3b9e866871ff404ae012978b9Chad Kienlevoid term_word(struct termp *, const char *);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienlevoid term_flushln(struct termp *);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienlevoid term_begin(struct termp *, term_margin,
e4b22b1a9af1faf38ffcd030aecc5f246550f701chad.kienle term_margin, const void *);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienlevoid term_end(struct termp *);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienlevoid term_setwidth(struct termp *, const char *);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienleint term_hspan(const struct termp *, const struct roffsu *);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienleint term_vspan(const struct termp *, const struct roffsu *);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienlesize_t term_strlen(const struct termp *, const char *);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienlesize_t term_len(const struct termp *, size_t);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienlevoid term_fontpush(struct termp *, enum termfont);
bdcef189d83ab13d06dde11499a03b16cdb5b432Chad Kienlevoid term_fontpop(struct termp *);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienlevoid term_fontpopq(struct termp *, int);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienlevoid term_fontrepl(struct termp *, enum termfont);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienlevoid term_fontlast(struct termp *);
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle__END_DECLS
49ca89f51e0242b83f998f16a269dc1982460f02Chad Kienle