xref: /titanic_44/usr/src/cmd/mandoc/term.h (revision 698f87a48e2e945bfe5493ce168e0d0ae1cedd5c)
1*698f87a4SGarrett D'Amore /*	$Id: term.h,v 1.97 2013/12/25 00:39:31 schwarze Exp $ */
295c635efSGarrett D'Amore /*
395c635efSGarrett D'Amore  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*698f87a4SGarrett D'Amore  * Copyright (c) 2011, 2012, 2013 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  *
1095c635efSGarrett D'Amore  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1195c635efSGarrett D'Amore  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1295c635efSGarrett D'Amore  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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 #ifndef TERM_H
1995c635efSGarrett D'Amore #define TERM_H
2095c635efSGarrett D'Amore 
2195c635efSGarrett D'Amore __BEGIN_DECLS
2295c635efSGarrett D'Amore 
2395c635efSGarrett D'Amore struct	termp;
2495c635efSGarrett D'Amore 
2595c635efSGarrett D'Amore enum	termenc {
2695c635efSGarrett D'Amore 	TERMENC_ASCII,
2795c635efSGarrett D'Amore 	TERMENC_LOCALE,
2895c635efSGarrett D'Amore 	TERMENC_UTF8
2995c635efSGarrett D'Amore };
3095c635efSGarrett D'Amore 
3195c635efSGarrett D'Amore enum	termtype {
3295c635efSGarrett D'Amore 	TERMTYPE_CHAR,
3395c635efSGarrett D'Amore 	TERMTYPE_PS,
3495c635efSGarrett D'Amore 	TERMTYPE_PDF
3595c635efSGarrett D'Amore };
3695c635efSGarrett D'Amore 
3795c635efSGarrett D'Amore enum	termfont {
3895c635efSGarrett D'Amore 	TERMFONT_NONE = 0,
3995c635efSGarrett D'Amore 	TERMFONT_BOLD,
4095c635efSGarrett D'Amore 	TERMFONT_UNDER,
41*698f87a4SGarrett D'Amore 	TERMFONT_BI,
4295c635efSGarrett D'Amore 	TERMFONT__MAX
4395c635efSGarrett D'Amore };
4495c635efSGarrett D'Amore 
4595c635efSGarrett D'Amore #define	TERM_MAXMARGIN	  100000 /* FIXME */
4695c635efSGarrett D'Amore 
4795c635efSGarrett D'Amore typedef void	(*term_margin)(struct termp *, const void *);
4895c635efSGarrett D'Amore 
4995c635efSGarrett D'Amore struct	termp_tbl {
5095c635efSGarrett D'Amore 	int		  width;	/* width in fixed chars */
5195c635efSGarrett D'Amore 	int		  decimal;	/* decimal point position */
5295c635efSGarrett D'Amore };
5395c635efSGarrett D'Amore 
5495c635efSGarrett D'Amore struct	termp {
5595c635efSGarrett D'Amore 	enum termtype	  type;
5695c635efSGarrett D'Amore 	struct rofftbl	  tbl;		/* table configuration */
5795c635efSGarrett D'Amore 	int		  mdocstyle;	/* imitate mdoc(7) output */
5895c635efSGarrett D'Amore 	size_t		  defindent;	/* Default indent for text. */
5995c635efSGarrett D'Amore 	size_t		  defrmargin;	/* Right margin of the device. */
6095c635efSGarrett D'Amore 	size_t		  rmargin;	/* Current right margin. */
6195c635efSGarrett D'Amore 	size_t		  maxrmargin;	/* Max right margin. */
62*698f87a4SGarrett D'Amore 	size_t		  maxcols;	/* Max size of buf. */
6395c635efSGarrett D'Amore 	size_t		  offset;	/* Margin offest. */
6495c635efSGarrett D'Amore 	size_t		  tabwidth;	/* Distance of tab positions. */
65*698f87a4SGarrett D'Amore 	size_t		  col;		/* Bytes in buf. */
6695c635efSGarrett D'Amore 	size_t		  viscol;	/* Chars on current line. */
67*698f87a4SGarrett D'Amore 	size_t		  trailspace;	/* See termp_flushln(). */
6895c635efSGarrett D'Amore 	int		  overstep;	/* See termp_flushln(). */
69*698f87a4SGarrett D'Amore 	int		  skipvsp;	/* Vertical space to skip. */
7095c635efSGarrett D'Amore 	int		  flags;
7195c635efSGarrett D'Amore #define	TERMP_SENTENCE	 (1 << 1)	/* Space before a sentence. */
7295c635efSGarrett D'Amore #define	TERMP_NOSPACE	 (1 << 2)	/* No space before words. */
73*698f87a4SGarrett D'Amore #define	TERMP_NONOSPACE	 (1 << 3)	/* No space (no autounset). */
74*698f87a4SGarrett D'Amore #define	TERMP_NBRWORD	 (1 << 4)	/* Make next word nonbreaking. */
75*698f87a4SGarrett D'Amore #define	TERMP_KEEP	 (1 << 5)	/* Keep words together. */
76*698f87a4SGarrett D'Amore #define	TERMP_PREKEEP	 (1 << 6)	/* ...starting with the next one. */
77*698f87a4SGarrett D'Amore #define	TERMP_SKIPCHAR	 (1 << 7)	/* Skip the next character. */
78*698f87a4SGarrett D'Amore #define	TERMP_NOBREAK	 (1 << 8)	/* See term_flushln(). */
79*698f87a4SGarrett D'Amore #define	TERMP_DANGLE	 (1 << 9)	/* See term_flushln(). */
80*698f87a4SGarrett D'Amore #define	TERMP_HANG	 (1 << 10)	/* See term_flushln(). */
8195c635efSGarrett D'Amore #define	TERMP_NOSPLIT	 (1 << 11)	/* See termp_an_pre/post(). */
8295c635efSGarrett D'Amore #define	TERMP_SPLIT	 (1 << 12)	/* See termp_an_pre/post(). */
8395c635efSGarrett D'Amore #define	TERMP_ANPREC	 (1 << 13)	/* See termp_an_pre(). */
8495c635efSGarrett D'Amore 	int		 *buf;		/* Output buffer. */
8595c635efSGarrett D'Amore 	enum termenc	  enc;		/* Type of encoding. */
8695c635efSGarrett D'Amore 	struct mchars	 *symtab;	/* Encoded-symbol table. */
8795c635efSGarrett D'Amore 	enum termfont	  fontl;	/* Last font set. */
8895c635efSGarrett D'Amore 	enum termfont	  fontq[10];	/* Symmetric fonts. */
8995c635efSGarrett D'Amore 	int		  fonti;	/* Index of font stack. */
9095c635efSGarrett D'Amore 	term_margin	  headf;	/* invoked to print head */
9195c635efSGarrett D'Amore 	term_margin	  footf;	/* invoked to print foot */
9295c635efSGarrett D'Amore 	void		(*letter)(struct termp *, int);
9395c635efSGarrett D'Amore 	void		(*begin)(struct termp *);
9495c635efSGarrett D'Amore 	void		(*end)(struct termp *);
9595c635efSGarrett D'Amore 	void		(*endline)(struct termp *);
9695c635efSGarrett D'Amore 	void		(*advance)(struct termp *, size_t);
9795c635efSGarrett D'Amore 	size_t		(*width)(const struct termp *, int);
9895c635efSGarrett D'Amore 	double		(*hspan)(const struct termp *,
9995c635efSGarrett D'Amore 				const struct roffsu *);
10095c635efSGarrett D'Amore 	const void	 *argf;		/* arg for headf/footf */
10195c635efSGarrett D'Amore 	struct termp_ps	 *ps;
10295c635efSGarrett D'Amore };
10395c635efSGarrett D'Amore 
10495c635efSGarrett D'Amore void		  term_eqn(struct termp *, const struct eqn *);
10595c635efSGarrett D'Amore void		  term_tbl(struct termp *, const struct tbl_span *);
10695c635efSGarrett D'Amore void		  term_free(struct termp *);
10795c635efSGarrett D'Amore void		  term_newln(struct termp *);
10895c635efSGarrett D'Amore void		  term_vspace(struct termp *);
10995c635efSGarrett D'Amore void		  term_word(struct termp *, const char *);
11095c635efSGarrett D'Amore void		  term_flushln(struct termp *);
11195c635efSGarrett D'Amore void		  term_begin(struct termp *, term_margin,
11295c635efSGarrett D'Amore 			term_margin, const void *);
11395c635efSGarrett D'Amore void		  term_end(struct termp *);
11495c635efSGarrett D'Amore 
11595c635efSGarrett D'Amore size_t		  term_hspan(const struct termp *,
11695c635efSGarrett D'Amore 			const struct roffsu *);
11795c635efSGarrett D'Amore size_t		  term_vspan(const struct termp *,
11895c635efSGarrett D'Amore 			const struct roffsu *);
11995c635efSGarrett D'Amore size_t		  term_strlen(const struct termp *, const char *);
12095c635efSGarrett D'Amore size_t		  term_len(const struct termp *, size_t);
12195c635efSGarrett D'Amore 
12295c635efSGarrett D'Amore enum termfont	  term_fonttop(struct termp *);
12395c635efSGarrett D'Amore const void	 *term_fontq(struct termp *);
12495c635efSGarrett D'Amore void		  term_fontpush(struct termp *, enum termfont);
12595c635efSGarrett D'Amore void		  term_fontpop(struct termp *);
12695c635efSGarrett D'Amore void		  term_fontpopq(struct termp *, const void *);
12795c635efSGarrett D'Amore void		  term_fontrepl(struct termp *, enum termfont);
12895c635efSGarrett D'Amore void		  term_fontlast(struct termp *);
12995c635efSGarrett D'Amore 
13095c635efSGarrett D'Amore __END_DECLS
13195c635efSGarrett D'Amore 
13295c635efSGarrett D'Amore #endif /*!TERM_H*/
133