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