]> git.cameronkatri.com Git - mandoc.git/blob - term.h
Many more ASCII escapes added.
[mandoc.git] / term.h
1 /* $Id: term.h,v 1.27 2009/03/19 11:49:00 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 /* FIXME - clean up tabs. */
25
26 #define INDENT 6
27
28 __BEGIN_DECLS
29
30 struct termp {
31 size_t rmargin; /* Current right margin. */
32 size_t maxrmargin; /* Max right margin. */
33 size_t maxcols; /* Max size of buf. */
34 size_t offset; /* Margin offest. */
35 size_t col; /* Bytes in buf. */
36 int flags;
37 #define TERMP_NOSPACE (1 << 0) /* No space before words. */
38 #define TERMP_NOLPAD (1 << 1) /* No leftpad before flush. */
39 #define TERMP_NOBREAK (1 << 2) /* No break after flush. */
40 #define TERMP_LITERAL (1 << 3) /* Literal words. */
41 #define TERMP_IGNDELIM (1 << 4) /* Delims like regulars. */
42 #define TERMP_NONOSPACE (1 << 5) /* No space (no autounset). */
43 #define TERMP_NONOBREAK (1 << 7) /* Don't newln NOBREAK. */
44 #define TERMP_STYLE 0x0300 /* Style mask. */
45 #define TERMP_BOLD (1 << 8) /* Styles... */
46 #define TERMP_UNDER (1 << 9)
47 char *buf; /* Output buffer. */
48 void *symtab; /* Encoded-symbol table. */
49 };
50
51 /* XXX - clean this up. */
52
53 struct termpair {
54 struct termpair *ppair;
55 int type;
56 #define TERMPAIR_FLAG (1 << 0)
57 int flag;
58 size_t offset;
59 size_t rmargin;
60 int count;
61 };
62
63 #define TERMPAIR_SETFLAG(termp, p, fl) \
64 do { \
65 assert(! (TERMPAIR_FLAG & (p)->type)); \
66 (termp)->flags |= (fl); \
67 (p)->flag = (fl); \
68 (p)->type |= TERMPAIR_FLAG; \
69 } while (0)
70
71 struct termact {
72 int (*pre)(struct termp *, struct termpair *,
73 const struct mdoc_meta *,
74 const struct mdoc_node *);
75 void (*post)(struct termp *, struct termpair *,
76 const struct mdoc_meta *,
77 const struct mdoc_node *);
78 };
79
80 void *ascii2htab(void);
81 const char *a2ascii(void *, const char *, size_t, size_t *);
82 void asciifree(void *);
83
84 void newln(struct termp *);
85 void vspace(struct termp *);
86 void word(struct termp *, const char *);
87 void flushln(struct termp *);
88 void transcode(struct termp *, const char *, size_t);
89 void subtree(struct termp *, const struct mdoc_meta *,
90 const struct mdoc_node *);
91
92 const struct termact *termacts;
93
94 __END_DECLS
95
96 #endif /*!TERM_H*/