]> git.cameronkatri.com Git - mandoc.git/blob - term.h
Support for maxrmargin-breaking with TERMP_NOBREAK.
[mandoc.git] / term.h
1 /* $Id: term.h,v 1.13 2009/03/02 12:09:32 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19 #ifndef TERM_H
20 #define TERM_H
21
22 #include "mdoc.h"
23
24 #define INDENT 6
25
26 __BEGIN_DECLS
27
28 struct termp {
29 size_t rmargin;
30 size_t maxrmargin;
31 size_t maxcols;
32 size_t offset;
33 size_t col;
34 int flags;
35 #define TERMP_BOLD (1 << 0) /* Embolden words. */
36 #define TERMP_UNDERLINE (1 << 1) /* Underline words. */
37 #define TERMP_NOSPACE (1 << 2) /* No space before words. */
38 #define TERMP_NOLPAD (1 << 3) /* No leftpad before flush. */
39 #define TERMP_NOBREAK (1 << 4) /* No break after flush. */
40 #define TERMP_LITERAL (1 << 5) /* Literal words. */
41 #define TERMP_IGNDELIM (1 << 6) /* Delims like regulars. */
42 #define TERMP_NONOSPACE (1 << 7) /* No space (no autounset). */
43 char *buf;
44 };
45
46 struct termpair {
47 struct termpair *ppair;
48 int type;
49 #define TERMPAIR_FLAG (1 << 0)
50 int flag;
51 size_t offset;
52 size_t rmargin;
53 int count;
54 };
55
56 #define TERMPAIR_SETFLAG(termp, p, fl) \
57 do { \
58 assert(! (TERMPAIR_FLAG & (p)->type)); \
59 (termp)->flags |= (fl); \
60 (p)->flag = (fl); \
61 (p)->type |= TERMPAIR_FLAG; \
62 } while (0)
63
64 struct termact {
65 int (*pre)(struct termp *,
66 struct termpair *,
67 const struct mdoc_meta *,
68 const struct mdoc_node *);
69 void (*post)(struct termp *,
70 struct termpair *,
71 const struct mdoc_meta *,
72 const struct mdoc_node *);
73 };
74
75 void newln(struct termp *);
76 void vspace(struct termp *);
77 void word(struct termp *, const char *);
78 void flushln(struct termp *);
79 void transcode(struct termp *,
80 const char *, size_t);
81
82 void subtree(struct termp *,
83 const struct mdoc_meta *,
84 const struct mdoc_node *);
85
86 const struct termact *termacts;
87
88 __END_DECLS
89
90 #endif /*!TERM_H*/