xref: /titanic_50/usr/src/cmd/mandoc/term.h (revision 260e9a87725c090ba5835b1f9f0b62fa2f96036f)
1*260e9a87SYuri Pankov /*	$Id: term.h,v 1.111 2015/01/31 00:12:41 schwarze Exp $ */
295c635efSGarrett D'Amore /*
395c635efSGarrett D'Amore  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*260e9a87SYuri Pankov  * Copyright (c) 2011, 2012, 2013, 2014 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 
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 
3995c635efSGarrett D'Amore #define	TERM_MAXMARGIN	  100000 /* FIXME */
4095c635efSGarrett D'Amore 
41*260e9a87SYuri Pankov struct	termp;
42*260e9a87SYuri Pankov 
4395c635efSGarrett D'Amore typedef void	(*term_margin)(struct termp *, const void *);
4495c635efSGarrett D'Amore 
4595c635efSGarrett D'Amore struct	termp_tbl {
4695c635efSGarrett D'Amore 	int		  width;	/* width in fixed chars */
4795c635efSGarrett D'Amore 	int		  decimal;	/* decimal point position */
4895c635efSGarrett D'Amore };
4995c635efSGarrett D'Amore 
5095c635efSGarrett D'Amore struct	termp {
5195c635efSGarrett D'Amore 	enum termtype	  type;
5295c635efSGarrett D'Amore 	struct rofftbl	  tbl;		/* table configuration */
53*260e9a87SYuri Pankov 	int		  synopsisonly; /* print the synopsis only */
5495c635efSGarrett D'Amore 	int		  mdocstyle;	/* imitate mdoc(7) output */
5595c635efSGarrett D'Amore 	size_t		  defindent;	/* Default indent for text. */
5695c635efSGarrett D'Amore 	size_t		  defrmargin;	/* Right margin of the device. */
57*260e9a87SYuri Pankov 	size_t		  lastrmargin;	/* Right margin before the last ll. */
5895c635efSGarrett D'Amore 	size_t		  rmargin;	/* Current right margin. */
5995c635efSGarrett D'Amore 	size_t		  maxrmargin;	/* Max right margin. */
60698f87a4SGarrett D'Amore 	size_t		  maxcols;	/* Max size of buf. */
6195c635efSGarrett D'Amore 	size_t		  offset;	/* Margin offest. */
6295c635efSGarrett D'Amore 	size_t		  tabwidth;	/* Distance of tab positions. */
63698f87a4SGarrett D'Amore 	size_t		  col;		/* Bytes in buf. */
6495c635efSGarrett D'Amore 	size_t		  viscol;	/* Chars on current line. */
65698f87a4SGarrett D'Amore 	size_t		  trailspace;	/* See termp_flushln(). */
6695c635efSGarrett D'Amore 	int		  overstep;	/* See termp_flushln(). */
67698f87a4SGarrett D'Amore 	int		  skipvsp;	/* Vertical space to skip. */
6895c635efSGarrett D'Amore 	int		  flags;
6995c635efSGarrett D'Amore #define	TERMP_SENTENCE	 (1 << 1)	/* Space before a sentence. */
7095c635efSGarrett D'Amore #define	TERMP_NOSPACE	 (1 << 2)	/* No space before words. */
71698f87a4SGarrett D'Amore #define	TERMP_NONOSPACE	 (1 << 3)	/* No space (no autounset). */
72698f87a4SGarrett D'Amore #define	TERMP_NBRWORD	 (1 << 4)	/* Make next word nonbreaking. */
73698f87a4SGarrett D'Amore #define	TERMP_KEEP	 (1 << 5)	/* Keep words together. */
74698f87a4SGarrett D'Amore #define	TERMP_PREKEEP	 (1 << 6)	/* ...starting with the next one. */
75698f87a4SGarrett D'Amore #define	TERMP_SKIPCHAR	 (1 << 7)	/* Skip the next character. */
76698f87a4SGarrett D'Amore #define	TERMP_NOBREAK	 (1 << 8)	/* See term_flushln(). */
77*260e9a87SYuri Pankov #define	TERMP_BRIND	 (1 << 9)	/* See term_flushln(). */
78*260e9a87SYuri Pankov #define	TERMP_DANGLE	 (1 << 10)	/* See term_flushln(). */
79*260e9a87SYuri Pankov #define	TERMP_HANG	 (1 << 11)	/* See term_flushln(). */
80*260e9a87SYuri Pankov #define	TERMP_NOSPLIT	 (1 << 12)	/* Do not break line before .An. */
81*260e9a87SYuri Pankov #define	TERMP_SPLIT	 (1 << 13)	/* Break line before .An. */
82*260e9a87SYuri Pankov #define	TERMP_NONEWLINE	 (1 << 14)	/* No line break in nofill mode. */
8395c635efSGarrett D'Amore 	int		 *buf;		/* Output buffer. */
8495c635efSGarrett D'Amore 	enum termenc	  enc;		/* Type of encoding. */
85*260e9a87SYuri Pankov 	const struct mchars *symtab;	/* Character table. */
8695c635efSGarrett D'Amore 	enum termfont	  fontl;	/* Last font set. */
87*260e9a87SYuri Pankov 	enum termfont	 *fontq;	/* Symmetric fonts. */
88*260e9a87SYuri Pankov 	int		  fontsz;	/* Allocated size of font stack */
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);
97*260e9a87SYuri Pankov 	void		(*setwidth)(struct termp *, int, size_t);
9895c635efSGarrett D'Amore 	size_t		(*width)(const struct termp *, int);
9995c635efSGarrett D'Amore 	double		(*hspan)(const struct termp *,
10095c635efSGarrett D'Amore 				const struct roffsu *);
10195c635efSGarrett D'Amore 	const void	 *argf;		/* arg for headf/footf */
10295c635efSGarrett D'Amore 	struct termp_ps	 *ps;
10395c635efSGarrett D'Amore };
10495c635efSGarrett D'Amore 
105*260e9a87SYuri Pankov __BEGIN_DECLS
106*260e9a87SYuri Pankov 
107*260e9a87SYuri Pankov struct	tbl_span;
108*260e9a87SYuri Pankov struct	eqn;
109*260e9a87SYuri Pankov 
110*260e9a87SYuri Pankov const char	 *ascii_uc2str(int);
111*260e9a87SYuri Pankov 
11295c635efSGarrett D'Amore void		  term_eqn(struct termp *, const struct eqn *);
11395c635efSGarrett D'Amore void		  term_tbl(struct termp *, const struct tbl_span *);
11495c635efSGarrett D'Amore void		  term_free(struct termp *);
11595c635efSGarrett D'Amore void		  term_newln(struct termp *);
11695c635efSGarrett D'Amore void		  term_vspace(struct termp *);
11795c635efSGarrett D'Amore void		  term_word(struct termp *, const char *);
11895c635efSGarrett D'Amore void		  term_flushln(struct termp *);
11995c635efSGarrett D'Amore void		  term_begin(struct termp *, term_margin,
12095c635efSGarrett D'Amore 			term_margin, const void *);
12195c635efSGarrett D'Amore void		  term_end(struct termp *);
12295c635efSGarrett D'Amore 
123*260e9a87SYuri Pankov void		  term_setwidth(struct termp *, const char *);
124*260e9a87SYuri Pankov int		  term_hspan(const struct termp *, const struct roffsu *);
125*260e9a87SYuri Pankov int		  term_vspan(const struct termp *, const struct roffsu *);
12695c635efSGarrett D'Amore size_t		  term_strlen(const struct termp *, const char *);
12795c635efSGarrett D'Amore size_t		  term_len(const struct termp *, size_t);
12895c635efSGarrett D'Amore 
12995c635efSGarrett D'Amore void		  term_fontpush(struct termp *, enum termfont);
13095c635efSGarrett D'Amore void		  term_fontpop(struct termp *);
131*260e9a87SYuri Pankov void		  term_fontpopq(struct termp *, int);
13295c635efSGarrett D'Amore void		  term_fontrepl(struct termp *, enum termfont);
13395c635efSGarrett D'Amore void		  term_fontlast(struct termp *);
13495c635efSGarrett D'Amore 
13595c635efSGarrett D'Amore __END_DECLS
136