xref: /freebsd/contrib/mandoc/term.h (revision 6829dae12bb055451fa467da4589c43bd03b1e64)
1 /*	$Id: term.h,v 1.130 2017/07/08 14:51:05 schwarze Exp $ */
2 /*
3  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4  * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 enum	termenc {
20 	TERMENC_ASCII,
21 	TERMENC_LOCALE,
22 	TERMENC_UTF8
23 };
24 
25 enum	termtype {
26 	TERMTYPE_CHAR,
27 	TERMTYPE_PS,
28 	TERMTYPE_PDF
29 };
30 
31 enum	termfont {
32 	TERMFONT_NONE = 0,
33 	TERMFONT_BOLD,
34 	TERMFONT_UNDER,
35 	TERMFONT_BI,
36 	TERMFONT__MAX
37 };
38 
39 struct	eqn_box;
40 struct	roff_meta;
41 struct	roff_node;
42 struct	tbl_span;
43 struct	termp;
44 
45 typedef void	(*term_margin)(struct termp *, const struct roff_meta *);
46 
47 struct	termp_tbl {
48 	int		  width;	/* width in fixed chars */
49 	int		  decimal;	/* decimal point position */
50 };
51 
52 struct	termp_col {
53 	int		 *buf;		/* Output buffer. */
54 	size_t		  maxcols;	/* Allocated bytes in buf. */
55 	size_t		  lastcol;	/* Last byte in buf. */
56 	size_t		  col;		/* Byte in buf to be written. */
57 	size_t		  rmargin;	/* Current right margin. */
58 	size_t		  offset;	/* Current left margin. */
59 };
60 
61 struct	termp {
62 	struct rofftbl	  tbl;		/* Table configuration. */
63 	struct termp_col *tcols;	/* Array of table columns. */
64 	struct termp_col *tcol;		/* Current table column. */
65 	size_t		  maxtcol;	/* Allocated table columns. */
66 	size_t		  lasttcol;	/* Last column currently used. */
67 	size_t		  line;		/* Current output line number. */
68 	size_t		  defindent;	/* Default indent for text. */
69 	size_t		  defrmargin;	/* Right margin of the device. */
70 	size_t		  lastrmargin;	/* Right margin before the last ll. */
71 	size_t		  maxrmargin;	/* Max right margin. */
72 	size_t		  col;		/* Byte position in buf. */
73 	size_t		  viscol;	/* Chars on current line. */
74 	size_t		  trailspace;	/* See term_flushln(). */
75 	size_t		  minbl;	/* Minimum blanks before next field. */
76 	int		  synopsisonly; /* Print the synopsis only. */
77 	int		  mdocstyle;	/* Imitate mdoc(7) output. */
78 	int		  ti;		/* Temporary indent for one line. */
79 	int		  skipvsp;	/* Vertical space to skip. */
80 	int		  flags;
81 #define	TERMP_SENTENCE	 (1 << 0)	/* Space before a sentence. */
82 #define	TERMP_NOSPACE	 (1 << 1)	/* No space before words. */
83 #define	TERMP_NONOSPACE	 (1 << 2)	/* No space (no autounset). */
84 #define	TERMP_NBRWORD	 (1 << 3)	/* Make next word nonbreaking. */
85 #define	TERMP_KEEP	 (1 << 4)	/* Keep words together. */
86 #define	TERMP_PREKEEP	 (1 << 5)	/* ...starting with the next one. */
87 #define	TERMP_BACKAFTER	 (1 << 6)	/* Back up after next character. */
88 #define	TERMP_BACKBEFORE (1 << 7)	/* Back up before next character. */
89 #define	TERMP_NOBREAK	 (1 << 8)	/* See term_flushln(). */
90 #define	TERMP_BRTRSP	 (1 << 9)	/* See term_flushln(). */
91 #define	TERMP_BRIND	 (1 << 10)	/* See term_flushln(). */
92 #define	TERMP_HANG	 (1 << 11)	/* See term_flushln(). */
93 #define	TERMP_NOPAD	 (1 << 12)	/* See term_flushln(). */
94 #define	TERMP_NOSPLIT	 (1 << 13)	/* Do not break line before .An. */
95 #define	TERMP_SPLIT	 (1 << 14)	/* Break line before .An. */
96 #define	TERMP_NONEWLINE	 (1 << 15)	/* No line break in nofill mode. */
97 #define	TERMP_BRNEVER	 (1 << 16)	/* Don't even break at maxrmargin. */
98 #define	TERMP_NOBUF	 (1 << 17)	/* Bypass output buffer. */
99 #define	TERMP_NEWMC	 (1 << 18)	/* No .mc printed yet. */
100 #define	TERMP_ENDMC	 (1 << 19)	/* Next break ends .mc mode. */
101 #define	TERMP_MULTICOL	 (1 << 20)	/* Multiple column mode. */
102 	enum termtype	  type;		/* Terminal, PS, or PDF. */
103 	enum termenc	  enc;		/* Type of encoding. */
104 	enum termfont	  fontl;	/* Last font set. */
105 	enum termfont	 *fontq;	/* Symmetric fonts. */
106 	int		  fontsz;	/* Allocated size of font stack */
107 	int		  fonti;	/* Index of font stack. */
108 	term_margin	  headf;	/* invoked to print head */
109 	term_margin	  footf;	/* invoked to print foot */
110 	void		(*letter)(struct termp *, int);
111 	void		(*begin)(struct termp *);
112 	void		(*end)(struct termp *);
113 	void		(*endline)(struct termp *);
114 	void		(*advance)(struct termp *, size_t);
115 	void		(*setwidth)(struct termp *, int, int);
116 	size_t		(*width)(const struct termp *, int);
117 	int		(*hspan)(const struct termp *,
118 				const struct roffsu *);
119 	const void	 *argf;		/* arg for headf/footf */
120 	const char	 *mc;		/* Margin character. */
121 	struct termp_ps	 *ps;
122 };
123 
124 
125 const char	 *ascii_uc2str(int);
126 
127 void		  roff_term_pre(struct termp *, const struct roff_node *);
128 
129 void		  term_eqn(struct termp *, const struct eqn_box *);
130 void		  term_tbl(struct termp *, const struct tbl_span *);
131 void		  term_free(struct termp *);
132 void		  term_setcol(struct termp *, size_t);
133 void		  term_newln(struct termp *);
134 void		  term_vspace(struct termp *);
135 void		  term_word(struct termp *, const char *);
136 void		  term_flushln(struct termp *);
137 void		  term_begin(struct termp *, term_margin,
138 			term_margin, const struct roff_meta *);
139 void		  term_end(struct termp *);
140 
141 void		  term_setwidth(struct termp *, const char *);
142 int		  term_hspan(const struct termp *, const struct roffsu *);
143 int		  term_hen(const struct termp *, const struct roffsu *);
144 int		  term_vspan(const struct termp *, const struct roffsu *);
145 size_t		  term_strlen(const struct termp *, const char *);
146 size_t		  term_len(const struct termp *, size_t);
147 
148 void		  term_tab_set(const struct termp *, const char *);
149 void		  term_tab_iset(size_t);
150 size_t		  term_tab_next(size_t);
151 
152 void		  term_fontpush(struct termp *, enum termfont);
153 void		  term_fontpop(struct termp *);
154 void		  term_fontpopq(struct termp *, int);
155 void		  term_fontrepl(struct termp *, enum termfont);
156 void		  term_fontlast(struct termp *);
157